@nx/js 16.4.0-beta.9 → 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 (38) hide show
  1. package/babel.js +3 -1
  2. package/migrations.json +12 -0
  3. package/package.json +6 -6
  4. package/src/executors/node/node.impl.d.ts +1 -0
  5. package/src/executors/node/node.impl.js +27 -7
  6. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +2 -1
  7. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +22 -17
  8. package/src/executors/tsc/lib/batch/index.d.ts +0 -4
  9. package/src/executors/tsc/lib/batch/index.js +0 -4
  10. package/src/executors/tsc/lib/batch/types.d.ts +5 -0
  11. package/src/executors/tsc/lib/get-task-options.d.ts +8 -0
  12. package/src/executors/tsc/lib/get-task-options.js +51 -0
  13. package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
  14. package/src/executors/tsc/lib/get-tsconfig.js +138 -0
  15. package/src/executors/tsc/lib/index.d.ts +2 -0
  16. package/src/executors/tsc/lib/index.js +2 -0
  17. package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
  18. package/src/executors/tsc/lib/typescript-compilation.js +206 -0
  19. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.d.ts → typescript-diagnostic-reporters.d.ts} +0 -1
  20. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.js → typescript-diagnostic-reporters.js} +1 -8
  21. package/src/executors/tsc/tsc.batch-impl.d.ts +3 -2
  22. package/src/executors/tsc/tsc.batch-impl.js +97 -7
  23. package/src/executors/verdaccio/verdaccio.impl.js +60 -24
  24. package/src/generators/setup-verdaccio/files/config.yml +4 -5
  25. package/src/internal.d.ts +1 -0
  26. package/src/internal.js +4 -1
  27. package/src/plugins/jest/start-local-registry.js +5 -1
  28. package/src/utils/compiler-helper-dependency.d.ts +2 -1
  29. package/src/utils/compiler-helper-dependency.js +14 -4
  30. package/src/utils/versions.d.ts +1 -1
  31. package/src/utils/versions.js +1 -1
  32. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.d.ts +0 -3
  33. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.js +0 -52
  34. package/src/executors/tsc/lib/batch/get-task-options.d.ts +0 -3
  35. package/src/executors/tsc/lib/batch/get-task-options.js +0 -24
  36. package/src/executors/tsc/lib/batch/typescript-compilation.d.ts +0 -7
  37. package/src/executors/tsc/lib/batch/typescript-compilation.js +0 -195
  38. package/src/generators/setup-verdaccio/files/htpasswd +0 -1
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileTypescriptSolution = void 0;
4
+ const tslib_1 = require("tslib");
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 compileTypescriptSolution(context, watch, logger, hooks, reporters) {
16
+ if (watch) {
17
+ // create an AsyncIterable that doesn't complete, watch mode is only
18
+ // stopped by killing the process
19
+ return (0, async_iterable_1.createAsyncIterable)(({ next }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ hooks !== null && hooks !== void 0 ? hooks : (hooks = {});
21
+ const callerAfterProjectCompilationCallback = hooks.afterProjectCompilationCallback;
22
+ hooks.afterProjectCompilationCallback = (tsConfig, success) => {
23
+ callerAfterProjectCompilationCallback === null || callerAfterProjectCompilationCallback === void 0 ? void 0 : callerAfterProjectCompilationCallback(tsConfig, success);
24
+ next({ tsConfig, success });
25
+ };
26
+ compileTSWithWatch(context, logger, hooks, reporters);
27
+ }));
28
+ }
29
+ // turn it into an AsyncIterable
30
+ const compilationGenerator = compileTS(context, logger, hooks, reporters);
31
+ return {
32
+ [Symbol.asyncIterator]() {
33
+ return {
34
+ next() {
35
+ return Promise.resolve(compilationGenerator.next());
36
+ },
37
+ };
38
+ },
39
+ };
40
+ }
41
+ exports.compileTypescriptSolution = compileTypescriptSolution;
42
+ function* compileTS(context, logger, hooks, reporters) {
43
+ var _a, _b, _c;
44
+ let project;
45
+ const formatDiagnosticsHost = {
46
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
47
+ getNewLine: () => ts.sys.newLine,
48
+ getCanonicalFileName: (filename) => ts.sys.useCaseSensitiveFileNames ? filename : filename.toLowerCase(),
49
+ };
50
+ const solutionBuilderHost = ts.createSolutionBuilderHost(getSystem(context),
51
+ /*createProgram*/ undefined, (diagnostic) => {
52
+ var _a;
53
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatDiagnosticReport)(diagnostic, formatDiagnosticsHost);
54
+ // handles edge case where a wrong a project reference path can't be read
55
+ if (diagnostic.code === TYPESCRIPT_CANNOT_READ_FILE) {
56
+ throw new Error(formattedDiagnostic);
57
+ }
58
+ logger.info(formattedDiagnostic, project.project);
59
+ (_a = reporters === null || reporters === void 0 ? void 0 : reporters.diagnosticReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project.project, diagnostic);
60
+ }, (diagnostic) => {
61
+ var _a;
62
+ const formattedDiagnostic = (0, typescript_diagnostic_reporters_1.formatSolutionBuilderStatusReport)(diagnostic);
63
+ logger.info(formattedDiagnostic, project.project);
64
+ (_a = reporters === null || reporters === void 0 ? void 0 : reporters.solutionBuilderStatusReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project.project, diagnostic);
65
+ });
66
+ const rootNames = Object.keys(context);
67
+ const solutionBuilder = ts.createSolutionBuilder(solutionBuilderHost, rootNames, {});
68
+ // eslint-disable-next-line no-constant-condition
69
+ while (true) {
70
+ project = solutionBuilder.getNextInvalidatedProject();
71
+ if (!project) {
72
+ break;
73
+ }
74
+ const projectContext = context[project.project];
75
+ const projectName = projectContext === null || projectContext === void 0 ? void 0 : projectContext.project;
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
+ logger.warn(`The project ${projectName} ` +
82
+ `is using the deprecated "prepend" Typescript compiler option. ` +
83
+ `This option is not supported by the batch executor and it's ignored.\n`, project.project);
84
+ continue;
85
+ }
86
+ (_a = hooks === null || hooks === void 0 ? void 0 : hooks.beforeProjectCompilationCallback) === null || _a === void 0 ? void 0 : _a.call(hooks, project.project);
87
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
88
+ logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
89
+ // update output timestamps and mark project as complete
90
+ const status = project.done();
91
+ const success = status === ts.ExitStatus.Success;
92
+ if (success) {
93
+ logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
94
+ }
95
+ (_b = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _b === void 0 ? void 0 : _b.call(hooks, project.project, success);
96
+ yield { success, tsConfig: project.project };
97
+ continue;
98
+ }
99
+ logger.info(`Compiling TypeScript files for project "${projectName}"...\n`, project.project);
100
+ // build and mark project as complete
101
+ const status = project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(projectContext.transformers)(project.getProgram()));
102
+ const success = status === ts.ExitStatus.Success;
103
+ if (success) {
104
+ logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
105
+ }
106
+ (_c = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _c === void 0 ? void 0 : _c.call(hooks, project.project, success);
107
+ yield {
108
+ success: status === ts.ExitStatus.Success,
109
+ tsConfig: project.project,
110
+ };
111
+ }
112
+ }
113
+ function compileTSWithWatch(context, logger, hooks, reporters) {
114
+ let project;
115
+ const solutionHost = ts.createSolutionBuilderWithWatchHost(getSystem(context),
116
+ /*createProgram*/ undefined);
117
+ if (reporters === null || reporters === void 0 ? void 0 : reporters.diagnosticReporter) {
118
+ const originalDiagnosticReporter = solutionHost.reportDiagnostic;
119
+ solutionHost.reportDiagnostic = (diagnostic) => {
120
+ originalDiagnosticReporter(diagnostic);
121
+ reporters.diagnosticReporter(project.project, diagnostic);
122
+ };
123
+ }
124
+ if (reporters === null || reporters === void 0 ? void 0 : reporters.solutionBuilderStatusReporter) {
125
+ const originalSolutionBuilderStatusReporter = solutionHost.reportSolutionBuilderStatus;
126
+ solutionHost.reportDiagnostic = (diagnostic) => {
127
+ originalSolutionBuilderStatusReporter(diagnostic);
128
+ reporters.solutionBuilderStatusReporter(project.project, diagnostic);
129
+ };
130
+ }
131
+ const originalWatchStatusReporter = solutionHost.onWatchStatusChange;
132
+ solutionHost.onWatchStatusChange = (diagnostic, newLine, options, errorCount) => {
133
+ var _a;
134
+ originalWatchStatusReporter(diagnostic, newLine, options, errorCount);
135
+ if (diagnostic.code ===
136
+ TYPESCRIPT_FILE_CHANGE_DETECTED_STARTING_INCREMENTAL_COMPILATION) {
137
+ // there's a change, build invalidated projects
138
+ build();
139
+ }
140
+ (_a = reporters === null || reporters === void 0 ? void 0 : reporters.watchStatusReporter) === null || _a === void 0 ? void 0 : _a.call(reporters, project === null || project === void 0 ? void 0 : project.project, diagnostic, newLine, options, errorCount);
141
+ };
142
+ const rootNames = Object.keys(context);
143
+ const solutionBuilder = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {});
144
+ const build = () => {
145
+ var _a, _b;
146
+ while (true) {
147
+ project = solutionBuilder.getNextInvalidatedProject();
148
+ if (!project) {
149
+ break;
150
+ }
151
+ const projectContext = context[project.project];
152
+ const projectName = projectContext.project;
153
+ /**
154
+ * This only applies when the deprecated `prepend` option is set to `true`.
155
+ * Skip support.
156
+ */
157
+ if (project.kind === ts.InvalidatedProjectKind.UpdateBundle) {
158
+ logger.warn(`The project ${projectName} ` +
159
+ `is using the deprecated "prepend" Typescript compiler option. ` +
160
+ `This option is not supported by the batch executor and it's ignored.`);
161
+ continue;
162
+ }
163
+ hooks === null || hooks === void 0 ? void 0 : hooks.beforeProjectCompilationCallback(project.project);
164
+ if (project.kind === ts.InvalidatedProjectKind.UpdateOutputFileStamps) {
165
+ if (projectName) {
166
+ logger.info(`Updating output timestamps of project "${projectName}"...\n`, project.project);
167
+ }
168
+ // update output timestamps and mark project as complete
169
+ const status = project.done();
170
+ const success = status === ts.ExitStatus.Success;
171
+ if (projectName && success) {
172
+ logger.info(`Done updating output timestamps of project "${projectName}"...\n`, project.project);
173
+ }
174
+ (_a = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _a === void 0 ? void 0 : _a.call(hooks, project.project, success);
175
+ continue;
176
+ }
177
+ logger.info(`Compiling TypeScript files for project "${projectName}"...\n`, project.project);
178
+ // build and mark project as complete
179
+ const status = project.done(undefined, undefined, (0, get_custom_transformers_factory_1.getCustomTrasformersFactory)(projectContext.transformers)(project.getProgram()));
180
+ const success = status === ts.ExitStatus.Success;
181
+ if (success) {
182
+ logger.info(`Done compiling TypeScript files for project "${projectName}".\n`, project.project);
183
+ }
184
+ (_b = hooks === null || hooks === void 0 ? void 0 : hooks.afterProjectCompilationCallback) === null || _b === void 0 ? void 0 : _b.call(hooks, project.project, success);
185
+ }
186
+ };
187
+ // initial build
188
+ build();
189
+ /**
190
+ * This is a workaround to get the TS file watching to kick off. It won't
191
+ * build twice since the `build` call above will mark invalidated projects
192
+ * as completed and then, the implementation of the `solutionBuilder.build`
193
+ * skips them.
194
+ * We can't rely solely in `solutionBuilder.build()` because it doesn't
195
+ * accept custom transformers.
196
+ */
197
+ solutionBuilder.build();
198
+ }
199
+ function getSystem(context) {
200
+ return Object.assign(Object.assign({}, ts.sys), { readFile(path, encoding) {
201
+ if (context[path]) {
202
+ return context[path].tsConfig.content;
203
+ }
204
+ return ts.sys.readFile(path, encoding);
205
+ } });
206
+ }
@@ -1,4 +1,3 @@
1
1
  import * as ts from 'typescript';
2
2
  export declare function formatDiagnosticReport(diagnostic: ts.Diagnostic, host: ts.FormatDiagnosticsHost): string;
3
3
  export declare function formatSolutionBuilderStatusReport(diagnostic: ts.Diagnostic): string;
4
- export declare function formatWatchStatusReport(diagnostic: ts.Diagnostic, newLine: string): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatWatchStatusReport = exports.formatSolutionBuilderStatusReport = exports.formatDiagnosticReport = void 0;
3
+ exports.formatSolutionBuilderStatusReport = exports.formatDiagnosticReport = void 0;
4
4
  const ts = require("typescript");
5
5
  // adapted from TS default diagnostic reporter
6
6
  function formatDiagnosticReport(diagnostic, host) {
@@ -20,13 +20,6 @@ function formatSolutionBuilderStatusReport(diagnostic) {
20
20
  return formattedDiagnostic;
21
21
  }
22
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
23
  function formatColorAndReset(text, formatStyle) {
31
24
  const resetEscapeSequence = '\u001b[0m';
32
25
  return formatStyle + text + resetEscapeSequence;
@@ -1,4 +1,5 @@
1
- import type { ExecutorContext, TaskGraph } from '@nx/devkit';
1
+ import { ExecutorContext, TaskGraph } from '@nx/devkit';
2
+ import type { BatchExecutorTaskResult } from 'nx/src/config/misc-interfaces';
2
3
  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 declare function tscBatchExecutor(taskGraph: TaskGraph, inputs: Record<string, ExecutorOptions>, overrides: ExecutorOptions, context: ExecutorContext): AsyncGenerator<BatchExecutorTaskResult, any, unknown>;
4
5
  export default tscBatchExecutor;
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tscBatchExecutor = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
5
6
  const fs_1 = require("fs");
7
+ const async_iterator_1 = require("nx/src/utils/async-iterator");
6
8
  const update_package_json_1 = require("../../utils/package-json/update-package-json");
9
+ const lib_1 = require("./lib");
7
10
  const batch_1 = require("./lib/batch");
8
11
  function tscBatchExecutor(taskGraph, inputs, overrides, context) {
9
12
  return tslib_1.__asyncGenerator(this, arguments, function* tscBatchExecutor_1() {
@@ -17,11 +20,43 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
17
20
  shouldWatch = true;
18
21
  }
19
22
  });
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);
23
+ const taskInMemoryTsConfigMap = (0, lib_1.getProcessedTaskTsConfigs)(Object.keys(taskGraph.tasks), tasksOptions, context);
24
+ const tsConfigTaskInfoMap = (0, batch_1.createTaskInfoPerTsConfigMap)(tasksOptions, context, Object.keys(taskGraph.tasks), taskInMemoryTsConfigMap);
25
+ const tsCompilationContext = createTypescriptCompilationContext(tsConfigTaskInfoMap, taskInMemoryTsConfigMap, context);
26
+ const logger = {
27
+ error: (message, tsConfig) => {
28
+ process.stderr.write(message);
29
+ if (tsConfig) {
30
+ tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
31
+ }
32
+ },
33
+ info: (message, tsConfig) => {
34
+ process.stdout.write(message);
35
+ if (tsConfig) {
36
+ tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
37
+ }
38
+ },
39
+ warn: (message, tsConfig) => {
40
+ process.stdout.write(message);
41
+ if (tsConfig) {
42
+ tsConfigTaskInfoMap[tsConfig].terminalOutput += message;
43
+ }
44
+ },
45
+ };
46
+ const typescriptCompilation = (0, lib_1.compileTypescriptSolution)(tsCompilationContext, shouldWatch, logger, {
47
+ beforeProjectCompilationCallback: (tsConfig) => {
48
+ if (tsConfigTaskInfoMap[tsConfig]) {
49
+ tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
50
+ }
51
+ },
52
+ afterProjectCompilationCallback: (tsConfig) => {
53
+ if (tsConfigTaskInfoMap[tsConfig]) {
54
+ const taskInfo = tsConfigTaskInfoMap[tsConfig];
55
+ taskInfo.assetsHandler.processAllAssetsOnceSync();
56
+ (0, update_package_json_1.updatePackageJson)(taskInfo.options, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
57
+ taskInfo.endTime = Date.now();
58
+ }
59
+ },
25
60
  });
26
61
  if (shouldWatch) {
27
62
  const taskInfos = Object.values(tsConfigTaskInfoMap);
@@ -32,16 +67,71 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
32
67
  }
33
68
  }));
34
69
  const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
35
- yield typescriptCompilation.close();
36
70
  watchAssetsChangesDisposer();
37
71
  watchProjectsChangesDisposer();
38
72
  process.exit(exitCode);
39
73
  });
40
74
  process.on('SIGINT', () => handleTermination(128 + 2));
41
75
  process.on('SIGTERM', () => handleTermination(128 + 15));
76
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(mapAsyncIterable(typescriptCompilation, (iterator) => tslib_1.__awaiter(this, void 0, void 0, function* () {
77
+ // drain the iterator, we don't use the results
78
+ yield (0, async_iterator_1.getLastValueFromAsyncIterableIterator)(iterator);
79
+ return { value: undefined, done: true };
80
+ }))))));
42
81
  }
43
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(typescriptCompilation.iterator))));
82
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(mapAsyncIterable(typescriptCompilation, (iterator) => tslib_1.__awaiter(this, void 0, void 0, function* () {
83
+ const { value, done } = yield iterator.next();
84
+ if (done) {
85
+ return { value, done: true };
86
+ }
87
+ const taskResult = {
88
+ task: tsConfigTaskInfoMap[value.tsConfig].task,
89
+ result: {
90
+ success: value.success,
91
+ terminalOutput: tsConfigTaskInfoMap[value.tsConfig].terminalOutput,
92
+ startTime: tsConfigTaskInfoMap[value.tsConfig].startTime,
93
+ endTime: tsConfigTaskInfoMap[value.tsConfig].endTime,
94
+ },
95
+ };
96
+ return { value: taskResult, done: false };
97
+ }))))));
44
98
  });
45
99
  }
46
100
  exports.tscBatchExecutor = tscBatchExecutor;
47
101
  exports.default = tscBatchExecutor;
102
+ function mapAsyncIterable(iterable, nextFn) {
103
+ return tslib_1.__asyncGenerator(this, arguments, function* mapAsyncIterable_1() {
104
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues({
105
+ [Symbol.asyncIterator]() {
106
+ const iterator = iterable[Symbol.asyncIterator].call(iterable);
107
+ return {
108
+ next() {
109
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
110
+ return yield nextFn(iterator);
111
+ });
112
+ },
113
+ };
114
+ },
115
+ }))));
116
+ });
117
+ }
118
+ function createTypescriptCompilationContext(tsConfigTaskInfoMap, taskInMemoryTsConfigMap, context) {
119
+ const tsCompilationContext = Object.entries(tsConfigTaskInfoMap).reduce((acc, [tsConfig, taskInfo]) => {
120
+ acc[tsConfig] = {
121
+ project: taskInfo.context.projectName,
122
+ tsConfig: taskInfo.tsConfig,
123
+ transformers: taskInfo.options.transformers,
124
+ };
125
+ return acc;
126
+ }, {});
127
+ Object.entries(taskInMemoryTsConfigMap).forEach(([task, tsConfig]) => {
128
+ if (!tsCompilationContext[tsConfig.path]) {
129
+ tsCompilationContext[tsConfig.path] = {
130
+ project: (0, devkit_1.parseTargetString)(task, context.projectGraph).project,
131
+ transformers: [],
132
+ tsConfig: tsConfig,
133
+ };
134
+ }
135
+ });
136
+ return tsCompilationContext;
137
+ }
@@ -7,6 +7,7 @@ const fs_extra_1 = require("fs-extra");
7
7
  const child_process_1 = require("child_process");
8
8
  const detectPort = require("detect-port");
9
9
  const path_1 = require("path");
10
+ const semver_1 = require("semver");
10
11
  let childProcess;
11
12
  /**
12
13
  * - set npm and yarn to use local registry
@@ -28,6 +29,11 @@ function verdaccioExecutor(options, context) {
28
29
  console.log(`Cleared local registry storage folder ${options.storage}`);
29
30
  }
30
31
  }
32
+ const port = yield detectPort(options.port);
33
+ if (port !== options.port) {
34
+ devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
35
+ options.port = port;
36
+ }
31
37
  const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
32
38
  const processExitListener = (signal) => {
33
39
  if (childProcess) {
@@ -42,11 +48,6 @@ function verdaccioExecutor(options, context) {
42
48
  process.on('SIGINT', processExitListener);
43
49
  process.on('SIGHUP', processExitListener);
44
50
  try {
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
51
  yield startVerdaccio(options, context.root);
51
52
  }
52
53
  catch (e) {
@@ -134,36 +135,71 @@ function setupNpm(options) {
134
135
  }
135
136
  };
136
137
  }
138
+ function getYarnUnsafeHttpWhitelist(isYarnV1) {
139
+ return !isYarnV1
140
+ ? new Set(JSON.parse((0, child_process_1.execSync)(`yarn config get unsafeHttpWhitelist --json`).toString()))
141
+ : null;
142
+ }
143
+ function setYarnUnsafeHttpWhitelist(currentWhitelist, options) {
144
+ if (currentWhitelist.size > 1) {
145
+ (0, child_process_1.execSync)(`yarn config set unsafeHttpWhitelist --json '${JSON.stringify(Array.from(currentWhitelist))}'` + (options.location === 'user' ? ' --home' : ''));
146
+ }
147
+ else {
148
+ (0, child_process_1.execSync)(`yarn config unset unsafeHttpWhitelist` +
149
+ (options.location === 'user' ? ' --home' : ''));
150
+ }
151
+ }
137
152
  function setupYarn(options) {
138
153
  var _a, _b, _c;
154
+ let isYarnV1;
139
155
  try {
140
- (0, child_process_1.execSync)('yarn --version');
156
+ isYarnV1 = (0, semver_1.major)((0, child_process_1.execSync)('yarn --version').toString().trim()) === 1;
141
157
  }
142
- catch (e) {
158
+ catch (_d) {
159
+ // This would fail if yarn is not installed which is okay
143
160
  return () => { };
144
161
  }
145
- let yarnRegistryPath;
146
162
  try {
147
- yarnRegistryPath = (_c = (_b = (_a = (0, child_process_1.execSync)(`yarn config get registry`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
148
- (0, child_process_1.execSync)(`yarn config set registry http://localhost:${options.port}/`);
163
+ const registryConfigName = isYarnV1 ? 'registry' : 'npmRegistryServer';
164
+ const yarnRegistryPath = (_c = (_b = (_a = (0, child_process_1.execSync)(`yarn config get ${registryConfigName}`)) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.replace('\u001b[2K\u001b[1G', ''); // strip out ansi codes
165
+ (0, child_process_1.execSync)(`yarn config set ${registryConfigName} http://localhost:${options.port}/` +
166
+ (options.location === 'user' ? ' --home' : ''));
149
167
  devkit_1.logger.info(`Set yarn registry to http://localhost:${options.port}/`);
168
+ const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
169
+ let whitelistedLocalhost = false;
170
+ if (!isYarnV1 && !currentWhitelist.has('localhost')) {
171
+ whitelistedLocalhost = true;
172
+ currentWhitelist.add('localhost');
173
+ setYarnUnsafeHttpWhitelist(currentWhitelist, options);
174
+ devkit_1.logger.info(`Whitelisted http://localhost:${options.port}/ as an unsafe http server`);
175
+ }
176
+ return () => {
177
+ try {
178
+ if (yarnRegistryPath) {
179
+ (0, child_process_1.execSync)(`yarn config set ${registryConfigName} ${yarnRegistryPath}` +
180
+ (options.location === 'user' ? ' --home' : ''));
181
+ devkit_1.logger.info(`Reset yarn ${registryConfigName} to ${yarnRegistryPath}`);
182
+ }
183
+ else {
184
+ (0, child_process_1.execSync)(`yarn config ${isYarnV1 ? 'delete' : 'unset'} ${registryConfigName}` +
185
+ (options.location === 'user' ? ' --home' : ''));
186
+ }
187
+ if (whitelistedLocalhost) {
188
+ const currentWhitelist = getYarnUnsafeHttpWhitelist(isYarnV1);
189
+ if (currentWhitelist.has('localhost')) {
190
+ currentWhitelist.delete('localhost');
191
+ setYarnUnsafeHttpWhitelist(currentWhitelist, options);
192
+ devkit_1.logger.info(`Removed http://localhost:${options.port}/ as an unsafe http server`);
193
+ }
194
+ }
195
+ }
196
+ catch (e) {
197
+ throw new Error(`Failed to reset yarn registry: ${e.message}`);
198
+ }
199
+ };
150
200
  }
151
201
  catch (e) {
152
202
  throw new Error(`Failed to set yarn registry to http://localhost:${options.port}/: ${e.message}`);
153
203
  }
154
- return () => {
155
- try {
156
- if (yarnRegistryPath) {
157
- (0, child_process_1.execSync)(`yarn config set registry ${yarnRegistryPath}`);
158
- devkit_1.logger.info(`Reset yarn registry to ${yarnRegistryPath}`);
159
- }
160
- else {
161
- (0, child_process_1.execSync)(`yarn config delete registry`);
162
- }
163
- }
164
- catch (e) {
165
- throw new Error(`Failed to reset yarn registry: ${e.message}`);
166
- }
167
- };
168
204
  }
169
205
  exports.default = verdaccioExecutor;
@@ -1,10 +1,6 @@
1
1
  # path to a directory with all packages
2
2
  storage: ../tmp/local-registry/storage
3
3
 
4
- auth:
5
- htpasswd:
6
- file: ./htpasswd
7
-
8
4
  # a list of other known repositories we can talk to
9
5
  uplinks:
10
6
  npmjs:
@@ -26,4 +22,7 @@ packages:
26
22
  logs:
27
23
  type: stdout
28
24
  format: pretty
29
- level: http
25
+ level: warn
26
+
27
+ publish:
28
+ allow_offline: true # set offline to true to allow publish offline
package/src/internal.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { resolveModuleByImport } from './utils/typescript/ast-utils';
2
2
  export { registerTsProject, registerTsConfigPaths, } from 'nx/src/plugins/js/utils/register';
3
3
  export { TargetProjectLocator } from 'nx/src/plugins/js/project-graph/build-dependencies/target-project-locator';
4
+ export { findProjectsNpmDependencies } from 'nx/src/plugins/js/package-json/create-package-json';
package/src/internal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TargetProjectLocator = exports.registerTsConfigPaths = exports.registerTsProject = exports.resolveModuleByImport = void 0;
3
+ exports.findProjectsNpmDependencies = exports.TargetProjectLocator = exports.registerTsConfigPaths = exports.registerTsProject = exports.resolveModuleByImport = void 0;
4
4
  var ast_utils_1 = require("./utils/typescript/ast-utils");
5
5
  Object.defineProperty(exports, "resolveModuleByImport", { enumerable: true, get: function () { return ast_utils_1.resolveModuleByImport; } });
6
6
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
@@ -10,3 +10,6 @@ Object.defineProperty(exports, "registerTsConfigPaths", { enumerable: true, get:
10
10
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
11
11
  var target_project_locator_1 = require("nx/src/plugins/js/project-graph/build-dependencies/target-project-locator");
12
12
  Object.defineProperty(exports, "TargetProjectLocator", { enumerable: true, get: function () { return target_project_locator_1.TargetProjectLocator; } });
13
+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports
14
+ var create_package_json_1 = require("nx/src/plugins/js/package-json/create-package-json");
15
+ Object.defineProperty(exports, "findProjectsNpmDependencies", { enumerable: true, get: function () { return create_package_json_1.findProjectsNpmDependencies; } });
@@ -28,8 +28,12 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, }) {
28
28
  console.log('Local registry started on port ' + port);
29
29
  const registry = `http://localhost:${port}`;
30
30
  process.env.npm_config_registry = registry;
31
- process.env.YARN_REGISTRY = registry;
32
31
  (0, child_process_1.execSync)(`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`);
32
+ // yarnv1
33
+ process.env.YARN_REGISTRY = registry;
34
+ // yarnv2
35
+ process.env.YARN_NPM_REGISTRY_SERVER = registry;
36
+ process.env.YARN_UNSAFE_HTTP_WHITELIST = 'localhost';
33
37
  console.log('Set npm and yarn config registry to ' + registry);
34
38
  resolve(() => {
35
39
  childProcess.kill();
@@ -1,4 +1,4 @@
1
- import { ProjectGraph, ProjectGraphDependency } from '@nx/devkit';
1
+ import { type ProjectGraph, type ProjectGraphDependency } from '@nx/devkit';
2
2
  import { DependentBuildableProjectNode } from './buildable-libs-utils';
3
3
  export declare enum HelperDependency {
4
4
  tsc = "npm:tslib",
@@ -11,6 +11,7 @@ export declare enum HelperDependency {
11
11
  * @param {HelperDependency} helperDependency
12
12
  * @param {string} configPath
13
13
  * @param {DependentBuildableProjectNode[]} dependencies
14
+ * @param {ProjectGraph} projectGraph
14
15
  * @param {boolean=false} returnDependencyIfFound
15
16
  */
16
17
  export declare function getHelperDependency(helperDependency: HelperDependency, configPath: string, dependencies: DependentBuildableProjectNode[], projectGraph: ProjectGraph, returnDependencyIfFound?: boolean): DependentBuildableProjectNode | null;
@@ -9,7 +9,7 @@ var HelperDependency;
9
9
  (function (HelperDependency) {
10
10
  HelperDependency["tsc"] = "npm:tslib";
11
11
  HelperDependency["swc"] = "npm:@swc/helpers";
12
- })(HelperDependency = exports.HelperDependency || (exports.HelperDependency = {}));
12
+ })(HelperDependency || (exports.HelperDependency = HelperDependency = {}));
13
13
  const jsExecutors = {
14
14
  '@nx/js:tsc': {
15
15
  helperDependency: HelperDependency.tsc,
@@ -27,6 +27,7 @@ const jsExecutors = {
27
27
  * @param {HelperDependency} helperDependency
28
28
  * @param {string} configPath
29
29
  * @param {DependentBuildableProjectNode[]} dependencies
30
+ * @param {ProjectGraph} projectGraph
30
31
  * @param {boolean=false} returnDependencyIfFound
31
32
  */
32
33
  function getHelperDependency(helperDependency, configPath, dependencies, projectGraph, returnDependencyIfFound = false) {
@@ -50,7 +51,17 @@ function getHelperDependency(helperDependency, configPath, dependencies, project
50
51
  }
51
52
  if (!isHelperNeeded)
52
53
  return null;
53
- const libNode = projectGraph.externalNodes[helperDependency];
54
+ let libNode = projectGraph[helperDependency];
55
+ // If libNode is not found due to the version suffix from pnpm lockfile, try to match it by package name.
56
+ if (!libNode) {
57
+ for (const nodeName of Object.keys(projectGraph.externalNodes)) {
58
+ const node = projectGraph.externalNodes[nodeName];
59
+ if (`npm:${node.data.packageName}` === helperDependency) {
60
+ libNode = node;
61
+ break;
62
+ }
63
+ }
64
+ }
54
65
  if (!libNode) {
55
66
  devkit_1.logger.warn(`Your library compilation option specifies that the compiler external helper (${helperDependency.split(':')[1]}) is needed but it is not installed.`);
56
67
  return null;
@@ -74,8 +85,7 @@ function getHelperDependenciesFromProjectGraph(contextRoot, sourceProject, proje
74
85
  const internalDependencies = sourceDependencies.reduce((result, dependency) => {
75
86
  // we check if a dependency is part of the workspace and if it's a library
76
87
  // because we wouldn't want to include external dependencies (npm packages)
77
- if (!dependency.target.startsWith('npm:') &&
78
- !!projectGraph.nodes[dependency.target] &&
88
+ if (projectGraph.nodes[dependency.target] &&
79
89
  projectGraph.nodes[dependency.target].type === 'lib') {
80
90
  const targetData = projectGraph.nodes[dependency.target].data;
81
91
  // check if the dependency has a buildable target with one of the jsExecutors
@@ -8,7 +8,7 @@ export declare const swcNodeVersion = "~1.4.2";
8
8
  export declare const tsLibVersion = "^2.3.0";
9
9
  export declare const typesNodeVersion = "18.7.1";
10
10
  export declare const verdaccioVersion = "^5.0.4";
11
- export declare const typescriptVersion = "~5.0.2";
11
+ export declare const typescriptVersion = "~5.1.3";
12
12
  /**
13
13
  * The minimum version is currently determined from the lowest version
14
14
  * that's supported by the lowest Angular supported version, e.g.
@@ -12,7 +12,7 @@ exports.tsLibVersion = '^2.3.0';
12
12
  exports.typesNodeVersion = '18.7.1';
13
13
  exports.verdaccioVersion = '^5.0.4';
14
14
  // Typescript
15
- exports.typescriptVersion = '~5.0.2';
15
+ exports.typescriptVersion = '~5.1.3';
16
16
  /**
17
17
  * The minimum version is currently determined from the lowest version
18
18
  * that's supported by the lowest Angular supported version, e.g.
@@ -1,3 +0,0 @@
1
- import type { ExecutorContext } from '@nx/devkit';
2
- import type { NormalizedExecutorOptions } from '../../../../utils/schema';
3
- export declare function generateTempTsConfig(taskOptionsMap: Record<string, NormalizedExecutorOptions>, taskName: string, taskOptions: NormalizedExecutorOptions, context: ExecutorContext): string;