@pulumi/pulumi 3.163.0-alpha.xc33c68d → 3.163.0-alpha.xe7c1e4f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/automation/cmd.js +92 -111
- package/automation/cmd.js.map +1 -1
- package/automation/localWorkspace.js +383 -476
- package/automation/localWorkspace.js.map +1 -1
- package/automation/remoteWorkspace.js +38 -55
- package/automation/remoteWorkspace.js.map +1 -1
- package/automation/server.js +6 -16
- package/automation/server.js.map +1 -1
- package/automation/stack.js +537 -608
- package/automation/stack.js.map +1 -1
- package/cmd/dynamic-provider/index.js +204 -235
- package/cmd/dynamic-provider/index.js.map +1 -1
- package/cmd/run/error.js +3 -3
- package/cmd/run/error.js.map +1 -1
- package/cmd/run/run.js +322 -336
- package/cmd/run/run.js.map +1 -1
- package/cmd/run/tracing.js +1 -2
- package/cmd/run/tracing.js.map +1 -1
- package/cmd/run-plugin/run.js +13 -17
- package/cmd/run-plugin/run.js.map +1 -1
- package/cmd/run-policy-pack/run.js +12 -16
- package/cmd/run-policy-pack/run.js.map +1 -1
- package/output.js +61 -78
- package/output.js.map +1 -1
- package/package.json +1 -1
- package/provider/experimental/analyzer.js +43 -46
- package/provider/experimental/analyzer.js.map +1 -1
- package/provider/experimental/provider.js +22 -36
- package/provider/experimental/provider.js.map +1 -1
- package/provider/server.js +359 -397
- package/provider/server.js.map +1 -1
- package/resource.js +29 -41
- package/resource.js.map +1 -1
- package/runtime/asyncIterableUtil.js +6 -17
- package/runtime/asyncIterableUtil.js.map +1 -1
- package/runtime/callbacks.js +254 -269
- package/runtime/callbacks.js.map +1 -1
- package/runtime/closure/codePaths.js +117 -135
- package/runtime/closure/codePaths.js.map +1 -1
- package/runtime/closure/createClosure.js +807 -871
- package/runtime/closure/createClosure.js.map +1 -1
- package/runtime/closure/parseFunction.js +2 -3
- package/runtime/closure/parseFunction.js.map +1 -1
- package/runtime/closure/serializeClosure.js +17 -30
- package/runtime/closure/serializeClosure.js.map +1 -1
- package/runtime/closure/v8.js +166 -190
- package/runtime/closure/v8.js.map +1 -1
- package/runtime/closure/v8Hooks.js +19 -34
- package/runtime/closure/v8Hooks.js.map +1 -1
- package/runtime/dependsOn.js +61 -80
- package/runtime/dependsOn.js.map +1 -1
- package/runtime/invoke.js +155 -170
- package/runtime/invoke.js.map +1 -1
- package/runtime/mocks.js +77 -96
- package/runtime/mocks.js.map +1 -1
- package/runtime/resource.js +238 -252
- package/runtime/resource.js.map +1 -1
- package/runtime/rpc.js +193 -215
- package/runtime/rpc.js.map +1 -1
- package/runtime/settings.js +70 -87
- package/runtime/settings.js.map +1 -1
- package/runtime/stack.js +111 -131
- package/runtime/stack.js.map +1 -1
- package/stackReference.js +39 -58
- package/stackReference.js.map +1 -1
- package/tsutils.js +1 -2
- package/tsutils.js.map +1 -1
- package/utils.js +2 -3
- package/utils.js.map +1 -1
- package/version.js +1 -1
package/cmd/run/run.js
CHANGED
|
@@ -12,15 +12,6 @@
|
|
|
12
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
15
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
16
|
if (mod && mod.__esModule) return mod;
|
|
26
17
|
var result = {};
|
|
@@ -58,13 +49,11 @@ const dynamicImport = (0, eval)("u=>import(u)");
|
|
|
58
49
|
* @param program The name of the program given to `run`, i.e. the top level module
|
|
59
50
|
* @param error The error that occured. Must be a module load error.
|
|
60
51
|
*/
|
|
61
|
-
function reportModuleLoadFailure(program, error) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return process.exit(mod.nodeJSProcessExitedAfterLoggingUserActionableMessage);
|
|
67
|
-
});
|
|
52
|
+
async function reportModuleLoadFailure(program, error) {
|
|
53
|
+
await throwOrPrintModuleLoadError(program, error);
|
|
54
|
+
// Note: from this point on, we've printed something to the user telling them about the
|
|
55
|
+
// problem. So we can let our langhost know it doesn't need to report any further issues.
|
|
56
|
+
return process.exit(mod.nodeJSProcessExitedAfterLoggingUserActionableMessage);
|
|
68
57
|
}
|
|
69
58
|
/**
|
|
70
59
|
* @internal
|
|
@@ -74,39 +63,37 @@ function reportModuleLoadFailure(program, error) {
|
|
|
74
63
|
* @param programPath the path to the Pulumi program; this is the project "main" directory,
|
|
75
64
|
* which defaults to the project "root" directory.
|
|
76
65
|
*/
|
|
77
|
-
function npmPackageRootFromProgramPath(programPath) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
cwd: programDirectory,
|
|
96
|
-
});
|
|
97
|
-
if (pkgDir === undefined) {
|
|
98
|
-
log.warn("Could not find a package.json file for the program. Using the Pulumi program directory as the project root.");
|
|
99
|
-
return programDirectory;
|
|
100
|
-
}
|
|
101
|
-
return pkgDir;
|
|
66
|
+
async function npmPackageRootFromProgramPath(programPath) {
|
|
67
|
+
// pkg-dir is an ESM module which we use to find the location of package.json
|
|
68
|
+
// Because it's an ESM module, we cannot import it directly.
|
|
69
|
+
const { packageDirectory } = await dynamicImport("pkg-dir");
|
|
70
|
+
// Check if programPath is a directory. If not, then we
|
|
71
|
+
// look at it's parent dir for the package root.
|
|
72
|
+
let isDirectory = false;
|
|
73
|
+
try {
|
|
74
|
+
const fileStat = await fspromises.lstat(programPath);
|
|
75
|
+
isDirectory = fileStat.isDirectory();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Since an exception was thrown, the program path doesn't exist.
|
|
79
|
+
// Do nothing, because isDirectory is already false.
|
|
80
|
+
}
|
|
81
|
+
const programDirectory = isDirectory ? programPath : path.dirname(programPath);
|
|
82
|
+
const pkgDir = await packageDirectory({
|
|
83
|
+
cwd: programDirectory,
|
|
102
84
|
});
|
|
85
|
+
if (pkgDir === undefined) {
|
|
86
|
+
log.warn("Could not find a package.json file for the program. Using the Pulumi program directory as the project root.");
|
|
87
|
+
return programDirectory;
|
|
88
|
+
}
|
|
89
|
+
return pkgDir;
|
|
103
90
|
}
|
|
104
91
|
function packageObjectFromProjectRoot(projectRoot) {
|
|
105
92
|
const packageJson = path.join(projectRoot, "package.json");
|
|
106
93
|
try {
|
|
107
94
|
return require(packageJson);
|
|
108
95
|
}
|
|
109
|
-
catch
|
|
96
|
+
catch {
|
|
110
97
|
// This is all best-effort so if we can't load the package.json file, that's
|
|
111
98
|
// fine.
|
|
112
99
|
return {};
|
|
@@ -131,338 +118,337 @@ function npmRcFromProjectRoot(projectRoot) {
|
|
|
131
118
|
rcSpan.end();
|
|
132
119
|
return parseResult;
|
|
133
120
|
}
|
|
134
|
-
catch
|
|
121
|
+
catch {
|
|
135
122
|
// .npmrc file exists but we couldn't read or parse it
|
|
136
123
|
// user out of luck here
|
|
137
124
|
rcSpan.end();
|
|
138
125
|
return emptyConfig;
|
|
139
126
|
}
|
|
140
127
|
}
|
|
141
|
-
function throwOrPrintModuleLoadError(program, error) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
128
|
+
async function throwOrPrintModuleLoadError(program, error) {
|
|
129
|
+
// error is guaranteed to be a Node module load error. Node emits a very
|
|
130
|
+
// specific string in its error message for module load errors, which includes
|
|
131
|
+
// the module it was trying to load.
|
|
132
|
+
const errorRegex = /Cannot find module '(.*)'/;
|
|
133
|
+
// If there's no match, who knows what this exception is; it's not something
|
|
134
|
+
// we can provide an intelligent diagnostic for.
|
|
135
|
+
const moduleNameMatches = errorRegex.exec(error.message);
|
|
136
|
+
if (moduleNameMatches === null) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
// Is the module that failed to load exactly the one that this script considered to
|
|
140
|
+
// be the top-level module for this program?
|
|
141
|
+
//
|
|
142
|
+
// We are only interested in producing good diagnostics for top-level module loads,
|
|
143
|
+
// since anything else are probably user code issues.
|
|
144
|
+
const moduleName = moduleNameMatches[1];
|
|
145
|
+
if (moduleName !== program) {
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
// Note: from this point on, we've printed something to the user telling them about the
|
|
149
|
+
// problem. So we can let our langhost know it doesn't need to report any further issues.
|
|
150
|
+
console.error(`We failed to locate the entry point for your program: ${program}`);
|
|
151
|
+
// From here on out, we're going to try to inspect the program we're being asked to run
|
|
152
|
+
// a little to see what sort of details we can glean from it, in the hopes of producing
|
|
153
|
+
// a better error message.
|
|
154
|
+
//
|
|
155
|
+
// The first step of this is trying to slurp up a package.json for this program, if
|
|
156
|
+
// one exists.
|
|
157
|
+
const packageRoot = await npmPackageRootFromProgramPath(program);
|
|
158
|
+
const packageObject = packageObjectFromProjectRoot(packageRoot);
|
|
159
|
+
console.error("Here's what we think went wrong:");
|
|
160
|
+
// The objective here is to emit the best diagnostic we can, starting from the
|
|
161
|
+
// most specific to the least specific.
|
|
162
|
+
const deps = packageObject["dependencies"] || {};
|
|
163
|
+
const devDeps = packageObject["devDependencies"] || {};
|
|
164
|
+
const scripts = packageObject["scripts"] || {};
|
|
165
|
+
const mainProperty = packageObject["main"] || "index.js";
|
|
166
|
+
// Is there a build script associated with this program? It's a little confusing that the
|
|
167
|
+
// Pulumi CLI doesn't run build scripts before running the program so call that out
|
|
168
|
+
// explicitly.
|
|
169
|
+
if ("build" in scripts) {
|
|
170
|
+
const command = scripts["build"];
|
|
171
|
+
console.error(` * Your program looks like it has a build script associated with it ('${command}').\n`);
|
|
172
|
+
console.error("Pulumi does not run build scripts before running your program. " +
|
|
173
|
+
`Please run '${command}', 'yarn build', or 'npm run build' and try again.`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// Not all typescript programs have build scripts. If we think it's a typescript program,
|
|
177
|
+
// tell the user to run tsc.
|
|
178
|
+
if ("typescript" in deps || "typescript" in devDeps) {
|
|
179
|
+
console.error(" * Your program looks like a TypeScript program. Have you run 'tsc'?");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Not all projects are typescript. If there's a main property, check that the file exists.
|
|
183
|
+
if (mainProperty !== undefined && typeof mainProperty === "string") {
|
|
184
|
+
const mainFile = path.join(packageRoot, mainProperty);
|
|
185
|
+
if (!fs.existsSync(mainFile)) {
|
|
186
|
+
console.error(` * Your program's 'main' file (${mainFile}) does not exist.`);
|
|
194
187
|
return;
|
|
195
188
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
console.error(` * Your program's 'main' file (${mainFile}) does not exist.`);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
console.error(" * Pulumi encountered an unexpected error.");
|
|
205
|
-
console.error(` Raw exception message: ${error.message}`);
|
|
206
|
-
return;
|
|
207
|
-
});
|
|
189
|
+
}
|
|
190
|
+
console.error(" * Pulumi encountered an unexpected error.");
|
|
191
|
+
console.error(` Raw exception message: ${error.message}`);
|
|
192
|
+
return;
|
|
208
193
|
}
|
|
209
194
|
function tracingIsEnabled(tracingUrl) {
|
|
210
|
-
var _a;
|
|
211
195
|
if (typeof tracingUrl !== "string") {
|
|
212
196
|
return false;
|
|
213
197
|
}
|
|
214
|
-
const experimental =
|
|
198
|
+
const experimental = process.env["PULUMI_EXPERIMENTAL"] ?? "";
|
|
215
199
|
const nonzeroLength = tracingUrl.length > 0;
|
|
216
200
|
const experimentalEnabled = experimental.length > 0;
|
|
217
201
|
return nonzeroLength && experimentalEnabled;
|
|
218
202
|
}
|
|
219
203
|
/** @internal */
|
|
220
|
-
function run(argv, programStarted, reportLoggedError, isErrorReported) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
204
|
+
async function run(argv, programStarted, reportLoggedError, isErrorReported) {
|
|
205
|
+
const tracingUrl = argv["tracing"];
|
|
206
|
+
// Start tracing. Before exiting, gracefully shutdown tracing, exporting
|
|
207
|
+
// all remaining spans in the batch.
|
|
208
|
+
if (tracingIsEnabled(tracingUrl)) {
|
|
209
|
+
tracing.start(tracingUrl); // safe cast, since tracingIsEnable confirmed the type
|
|
210
|
+
process.on("exit", tracing.stop);
|
|
211
|
+
}
|
|
212
|
+
// Start a new span, which we shutdown at the bottom of this method.
|
|
213
|
+
const span = tracing.newSpan("language-runtime.run");
|
|
214
|
+
// If there is a --pwd directive, switch directories.
|
|
215
|
+
const pwd = argv["pwd"];
|
|
216
|
+
if (pwd) {
|
|
217
|
+
process.chdir(pwd);
|
|
218
|
+
}
|
|
219
|
+
// If this is a typescript project, we'll want to load node-ts.
|
|
220
|
+
const typeScript = process.env["PULUMI_NODEJS_TYPESCRIPT"] === "true";
|
|
221
|
+
// We provide reasonable defaults for many ts options, meaning you don't need to have a tsconfig.json present
|
|
222
|
+
// if you want to use TypeScript with Pulumi. However, ts-node's default behavior is to walk up from the cwd to
|
|
223
|
+
// find a tsconfig.json. For us, it's reasonable to say that the "root" of the project is the cwd,
|
|
224
|
+
// if there's a tsconfig.json file here. Otherwise, just tell ts-node to not load project options at all.
|
|
225
|
+
// This helps with cases like pulumi/pulumi#1772.
|
|
226
|
+
const defaultTsConfigPath = "tsconfig.json";
|
|
227
|
+
const tsConfigPath = process.env["PULUMI_NODEJS_TSCONFIG_PATH"] ?? defaultTsConfigPath;
|
|
228
|
+
const skipProject = !fs.existsSync(tsConfigPath);
|
|
229
|
+
span.setAttribute("typescript-enabled", typeScript);
|
|
230
|
+
if (typeScript) {
|
|
231
|
+
const compilerOptions = tsutils.loadTypeScriptCompilerOptions(tsConfigPath);
|
|
232
|
+
// tanspileOnly controls wether ts-node should do type checking or not.
|
|
233
|
+
// Users might have a separate build step that runs tsc for type
|
|
234
|
+
// checking, and don't want to pay the performance cost of type checking
|
|
235
|
+
// twice. This also enables using swc, which doesn' support type
|
|
236
|
+
// checking, with ts-node.
|
|
237
|
+
//
|
|
238
|
+
// If the `PULUMI_NODEJS_TRANSPILE_ONLY `env variable is set, we use
|
|
239
|
+
// that to determine the value of `transpileOnly.` Otherwise we use the
|
|
240
|
+
// `noCheck `compiler option from the tsconfig. Otherwise we default to
|
|
241
|
+
// ts-node's default, which is to type check.
|
|
242
|
+
let transpileOnly = undefined;
|
|
243
|
+
const transpileOnlyEnv = process.env["PULUMI_NODEJS_TRANSPILE_ONLY"];
|
|
244
|
+
if (transpileOnlyEnv) {
|
|
245
|
+
transpileOnly = transpileOnlyEnv === "true";
|
|
229
246
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const pwd = argv["pwd"];
|
|
234
|
-
if (pwd) {
|
|
235
|
-
process.chdir(pwd);
|
|
247
|
+
else {
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
transpileOnly = compilerOptions.noCheck;
|
|
236
250
|
}
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
transpileOnly,
|
|
274
|
-
// PULUMI_NODEJS_TSCONFIG_PATH might be set to a config file such as "tsconfig.pulumi.yaml" which
|
|
275
|
-
// would not get picked up by tsnode by default, so we explicitly tell tsnode which config file to
|
|
276
|
-
// use (Which might just be ./tsconfig.yaml)
|
|
277
|
-
project: tsConfigPath,
|
|
278
|
-
skipProject: skipProject,
|
|
279
|
-
compilerOptions: Object.assign({ target: "es6", module: "commonjs", moduleResolution: "node", sourceMap: "true" }, compilerOptions),
|
|
280
|
-
});
|
|
251
|
+
const { tsnodeRequire, typescriptRequire } = tsutils.typeScriptRequireStrings();
|
|
252
|
+
const tsn = require(tsnodeRequire);
|
|
253
|
+
tsn.register({
|
|
254
|
+
compiler: typescriptRequire,
|
|
255
|
+
transpileOnly,
|
|
256
|
+
// PULUMI_NODEJS_TSCONFIG_PATH might be set to a config file such as "tsconfig.pulumi.yaml" which
|
|
257
|
+
// would not get picked up by tsnode by default, so we explicitly tell tsnode which config file to
|
|
258
|
+
// use (Which might just be ./tsconfig.yaml)
|
|
259
|
+
project: tsConfigPath,
|
|
260
|
+
skipProject: skipProject,
|
|
261
|
+
compilerOptions: {
|
|
262
|
+
target: "es6",
|
|
263
|
+
module: "commonjs",
|
|
264
|
+
moduleResolution: "node",
|
|
265
|
+
sourceMap: "true",
|
|
266
|
+
...compilerOptions,
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
const hasEntrypoint = argv._[0] !== ".";
|
|
271
|
+
let program = argv._[0];
|
|
272
|
+
if (!path.isAbsolute(program)) {
|
|
273
|
+
// If this isn't an absolute path, make it relative to the working directory.
|
|
274
|
+
program = path.join(process.cwd(), program);
|
|
275
|
+
}
|
|
276
|
+
// Now fake out the process-wide argv, to make the program think it was run normally.
|
|
277
|
+
const programArgs = argv._.slice(1);
|
|
278
|
+
process.argv = [process.argv[0], process.argv[1], ...programArgs];
|
|
279
|
+
// Set up the process uncaught exception, unhandled rejection, and program exit handlers.
|
|
280
|
+
const uncaughtHandler = (err) => {
|
|
281
|
+
// In node, if you throw an error in a chained promise, but the exception is not finally
|
|
282
|
+
// handled, then you can end up getting an unhandledRejection for each exception/promise
|
|
283
|
+
// pair. Because the exception is the same through all of these, we keep track of it and
|
|
284
|
+
// only report it once so the user doesn't get N messages for the same thing.
|
|
285
|
+
if (isErrorReported(err)) {
|
|
286
|
+
return;
|
|
281
287
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
program = path.join(process.cwd(), program);
|
|
288
|
+
// First, log the error.
|
|
289
|
+
if (errors_1.RunError.isInstance(err)) {
|
|
290
|
+
// Always hide the stack for RunErrors.
|
|
291
|
+
log.error(err.message);
|
|
287
292
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// pair. Because the exception is the same through all of these, we keep track of it and
|
|
297
|
-
// only report it once so the user doesn't get N messages for the same thing.
|
|
298
|
-
if (isErrorReported(err)) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
// First, log the error.
|
|
302
|
-
if (errors_1.RunError.isInstance(err)) {
|
|
303
|
-
// Always hide the stack for RunErrors.
|
|
304
|
-
log.error(err.message);
|
|
293
|
+
else if (err.name === "TSError" || err.name === SyntaxError.name) {
|
|
294
|
+
// Hide stack frames as TSError/SyntaxError have messages containing
|
|
295
|
+
// where the error is located
|
|
296
|
+
const errOut = err.stack?.toString() || "";
|
|
297
|
+
let errMsg = err.message;
|
|
298
|
+
const errParts = errOut.split(err.message);
|
|
299
|
+
if (errParts.length === 2) {
|
|
300
|
+
errMsg = errParts[0] + err.message;
|
|
305
301
|
}
|
|
306
|
-
|
|
307
|
-
// Hide stack frames as TSError/SyntaxError have messages containing
|
|
308
|
-
// where the error is located
|
|
309
|
-
const errOut = ((_a = err.stack) === null || _a === void 0 ? void 0 : _a.toString()) || "";
|
|
310
|
-
let errMsg = err.message;
|
|
311
|
-
const errParts = errOut.split(err.message);
|
|
312
|
-
if (errParts.length === 2) {
|
|
313
|
-
errMsg = errParts[0] + err.message;
|
|
314
|
-
}
|
|
315
|
-
log.error(`Running program '${program}' failed with an unhandled exception:
|
|
302
|
+
log.error(`Running program '${program}' failed with an unhandled exception:
|
|
316
303
|
${errMsg}`);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
304
|
+
}
|
|
305
|
+
else if (errors_1.ResourceError.isInstance(err)) {
|
|
306
|
+
// Hide the stack if requested to by the ResourceError creator.
|
|
307
|
+
const message = err.hideStack ? err.message : error_1.defaultErrorMessage(err);
|
|
308
|
+
log.error(message, err.resource);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
log.error(`Running program '${program}' failed with an unhandled exception:
|
|
325
312
|
${error_1.defaultErrorMessage(err)}`);
|
|
326
|
-
}
|
|
327
|
-
span.addEvent(`uncaughtError: ${err}`);
|
|
328
|
-
reportLoggedError(err);
|
|
329
|
-
};
|
|
330
|
-
process.on("uncaughtException", uncaughtHandler);
|
|
331
|
-
// @ts-ignore 'unhandledRejection' will almost always invoke uncaughtHandler with an Error. so
|
|
332
|
-
// just suppress the TS strictness here.
|
|
333
|
-
process.on("unhandledRejection", uncaughtHandler);
|
|
334
|
-
process.on("exit", settings.disconnectSync);
|
|
335
|
-
// Trigger callback to update a sentinel variable tracking
|
|
336
|
-
// whether the program is running.
|
|
337
|
-
programStarted();
|
|
338
|
-
// This needs to occur after `programStarted` to ensure execution of the parent process stops.
|
|
339
|
-
if (skipProject && tsConfigPath !== defaultTsConfigPath) {
|
|
340
|
-
span.addEvent("Missing tsconfig file");
|
|
341
|
-
return new Promise(() => {
|
|
342
|
-
const e = new Error(`tsconfig path was set to ${tsConfigPath} but the file was not found`);
|
|
343
|
-
e.stack = undefined;
|
|
344
|
-
throw e;
|
|
345
|
-
});
|
|
346
313
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
314
|
+
span.addEvent(`uncaughtError: ${err}`);
|
|
315
|
+
reportLoggedError(err);
|
|
316
|
+
};
|
|
317
|
+
process.on("uncaughtException", uncaughtHandler);
|
|
318
|
+
// @ts-ignore 'unhandledRejection' will almost always invoke uncaughtHandler with an Error. so
|
|
319
|
+
// just suppress the TS strictness here.
|
|
320
|
+
process.on("unhandledRejection", uncaughtHandler);
|
|
321
|
+
process.on("exit", settings.disconnectSync);
|
|
322
|
+
// Trigger callback to update a sentinel variable tracking
|
|
323
|
+
// whether the program is running.
|
|
324
|
+
programStarted();
|
|
325
|
+
// This needs to occur after `programStarted` to ensure execution of the parent process stops.
|
|
326
|
+
if (skipProject && tsConfigPath !== defaultTsConfigPath) {
|
|
327
|
+
span.addEvent("Missing tsconfig file");
|
|
328
|
+
return new Promise(() => {
|
|
329
|
+
const e = new Error(`tsconfig path was set to ${tsConfigPath} but the file was not found`);
|
|
330
|
+
e.stack = undefined;
|
|
331
|
+
throw e;
|
|
356
332
|
});
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const main = path.isAbsolute(mainPath) ? url.pathToFileURL(mainPath).href : mainPath;
|
|
389
|
-
// Import the module and capture any module outputs it exported. Finally, await the value we get
|
|
390
|
-
// back. That way, if it is async and throws an exception, we properly capture it here
|
|
391
|
-
// and handle it.
|
|
392
|
-
programExport = yield dynamicImport(main);
|
|
393
|
-
// If there is a default export, use that instead of the named exports (and error if there are both).
|
|
394
|
-
if (Object.getOwnPropertyDescriptor(programExport, "default") !== undefined) {
|
|
395
|
-
if (Object.keys(programExport).length !== 1) {
|
|
396
|
-
throw new Error("expected entrypoint module to have either a default export or named exports but not both");
|
|
397
|
-
}
|
|
398
|
-
programExport = programExport.default;
|
|
399
|
-
}
|
|
333
|
+
}
|
|
334
|
+
const containsTSAndJSModules = async (programPath) => {
|
|
335
|
+
const programStats = await fs.promises.lstat(programPath);
|
|
336
|
+
if (programStats.isDirectory()) {
|
|
337
|
+
const programDirFiles = await fs.promises.readdir(programPath);
|
|
338
|
+
return programDirFiles.includes("index.js") && programDirFiles.includes("index.ts");
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const runProgram = async () => {
|
|
345
|
+
// We run the program inside this context so that it adopts all resources.
|
|
346
|
+
//
|
|
347
|
+
// IDEA: This will miss any resources created on other turns of the event loop. I think that's a fundamental
|
|
348
|
+
// problem with the current Component design though - not sure what else we could do here.
|
|
349
|
+
//
|
|
350
|
+
// Now go ahead and execute the code. The process will remain alive until the message loop empties.
|
|
351
|
+
log.debug(`Running program '${program}' in pwd '${process.cwd()}' w/ args: ${programArgs}`);
|
|
352
|
+
// Create a new span for the execution of the user program.
|
|
353
|
+
const runProgramSpan = tracing.newSpan("language-runtime.runProgram");
|
|
354
|
+
try {
|
|
355
|
+
const packageRoot = await npmPackageRootFromProgramPath(program);
|
|
356
|
+
const packageObject = packageObjectFromProjectRoot(packageRoot);
|
|
357
|
+
let programExport;
|
|
358
|
+
// If there is no entrypoint set in Pulumi.yaml via the main
|
|
359
|
+
// option, look for an entrypoint defined in package.json
|
|
360
|
+
if (!hasEntrypoint && packageObject["main"]) {
|
|
361
|
+
const packageMainPath = path.join(packageRoot, packageObject["main"]);
|
|
362
|
+
if (fs.existsSync(packageMainPath)) {
|
|
363
|
+
program = packageMainPath;
|
|
400
364
|
}
|
|
401
365
|
else {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const programStats = yield fs.promises.lstat(program);
|
|
405
|
-
if (programStats.isDirectory() && !program.endsWith("/")) {
|
|
406
|
-
program = program + "/";
|
|
407
|
-
}
|
|
408
|
-
programExport = require(program);
|
|
366
|
+
log.warn(`Could not find entry point '${packageMainPath}' specified in package.json; ` +
|
|
367
|
+
`using '${program}' instead`);
|
|
409
368
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
`Your current Node version is incompatible to run ${packageRoot}`,
|
|
426
|
-
`Expected version: ${requiredNodeVersion} as found in package.json > engines > node`,
|
|
427
|
-
`Actual Node version: ${currentNodeVersion}`,
|
|
428
|
-
`To fix issue, install a Node version that is compatible with ${requiredNodeVersion}`,
|
|
429
|
-
];
|
|
430
|
-
runProgramSpan.addEvent("Incompatible Node version");
|
|
431
|
-
throw new Error(errorMessage.join("\n"));
|
|
369
|
+
}
|
|
370
|
+
// We use dynamic import instead of require for projects using native ES modules instead of commonjs
|
|
371
|
+
if (packageObject["type"] === "module") {
|
|
372
|
+
// Use the same behavior for loading the main entrypoint as `node <program>`.
|
|
373
|
+
// See https://github.com/nodejs/node/blob/master/lib/internal/modules/run_main.js#L74.
|
|
374
|
+
const mainPath = require("module").Module._findPath(path.resolve(program), null, true) || program;
|
|
375
|
+
const main = path.isAbsolute(mainPath) ? url.pathToFileURL(mainPath).href : mainPath;
|
|
376
|
+
// Import the module and capture any module outputs it exported. Finally, await the value we get
|
|
377
|
+
// back. That way, if it is async and throws an exception, we properly capture it here
|
|
378
|
+
// and handle it.
|
|
379
|
+
programExport = await dynamicImport(main);
|
|
380
|
+
// If there is a default export, use that instead of the named exports (and error if there are both).
|
|
381
|
+
if (Object.getOwnPropertyDescriptor(programExport, "default") !== undefined) {
|
|
382
|
+
if (Object.keys(programExport).length !== 1) {
|
|
383
|
+
throw new Error("expected entrypoint module to have either a default export or named exports but not both");
|
|
432
384
|
}
|
|
385
|
+
programExport = programExport.default;
|
|
433
386
|
}
|
|
434
|
-
// If the exported value was itself a Function, then just execute it. This allows for
|
|
435
|
-
// exported top level async functions that pulumi programs can live in. Finally, await
|
|
436
|
-
// the value we get back. That way, if it is async and throws an exception, we properly
|
|
437
|
-
// capture it here and handle it.
|
|
438
|
-
const invokeResult = programExport instanceof Function ? programExport() : programExport;
|
|
439
|
-
runProgramSpan.end();
|
|
440
|
-
return yield invokeResult;
|
|
441
387
|
}
|
|
442
|
-
|
|
443
|
-
//
|
|
444
|
-
//
|
|
445
|
-
|
|
446
|
-
|
|
388
|
+
else {
|
|
389
|
+
// It's a CommonJS module, so require the module and capture any module outputs it exported.
|
|
390
|
+
// If this is a folder ensure it ends with a "/" so we require the folder, not any adjacent .json file
|
|
391
|
+
const programStats = await fs.promises.lstat(program);
|
|
392
|
+
if (programStats.isDirectory() && !program.endsWith("/")) {
|
|
393
|
+
program = program + "/";
|
|
447
394
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
395
|
+
programExport = require(program);
|
|
396
|
+
}
|
|
397
|
+
if (await containsTSAndJSModules(program)) {
|
|
398
|
+
log.warn("Found a TypeScript project containing an index.js file and no explicit entrypoint in Pulumi.yaml - Pulumi will use index.js");
|
|
399
|
+
}
|
|
400
|
+
// Check compatible engines before running the program:
|
|
401
|
+
const npmRc = npmRcFromProjectRoot(packageRoot);
|
|
402
|
+
if (npmRc["engine-strict"] && packageObject.engines && packageObject.engines.node) {
|
|
403
|
+
// found:
|
|
404
|
+
// - { engines: { node: "<version>" } } in package.json
|
|
405
|
+
// - engine-strict=true in .npmrc
|
|
406
|
+
//
|
|
407
|
+
// Check that current node version satistfies the required version
|
|
408
|
+
const requiredNodeVersion = packageObject.engines.node;
|
|
409
|
+
const currentNodeVersion = process.versions.node;
|
|
410
|
+
if (!semver.satisfies(currentNodeVersion, requiredNodeVersion)) {
|
|
411
|
+
const errorMessage = [
|
|
412
|
+
`Your current Node version is incompatible to run ${packageRoot}`,
|
|
413
|
+
`Expected version: ${requiredNodeVersion} as found in package.json > engines > node`,
|
|
414
|
+
`Actual Node version: ${currentNodeVersion}`,
|
|
415
|
+
`To fix issue, install a Node version that is compatible with ${requiredNodeVersion}`,
|
|
416
|
+
];
|
|
417
|
+
runProgramSpan.addEvent("Incompatible Node version");
|
|
418
|
+
throw new Error(errorMessage.join("\n"));
|
|
453
419
|
}
|
|
420
|
+
}
|
|
421
|
+
// If the exported value was itself a Function, then just execute it. This allows for
|
|
422
|
+
// exported top level async functions that pulumi programs can live in. Finally, await
|
|
423
|
+
// the value we get back. That way, if it is async and throws an exception, we properly
|
|
424
|
+
// capture it here and handle it.
|
|
425
|
+
const invokeResult = programExport instanceof Function ? programExport() : programExport;
|
|
426
|
+
runProgramSpan.end();
|
|
427
|
+
return await invokeResult;
|
|
428
|
+
}
|
|
429
|
+
catch (e) {
|
|
430
|
+
// User JavaScript can throw anything, so if it's not an Error it's definitely
|
|
431
|
+
// not something we want to catch up here.
|
|
432
|
+
if (!(e instanceof Error)) {
|
|
454
433
|
throw e;
|
|
455
434
|
}
|
|
456
|
-
|
|
457
|
-
|
|
435
|
+
// Give a better error message, if we can.
|
|
436
|
+
const errorCode = e.code;
|
|
437
|
+
if (errorCode === "MODULE_NOT_FOUND") {
|
|
438
|
+
runProgramSpan.addEvent("Module Load Failure.");
|
|
439
|
+
await reportModuleLoadFailure(program, e);
|
|
458
440
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
441
|
+
throw e;
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
runProgramSpan.end();
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
// Construct a `Stack` resource to represent the outputs of the program.
|
|
448
|
+
const stackOutputs = await stack.runInPulumiStack(runProgram);
|
|
449
|
+
await settings.disconnect();
|
|
450
|
+
span.end();
|
|
451
|
+
return stackOutputs;
|
|
466
452
|
}
|
|
467
453
|
exports.run = run;
|
|
468
454
|
//# sourceMappingURL=run.js.map
|