New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[langhost/node] More ESM support: nodeargs
, main entrypoints, and tests
#8655
Conversation
b73a832
to
ba09f6d
Compare
2f6ddd4
to
421fef5
Compare
nodeargs
, main entrypoints, and tests
Unfortunately running out of time to properly review this till Monday. |
It's looking good but I'm having trouble running tests locally and verifying a few things due to #8678 - looking into that first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, working for me now. Thank you! LGTM.
This follows up on the changes in #7764 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 #5161. 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.
3f2a791
to
97da26a
Compare
In #7764 and #8655 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 #8725, which includes a motivating example where this is ~necessary.
@lukehoban Does this change (specifically the nodeargs part, allowing the passing of various --experimental-* flags to node) enable full support for tsconfig's baseUrl/paths? It seems like I'm getting closer to getting this working, but I'm not all the way there. |
Would it be possible to file this as an issue? That'd be very helpful for us. |
In #7764 and #8655 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 #8725, which includes a motivating example where this is ~necessary.
In #7764 and #8655 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 #8725, which includes a motivating example where this is ~necessary.
pulumi/pulumi#8655 added support for a `nodeargs` runtime option for Node.js projects, but we never explicitly documented it. This PR does that.
pulumi/pulumi#8655 added support for a `nodeargs` runtime option for Node.js projects, but we never explicitly documented it. This PR does that.
This follows up on the changes in #7764 with three additions:
node
so that ESM loaders and other node process level configuration can be accessed via Puluminode <program>
, including support for resolving main entrypoint from package folder..js
, pre-complied.ts
andts-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 #5161.
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.