@nx/js 16.5.2 → 16.5.3
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/package.json +5 -5
- package/src/executors/node/node.impl.js +83 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "16.5.
|
|
3
|
+
"version": "16.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.15.0",
|
|
40
40
|
"@babel/preset-typescript": "^7.15.0",
|
|
41
41
|
"@babel/runtime": "^7.14.8",
|
|
42
|
-
"@nrwl/js": "16.5.
|
|
43
|
-
"@nx/devkit": "16.5.
|
|
44
|
-
"@nx/workspace": "16.5.
|
|
42
|
+
"@nrwl/js": "16.5.3",
|
|
43
|
+
"@nx/devkit": "16.5.3",
|
|
44
|
+
"@nx/workspace": "16.5.3",
|
|
45
45
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
71
|
"types": "./src/index.d.ts",
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "e886dc76e203b05908b1a1b8872dee834cc4d2c8"
|
|
73
73
|
}
|
|
@@ -32,6 +32,11 @@ function nodeExecutor(options, context) {
|
|
|
32
32
|
throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
|
|
33
33
|
}
|
|
34
34
|
const buildTargetExecutor = (_c = project.data.targets[buildTarget.target]) === null || _c === void 0 ? void 0 : _c.executor;
|
|
35
|
+
if (buildTargetExecutor === 'nx:run-commands' ||
|
|
36
|
+
buildTargetExecutor === '@nrwl/workspace:run-commands') {
|
|
37
|
+
// Run commands does not emit build event, so we have to switch to run entire build through Nx CLI.
|
|
38
|
+
options.runBuildTargetDependencies = true;
|
|
39
|
+
}
|
|
35
40
|
const buildOptions = Object.assign(Object.assign({}, (0, devkit_1.readTargetOptions)(buildTarget, context)), options.buildTargetOptions);
|
|
36
41
|
if (options.waitUntilTargets && options.waitUntilTargets.length > 0) {
|
|
37
42
|
const results = yield tslib_1.__await(runWaitUntilTargets(options, context));
|
|
@@ -44,8 +49,9 @@ function nodeExecutor(options, context) {
|
|
|
44
49
|
// Re-map buildable workspace projects to their output directory.
|
|
45
50
|
const mappings = calculateResolveMappings(context, options);
|
|
46
51
|
const fileToRun = getFileToRun(context, project, buildOptions, buildTargetExecutor);
|
|
47
|
-
|
|
52
|
+
let additionalExitHandler = null;
|
|
48
53
|
let currentTask = null;
|
|
54
|
+
const tasks = [];
|
|
49
55
|
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ done, next, error }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
56
|
var _e;
|
|
51
57
|
const processQueue = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -58,59 +64,22 @@ function nodeExecutor(options, context) {
|
|
|
58
64
|
yield task.start();
|
|
59
65
|
});
|
|
60
66
|
const debouncedProcessQueue = debounce(processQueue, (_e = options.debounce) !== null && _e !== void 0 ? _e : 1000);
|
|
61
|
-
const addToQueue = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const addToQueue = (childProcess, buildResult) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
62
68
|
const task = {
|
|
63
69
|
id: (0, crypto_1.randomUUID)(),
|
|
64
70
|
killed: false,
|
|
65
|
-
childProcess
|
|
71
|
+
childProcess,
|
|
66
72
|
promise: null,
|
|
67
73
|
start: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
if (options.runBuildTargetDependencies) {
|
|
69
|
-
// If task dependencies are to be run, then we need to run through CLI since `runExecutor` doesn't support it.
|
|
70
|
-
task.promise = new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
task.childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
|
|
72
|
-
'run',
|
|
73
|
-
`${context.projectName}:${buildTarget.target}${buildTarget.configuration
|
|
74
|
-
? `:${buildTarget.configuration}`
|
|
75
|
-
: ''}`,
|
|
76
|
-
], {
|
|
77
|
-
cwd: context.root,
|
|
78
|
-
stdio: 'inherit',
|
|
79
|
-
});
|
|
80
|
-
task.childProcess.once('exit', (code) => {
|
|
81
|
-
if (code === 0)
|
|
82
|
-
resolve();
|
|
83
|
-
else
|
|
84
|
-
reject();
|
|
85
|
-
});
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const output = yield (0, devkit_1.runExecutor)(buildTarget, Object.assign(Object.assign({}, options.buildTargetOptions), { watch: false }), context);
|
|
90
|
-
task.promise = new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
var _g;
|
|
92
|
-
let error = false;
|
|
93
|
-
let event;
|
|
94
|
-
do {
|
|
95
|
-
event = yield output.next();
|
|
96
|
-
if (((_g = event.value) === null || _g === void 0 ? void 0 : _g.success) === false) {
|
|
97
|
-
error = true;
|
|
98
|
-
}
|
|
99
|
-
} while (!event.done);
|
|
100
|
-
if (error)
|
|
101
|
-
reject();
|
|
102
|
-
else
|
|
103
|
-
resolve();
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
74
|
// Wait for build to finish.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
catch (_f) {
|
|
75
|
+
const result = yield buildResult;
|
|
76
|
+
if (!result.success) {
|
|
111
77
|
// If in watch-mode, don't throw or else the process exits.
|
|
112
78
|
if (options.watch) {
|
|
113
|
-
|
|
79
|
+
if (!task.killed) {
|
|
80
|
+
// Only log build error if task was not killed by a new change.
|
|
81
|
+
devkit_1.logger.error(`Build failed, waiting for changes to restart...`);
|
|
82
|
+
}
|
|
114
83
|
return;
|
|
115
84
|
}
|
|
116
85
|
else {
|
|
@@ -160,55 +129,88 @@ function nodeExecutor(options, context) {
|
|
|
160
129
|
try {
|
|
161
130
|
yield task.promise;
|
|
162
131
|
}
|
|
163
|
-
catch (
|
|
132
|
+
catch (_f) {
|
|
164
133
|
// Doesn't matter if task fails, we just need to wait until it finishes.
|
|
165
134
|
}
|
|
166
135
|
}),
|
|
167
136
|
};
|
|
168
137
|
tasks.push(task);
|
|
169
138
|
});
|
|
170
|
-
if (options.
|
|
171
|
-
|
|
139
|
+
if (options.runBuildTargetDependencies) {
|
|
140
|
+
// If a all dependencies need to be rebuild on changes, then register with watcher
|
|
141
|
+
// and run through CLI, otherwise only the current project will rebuild.
|
|
142
|
+
const runBuild = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
let childProcess = null;
|
|
144
|
+
const whenReady = new Promise((resolve) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
|
|
146
|
+
'run',
|
|
147
|
+
`${context.projectName}:${buildTarget.target}${buildTarget.configuration ? `:${buildTarget.configuration}` : ''}`,
|
|
148
|
+
], {
|
|
149
|
+
cwd: context.root,
|
|
150
|
+
stdio: 'inherit',
|
|
151
|
+
});
|
|
152
|
+
childProcess.once('exit', (code) => {
|
|
153
|
+
if (code === 0)
|
|
154
|
+
resolve({ success: true });
|
|
155
|
+
// If process is killed due to current task being killed, then resolve with success.
|
|
156
|
+
else
|
|
157
|
+
resolve({ success: !!(currentTask === null || currentTask === void 0 ? void 0 : currentTask.killed) });
|
|
158
|
+
});
|
|
159
|
+
}));
|
|
160
|
+
yield addToQueue(childProcess, whenReady);
|
|
161
|
+
yield debouncedProcessQueue();
|
|
162
|
+
});
|
|
163
|
+
additionalExitHandler = yield client_1.daemonClient.registerFileWatcher({
|
|
172
164
|
watchProjects: [context.projectName],
|
|
173
165
|
includeDependentProjects: true,
|
|
174
166
|
}, (err, data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
var
|
|
167
|
+
var _g;
|
|
176
168
|
if (err === 'closed') {
|
|
177
169
|
devkit_1.logger.error(`Watch error: Daemon closed the connection`);
|
|
178
170
|
process.exit(1);
|
|
179
171
|
}
|
|
180
172
|
else if (err) {
|
|
181
|
-
devkit_1.logger.error(`Watch error: ${(
|
|
173
|
+
devkit_1.logger.error(`Watch error: ${(_g = err === null || err === void 0 ? void 0 : err.message) !== null && _g !== void 0 ? _g : 'Unknown'}`);
|
|
182
174
|
}
|
|
183
175
|
else {
|
|
184
176
|
devkit_1.logger.info(`NX File change detected. Restarting...`);
|
|
185
|
-
yield
|
|
186
|
-
yield debouncedProcessQueue();
|
|
177
|
+
yield runBuild();
|
|
187
178
|
}
|
|
188
179
|
}));
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
yield runBuild(); // run first build
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// Otherwise, run the build executor, which will not run task dependencies.
|
|
184
|
+
// This is mostly fine for bundlers like webpack that should already watch for dependency libs.
|
|
185
|
+
// For tsc/swc or custom build commands, consider using `runBuildTargetDependencies` instead.
|
|
186
|
+
const output = yield (0, devkit_1.runExecutor)(buildTarget, Object.assign(Object.assign({}, options.buildTargetOptions), { watch: options.watch }), context);
|
|
187
|
+
while (true) {
|
|
188
|
+
const event = yield output.next();
|
|
189
|
+
yield addToQueue(null, Promise.resolve(event.value));
|
|
190
|
+
yield debouncedProcessQueue();
|
|
191
|
+
if (event.done || !options.watch) {
|
|
192
|
+
break;
|
|
192
193
|
}
|
|
193
|
-
}
|
|
194
|
-
process.on('SIGTERM', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
stopWatch();
|
|
196
|
-
stopAllTasks('SIGTERM');
|
|
197
|
-
process.exit(128 + 15);
|
|
198
|
-
}));
|
|
199
|
-
process.on('SIGINT', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
stopWatch();
|
|
201
|
-
stopAllTasks('SIGINT');
|
|
202
|
-
process.exit(128 + 2);
|
|
203
|
-
}));
|
|
204
|
-
process.on('SIGHUP', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
stopWatch();
|
|
206
|
-
stopAllTasks('SIGHUP');
|
|
207
|
-
process.exit(128 + 1);
|
|
208
|
-
}));
|
|
194
|
+
}
|
|
209
195
|
}
|
|
210
|
-
|
|
211
|
-
|
|
196
|
+
const stopAllTasks = (signal = 'SIGTERM') => {
|
|
197
|
+
additionalExitHandler === null || additionalExitHandler === void 0 ? void 0 : additionalExitHandler();
|
|
198
|
+
for (const task of tasks) {
|
|
199
|
+
task.stop(signal);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
process.on('SIGTERM', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
stopAllTasks('SIGTERM');
|
|
204
|
+
process.exit(128 + 15);
|
|
205
|
+
}));
|
|
206
|
+
process.on('SIGINT', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
stopAllTasks('SIGINT');
|
|
208
|
+
process.exit(128 + 2);
|
|
209
|
+
}));
|
|
210
|
+
process.on('SIGHUP', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
stopAllTasks('SIGHUP');
|
|
212
|
+
process.exit(128 + 1);
|
|
213
|
+
}));
|
|
212
214
|
})))));
|
|
213
215
|
});
|
|
214
216
|
}
|
|
@@ -251,6 +253,13 @@ function runWaitUntilTargets(options, context) {
|
|
|
251
253
|
})));
|
|
252
254
|
}
|
|
253
255
|
function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
|
|
256
|
+
// If using run-commands or another custom executor, then user should set
|
|
257
|
+
// outputFileName, but we can try the default value that we use.
|
|
258
|
+
if (!(buildOptions === null || buildOptions === void 0 ? void 0 : buildOptions.outputPath) && !(buildOptions === null || buildOptions === void 0 ? void 0 : buildOptions.outputFileName)) {
|
|
259
|
+
const fallbackFile = path.join('dist', project.data.root, 'main.js');
|
|
260
|
+
devkit_1.logger.warn(`Build option ${chalk.bold('outputFileName')} not set for ${chalk.bold(project.name)}. Using fallback value of ${chalk.bold(fallbackFile)}.`);
|
|
261
|
+
return (0, path_1.join)(context.root, fallbackFile);
|
|
262
|
+
}
|
|
254
263
|
let outputFileName = buildOptions.outputFileName;
|
|
255
264
|
if (!outputFileName) {
|
|
256
265
|
const fileName = `${path.parse(buildOptions.main).name}.js`;
|