@nx/js 16.4.0-beta.8 → 16.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/babel.js +3 -1
  2. package/migrations.json +12 -0
  3. package/package.json +6 -6
  4. package/plugins/jest/local-registry.d.ts +1 -0
  5. package/plugins/jest/local-registry.js +4 -0
  6. package/src/executors/node/node.impl.d.ts +1 -0
  7. package/src/executors/node/node.impl.js +27 -7
  8. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +2 -1
  9. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +22 -17
  10. package/src/executors/tsc/lib/batch/index.d.ts +0 -4
  11. package/src/executors/tsc/lib/batch/index.js +0 -4
  12. package/src/executors/tsc/lib/batch/types.d.ts +5 -0
  13. package/src/executors/tsc/lib/get-task-options.d.ts +8 -0
  14. package/src/executors/tsc/lib/get-task-options.js +51 -0
  15. package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
  16. package/src/executors/tsc/lib/get-tsconfig.js +138 -0
  17. package/src/executors/tsc/lib/index.d.ts +2 -0
  18. package/src/executors/tsc/lib/index.js +2 -0
  19. package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
  20. package/src/executors/tsc/lib/typescript-compilation.js +206 -0
  21. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.d.ts → typescript-diagnostic-reporters.d.ts} +0 -1
  22. package/src/executors/tsc/lib/{batch/typescript-diagnostic-reporters.js → typescript-diagnostic-reporters.js} +1 -8
  23. package/src/executors/tsc/tsc.batch-impl.d.ts +3 -2
  24. package/src/executors/tsc/tsc.batch-impl.js +97 -7
  25. package/src/executors/verdaccio/verdaccio.impl.js +67 -39
  26. package/src/generators/setup-verdaccio/files/config.yml +5 -6
  27. package/src/generators/setup-verdaccio/generator.js +5 -1
  28. package/src/internal.d.ts +1 -0
  29. package/src/internal.js +4 -1
  30. package/src/plugins/jest/start-local-registry.d.ts +12 -0
  31. package/src/plugins/jest/start-local-registry.js +65 -0
  32. package/src/utils/add-local-registry-scripts.d.ts +5 -0
  33. package/src/utils/add-local-registry-scripts.js +57 -0
  34. package/src/utils/compiler-helper-dependency.d.ts +2 -1
  35. package/src/utils/compiler-helper-dependency.js +14 -4
  36. package/src/utils/minimal-publish-script.js +2 -5
  37. package/src/utils/versions.d.ts +1 -1
  38. package/src/utils/versions.js +1 -1
  39. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.d.ts +0 -3
  40. package/src/executors/tsc/lib/batch/generate-temp-tsconfig.js +0 -52
  41. package/src/executors/tsc/lib/batch/get-task-options.d.ts +0 -3
  42. package/src/executors/tsc/lib/batch/get-task-options.js +0 -24
  43. package/src/executors/tsc/lib/batch/typescript-compilation.d.ts +0 -7
  44. package/src/executors/tsc/lib/batch/typescript-compilation.js +0 -195
  45. package/src/generators/setup-verdaccio/files/htpasswd +0 -1
@@ -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
@@ -21,8 +22,17 @@ function verdaccioExecutor(options, context) {
21
22
  catch (e) {
22
23
  throw new Error('Verdaccio is not installed. Please run `npm install verdaccio` or `yarn add verdaccio`');
23
24
  }
24
- if (options.clear && options.storage && (0, fs_extra_1.existsSync)(options.storage)) {
25
- (0, fs_extra_1.removeSync)(options.storage);
25
+ if (options.storage) {
26
+ options.storage = (0, path_1.resolve)(context.root, options.storage);
27
+ if (options.clear && (0, fs_extra_1.existsSync)(options.storage)) {
28
+ (0, fs_extra_1.rmSync)(options.storage, { recursive: true, force: true });
29
+ console.log(`Cleared local registry storage folder ${options.storage}`);
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;
26
36
  }
27
37
  const cleanupFunctions = options.location === 'none' ? [] : [setupNpm(options), setupYarn(options)];
28
38
  const processExitListener = (signal) => {
@@ -38,11 +48,6 @@ function verdaccioExecutor(options, context) {
38
48
  process.on('SIGINT', processExitListener);
39
49
  process.on('SIGHUP', processExitListener);
40
50
  try {
41
- const port = yield detectPort(options.port);
42
- if (port !== options.port) {
43
- devkit_1.logger.info(`Port ${options.port} was occupied. Using port ${port}.`);
44
- options.port = port;
45
- }
46
51
  yield startVerdaccio(options, context.root);
47
52
  }
48
53
  catch (e) {
@@ -68,19 +73,7 @@ function startVerdaccio(options, workspaceRoot) {
68
73
  env: Object.assign(Object.assign(Object.assign({}, process.env), { VERDACCIO_HANDLE_KILL_SIGNALS: 'true' }), (options.storage
69
74
  ? { VERDACCIO_STORAGE_PATH: options.storage }
70
75
  : {})),
71
- stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
72
- });
73
- childProcess.stdout.on('data', (data) => {
74
- process.stdout.write(data);
75
- });
76
- childProcess.stderr.on('data', (data) => {
77
- if (data.includes('VerdaccioWarning') ||
78
- data.includes('DeprecationWarning')) {
79
- process.stdout.write(data);
80
- }
81
- else {
82
- reject(data);
83
- }
76
+ stdio: 'inherit',
84
77
  });
85
78
  childProcess.on('error', (err) => {
86
79
  reject(err);
@@ -142,36 +135,71 @@ function setupNpm(options) {
142
135
  }
143
136
  };
144
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
+ }
145
152
  function setupYarn(options) {
146
153
  var _a, _b, _c;
154
+ let isYarnV1;
147
155
  try {
148
- (0, child_process_1.execSync)('yarn --version');
156
+ isYarnV1 = (0, semver_1.major)((0, child_process_1.execSync)('yarn --version').toString().trim()) === 1;
149
157
  }
150
- catch (e) {
158
+ catch (_d) {
159
+ // This would fail if yarn is not installed which is okay
151
160
  return () => { };
152
161
  }
153
- let yarnRegistryPath;
154
162
  try {
155
- 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
156
- (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' : ''));
157
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
+ };
158
200
  }
159
201
  catch (e) {
160
202
  throw new Error(`Failed to set yarn registry to http://localhost:${options.port}/: ${e.message}`);
161
203
  }
162
- return () => {
163
- try {
164
- if (yarnRegistryPath) {
165
- (0, child_process_1.execSync)(`yarn config set registry ${yarnRegistryPath}`);
166
- devkit_1.logger.info(`Reset yarn registry to ${yarnRegistryPath}`);
167
- }
168
- else {
169
- (0, child_process_1.execSync)(`yarn config delete registry`);
170
- }
171
- }
172
- catch (e) {
173
- throw new Error(`Failed to reset yarn registry: ${e.message}`);
174
- }
175
- };
176
204
  }
177
205
  exports.default = verdaccioExecutor;
@@ -1,14 +1,10 @@
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:
11
- url: https://registry.npmjs.org/
7
+ url: <%= npmUplinkRegistry %>
12
8
  maxage: 60m
13
9
 
14
10
  packages:
@@ -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
@@ -5,10 +5,14 @@ const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const path = require("path");
7
7
  const versions_1 = require("../../utils/versions");
8
+ const child_process_1 = require("child_process");
8
9
  function setupVerdaccio(tree, options) {
10
+ var _a, _b, _c;
9
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
12
  if (!tree.exists('.verdaccio/config.yml')) {
11
- (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), '.verdaccio', {});
13
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), '.verdaccio', {
14
+ npmUplinkRegistry: (_c = (_b = (_a = (0, child_process_1.execSync)('npm config get registry')) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : 'https://registry.npmjs.org',
15
+ });
12
16
  }
13
17
  const verdaccioTarget = {
14
18
  executor: '@nx/js:verdaccio',
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; } });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This function is used to start a local registry for testing purposes.
3
+ * @param localRegistryTarget the target to run to start the local registry e.g. workspace:local-registry
4
+ * @param storage the storage location for the local registry
5
+ * @param verbose whether to log verbose output
6
+ */
7
+ export declare function startLocalRegistry({ localRegistryTarget, storage, verbose, }: {
8
+ localRegistryTarget: string;
9
+ storage?: string;
10
+ verbose?: boolean;
11
+ }): Promise<() => void>;
12
+ export default startLocalRegistry;