@nx/js 16.8.0-beta.4 → 16.8.0-beta.6
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/babel.js +7 -8
- package/package.json +5 -5
- package/src/executors/node/lib/kill-tree.js +42 -45
- package/src/executors/node/node.impl.js +190 -189
- package/src/executors/swc/swc.impl.js +82 -70
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
- package/src/executors/tsc/lib/batch/watch.js +42 -49
- package/src/executors/tsc/lib/get-task-options.js +8 -6
- package/src/executors/tsc/lib/get-tsconfig.js +16 -5
- package/src/executors/tsc/lib/normalize-options.js +9 -2
- package/src/executors/tsc/lib/typescript-compilation.js +21 -24
- package/src/executors/tsc/tsc.batch-impl.js +133 -132
- package/src/executors/tsc/tsc.impl.js +54 -50
- package/src/executors/verdaccio/verdaccio.impl.js +64 -55
- package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
- package/src/generators/init/init.js +86 -92
- package/src/generators/library/library.js +289 -245
- package/src/generators/setup-build/generator.js +119 -123
- package/src/generators/setup-verdaccio/generator.js +45 -50
- package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
- package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
- package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
- package/src/plugins/jest/start-local-registry.js +4 -6
- package/src/plugins/rollup/type-definitions.js +21 -24
- package/src/utils/add-babel-inputs.js +1 -2
- package/src/utils/assets/assets.js +1 -2
- package/src/utils/assets/copy-assets-handler.js +48 -59
- package/src/utils/assets/index.js +20 -23
- package/src/utils/buildable-libs-utils.js +9 -13
- package/src/utils/find-npm-dependencies.js +9 -11
- package/src/utils/generate-globs.js +3 -3
- package/src/utils/inline.js +5 -10
- package/src/utils/package-json/get-npm-scope.js +2 -2
- package/src/utils/package-json/index.js +22 -25
- package/src/utils/package-json/update-package-json.js +23 -21
- package/src/utils/prettier.js +21 -24
- package/src/utils/swc/compile-swc.js +101 -106
- package/src/utils/typescript/compile-typescript-files.js +7 -8
- package/src/utils/typescript/print-diagnostics.js +13 -16
- package/src/utils/typescript/run-type-check.js +62 -59
- package/src/utils/typescript/ts-config.js +3 -5
- package/src/utils/typescript/tsnode-register.js +1 -1
- package/src/utils/watch-for-single-file-changes.js +13 -17
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tscBatchExecutor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const fs_1 = require("fs");
|
|
7
6
|
const async_iterator_1 = require("nx/src/utils/async-iterator");
|
|
@@ -9,152 +8,154 @@ const update_package_json_1 = require("../../utils/package-json/update-package-j
|
|
|
9
8
|
const tsc_impl_1 = require("./tsc.impl");
|
|
10
9
|
const lib_1 = require("./lib");
|
|
11
10
|
const batch_1 = require("./lib/batch");
|
|
12
|
-
function tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
12
|
+
const tasksOptions = (0, batch_1.normalizeTasksOptions)(inputs, context);
|
|
13
|
+
let shouldWatch = false;
|
|
14
|
+
Object.values(tasksOptions).forEach((taskOptions) => {
|
|
15
|
+
if (taskOptions.clean) {
|
|
16
|
+
(0, fs_1.rmSync)(taskOptions.outputPath, { force: true, recursive: true });
|
|
17
|
+
}
|
|
18
|
+
if (taskOptions.watch) {
|
|
19
|
+
shouldWatch = true;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const taskInMemoryTsConfigMap = (0, lib_1.getProcessedTaskTsConfigs)(Object.keys(taskGraph.tasks), tasksOptions, context);
|
|
23
|
+
const tsConfigTaskInfoMap = (0, batch_1.createTaskInfoPerTsConfigMap)(tasksOptions, context, Object.keys(taskGraph.tasks), taskInMemoryTsConfigMap);
|
|
24
|
+
const tsCompilationContext = createTypescriptCompilationContext(tsConfigTaskInfoMap, taskInMemoryTsConfigMap, context);
|
|
25
|
+
const logger = {
|
|
26
|
+
error: (message, tsConfig) => {
|
|
27
|
+
process.stderr.write(message);
|
|
28
|
+
if (tsConfig) {
|
|
29
|
+
tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
|
|
19
30
|
}
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
},
|
|
32
|
+
info: (message, tsConfig) => {
|
|
33
|
+
process.stdout.write(message);
|
|
34
|
+
if (tsConfig) {
|
|
35
|
+
tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
|
|
22
36
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
},
|
|
38
|
+
warn: (message, tsConfig) => {
|
|
39
|
+
process.stdout.write(message);
|
|
40
|
+
if (tsConfig) {
|
|
41
|
+
tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const processTaskPostCompilation = (tsConfig) => {
|
|
46
|
+
if (tsConfigTaskInfoMap[tsConfig]) {
|
|
47
|
+
const taskInfo = tsConfigTaskInfoMap[tsConfig];
|
|
48
|
+
taskInfo.assetsHandler.processAllAssetsOnceSync();
|
|
49
|
+
(0, update_package_json_1.updatePackageJson)({
|
|
50
|
+
...taskInfo.options,
|
|
51
|
+
additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(taskInfo.options, context),
|
|
52
|
+
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
|
|
53
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
54
|
+
// TSC can match them correctly based on file names.
|
|
55
|
+
skipTypings: true,
|
|
56
|
+
}, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
|
|
57
|
+
taskInfo.endTime = Date.now();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const typescriptCompilation = (0, lib_1.compileTypescriptSolution)(tsCompilationContext, shouldWatch, logger, {
|
|
61
|
+
beforeProjectCompilationCallback: (tsConfig) => {
|
|
48
62
|
if (tsConfigTaskInfoMap[tsConfig]) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
afterProjectCompilationCallback: processTaskPostCompilation,
|
|
67
|
+
});
|
|
68
|
+
if (shouldWatch) {
|
|
69
|
+
const taskInfos = Object.values(tsConfigTaskInfoMap);
|
|
70
|
+
const watchAssetsChangesDisposer = await (0, batch_1.watchTaskProjectsFileChangesForAssets)(taskInfos);
|
|
71
|
+
const watchProjectsChangesDisposer = await (0, batch_1.watchTaskProjectsPackageJsonFileChanges)(taskInfos, (changedTaskInfos) => {
|
|
72
|
+
for (const t of changedTaskInfos) {
|
|
73
|
+
(0, update_package_json_1.updatePackageJson)({
|
|
74
|
+
...t.options,
|
|
75
|
+
additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(t.options, context),
|
|
76
|
+
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
|
|
52
77
|
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
53
78
|
// TSC can match them correctly based on file names.
|
|
54
|
-
skipTypings: true
|
|
55
|
-
|
|
79
|
+
skipTypings: true,
|
|
80
|
+
}, t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
|
|
56
81
|
}
|
|
82
|
+
});
|
|
83
|
+
const handleTermination = async (exitCode) => {
|
|
84
|
+
watchAssetsChangesDisposer();
|
|
85
|
+
watchProjectsChangesDisposer();
|
|
86
|
+
process.exit(exitCode);
|
|
57
87
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
afterProjectCompilationCallback: processTaskPostCompilation,
|
|
88
|
+
process.on('SIGINT', () => handleTermination(128 + 2));
|
|
89
|
+
process.on('SIGTERM', () => handleTermination(128 + 15));
|
|
90
|
+
return yield* mapAsyncIterable(typescriptCompilation, async (iterator) => {
|
|
91
|
+
// drain the iterator, we don't use the results
|
|
92
|
+
await (0, async_iterator_1.getLastValueFromAsyncIterableIterator)(iterator);
|
|
93
|
+
return { value: undefined, done: true };
|
|
65
94
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
process.on('SIGTERM', () => handleTermination(128 + 15));
|
|
84
|
-
return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(mapAsyncIterable(typescriptCompilation, (iterator) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
// drain the iterator, we don't use the results
|
|
86
|
-
yield (0, async_iterator_1.getLastValueFromAsyncIterableIterator)(iterator);
|
|
87
|
-
return { value: undefined, done: true };
|
|
88
|
-
}))))));
|
|
95
|
+
}
|
|
96
|
+
const toBatchExecutorTaskResult = (tsConfig, success) => ({
|
|
97
|
+
task: tsConfigTaskInfoMap[tsConfig].task,
|
|
98
|
+
result: {
|
|
99
|
+
success: success,
|
|
100
|
+
terminalOutput: tsConfigTaskInfoMap[tsConfig].terminalOutput,
|
|
101
|
+
startTime: tsConfigTaskInfoMap[tsConfig].startTime,
|
|
102
|
+
endTime: tsConfigTaskInfoMap[tsConfig].endTime,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
let isCompilationDone = false;
|
|
106
|
+
const taskTsConfigsToReport = new Set(Object.keys(taskGraph.tasks).map((t) => taskInMemoryTsConfigMap[t].path));
|
|
107
|
+
let tasksToReportIterator;
|
|
108
|
+
const processSkippedTasks = () => {
|
|
109
|
+
const { value: tsConfig, done } = tasksToReportIterator.next();
|
|
110
|
+
if (done) {
|
|
111
|
+
return { value: undefined, done: true };
|
|
89
112
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (isCompilationDone) {
|
|
113
|
+
tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
|
|
114
|
+
processTaskPostCompilation(tsConfig);
|
|
115
|
+
return { value: toBatchExecutorTaskResult(tsConfig, true), done: false };
|
|
116
|
+
};
|
|
117
|
+
return yield* mapAsyncIterable(typescriptCompilation, async (iterator) => {
|
|
118
|
+
if (isCompilationDone) {
|
|
119
|
+
return processSkippedTasks();
|
|
120
|
+
}
|
|
121
|
+
const { value, done } = await iterator.next();
|
|
122
|
+
if (done) {
|
|
123
|
+
if (taskTsConfigsToReport.size > 0) {
|
|
124
|
+
/**
|
|
125
|
+
* TS compilation is done but we still have tasks to report. This can
|
|
126
|
+
* happen if, for example, a project is identified as affected, but
|
|
127
|
+
* no file in the TS project is actually changed or if running a
|
|
128
|
+
* task with `--skip-nx-cache` and the outputs are already there. There
|
|
129
|
+
* can still be changes to assets or other files we need to process.
|
|
130
|
+
*
|
|
131
|
+
* Switch to handle the iterator for the tasks we still need to report.
|
|
132
|
+
*/
|
|
133
|
+
isCompilationDone = true;
|
|
134
|
+
tasksToReportIterator = taskTsConfigsToReport.values();
|
|
113
135
|
return processSkippedTasks();
|
|
114
136
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* task with `--skip-nx-cache` and the outputs are already there. There
|
|
123
|
-
* can still be changes to assets or other files we need to process.
|
|
124
|
-
*
|
|
125
|
-
* Switch to handle the iterator for the tasks we still need to report.
|
|
126
|
-
*/
|
|
127
|
-
isCompilationDone = true;
|
|
128
|
-
tasksToReportIterator = taskTsConfigsToReport.values();
|
|
129
|
-
return processSkippedTasks();
|
|
130
|
-
}
|
|
131
|
-
return { value: undefined, done: true };
|
|
132
|
-
}
|
|
133
|
-
taskTsConfigsToReport.delete(value.tsConfig);
|
|
134
|
-
return {
|
|
135
|
-
value: toBatchExecutorTaskResult(value.tsConfig, value.success),
|
|
136
|
-
done: false,
|
|
137
|
-
};
|
|
138
|
-
}))))));
|
|
137
|
+
return { value: undefined, done: true };
|
|
138
|
+
}
|
|
139
|
+
taskTsConfigsToReport.delete(value.tsConfig);
|
|
140
|
+
return {
|
|
141
|
+
value: toBatchExecutorTaskResult(value.tsConfig, value.success),
|
|
142
|
+
done: false,
|
|
143
|
+
};
|
|
139
144
|
});
|
|
140
145
|
}
|
|
141
146
|
exports.tscBatchExecutor = tscBatchExecutor;
|
|
142
147
|
exports.default = tscBatchExecutor;
|
|
143
|
-
function mapAsyncIterable(iterable, nextFn) {
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
[Symbol.asyncIterator]()
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
}))));
|
|
157
|
-
});
|
|
148
|
+
async function* mapAsyncIterable(iterable, nextFn) {
|
|
149
|
+
return yield* {
|
|
150
|
+
[Symbol.asyncIterator]() {
|
|
151
|
+
const iterator = iterable[Symbol.asyncIterator].call(iterable);
|
|
152
|
+
return {
|
|
153
|
+
async next() {
|
|
154
|
+
return await nextFn(iterator);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
158
159
|
}
|
|
159
160
|
function createTypescriptCompilationContext(tsConfigTaskInfoMap, taskInMemoryTsConfigMap, context) {
|
|
160
161
|
const tsCompilationContext = Object.entries(tsConfigTaskInfoMap).reduce((acc, [tsConfig, taskInfo]) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createEntryPoints = exports.tscExecutor = exports.createTypeScriptCompilationOptions = exports.determineModuleFormatFromTsConfig = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const ts = require("typescript");
|
|
6
5
|
const fast_glob_1 = require("fast-glob");
|
|
7
6
|
const copy_assets_handler_1 = require("../../utils/assets/copy-assets-handler");
|
|
@@ -39,59 +38,64 @@ function createTypeScriptCompilationOptions(normalizedOptions, context) {
|
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
exports.createTypeScriptCompilationOptions = createTypeScriptCompilationOptions;
|
|
42
|
-
function tscExecutor(_options, context) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
assets: _options.assets,
|
|
59
|
-
});
|
|
60
|
-
const tsCompilationOptions = createTypeScriptCompilationOptions(options, context);
|
|
61
|
-
const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, tsCompilationOptions.tsConfig);
|
|
62
|
-
if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
|
|
63
|
-
tsCompilationOptions.rootDir = '.';
|
|
64
|
-
}
|
|
65
|
-
const typescriptCompilation = (0, compile_typescript_files_1.compileTypeScriptFiles)(options, tsCompilationOptions, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
yield assetHandler.processAllAssetsOnce();
|
|
67
|
-
(0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
68
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
69
|
-
// TSC can match them correctly based on file names.
|
|
70
|
-
skipTypings: true }), context, target, dependencies);
|
|
71
|
-
(0, inline_1.postProcessInlinedDependencies)(tsCompilationOptions.outputPath, tsCompilationOptions.projectRoot, inlineProjectGraph);
|
|
72
|
-
}));
|
|
73
|
-
if (options.watch) {
|
|
74
|
-
const disposeWatchAssetChanges = yield tslib_1.__await(assetHandler.watchAndProcessOnAssetChange());
|
|
75
|
-
const disposePackageJsonChanges = yield tslib_1.__await((0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context),
|
|
76
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
77
|
-
// TSC can match them correctly based on file names.
|
|
78
|
-
skipTypings: true, format: [determineModuleFormatFromTsConfig(options.tsConfig)] }), context, target, dependencies)));
|
|
79
|
-
const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
yield typescriptCompilation.close();
|
|
81
|
-
disposeWatchAssetChanges();
|
|
82
|
-
disposePackageJsonChanges();
|
|
83
|
-
process.exit(exitCode);
|
|
84
|
-
});
|
|
85
|
-
process.on('SIGINT', () => handleTermination(128 + 2));
|
|
86
|
-
process.on('SIGTERM', () => handleTermination(128 + 15));
|
|
87
|
-
}
|
|
88
|
-
return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(typescriptCompilation.iterator))));
|
|
41
|
+
async function* tscExecutor(_options, context) {
|
|
42
|
+
const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
|
|
43
|
+
const options = (0, lib_1.normalizeOptions)(_options, context.root, sourceRoot, root);
|
|
44
|
+
const { projectRoot, tmpTsConfig, target, dependencies } = (0, check_dependencies_1.checkDependencies)(context, _options.tsConfig);
|
|
45
|
+
if (tmpTsConfig) {
|
|
46
|
+
options.tsConfig = tmpTsConfig;
|
|
47
|
+
}
|
|
48
|
+
const tsLibDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.tsc, options.tsConfig, dependencies, context.projectGraph);
|
|
49
|
+
if (tsLibDependency) {
|
|
50
|
+
dependencies.push(tsLibDependency);
|
|
51
|
+
}
|
|
52
|
+
const assetHandler = new copy_assets_handler_1.CopyAssetsHandler({
|
|
53
|
+
projectDir: projectRoot,
|
|
54
|
+
rootDir: context.root,
|
|
55
|
+
outputDir: _options.outputPath,
|
|
56
|
+
assets: _options.assets,
|
|
89
57
|
});
|
|
58
|
+
const tsCompilationOptions = createTypeScriptCompilationOptions(options, context);
|
|
59
|
+
const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, tsCompilationOptions.tsConfig);
|
|
60
|
+
if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
|
|
61
|
+
tsCompilationOptions.rootDir = '.';
|
|
62
|
+
}
|
|
63
|
+
const typescriptCompilation = (0, compile_typescript_files_1.compileTypeScriptFiles)(options, tsCompilationOptions, async () => {
|
|
64
|
+
await assetHandler.processAllAssetsOnce();
|
|
65
|
+
(0, update_package_json_1.updatePackageJson)({
|
|
66
|
+
...options,
|
|
67
|
+
additionalEntryPoints: createEntryPoints(options, context),
|
|
68
|
+
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
69
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
70
|
+
// TSC can match them correctly based on file names.
|
|
71
|
+
skipTypings: true,
|
|
72
|
+
}, context, target, dependencies);
|
|
73
|
+
(0, inline_1.postProcessInlinedDependencies)(tsCompilationOptions.outputPath, tsCompilationOptions.projectRoot, inlineProjectGraph);
|
|
74
|
+
});
|
|
75
|
+
if (options.watch) {
|
|
76
|
+
const disposeWatchAssetChanges = await assetHandler.watchAndProcessOnAssetChange();
|
|
77
|
+
const disposePackageJsonChanges = await (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)({
|
|
78
|
+
...options,
|
|
79
|
+
additionalEntryPoints: createEntryPoints(options, context),
|
|
80
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
81
|
+
// TSC can match them correctly based on file names.
|
|
82
|
+
skipTypings: true,
|
|
83
|
+
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
84
|
+
}, context, target, dependencies));
|
|
85
|
+
const handleTermination = async (exitCode) => {
|
|
86
|
+
await typescriptCompilation.close();
|
|
87
|
+
disposeWatchAssetChanges();
|
|
88
|
+
disposePackageJsonChanges();
|
|
89
|
+
process.exit(exitCode);
|
|
90
|
+
};
|
|
91
|
+
process.on('SIGINT', () => handleTermination(128 + 2));
|
|
92
|
+
process.on('SIGTERM', () => handleTermination(128 + 15));
|
|
93
|
+
}
|
|
94
|
+
return yield* typescriptCompilation.iterator;
|
|
90
95
|
}
|
|
91
96
|
exports.tscExecutor = tscExecutor;
|
|
92
97
|
function createEntryPoints(options, context) {
|
|
93
|
-
|
|
94
|
-
if (!((_a = options.additionalEntryPoints) === null || _a === void 0 ? void 0 : _a.length))
|
|
98
|
+
if (!options.additionalEntryPoints?.length)
|
|
95
99
|
return [];
|
|
96
100
|
return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
|
|
97
101
|
cwd: context.root,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.verdaccioExecutor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const fs_extra_1 = require("fs-extra");
|
|
7
6
|
const child_process_1 = require("child_process");
|
|
@@ -14,54 +13,52 @@ let childProcess;
|
|
|
14
13
|
* - start verdaccio
|
|
15
14
|
* - stop local registry when done
|
|
16
15
|
*/
|
|
17
|
-
function verdaccioExecutor(options, context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(`Cleared local registry storage folder ${options.storage}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const port = yield detectPort(options.port);
|
|
33
|
-
if (port !== options.port) {
|
|
34
|
-
devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
|
|
35
|
-
options.port = port;
|
|
16
|
+
async function verdaccioExecutor(options, context) {
|
|
17
|
+
try {
|
|
18
|
+
require.resolve('verdaccio');
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
|
|
22
|
+
}
|
|
23
|
+
if (options.storage) {
|
|
24
|
+
options.storage = (0, path_1.resolve)(context.root, options.storage);
|
|
25
|
+
if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
|
|
26
|
+
(0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
|
|
27
|
+
console.log(`Cleared local registry storage folder ${options.storage}`);
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
process.on('SIGTERM', processExitListener);
|
|
48
|
-
process.on('SIGINT', processExitListener);
|
|
49
|
-
process.on('SIGHUP', processExitListener);
|
|
50
|
-
try {
|
|
51
|
-
yield startVerdaccio(options, context.root);
|
|
29
|
+
}
|
|
30
|
+
const port = await detectPort(options.port);
|
|
31
|
+
if (port !== options.port) {
|
|
32
|
+
devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
|
|
33
|
+
options.port = port;
|
|
34
|
+
}
|
|
35
|
+
const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
|
|
36
|
+
const processExitListener = (signal) => {
|
|
37
|
+
if (childProcess) {
|
|
38
|
+
childProcess.kill(signal);
|
|
52
39
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
port: options.port,
|
|
58
|
-
};
|
|
40
|
+
for (const fn of cleanupFunctions) {
|
|
41
|
+
fn();
|
|
59
42
|
}
|
|
43
|
+
};
|
|
44
|
+
process.on('exit', processExitListener);
|
|
45
|
+
process.on('SIGTERM', processExitListener);
|
|
46
|
+
process.on('SIGINT', processExitListener);
|
|
47
|
+
process.on('SIGHUP', processExitListener);
|
|
48
|
+
try {
|
|
49
|
+
await startVerdaccio(options, context.root);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
devkit_1.logger.error('Failed to start verdaccio: ' + e?.toString());
|
|
60
53
|
return {
|
|
61
|
-
success:
|
|
54
|
+
success: false,
|
|
62
55
|
port: options.port,
|
|
63
56
|
};
|
|
64
|
-
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
port: options.port,
|
|
61
|
+
};
|
|
65
62
|
}
|
|
66
63
|
exports.verdaccioExecutor = verdaccioExecutor;
|
|
67
64
|
/**
|
|
@@ -70,9 +67,13 @@ exports.verdaccioExecutor = verdaccioExecutor;
|
|
|
70
67
|
function startVerdaccio(options, workspaceRoot) {
|
|
71
68
|
return new Promise((resolve, reject) => {
|
|
72
69
|
childProcess = (0, child_process_1.fork)(require.resolve('verdaccio/bin/verdaccio'), createVerdaccioOptions(options, workspaceRoot), {
|
|
73
|
-
env:
|
|
74
|
-
|
|
75
|
-
:
|
|
70
|
+
env: {
|
|
71
|
+
...process.env,
|
|
72
|
+
VERDACCIO_HANDLE_KILL_SIGNALS: 'true',
|
|
73
|
+
...(options.storage
|
|
74
|
+
? { VERDACCIO_STORAGE_PATH: options.storage }
|
|
75
|
+
: {}),
|
|
76
|
+
},
|
|
76
77
|
stdio: 'inherit',
|
|
77
78
|
});
|
|
78
79
|
childProcess.on('error', (err) => {
|
|
@@ -102,7 +103,6 @@ function createVerdaccioOptions(options, workspaceRoot) {
|
|
|
102
103
|
return verdaccioArgs;
|
|
103
104
|
}
|
|
104
105
|
function setupNpm(options) {
|
|
105
|
-
var _a, _b, _c;
|
|
106
106
|
try {
|
|
107
107
|
(0, child_process_1.execSync)('npm --version');
|
|
108
108
|
}
|
|
@@ -111,7 +111,10 @@ function setupNpm(options) {
|
|
|
111
111
|
}
|
|
112
112
|
let npmRegistryPath;
|
|
113
113
|
try {
|
|
114
|
-
npmRegistryPath = (
|
|
114
|
+
npmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)
|
|
115
|
+
?.toString()
|
|
116
|
+
?.trim()
|
|
117
|
+
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
115
118
|
(0, child_process_1.execSync)(`npm config set registry http://localhost:${options.port}/ --location ${options.location}`);
|
|
116
119
|
(0, child_process_1.execSync)(`npm config set //localhost:${options.port}/:_authToken="secretVerdaccioToken" --location ${options.location}`);
|
|
117
120
|
devkit_1.logger.info(`Set npm registry to http://localhost:${options.port}/`);
|
|
@@ -120,9 +123,11 @@ function setupNpm(options) {
|
|
|
120
123
|
throw new Error(`Failed to set npm registry to http://localhost:${options.port}/: ${e.message}`);
|
|
121
124
|
}
|
|
122
125
|
return () => {
|
|
123
|
-
var _a, _b, _c;
|
|
124
126
|
try {
|
|
125
|
-
const currentNpmRegistryPath = (
|
|
127
|
+
const currentNpmRegistryPath = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)
|
|
128
|
+
?.toString()
|
|
129
|
+
?.trim()
|
|
130
|
+
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
126
131
|
if (npmRegistryPath && currentNpmRegistryPath.includes('localhost')) {
|
|
127
132
|
(0, child_process_1.execSync)(`npm config set registry ${npmRegistryPath} --location ${options.location}`);
|
|
128
133
|
devkit_1.logger.info(`Reset npm registry to ${npmRegistryPath}`);
|
|
@@ -152,18 +157,20 @@ function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
|
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
159
|
function setupYarn(options) {
|
|
155
|
-
var _a, _b, _c;
|
|
156
160
|
let isYarnV1;
|
|
157
161
|
try {
|
|
158
162
|
isYarnV1 = (0, semver_1.major)((0, child_process_1.execSync)('yarn --version').toString().trim()) === 1;
|
|
159
163
|
}
|
|
160
|
-
catch
|
|
164
|
+
catch {
|
|
161
165
|
// This would fail if yarn is not installed which is okay
|
|
162
166
|
return () => { };
|
|
163
167
|
}
|
|
164
168
|
try {
|
|
165
169
|
const registryConfigName = isYarnV1 ? 'registry' : 'npmRegistryServer';
|
|
166
|
-
const yarnRegistryPath = (
|
|
170
|
+
const yarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)
|
|
171
|
+
?.toString()
|
|
172
|
+
?.trim()
|
|
173
|
+
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
167
174
|
(0, child_process_1.execSync)(`yarn config set ${registryConfigName} http://localhost:${options.port}/` +
|
|
168
175
|
(options.location === 'user' ? ' --home' : ''));
|
|
169
176
|
devkit_1.logger.info(`Set yarn registry to http://localhost:${options.port}/`);
|
|
@@ -176,9 +183,11 @@ function setupYarn(options) {
|
|
|
176
183
|
devkit_1.logger.info(`Whitelisted http://localhost:${options.port}/ as an unsafe http server`);
|
|
177
184
|
}
|
|
178
185
|
return () => {
|
|
179
|
-
var _a, _b, _c;
|
|
180
186
|
try {
|
|
181
|
-
const currentYarnRegistryPath = (
|
|
187
|
+
const currentYarnRegistryPath = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)
|
|
188
|
+
?.toString()
|
|
189
|
+
?.trim()
|
|
190
|
+
?.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
|
|
182
191
|
if (yarnRegistryPath && currentYarnRegistryPath.includes('localhost')) {
|
|
183
192
|
(0, child_process_1.execSync)(`yarn config set ${registryConfigName} ${yarnRegistryPath}` +
|
|
184
193
|
(options.location === 'user' ? ' --home' : ''));
|