-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
27 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.pulumi/ | ||
bin/ | ||
node_modules/ | ||
Pulumi.*.yaml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: esm-js-main | ||
runtime: nodejs | ||
description: Use ECMAScript modules for a plain JS program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "esm-js-main", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"main": "src/main.js", | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^4.33.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as fs from "fs"; | ||
import * as aws from "@pulumi/aws"; | ||
|
||
const b = new aws.s3.Bucket("b"); | ||
|
||
export const res = fs.readFileSync("Pulumi.yaml").toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: esm-js | ||
runtime: nodejs | ||
description: Use ECMAScript modules for a plain JS program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as fs from "fs"; | ||
|
||
export const res = fs.readFileSync("Pulumi.yaml").toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "esm-js", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: esm-ts-compiled | ||
runtime: | ||
name: nodejs | ||
options: | ||
typescript: false | ||
description: Use ECMAScript modules for a TS program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as fs from "fs"; | ||
import { x } from "./other.js"; // this is the "by design" way to do this, even in TS. | ||
|
||
// Use top-level await | ||
await new Promise(r => setTimeout(r, 2000)); | ||
|
||
export const res = fs.readFileSync("Pulumi.yaml").toString(); | ||
export const otherx = x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "esm-ts-compiled", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"main": "bin", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.5" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"dependencies": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
}, | ||
"resolutions": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
tests/integration/nodejs/esm-ts-specifier-resolution-node/Pulumi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: esm-ts-specifier-resolution-node | ||
runtime: | ||
name: nodejs | ||
options: | ||
# See https://github.com/TypeStrong/ts-node/issues/1007 | ||
nodeargs: "--experimental-specifier-resolution=node --loader ts-node/esm --no-warnings" | ||
description: Use ECMAScript modules for a TS program. |
10 changes: 10 additions & 0 deletions
10
tests/integration/nodejs/esm-ts-specifier-resolution-node/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as fs from "fs"; | ||
import { x } from "./other"; | ||
|
||
// Use top-level await | ||
await new Promise(r => setTimeout(r, 2000)); | ||
|
||
export const res = fs.readFileSync("Pulumi.yaml").toString(); | ||
export const otherx = x; |
1 change: 1 addition & 0 deletions
1
tests/integration/nodejs/esm-ts-specifier-resolution-node/other.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 42; |
19 changes: 19 additions & 0 deletions
19
tests/integration/nodejs/esm-ts-specifier-resolution-node/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "esm-ts-specifier-resolution-node", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/node": "^17.0.5" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"dependencies": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
}, | ||
"resolutions": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/integration/nodejs/esm-ts-specifier-resolution-node/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: esm-ts | ||
runtime: | ||
name: nodejs | ||
options: | ||
# See https://github.com/TypeStrong/ts-node/issues/1007 | ||
nodeargs: "--loader ts-node/esm --no-warnings" | ||
description: Use ECMAScript modules for a TS program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
import * as fs from "fs"; | ||
import { x } from "./other.js"; // this is the "by design" way to do this, even in TS | ||
|
||
// Use top-level await | ||
await new Promise(r => setTimeout(r, 2000)); | ||
|
||
export const res = fs.readFileSync("Pulumi.yaml").toString(); | ||
export const otherx = x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "esm-ts", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/node": "^17.0.5" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"dependencies": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
}, | ||
"resolutions": { | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} | ||
|