@nx/js 0.0.0-pr-22179-271588f
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/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +13 -0
- package/babel.js +91 -0
- package/executors.json +32 -0
- package/generators.json +46 -0
- package/migrations.json +159 -0
- package/package.json +76 -0
- package/plugins/jest/local-registry.d.ts +1 -0
- package/plugins/jest/local-registry.js +4 -0
- package/src/executors/node/lib/kill-tree.d.ts +2 -0
- package/src/executors/node/lib/kill-tree.js +114 -0
- package/src/executors/node/node-with-require-overrides.d.ts +7 -0
- package/src/executors/node/node-with-require-overrides.js +21 -0
- package/src/executors/node/node.impl.d.ts +7 -0
- package/src/executors/node/node.impl.js +288 -0
- package/src/executors/node/schema.d.ts +18 -0
- package/src/executors/node/schema.json +92 -0
- package/src/executors/release-publish/format-bytes.d.ts +1 -0
- package/src/executors/release-publish/format-bytes.js +28 -0
- package/src/executors/release-publish/log-tar.d.ts +1 -0
- package/src/executors/release-publish/log-tar.js +68 -0
- package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
- package/src/executors/release-publish/release-publish.impl.js +198 -0
- package/src/executors/release-publish/schema.d.ts +8 -0
- package/src/executors/release-publish/schema.json +26 -0
- package/src/executors/swc/schema.json +154 -0
- package/src/executors/swc/swc.impl.d.ts +10 -0
- package/src/executors/swc/swc.impl.js +149 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
- package/src/executors/tsc/lib/batch/index.d.ts +4 -0
- package/src/executors/tsc/lib/batch/index.js +7 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
- package/src/executors/tsc/lib/batch/types.d.ts +17 -0
- package/src/executors/tsc/lib/batch/types.js +2 -0
- package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
- package/src/executors/tsc/lib/batch/watch.js +56 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
- package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
- package/src/executors/tsc/lib/get-task-options.js +34 -0
- package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
- package/src/executors/tsc/lib/get-tsconfig.js +86 -0
- package/src/executors/tsc/lib/index.d.ts +4 -0
- package/src/executors/tsc/lib/index.js +7 -0
- package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
- package/src/executors/tsc/lib/normalize-options.js +39 -0
- package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
- package/src/executors/tsc/lib/typescript-compilation.js +203 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
- package/src/executors/tsc/schema.json +163 -0
- package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
- package/src/executors/tsc/tsc.batch-impl.js +180 -0
- package/src/executors/tsc/tsc.impl.d.ts +7 -0
- package/src/executors/tsc/tsc.impl.js +97 -0
- package/src/executors/verdaccio/schema.d.ts +7 -0
- package/src/executors/verdaccio/schema.json +35 -0
- package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
- package/src/executors/verdaccio/verdaccio.impl.js +220 -0
- package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
- package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
- package/src/generators/convert-to-swc/schema.d.ts +4 -0
- package/src/generators/convert-to-swc/schema.json +36 -0
- package/src/generators/init/files/__fileName__ +20 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +114 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +36 -0
- package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
- package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
- package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/readme/README.md +19 -0
- package/src/generators/library/library.d.ts +16 -0
- package/src/generators/library/library.js +751 -0
- package/src/generators/library/schema.json +151 -0
- package/src/generators/release-version/release-version.d.ts +5 -0
- package/src/generators/release-version/release-version.js +390 -0
- package/src/generators/release-version/schema.d.ts +1 -0
- package/src/generators/release-version/schema.json +67 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
- package/src/generators/release-version/utils/package.d.ts +12 -0
- package/src/generators/release-version/utils/package.js +34 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
- package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
- package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
- package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
- package/src/generators/release-version/utils/update-lock-file.js +105 -0
- package/src/generators/setup-build/generator.d.ts +4 -0
- package/src/generators/setup-build/generator.js +142 -0
- package/src/generators/setup-build/schema.d.ts +7 -0
- package/src/generators/setup-build/schema.json +42 -0
- package/src/generators/setup-verdaccio/files/config.yml +28 -0
- package/src/generators/setup-verdaccio/generator.d.ts +4 -0
- package/src/generators/setup-verdaccio/generator.js +56 -0
- package/src/generators/setup-verdaccio/schema.d.ts +3 -0
- package/src/generators/setup-verdaccio/schema.json +16 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +28 -0
- package/src/internal.d.ts +4 -0
- package/src/internal.js +15 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
- package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
- package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
- package/src/plugins/jest/start-local-registry.d.ts +12 -0
- package/src/plugins/jest/start-local-registry.js +63 -0
- package/src/plugins/rollup/type-definitions.d.ts +8 -0
- package/src/plugins/rollup/type-definitions.js +48 -0
- package/src/utils/add-babel-inputs.d.ts +3 -0
- package/src/utils/add-babel-inputs.js +23 -0
- package/src/utils/add-local-registry-scripts.d.ts +5 -0
- package/src/utils/add-local-registry-scripts.js +77 -0
- package/src/utils/assets/assets.d.ts +10 -0
- package/src/utils/assets/assets.js +36 -0
- package/src/utils/assets/copy-assets-handler.d.ts +32 -0
- package/src/utils/assets/copy-assets-handler.js +154 -0
- package/src/utils/assets/index.d.ts +16 -0
- package/src/utils/assets/index.js +27 -0
- package/src/utils/buildable-libs-utils.d.ts +43 -0
- package/src/utils/buildable-libs-utils.js +375 -0
- package/src/utils/check-dependencies.d.ts +8 -0
- package/src/utils/check-dependencies.js +23 -0
- package/src/utils/code-frames/highlight.d.ts +1 -0
- package/src/utils/code-frames/highlight.js +86 -0
- package/src/utils/code-frames/identifiers.d.ts +5 -0
- package/src/utils/code-frames/identifiers.js +52 -0
- package/src/utils/compiler-helper-dependency.d.ts +18 -0
- package/src/utils/compiler-helper-dependency.js +120 -0
- package/src/utils/find-npm-dependencies.d.ts +9 -0
- package/src/utils/find-npm-dependencies.js +140 -0
- package/src/utils/generate-globs.d.ts +6 -0
- package/src/utils/generate-globs.js +80 -0
- package/src/utils/get-import-path.d.ts +5 -0
- package/src/utils/get-import-path.js +14 -0
- package/src/utils/get-main-file-dir.d.ts +1 -0
- package/src/utils/get-main-file-dir.js +11 -0
- package/src/utils/inline.d.ts +19 -0
- package/src/utils/inline.js +210 -0
- package/src/utils/package-json/create-entry-points.d.ts +1 -0
- package/src/utils/package-json/create-entry-points.js +23 -0
- package/src/utils/package-json/get-npm-scope.d.ts +5 -0
- package/src/utils/package-json/get-npm-scope.js +16 -0
- package/src/utils/package-json/index.d.ts +13 -0
- package/src/utils/package-json/index.js +30 -0
- package/src/utils/package-json/update-package-json.d.ts +30 -0
- package/src/utils/package-json/update-package-json.js +179 -0
- package/src/utils/prettier.d.ts +6 -0
- package/src/utils/prettier.js +34 -0
- package/src/utils/schema.d.ts +87 -0
- package/src/utils/swc/add-swc-config.d.ts +3 -0
- package/src/utils/swc/add-swc-config.js +41 -0
- package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
- package/src/utils/swc/add-swc-dependencies.js +18 -0
- package/src/utils/swc/compile-swc.d.ts +13 -0
- package/src/utils/swc/compile-swc.js +160 -0
- package/src/utils/swc/get-swcrc-path.d.ts +5 -0
- package/src/utils/swc/get-swcrc-path.js +15 -0
- package/src/utils/swc/inline.d.ts +2 -0
- package/src/utils/swc/inline.js +11 -0
- package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
- package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
- package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
- package/src/utils/typescript/add-tslib-dependencies.js +11 -0
- package/src/utils/typescript/ast-utils.d.ts +32 -0
- package/src/utils/typescript/ast-utils.js +266 -0
- package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
- package/src/utils/typescript/compile-typescript-files.js +43 -0
- package/src/utils/typescript/create-ts-config.d.ts +18 -0
- package/src/utils/typescript/create-ts-config.js +48 -0
- package/src/utils/typescript/ensure-typescript.d.ts +1 -0
- package/src/utils/typescript/ensure-typescript.js +9 -0
- package/src/utils/typescript/get-source-nodes.d.ts +2 -0
- package/src/utils/typescript/get-source-nodes.js +18 -0
- package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
- package/src/utils/typescript/load-ts-transformers.js +62 -0
- package/src/utils/typescript/print-diagnostics.d.ts +1 -0
- package/src/utils/typescript/print-diagnostics.js +18 -0
- package/src/utils/typescript/run-type-check.d.ts +32 -0
- package/src/utils/typescript/run-type-check.js +128 -0
- package/src/utils/typescript/ts-config.d.ts +9 -0
- package/src/utils/typescript/ts-config.js +85 -0
- package/src/utils/typescript/tsnode-register.d.ts +1 -0
- package/src/utils/typescript/tsnode-register.js +24 -0
- package/src/utils/typescript/types.d.ts +18 -0
- package/src/utils/typescript/types.js +2 -0
- package/src/utils/versions.d.ts +17 -0
- package/src/utils/versions.js +21 -0
- package/src/utils/watch-for-single-file-changes.d.ts +1 -0
- package/src/utils/watch-for-single-file-changes.js +22 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { NodeExecutorOptions } from './schema';
|
|
3
|
+
export declare function nodeExecutor(options: NodeExecutorOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
options?: Record<string, any>;
|
|
6
|
+
}, void, undefined>;
|
|
7
|
+
export default nodeExecutor;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nodeExecutor = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
8
|
+
const client_1 = require("nx/src/daemon/client/client");
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const buildable_libs_utils_1 = require("../../utils/buildable-libs-utils");
|
|
13
|
+
const kill_tree_1 = require("./lib/kill-tree");
|
|
14
|
+
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
15
|
+
const get_main_file_dir_1 = require("../../utils/get-main-file-dir");
|
|
16
|
+
function debounce(fn, wait) {
|
|
17
|
+
let timeoutId;
|
|
18
|
+
return () => {
|
|
19
|
+
clearTimeout(timeoutId);
|
|
20
|
+
timeoutId = setTimeout(fn, wait);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function* nodeExecutor(options, context) {
|
|
24
|
+
process.env.NODE_ENV ??= context?.configurationName ?? 'development';
|
|
25
|
+
const project = context.projectGraph.nodes[context.projectName];
|
|
26
|
+
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
27
|
+
if (!project.data.targets[buildTarget.target]) {
|
|
28
|
+
throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
|
|
29
|
+
}
|
|
30
|
+
const buildTargetExecutor = project.data.targets[buildTarget.target]?.executor;
|
|
31
|
+
if (buildTargetExecutor === 'nx:run-commands' ||
|
|
32
|
+
buildTargetExecutor === '@nrwl/workspace:run-commands') {
|
|
33
|
+
// Run commands does not emit build event, so we have to switch to run entire build through Nx CLI.
|
|
34
|
+
options.runBuildTargetDependencies = true;
|
|
35
|
+
}
|
|
36
|
+
const buildOptions = {
|
|
37
|
+
...(0, devkit_1.readTargetOptions)(buildTarget, context),
|
|
38
|
+
...options.buildTargetOptions,
|
|
39
|
+
};
|
|
40
|
+
if (options.waitUntilTargets && options.waitUntilTargets.length > 0) {
|
|
41
|
+
const results = await runWaitUntilTargets(options, context);
|
|
42
|
+
for (const [i, result] of results.entries()) {
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
throw new Error(`Wait until target failed: ${options.waitUntilTargets[i]}.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Re-map buildable workspace projects to their output directory.
|
|
49
|
+
const mappings = calculateResolveMappings(context, options);
|
|
50
|
+
const fileToRun = getFileToRun(context, project, buildOptions, buildTargetExecutor);
|
|
51
|
+
let additionalExitHandler = null;
|
|
52
|
+
let currentTask = null;
|
|
53
|
+
const tasks = [];
|
|
54
|
+
yield* (0, async_iterable_1.createAsyncIterable)(async ({ done, next, error }) => {
|
|
55
|
+
const processQueue = async () => {
|
|
56
|
+
if (tasks.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
const previousTask = currentTask;
|
|
59
|
+
const task = tasks.shift();
|
|
60
|
+
currentTask = task;
|
|
61
|
+
await previousTask?.stop('SIGTERM');
|
|
62
|
+
await task.start();
|
|
63
|
+
};
|
|
64
|
+
const debouncedProcessQueue = debounce(processQueue, options.debounce ?? 1000);
|
|
65
|
+
const addToQueue = async (childProcess, buildResult) => {
|
|
66
|
+
const task = {
|
|
67
|
+
id: (0, crypto_1.randomUUID)(),
|
|
68
|
+
killed: false,
|
|
69
|
+
childProcess,
|
|
70
|
+
promise: null,
|
|
71
|
+
start: async () => {
|
|
72
|
+
// Wait for build to finish.
|
|
73
|
+
const result = await buildResult;
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
// If in watch-mode, don't throw or else the process exits.
|
|
76
|
+
if (options.watch) {
|
|
77
|
+
if (!task.killed) {
|
|
78
|
+
// Only log build error if task was not killed by a new change.
|
|
79
|
+
devkit_1.logger.error(`Build failed, waiting for changes to restart...`);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error(`Build failed. See above for errors.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Before running the program, check if the task has been killed (by a new change during watch).
|
|
88
|
+
if (task.killed)
|
|
89
|
+
return;
|
|
90
|
+
// Run the program
|
|
91
|
+
task.promise = new Promise((resolve, reject) => {
|
|
92
|
+
task.childProcess = (0, child_process_1.fork)((0, devkit_1.joinPathFragments)(__dirname, 'node-with-require-overrides'), options.args ?? [], {
|
|
93
|
+
execArgv: getExecArgv(options),
|
|
94
|
+
stdio: [0, 1, 'pipe', 'ipc'],
|
|
95
|
+
env: {
|
|
96
|
+
...process.env,
|
|
97
|
+
NX_FILE_TO_RUN: fileToRunCorrectPath(fileToRun),
|
|
98
|
+
NX_MAPPINGS: JSON.stringify(mappings),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const handleStdErr = (data) => {
|
|
102
|
+
// Don't log out error if task is killed and new one has started.
|
|
103
|
+
// This could happen if a new build is triggered while new process is starting, since the operation is not atomic.
|
|
104
|
+
// Log the error in normal mode
|
|
105
|
+
if (!options.watch || !task.killed) {
|
|
106
|
+
devkit_1.logger.error(data.toString());
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
task.childProcess.stderr.on('data', handleStdErr);
|
|
110
|
+
task.childProcess.once('exit', (code) => {
|
|
111
|
+
task.childProcess.off('data', handleStdErr);
|
|
112
|
+
if (options.watch && !task.killed) {
|
|
113
|
+
devkit_1.logger.info(`NX Process exited with code ${code}, waiting for changes to restart...`);
|
|
114
|
+
}
|
|
115
|
+
if (!options.watch)
|
|
116
|
+
done();
|
|
117
|
+
resolve();
|
|
118
|
+
});
|
|
119
|
+
next({ success: true, options: buildOptions });
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
stop: async (signal = 'SIGTERM') => {
|
|
123
|
+
task.killed = true;
|
|
124
|
+
// Request termination and wait for process to finish gracefully.
|
|
125
|
+
// NOTE: `childProcess` may not have been set yet if the task did not have a chance to start.
|
|
126
|
+
// e.g. multiple file change events in a short time (like git checkout).
|
|
127
|
+
if (task.childProcess) {
|
|
128
|
+
await (0, kill_tree_1.killTree)(task.childProcess.pid, signal);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
await task.promise;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Doesn't matter if task fails, we just need to wait until it finishes.
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
tasks.push(task);
|
|
139
|
+
};
|
|
140
|
+
if (options.runBuildTargetDependencies) {
|
|
141
|
+
// If a all dependencies need to be rebuild on changes, then register with watcher
|
|
142
|
+
// and run through CLI, otherwise only the current project will rebuild.
|
|
143
|
+
const runBuild = async () => {
|
|
144
|
+
let childProcess = null;
|
|
145
|
+
const whenReady = new Promise(async (resolve) => {
|
|
146
|
+
childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
|
|
147
|
+
'run',
|
|
148
|
+
`${context.projectName}:${buildTarget.target}${buildTarget.configuration ? `:${buildTarget.configuration}` : ''}`,
|
|
149
|
+
], {
|
|
150
|
+
cwd: context.root,
|
|
151
|
+
stdio: 'inherit',
|
|
152
|
+
});
|
|
153
|
+
childProcess.once('exit', (code) => {
|
|
154
|
+
if (code === 0)
|
|
155
|
+
resolve({ success: true });
|
|
156
|
+
// If process is killed due to current task being killed, then resolve with success.
|
|
157
|
+
else
|
|
158
|
+
resolve({ success: !!currentTask?.killed });
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
await addToQueue(childProcess, whenReady);
|
|
162
|
+
await debouncedProcessQueue();
|
|
163
|
+
};
|
|
164
|
+
additionalExitHandler = await client_1.daemonClient.registerFileWatcher({
|
|
165
|
+
watchProjects: [context.projectName],
|
|
166
|
+
includeDependentProjects: true,
|
|
167
|
+
}, async (err, data) => {
|
|
168
|
+
if (err === 'closed') {
|
|
169
|
+
devkit_1.logger.error(`Watch error: Daemon closed the connection`);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
else if (err) {
|
|
173
|
+
devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
devkit_1.logger.info(`NX File change detected. Restarting...`);
|
|
177
|
+
await runBuild();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
await 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 = await (0, devkit_1.runExecutor)(buildTarget, {
|
|
187
|
+
...options.buildTargetOptions,
|
|
188
|
+
watch: options.watch,
|
|
189
|
+
}, context);
|
|
190
|
+
while (true) {
|
|
191
|
+
const event = await output.next();
|
|
192
|
+
await addToQueue(null, Promise.resolve(event.value));
|
|
193
|
+
await debouncedProcessQueue();
|
|
194
|
+
if (event.done || !options.watch) {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const stopAllTasks = (signal = 'SIGTERM') => {
|
|
200
|
+
additionalExitHandler?.();
|
|
201
|
+
for (const task of tasks) {
|
|
202
|
+
task.stop(signal);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
process.on('SIGTERM', async () => {
|
|
206
|
+
stopAllTasks('SIGTERM');
|
|
207
|
+
process.exit(128 + 15);
|
|
208
|
+
});
|
|
209
|
+
process.on('SIGINT', async () => {
|
|
210
|
+
stopAllTasks('SIGINT');
|
|
211
|
+
process.exit(128 + 2);
|
|
212
|
+
});
|
|
213
|
+
process.on('SIGHUP', async () => {
|
|
214
|
+
stopAllTasks('SIGHUP');
|
|
215
|
+
process.exit(128 + 1);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.nodeExecutor = nodeExecutor;
|
|
220
|
+
function getExecArgv(options) {
|
|
221
|
+
const args = (options.runtimeArgs ??= []);
|
|
222
|
+
args.push('-r', require.resolve('source-map-support/register'));
|
|
223
|
+
if (options.inspect === true) {
|
|
224
|
+
options.inspect = "inspect" /* InspectType.Inspect */;
|
|
225
|
+
}
|
|
226
|
+
if (options.inspect) {
|
|
227
|
+
args.push(`--${options.inspect}=${options.host}:${options.port}`);
|
|
228
|
+
}
|
|
229
|
+
return args;
|
|
230
|
+
}
|
|
231
|
+
function calculateResolveMappings(context, options) {
|
|
232
|
+
const parsed = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
233
|
+
const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, parsed.project, parsed.target, parsed.configuration);
|
|
234
|
+
return dependencies.reduce((m, c) => {
|
|
235
|
+
if (c.node.type !== 'npm' && c.outputs[0] != null) {
|
|
236
|
+
m[c.name] = (0, devkit_1.joinPathFragments)(context.root, c.outputs[0]);
|
|
237
|
+
}
|
|
238
|
+
return m;
|
|
239
|
+
}, {});
|
|
240
|
+
}
|
|
241
|
+
function runWaitUntilTargets(options, context) {
|
|
242
|
+
return Promise.all(options.waitUntilTargets.map(async (waitUntilTarget) => {
|
|
243
|
+
const target = (0, devkit_1.parseTargetString)(waitUntilTarget, context);
|
|
244
|
+
const output = await (0, devkit_1.runExecutor)(target, {}, context);
|
|
245
|
+
return new Promise(async (resolve) => {
|
|
246
|
+
let event = await output.next();
|
|
247
|
+
// Resolve after first event
|
|
248
|
+
resolve(event.value);
|
|
249
|
+
// Continue iterating
|
|
250
|
+
while (!event.done) {
|
|
251
|
+
event = await output.next();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
|
|
257
|
+
// If using run-commands or another custom executor, then user should set
|
|
258
|
+
// outputFileName, but we can try the default value that we use.
|
|
259
|
+
if (!buildOptions?.outputPath && !buildOptions?.outputFileName) {
|
|
260
|
+
const fallbackFile = path.join('dist', project.data.root, 'main.js');
|
|
261
|
+
devkit_1.logger.warn(`Build option ${chalk.bold('outputFileName')} not set for ${chalk.bold(project.name)}. Using fallback value of ${chalk.bold(fallbackFile)}.`);
|
|
262
|
+
return (0, path_1.join)(context.root, fallbackFile);
|
|
263
|
+
}
|
|
264
|
+
let outputFileName = buildOptions.outputFileName;
|
|
265
|
+
if (!outputFileName) {
|
|
266
|
+
const fileName = `${path.parse(buildOptions.main).name}.js`;
|
|
267
|
+
if (buildTargetExecutor === '@nx/js:tsc' ||
|
|
268
|
+
buildTargetExecutor === '@nx/js:swc') {
|
|
269
|
+
outputFileName = path.join((0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(buildOptions.main, project.data.root), fileName);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
outputFileName = fileName;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return (0, path_1.join)(context.root, buildOptions.outputPath, outputFileName);
|
|
276
|
+
}
|
|
277
|
+
function fileToRunCorrectPath(fileToRun) {
|
|
278
|
+
if ((0, fileutils_1.fileExists)(fileToRun))
|
|
279
|
+
return fileToRun;
|
|
280
|
+
const extensionsToTry = ['.cjs', '.mjs', 'cjs.js', '.esm.js'];
|
|
281
|
+
for (const ext of extensionsToTry) {
|
|
282
|
+
const file = fileToRun.replace(/\.js$/, ext);
|
|
283
|
+
if ((0, fileutils_1.fileExists)(file))
|
|
284
|
+
return file;
|
|
285
|
+
}
|
|
286
|
+
throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
|
|
287
|
+
}
|
|
288
|
+
exports.default = nodeExecutor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const enum InspectType {
|
|
2
|
+
Inspect = 'inspect',
|
|
3
|
+
InspectBrk = 'inspect-brk',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface NodeExecutorOptions {
|
|
7
|
+
inspect: boolean | InspectType;
|
|
8
|
+
runtimeArgs: string[];
|
|
9
|
+
args: string[];
|
|
10
|
+
waitUntilTargets: string[];
|
|
11
|
+
buildTarget: string;
|
|
12
|
+
buildTargetOptions: Record<string, any>;
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
watch?: boolean;
|
|
16
|
+
debounce?: number;
|
|
17
|
+
runBuildTargetDependencies?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "direct-nodejs",
|
|
4
|
+
"$schema": "https://json-schema.org/schema",
|
|
5
|
+
"cli": "nx",
|
|
6
|
+
"title": "Node executor",
|
|
7
|
+
"description": "Execute Nodejs applications.",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"buildTarget": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "The target to run to build you the app."
|
|
13
|
+
},
|
|
14
|
+
"buildTargetOptions": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"description": "Additional options to pass into the build target.",
|
|
17
|
+
"default": {}
|
|
18
|
+
},
|
|
19
|
+
"waitUntilTargets": {
|
|
20
|
+
"type": "array",
|
|
21
|
+
"description": "The targets to run before starting the node app. Listed in the form <project>:<target>. The main target will run once all listed targets have output something to the console.",
|
|
22
|
+
"default": [],
|
|
23
|
+
"items": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"host": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"default": "localhost",
|
|
30
|
+
"description": "The host to inspect the process on.",
|
|
31
|
+
"x-priority": "important"
|
|
32
|
+
},
|
|
33
|
+
"port": {
|
|
34
|
+
"type": "number",
|
|
35
|
+
"default": 9229,
|
|
36
|
+
"description": "The port to inspect the process on. Setting port to 0 will assign random free ports to all forked processes.",
|
|
37
|
+
"x-priority": "important"
|
|
38
|
+
},
|
|
39
|
+
"inspect": {
|
|
40
|
+
"oneOf": [
|
|
41
|
+
{
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": ["inspect", "inspect-brk"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"type": "boolean"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"description": "Ensures the app is starting with debugging.",
|
|
50
|
+
"default": "inspect",
|
|
51
|
+
"x-priority": "important"
|
|
52
|
+
},
|
|
53
|
+
"runtimeArgs": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"description": "Extra args passed to the node process.",
|
|
56
|
+
"default": [],
|
|
57
|
+
"items": {
|
|
58
|
+
"type": "string"
|
|
59
|
+
},
|
|
60
|
+
"x-priority": "important"
|
|
61
|
+
},
|
|
62
|
+
"args": {
|
|
63
|
+
"type": "array",
|
|
64
|
+
"description": "Extra args when starting the app.",
|
|
65
|
+
"default": [],
|
|
66
|
+
"items": {
|
|
67
|
+
"type": "string"
|
|
68
|
+
},
|
|
69
|
+
"x-priority": "important"
|
|
70
|
+
},
|
|
71
|
+
"watch": {
|
|
72
|
+
"type": "boolean",
|
|
73
|
+
"description": "Enable re-building when files change.",
|
|
74
|
+
"default": true,
|
|
75
|
+
"x-priority": "important"
|
|
76
|
+
},
|
|
77
|
+
"debounce": {
|
|
78
|
+
"type": "number",
|
|
79
|
+
"description": "Delay in milliseconds to wait before restarting. Useful to batch multiple file changes events together. Set to zero (0) to disable.",
|
|
80
|
+
"default": 500,
|
|
81
|
+
"x-priority": "important"
|
|
82
|
+
},
|
|
83
|
+
"runBuildTargetDependencies": {
|
|
84
|
+
"type": "boolean",
|
|
85
|
+
"description": "Whether to run dependencies before running the build. Set this to true if the project does not build libraries from source (e.g. 'buildLibsFromSource: false').",
|
|
86
|
+
"default": false
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"additionalProperties": false,
|
|
90
|
+
"required": ["buildTarget"],
|
|
91
|
+
"examplesFile": "../../../docs/node-examples.md"
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatBytes: (bytes: any, space?: boolean) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Taken from https://github.com/npm/cli/blob/c736b622b8504b07f5a19f631ade42dd40063269/lib/utils/format-bytes.js
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.formatBytes = void 0;
|
|
5
|
+
// Convert bytes to printable output, for file reporting in tarballs
|
|
6
|
+
// Only supports up to GB because that's way larger than anything the registry
|
|
7
|
+
// supports anyways.
|
|
8
|
+
const formatBytes = (bytes, space = true) => {
|
|
9
|
+
let spacer = '';
|
|
10
|
+
if (space) {
|
|
11
|
+
spacer = ' ';
|
|
12
|
+
}
|
|
13
|
+
if (bytes < 1000) {
|
|
14
|
+
// B
|
|
15
|
+
return `${bytes}${spacer}B`;
|
|
16
|
+
}
|
|
17
|
+
if (bytes < 1000000) {
|
|
18
|
+
// kB
|
|
19
|
+
return `${(bytes / 1000).toFixed(1)}${spacer}kB`;
|
|
20
|
+
}
|
|
21
|
+
if (bytes < 1000000000) {
|
|
22
|
+
// MB
|
|
23
|
+
return `${(bytes / 1000000).toFixed(1)}${spacer}MB`;
|
|
24
|
+
}
|
|
25
|
+
// GB
|
|
26
|
+
return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`;
|
|
27
|
+
};
|
|
28
|
+
exports.formatBytes = formatBytes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const logTar: (tarball: any, opts?: {}) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logTar = void 0;
|
|
4
|
+
// Adapted from https://github.com/npm/cli/blob/c736b622b8504b07f5a19f631ade42dd40063269/lib/utils/tar.js
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const columnify = require("columnify");
|
|
7
|
+
const format_bytes_1 = require("./format-bytes");
|
|
8
|
+
const logTar = (tarball, opts = {}) => {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const { unicode = true } = opts;
|
|
11
|
+
console.log('');
|
|
12
|
+
console.log(`${unicode ? '📦 ' : 'package:'} ${tarball.name}@${tarball.version}`);
|
|
13
|
+
console.log(chalk.magenta('=== Tarball Contents ==='));
|
|
14
|
+
if (tarball.files.length) {
|
|
15
|
+
console.log('');
|
|
16
|
+
const columnData = columnify(tarball.files
|
|
17
|
+
.map((f) => {
|
|
18
|
+
const bytes = (0, format_bytes_1.formatBytes)(f.size, false);
|
|
19
|
+
return /^node_modules\//.test(f.path)
|
|
20
|
+
? null
|
|
21
|
+
: { path: f.path, size: `${bytes}` };
|
|
22
|
+
})
|
|
23
|
+
.filter((f) => f), {
|
|
24
|
+
include: ['size', 'path'],
|
|
25
|
+
showHeaders: false,
|
|
26
|
+
});
|
|
27
|
+
columnData.split('\n').forEach((line) => {
|
|
28
|
+
console.log(line);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (tarball.bundled.length) {
|
|
32
|
+
console.log(chalk.magenta('=== Bundled Dependencies ==='));
|
|
33
|
+
tarball.bundled.forEach((name) => console.log('', name));
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk.magenta('=== Tarball Details ==='));
|
|
36
|
+
console.log(columnify([
|
|
37
|
+
{ name: 'name:', value: tarball.name },
|
|
38
|
+
{ name: 'version:', value: tarball.version },
|
|
39
|
+
tarball.filename && { name: 'filename:', value: tarball.filename },
|
|
40
|
+
{ name: 'package size:', value: (0, format_bytes_1.formatBytes)(tarball.size) },
|
|
41
|
+
{ name: 'unpacked size:', value: (0, format_bytes_1.formatBytes)(tarball.unpackedSize) },
|
|
42
|
+
{ name: 'shasum:', value: tarball.shasum },
|
|
43
|
+
{
|
|
44
|
+
name: 'integrity:',
|
|
45
|
+
value: tarball.integrity.toString().slice(0, 20) +
|
|
46
|
+
'[...]' +
|
|
47
|
+
tarball.integrity.toString().slice(80),
|
|
48
|
+
},
|
|
49
|
+
tarball.bundled.length && {
|
|
50
|
+
name: 'bundled deps:',
|
|
51
|
+
value: tarball.bundled.length,
|
|
52
|
+
},
|
|
53
|
+
tarball.bundled.length && {
|
|
54
|
+
name: 'bundled files:',
|
|
55
|
+
value: tarball.entryCount - tarball.files.length,
|
|
56
|
+
},
|
|
57
|
+
tarball.bundled.length && {
|
|
58
|
+
name: 'own files:',
|
|
59
|
+
value: tarball.files.length,
|
|
60
|
+
},
|
|
61
|
+
{ name: 'total files:', value: tarball.entryCount },
|
|
62
|
+
].filter((x) => x), {
|
|
63
|
+
include: ['name', 'value'],
|
|
64
|
+
showHeaders: false,
|
|
65
|
+
}));
|
|
66
|
+
console.log('', '');
|
|
67
|
+
};
|
|
68
|
+
exports.logTar = logTar;
|