@nx/js 16.5.1 → 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
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`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ProjectGraph, type ProjectGraphProjectNode, type ProjectFileMap } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Finds all npm dependencies and their expected versions for a given project.
|
|
4
|
+
*/
|
|
5
|
+
export declare function findNpmDependencies(workspaceRoot: string, sourceProject: ProjectGraphProjectNode, projectGraph: ProjectGraph, projectFileMap: ProjectFileMap, buildTarget: string, options?: {
|
|
6
|
+
includeTransitiveDependencies?: boolean;
|
|
7
|
+
}): Record<string, string>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findNpmDependencies = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const file_utils_1 = require("nx/src/project-graph/file-utils");
|
|
6
|
+
const task_hasher_1 = require("nx/src/hasher/task-hasher");
|
|
7
|
+
const devkit_1 = require("@nx/devkit");
|
|
8
|
+
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
9
|
+
const project_graph_1 = require("nx/src/config/project-graph");
|
|
10
|
+
const ts_config_1 = require("./typescript/ts-config");
|
|
11
|
+
/**
|
|
12
|
+
* Finds all npm dependencies and their expected versions for a given project.
|
|
13
|
+
*/
|
|
14
|
+
function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, options = {}) {
|
|
15
|
+
let seen = null;
|
|
16
|
+
if (options.includeTransitiveDependencies) {
|
|
17
|
+
seen = new Set();
|
|
18
|
+
}
|
|
19
|
+
const results = {};
|
|
20
|
+
function collectAll(currentProject, collectedDeps) {
|
|
21
|
+
if (seen === null || seen === void 0 ? void 0 : seen.has(currentProject.name))
|
|
22
|
+
return;
|
|
23
|
+
collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, collectedDeps);
|
|
24
|
+
collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
|
|
25
|
+
if (options.includeTransitiveDependencies) {
|
|
26
|
+
const projectDeps = projectGraph.dependencies[currentProject.name];
|
|
27
|
+
for (const dep of projectDeps) {
|
|
28
|
+
const projectDep = projectGraph.nodes[dep.target];
|
|
29
|
+
if (projectDep)
|
|
30
|
+
collectAll(projectDep, collectedDeps);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
collectAll(sourceProject, results);
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
exports.findNpmDependencies = findNpmDependencies;
|
|
38
|
+
// Keep track of workspace libs we already read package.json for so we don't read from disk again.
|
|
39
|
+
const seenWorkspaceDeps = {};
|
|
40
|
+
function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, npmDeps) {
|
|
41
|
+
const rawFiles = projectFileMap[sourceProject.name];
|
|
42
|
+
if (!rawFiles)
|
|
43
|
+
return;
|
|
44
|
+
// Cannot read inputs if the target does not exist on the project.
|
|
45
|
+
if (!sourceProject.data.targets[buildTarget])
|
|
46
|
+
return;
|
|
47
|
+
const inputs = (0, task_hasher_1.getTargetInputs)((0, file_utils_1.readNxJson)(), sourceProject, buildTarget).selfInputs;
|
|
48
|
+
const files = (0, task_hasher_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
|
|
49
|
+
for (const fileData of files) {
|
|
50
|
+
if (!fileData.deps ||
|
|
51
|
+
fileData.file ===
|
|
52
|
+
(0, devkit_1.joinPathFragments)(sourceProject.data.root, 'package.json')) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (const dep of fileData.deps) {
|
|
56
|
+
const target = (0, project_graph_1.fileDataDepTarget)(dep);
|
|
57
|
+
// If the node is external, then read package info from `data`.
|
|
58
|
+
const externalDep = projectGraph.externalNodes[target];
|
|
59
|
+
if ((externalDep === null || externalDep === void 0 ? void 0 : externalDep.type) === 'npm') {
|
|
60
|
+
npmDeps[externalDep.data.packageName] = externalDep.data.version;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// If node is internal, then try reading package info from `package.json` (which must exist for this to work).
|
|
64
|
+
const workspaceDep = projectGraph.nodes[target];
|
|
65
|
+
if (!workspaceDep)
|
|
66
|
+
continue;
|
|
67
|
+
const cached = seenWorkspaceDeps[workspaceDep.name];
|
|
68
|
+
if (cached) {
|
|
69
|
+
npmDeps[cached.name] = cached.version;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const packageJson = readPackageJson(workspaceDep, workspaceRoot);
|
|
73
|
+
if (packageJson) {
|
|
74
|
+
// This is a workspace lib so we can't reliably read in a specific version since it depends on how the workspace is set up.
|
|
75
|
+
// ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
|
|
76
|
+
npmDeps[packageJson.name] = '*';
|
|
77
|
+
seenWorkspaceDeps[workspaceDep.name] = {
|
|
78
|
+
name: packageJson.name,
|
|
79
|
+
version: '*',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function readPackageJson(project, workspaceRoot) {
|
|
87
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, project.data.root, 'package.json');
|
|
88
|
+
if ((0, fileutils_1.fileExists)(packageJsonPath))
|
|
89
|
+
return (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, npmDeps) {
|
|
93
|
+
var _a, _b, _c, _d;
|
|
94
|
+
const target = sourceProject.data.targets[buildTarget];
|
|
95
|
+
if (!target)
|
|
96
|
+
return;
|
|
97
|
+
if (target.executor === '@nx/js:tsc' && ((_a = target.options) === null || _a === void 0 ? void 0 : _a.tsConfig)) {
|
|
98
|
+
const tsConfig = (0, ts_config_1.readTsConfig)((0, path_1.join)(workspaceRoot, target.options.tsConfig));
|
|
99
|
+
if (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.options['importHelpers']) {
|
|
100
|
+
npmDeps['tslib'] = (_b = projectGraph.externalNodes['npm:tslib']) === null || _b === void 0 ? void 0 : _b.data.version;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (target.executor === '@nx/js:swc') {
|
|
104
|
+
const swcConfigPath = target.options.swcrc
|
|
105
|
+
? (0, path_1.join)(workspaceRoot, target.options.swcrc)
|
|
106
|
+
: (0, path_1.join)(workspaceRoot, sourceProject.data.root, '.swcrc');
|
|
107
|
+
const swcConfig = (0, fileutils_1.fileExists)(swcConfigPath)
|
|
108
|
+
? (0, devkit_1.readJsonFile)(swcConfigPath)
|
|
109
|
+
: {};
|
|
110
|
+
if ((_c = swcConfig === null || swcConfig === void 0 ? void 0 : swcConfig.jsc) === null || _c === void 0 ? void 0 : _c.externalHelpers) {
|
|
111
|
+
npmDeps['@swc/helpers'] =
|
|
112
|
+
(_d = projectGraph.externalNodes['npm:@swc/helpers']) === null || _d === void 0 ? void 0 : _d.data.version;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|