Commit Graph

100 Commits

Author SHA1 Message Date
Julien P 13ffd51017
Only look for main in package.json if no entyrpoint was set via Pulumi.yaml ()
# Description

`main` in Pulumi.yaml is supposed to take precedence over `main` in
`package.json`, but we inadvertently broke this in
cf1189bf2c

Fixes https://github.com/pulumi/pulumi/issues/16274

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`
2024-06-11 11:36:34 +00:00
Julien P fa2a196c27
Vendor TypeScript and ts-node ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

Fixes https://github.com/pulumi/pulumi/issues/15733

Historically these packages were direct dependencies of
`@pulumi/pulumi`. To decouple the node SDK from the precise version of
TypeScript, the packages are now declared as optional peer pependencies
of `@pulumi/pulumi` and customers can pick the versions they want.

The reason we mark the peer dependencies as *optional* is to prevent
package managers from automatically installing them. This avoids the
situation where the package manger would install a more recent version
of TypeScript without the user explictly opting in. Newer versions have
stricter type checks, and can thus stop existing programs from running
successfully.

When the peer dependencies are not present, we load the vendored
versions of the modules.

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-04-10 15:26:37 +00:00
Fraser Waters a18399285f
NodeJS transforms ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

This adds a new experimental feature to the NodeJS SDK to register
remote transform functions. These are currently all prefixed 'X' to show
they're experimental.

These transform functions will run even for resources created inside
MLCs.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-07 08:52:34 +00:00
Justin Van Patten cf1189bf2c [sdk/nodejs] Support loading package.json from parent dir
This commit changes how the Node SDK resolves package.json to recursively look up the directory tree for the file when it's not present in the cwd. The previous behavior was to only look in the current directory, and fallback to an empty object when the file could not be found.
2023-06-29 07:57:43 -07:00
Robbie McKinstry 0473bb0d2a
Set programRunning to true only once programStarted callback is invoked. 2023-05-17 17:02:43 -04:00
Robbie McKinstry 1c937e3593
Eliminate assignment statements used as expressions.
This change refactors assignment statements used as expressions
to prefer assignment statements instead. Assignments are often
assumed to now evaluate to a value, but instead to represent a
change to a lexical binding. By using them as expressions, we can
write confusing and buggy code. This commit eliminates those instances,
and enables a lint to prevent future occurances.
2023-05-15 19:48:47 -04:00
Robbie McKinstry c500b3b997
Revert package.json lookup fix. 2023-05-15 14:14:57 -04:00
Robbie McKinstry c3e5e483ca
Update four tests to reflected the standardized "main" behavior.
The `main` field in package.json is standardized by Node to refer
to a file relative to package.json. The previous commits in this
PR used `main` relative to the Pulumi main directory, which was
incorrect. This commit upgrades two tests, and introduces two more,
to verify the correctness of this behavior and the PR in general.
2023-05-10 18:04:59 -04:00
Robbie McKinstry dad42a4954
Remove references to missing files.
It appears that a large number of tests were using references
to main fields which don't currently exist. The runtime didn't
produce an error because package.json was being ignored.
2023-05-10 18:04:59 -04:00
Robbie McKinstry e15fd85696
Test ESM module with package.json located in parent folder
This commit adds a test to assert Pulumi programs written as ESM
modules can be executed when their package.json file is located
in the parent directory.
2023-05-10 15:39:19 -04:00
Robbie McKinstry b8cd5c966f
Recursively lookup directories for package.json.
With this commit, if package.json is not in pwd, Pulumi
recursively scans up the directory tree to find package.json.
2023-05-10 15:39:19 -04:00
Robbie McKinstry e05a3bd81c
Apply autoformat
This commit applies the Rome autoformatter to the Node SDK.
These changes are automatically produced. To reproduce these
changes, run `make format` from inside sdk/nodejs.
2023-04-28 18:27:10 -04:00
Fraser Waters 48ec2c6336 Fix require reading JSON files 2023-02-28 21:24:04 +00:00
Kyle Dixler b716e591d3
This commit colorizes nodejs stack traces to respect the default
highlighting. The service doesn't currently support ANSI control
codes so all ANSI control codes are removed before being sent to
the service, but still displayed in the CLI.
2023-02-16 14:20:42 -08:00
Kyle Pitzen 5cfad4a909 fix: Allows for parallel pulumi programs to run in the node runtime 2022-10-13 07:15:25 -04:00
bors[bot] 5493b82530
Merge
10622: Enable ESModule interoperability r=RobbieMcKinstry a=RobbieMcKinstry

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

This PR enables ESModule interop for the NodeJS SDK. By enabling interop, we should in theory remove subtle bugs from Pulumi programs that assume our libraries are interopable. In practice, only a few modules weren't already interoperable. Nevertheless, enabling this compiler flag will require future code to be compatible with ESModules, potentially eliminating future bugs.

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes https://github.com/pulumi/pulumi/issues/10621

This PR is required for bundling the NodeJS runtime (https://github.com/pulumi/pulumi/issues/10210).

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Robbie McKinstry <robbie@pulumi.com>
2022-09-21 22:20:53 +00:00
Justin Van Patten dc7f3f0c66 [sdk/nodejs] Mark internal APIs `@internal` to filter from SDK docs
These exported APIs aren't intended for public use. Marking them as `@internal` makes TypeScript remove them from the `.d.ts` files and removes them from our Node.js SDK docs.
2022-09-20 11:54:06 -07:00
Robbie McKinstry e978311216
Enable ESModule interoperability 2022-09-20 10:34:00 -04:00
Robbie McKinstry 14dcf2ebe4
Fix lint issues 2022-09-15 07:27:44 -04:00
Robbie McKinstry 20fd7c4530
Put NodeJS tracing behind the PULUMI_EXPERIMENTAL flag. 2022-09-15 07:27:44 -04:00
Robbie McKinstry ab0c77ceec
Ditch transforming the URL, use whatever is provided. 2022-09-15 07:26:53 -04:00
Robbie McKinstry 76da04cf48
Move tracing module into cmd, since it should not be part of the library code. 2022-09-15 07:26:52 -04:00
Robbie McKinstry 4d4309712a
Gracefully handle engine-provided tracing URI 2022-09-15 07:26:52 -04:00
Robbie McKinstry 7a125ed4b4
Replace console.log with log.debug 2022-09-15 07:26:52 -04:00
Robbie McKinstry 3133ecf4fa
More instrumentation 2022-09-15 07:26:52 -04:00
Robbie McKinstry cdd3f42db9
WIP Add debug info for zipkin tracing 2022-09-15 07:26:52 -04:00
Robbie McKinstry 1d246208d6
Make tracing conditional. Add gRPC instrumentation. 2022-09-15 07:26:52 -04:00
Robbie McKinstry 1f1bd9d130
Clean up tracing impl, ensure it can gracefully shutdown 2022-09-15 07:26:52 -04:00
Robbie McKinstry 608086dd5e
WIP Add Jaegar-based tracing 2022-09-15 07:26:51 -04:00
Fraser Waters 78b82c282d
Fix getOrganization for nodejs () 2022-08-31 18:24:25 +01:00
Kyle Dixler c1bf31a26a
updated error message to catch syntax errors () 2022-08-23 21:33:29 -05:00
Kyle Pitzen c4c46c3222
fix(ux): Adds a warning message when module resolution is ambiguous ()
previously, when both index.ts and index.js were present
and no main key was provided in Pulumi.yaml, Pulumi would quietly
resolve the entrypoint as index.js.  This messages that decision in a warning
2022-08-16 14:41:15 -04:00
Kyle Pitzen 0dae8fdbdd
fix: Replaces current fallback nodejs error messaging () 2022-08-15 10:52:12 -04:00
Kyle Dixler 0c196d3dca
[sdk/nodejs] removed ts compilation stack trace ()
* removed ts compilation stack trace
2022-07-27 14:14:36 -07:00
Anton Tayanovskyy f6fc099792
Avoid importing typescript unless necessary ()
* Avoid importing typescript in node SDK where possible

* Lazy-load runtime/closure in dynamic/index.ts

* More targeted runtime import in config.ts

* More precise imports in run-policy-pack/run.ts

* More precise imports for dynamic-provider/index.ts

* More precise imports for automation/server.ts

* Share typescript compiler option loading func in run.ts and run-policy-pack/run.ts

* Lazy-load ts-node that depends on TypeScript

* Break module import cycle

* Fix node lint
2022-07-20 17:38:55 -04:00
Zaid Ajaj 36b03bc196
[area/nodejs] Take engines property into account when engine-strict appear in .npmrc file ()
* Take required nodejs version into account as specified in engine.node

* Simplify check for strict node engine

* Add changelog entry

* make linter happy
2022-03-22 12:26:55 +01:00
Aaron Friel 9c1d7f9c89 ci: improve x-plat testing on Windows 2022-03-06 14:45:26 -08:00
Fraser Waters 6b731c617c
Pass project path to tsnode ()
* Pass project path to tsnode

* Add to changelog
2022-02-28 16:35:44 +00:00
David Mattia 38a68bbf95
Allow turning ts typechecking off ()
* Allow turning ts typechecking off

In our case, we prefer to run Pulumi separately from `tsc` to compile our code.

* Add changelog pending update

* Accept suggested change

Co-authored-by: Fraser Waters <frassle@gmail.com>

* Update sdk/nodejs/cmd/run/run.ts

Co-authored-by: Fraser Waters <frassle@gmail.com>

* lint

Co-authored-by: Fraser Waters <frassle@gmail.com>
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2022-02-15 10:48:53 +00:00
Luke Hoban 1181311c4e
[sdk/nodejs] Support top-level default exports in ESM ()
In  and  we added support for ESM entrypoints.  However, ESM "default exports" were handled just as "normal" in Node.js dynamic import of ESM - as a `default` proeprty in the export object.

This is not a particularly useful behaviour for Pulumi program entry points, and doesn't quite match some of the special logic we apply to non-object exports in CommonJS modules (invoking exported functions, and then awaiting exports promises).

Instead, this change adds support for default exports, treating the default export (if present) as the full returned export value.

It is for now an error to have both a default export and named exports, since it is unclear what this should mean.  In the future, we could potentially relax this and define how these two sets of exports are merged.

This is technically a breaking change from the support added in the recent releases, but only in a narrow case, and in that case the Pulumi stack exports were almost certainly not what the user wanted.

Fixes , which includes a motivating example where this is ~necessary.
2022-01-22 18:33:28 -08:00
Luke Hoban 6bc7b1cc67
[langhost/node] More ESM support: `nodeargs`, main entrypoints, and tests ()
This follows up on the changes in  with three additions:

* Support for passing args directly to node so that ESM loaders and other node process level configuration can be accessed via Pulumi
* Support the same default behaviour for loading a ESM module from Pulumi as for node <program>, including support for resolving main entrypoint from package folder.
* Add test cases for .js, pre-complied .ts and ts-node-based `.ts.

This includes test cases that show how to use top-level await in Node.js (which is only possible inside ESM), addressing .

Using ESM via the default ts-node-based TypeScript support is a little tricky, as it is dependent on experimental loader hook support in Node, upon which partially in-progress ts-node support has been added. We cannot make these the default experience yet, but the examples here show how users can configure things themselves to access these features. Once this support solidifies and we can rely on it in all supported Node and TypeScript versions, we may be able to update templates to support more of this by default.
2022-01-04 18:54:38 -08:00
Lewis Liu b640c8dd7b
Support native ES module for node sdk ()
This PR makes the minimum set of changes possible to support native ES modules in the Pulumi Node SDK.
2021-12-29 19:22:01 -08:00
Ian Wahbe d9dd88c740
Add tsconfig option to specify tsconfig path ()
* Add tsconfig option to specify tsconfig path

* Add CHANGELOG entry and fix lint

* Add a test

* Fix test
2021-11-22 11:42:39 -08:00
PND b5ee840b16
[sdk/nodejs] Prevent Pulumi from overriding tsconfig.json options. () 2021-08-15 18:58:43 -07:00
Horace Lee a92a005d68
Use ESlint instead of TSlint ()
Migrated TSlint configs to ESlint ones using [tslint-to-eslint-config](https://github.com/typescript-eslint/tslint-to-eslint-config) tool, and refined the configs to better match the current coding style.

Changes:
- [member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md#options) that as suggested default for type definition to be  with `semicolon`
- Indentation fixes that is enforced by [eslint-indent](https://eslint.org/docs/rules/indent#options)
- Added dependencies for ESlint with Typescript
- Removed TSlint
2021-08-10 11:31:59 -07:00
Evan Boyle 15418b6789
Fix noisy nodejs runtime errors () 2021-05-10 15:04:03 -07:00
Pat Gavlin 2585b86aa4
Initial support for remote component construction. ()
These changes add initial support for the construction of remote
components. For now, this support is limited to the NodeJS SDK;
follow-up changes will implement support for the other SDKs.

Remote components are component resources that are constructed and
managed by plugins rather than by Pulumi programs. In this sense, they
are a bit like cloud resources, and are supported by the same
distribution and plugin loading mechanisms and described by the same
schema system.

The construction of a remote component is initiated by a
`RegisterResourceRequest` with the new `remote` field set to `true`.
When the resource monitor receives such a request, it loads the plugin
that implements the component resource and calls the `Construct`
method added to the resource provider interface as part of these
changes. This method accepts the information necessary to construct the
component and its children: the component's name, type, resource
options, inputs, and input dependencies. It is responsible for
dispatching to the appropriate component factory to create the
component, then returning its URN, resolved output properties, and
output property dependencies. The dependency information is necessary to
support features such as delete-before-replace, which rely on precise
dependency information for custom resources.

These changes also add initial support for more conveniently
implementing resource providers in NodeJS. The interface used to
implement such a provider is similar to the dynamic provider interface
(and may be unified with that interface in the future).

An example of a NodeJS program constructing a remote component resource
also implemented in NodeJS can be found in
`tests/construct_component/nodejs`.

This is the core of .
2020-09-07 19:33:55 -07:00
Justin Van Patten 9abcca345a
Mark internal APIs `@internal` to filter from API docs ()
Also:

 - Cleaned up existing tags so they're consistently at the bottom of doc comments where they should be
 - Cleaned up some unused imports while I was taking a pass over the files
 - Marked one function `@deprecated` that should be deprecated
2020-01-26 09:06:35 -08:00
CyrusNajmabadi ef69915864
Produce a slightly better error message when a user throws a non-Error object in JS. () 2019-12-16 17:27:36 -08:00
CyrusNajmabadi 048acc24f7
Allow users to export a top-level function to serve as the entrypoint to their pulumi app. () 2019-12-09 11:28:20 -08:00