Skip to content
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

Merged
merged 3 commits into from Jan 5, 2022

Conversation

lukehoban
Copy link
Member

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.

@codecov
Copy link

codecov bot commented Dec 30, 2021

Codecov Report

Merging #8655 (97da26a) into master (08df93f) will decrease coverage by 0.29%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8655      +/-   ##
==========================================
- Coverage   58.95%   58.65%   -0.30%     
==========================================
  Files         634      555      -79     
  Lines       97347    93978    -3369     
  Branches     1382     1382              
==========================================
- Hits        57389    55127    -2262     
+ Misses      36709    35600    -1109     
- Partials     3249     3251       +2     
Impacted Files Coverage Δ
sdk/nodejs/cmd/pulumi-language-nodejs/main.go 12.40% <0.00%> (-0.29%) ⬇️
...dk/go/common/resource/plugin/langruntime_plugin.go 67.29% <0.00%> (-1.89%) ⬇️
sdk/dotnet/Pulumi/Core/AssetOrArchive.cs
sdk/dotnet/Pulumi/Resources/ComponentResource.cs
.../dotnet/Pulumi/Resources/ResourceTransformation.cs
...tnet/Pulumi/Deployment/Deployment_Serialization.cs
sdk/dotnet/Pulumi/Deployment/Deployment_Run.cs
sdk/dotnet/Pulumi/Resources/CustomResource.cs
sdk/dotnet/Pulumi/Deployment/Deployment_Config.cs
...mi/Deployment/Deployment_ReadOrRegisterResource.cs
... and 73 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08df93f...97da26a. Read the comment docs.

@lukehoban lukehoban changed the title [langhost/node] More ESM support [langhost/node] More ESM support: nodeargs, main entrypoints, and tests Dec 30, 2021
@t0yv0
Copy link
Member

t0yv0 commented Dec 30, 2021

Unfortunately running out of time to properly review this till Monday.

@t0yv0
Copy link
Member

t0yv0 commented Jan 4, 2022

It's looking good but I'm having trouble running tests locally and verifying a few things due to #8678 - looking into that first.

@t0yv0 t0yv0 self-requested a review January 4, 2022 21:04
Copy link
Member

@t0yv0 t0yv0 left a 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.
@lukehoban lukehoban merged commit 6bc7b1c into master Jan 5, 2022
@pulumi-bot pulumi-bot deleted the lukehoban/moreesm branch January 5, 2022 02:54
lukehoban added a commit that referenced this pull request Jan 17, 2022
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.
@tenwit
Copy link

tenwit commented Jan 19, 2022

@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.
If it does enable better support for shiny new TS features, would it be appropriate to update the docs at https://www.pulumi.com/docs/intro/languages/javascript/#typescript to explain how to do it? I'm stuck... :(

@t0yv0
Copy link
Member

t0yv0 commented Jan 19, 2022

Would it be possible to file this as an issue? That'd be very helpful for us.

lukehoban added a commit that referenced this pull request Jan 23, 2022
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 added a commit that referenced this pull request Jan 23, 2022
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.
justinvp added a commit to pulumi/pulumi-hugo that referenced this pull request Sep 9, 2022
pulumi/pulumi#8655 added support for a `nodeargs` runtime option for Node.js projects, but we never explicitly documented it. This PR does that.
justinvp added a commit to pulumi/pulumi-hugo that referenced this pull request Sep 9, 2022
pulumi/pulumi#8655 added support for a `nodeargs` runtime option for Node.js projects, but we never explicitly documented it. This PR does that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants