@nx/js 16.4.0-beta.0 → 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 (171) hide show
  1. package/babel.js +0 -1
  2. package/executors.json +1 -0
  3. package/generators.json +12 -0
  4. package/package.json +6 -5
  5. package/plugins/jest/local-registry.d.ts +1 -0
  6. package/plugins/jest/local-registry.js +4 -0
  7. package/src/executors/node/compat.js +0 -1
  8. package/src/executors/node/lib/kill-tree.js +0 -1
  9. package/src/executors/node/node-with-require-overrides.js +0 -1
  10. package/src/executors/node/node.impl.js +64 -13
  11. package/src/executors/swc/compat.js +0 -1
  12. package/src/executors/swc/swc.impl.js +0 -1
  13. package/src/executors/tsc/compat.js +0 -1
  14. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +4 -0
  15. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +54 -0
  16. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.d.ts +3 -0
  17. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.js +52 -0
  18. package/src/executors/tsc/lib/batch/get-task-options.d.ts +3 -0
  19. package/src/executors/tsc/lib/batch/get-task-options.js +24 -0
  20. package/src/executors/tsc/lib/batch/index.d.ts +8 -0
  21. package/src/executors/tsc/lib/batch/index.js +11 -0
  22. package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
  23. package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
  24. package/src/executors/tsc/lib/batch/types.d.ts +12 -0
  25. package/src/executors/tsc/lib/batch/types.js +2 -0
  26. package/src/executors/tsc/lib/batch/typescript-compilation.d.ts +7 -0
  27. package/src/executors/tsc/lib/batch/typescript-compilation.js +195 -0
  28. package/src/executors/tsc/lib/batch/typescript-diagnostic-reporters.d.ts +4 -0
  29. package/src/executors/tsc/lib/batch/typescript-diagnostic-reporters.js +44 -0
  30. package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
  31. package/src/executors/tsc/lib/batch/watch.js +63 -0
  32. package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
  33. package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
  34. package/src/executors/tsc/lib/index.d.ts +2 -0
  35. package/src/executors/tsc/lib/index.js +5 -0
  36. package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
  37. package/src/executors/tsc/lib/normalize-options.js +32 -0
  38. package/src/executors/tsc/tsc.batch-impl.d.ts +4 -0
  39. package/src/executors/tsc/tsc.batch-impl.js +47 -0
  40. package/src/executors/tsc/tsc.impl.d.ts +0 -1
  41. package/src/executors/tsc/tsc.impl.js +4 -40
  42. package/src/executors/verdaccio/compat.js +0 -1
  43. package/src/executors/verdaccio/verdaccio.impl.d.ts +1 -0
  44. package/src/executors/verdaccio/verdaccio.impl.js +25 -23
  45. package/src/generators/convert-to-swc/convert-to-swc.js +0 -1
  46. package/src/generators/init/init.js +0 -1
  47. package/src/generators/library/library.js +2 -11
  48. package/src/generators/library/schema.json +7 -6
  49. package/src/generators/setup-build/generator.d.ts +5 -0
  50. package/src/generators/setup-build/generator.js +133 -0
  51. package/src/generators/setup-build/schema.d.ts +7 -0
  52. package/src/generators/setup-build/schema.json +42 -0
  53. package/src/generators/setup-verdaccio/files/config.yml +1 -1
  54. package/src/generators/setup-verdaccio/generator.js +5 -2
  55. package/src/index.d.ts +1 -0
  56. package/src/index.js +1 -1
  57. package/src/internal.js +0 -1
  58. package/src/migrations/update-13-10-1/update-lib-swcrc-exclude.js +0 -1
  59. package/src/migrations/update-13-8-5/update-node-executor.js +0 -1
  60. package/src/migrations/update-13-8-5/update-swcrc.js +0 -1
  61. package/src/migrations/update-14-0-0/exclude-jest-config-swcrc.js +0 -1
  62. package/src/migrations/update-14-1-5/update-swcrc-path.js +0 -1
  63. package/src/migrations/update-15-8-0/rename-swcrc-config.js +0 -1
  64. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -1
  65. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  66. package/src/plugins/jest/start-local-registry.js +61 -0
  67. package/src/utils/add-babel-inputs.d.ts +1 -0
  68. package/src/utils/add-babel-inputs.js +2 -1
  69. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  70. package/src/utils/add-local-registry-scripts.js +57 -0
  71. package/src/utils/assets/assets.js +0 -1
  72. package/src/utils/assets/copy-assets-handler.d.ts +5 -1
  73. package/src/utils/assets/copy-assets-handler.js +34 -24
  74. package/src/utils/assets/index.js +0 -1
  75. package/src/utils/buildable-libs-utils.js +0 -1
  76. package/src/utils/check-dependencies.js +0 -1
  77. package/src/utils/code-frames/highlight.js +0 -1
  78. package/src/utils/code-frames/identifiers.js +0 -1
  79. package/src/utils/compiler-helper-dependency.js +0 -1
  80. package/src/utils/generate-globs.js +0 -1
  81. package/src/utils/get-import-path.js +0 -1
  82. package/src/utils/inline.d.ts +1 -1
  83. package/src/utils/inline.js +3 -4
  84. package/src/utils/minimal-publish-script.js +2 -6
  85. package/src/utils/package-json/get-npm-scope.js +0 -1
  86. package/src/utils/package-json/index.js +0 -1
  87. package/src/utils/package-json/update-package-json.js +0 -1
  88. package/src/utils/prettier.js +0 -1
  89. package/src/utils/schema.d.ts +3 -2
  90. package/src/utils/swc/add-swc-config.d.ts +1 -1
  91. package/src/utils/swc/add-swc-config.js +0 -1
  92. package/src/utils/swc/add-swc-dependencies.js +0 -1
  93. package/src/utils/swc/compile-swc.js +0 -1
  94. package/src/utils/swc/get-swcrc-path.js +0 -1
  95. package/src/utils/swc/inline.js +0 -1
  96. package/src/utils/typescript/__mocks__/plugin-a.js +0 -1
  97. package/src/utils/typescript/__mocks__/plugin-b.js +0 -1
  98. package/src/utils/typescript/add-tslib-dependencies.js +0 -1
  99. package/src/utils/typescript/ast-utils.js +0 -1
  100. package/src/utils/typescript/compile-typescript-files.js +0 -1
  101. package/src/utils/typescript/create-ts-config.js +0 -1
  102. package/src/utils/typescript/ensure-typescript.js +0 -1
  103. package/src/utils/typescript/get-source-nodes.js +0 -1
  104. package/src/utils/typescript/load-ts-transformers.js +0 -1
  105. package/src/utils/typescript/print-diagnostics.js +0 -1
  106. package/src/utils/typescript/run-type-check.js +0 -1
  107. package/src/utils/typescript/ts-config.js +0 -1
  108. package/src/utils/typescript/types.js +0 -1
  109. package/src/utils/versions.js +0 -1
  110. package/src/utils/watch-for-single-file-changes.js +0 -1
  111. package/babel.js.map +0 -1
  112. package/src/executors/node/compat.js.map +0 -1
  113. package/src/executors/node/lib/kill-tree.js.map +0 -1
  114. package/src/executors/node/node-with-require-overrides.js.map +0 -1
  115. package/src/executors/node/node.impl.js.map +0 -1
  116. package/src/executors/swc/compat.js.map +0 -1
  117. package/src/executors/swc/swc.impl.js.map +0 -1
  118. package/src/executors/tsc/compat.js.map +0 -1
  119. package/src/executors/tsc/tsc.impl.js.map +0 -1
  120. package/src/executors/verdaccio/compat.js.map +0 -1
  121. package/src/executors/verdaccio/verdaccio.impl.js.map +0 -1
  122. package/src/generators/convert-to-swc/convert-to-swc.js.map +0 -1
  123. package/src/generators/init/init.js.map +0 -1
  124. package/src/generators/library/library.js.map +0 -1
  125. package/src/generators/setup-verdaccio/generator.js.map +0 -1
  126. package/src/index.js.map +0 -1
  127. package/src/internal.js.map +0 -1
  128. package/src/migrations/update-13-10-1/update-lib-swcrc-exclude.js.map +0 -1
  129. package/src/migrations/update-13-8-5/update-node-executor.js.map +0 -1
  130. package/src/migrations/update-13-8-5/update-swcrc.js.map +0 -1
  131. package/src/migrations/update-14-0-0/exclude-jest-config-swcrc.js.map +0 -1
  132. package/src/migrations/update-14-1-5/update-swcrc-path.js.map +0 -1
  133. package/src/migrations/update-15-8-0/rename-swcrc-config.js.map +0 -1
  134. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
  135. package/src/utils/add-babel-inputs.js.map +0 -1
  136. package/src/utils/assets/assets.js.map +0 -1
  137. package/src/utils/assets/copy-assets-handler.js.map +0 -1
  138. package/src/utils/assets/index.js.map +0 -1
  139. package/src/utils/buildable-libs-utils.js.map +0 -1
  140. package/src/utils/check-dependencies.js.map +0 -1
  141. package/src/utils/code-frames/highlight.js.map +0 -1
  142. package/src/utils/code-frames/identifiers.js.map +0 -1
  143. package/src/utils/compiler-helper-dependency.js.map +0 -1
  144. package/src/utils/generate-globs.js.map +0 -1
  145. package/src/utils/get-import-path.js.map +0 -1
  146. package/src/utils/inline.js.map +0 -1
  147. package/src/utils/minimal-publish-script.js.map +0 -1
  148. package/src/utils/package-json/get-npm-scope.js.map +0 -1
  149. package/src/utils/package-json/index.js.map +0 -1
  150. package/src/utils/package-json/update-package-json.js.map +0 -1
  151. package/src/utils/prettier.js.map +0 -1
  152. package/src/utils/swc/add-swc-config.js.map +0 -1
  153. package/src/utils/swc/add-swc-dependencies.js.map +0 -1
  154. package/src/utils/swc/compile-swc.js.map +0 -1
  155. package/src/utils/swc/get-swcrc-path.js.map +0 -1
  156. package/src/utils/swc/inline.js.map +0 -1
  157. package/src/utils/typescript/__mocks__/plugin-a.js.map +0 -1
  158. package/src/utils/typescript/__mocks__/plugin-b.js.map +0 -1
  159. package/src/utils/typescript/add-tslib-dependencies.js.map +0 -1
  160. package/src/utils/typescript/ast-utils.js.map +0 -1
  161. package/src/utils/typescript/compile-typescript-files.js.map +0 -1
  162. package/src/utils/typescript/create-ts-config.js.map +0 -1
  163. package/src/utils/typescript/ensure-typescript.js.map +0 -1
  164. package/src/utils/typescript/get-source-nodes.js.map +0 -1
  165. package/src/utils/typescript/load-ts-transformers.js.map +0 -1
  166. package/src/utils/typescript/print-diagnostics.js.map +0 -1
  167. package/src/utils/typescript/run-type-check.js.map +0 -1
  168. package/src/utils/typescript/ts-config.js.map +0 -1
  169. package/src/utils/typescript/types.js.map +0 -1
  170. package/src/utils/versions.js.map +0 -1
  171. package/src/utils/watch-for-single-file-changes.js.map +0 -1
@@ -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;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatWatchStatusReport = 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
+ // adapted from TS default watch status reporter
24
+ function formatWatchStatusReport(diagnostic, newLine) {
25
+ let output = `[${formatColorAndReset(getLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
26
+ output += `${ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine)}${newLine + newLine}`;
27
+ return output;
28
+ }
29
+ exports.formatWatchStatusReport = formatWatchStatusReport;
30
+ function formatColorAndReset(text, formatStyle) {
31
+ const resetEscapeSequence = '\u001b[0m';
32
+ return formatStyle + text + resetEscapeSequence;
33
+ }
34
+ function getLocaleTimeString() {
35
+ return new Date().toLocaleTimeString();
36
+ }
37
+ var ForegroundColorEscapeSequences;
38
+ (function (ForegroundColorEscapeSequences) {
39
+ ForegroundColorEscapeSequences["Grey"] = "\u001B[90m";
40
+ ForegroundColorEscapeSequences["Red"] = "\u001B[91m";
41
+ ForegroundColorEscapeSequences["Yellow"] = "\u001B[93m";
42
+ ForegroundColorEscapeSequences["Blue"] = "\u001B[94m";
43
+ ForegroundColorEscapeSequences["Cyan"] = "\u001B[96m";
44
+ })(ForegroundColorEscapeSequences || (ForegroundColorEscapeSequences = {}));
@@ -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,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.watchTaskProjectsFileChangesForAssets = exports.watchTaskProjectsPackageJsonFileChanges = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const client_1 = require("nx/src/daemon/client/client");
7
+ const path_1 = require("path");
8
+ function watchTaskProjectsPackageJsonFileChanges(taskInfos, callback) {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const projects = [];
11
+ const packageJsonTaskInfoMap = new Map();
12
+ taskInfos.forEach((t) => {
13
+ projects.push(t.context.projectName);
14
+ packageJsonTaskInfoMap.set((0, path_1.join)(t.options.projectRoot, 'package.json'), t);
15
+ });
16
+ const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({ watchProjects: projects }, (err, data) => {
17
+ var _a;
18
+ if (err === 'closed') {
19
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
20
+ process.exit(1);
21
+ }
22
+ else if (err) {
23
+ devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
24
+ }
25
+ else {
26
+ const changedTasks = [];
27
+ data.changedFiles.forEach((file) => {
28
+ if (packageJsonTaskInfoMap.has(file.path)) {
29
+ changedTasks.push(packageJsonTaskInfoMap.get(file.path));
30
+ }
31
+ });
32
+ if (changedTasks.length) {
33
+ callback(changedTasks);
34
+ }
35
+ }
36
+ });
37
+ return () => unregisterFileWatcher();
38
+ });
39
+ }
40
+ exports.watchTaskProjectsPackageJsonFileChanges = watchTaskProjectsPackageJsonFileChanges;
41
+ function watchTaskProjectsFileChangesForAssets(taskInfos) {
42
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
+ const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({
44
+ watchProjects: taskInfos.map((t) => t.context.projectName),
45
+ includeDependentProjects: true,
46
+ includeGlobalWorkspaceFiles: true,
47
+ }, (err, data) => {
48
+ var _a;
49
+ if (err === 'closed') {
50
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
51
+ process.exit(1);
52
+ }
53
+ else if (err) {
54
+ devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
55
+ }
56
+ else {
57
+ taskInfos.forEach((t) => t.assetsHandler.processWatchEvents(data.changedFiles));
58
+ }
59
+ });
60
+ return () => unregisterFileWatcher();
61
+ });
62
+ }
63
+ 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,2 @@
1
+ export * from './get-custom-transformers-factory';
2
+ export * from './normalize-options';
@@ -0,0 +1,5 @@
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("./normalize-options"), 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,32 @@
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 Object.assign(Object.assign({}, options), { root: contextRoot, sourceRoot,
28
+ projectRoot,
29
+ files,
30
+ outputPath, tsConfig: (0, path_1.join)(contextRoot, options.tsConfig), rootDir, mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')) });
31
+ }
32
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,4 @@
1
+ import type { ExecutorContext, TaskGraph } from '@nx/devkit';
2
+ import type { ExecutorOptions } from '../../utils/schema';
3
+ export declare function tscBatchExecutor(taskGraph: TaskGraph, inputs: Record<string, ExecutorOptions>, overrides: ExecutorOptions, context: ExecutorContext): AsyncGenerator<import("../../../../../build/packages/nx/src/tasks-runner/batch/batch-messages").BatchResults, any, undefined>;
4
+ export default tscBatchExecutor;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tscBatchExecutor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("fs");
6
+ const update_package_json_1 = require("../../utils/package-json/update-package-json");
7
+ const batch_1 = require("./lib/batch");
8
+ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
9
+ return tslib_1.__asyncGenerator(this, arguments, function* tscBatchExecutor_1() {
10
+ const tasksOptions = (0, batch_1.normalizeTasksOptions)(inputs, context);
11
+ let shouldWatch = false;
12
+ Object.values(tasksOptions).forEach((taskOptions) => {
13
+ if (taskOptions.clean) {
14
+ (0, fs_1.rmSync)(taskOptions.outputPath, { force: true, recursive: true });
15
+ }
16
+ if (taskOptions.watch) {
17
+ shouldWatch = true;
18
+ }
19
+ });
20
+ const tsConfigTaskInfoMap = {};
21
+ (0, batch_1.buildTaskInfoPerTsConfigMap)(tsConfigTaskInfoMap, tasksOptions, context, Object.keys(taskGraph.tasks), shouldWatch);
22
+ const typescriptCompilation = (0, batch_1.compileBatchTypescript)(tsConfigTaskInfoMap, taskGraph, shouldWatch, (taskInfo) => {
23
+ taskInfo.assetsHandler.processAllAssetsOnceSync();
24
+ (0, update_package_json_1.updatePackageJson)(taskInfo.options, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
25
+ });
26
+ if (shouldWatch) {
27
+ const taskInfos = Object.values(tsConfigTaskInfoMap);
28
+ const watchAssetsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsFileChangesForAssets)(taskInfos));
29
+ const watchProjectsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsPackageJsonFileChanges)(taskInfos, (changedTaskInfos) => {
30
+ for (const t of changedTaskInfos) {
31
+ (0, update_package_json_1.updatePackageJson)(t.options, t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
32
+ }
33
+ }));
34
+ const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ yield typescriptCompilation.close();
36
+ watchAssetsChangesDisposer();
37
+ watchProjectsChangesDisposer();
38
+ process.exit(exitCode);
39
+ });
40
+ process.on('SIGINT', () => handleTermination(128 + 2));
41
+ process.on('SIGTERM', () => handleTermination(128 + 15));
42
+ }
43
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(typescriptCompilation.iterator))));
44
+ });
45
+ }
46
+ exports.tscBatchExecutor = tscBatchExecutor;
47
+ exports.default = tscBatchExecutor;
@@ -1,7 +1,6 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
2
  import type { TypeScriptCompilationOptions } from '@nx/workspace/src/utilities/typescript/compilation';
3
3
  import { ExecutorOptions, NormalizedExecutorOptions } from '../../utils/schema';
4
- export declare function normalizeOptions(options: ExecutorOptions, contextRoot: string, sourceRoot: string, projectRoot: string): NormalizedExecutorOptions;
5
4
  export declare function createTypeScriptCompilationOptions(normalizedOptions: NormalizedExecutorOptions, context: ExecutorContext): TypeScriptCompilationOptions;
6
5
  export declare function tscExecutor(_options: ExecutorOptions, context: ExecutorContext): AsyncGenerator<import("../../utils/typescript/compile-typescript-files").TypescriptCompilationResult, any, undefined>;
7
6
  export default tscExecutor;
@@ -1,51 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tscExecutor = exports.createTypeScriptCompilationOptions = exports.normalizeOptions = void 0;
3
+ exports.tscExecutor = exports.createTypeScriptCompilationOptions = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const assets_1 = require("../../utils/assets/assets");
6
- const path_1 = require("path");
7
5
  const copy_assets_handler_1 = require("../../utils/assets/copy-assets-handler");
8
6
  const check_dependencies_1 = require("../../utils/check-dependencies");
9
7
  const compiler_helper_dependency_1 = require("../../utils/compiler-helper-dependency");
10
8
  const inline_1 = require("../../utils/inline");
11
9
  const update_package_json_1 = require("../../utils/package-json/update-package-json");
12
10
  const compile_typescript_files_1 = require("../../utils/typescript/compile-typescript-files");
13
- const load_ts_transformers_1 = require("../../utils/typescript/load-ts-transformers");
14
11
  const watch_for_single_file_changes_1 = require("../../utils/watch-for-single-file-changes");
15
- function normalizeOptions(options, contextRoot, sourceRoot, projectRoot) {
16
- const outputPath = (0, path_1.join)(contextRoot, options.outputPath);
17
- const rootDir = options.rootDir
18
- ? (0, path_1.join)(contextRoot, options.rootDir)
19
- : projectRoot;
20
- if (options.watch == null) {
21
- options.watch = false;
22
- }
23
- // TODO: put back when inlining story is more stable
24
- // if (options.external == null) {
25
- // options.external = 'all';
26
- // } else if (Array.isArray(options.external) && options.external.length === 0) {
27
- // options.external = 'none';
28
- // }
29
- if (Array.isArray(options.external) && options.external.length > 0) {
30
- const firstItem = options.external[0];
31
- if (firstItem === 'all' || firstItem === 'none') {
32
- options.external = firstItem;
33
- }
34
- }
35
- const files = (0, assets_1.assetGlobsToFiles)(options.assets, contextRoot, outputPath);
36
- return Object.assign(Object.assign({}, options), { root: contextRoot, sourceRoot,
37
- projectRoot,
38
- files,
39
- outputPath, tsConfig: (0, path_1.join)(contextRoot, options.tsConfig), rootDir, mainOutputPath: (0, path_1.resolve)(outputPath, options.main.replace(`${projectRoot}/`, '').replace('.ts', '.js')) });
40
- }
41
- exports.normalizeOptions = normalizeOptions;
12
+ const lib_1 = require("./lib");
42
13
  function createTypeScriptCompilationOptions(normalizedOptions, context) {
43
- const { compilerPluginHooks } = (0, load_ts_transformers_1.loadTsTransformers)(normalizedOptions.transformers);
44
- const getCustomTransformers = (program) => ({
45
- before: compilerPluginHooks.beforeHooks.map((hook) => hook(program)),
46
- after: compilerPluginHooks.afterHooks.map((hook) => hook(program)),
47
- afterDeclarations: compilerPluginHooks.afterDeclarationsHooks.map((hook) => hook(program)),
48
- });
49
14
  return {
50
15
  outputPath: normalizedOptions.outputPath,
51
16
  projectName: context.projectName,
@@ -54,14 +19,14 @@ function createTypeScriptCompilationOptions(normalizedOptions, context) {
54
19
  tsConfig: normalizedOptions.tsConfig,
55
20
  watch: normalizedOptions.watch,
56
21
  deleteOutputPath: normalizedOptions.clean,
57
- getCustomTransformers,
22
+ getCustomTransformers: (0, lib_1.getCustomTrasformersFactory)(normalizedOptions.transformers),
58
23
  };
59
24
  }
60
25
  exports.createTypeScriptCompilationOptions = createTypeScriptCompilationOptions;
61
26
  function tscExecutor(_options, context) {
62
27
  return tslib_1.__asyncGenerator(this, arguments, function* tscExecutor_1() {
63
28
  const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
64
- const options = normalizeOptions(_options, context.root, sourceRoot, root);
29
+ const options = (0, lib_1.normalizeOptions)(_options, context.root, sourceRoot, root);
65
30
  const { projectRoot, tmpTsConfig, target, dependencies } = (0, check_dependencies_1.checkDependencies)(context, _options.tsConfig);
66
31
  if (tmpTsConfig) {
67
32
  options.tsConfig = tmpTsConfig;
@@ -103,4 +68,3 @@ function tscExecutor(_options, context) {
103
68
  }
104
69
  exports.tscExecutor = tscExecutor;
105
70
  exports.default = tscExecutor;
106
- //# sourceMappingURL=tsc.impl.js.map
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
4
  const verdaccio_impl_1 = require("./verdaccio.impl");
5
5
  exports.default = (0, devkit_1.convertNxExecutor)(verdaccio_impl_1.verdaccioExecutor);
6
- //# sourceMappingURL=compat.js.map
@@ -7,5 +7,6 @@ import { VerdaccioExecutorSchema } from './schema';
7
7
  */
8
8
  export declare function verdaccioExecutor(options: VerdaccioExecutorSchema, context: ExecutorContext): Promise<{
9
9
  success: boolean;
10
+ port: number;
10
11
  }>;
11
12
  export default verdaccioExecutor;
@@ -5,6 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const fs_extra_1 = require("fs-extra");
7
7
  const child_process_1 = require("child_process");
8
+ const detectPort = require("detect-port");
9
+ const path_1 = require("path");
8
10
  let childProcess;
9
11
  /**
10
12
  * - set npm and yarn to use local registry
@@ -19,8 +21,12 @@ function verdaccioExecutor(options, context) {
19
21
  catch (e) {
20
22
  throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
21
23
  }
22
- if (options.clear && options.storage && (0, fs_extra_1.existsSync)(options.storage)) {
23
- (0, fs_extra_1.removeSync)(options.storage);
24
+ if (options.storage) {
25
+ options.storage = (0, path_1.resolve)(context.root, options.storage);
26
+ if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
27
+ (0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
28
+ console.log(`Cleared local registry storage folder ${options.storage}`);
29
+ }
24
30
  }
25
31
  const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
26
32
  const processExitListener = (signal) => {
@@ -36,16 +42,23 @@ function verdaccioExecutor(options, context) {
36
42
  process.on('SIGINT', processExitListener);
37
43
  process.on('SIGHUP', processExitListener);
38
44
  try {
39
- yield startVerdaccio(options);
45
+ const port = yield detectPort(options.port);
46
+ if (port !== options.port) {
47
+ devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
48
+ options.port = port;
49
+ }
50
+ yield startVerdaccio(options, context.root);
40
51
  }
41
52
  catch (e) {
42
- devkit_1.logger.error('Failed to start verdaccio: ' + e.toString());
53
+ devkit_1.logger.error('Failed to start verdaccio: ' + (e === null || e === void 0 ? void 0 : e.toString()));
43
54
  return {
44
55
  success: false,
56
+ port: options.port,
45
57
  };
46
58
  }
47
59
  return {
48
60
  success: true,
61
+ port: options.port,
49
62
  };
50
63
  });
51
64
  }
@@ -53,23 +66,13 @@ exports.verdaccioExecutor = verdaccioExecutor;
53
66
  /**
54
67
  * Fork the verdaccio process: https://verdaccio.org/docs/verdaccio-programmatically/#using-fork-from-child_process-module
55
68
  */
56
- function startVerdaccio(options) {
69
+ function startVerdaccio(options, workspaceRoot) {
57
70
  return new Promise((resolve, reject) => {
58
- childProcess = (0, child_process_1.fork)(require.resolve('verdaccio/bin/verdaccio'), createVerdaccioOptions(options), {
59
- env: Object.assign(Object.assign({}, process.env), { VERDACCIO_HANDLE_KILL_SIGNALS: 'true' }),
60
- stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
61
- });
62
- childProcess.stdout.on('data', (data) => {
63
- process.stdout.write(data);
64
- });
65
- childProcess.stderr.on('data', (data) => {
66
- if (data.includes('VerdaccioWarning') ||
67
- data.includes('DeprecationWarning')) {
68
- process.stdout.write(data);
69
- }
70
- else {
71
- reject(data);
72
- }
71
+ childProcess = (0, child_process_1.fork)(require.resolve('verdaccio/bin/verdaccio'), createVerdaccioOptions(options, workspaceRoot), {
72
+ env: Object.assign(Object.assign(Object.assign({}, process.env), { VERDACCIO_HANDLE_KILL_SIGNALS: 'true' }), (options.storage
73
+ ? { VERDACCIO_STORAGE_PATH: options.storage }
74
+ : {})),
75
+ stdio: 'inherit',
73
76
  });
74
77
  childProcess.on('error', (err) => {
75
78
  reject(err);
@@ -87,13 +90,13 @@ function startVerdaccio(options) {
87
90
  });
88
91
  });
89
92
  }
90
- function createVerdaccioOptions(options) {
93
+ function createVerdaccioOptions(options, workspaceRoot) {
91
94
  const verdaccioArgs = [];
92
95
  if (options.port) {
93
96
  verdaccioArgs.push('--listen', options.port.toString());
94
97
  }
95
98
  if (options.config) {
96
- verdaccioArgs.push('--config', options.config);
99
+ verdaccioArgs.push('--config', (0, path_1.join)(workspaceRoot, options.config));
97
100
  }
98
101
  return verdaccioArgs;
99
102
  }
@@ -164,4 +167,3 @@ function setupYarn(options) {
164
167
  };
165
168
  }
166
169
  exports.default = verdaccioExecutor;
167
- //# sourceMappingURL=verdaccio.impl.js.map
@@ -61,4 +61,3 @@ function checkSwcDependencies(tree, projectConfiguration) {
61
61
  }
62
62
  exports.default = convertToSwcGenerator;
63
63
  exports.convertToSwcSchematic = (0, devkit_1.convertNxGenerator)(convertToSwcGenerator);
64
- //# sourceMappingURL=convert-to-swc.js.map
@@ -112,4 +112,3 @@ function initGenerator(tree, schema) {
112
112
  exports.initGenerator = initGenerator;
113
113
  exports.default = initGenerator;
114
114
  exports.initSchematic = (0, devkit_1.convertNxGenerator)(initGenerator);
115
- //# sourceMappingURL=init.js.map