@nx/js 16.4.0-beta.8 → 16.4.0

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 (45) hide show
  1. package/babel.js +3 -1
  2. package/migrations.json +12 -0
  3. package/package.json +6 -6
  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.d.ts +1 -0
  7. package/src/executors/node/node.impl.js +27 -7
  8. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +2 -1
  9. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +22 -17
  10. package/src/executors/tsc/lib/batch/index.d.ts +0 -4
  11. package/src/executors/tsc/lib/batch/index.js +0 -4
  12. package/src/executors/tsc/lib/batch/types.d.ts +5 -0
  13. package/src/executors/tsc/lib/get-task-options.d.ts +8 -0
  14. package/src/executors/tsc/lib/get-task-options.js +51 -0
  15. package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
  16. package/src/executors/tsc/lib/get-tsconfig.js +138 -0
  17. package/src/executors/tsc/lib/index.d.ts +2 -0
  18. package/src/executors/tsc/lib/index.js +2 -0
  19. package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
  20. package/src/executors/tsc/lib/typescript-compilation.js +206 -0
  21. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.d.ts → typescript-diagnostic-reporters.d.ts} +0 -1
  22. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.js → typescript-diagnostic-reporters.js} +1 -8
  23. package/src/executors/tsc/tsc.batch-impl.d.ts +3 -2
  24. package/src/executors/tsc/tsc.batch-impl.js +97 -7
  25. package/src/executors/verdaccio/verdaccio.impl.js +67 -39
  26. package/src/generators/setup-verdaccio/files/config.yml +5 -6
  27. package/src/generators/setup-verdaccio/generator.js +5 -1
  28. package/src/internal.d.ts +1 -0
  29. package/src/internal.js +4 -1
  30. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  31. package/src/plugins/jest/start-local-registry.js +65 -0
  32. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  33. package/src/utils/add-local-registry-scripts.js +57 -0
  34. package/src/utils/compiler-helper-dependency.d.ts +2 -1
  35. package/src/utils/compiler-helper-dependency.js +14 -4
  36. package/src/utils/minimal-publish-script.js +2 -5
  37. package/src/utils/versions.d.ts +1 -1
  38. package/src/utils/versions.js +1 -1
  39. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.d.ts +0 -3
  40. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.js +0 -52
  41. package/src/executors/tsc/lib/batch/get-task-options.d.ts +0 -3
  42. package/src/executors/tsc/lib/batch/get-task-options.js +0 -24
  43. package/src/executors/tsc/lib/batch/typescript-compilation.d.ts +0 -7
  44. package/src/executors/tsc/lib/batch/typescript-compilation.js +0 -195
  45. package/src/generators/setup-verdaccio/files/htpasswd +0 -1
package/babel.js CHANGED
@@ -5,6 +5,8 @@ module.exports = function (api, options = {}) {
5
5
  var _a, _b, _c;
6
6
  api.assertVersion(7);
7
7
  const isModern = api.caller((caller) => caller === null || caller === void 0 ? void 0 : caller.isModern);
8
+ // use by @nx/cypress react component testing to prevent core js build issues
9
+ const isTest = api.caller((caller) => caller === null || caller === void 0 ? void 0 : caller.isTest);
8
10
  // This is set by `@nx/rollup:rollup` executor
9
11
  const isNxPackage = api.caller((caller) => caller === null || caller === void 0 ? void 0 : caller.isNxPackage);
10
12
  const emitDecoratorMetadata = api.caller((caller) => { var _a; return (_a = caller === null || caller === void 0 ? void 0 : caller.emitDecoratorMetadata) !== null && _a !== void 0 ? _a : true; });
@@ -19,7 +21,7 @@ module.exports = function (api, options = {}) {
19
21
  // For Jest tests, NODE_ENV is set as 'test' and we only want to set target as Node.
20
22
  // All other options will fail in Jest since Node does not support some ES features
21
23
  // such as import syntax.
22
- process.env.NODE_ENV === 'test'
24
+ isTest || process.env.NODE_ENV === 'test'
23
25
  ? { targets: { node: 'current' }, loose: true }
24
26
  : {
25
27
  // Allow importing core-js in entrypoint and use browserslist to select polyfills.
package/migrations.json CHANGED
@@ -80,6 +80,18 @@
80
80
  "version": "~5.0.2"
81
81
  }
82
82
  }
83
+ },
84
+ "16.4.0": {
85
+ "version": "16.4.0-beta.11",
86
+ "x-prompt": "Do you want to update to TypeScript v5.1?",
87
+ "requires": {
88
+ "typescript": ">=5.0.0 <5.1.0"
89
+ },
90
+ "packages": {
91
+ "typescript": {
92
+ "version": "~5.1.3"
93
+ }
94
+ }
83
95
  }
84
96
  }
85
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "16.4.0-beta.8",
3
+ "version": "16.4.0",
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,9 +39,9 @@
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.8",
43
- "@nx/devkit": "16.4.0-beta.8",
44
- "@nx/workspace": "16.4.0-beta.8",
42
+ "@nrwl/js": "16.4.0",
43
+ "@nx/devkit": "16.4.0",
44
+ "@nx/workspace": "16.4.0",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -53,7 +53,7 @@
53
53
  "ignore": "^5.0.4",
54
54
  "js-tokens": "^4.0.0",
55
55
  "minimatch": "3.0.5",
56
- "semver": "7.3.4",
56
+ "semver": "7.5.3",
57
57
  "source-map-support": "0.5.19",
58
58
  "tslib": "^2.3.0"
59
59
  },
@@ -69,5 +69,5 @@
69
69
  "access": "public"
70
70
  },
71
71
  "types": "./src/index.d.ts",
72
- "gitHead": "a6589ab111fc01fd4d2cd215c31bfcff004dfc00"
72
+ "gitHead": "ae698a72748d9f33aa5395aeeaa7b7af436a1dc5"
73
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);
@@ -2,5 +2,6 @@ import { ExecutorContext } from '@nx/devkit';
2
2
  import { NodeExecutorOptions } from './schema';
3
3
  export declare function nodeExecutor(options: NodeExecutorOptions, context: ExecutorContext): AsyncGenerator<{
4
4
  success: boolean;
5
+ options?: Record<string, any>;
5
6
  }, void, undefined>;
6
7
  export default nodeExecutor;
@@ -7,10 +7,12 @@ const child_process_1 = require("child_process");
7
7
  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
+ const path = require("path");
10
11
  const path_1 = 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 () => {
@@ -42,7 +44,8 @@ function nodeExecutor(options, context) {
42
44
  }
43
45
  // Re-map buildable workspace projects to their output directory.
44
46
  const mappings = calculateResolveMappings(context, options);
45
- 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);
46
49
  const tasks = [];
47
50
  let currentTask = null;
48
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* () {
@@ -67,9 +70,7 @@ function nodeExecutor(options, context) {
67
70
  let buildFailed = false;
68
71
  // Run the build
69
72
  task.promise = new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
70
- task.childProcess = (0, child_process_1.exec)(`npx nx run ${context.projectName}:${buildTarget.target}${buildTarget.configuration
71
- ? `:${buildTarget.configuration}`
72
- : ''}`, {
73
+ task.childProcess = (0, child_process_1.exec)(`npx nx run ${context.projectName}:${buildTarget.target}${buildTarget.configuration ? `:${buildTarget.configuration}` : ''}`, {
73
74
  cwd: context.root,
74
75
  }, (error, stdout, stderr) => {
75
76
  if (
@@ -104,12 +105,13 @@ function nodeExecutor(options, context) {
104
105
  task.childProcess = (0, child_process_1.fork)((0, devkit_1.joinPathFragments)(__dirname, 'node-with-require-overrides'), (_a = options.args) !== null && _a !== void 0 ? _a : [], {
105
106
  execArgv: getExecArgv(options),
106
107
  stdio: [0, 1, 'pipe', 'ipc'],
107
- env: Object.assign(Object.assign({}, process.env), { NX_FILE_TO_RUN: fileToRun, NX_MAPPINGS: JSON.stringify(mappings) }),
108
+ env: Object.assign(Object.assign({}, process.env), { NX_FILE_TO_RUN: fileToRunCorrectPath(fileToRun), NX_MAPPINGS: JSON.stringify(mappings) }),
108
109
  });
109
110
  task.childProcess.stderr.on('data', (data) => {
110
111
  // Don't log out error if task is killed and new one has started.
111
112
  // This could happen if a new build is triggered while new process is starting, since the operation is not atomic.
112
- if (options.watch && !task.killed) {
113
+ // Log the error in normal mode
114
+ if (!options.watch || !task.killed) {
113
115
  devkit_1.logger.error(data.toString());
114
116
  }
115
117
  });
@@ -121,7 +123,7 @@ function nodeExecutor(options, context) {
121
123
  done();
122
124
  resolve();
123
125
  });
124
- next({ success: true });
126
+ next({ success: true, options: buildOptions });
125
127
  });
126
128
  }),
127
129
  stop: (signal = 'SIGTERM') => tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -218,4 +220,22 @@ function runWaitUntilTargets(options, context) {
218
220
  }));
219
221
  })));
220
222
  }
223
+ function fileToRunCorrectPath(fileToRun) {
224
+ if (!(0, fileutils_1.fileExists)(fileToRun)) {
225
+ const cjsFile = fileToRun.replace(/\.js$/, '.cjs');
226
+ if ((0, fileutils_1.fileExists)(cjsFile)) {
227
+ fileToRun = cjsFile;
228
+ }
229
+ else {
230
+ const mjsFile = fileToRun.replace(/\.js$/, '.mjs');
231
+ if ((0, fileutils_1.fileExists)(mjsFile)) {
232
+ fileToRun = mjsFile;
233
+ }
234
+ else {
235
+ throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.`);
236
+ }
237
+ }
238
+ }
239
+ return fileToRun;
240
+ }
221
241
  exports.default = nodeExecutor;
@@ -1,4 +1,5 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
2
  import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
+ import type { TypescriptInMemoryTsConfig } from '../typescript-compilation';
3
4
  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;
5
+ export declare function createTaskInfoPerTsConfigMap(tasksOptions: Record<string, NormalizedExecutorOptions>, context: ExecutorContext, tasks: string[], taskInMemoryTsConfigMap: Record<string, TypescriptInMemoryTsConfig>): Record<string, TaskInfo>;
@@ -1,36 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildTaskInfoPerTsConfigMap = void 0;
3
+ exports.createTaskInfoPerTsConfigMap = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
5
6
  const copy_assets_handler_1 = require("../../../../utils/assets/copy-assets-handler");
6
7
  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");
8
+ const get_task_options_1 = require("../get-task-options");
9
9
  const taskTsConfigCache = new Set();
10
- function buildTaskInfoPerTsConfigMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, shouldWatch) {
10
+ function createTaskInfoPerTsConfigMap(tasksOptions, context, tasks, taskInMemoryTsConfigMap) {
11
+ const tsConfigTaskInfoMap = {};
12
+ processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, taskInMemoryTsConfigMap);
13
+ return tsConfigTaskInfoMap;
14
+ }
15
+ exports.createTaskInfoPerTsConfigMap = createTaskInfoPerTsConfigMap;
16
+ function processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, tasks, taskInMemoryTsConfigMap) {
17
+ var _a;
11
18
  for (const taskName of tasks) {
12
19
  if (taskTsConfigCache.has(taskName)) {
13
20
  continue;
14
21
  }
15
- let taskOptions = tasksOptions[taskName];
16
- // task is in the batch (it's meant to be processed), create TaskInfo
22
+ const tsConfig = taskInMemoryTsConfigMap[taskName];
23
+ if (!tsConfig) {
24
+ continue;
25
+ }
26
+ let taskOptions = (_a = tasksOptions[taskName]) !== null && _a !== void 0 ? _a : (0, get_task_options_1.getTaskWithTscExecutorOptions)(taskName, context);
17
27
  if (taskOptions) {
18
- const taskInfo = createTaskInfo(taskName, taskOptions, context);
19
- const tsConfigPath = (0, generate_temp_tsconfig_1.generateTempTsConfig)(tasksOptions, taskName, taskOptions, context);
28
+ const taskInfo = createTaskInfo(taskName, taskOptions, context, tsConfig);
29
+ const tsConfigPath = (0, path_1.join)(context.root, (0, path_1.relative)(context.root, taskOptions.tsConfig));
20
30
  tsConfigTaskInfoMap[tsConfigPath] = taskInfo;
21
31
  taskTsConfigCache.add(taskName);
22
32
  }
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);
33
+ processTasksAndPopulateTsConfigTaskInfoMap(tsConfigTaskInfoMap, tasksOptions, context, context.taskGraph.dependencies[taskName], taskInMemoryTsConfigMap);
30
34
  }
31
35
  }
32
- exports.buildTaskInfoPerTsConfigMap = buildTaskInfoPerTsConfigMap;
33
- function createTaskInfo(taskName, taskOptions, context) {
36
+ function createTaskInfo(taskName, taskOptions, context, tsConfig) {
34
37
  const target = (0, devkit_1.parseTargetString)(taskName, context.projectGraph);
35
38
  const taskContext = Object.assign(Object.assign({}, context), {
36
39
  // batch executors don't get these in the context, we provide them
@@ -50,5 +53,7 @@ function createTaskInfo(taskName, taskOptions, context) {
50
53
  assetsHandler,
51
54
  buildableProjectNodeDependencies,
52
55
  projectGraphNode,
56
+ tsConfig,
57
+ terminalOutput: '',
53
58
  };
54
59
  }
@@ -1,8 +1,4 @@
1
1
  export * from './build-task-info-per-tsconfig-map';
2
- export * from './generate-temp-tsconfig';
3
- export * from './get-task-options';
4
2
  export * from './normalize-tasks-options';
5
3
  export * from './types';
6
- export * from './typescript-compilation';
7
- export * from './typescript-diagnostic-reporters';
8
4
  export * from './watch';
@@ -2,10 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
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
5
  tslib_1.__exportStar(require("./normalize-tasks-options"), exports);
8
6
  tslib_1.__exportStar(require("./types"), exports);
9
- tslib_1.__exportStar(require("./typescript-compilation"), exports);
10
- tslib_1.__exportStar(require("./typescript-diagnostic-reporters"), exports);
11
7
  tslib_1.__exportStar(require("./watch"), exports);
@@ -2,6 +2,7 @@ import type { ExecutorContext, ProjectGraphProjectNode } from '@nx/devkit';
2
2
  import type { CopyAssetsHandler } from '../../../../utils/assets/copy-assets-handler';
3
3
  import type { DependentBuildableProjectNode } from '../../../../utils/buildable-libs-utils';
4
4
  import type { NormalizedExecutorOptions } from '../../../../utils/schema';
5
+ import type { TypescriptInMemoryTsConfig } from '../typescript-compilation';
5
6
  export interface TaskInfo {
6
7
  task: string;
7
8
  options: NormalizedExecutorOptions;
@@ -9,4 +10,8 @@ export interface TaskInfo {
9
10
  assetsHandler: CopyAssetsHandler;
10
11
  buildableProjectNodeDependencies: DependentBuildableProjectNode[];
11
12
  projectGraphNode: ProjectGraphProjectNode;
13
+ tsConfig: TypescriptInMemoryTsConfig;
14
+ startTime?: number;
15
+ endTime?: number;
16
+ terminalOutput: string;
12
17
  }
@@ -0,0 +1,8 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../utils/schema';
3
+ export declare function getTaskOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions | {
4
+ tsConfig: string | null;
5
+ rootDir: string;
6
+ outputPath: string;
7
+ };
8
+ export declare function getTaskWithTscExecutorOptions(taskName: string, context: ExecutorContext): NormalizedExecutorOptions | null;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTaskWithTscExecutorOptions = exports.getTaskOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const normalize_options_1 = require("./normalize-options");
7
+ function getTaskOptions(taskName, context) {
8
+ const result = getTaskWithTscExecutorOptions(taskName, context);
9
+ if (result) {
10
+ return result;
11
+ }
12
+ const { taskOptions, root, projectNode, target } = parseTaskInfo(taskName, context);
13
+ const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({ overrides: context.taskGraph.tasks[taskName].overrides, target }, projectNode);
14
+ const outputPath = outputs.length
15
+ ? (0, path_1.join)(context.root, outputs[0])
16
+ : (0, path_1.join)(context.root, 'dist', root);
17
+ const rootDir = (0, path_1.join)(context.root, root);
18
+ const tsConfig = taskOptions.tsConfig
19
+ ? (0, path_1.join)(context.root, taskOptions.tsConfig)
20
+ : null;
21
+ return { tsConfig, rootDir, outputPath };
22
+ }
23
+ exports.getTaskOptions = getTaskOptions;
24
+ const tasksOptionsCache = new Map();
25
+ function getTaskWithTscExecutorOptions(taskName, context) {
26
+ if (tasksOptionsCache.has(taskName)) {
27
+ return tasksOptionsCache.get(taskName);
28
+ }
29
+ try {
30
+ const { taskOptions, sourceRoot, root } = parseTaskInfo(taskName, context);
31
+ const normalizedTaskOptions = (0, normalize_options_1.normalizeOptions)(taskOptions, context.root, sourceRoot, root);
32
+ tasksOptionsCache.set(taskName, normalizedTaskOptions);
33
+ return normalizedTaskOptions;
34
+ }
35
+ catch (_a) {
36
+ tasksOptionsCache.set(taskName, null);
37
+ return null;
38
+ }
39
+ }
40
+ exports.getTaskWithTscExecutorOptions = getTaskWithTscExecutorOptions;
41
+ function parseTaskInfo(taskName, context) {
42
+ var _a, _b;
43
+ const target = context.taskGraph.tasks[taskName].target;
44
+ const projectNode = context.projectGraph.nodes[target.project];
45
+ const targetConfig = (_a = projectNode.data.targets) === null || _a === void 0 ? void 0 : _a[target.target];
46
+ const { sourceRoot, root } = projectNode.data;
47
+ const taskOptions = Object.assign(Object.assign({}, targetConfig.options), (target.configuration
48
+ ? (_b = targetConfig.configurations) === null || _b === void 0 ? void 0 : _b[target.configuration]
49
+ : {}));
50
+ return { taskOptions, root, sourceRoot, projectNode, target };
51
+ }
@@ -0,0 +1,4 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import type { NormalizedExecutorOptions } from '../../../utils/schema';
3
+ import type { TypescriptInMemoryTsConfig } from './typescript-compilation';
4
+ export declare function getProcessedTaskTsConfigs(tasks: string[], tasksOptions: Record<string, NormalizedExecutorOptions>, context: ExecutorContext): Record<string, TypescriptInMemoryTsConfig>;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProcessedTaskTsConfigs = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const fileutils_1 = require("nx/src/utils/fileutils");
6
+ const path_1 = require("path");
7
+ const buildable_libs_utils_1 = require("../../../utils/buildable-libs-utils");
8
+ const get_task_options_1 = require("./get-task-options");
9
+ function getProcessedTaskTsConfigs(tasks, tasksOptions, context) {
10
+ const taskInMemoryTsConfigMap = {};
11
+ for (const task of tasks) {
12
+ generateTaskTsConfigOrGetDependentBuildableProjectNode(task, tasksOptions, context, taskInMemoryTsConfigMap);
13
+ }
14
+ return taskInMemoryTsConfigMap;
15
+ }
16
+ exports.getProcessedTaskTsConfigs = getProcessedTaskTsConfigs;
17
+ const taskTsConfigGenerationCache = new Map();
18
+ function generateTaskTsConfigOrGetDependentBuildableProjectNode(task, tasksOptions, context, taskInMemoryTsConfigMap) {
19
+ var _a, _b, _c;
20
+ if (taskTsConfigGenerationCache.has(task)) {
21
+ return taskTsConfigGenerationCache.get(task);
22
+ }
23
+ let tsConfig = (_b = (_a = tasksOptions[task]) === null || _a === void 0 ? void 0 : _a.tsConfig) !== null && _b !== void 0 ? _b : (0, get_task_options_1.getTaskOptions)(task, context).tsConfig;
24
+ let taskWithTsConfig = task;
25
+ if (!tsConfig) {
26
+ // check if other tasks in the task graph from the same project has a tsConfig
27
+ const otherTasksInProject = getDependencyTasksInSameProject(task, context);
28
+ const taskTsConfig = findTaskWithTsConfig(otherTasksInProject, context);
29
+ if (taskTsConfig) {
30
+ if (taskTsConfigGenerationCache.has(taskTsConfig.tsConfig)) {
31
+ return taskTsConfigGenerationCache.get(taskTsConfig.tsConfig);
32
+ }
33
+ tsConfig = taskTsConfig.tsConfig;
34
+ taskWithTsConfig = taskTsConfig.task;
35
+ }
36
+ }
37
+ if (tsConfig) {
38
+ const { projectReferences, dependentBuildableProjectNodes } = collectDependenciesFromTask(task, tasksOptions, context, taskInMemoryTsConfigMap);
39
+ taskInMemoryTsConfigMap[taskWithTsConfig] = getInMemoryTsConfig(tsConfig, (_c = tasksOptions[taskWithTsConfig]) !== null && _c !== void 0 ? _c : (0, get_task_options_1.getTaskOptions)(taskWithTsConfig, context), projectReferences, dependentBuildableProjectNodes);
40
+ const result = { tsConfig };
41
+ taskTsConfigGenerationCache.set(task, result);
42
+ return result;
43
+ }
44
+ // there's no tsConfig, return a buildable project node so the path mapping
45
+ // is remapped to the output
46
+ const result = taskToDependentBuildableProjectNode(task, context);
47
+ taskTsConfigGenerationCache.set(task, result);
48
+ return result;
49
+ }
50
+ const projectDependenciesCache = new Map();
51
+ function collectDependenciesFromTask(task, tasksOptions, context, taskInMemoryTsConfigMap) {
52
+ var _a;
53
+ const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
54
+ if (projectDependenciesCache.has(taskProject)) {
55
+ return projectDependenciesCache.get(taskProject);
56
+ }
57
+ const dependentBuildableProjectNodes = [];
58
+ const projectReferences = new Set();
59
+ const allProjectTasks = [
60
+ task,
61
+ ...getDependencyTasksInSameProject(task, context),
62
+ ];
63
+ for (const projectTask of allProjectTasks) {
64
+ for (const depTask of (_a = context.taskGraph.dependencies[projectTask]) !== null && _a !== void 0 ? _a : []) {
65
+ if (task === depTask) {
66
+ continue;
67
+ }
68
+ const { project: depTaskProject } = (0, devkit_1.parseTargetString)(depTask, context.projectGraph);
69
+ if (depTaskProject === taskProject) {
70
+ // recursively collect dependencies for tasks in the same project
71
+ const result = collectDependenciesFromTask(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
72
+ result.projectReferences.forEach((pr) => {
73
+ projectReferences.add(pr);
74
+ });
75
+ result.dependentBuildableProjectNodes.forEach((node) => {
76
+ dependentBuildableProjectNodes.push(node);
77
+ });
78
+ }
79
+ else {
80
+ // task is from a different project, get its project reference or buildable node
81
+ const result = generateTaskTsConfigOrGetDependentBuildableProjectNode(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
82
+ if ('tsConfig' in result) {
83
+ projectReferences.add(result.tsConfig);
84
+ }
85
+ else {
86
+ dependentBuildableProjectNodes.push(result);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ projectDependenciesCache.set(taskProject, {
92
+ projectReferences: Array.from(projectReferences),
93
+ dependentBuildableProjectNodes,
94
+ });
95
+ return projectDependenciesCache.get(taskProject);
96
+ }
97
+ function taskToDependentBuildableProjectNode(task, context) {
98
+ const target = context.taskGraph.tasks[task].target;
99
+ const projectGraphNode = context.projectGraph.nodes[target.project];
100
+ const libPackageJsonPath = (0, path_1.join)(context.root, projectGraphNode.data.root, 'package.json');
101
+ return {
102
+ name: (0, fileutils_1.fileExists)(libPackageJsonPath)
103
+ ? (0, devkit_1.readJsonFile)(libPackageJsonPath).name
104
+ : target.project,
105
+ outputs: (0, devkit_1.getOutputsForTargetAndConfiguration)({ overrides: {}, target }, projectGraphNode),
106
+ node: projectGraphNode,
107
+ };
108
+ }
109
+ function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences, dependentBuildableProjectNodes) {
110
+ var _a, _b;
111
+ const originalTsConfig = (0, devkit_1.readJsonFile)(tsConfig, {
112
+ allowTrailingComma: true,
113
+ disallowComments: false,
114
+ });
115
+ const allProjectReferences = Array.from(new Set(((_a = originalTsConfig.references) !== null && _a !== void 0 ? _a : [])
116
+ .map((r) => r.path)
117
+ .concat(projectReferences)));
118
+ return {
119
+ 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'), paths: dependentBuildableProjectNodes.length
120
+ ? (0, buildable_libs_utils_1.computeCompilerOptionsPaths)(tsConfig, dependentBuildableProjectNodes)
121
+ : (_b = originalTsConfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths }), references: allProjectReferences.map((pr) => ({ path: pr })) })),
122
+ path: tsConfig,
123
+ };
124
+ }
125
+ function findTaskWithTsConfig(tasks, context) {
126
+ for (const task of tasks) {
127
+ const depTaskOptions = (0, get_task_options_1.getTaskOptions)(task, context);
128
+ if (depTaskOptions === null || depTaskOptions === void 0 ? void 0 : depTaskOptions.tsConfig) {
129
+ return { task: task, tsConfig: depTaskOptions.tsConfig };
130
+ }
131
+ }
132
+ return null;
133
+ }
134
+ function getDependencyTasksInSameProject(task, context) {
135
+ const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context.projectGraph);
136
+ return Object.keys(context.taskGraph.tasks).filter((t) => t !== task &&
137
+ (0, devkit_1.parseTargetString)(t, context.projectGraph).project === taskProject);
138
+ }
@@ -1,2 +1,4 @@
1
1
  export * from './get-custom-transformers-factory';
2
+ export * from './get-tsconfig';
2
3
  export * from './normalize-options';
4
+ export * from './typescript-compilation';
@@ -2,4 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./get-custom-transformers-factory"), exports);
5
+ tslib_1.__exportStar(require("./get-tsconfig"), exports);
5
6
  tslib_1.__exportStar(require("./normalize-options"), exports);
7
+ tslib_1.__exportStar(require("./typescript-compilation"), exports);
@@ -0,0 +1,29 @@
1
+ import * as ts from 'typescript';
2
+ import type { TransformerEntry } from '../../../utils/typescript/types';
3
+ export interface TypescriptInMemoryTsConfig {
4
+ content: string;
5
+ path: string;
6
+ }
7
+ export interface TypescripCompilationLogger {
8
+ error: (message: string, tsConfig?: string) => void;
9
+ info: (message: string, tsConfig?: string) => void;
10
+ warn: (message: string, tsConfig?: string) => void;
11
+ }
12
+ export interface TypescriptProjectContext {
13
+ project: string;
14
+ tsConfig: TypescriptInMemoryTsConfig;
15
+ transformers: TransformerEntry[];
16
+ }
17
+ export interface TypescriptCompilationResult {
18
+ tsConfig: string;
19
+ success: boolean;
20
+ }
21
+ export type ReporterWithTsConfig<Fn extends (...args: any[]) => any> = (tsConfig: string | undefined, ...foo: Parameters<Fn>) => ReturnType<Fn>;
22
+ export declare function compileTypescriptSolution(context: Record<string, TypescriptProjectContext>, watch: boolean, logger: TypescripCompilationLogger, hooks?: {
23
+ beforeProjectCompilationCallback?: (tsConfig: string) => void;
24
+ afterProjectCompilationCallback?: (tsConfig: string, success: boolean) => void;
25
+ }, reporters?: {
26
+ diagnosticReporter?: ReporterWithTsConfig<ts.DiagnosticReporter>;
27
+ solutionBuilderStatusReporter?: ReporterWithTsConfig<ts.DiagnosticReporter>;
28
+ watchStatusReporter?: ReporterWithTsConfig<ts.WatchStatusReporter>;
29
+ }): AsyncIterable<TypescriptCompilationResult>;