@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.swcExecutor = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const assets_1 = require("../../utils/assets/assets");
7
6
  const fs_extra_1 = require("fs-extra");
@@ -50,76 +49,90 @@ function normalizeOptions(options, root, sourceRoot, projectRoot) {
50
49
  swcCwd,
51
50
  swcrcPath,
52
51
  };
53
- return Object.assign(Object.assign({}, options), { mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')), files,
52
+ return {
53
+ ...options,
54
+ mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')),
55
+ files,
54
56
  root,
55
57
  sourceRoot,
56
- projectRoot, originalProjectRoot: projectRoot, outputPath, tsConfig: (0, path_1.join)(root, options.tsConfig), swcCliOptions });
58
+ projectRoot,
59
+ originalProjectRoot: projectRoot,
60
+ outputPath,
61
+ tsConfig: (0, path_1.join)(root, options.tsConfig),
62
+ swcCliOptions,
63
+ };
57
64
  }
58
- function swcExecutor(_options, context) {
59
- return tslib_1.__asyncGenerator(this, arguments, function* swcExecutor_1() {
60
- const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
61
- const options = normalizeOptions(_options, context.root, sourceRoot, root);
62
- const { tmpTsConfig, dependencies } = (0, check_dependencies_1.checkDependencies)(context, options.tsConfig);
63
- if (tmpTsConfig) {
64
- options.tsConfig = tmpTsConfig;
65
- }
66
- const swcHelperDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.swc, options.swcCliOptions.swcrcPath, dependencies, context.projectGraph);
67
- if (swcHelperDependency) {
68
- dependencies.push(swcHelperDependency);
69
- }
70
- const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
71
- if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
72
- options.projectRoot = '.'; // set to root of workspace to include other libs for type check
73
- // remap paths for SWC compilation
74
- options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
75
- options.swcCliOptions.swcCwd = '.';
76
- options.swcCliOptions.destPath = options.swcCliOptions.destPath
77
- .split('../')
78
- .at(-1)
79
- .concat('/', options.swcCliOptions.srcPath);
80
- // tmp swcrc with dependencies to exclude
81
- // - buildable libraries
82
- // - other libraries that are not dependent on the current project
83
- options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath);
84
- }
85
- function determineModuleFormatFromSwcrc(absolutePathToSwcrc) {
86
- var _a, _b;
87
- const swcrc = (0, devkit_1.readJsonFile)(absolutePathToSwcrc);
88
- return ((_b = (_a = swcrc.module) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.startsWith('es')) ? 'esm' : 'cjs';
89
- }
90
- if (options.watch) {
91
- let disposeFn;
92
- process.on('SIGINT', () => disposeFn());
93
- process.on('SIGTERM', () => disposeFn());
94
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, compile_swc_1.compileSwcWatch)(context, options, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- const assetResult = yield (0, assets_2.copyAssets)(options, context);
96
- const packageJsonResult = yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [
97
- determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
98
- ],
99
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
100
- // TSC can match them correctly based on file names.
101
- skipTypings: true }), context);
102
- removeTmpSwcrc(options.swcCliOptions.swcrcPath);
103
- disposeFn = () => {
104
- assetResult === null || assetResult === void 0 ? void 0 : assetResult.stop();
105
- packageJsonResult === null || packageJsonResult === void 0 ? void 0 : packageJsonResult.stop();
106
- };
107
- }))))));
108
- }
109
- else {
110
- return yield tslib_1.__await(yield yield tslib_1.__await((0, compile_swc_1.compileSwc)(context, options, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
111
- yield (0, assets_2.copyAssets)(options, context);
112
- yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [
113
- determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
114
- ],
115
- // As long as d.ts files match their .js counterparts, we don't need to emit them.
116
- // TSC can match them correctly based on file names.
117
- skipTypings: true, extraDependencies: swcHelperDependency ? [swcHelperDependency] : [] }), context);
118
- removeTmpSwcrc(options.swcCliOptions.swcrcPath);
119
- (0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
120
- }))));
121
- }
122
- });
65
+ async function* swcExecutor(_options, context) {
66
+ const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
67
+ const options = normalizeOptions(_options, context.root, sourceRoot, root);
68
+ const { tmpTsConfig, dependencies } = (0, check_dependencies_1.checkDependencies)(context, options.tsConfig);
69
+ if (tmpTsConfig) {
70
+ options.tsConfig = tmpTsConfig;
71
+ }
72
+ const swcHelperDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.swc, options.swcCliOptions.swcrcPath, dependencies, context.projectGraph);
73
+ if (swcHelperDependency) {
74
+ dependencies.push(swcHelperDependency);
75
+ }
76
+ const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
77
+ if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
78
+ options.projectRoot = '.'; // set to root of workspace to include other libs for type check
79
+ // remap paths for SWC compilation
80
+ options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
81
+ options.swcCliOptions.swcCwd = '.';
82
+ options.swcCliOptions.destPath = options.swcCliOptions.destPath
83
+ .split('../')
84
+ .at(-1)
85
+ .concat('/', options.swcCliOptions.srcPath);
86
+ // tmp swcrc with dependencies to exclude
87
+ // - buildable libraries
88
+ // - other libraries that are not dependent on the current project
89
+ options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath);
90
+ }
91
+ function determineModuleFormatFromSwcrc(absolutePathToSwcrc) {
92
+ const swcrc = (0, devkit_1.readJsonFile)(absolutePathToSwcrc);
93
+ return swcrc.module?.type?.startsWith('es') ? 'esm' : 'cjs';
94
+ }
95
+ if (options.watch) {
96
+ let disposeFn;
97
+ process.on('SIGINT', () => disposeFn());
98
+ process.on('SIGTERM', () => disposeFn());
99
+ return yield* (0, compile_swc_1.compileSwcWatch)(context, options, async () => {
100
+ const assetResult = await (0, assets_2.copyAssets)(options, context);
101
+ const packageJsonResult = await (0, package_json_1.copyPackageJson)({
102
+ ...options,
103
+ additionalEntryPoints: createEntryPoints(options, context),
104
+ format: [
105
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
106
+ ],
107
+ // As long as d.ts files match their .js counterparts, we don't need to emit them.
108
+ // TSC can match them correctly based on file names.
109
+ skipTypings: true,
110
+ }, context);
111
+ removeTmpSwcrc(options.swcCliOptions.swcrcPath);
112
+ disposeFn = () => {
113
+ assetResult?.stop();
114
+ packageJsonResult?.stop();
115
+ };
116
+ });
117
+ }
118
+ else {
119
+ return yield (0, compile_swc_1.compileSwc)(context, options, async () => {
120
+ await (0, assets_2.copyAssets)(options, context);
121
+ await (0, package_json_1.copyPackageJson)({
122
+ ...options,
123
+ additionalEntryPoints: createEntryPoints(options, context),
124
+ format: [
125
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
126
+ ],
127
+ // As long as d.ts files match their .js counterparts, we don't need to emit them.
128
+ // TSC can match them correctly based on file names.
129
+ skipTypings: true,
130
+ extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
131
+ }, context);
132
+ removeTmpSwcrc(options.swcCliOptions.swcrcPath);
133
+ (0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
134
+ });
135
+ }
123
136
  }
124
137
  exports.swcExecutor = swcExecutor;
125
138
  function removeTmpSwcrc(swcrcPath) {
@@ -128,8 +141,7 @@ function removeTmpSwcrc(swcrcPath) {
128
141
  }
129
142
  }
130
143
  function createEntryPoints(options, context) {
131
- var _a;
132
- if (!((_a = options.additionalEntryPoints) === null || _a === void 0 ? void 0 : _a.length))
144
+ if (!options.additionalEntryPoints?.length)
133
145
  return [];
134
146
  return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
135
147
  cwd: context.root,
@@ -14,7 +14,6 @@ function createTaskInfoPerTsConfigMap(tasksOptions, context, tasks, taskInMemory
14
14
  }
15
15
  exports.createTaskInfoPerTsConfigMap = createTaskInfoPerTsConfigMap;
16
16
  function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, taskInMemoryTsConfigMap) {
17
- var _a;
18
17
  for (const taskName of tasks) {
19
18
  if (taskTsConfigCache.has(taskName)) {
20
19
  continue;
@@ -23,7 +22,7 @@ function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOp
23
22
  if (!tsConfig) {
24
23
  continue;
25
24
  }
26
- let taskOptions = (_a = tasksOptions[taskName]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskOptions)(taskName, context);
25
+ let taskOptions = tasksOptions[taskName] ?? (0, get_task_options_1.getTaskOptions)(taskName, context);
27
26
  if (taskOptions) {
28
27
  const taskInfo = createTaskInfo(taskName, taskOptions, context, tsConfig);
29
28
  const tsConfigPath = (0, path_1.join)(context.root, (0, path_1.relative)(context.root, taskOptions.tsConfig)).replace(/\\/g, '/');
@@ -35,10 +34,14 @@ function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOp
35
34
  }
36
35
  function createTaskInfo(taskName, taskOptions, context, tsConfig) {
37
36
  const target = (0, devkit_1.parseTargetString)(taskName, context.projectGraph);
38
- const taskContext = Object.assign(Object.assign({}, context), {
37
+ const taskContext = {
38
+ ...context,
39
39
  // batch executors don't get these in the context, we provide them
40
40
  // here per task
41
- projectName: target.project, targetName: target.target, configurationName: target.configuration });
41
+ projectName: target.project,
42
+ targetName: target.target,
43
+ configurationName: target.configuration,
44
+ };
42
45
  const assetsHandler = new copy_assets_handler_1.CopyAssetsHandler({
43
46
  projectDir: taskOptions.projectRoot,
44
47
  rootDir: context.root,
@@ -1,63 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watchTaskProjectsFileChangesForAssets = exports.watchTaskProjectsPackageJsonFileChanges = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const client_1 = require("nx/src/daemon/client/client");
7
6
  const path_1 = require("path");
8
- function watchTaskProjectsPackageJsonFileChanges(taskInfos, callback) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const projects = [];
11
- const packageJsonTaskInfoMap = new Map();
12
- taskInfos.forEach((t) => {
13
- projects.push(t.context.projectName);
14
- packageJsonTaskInfoMap.set((0, path_1.join)(t.options.projectRoot, 'package.json'), t);
15
- });
16
- const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({ watchProjects: projects }, (err, data) => {
17
- var _a;
18
- if (err === 'closed') {
19
- devkit_1.logger.error(`Watch error: Daemon closed the connection`);
20
- process.exit(1);
21
- }
22
- else if (err) {
23
- devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
24
- }
25
- else {
26
- const changedTasks = [];
27
- data.changedFiles.forEach((file) => {
28
- if (packageJsonTaskInfoMap.has(file.path)) {
29
- changedTasks.push(packageJsonTaskInfoMap.get(file.path));
30
- }
31
- });
32
- if (changedTasks.length) {
33
- callback(changedTasks);
7
+ async function watchTaskProjectsPackageJsonFileChanges(taskInfos, callback) {
8
+ const projects = [];
9
+ const packageJsonTaskInfoMap = new Map();
10
+ taskInfos.forEach((t) => {
11
+ projects.push(t.context.projectName);
12
+ packageJsonTaskInfoMap.set((0, path_1.join)(t.options.projectRoot, 'package.json'), t);
13
+ });
14
+ const unregisterFileWatcher = await client_1.daemonClient.registerFileWatcher({ watchProjects: projects }, (err, data) => {
15
+ if (err === 'closed') {
16
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
17
+ process.exit(1);
18
+ }
19
+ else if (err) {
20
+ devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
21
+ }
22
+ else {
23
+ const changedTasks = [];
24
+ data.changedFiles.forEach((file) => {
25
+ if (packageJsonTaskInfoMap.has(file.path)) {
26
+ changedTasks.push(packageJsonTaskInfoMap.get(file.path));
34
27
  }
28
+ });
29
+ if (changedTasks.length) {
30
+ callback(changedTasks);
35
31
  }
36
- });
37
- return () => unregisterFileWatcher();
32
+ }
38
33
  });
34
+ return () => unregisterFileWatcher();
39
35
  }
40
36
  exports.watchTaskProjectsPackageJsonFileChanges = watchTaskProjectsPackageJsonFileChanges;
41
- function watchTaskProjectsFileChangesForAssets(taskInfos) {
42
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
- const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({
44
- watchProjects: taskInfos.map((t) => t.context.projectName),
45
- includeDependentProjects: true,
46
- includeGlobalWorkspaceFiles: true,
47
- }, (err, data) => {
48
- var _a;
49
- if (err === 'closed') {
50
- devkit_1.logger.error(`Watch error: Daemon closed the connection`);
51
- process.exit(1);
52
- }
53
- else if (err) {
54
- devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
55
- }
56
- else {
57
- taskInfos.forEach((t) => t.assetsHandler.processWatchEvents(data.changedFiles));
58
- }
59
- });
60
- return () => unregisterFileWatcher();
37
+ async function watchTaskProjectsFileChangesForAssets(taskInfos) {
38
+ const unregisterFileWatcher = await client_1.daemonClient.registerFileWatcher({
39
+ watchProjects: taskInfos.map((t) => t.context.projectName),
40
+ includeDependentProjects: true,
41
+ includeGlobalWorkspaceFiles: true,
42
+ }, (err, data) => {
43
+ if (err === 'closed') {
44
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
45
+ process.exit(1);
46
+ }
47
+ else if (err) {
48
+ devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
49
+ }
50
+ else {
51
+ taskInfos.forEach((t) => t.assetsHandler.processWatchEvents(data.changedFiles));
52
+ }
61
53
  });
54
+ return () => unregisterFileWatcher();
62
55
  }
63
56
  exports.watchTaskProjectsFileChangesForAssets = watchTaskProjectsFileChangesForAssets;
@@ -13,20 +13,22 @@ function getTaskOptions(taskName, context) {
13
13
  tasksOptionsCache.set(taskName, normalizedTaskOptions);
14
14
  return normalizedTaskOptions;
15
15
  }
16
- catch (_a) {
16
+ catch {
17
17
  tasksOptionsCache.set(taskName, null);
18
18
  return null;
19
19
  }
20
20
  }
21
21
  exports.getTaskOptions = getTaskOptions;
22
22
  function parseTaskInfo(taskName, context) {
23
- var _a, _b;
24
23
  const target = context.taskGraph.tasks[taskName].target;
25
24
  const projectNode = context.projectGraph.nodes[target.project];
26
- const targetConfig = (_a = projectNode.data.targets) === null || _a === void 0 ? void 0 : _a[target.target];
25
+ const targetConfig = projectNode.data.targets?.[target.target];
27
26
  const { sourceRoot, root } = projectNode.data;
28
- const taskOptions = Object.assign(Object.assign({}, targetConfig.options), (target.configuration
29
- ? (_b = targetConfig.configurations) === null || _b === void 0 ? void 0 : _b[target.configuration]
30
- : {}));
27
+ const taskOptions = {
28
+ ...targetConfig.options,
29
+ ...(target.configuration
30
+ ? targetConfig.configurations?.[target.configuration]
31
+ : {}),
32
+ };
31
33
  return { taskOptions, root, sourceRoot, projectNode, target };
32
34
  }
@@ -14,7 +14,6 @@ function getProcessedTaskTsConfigs(tasks, tasksOptions, context) {
14
14
  exports.getProcessedTaskTsConfigs = getProcessedTaskTsConfigs;
15
15
  const projectTsConfigCache = new Map();
16
16
  function generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTsConfigMap) {
17
- var _a;
18
17
  const { project } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
19
18
  if (projectTsConfigCache.has(project)) {
20
19
  const { tsConfig, tsConfigPath } = projectTsConfigCache.get(project);
@@ -38,7 +37,8 @@ function generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTs
38
37
  projectReferences.push(tsConfigPath);
39
38
  }
40
39
  }
41
- const taskOptions = (_a = tasksOptions[taskWithTscExecutor]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskOptions)(taskWithTscExecutor, context);
40
+ const taskOptions = tasksOptions[taskWithTscExecutor] ??
41
+ (0, get_task_options_1.getTaskOptions)(taskWithTscExecutor, context);
42
42
  const tsConfigPath = taskOptions.tsConfig;
43
43
  taskInMemoryTsConfigMap[taskWithTscExecutor] = getInMemoryTsConfig(tsConfigPath, taskOptions, projectReferences);
44
44
  projectTsConfigCache.set(project, {
@@ -57,16 +57,27 @@ function getDependencyTasksInSameProject(task, context) {
57
57
  (0, devkit_1.parseTargetString)(t, context.projectGraph).project === taskProject);
58
58
  }
59
59
  function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences) {
60
- var _a;
61
60
  const originalTsConfig = (0, devkit_1.readJsonFile)(tsConfig, {
62
61
  allowTrailingComma: true,
63
62
  disallowComments: false,
64
63
  });
65
- const allProjectReferences = Array.from(new Set(((_a = originalTsConfig.references) !== null && _a !== void 0 ? _a : [])
64
+ const allProjectReferences = Array.from(new Set((originalTsConfig.references ?? [])
66
65
  .map((r) => r.path)
67
66
  .concat(projectReferences)));
68
67
  return {
69
- content: JSON.stringify(Object.assign(Object.assign({}, originalTsConfig), { compilerOptions: Object.assign(Object.assign({}, originalTsConfig.compilerOptions), { rootDir: taskOptions.rootDir, outDir: taskOptions.outputPath, composite: true, declaration: true, declarationMap: true, tsBuildInfoFile: (0, path_1.join)(taskOptions.outputPath, 'tsconfig.tsbuildinfo') }), references: allProjectReferences.map((pr) => ({ path: pr })) })),
68
+ content: JSON.stringify({
69
+ ...originalTsConfig,
70
+ compilerOptions: {
71
+ ...originalTsConfig.compilerOptions,
72
+ rootDir: taskOptions.rootDir,
73
+ outDir: taskOptions.outputPath,
74
+ composite: true,
75
+ declaration: true,
76
+ declarationMap: true,
77
+ tsBuildInfoFile: (0, path_1.join)(taskOptions.outputPath, 'tsconfig.tsbuildinfo'),
78
+ },
79
+ references: allProjectReferences.map((pr) => ({ path: pr })),
80
+ }),
70
81
  path: tsConfig.replace(/\\/g, '/'),
71
82
  };
72
83
  }
@@ -24,9 +24,16 @@ function normalizeOptions(options, contextRoot, sourceRoot, projectRoot) {
24
24
  }
25
25
  }
26
26
  const files = (0, assets_1.assetGlobsToFiles)(options.assets, contextRoot, outputPath);
27
- return Object.assign(Object.assign({}, options), { root: contextRoot, sourceRoot,
27
+ return {
28
+ ...options,
29
+ root: contextRoot,
30
+ sourceRoot,
28
31
  projectRoot,
29
32
  files,
30
- outputPath, tsConfig: (0, path_1.join)(contextRoot, options.tsConfig), rootDir, mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')) });
33
+ outputPath,
34
+ tsConfig: (0, path_1.join)(contextRoot, options.tsConfig),
35
+ rootDir,
36
+ mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')),
37
+ };
31
38
  }
32
39
  exports.normalizeOptions = normalizeOptions;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compileTypescriptSolution = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
6
5
  const ts = require("typescript");
7
6
  const get_custom_transformers_factory_1 = require("./get-custom-transformers-factory");
@@ -16,15 +15,15 @@ function compileTypescriptSolution(context, watch, logger, hooks, reporters) {
16
15
  if (watch) {
17
16
  // create an AsyncIterable that doesn't complete, watch mode is only
18
17
  // stopped by killing the process
19
- return (0, async_iterable_1.createAsyncIterable)(({ next }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
20
- hooks !== null && hooks !== void 0 ? hooks : (hooks = {});
18
+ return (0, async_iterable_1.createAsyncIterable)(async ({ next }) => {
19
+ hooks ??= {};
21
20
  const callerAfterProjectCompilationCallback = hooks.afterProjectCompilationCallback;
22
21
  hooks.afterProjectCompilationCallback = (tsConfig, success) => {
23
- callerAfterProjectCompilationCallback === null || callerAfterProjectCompilationCallback === void 0 ? void 0 : callerAfterProjectCompilationCallback(tsConfig, success);
22
+ callerAfterProjectCompilationCallback?.(tsConfig, success);
24
23
  next({ tsConfig, success });
25
24
  };
26
25
  compileTSWithWatch(context, logger, hooks, reporters);
27
- }));
26
+ });
28
27
  }
29
28
  // turn it into an AsyncIterable
30
29
  const compilationGenerator = compileTS(context, logger, hooks, reporters);
@@ -40,7 +39,6 @@ function compileTypescriptSolution(context, watch, logger, hooks, reporters) {
40
39
  }
41
40
  exports.compileTypescriptSolution = compileTypescriptSolution;
42
41
  function* compileTS(context, logger, hooks, reporters) {
43
- var _a, _b, _c;
44
42
  let project;
45
43
  const formatDiagnosticsHost = {
46
44
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
@@ -49,19 +47,17 @@ function* compileTS(context, logger, hooks, reporters) {
49
47
  };
50
48
  const solutionBuilderHost = ts.createSolutionBuilderHost(getSystem(context),
51
49
  /*createProgram*/ undefined, (diagnostic) => {
52
- var _a;
53
50
  const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatDiagnosticReport)(diagnostic, formatDiagnosticsHost);
54
51
  // handles edge case where a wrong a project reference path can't be read
55
52
  if (diagnostic.code === TYPESCRIPT_CANNOT_READ_FILE) {
56
53
  throw new Error(formattedDiagnostic);
57
54
  }
58
55
  logger.info(formattedDiagnostic, project.project);
59
- (_a = reporters === null || reporters === void 0 ? void 0 : reporters.diagnosticReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project.project, diagnostic);
56
+ reporters?.diagnosticReporter?.(project.project, diagnostic);
60
57
  }, (diagnostic) => {
61
- var _a;
62
58
  const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatSolutionBuilderStatusReport)(diagnostic);
63
59
  logger.info(formattedDiagnostic, project.project);
64
- (_a = reporters === null || reporters === void 0 ? void 0 : reporters.solutionBuilderStatusReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project.project, diagnostic);
60
+ reporters?.solutionBuilderStatusReporter?.(project.project, diagnostic);
65
61
  });
66
62
  const rootNames = Object.keys(context);
67
63
  const solutionBuilder = ts.createSolutionBuilder(solutionBuilderHost, rootNames, {});
@@ -72,7 +68,7 @@ function* compileTS(context, logger, hooks, reporters) {
72
68
  break;
73
69
  }
74
70
  const projectContext = context[project.project];
75
- const projectName = projectContext === null || projectContext === void 0 ? void 0 : projectContext.project;
71
+ const projectName = projectContext?.project;
76
72
  /**
77
73
  * This only applies when the deprecated `prepend` option is set to `true`.
78
74
  * Skip support.
@@ -83,7 +79,7 @@ function* compileTS(context, logger, hooks, reporters) {
83
79
  `This option is not supported by the batch executor and it's ignored.\n`, project.project);
84
80
  continue;
85
81
  }
86
- (_a = hooks === null || hooks === void 0 ? void 0 : hooks.beforeProjectCompilationCallback) === null || _a === void 0 ? void 0 : _a.call(hooks, project.project);
82
+ hooks?.beforeProjectCompilationCallback?.(project.project);
87
83
  if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
88
84
  logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
89
85
  // update output timestamps and mark project as complete
@@ -92,7 +88,7 @@ function* compileTS(context, logger, hooks, reporters) {
92
88
  if (success) {
93
89
  logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
94
90
  }
95
- (_b = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _b === void 0 ? void 0 : _b.call(hooks, project.project, success);
91
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
96
92
  yield { success, tsConfig: project.project };
97
93
  continue;
98
94
  }
@@ -103,7 +99,7 @@ function* compileTS(context, logger, hooks, reporters) {
103
99
  if (success) {
104
100
  logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
105
101
  }
106
- (_c = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _c === void 0 ? void 0 : _c.call(hooks, project.project, success);
102
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
107
103
  yield {
108
104
  success: status === ts.ExitStatus.Success,
109
105
  tsConfig: project.project,
@@ -114,14 +110,14 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
114
110
  let project;
115
111
  const solutionHost = ts.createSolutionBuilderWithWatchHost(getSystem(context),
116
112
  /*createProgram*/ undefined);
117
- if (reporters === null || reporters === void 0 ? void 0 : reporters.diagnosticReporter) {
113
+ if (reporters?.diagnosticReporter) {
118
114
  const originalDiagnosticReporter = solutionHost.reportDiagnostic;
119
115
  solutionHost.reportDiagnostic = (diagnostic) => {
120
116
  originalDiagnosticReporter(diagnostic);
121
117
  reporters.diagnosticReporter(project.project, diagnostic);
122
118
  };
123
119
  }
124
- if (reporters === null || reporters === void 0 ? void 0 : reporters.solutionBuilderStatusReporter) {
120
+ if (reporters?.solutionBuilderStatusReporter) {
125
121
  const originalSolutionBuilderStatusReporter = solutionHost.reportSolutionBuilderStatus;
126
122
  solutionHost.reportDiagnostic = (diagnostic) => {
127
123
  originalSolutionBuilderStatusReporter(diagnostic);
@@ -130,19 +126,17 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
130
126
  }
131
127
  const originalWatchStatusReporter = solutionHost.onWatchStatusChange;
132
128
  solutionHost.onWatchStatusChange = (diagnostic, newLine, options, errorCount) => {
133
- var _a;
134
129
  originalWatchStatusReporter(diagnostic, newLine, options, errorCount);
135
130
  if (diagnostic.code ===
136
131
  TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION) {
137
132
  // there's a change, build invalidated projects
138
133
  build();
139
134
  }
140
- (_a = reporters === null || reporters === void 0 ? void 0 : reporters.watchStatusReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project === null || project === void 0 ? void 0 : project.project, diagnostic, newLine, options, errorCount);
135
+ reporters?.watchStatusReporter?.(project?.project, diagnostic, newLine, options, errorCount);
141
136
  };
142
137
  const rootNames = Object.keys(context);
143
138
  const solutionBuilder = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {});
144
139
  const build = () => {
145
- var _a, _b;
146
140
  while (true) {
147
141
  project = solutionBuilder.getNextInvalidatedProject();
148
142
  if (!project) {
@@ -160,7 +154,7 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
160
154
  `This option is not supported by the batch executor and it's ignored.`);
161
155
  continue;
162
156
  }
163
- hooks === null || hooks === void 0 ? void 0 : hooks.beforeProjectCompilationCallback(project.project);
157
+ hooks?.beforeProjectCompilationCallback(project.project);
164
158
  if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
165
159
  if (projectName) {
166
160
  logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
@@ -171,7 +165,7 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
171
165
  if (projectName && success) {
172
166
  logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
173
167
  }
174
- (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _a === void 0 ? void 0 : _a.call(hooks, project.project, success);
168
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
175
169
  continue;
176
170
  }
177
171
  logger.info(`Compiling TypeScript files for project "${projectName}"...\n`, project.project);
@@ -181,7 +175,7 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
181
175
  if (success) {
182
176
  logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
183
177
  }
184
- (_b = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _b === void 0 ? void 0 : _b.call(hooks, project.project, success);
178
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
185
179
  }
186
180
  };
187
181
  // initial build
@@ -197,10 +191,13 @@ function compileTSWithWatch(context, logger, hooks, reporters) {
197
191
  solutionBuilder.build();
198
192
  }
199
193
  function getSystem(context) {
200
- return Object.assign(Object.assign({}, ts.sys), { readFile(path, encoding) {
194
+ return {
195
+ ...ts.sys,
196
+ readFile(path, encoding) {
201
197
  if (context[path]) {
202
198
  return context[path].tsConfig.content;
203
199
  }
204
200
  return ts.sys.readFile(path, encoding);
205
- } });
201
+ },
202
+ };
206
203
  }