@nx/js 16.4.0-beta.1 → 16.4.0-beta.10

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 (59) hide show
  1. package/executors.json +1 -0
  2. package/generators.json +12 -0
  3. package/package.json +6 -5
  4. package/plugins/jest/local-registry.d.ts +1 -0
  5. package/plugins/jest/local-registry.js +4 -0
  6. package/src/executors/node/node.impl.js +57 -7
  7. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +4 -0
  8. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +54 -0
  9. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.d.ts +3 -0
  10. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.js +52 -0
  11. package/src/executors/tsc/lib/batch/get-task-options.d.ts +3 -0
  12. package/src/executors/tsc/lib/batch/get-task-options.js +24 -0
  13. package/src/executors/tsc/lib/batch/index.d.ts +8 -0
  14. package/src/executors/tsc/lib/batch/index.js +11 -0
  15. package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
  16. package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
  17. package/src/executors/tsc/lib/batch/types.d.ts +12 -0
  18. package/src/executors/tsc/lib/batch/types.js +2 -0
  19. package/src/executors/tsc/lib/batch/typescript-compilation.d.ts +7 -0
  20. package/src/executors/tsc/lib/batch/typescript-compilation.js +195 -0
  21. package/src/executors/tsc/lib/batch/typescript-diagnostic-reporters.d.ts +4 -0
  22. package/src/executors/tsc/lib/batch/typescript-diagnostic-reporters.js +44 -0
  23. package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
  24. package/src/executors/tsc/lib/batch/watch.js +63 -0
  25. package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
  26. package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
  27. package/src/executors/tsc/lib/index.d.ts +2 -0
  28. package/src/executors/tsc/lib/index.js +5 -0
  29. package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
  30. package/src/executors/tsc/lib/normalize-options.js +32 -0
  31. package/src/executors/tsc/tsc.batch-impl.d.ts +4 -0
  32. package/src/executors/tsc/tsc.batch-impl.js +47 -0
  33. package/src/executors/tsc/tsc.impl.d.ts +0 -1
  34. package/src/executors/tsc/tsc.impl.js +4 -39
  35. package/src/executors/verdaccio/verdaccio.impl.d.ts +1 -0
  36. package/src/executors/verdaccio/verdaccio.impl.js +25 -22
  37. package/src/generators/library/library.js +2 -10
  38. package/src/generators/library/schema.json +7 -6
  39. package/src/generators/setup-build/generator.d.ts +5 -0
  40. package/src/generators/setup-build/generator.js +133 -0
  41. package/src/generators/setup-build/schema.d.ts +7 -0
  42. package/src/generators/setup-build/schema.json +42 -0
  43. package/src/generators/setup-verdaccio/files/config.yml +1 -1
  44. package/src/generators/setup-verdaccio/generator.js +5 -1
  45. package/src/index.d.ts +1 -0
  46. package/src/index.js +1 -0
  47. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  48. package/src/plugins/jest/start-local-registry.js +61 -0
  49. package/src/utils/add-babel-inputs.d.ts +1 -0
  50. package/src/utils/add-babel-inputs.js +2 -0
  51. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  52. package/src/utils/add-local-registry-scripts.js +57 -0
  53. package/src/utils/assets/copy-assets-handler.d.ts +5 -1
  54. package/src/utils/assets/copy-assets-handler.js +34 -23
  55. package/src/utils/inline.d.ts +1 -1
  56. package/src/utils/inline.js +3 -3
  57. package/src/utils/minimal-publish-script.js +2 -5
  58. package/src/utils/schema.d.ts +3 -2
  59. package/src/utils/swc/add-swc-config.d.ts +1 -1
package/executors.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "executors": {
4
4
  "tsc": {
5
5
  "implementation": "./src/executors/tsc/tsc.impl",
6
+ "batchImplementation": "./src/executors/tsc/tsc.batch-impl",
6
7
  "schema": "./src/executors/tsc/schema.json",
7
8
  "description": "Build a project using TypeScript."
8
9
  },
package/generators.json CHANGED
@@ -29,6 +29,12 @@
29
29
  "schema": "./src/generators/setup-verdaccio/schema.json",
30
30
  "alias": ["verdaccio"],
31
31
  "description": "Setup Verdaccio for local package management."
32
+ },
33
+ "setup-build": {
34
+ "factory": "./src/generators/setup-build/generator#setupBuildSchematic",
35
+ "schema": "./src/generators/setup-build/schema.json",
36
+ "alias": ["build"],
37
+ "description": "setup-build generator"
32
38
  }
33
39
  },
34
40
  "generators": {
@@ -59,6 +65,12 @@
59
65
  "schema": "./src/generators/setup-verdaccio/schema.json",
60
66
  "alias": ["verdaccio"],
61
67
  "description": "Setup Verdaccio for local package management."
68
+ },
69
+ "setup-build": {
70
+ "factory": "./src/generators/setup-build/generator",
71
+ "schema": "./src/generators/setup-build/schema.json",
72
+ "alias": ["build"],
73
+ "description": "setup-build generator"
62
74
  }
63
75
  }
64
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "16.4.0-beta.1",
3
+ "version": "16.4.0-beta.10",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,14 +39,15 @@
39
39
  "@babel/preset-env": "^7.15.0",
40
40
  "@babel/preset-typescript": "^7.15.0",
41
41
  "@babel/runtime": "^7.14.8",
42
- "@nrwl/js": "16.4.0-beta.1",
43
- "@nx/devkit": "16.4.0-beta.1",
44
- "@nx/workspace": "16.4.0-beta.1",
42
+ "@nrwl/js": "16.4.0-beta.10",
43
+ "@nx/devkit": "16.4.0-beta.10",
44
+ "@nx/workspace": "16.4.0-beta.10",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
48
48
  "babel-plugin-transform-typescript-metadata": "^0.3.1",
49
49
  "chalk": "^4.1.0",
50
+ "detect-port": "^1.5.1",
50
51
  "fast-glob": "3.2.7",
51
52
  "fs-extra": "^11.1.0",
52
53
  "ignore": "^5.0.4",
@@ -68,5 +69,5 @@
68
69
  "access": "public"
69
70
  },
70
71
  "types": "./src/index.d.ts",
71
- "gitHead": "1c4fb934b607f0d93bb23bff2cf0f39b31a8fa43"
72
+ "gitHead": "d2bde0605c692a023bc9c28686f3a3037bbd56d3"
72
73
  }
@@ -0,0 +1 @@
1
+ export * from '../../src/plugins/jest/start-local-registry';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("../../src/plugins/jest/start-local-registry"), exports);
@@ -8,9 +8,11 @@ const devkit_1 = require("@nx/devkit");
8
8
  const client_1 = require("nx/src/daemon/client/client");
9
9
  const crypto_1 = require("crypto");
10
10
  const path_1 = require("path");
11
+ const path = require("path");
11
12
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
12
13
  const buildable_libs_utils_1 = require("../../utils/buildable-libs-utils");
13
14
  const kill_tree_1 = require("./lib/kill-tree");
15
+ const fileutils_1 = require("nx/src/utils/fileutils");
14
16
  function debounce(fn, wait) {
15
17
  let timeoutId;
16
18
  return () => {
@@ -25,13 +27,25 @@ function nodeExecutor(options, context) {
25
27
  (_a = (_e = process.env).NODE_ENV) !== null && _a !== void 0 ? _a : (_e.NODE_ENV = (_b = context === null || context === void 0 ? void 0 : context.configurationName) !== null && _b !== void 0 ? _b : 'development');
26
28
  const project = context.projectGraph.nodes[context.projectName];
27
29
  const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
28
- const buildOptions = (_c = project.data.targets[buildTarget.target]) === null || _c === void 0 ? void 0 : _c.options;
29
- if (!buildOptions) {
30
+ let buildOptions;
31
+ if (project.data.targets[buildTarget.target]) {
32
+ buildOptions = Object.assign(Object.assign({}, (_c = project.data.targets[buildTarget.target]) === null || _c === void 0 ? void 0 : _c.options), options.buildTargetOptions);
33
+ }
34
+ else {
30
35
  throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
31
36
  }
37
+ if (options.waitUntilTargets && options.waitUntilTargets.length > 0) {
38
+ const results = yield tslib_1.__await(runWaitUntilTargets(options, context));
39
+ for (const [i, result] of results.entries()) {
40
+ if (!result.success) {
41
+ throw new Error(`Wait until target failed: ${options.waitUntilTargets[i]}.`);
42
+ }
43
+ }
44
+ }
32
45
  // Re-map buildable workspace projects to their output directory.
33
46
  const mappings = calculateResolveMappings(context, options);
34
- const fileToRun = (0, path_1.join)(context.root, buildOptions.outputPath, (_d = buildOptions.outputFileName) !== null && _d !== void 0 ? _d : 'main.js');
47
+ const outputFileName = (_d = buildOptions.outputFileName) !== null && _d !== void 0 ? _d : `${path.parse(buildOptions.main).name}.js`;
48
+ const fileToRun = (0, path_1.join)(context.root, buildOptions.outputPath, outputFileName);
35
49
  const tasks = [];
36
50
  let currentTask = null;
37
51
  yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ done, next, error }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -90,15 +104,16 @@ function nodeExecutor(options, context) {
90
104
  // Run the program
91
105
  task.promise = new Promise((resolve, reject) => {
92
106
  var _a;
93
- task.childProcess = (0, child_process_1.fork)((0, devkit_1.joinPathFragments)(__dirname, 'node-with-require-overrides'), (_a = options.runtimeArgs) !== null && _a !== void 0 ? _a : [], {
107
+ task.childProcess = (0, child_process_1.fork)((0, devkit_1.joinPathFragments)(__dirname, 'node-with-require-overrides'), (_a = options.args) !== null && _a !== void 0 ? _a : [], {
94
108
  execArgv: getExecArgv(options),
95
109
  stdio: [0, 1, 'pipe', 'ipc'],
96
- env: Object.assign(Object.assign({}, process.env), { NX_FILE_TO_RUN: fileToRun, NX_MAPPINGS: JSON.stringify(mappings) }),
110
+ env: Object.assign(Object.assign({}, process.env), { NX_FILE_TO_RUN: fileToRunCorrectPath(fileToRun), NX_MAPPINGS: JSON.stringify(mappings) }),
97
111
  });
98
112
  task.childProcess.stderr.on('data', (data) => {
99
113
  // Don't log out error if task is killed and new one has started.
100
114
  // This could happen if a new build is triggered while new process is starting, since the operation is not atomic.
101
- if (options.watch && !task.killed) {
115
+ // Log the error in normal mode
116
+ if (!options.watch || !task.killed) {
102
117
  devkit_1.logger.error(data.toString());
103
118
  }
104
119
  });
@@ -171,7 +186,9 @@ function nodeExecutor(options, context) {
171
186
  }
172
187
  exports.nodeExecutor = nodeExecutor;
173
188
  function getExecArgv(options) {
174
- const args = ['-r', require.resolve('source-map-support/register')];
189
+ var _a;
190
+ const args = ((_a = options.runtimeArgs) !== null && _a !== void 0 ? _a : (options.runtimeArgs = []));
191
+ args.push('-r', require.resolve('source-map-support/register'));
175
192
  if (options.inspect === true) {
176
193
  options.inspect = "inspect" /* InspectType.Inspect */;
177
194
  }
@@ -190,4 +207,37 @@ function calculateResolveMappings(context, options) {
190
207
  return m;
191
208
  }, {});
192
209
  }
210
+ function runWaitUntilTargets(options, context) {
211
+ return Promise.all(options.waitUntilTargets.map((waitUntilTarget) => tslib_1.__awaiter(this, void 0, void 0, function* () {
212
+ const target = (0, devkit_1.parseTargetString)(waitUntilTarget, context.projectGraph);
213
+ const output = yield (0, devkit_1.runExecutor)(target, {}, context);
214
+ return new Promise((resolve) => tslib_1.__awaiter(this, void 0, void 0, function* () {
215
+ let event = yield output.next();
216
+ // Resolve after first event
217
+ resolve(event.value);
218
+ // Continue iterating
219
+ while (!event.done) {
220
+ event = yield output.next();
221
+ }
222
+ }));
223
+ })));
224
+ }
225
+ function fileToRunCorrectPath(fileToRun) {
226
+ if (!(0, fileutils_1.fileExists)(fileToRun)) {
227
+ const cjsFile = fileToRun.replace(/\.js$/, '.cjs');
228
+ if ((0, fileutils_1.fileExists)(cjsFile)) {
229
+ fileToRun = cjsFile;
230
+ }
231
+ else {
232
+ const mjsFile = fileToRun.replace(/\.js$/, '.mjs');
233
+ if ((0, fileutils_1.fileExists)(mjsFile)) {
234
+ fileToRun = mjsFile;
235
+ }
236
+ else {
237
+ throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
238
+ }
239
+ }
240
+ }
241
+ return fileToRun;
242
+ }
193
243
  exports.default = nodeExecutor;
@@ -0,0 +1,4 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ import type { TaskInfo } from './types';
4
+ export declare function buildTaskInfoPerTsConfigMap(tsConfigTaskInfoMap: Record<string, TaskInfo>, tasksOptions: Record<string, NormalizedExecutorOptions>, context: ExecutorContext, tasks: string[], shouldWatch: boolean): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTaskInfoPerTsConfigMap = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const copy_assets_handler_1 = require("../../../../utils/assets/copy-assets-handler");
6
+ const buildable_libs_utils_1 = require("../../../../utils/buildable-libs-utils");
7
+ const generate_temp_tsconfig_1 = require("./generate-temp-tsconfig");
8
+ const get_task_options_1 = require("./get-task-options");
9
+ const taskTsConfigCache = new Set();
10
+ function buildTaskInfoPerTsConfigMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, shouldWatch) {
11
+ for (const taskName of tasks) {
12
+ if (taskTsConfigCache.has(taskName)) {
13
+ continue;
14
+ }
15
+ let taskOptions = tasksOptions[taskName];
16
+ // task is in the batch (it's meant to be processed), create TaskInfo
17
+ if (taskOptions) {
18
+ const taskInfo = createTaskInfo(taskName, taskOptions, context);
19
+ const tsConfigPath = (0, generate_temp_tsconfig_1.generateTempTsConfig)(tasksOptions, taskName, taskOptions, context);
20
+ tsConfigTaskInfoMap[tsConfigPath] = taskInfo;
21
+ taskTsConfigCache.add(taskName);
22
+ }
23
+ else {
24
+ // if it's not included in the provided map, it could be a cached task and
25
+ // we need to pull the options from the relevant project graph node
26
+ taskOptions = (0, get_task_options_1.getTaskOptions)(taskName, context);
27
+ (0, generate_temp_tsconfig_1.generateTempTsConfig)(tasksOptions, taskName, taskOptions, context);
28
+ }
29
+ buildTaskInfoPerTsConfigMap(tsConfigTaskInfoMap, tasksOptions, context, context.taskGraph.dependencies[taskName], shouldWatch);
30
+ }
31
+ }
32
+ exports.buildTaskInfoPerTsConfigMap = buildTaskInfoPerTsConfigMap;
33
+ function createTaskInfo(taskName, taskOptions, context) {
34
+ const target = (0, devkit_1.parseTargetString)(taskName, context.projectGraph);
35
+ const taskContext = Object.assign(Object.assign({}, context), {
36
+ // batch executors don't get these in the context, we provide them
37
+ // here per task
38
+ projectName: target.project, targetName: target.target, configurationName: target.configuration });
39
+ const assetsHandler = new copy_assets_handler_1.CopyAssetsHandler({
40
+ projectDir: taskOptions.projectRoot,
41
+ rootDir: context.root,
42
+ outputDir: taskOptions.outputPath,
43
+ assets: taskOptions.assets,
44
+ });
45
+ const { target: projectGraphNode, dependencies: buildableProjectNodeDependencies, } = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph, context.root, context.taskGraph.tasks[taskName].target.project, context.taskGraph.tasks[taskName].target.target, context.taskGraph.tasks[taskName].target.configuration);
46
+ return {
47
+ task: taskName,
48
+ options: taskOptions,
49
+ context: taskContext,
50
+ assetsHandler,
51
+ buildableProjectNodeDependencies,
52
+ projectGraphNode,
53
+ };
54
+ }
@@ -0,0 +1,3 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ export declare function generateTempTsConfig(taskOptionsMap: Record<string, NormalizedExecutorOptions>, taskName: string, taskOptions: NormalizedExecutorOptions, context: ExecutorContext): string;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTempTsConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const ts = require("typescript");
7
+ const get_task_options_1 = require("./get-task-options");
8
+ function generateTempTsConfig(taskOptionsMap, taskName, taskOptions, context) {
9
+ const tmpDir = (0, path_1.join)(context.root, 'tmp');
10
+ const originalTsConfigPath = taskOptions.tsConfig;
11
+ const tmpTsConfigPath = (0, path_1.join)(tmpDir, (0, path_1.relative)(context.root, originalTsConfigPath));
12
+ const projectReferences = [];
13
+ for (const depTask of context.taskGraph.dependencies[taskName]) {
14
+ // if included in the provided map, use it
15
+ if (taskOptionsMap[depTask]) {
16
+ projectReferences.push({
17
+ path: (0, path_1.join)(tmpDir, (0, path_1.relative)(context.root, taskOptionsMap[depTask].tsConfig)),
18
+ });
19
+ continue;
20
+ }
21
+ // if it's not included in the provided map, it could be a cached task and
22
+ // we need to pull the tsconfig from the relevant project graph node
23
+ const options = (0, get_task_options_1.getTaskOptions)(depTask, context);
24
+ if (options.tsConfig) {
25
+ projectReferences.push({
26
+ path: (0, path_1.join)(tmpDir, (0, path_1.relative)(context.root, options.tsConfig)),
27
+ });
28
+ }
29
+ }
30
+ (0, devkit_1.writeJsonFile)(tmpTsConfigPath, {
31
+ extends: (0, devkit_1.normalizePath)((0, path_1.relative)((0, path_1.dirname)(tmpTsConfigPath), taskOptions.tsConfig)),
32
+ compilerOptions: {
33
+ rootDir: taskOptions.rootDir,
34
+ outDir: taskOptions.outputPath,
35
+ composite: true,
36
+ declaration: true,
37
+ declarationMap: true,
38
+ tsBuildInfoFile: (0, devkit_1.joinPathFragments)(taskOptions.outputPath, 'tsconfig.tsbuildinfo'),
39
+ },
40
+ references: projectReferences,
41
+ });
42
+ /**
43
+ * Ensure the temp tsconfig has the same modified date as the original.
44
+ * Typescript compares this against the modified date of the tsbuildinfo
45
+ * file. If the tsbuildinfo file is older, the cache is invalidated.
46
+ * Since we always generate the temp tsconfig, any existing tsbuildinfo
47
+ * file will be older even if they are not older than the original tsconfig.
48
+ */
49
+ ts.sys.setModifiedTime(tmpTsConfigPath, ts.sys.getModifiedTime(originalTsConfigPath));
50
+ return tmpTsConfigPath;
51
+ }
52
+ exports.generateTempTsConfig = generateTempTsConfig;
@@ -0,0 +1,3 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ export declare function getTaskOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTaskOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const normalize_options_1 = require("../normalize-options");
6
+ const tasksOptionsCache = new Map();
7
+ function getTaskOptions(taskName, context) {
8
+ var _a, _b;
9
+ if (tasksOptionsCache.has(taskName)) {
10
+ return tasksOptionsCache.get(taskName);
11
+ }
12
+ const target = context.taskGraph.tasks[taskName].target;
13
+ const projectNode = context.projectGraph.nodes[target.project];
14
+ const targetConfig = (_a = projectNode.data.targets) === null || _a === void 0 ? void 0 : _a[target.target];
15
+ const taskOptions = Object.assign(Object.assign({}, targetConfig.options), (target.configuration
16
+ ? (_b = targetConfig.configurations) === null || _b === void 0 ? void 0 : _b[target.configuration]
17
+ : {}));
18
+ const { project } = (0, devkit_1.parseTargetString)(taskName, context.projectGraph);
19
+ const { sourceRoot, root } = context.projectsConfigurations.projects[project];
20
+ const normalizedTaskOptions = (0, normalize_options_1.normalizeOptions)(taskOptions, context.root, sourceRoot, root);
21
+ tasksOptionsCache.set(taskName, normalizedTaskOptions);
22
+ return normalizedTaskOptions;
23
+ }
24
+ exports.getTaskOptions = getTaskOptions;
@@ -0,0 +1,8 @@
1
+ export * from './build-task-info-per-tsconfig-map';
2
+ export * from './generate-temp-tsconfig';
3
+ export * from './get-task-options';
4
+ export * from './normalize-tasks-options';
5
+ export * from './types';
6
+ export * from './typescript-compilation';
7
+ export * from './typescript-diagnostic-reporters';
8
+ export * from './watch';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./build-task-info-per-tsconfig-map"), exports);
5
+ tslib_1.__exportStar(require("./generate-temp-tsconfig"), exports);
6
+ tslib_1.__exportStar(require("./get-task-options"), exports);
7
+ tslib_1.__exportStar(require("./normalize-tasks-options"), exports);
8
+ tslib_1.__exportStar(require("./types"), exports);
9
+ tslib_1.__exportStar(require("./typescript-compilation"), exports);
10
+ tslib_1.__exportStar(require("./typescript-diagnostic-reporters"), exports);
11
+ tslib_1.__exportStar(require("./watch"), exports);
@@ -0,0 +1,3 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { ExecutorOptions, NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ export declare function normalizeTasksOptions(inputs: Record<string, ExecutorOptions>, context: ExecutorContext): Record<string, NormalizedExecutorOptions>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeTasksOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const normalize_options_1 = require("../normalize-options");
6
+ function normalizeTasksOptions(inputs, context) {
7
+ return Object.entries(inputs).reduce((tasksOptions, [taskName, options]) => {
8
+ const { project } = (0, devkit_1.parseTargetString)(taskName, context.projectGraph);
9
+ const { sourceRoot, root } = context.projectsConfigurations.projects[project];
10
+ tasksOptions[taskName] = (0, normalize_options_1.normalizeOptions)(options, context.root, sourceRoot, root);
11
+ return tasksOptions;
12
+ }, {});
13
+ }
14
+ exports.normalizeTasksOptions = normalizeTasksOptions;
@@ -0,0 +1,12 @@
1
+ import type { ExecutorContext, ProjectGraphProjectNode } from '@nx/devkit';
2
+ import type { CopyAssetsHandler } from '../../../../utils/assets/copy-assets-handler';
3
+ import type { DependentBuildableProjectNode } from '../../../../utils/buildable-libs-utils';
4
+ import type { NormalizedExecutorOptions } from '../../../../utils/schema';
5
+ export interface TaskInfo {
6
+ task: string;
7
+ options: NormalizedExecutorOptions;
8
+ context: ExecutorContext;
9
+ assetsHandler: CopyAssetsHandler;
10
+ buildableProjectNodeDependencies: DependentBuildableProjectNode[];
11
+ projectGraphNode: ProjectGraphProjectNode;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import type { TaskGraph } from '@nx/devkit';
2
+ import type { BatchResults } from 'nx/src/tasks-runner/batch/batch-messages';
3
+ import type { TaskInfo } from './types';
4
+ export declare function compileBatchTypescript(tsConfigTaskInfoMap: Record<string, TaskInfo>, taskGraph: TaskGraph, watch: boolean, postProjectCompilationCallback: (taskInfo: TaskInfo) => void): {
5
+ iterator: AsyncIterable<BatchResults>;
6
+ close: () => void | Promise<void>;
7
+ };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileBatchTypescript = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
6
+ const ts = require("typescript");
7
+ const get_custom_transformers_factory_1 = require("../get-custom-transformers-factory");
8
+ const typescript_diagnostic_reporters_1 = require("./typescript-diagnostic-reporters");
9
+ // https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4050-L4053
10
+ // Typescript diagnostic message for 5083: Cannot read file '{0}'.
11
+ const TYPESCRIPT_CANNOT_READ_FILE = 5083;
12
+ // https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4211-4214
13
+ // Typescript diagnostic message for 6032: File change detected. Starting incremental compilation...
14
+ const TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION = 6032;
15
+ function compileBatchTypescript(tsConfigTaskInfoMap, taskGraph, watch, postProjectCompilationCallback) {
16
+ const timeNow = Date.now();
17
+ const defaultResults = Object.keys(taskGraph.tasks).reduce((acc, task) => {
18
+ acc[task] = { success: true, startTime: timeNow, terminalOutput: '' };
19
+ return acc;
20
+ }, {});
21
+ let tearDown;
22
+ return {
23
+ iterator: (0, async_iterable_1.createAsyncIterable)(({ next, done }) => {
24
+ if (watch) {
25
+ compileTSWithWatch(tsConfigTaskInfoMap, postProjectCompilationCallback);
26
+ tearDown = () => {
27
+ done();
28
+ };
29
+ }
30
+ else {
31
+ const compilationResults = compileTS(tsConfigTaskInfoMap, postProjectCompilationCallback);
32
+ next(Object.assign(Object.assign({}, defaultResults), compilationResults));
33
+ done();
34
+ }
35
+ }),
36
+ close: () => tearDown === null || tearDown === void 0 ? void 0 : tearDown(),
37
+ };
38
+ }
39
+ exports.compileBatchTypescript = compileBatchTypescript;
40
+ function compileTSWithWatch(tsConfigTaskInfoMap, postProjectCompilationCallback) {
41
+ const formatDiagnosticsHost = {
42
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
43
+ getNewLine: () => ts.sys.newLine,
44
+ getCanonicalFileName: (filename) => ts.sys.useCaseSensitiveFileNames ? filename : filename.toLowerCase(),
45
+ };
46
+ const solutionHost = ts.createSolutionBuilderWithWatchHost(ts.sys,
47
+ /*createProgram*/ undefined, (diagnostic) => {
48
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatDiagnosticReport)(diagnostic, formatDiagnosticsHost);
49
+ devkit_1.logger.info(formattedDiagnostic);
50
+ }, (diagnostic) => {
51
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatSolutionBuilderStatusReport)(diagnostic);
52
+ devkit_1.logger.info(formattedDiagnostic);
53
+ }, (diagnostic, newLine) => {
54
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatWatchStatusReport)(diagnostic, newLine);
55
+ devkit_1.logger.info(formattedDiagnostic);
56
+ if (diagnostic.code ===
57
+ TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION) {
58
+ // there's a change, build invalidated projects
59
+ build();
60
+ }
61
+ });
62
+ const rootNames = Object.keys(tsConfigTaskInfoMap);
63
+ const solutionBuilder = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {});
64
+ const build = () => {
65
+ while (true) {
66
+ const project = solutionBuilder.getNextInvalidatedProject();
67
+ if (!project) {
68
+ break;
69
+ }
70
+ const taskInfo = tsConfigTaskInfoMap[project.project];
71
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
72
+ // update output timestamps and mark project as complete
73
+ project.done();
74
+ continue;
75
+ }
76
+ /**
77
+ * This only applies when the deprecated `prepend` option is set to `true`.
78
+ * Skip support.
79
+ */
80
+ if (project.kind === ts.InvalidatedProjectKind.UpdateBundle) {
81
+ devkit_1.logger.warn(`The project ${taskInfo.context.projectName} ` +
82
+ `is using the deprecated "prepend" Typescript compiler option. ` +
83
+ `This option is not supported by the batch executor and it's ignored.`);
84
+ continue;
85
+ }
86
+ // build and mark project as complete
87
+ project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(taskInfo.options.transformers)(project.getProgram()));
88
+ postProjectCompilationCallback(taskInfo);
89
+ }
90
+ };
91
+ // initial build
92
+ build();
93
+ /**
94
+ * This is a workaround to get the TS file watching to kick off. It won't
95
+ * build twice since the `build` call above will mark invalidated projects
96
+ * as completed and then, the implementation of the `solutionBuilder.build`
97
+ * skips them.
98
+ * We can't rely solely in `solutionBuilder.build()` because it doesn't
99
+ * accept custom transformers.
100
+ */
101
+ solutionBuilder.build();
102
+ return solutionHost;
103
+ }
104
+ function compileTS(tsConfigTaskInfoMap, postProjectCompilationCallback) {
105
+ var _a;
106
+ const results = {};
107
+ let terminalOutput;
108
+ const logInfo = (text) => {
109
+ devkit_1.logger.info(text);
110
+ terminalOutput += `${text}\n`;
111
+ };
112
+ const logWarn = (text) => {
113
+ devkit_1.logger.warn(text);
114
+ terminalOutput += `${text}\n`;
115
+ };
116
+ const formatDiagnosticsHost = {
117
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
118
+ getNewLine: () => ts.sys.newLine,
119
+ getCanonicalFileName: (filename) => ts.sys.useCaseSensitiveFileNames ? filename : filename.toLowerCase(),
120
+ };
121
+ const solutionBuilderHost = ts.createSolutionBuilderHost(ts.sys,
122
+ /*createProgram*/ undefined, (diagnostic) => {
123
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatDiagnosticReport)(diagnostic, formatDiagnosticsHost);
124
+ // handles edge case where a wrong a project reference path can't be read
125
+ if (diagnostic.code === TYPESCRIPT_CANNOT_READ_FILE) {
126
+ Object.values(tsConfigTaskInfoMap).forEach((taskInfo) => {
127
+ var _a, _b;
128
+ var _c;
129
+ (_a = results[_c = taskInfo.task]) !== null && _a !== void 0 ? _a : (results[_c] = { success: false, terminalOutput: '' });
130
+ results[taskInfo.task].success = false;
131
+ results[taskInfo.task].terminalOutput = `${(_b = results[taskInfo.task]) === null || _b === void 0 ? void 0 : _b.terminalOutput}${formattedDiagnostic}`;
132
+ });
133
+ }
134
+ logInfo(formattedDiagnostic);
135
+ }, (diagnostic) => {
136
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatSolutionBuilderStatusReport)(diagnostic);
137
+ logInfo(formattedDiagnostic);
138
+ });
139
+ const rootNames = Object.keys(tsConfigTaskInfoMap);
140
+ const solutionBuilder = ts.createSolutionBuilder(solutionBuilderHost, rootNames, {});
141
+ // eslint-disable-next-line no-constant-condition
142
+ while (true) {
143
+ const project = solutionBuilder.getNextInvalidatedProject();
144
+ if (!project) {
145
+ break;
146
+ }
147
+ const startTime = Date.now();
148
+ terminalOutput = '';
149
+ const taskInfo = tsConfigTaskInfoMap[project.project];
150
+ const projectName = (_a = taskInfo === null || taskInfo === void 0 ? void 0 : taskInfo.context) === null || _a === void 0 ? void 0 : _a.projectName;
151
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
152
+ if (projectName) {
153
+ logInfo(`Updating output timestamps of project "${projectName}"...`);
154
+ }
155
+ // update output timestamps and mark project as complete
156
+ const status = project.done();
157
+ if (projectName && status === ts.ExitStatus.Success) {
158
+ logInfo(`Done updating output timestamps of project "${projectName}"...`);
159
+ }
160
+ if (taskInfo) {
161
+ results[taskInfo.task] = {
162
+ success: status === ts.ExitStatus.Success,
163
+ terminalOutput,
164
+ startTime,
165
+ endTime: Date.now(),
166
+ };
167
+ }
168
+ continue;
169
+ }
170
+ /**
171
+ * This only applies when the deprecated `prepend` option is set to `true`.
172
+ * Skip support.
173
+ */
174
+ if (project.kind === ts.InvalidatedProjectKind.UpdateBundle) {
175
+ logWarn(`The project ${taskInfo.context.projectName} ` +
176
+ `is using the deprecated "prepend" Typescript compiler option. ` +
177
+ `This option is not supported by the batch executor and it's ignored.`);
178
+ continue;
179
+ }
180
+ logInfo(`Compiling TypeScript files for project "${projectName}"...`);
181
+ // build and mark project as complete
182
+ const status = project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(taskInfo.options.transformers)(project.getProgram()));
183
+ postProjectCompilationCallback(taskInfo);
184
+ if (status === ts.ExitStatus.Success) {
185
+ logInfo(`Done compiling TypeScript files for project "${projectName}".`);
186
+ }
187
+ results[taskInfo.task] = {
188
+ success: status === ts.ExitStatus.Success,
189
+ terminalOutput,
190
+ startTime,
191
+ endTime: Date.now(),
192
+ };
193
+ }
194
+ return results;
195
+ }
@@ -0,0 +1,4 @@
1
+ import * as ts from 'typescript';
2
+ export declare function formatDiagnosticReport(diagnostic: ts.Diagnostic, host: ts.FormatDiagnosticsHost): string;
3
+ export declare function formatSolutionBuilderStatusReport(diagnostic: ts.Diagnostic): string;
4
+ export declare function formatWatchStatusReport(diagnostic: ts.Diagnostic, newLine: string): string;