@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.
Files changed (46) hide show
  1. package/babel.js +7 -8
  2. package/package.json +5 -5
  3. package/src/executors/node/lib/kill-tree.js +42 -45
  4. package/src/executors/node/node.impl.js +190 -189
  5. package/src/executors/swc/swc.impl.js +82 -70
  6. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
  7. package/src/executors/tsc/lib/batch/watch.js +42 -49
  8. package/src/executors/tsc/lib/get-task-options.js +8 -6
  9. package/src/executors/tsc/lib/get-tsconfig.js +16 -5
  10. package/src/executors/tsc/lib/normalize-options.js +9 -2
  11. package/src/executors/tsc/lib/typescript-compilation.js +21 -24
  12. package/src/executors/tsc/tsc.batch-impl.js +133 -132
  13. package/src/executors/tsc/tsc.impl.js +54 -50
  14. package/src/executors/verdaccio/verdaccio.impl.js +64 -55
  15. package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
  16. package/src/generators/init/init.js +86 -92
  17. package/src/generators/library/library.js +289 -245
  18. package/src/generators/setup-build/generator.js +119 -123
  19. package/src/generators/setup-verdaccio/generator.js +45 -50
  20. package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
  21. package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
  22. package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
  23. package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
  24. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  25. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
  26. package/src/plugins/jest/start-local-registry.js +4 -6
  27. package/src/plugins/rollup/type-definitions.js +21 -24
  28. package/src/utils/add-babel-inputs.js +1 -2
  29. package/src/utils/assets/assets.js +1 -2
  30. package/src/utils/assets/copy-assets-handler.js +48 -59
  31. package/src/utils/assets/index.js +20 -23
  32. package/src/utils/buildable-libs-utils.js +9 -13
  33. package/src/utils/find-npm-dependencies.js +9 -11
  34. package/src/utils/generate-globs.js +3 -3
  35. package/src/utils/inline.js +5 -10
  36. package/src/utils/package-json/get-npm-scope.js +2 -2
  37. package/src/utils/package-json/index.js +22 -25
  38. package/src/utils/package-json/update-package-json.js +23 -21
  39. package/src/utils/prettier.js +21 -24
  40. package/src/utils/swc/compile-swc.js +101 -106
  41. package/src/utils/typescript/compile-typescript-files.js +7 -8
  42. package/src/utils/typescript/print-diagnostics.js +13 -16
  43. package/src/utils/typescript/run-type-check.js +62 -59
  44. package/src/utils/typescript/ts-config.js +3 -5
  45. package/src/utils/typescript/tsnode-register.js +1 -1
  46. 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
- return tslib_1.__asyncGenerator(this, arguments, function* tscBatchExecutor_1() {
14
- const tasksOptions = (0, batch_1.normalizeTasksOptions)(inputs, context);
15
- let shouldWatch = false;
16
- Object.values(tasksOptions).forEach((taskOptions) => {
17
- if (taskOptions.clean) {
18
- (0, fs_1.rmSync)(taskOptions.outputPath, { force: true, recursive: true });
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
- if (taskOptions.watch) {
21
- shouldWatch = true;
31
+ },
32
+ info: (message, tsConfig) => {
33
+ process.stdout.write(message);
34
+ if (tsConfig) {
35
+ tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
22
36
  }
23
- });
24
- const taskInMemoryTsConfigMap = (0, lib_1.getProcessedTaskTsConfigs)(Object.keys(taskGraph.tasks), tasksOptions, context);
25
- const tsConfigTaskInfoMap = (0, batch_1.createTaskInfoPerTsConfigMap)(tasksOptions, context, Object.keys(taskGraph.tasks), taskInMemoryTsConfigMap);
26
- const tsCompilationContext = createTypescriptCompilationContext(tsConfigTaskInfoMap, taskInMemoryTsConfigMap, context);
27
- const logger = {
28
- error: (message, tsConfig) => {
29
- process.stderr.write(message);
30
- if (tsConfig) {
31
- tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
32
- }
33
- },
34
- info: (message, tsConfig) => {
35
- process.stdout.write(message);
36
- if (tsConfig) {
37
- tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
38
- }
39
- },
40
- warn: (message, tsConfig) => {
41
- process.stdout.write(message);
42
- if (tsConfig) {
43
- tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
44
- }
45
- },
46
- };
47
- const processTaskPostCompilation = (tsConfig) => {
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
- const taskInfo = tsConfigTaskInfoMap[tsConfig];
50
- taskInfo.assetsHandler.processAllAssetsOnceSync();
51
- (0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, taskInfo.options), { additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(taskInfo.options, context), format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
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 }), taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
55
- taskInfo.endTime = Date.now();
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
- const typescriptCompilation = (0, lib_1.compileTypescriptSolution)(tsCompilationContext, shouldWatch, logger, {
59
- beforeProjectCompilationCallback: (tsConfig) => {
60
- if (tsConfigTaskInfoMap[tsConfig]) {
61
- tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
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
- if (shouldWatch) {
67
- const taskInfos = Object.values(tsConfigTaskInfoMap);
68
- const watchAssetsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsFileChangesForAssets)(taskInfos));
69
- const watchProjectsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsPackageJsonFileChanges)(taskInfos, (changedTaskInfos) => {
70
- for (const t of changedTaskInfos) {
71
- (0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, t.options), { additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(t.options, context), format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
72
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
73
- // TSC can match them correctly based on file names.
74
- skipTypings: true }), t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
75
- }
76
- }));
77
- const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
78
- watchAssetsChangesDisposer();
79
- watchProjectsChangesDisposer();
80
- process.exit(exitCode);
81
- });
82
- process.on('SIGINT', () => handleTermination(128 + 2));
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
- const toBatchExecutorTaskResult = (tsConfig, success) => ({
91
- task: tsConfigTaskInfoMap[tsConfig].task,
92
- result: {
93
- success: success,
94
- terminalOutput: tsConfigTaskInfoMap[tsConfig].terminalOutput,
95
- startTime: tsConfigTaskInfoMap[tsConfig].startTime,
96
- endTime: tsConfigTaskInfoMap[tsConfig].endTime,
97
- },
98
- });
99
- let isCompilationDone = false;
100
- const taskTsConfigsToReport = new Set(Object.keys(taskGraph.tasks).map((t) => taskInMemoryTsConfigMap[t].path));
101
- let tasksToReportIterator;
102
- const processSkippedTasks = () => {
103
- const { value: tsConfig, done } = tasksToReportIterator.next();
104
- if (done) {
105
- return { value: undefined, done: true };
106
- }
107
- tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
108
- processTaskPostCompilation(tsConfig);
109
- return { value: toBatchExecutorTaskResult(tsConfig, true), done: false };
110
- };
111
- 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* () {
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
- const { value, done } = yield iterator.next();
116
- if (done) {
117
- if (taskTsConfigsToReport.size > 0) {
118
- /**
119
- * TS compilation is done but we still have tasks to report. This can
120
- * happen if, for example, a project is identified as affected, but
121
- * no file in the TS project is actually changed or if running a
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 tslib_1.__asyncGenerator(this, arguments, function* mapAsyncIterable_1() {
145
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues({
146
- [Symbol.asyncIterator]() {
147
- const iterator = iterable[Symbol.asyncIterator].call(iterable);
148
- return {
149
- next() {
150
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
151
- return yield nextFn(iterator);
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
- return tslib_1.__asyncGenerator(this, arguments, function* tscExecutor_1() {
44
- const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
45
- const options = (0, lib_1.normalizeOptions)(_options, context.root, sourceRoot, root);
46
- const { projectRoot, tmpTsConfig, target, dependencies } = (0, check_dependencies_1.checkDependencies)(context, _options.tsConfig);
47
- if (tmpTsConfig) {
48
- options.tsConfig = tmpTsConfig;
49
- }
50
- const tsLibDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.tsc, options.tsConfig, dependencies, context.projectGraph);
51
- if (tsLibDependency) {
52
- dependencies.push(tsLibDependency);
53
- }
54
- const assetHandler = new copy_assets_handler_1.CopyAssetsHandler({
55
- projectDir: projectRoot,
56
- rootDir: context.root,
57
- outputDir: _options.outputPath,
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
- var _a;
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
- try {
20
- require.resolve('verdaccio');
21
- }
22
- catch (e) {
23
- throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
24
- }
25
- if (options.storage) {
26
- options.storage = (0, path_1.resolve)(context.root, options.storage);
27
- if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
28
- (0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
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
- const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
38
- const processExitListener = (signal) => {
39
- if (childProcess) {
40
- childProcess.kill(signal);
41
- }
42
- for (const fn of cleanupFunctions) {
43
- fn();
44
- }
45
- };
46
- process.on('exit', processExitListener);
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
- catch (e) {
54
- devkit_1.logger.error('Failed to start verdaccio: ' + (e === null || e === void 0 ? void 0 : e.toString()));
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: true,
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: Object.assign(Object.assign(Object.assign({}, process.env), { VERDACCIO_HANDLE_KILL_SIGNALS: 'true' }), (options.storage
74
- ? { VERDACCIO_STORAGE_PATH: options.storage }
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 = (_c = (_b = (_a = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
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 = (_c = (_b = (_a = (0, child_process_1.execSync)(`npm config get registry --location ${options.location}`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
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 (_d) {
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 = (_c = (_b = (_a = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
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 = (_c = (_b = (_a = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
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' : ''));