@nx/js 0.0.0-pr-22179-271588f

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 (204) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/babel.d.ts +13 -0
  4. package/babel.js +91 -0
  5. package/executors.json +32 -0
  6. package/generators.json +46 -0
  7. package/migrations.json +159 -0
  8. package/package.json +76 -0
  9. package/plugins/jest/local-registry.d.ts +1 -0
  10. package/plugins/jest/local-registry.js +4 -0
  11. package/src/executors/node/lib/kill-tree.d.ts +2 -0
  12. package/src/executors/node/lib/kill-tree.js +114 -0
  13. package/src/executors/node/node-with-require-overrides.d.ts +7 -0
  14. package/src/executors/node/node-with-require-overrides.js +21 -0
  15. package/src/executors/node/node.impl.d.ts +7 -0
  16. package/src/executors/node/node.impl.js +288 -0
  17. package/src/executors/node/schema.d.ts +18 -0
  18. package/src/executors/node/schema.json +92 -0
  19. package/src/executors/release-publish/format-bytes.d.ts +1 -0
  20. package/src/executors/release-publish/format-bytes.js +28 -0
  21. package/src/executors/release-publish/log-tar.d.ts +1 -0
  22. package/src/executors/release-publish/log-tar.js +68 -0
  23. package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
  24. package/src/executors/release-publish/release-publish.impl.js +198 -0
  25. package/src/executors/release-publish/schema.d.ts +8 -0
  26. package/src/executors/release-publish/schema.json +26 -0
  27. package/src/executors/swc/schema.json +154 -0
  28. package/src/executors/swc/swc.impl.d.ts +10 -0
  29. package/src/executors/swc/swc.impl.js +149 -0
  30. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
  31. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
  32. package/src/executors/tsc/lib/batch/index.d.ts +4 -0
  33. package/src/executors/tsc/lib/batch/index.js +7 -0
  34. package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
  35. package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
  36. package/src/executors/tsc/lib/batch/types.d.ts +17 -0
  37. package/src/executors/tsc/lib/batch/types.js +2 -0
  38. package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
  39. package/src/executors/tsc/lib/batch/watch.js +56 -0
  40. package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
  41. package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
  42. package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
  43. package/src/executors/tsc/lib/get-task-options.js +34 -0
  44. package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
  45. package/src/executors/tsc/lib/get-tsconfig.js +86 -0
  46. package/src/executors/tsc/lib/index.d.ts +4 -0
  47. package/src/executors/tsc/lib/index.js +7 -0
  48. package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
  49. package/src/executors/tsc/lib/normalize-options.js +39 -0
  50. package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
  51. package/src/executors/tsc/lib/typescript-compilation.js +203 -0
  52. package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
  53. package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
  54. package/src/executors/tsc/schema.json +163 -0
  55. package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
  56. package/src/executors/tsc/tsc.batch-impl.js +180 -0
  57. package/src/executors/tsc/tsc.impl.d.ts +7 -0
  58. package/src/executors/tsc/tsc.impl.js +97 -0
  59. package/src/executors/verdaccio/schema.d.ts +7 -0
  60. package/src/executors/verdaccio/schema.json +35 -0
  61. package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
  62. package/src/executors/verdaccio/verdaccio.impl.js +220 -0
  63. package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
  64. package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
  65. package/src/generators/convert-to-swc/schema.d.ts +4 -0
  66. package/src/generators/convert-to-swc/schema.json +36 -0
  67. package/src/generators/init/files/__fileName__ +20 -0
  68. package/src/generators/init/init.d.ts +4 -0
  69. package/src/generators/init/init.js +114 -0
  70. package/src/generators/init/schema.d.ts +7 -0
  71. package/src/generators/init/schema.json +36 -0
  72. package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
  73. package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
  74. package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
  75. package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
  76. package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
  77. package/src/generators/library/files/readme/README.md +19 -0
  78. package/src/generators/library/library.d.ts +16 -0
  79. package/src/generators/library/library.js +751 -0
  80. package/src/generators/library/schema.json +151 -0
  81. package/src/generators/release-version/release-version.d.ts +5 -0
  82. package/src/generators/release-version/release-version.js +390 -0
  83. package/src/generators/release-version/schema.d.ts +1 -0
  84. package/src/generators/release-version/schema.json +67 -0
  85. package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
  86. package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
  87. package/src/generators/release-version/utils/package.d.ts +12 -0
  88. package/src/generators/release-version/utils/package.js +34 -0
  89. package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
  90. package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
  91. package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
  92. package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
  93. package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
  94. package/src/generators/release-version/utils/update-lock-file.js +105 -0
  95. package/src/generators/setup-build/generator.d.ts +4 -0
  96. package/src/generators/setup-build/generator.js +142 -0
  97. package/src/generators/setup-build/schema.d.ts +7 -0
  98. package/src/generators/setup-build/schema.json +42 -0
  99. package/src/generators/setup-verdaccio/files/config.yml +28 -0
  100. package/src/generators/setup-verdaccio/generator.d.ts +4 -0
  101. package/src/generators/setup-verdaccio/generator.js +56 -0
  102. package/src/generators/setup-verdaccio/schema.d.ts +3 -0
  103. package/src/generators/setup-verdaccio/schema.json +16 -0
  104. package/src/index.d.ts +17 -0
  105. package/src/index.js +28 -0
  106. package/src/internal.d.ts +4 -0
  107. package/src/internal.js +15 -0
  108. package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
  109. package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -0
  110. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  111. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  112. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
  113. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
  114. package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
  115. package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
  116. package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
  117. package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
  118. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  119. package/src/plugins/jest/start-local-registry.js +63 -0
  120. package/src/plugins/rollup/type-definitions.d.ts +8 -0
  121. package/src/plugins/rollup/type-definitions.js +48 -0
  122. package/src/utils/add-babel-inputs.d.ts +3 -0
  123. package/src/utils/add-babel-inputs.js +23 -0
  124. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  125. package/src/utils/add-local-registry-scripts.js +77 -0
  126. package/src/utils/assets/assets.d.ts +10 -0
  127. package/src/utils/assets/assets.js +36 -0
  128. package/src/utils/assets/copy-assets-handler.d.ts +32 -0
  129. package/src/utils/assets/copy-assets-handler.js +154 -0
  130. package/src/utils/assets/index.d.ts +16 -0
  131. package/src/utils/assets/index.js +27 -0
  132. package/src/utils/buildable-libs-utils.d.ts +43 -0
  133. package/src/utils/buildable-libs-utils.js +375 -0
  134. package/src/utils/check-dependencies.d.ts +8 -0
  135. package/src/utils/check-dependencies.js +23 -0
  136. package/src/utils/code-frames/highlight.d.ts +1 -0
  137. package/src/utils/code-frames/highlight.js +86 -0
  138. package/src/utils/code-frames/identifiers.d.ts +5 -0
  139. package/src/utils/code-frames/identifiers.js +52 -0
  140. package/src/utils/compiler-helper-dependency.d.ts +18 -0
  141. package/src/utils/compiler-helper-dependency.js +120 -0
  142. package/src/utils/find-npm-dependencies.d.ts +9 -0
  143. package/src/utils/find-npm-dependencies.js +140 -0
  144. package/src/utils/generate-globs.d.ts +6 -0
  145. package/src/utils/generate-globs.js +80 -0
  146. package/src/utils/get-import-path.d.ts +5 -0
  147. package/src/utils/get-import-path.js +14 -0
  148. package/src/utils/get-main-file-dir.d.ts +1 -0
  149. package/src/utils/get-main-file-dir.js +11 -0
  150. package/src/utils/inline.d.ts +19 -0
  151. package/src/utils/inline.js +210 -0
  152. package/src/utils/package-json/create-entry-points.d.ts +1 -0
  153. package/src/utils/package-json/create-entry-points.js +23 -0
  154. package/src/utils/package-json/get-npm-scope.d.ts +5 -0
  155. package/src/utils/package-json/get-npm-scope.js +16 -0
  156. package/src/utils/package-json/index.d.ts +13 -0
  157. package/src/utils/package-json/index.js +30 -0
  158. package/src/utils/package-json/update-package-json.d.ts +30 -0
  159. package/src/utils/package-json/update-package-json.js +179 -0
  160. package/src/utils/prettier.d.ts +6 -0
  161. package/src/utils/prettier.js +34 -0
  162. package/src/utils/schema.d.ts +87 -0
  163. package/src/utils/swc/add-swc-config.d.ts +3 -0
  164. package/src/utils/swc/add-swc-config.js +41 -0
  165. package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
  166. package/src/utils/swc/add-swc-dependencies.js +18 -0
  167. package/src/utils/swc/compile-swc.d.ts +13 -0
  168. package/src/utils/swc/compile-swc.js +160 -0
  169. package/src/utils/swc/get-swcrc-path.d.ts +5 -0
  170. package/src/utils/swc/get-swcrc-path.js +15 -0
  171. package/src/utils/swc/inline.d.ts +2 -0
  172. package/src/utils/swc/inline.js +11 -0
  173. package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
  174. package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
  175. package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
  176. package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
  177. package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
  178. package/src/utils/typescript/add-tslib-dependencies.js +11 -0
  179. package/src/utils/typescript/ast-utils.d.ts +32 -0
  180. package/src/utils/typescript/ast-utils.js +266 -0
  181. package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
  182. package/src/utils/typescript/compile-typescript-files.js +43 -0
  183. package/src/utils/typescript/create-ts-config.d.ts +18 -0
  184. package/src/utils/typescript/create-ts-config.js +48 -0
  185. package/src/utils/typescript/ensure-typescript.d.ts +1 -0
  186. package/src/utils/typescript/ensure-typescript.js +9 -0
  187. package/src/utils/typescript/get-source-nodes.d.ts +2 -0
  188. package/src/utils/typescript/get-source-nodes.js +18 -0
  189. package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
  190. package/src/utils/typescript/load-ts-transformers.js +62 -0
  191. package/src/utils/typescript/print-diagnostics.d.ts +1 -0
  192. package/src/utils/typescript/print-diagnostics.js +18 -0
  193. package/src/utils/typescript/run-type-check.d.ts +32 -0
  194. package/src/utils/typescript/run-type-check.js +128 -0
  195. package/src/utils/typescript/ts-config.d.ts +9 -0
  196. package/src/utils/typescript/ts-config.js +85 -0
  197. package/src/utils/typescript/tsnode-register.d.ts +1 -0
  198. package/src/utils/typescript/tsnode-register.js +24 -0
  199. package/src/utils/typescript/types.d.ts +18 -0
  200. package/src/utils/typescript/types.js +2 -0
  201. package/src/utils/versions.d.ts +17 -0
  202. package/src/utils/versions.js +21 -0
  203. package/src/utils/watch-for-single-file-changes.d.ts +1 -0
  204. package/src/utils/watch-for-single-file-changes.js +22 -0
@@ -0,0 +1,17 @@
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
+ import type { TypescriptInMemoryTsConfig } from '../typescript-compilation';
6
+ export interface TaskInfo {
7
+ task: string;
8
+ options: NormalizedExecutorOptions;
9
+ context: ExecutorContext;
10
+ assetsHandler: CopyAssetsHandler;
11
+ buildableProjectNodeDependencies: DependentBuildableProjectNode[];
12
+ projectGraphNode: ProjectGraphProjectNode;
13
+ tsConfig: TypescriptInMemoryTsConfig;
14
+ startTime?: number;
15
+ endTime?: number;
16
+ terminalOutput: string;
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import type { TaskInfo } from './types';
2
+ export declare function watchTaskProjectsPackageJsonFileChanges(taskInfos: TaskInfo[], callback: (changedTaskInfos: TaskInfo[]) => void): Promise<() => void>;
3
+ export declare function watchTaskProjectsFileChangesForAssets(taskInfos: TaskInfo[]): Promise<() => void>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.watchTaskProjectsFileChangesForAssets = exports.watchTaskProjectsPackageJsonFileChanges = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const client_1 = require("nx/src/daemon/client/client");
6
+ const path_1 = require("path");
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));
27
+ }
28
+ });
29
+ if (changedTasks.length) {
30
+ callback(changedTasks);
31
+ }
32
+ }
33
+ });
34
+ return () => unregisterFileWatcher();
35
+ }
36
+ exports.watchTaskProjectsPackageJsonFileChanges = watchTaskProjectsPackageJsonFileChanges;
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
+ }
53
+ });
54
+ return () => unregisterFileWatcher();
55
+ }
56
+ exports.watchTaskProjectsFileChangesForAssets = watchTaskProjectsFileChangesForAssets;
@@ -0,0 +1,3 @@
1
+ import * as ts from 'typescript';
2
+ import type { TransformerEntry } from '../../../utils/typescript/types';
3
+ export declare function getCustomTrasformersFactory(transformers: TransformerEntry[]): (program: ts.Program) => ts.CustomTransformers;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCustomTrasformersFactory = void 0;
4
+ const load_ts_transformers_1 = require("../../../utils/typescript/load-ts-transformers");
5
+ function getCustomTrasformersFactory(transformers) {
6
+ const { compilerPluginHooks } = (0, load_ts_transformers_1.loadTsTransformers)(transformers);
7
+ return (program) => ({
8
+ before: compilerPluginHooks.beforeHooks.map((hook) => hook(program)),
9
+ after: compilerPluginHooks.afterHooks.map((hook) => hook(program)),
10
+ afterDeclarations: compilerPluginHooks.afterDeclarationsHooks.map((hook) => hook(program)),
11
+ });
12
+ }
13
+ exports.getCustomTrasformersFactory = getCustomTrasformersFactory;
@@ -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 | null;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTaskOptions = void 0;
4
+ const normalize_options_1 = require("./normalize-options");
5
+ const tasksOptionsCache = new Map();
6
+ function getTaskOptions(taskName, context) {
7
+ if (tasksOptionsCache.has(taskName)) {
8
+ return tasksOptionsCache.get(taskName);
9
+ }
10
+ try {
11
+ const { taskOptions, sourceRoot, root } = parseTaskInfo(taskName, context);
12
+ const normalizedTaskOptions = (0, normalize_options_1.normalizeOptions)(taskOptions, context.root, sourceRoot, root);
13
+ tasksOptionsCache.set(taskName, normalizedTaskOptions);
14
+ return normalizedTaskOptions;
15
+ }
16
+ catch {
17
+ tasksOptionsCache.set(taskName, null);
18
+ return null;
19
+ }
20
+ }
21
+ exports.getTaskOptions = getTaskOptions;
22
+ function parseTaskInfo(taskName, context) {
23
+ const target = context.taskGraph.tasks[taskName].target;
24
+ const projectNode = context.projectGraph.nodes[target.project];
25
+ const targetConfig = projectNode.data.targets?.[target.target];
26
+ const { sourceRoot, root } = projectNode.data;
27
+ const taskOptions = {
28
+ ...targetConfig.options,
29
+ ...(target.configuration
30
+ ? targetConfig.configurations?.[target.configuration]
31
+ : {}),
32
+ };
33
+ return { taskOptions, root, sourceRoot, projectNode, target };
34
+ }
@@ -0,0 +1,4 @@
1
+ import { type 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,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProcessedTaskTsConfigs = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const get_task_options_1 = require("./get-task-options");
7
+ function getProcessedTaskTsConfigs(tasks, tasksOptions, context) {
8
+ const taskInMemoryTsConfigMap = {};
9
+ for (const task of tasks) {
10
+ generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTsConfigMap);
11
+ }
12
+ return taskInMemoryTsConfigMap;
13
+ }
14
+ exports.getProcessedTaskTsConfigs = getProcessedTaskTsConfigs;
15
+ const projectTsConfigCache = new Map();
16
+ function generateTaskProjectTsConfig(task, tasksOptions, context, taskInMemoryTsConfigMap) {
17
+ const { project } = (0, devkit_1.parseTargetString)(task, context);
18
+ if (projectTsConfigCache.has(project)) {
19
+ const { tsConfig, tsConfigPath } = projectTsConfigCache.get(project);
20
+ taskInMemoryTsConfigMap[task] = tsConfig;
21
+ return tsConfigPath;
22
+ }
23
+ const tasksInProject = [
24
+ task,
25
+ ...getDependencyTasksInSameProject(task, context),
26
+ ];
27
+ const taskWithTscExecutor = tasksInProject.find((t) => hasTscExecutor(t, context));
28
+ if (!taskWithTscExecutor) {
29
+ throw new Error((0, devkit_1.stripIndents) `The "@nx/js:tsc" batch executor requires all dependencies to use the "@nx/js:tsc" executor.
30
+ None of the following tasks in the "${project}" project use the "@nx/js:tsc" executor:
31
+ ${tasksInProject.map((t) => `- ${t}`).join('\n')}`);
32
+ }
33
+ const projectReferences = [];
34
+ for (const task of tasksInProject) {
35
+ for (const depTask of getDependencyTasksInOtherProjects(task, project, context)) {
36
+ const tsConfigPath = generateTaskProjectTsConfig(depTask, tasksOptions, context, taskInMemoryTsConfigMap);
37
+ projectReferences.push(tsConfigPath);
38
+ }
39
+ }
40
+ const taskOptions = tasksOptions[taskWithTscExecutor] ??
41
+ (0, get_task_options_1.getTaskOptions)(taskWithTscExecutor, context);
42
+ const tsConfigPath = taskOptions.tsConfig;
43
+ taskInMemoryTsConfigMap[taskWithTscExecutor] = getInMemoryTsConfig(tsConfigPath, taskOptions, projectReferences);
44
+ projectTsConfigCache.set(project, {
45
+ tsConfigPath: tsConfigPath,
46
+ tsConfig: taskInMemoryTsConfigMap[taskWithTscExecutor],
47
+ });
48
+ return tsConfigPath;
49
+ }
50
+ function getDependencyTasksInOtherProjects(task, project, context) {
51
+ return context.taskGraph.dependencies[task].filter((t) => t !== task && (0, devkit_1.parseTargetString)(t, context).project !== project);
52
+ }
53
+ function getDependencyTasksInSameProject(task, context) {
54
+ const { project: taskProject } = (0, devkit_1.parseTargetString)(task, context);
55
+ return Object.keys(context.taskGraph.tasks).filter((t) => t !== task && (0, devkit_1.parseTargetString)(t, context).project === taskProject);
56
+ }
57
+ function getInMemoryTsConfig(tsConfig, taskOptions, projectReferences) {
58
+ const originalTsConfig = (0, devkit_1.readJsonFile)(tsConfig, {
59
+ allowTrailingComma: true,
60
+ disallowComments: false,
61
+ });
62
+ const allProjectReferences = Array.from(new Set((originalTsConfig.references ?? [])
63
+ .map((r) => r.path)
64
+ .concat(projectReferences)));
65
+ return {
66
+ content: JSON.stringify({
67
+ ...originalTsConfig,
68
+ compilerOptions: {
69
+ ...originalTsConfig.compilerOptions,
70
+ rootDir: taskOptions.rootDir,
71
+ outDir: taskOptions.outputPath,
72
+ composite: true,
73
+ declaration: true,
74
+ declarationMap: true,
75
+ tsBuildInfoFile: (0, path_1.join)(taskOptions.outputPath, 'tsconfig.tsbuildinfo'),
76
+ },
77
+ references: allProjectReferences.map((pr) => ({ path: pr })),
78
+ }),
79
+ path: tsConfig.replace(/\\/g, '/'),
80
+ };
81
+ }
82
+ function hasTscExecutor(task, context) {
83
+ const { project, target } = (0, devkit_1.parseTargetString)(task, context);
84
+ return (context.projectGraph.nodes[project].data.targets[target].executor ===
85
+ '@nx/js:tsc');
86
+ }
@@ -0,0 +1,4 @@
1
+ export * from './get-custom-transformers-factory';
2
+ export * from './get-tsconfig';
3
+ export * from './normalize-options';
4
+ export * from './typescript-compilation';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./get-custom-transformers-factory"), exports);
5
+ tslib_1.__exportStar(require("./get-tsconfig"), exports);
6
+ tslib_1.__exportStar(require("./normalize-options"), exports);
7
+ tslib_1.__exportStar(require("./typescript-compilation"), exports);
@@ -0,0 +1,2 @@
1
+ import type { ExecutorOptions, NormalizedExecutorOptions } from '../../../utils/schema';
2
+ export declare function normalizeOptions(options: ExecutorOptions, contextRoot: string, sourceRoot: string, projectRoot: string): NormalizedExecutorOptions;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const path_1 = require("path");
5
+ const assets_1 = require("../../../utils/assets/assets");
6
+ function normalizeOptions(options, contextRoot, sourceRoot, projectRoot) {
7
+ const outputPath = (0, path_1.join)(contextRoot, options.outputPath);
8
+ const rootDir = options.rootDir
9
+ ? (0, path_1.join)(contextRoot, options.rootDir)
10
+ : (0, path_1.join)(contextRoot, projectRoot);
11
+ if (options.watch == null) {
12
+ options.watch = false;
13
+ }
14
+ // TODO: put back when inlining story is more stable
15
+ // if (options.external == null) {
16
+ // options.external = 'all';
17
+ // } else if (Array.isArray(options.external) && options.external.length === 0) {
18
+ // options.external = 'none';
19
+ // }
20
+ if (Array.isArray(options.external) && options.external.length > 0) {
21
+ const firstItem = options.external[0];
22
+ if (firstItem === 'all' || firstItem === 'none') {
23
+ options.external = firstItem;
24
+ }
25
+ }
26
+ const files = (0, assets_1.assetGlobsToFiles)(options.assets, contextRoot, outputPath);
27
+ return {
28
+ ...options,
29
+ root: contextRoot,
30
+ sourceRoot,
31
+ projectRoot,
32
+ files,
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
+ };
38
+ }
39
+ exports.normalizeOptions = normalizeOptions;
@@ -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>;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileTypescriptSolution = void 0;
4
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
5
+ const ts = require("typescript");
6
+ const get_custom_transformers_factory_1 = require("./get-custom-transformers-factory");
7
+ const typescript_diagnostic_reporters_1 = require("./typescript-diagnostic-reporters");
8
+ // https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4050-L4053
9
+ // Typescript diagnostic message for 5083: Cannot read file '{0}'.
10
+ const TYPESCRIPT_CANNOT_READ_FILE = 5083;
11
+ // https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4211-4214
12
+ // Typescript diagnostic message for 6032: File change detected. Starting incremental compilation...
13
+ const TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION = 6032;
14
+ function compileTypescriptSolution(context, watch, logger, hooks, reporters) {
15
+ if (watch) {
16
+ // create an AsyncIterable that doesn't complete, watch mode is only
17
+ // stopped by killing the process
18
+ return (0, async_iterable_1.createAsyncIterable)(async ({ next }) => {
19
+ hooks ??= {};
20
+ const callerAfterProjectCompilationCallback = hooks.afterProjectCompilationCallback;
21
+ hooks.afterProjectCompilationCallback = (tsConfig, success) => {
22
+ callerAfterProjectCompilationCallback?.(tsConfig, success);
23
+ next({ tsConfig, success });
24
+ };
25
+ compileTSWithWatch(context, logger, hooks, reporters);
26
+ });
27
+ }
28
+ // turn it into an AsyncIterable
29
+ const compilationGenerator = compileTS(context, logger, hooks, reporters);
30
+ return {
31
+ [Symbol.asyncIterator]() {
32
+ return {
33
+ next() {
34
+ return Promise.resolve(compilationGenerator.next());
35
+ },
36
+ };
37
+ },
38
+ };
39
+ }
40
+ exports.compileTypescriptSolution = compileTypescriptSolution;
41
+ function* compileTS(context, logger, hooks, reporters) {
42
+ let project;
43
+ const formatDiagnosticsHost = {
44
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
45
+ getNewLine: () => ts.sys.newLine,
46
+ getCanonicalFileName: (filename) => ts.sys.useCaseSensitiveFileNames ? filename : filename.toLowerCase(),
47
+ };
48
+ const solutionBuilderHost = ts.createSolutionBuilderHost(getSystem(context),
49
+ /*createProgram*/ undefined, (diagnostic) => {
50
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatDiagnosticReport)(diagnostic, formatDiagnosticsHost);
51
+ // handles edge case where a wrong a project reference path can't be read
52
+ if (diagnostic.code === TYPESCRIPT_CANNOT_READ_FILE) {
53
+ throw new Error(formattedDiagnostic);
54
+ }
55
+ logger.info(formattedDiagnostic, project.project);
56
+ reporters?.diagnosticReporter?.(project.project, diagnostic);
57
+ }, (diagnostic) => {
58
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatSolutionBuilderStatusReport)(diagnostic);
59
+ logger.info(formattedDiagnostic, project.project);
60
+ reporters?.solutionBuilderStatusReporter?.(project.project, diagnostic);
61
+ });
62
+ const rootNames = Object.keys(context);
63
+ const solutionBuilder = ts.createSolutionBuilder(solutionBuilderHost, rootNames, {});
64
+ // eslint-disable-next-line no-constant-condition
65
+ while (true) {
66
+ project = solutionBuilder.getNextInvalidatedProject();
67
+ if (!project) {
68
+ break;
69
+ }
70
+ const projectContext = context[project.project];
71
+ const projectName = projectContext?.project;
72
+ /**
73
+ * This only applies when the deprecated `prepend` option is set to `true`.
74
+ * Skip support.
75
+ */
76
+ if (project.kind === ts.InvalidatedProjectKind.UpdateBundle) {
77
+ logger.warn(`The project ${projectName} ` +
78
+ `is using the deprecated "prepend" Typescript compiler option. ` +
79
+ `This option is not supported by the batch executor and it's ignored.\n`, project.project);
80
+ continue;
81
+ }
82
+ hooks?.beforeProjectCompilationCallback?.(project.project);
83
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
84
+ logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
85
+ // update output timestamps and mark project as complete
86
+ const status = project.done();
87
+ const success = status === ts.ExitStatus.Success;
88
+ if (success) {
89
+ logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
90
+ }
91
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
92
+ yield { success, tsConfig: project.project };
93
+ continue;
94
+ }
95
+ logger.info(`Compiling TypeScript files for project "${projectName}"...\n`, project.project);
96
+ // build and mark project as complete
97
+ const status = project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(projectContext.transformers)(project.getProgram()));
98
+ const success = status === ts.ExitStatus.Success;
99
+ if (success) {
100
+ logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
101
+ }
102
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
103
+ yield {
104
+ success: status === ts.ExitStatus.Success,
105
+ tsConfig: project.project,
106
+ };
107
+ }
108
+ }
109
+ function compileTSWithWatch(context, logger, hooks, reporters) {
110
+ let project;
111
+ const solutionHost = ts.createSolutionBuilderWithWatchHost(getSystem(context),
112
+ /*createProgram*/ undefined);
113
+ if (reporters?.diagnosticReporter) {
114
+ const originalDiagnosticReporter = solutionHost.reportDiagnostic;
115
+ solutionHost.reportDiagnostic = (diagnostic) => {
116
+ originalDiagnosticReporter(diagnostic);
117
+ reporters.diagnosticReporter(project.project, diagnostic);
118
+ };
119
+ }
120
+ if (reporters?.solutionBuilderStatusReporter) {
121
+ const originalSolutionBuilderStatusReporter = solutionHost.reportSolutionBuilderStatus;
122
+ solutionHost.reportDiagnostic = (diagnostic) => {
123
+ originalSolutionBuilderStatusReporter(diagnostic);
124
+ reporters.solutionBuilderStatusReporter(project.project, diagnostic);
125
+ };
126
+ }
127
+ const originalWatchStatusReporter = solutionHost.onWatchStatusChange;
128
+ solutionHost.onWatchStatusChange = (diagnostic, newLine, options, errorCount) => {
129
+ originalWatchStatusReporter(diagnostic, newLine, options, errorCount);
130
+ if (diagnostic.code ===
131
+ TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION) {
132
+ // there's a change, build invalidated projects
133
+ build();
134
+ }
135
+ reporters?.watchStatusReporter?.(project?.project, diagnostic, newLine, options, errorCount);
136
+ };
137
+ const rootNames = Object.keys(context);
138
+ const solutionBuilder = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {});
139
+ const build = () => {
140
+ while (true) {
141
+ project = solutionBuilder.getNextInvalidatedProject();
142
+ if (!project) {
143
+ break;
144
+ }
145
+ const projectContext = context[project.project];
146
+ const projectName = projectContext.project;
147
+ /**
148
+ * This only applies when the deprecated `prepend` option is set to `true`.
149
+ * Skip support.
150
+ */
151
+ if (project.kind === ts.InvalidatedProjectKind.UpdateBundle) {
152
+ logger.warn(`The project ${projectName} ` +
153
+ `is using the deprecated "prepend" Typescript compiler option. ` +
154
+ `This option is not supported by the batch executor and it's ignored.`);
155
+ continue;
156
+ }
157
+ hooks?.beforeProjectCompilationCallback(project.project);
158
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
159
+ if (projectName) {
160
+ logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
161
+ }
162
+ // update output timestamps and mark project as complete
163
+ const status = project.done();
164
+ const success = status === ts.ExitStatus.Success;
165
+ if (projectName && success) {
166
+ logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
167
+ }
168
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
169
+ continue;
170
+ }
171
+ logger.info(`Compiling TypeScript files for project "${projectName}"...\n`, project.project);
172
+ // build and mark project as complete
173
+ const status = project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(projectContext.transformers)(project.getProgram()));
174
+ const success = status === ts.ExitStatus.Success;
175
+ if (success) {
176
+ logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
177
+ }
178
+ hooks?.afterProjectCompilationCallback?.(project.project, success);
179
+ }
180
+ };
181
+ // initial build
182
+ build();
183
+ /**
184
+ * This is a workaround to get the TS file watching to kick off. It won't
185
+ * build twice since the `build` call above will mark invalidated projects
186
+ * as completed and then, the implementation of the `solutionBuilder.build`
187
+ * skips them.
188
+ * We can't rely solely in `solutionBuilder.build()` because it doesn't
189
+ * accept custom transformers.
190
+ */
191
+ solutionBuilder.build();
192
+ }
193
+ function getSystem(context) {
194
+ return {
195
+ ...ts.sys,
196
+ readFile(path, encoding) {
197
+ if (context[path]) {
198
+ return context[path].tsConfig.content;
199
+ }
200
+ return ts.sys.readFile(path, encoding);
201
+ },
202
+ };
203
+ }
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatSolutionBuilderStatusReport = exports.formatDiagnosticReport = void 0;
4
+ const ts = require("typescript");
5
+ // adapted from TS default diagnostic reporter
6
+ function formatDiagnosticReport(diagnostic, host) {
7
+ const diagnostics = new Array(1);
8
+ diagnostics[0] = diagnostic;
9
+ const formattedDiagnostic = '\n' +
10
+ ts.formatDiagnosticsWithColorAndContext(diagnostics, host) +
11
+ host.getNewLine();
12
+ diagnostics[0] = undefined;
13
+ return formattedDiagnostic;
14
+ }
15
+ exports.formatDiagnosticReport = formatDiagnosticReport;
16
+ // adapted from TS default solution builder status reporter
17
+ function formatSolutionBuilderStatusReport(diagnostic) {
18
+ let formattedDiagnostic = `[${formatColorAndReset(getLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
19
+ formattedDiagnostic += `${ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine)}${ts.sys.newLine + ts.sys.newLine}`;
20
+ return formattedDiagnostic;
21
+ }
22
+ exports.formatSolutionBuilderStatusReport = formatSolutionBuilderStatusReport;
23
+ function formatColorAndReset(text, formatStyle) {
24
+ const resetEscapeSequence = '\u001b[0m';
25
+ return formatStyle + text + resetEscapeSequence;
26
+ }
27
+ function getLocaleTimeString() {
28
+ return new Date().toLocaleTimeString();
29
+ }
30
+ var ForegroundColorEscapeSequences;
31
+ (function (ForegroundColorEscapeSequences) {
32
+ ForegroundColorEscapeSequences["Grey"] = "\u001B[90m";
33
+ ForegroundColorEscapeSequences["Red"] = "\u001B[91m";
34
+ ForegroundColorEscapeSequences["Yellow"] = "\u001B[93m";
35
+ ForegroundColorEscapeSequences["Blue"] = "\u001B[94m";
36
+ ForegroundColorEscapeSequences["Cyan"] = "\u001B[96m";
37
+ })(ForegroundColorEscapeSequences || (ForegroundColorEscapeSequences = {}));