@nx/js 16.8.0-beta.4 → 16.8.0-beta.6

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 (46) hide show
  1. package/babel.js +7 -8
  2. package/package.json +5 -5
  3. package/src/executors/node/lib/kill-tree.js +42 -45
  4. package/src/executors/node/node.impl.js +190 -189
  5. package/src/executors/swc/swc.impl.js +82 -70
  6. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
  7. package/src/executors/tsc/lib/batch/watch.js +42 -49
  8. package/src/executors/tsc/lib/get-task-options.js +8 -6
  9. package/src/executors/tsc/lib/get-tsconfig.js +16 -5
  10. package/src/executors/tsc/lib/normalize-options.js +9 -2
  11. package/src/executors/tsc/lib/typescript-compilation.js +21 -24
  12. package/src/executors/tsc/tsc.batch-impl.js +133 -132
  13. package/src/executors/tsc/tsc.impl.js +54 -50
  14. package/src/executors/verdaccio/verdaccio.impl.js +64 -55
  15. package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
  16. package/src/generators/init/init.js +86 -92
  17. package/src/generators/library/library.js +289 -245
  18. package/src/generators/setup-build/generator.js +119 -123
  19. package/src/generators/setup-verdaccio/generator.js +45 -50
  20. package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
  21. package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
  22. package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
  23. package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
  24. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  25. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
  26. package/src/plugins/jest/start-local-registry.js +4 -6
  27. package/src/plugins/rollup/type-definitions.js +21 -24
  28. package/src/utils/add-babel-inputs.js +1 -2
  29. package/src/utils/assets/assets.js +1 -2
  30. package/src/utils/assets/copy-assets-handler.js +48 -59
  31. package/src/utils/assets/index.js +20 -23
  32. package/src/utils/buildable-libs-utils.js +9 -13
  33. package/src/utils/find-npm-dependencies.js +9 -11
  34. package/src/utils/generate-globs.js +3 -3
  35. package/src/utils/inline.js +5 -10
  36. package/src/utils/package-json/get-npm-scope.js +2 -2
  37. package/src/utils/package-json/index.js +22 -25
  38. package/src/utils/package-json/update-package-json.js +23 -21
  39. package/src/utils/prettier.js +21 -24
  40. package/src/utils/swc/compile-swc.js +101 -106
  41. package/src/utils/typescript/compile-typescript-files.js +7 -8
  42. package/src/utils/typescript/print-diagnostics.js +13 -16
  43. package/src/utils/typescript/run-type-check.js +62 -59
  44. package/src/utils/typescript/ts-config.js +3 -5
  45. package/src/utils/typescript/tsnode-register.js +1 -1
  46. package/src/utils/watch-for-single-file-changes.js +13 -17
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compileTypeScriptFiles = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const compilation_1 = require("@nx/workspace/src/utilities/typescript/compilation");
6
5
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
6
  const TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES = 6194;
@@ -18,14 +17,14 @@ function compileTypeScriptFiles(normalizedOptions, tscOptions, postCompilationCa
18
17
  });
19
18
  let tearDown;
20
19
  return {
21
- iterator: (0, async_iterable_1.createAsyncIterable)(({ next, done }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ iterator: (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
22
21
  if (normalizedOptions.watch) {
23
- const host = (0, compilation_1.compileTypeScriptWatcher)(tscOptions, (d) => tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ const host = (0, compilation_1.compileTypeScriptWatcher)(tscOptions, async (d) => {
24
23
  if (d.code === TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES) {
25
- yield postCompilationCallback();
24
+ await postCompilationCallback();
26
25
  next(getResult(getErrorCountFromMessage(d.messageText) === 0));
27
26
  }
28
- }));
27
+ });
29
28
  tearDown = () => {
30
29
  host.close();
31
30
  done();
@@ -33,12 +32,12 @@ function compileTypeScriptFiles(normalizedOptions, tscOptions, postCompilationCa
33
32
  }
34
33
  else {
35
34
  const { success } = (0, compilation_1.compileTypeScript)(tscOptions);
36
- yield postCompilationCallback();
35
+ await postCompilationCallback();
37
36
  next(getResult(success));
38
37
  done();
39
38
  }
40
- })),
41
- close: () => tearDown === null || tearDown === void 0 ? void 0 : tearDown(),
39
+ }),
40
+ close: () => tearDown?.(),
42
41
  };
43
42
  }
44
43
  exports.compileTypeScriptFiles = compileTypeScriptFiles;
@@ -1,21 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printDiagnostics = void 0;
4
- const tslib_1 = require("tslib");
5
- function printDiagnostics(errors = [], warnings = []) {
6
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
7
- if (errors.length > 0) {
8
- errors.forEach((err) => {
9
- console.log(`${err}\n`);
10
- });
11
- console.log(`Found ${errors.length} error${errors.length > 1 ? 's' : ''}.`);
12
- }
13
- else if (warnings.length > 0) {
14
- warnings.forEach((err) => {
15
- console.log(`${err}\n`);
16
- });
17
- console.log(`Found ${warnings.length} warnings.`);
18
- }
19
- });
4
+ async function printDiagnostics(errors = [], warnings = []) {
5
+ if (errors.length > 0) {
6
+ errors.forEach((err) => {
7
+ console.log(`${err}\n`);
8
+ });
9
+ console.log(`Found ${errors.length} error${errors.length > 1 ? 's' : ''}.`);
10
+ }
11
+ else if (warnings.length > 0) {
12
+ warnings.forEach((err) => {
13
+ console.log(`${err}\n`);
14
+ });
15
+ console.log(`Found ${warnings.length} warnings.`);
16
+ }
20
17
  }
21
18
  exports.printDiagnostics = printDiagnostics;
@@ -1,74 +1,77 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFormattedDiagnostic = exports.runTypeCheck = exports.runTypeCheckWatch = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const chalk = require("chalk");
6
5
  const path = require("path");
7
6
  const code_frames_1 = require("nx/src/utils/code-frames");
8
7
  const highlight_1 = require("../code-frames/highlight");
9
8
  const ts_config_1 = require("../../utils/typescript/ts-config");
10
- function runTypeCheckWatch(options, callback) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const { ts, workspaceRoot, config, compilerOptions } = yield setupTypeScript(options);
13
- const host = ts.createWatchCompilerHost(config.fileNames, compilerOptions, ts.sys, ts.createEmitAndSemanticDiagnosticsBuilderProgram);
14
- const originalOnWatchStatusChange = host.onWatchStatusChange;
15
- host.onWatchStatusChange = (diagnostic, newLine, opts, errorCount) => {
16
- originalOnWatchStatusChange === null || originalOnWatchStatusChange === void 0 ? void 0 : originalOnWatchStatusChange(diagnostic, newLine, opts, errorCount);
17
- callback(diagnostic, getFormattedDiagnostic(ts, workspaceRoot, diagnostic), errorCount);
18
- };
19
- const watchProgram = ts.createWatchProgram(host);
20
- const program = watchProgram.getProgram().getProgram();
21
- const diagnostics = ts.getPreEmitDiagnostics(program);
22
- return {
23
- close: watchProgram.close.bind(watchProgram),
24
- preEmitErrors: diagnostics
25
- .filter((d) => d.category === ts.DiagnosticCategory.Error)
26
- .map((d) => getFormattedDiagnostic(ts, workspaceRoot, d)),
27
- preEmitWarnings: diagnostics
28
- .filter((d) => d.category === ts.DiagnosticCategory.Warning)
29
- .map((d) => getFormattedDiagnostic(ts, workspaceRoot, d)),
30
- };
31
- });
9
+ async function runTypeCheckWatch(options, callback) {
10
+ const { ts, workspaceRoot, config, compilerOptions } = await setupTypeScript(options);
11
+ const host = ts.createWatchCompilerHost(config.fileNames, compilerOptions, ts.sys, ts.createEmitAndSemanticDiagnosticsBuilderProgram);
12
+ const originalOnWatchStatusChange = host.onWatchStatusChange;
13
+ host.onWatchStatusChange = (diagnostic, newLine, opts, errorCount) => {
14
+ originalOnWatchStatusChange?.(diagnostic, newLine, opts, errorCount);
15
+ callback(diagnostic, getFormattedDiagnostic(ts, workspaceRoot, diagnostic), errorCount);
16
+ };
17
+ const watchProgram = ts.createWatchProgram(host);
18
+ const program = watchProgram.getProgram().getProgram();
19
+ const diagnostics = ts.getPreEmitDiagnostics(program);
20
+ return {
21
+ close: watchProgram.close.bind(watchProgram),
22
+ preEmitErrors: diagnostics
23
+ .filter((d) => d.category === ts.DiagnosticCategory.Error)
24
+ .map((d) => getFormattedDiagnostic(ts, workspaceRoot, d)),
25
+ preEmitWarnings: diagnostics
26
+ .filter((d) => d.category === ts.DiagnosticCategory.Warning)
27
+ .map((d) => getFormattedDiagnostic(ts, workspaceRoot, d)),
28
+ };
32
29
  }
33
30
  exports.runTypeCheckWatch = runTypeCheckWatch;
34
- function runTypeCheck(options) {
35
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
- const { ts, workspaceRoot, cacheDir, config, compilerOptions } = yield setupTypeScript(options);
37
- let program;
38
- let incremental = false;
39
- if (compilerOptions.incremental && cacheDir) {
40
- incremental = true;
41
- program = ts.createIncrementalProgram({
42
- rootNames: config.fileNames,
43
- options: Object.assign(Object.assign({}, compilerOptions), { incremental: true, tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo') }),
44
- });
45
- }
46
- else {
47
- program = ts.createProgram(config.fileNames, compilerOptions);
48
- }
49
- const result = program.emit();
50
- const allDiagnostics = ts
51
- .getPreEmitDiagnostics(program)
52
- .concat(result.diagnostics);
53
- return getTypeCheckResult(ts, allDiagnostics, workspaceRoot, config.fileNames.length, program.getSourceFiles().length, incremental);
54
- });
31
+ async function runTypeCheck(options) {
32
+ const { ts, workspaceRoot, cacheDir, config, compilerOptions } = await setupTypeScript(options);
33
+ let program;
34
+ let incremental = false;
35
+ if (compilerOptions.incremental && cacheDir) {
36
+ incremental = true;
37
+ program = ts.createIncrementalProgram({
38
+ rootNames: config.fileNames,
39
+ options: {
40
+ ...compilerOptions,
41
+ incremental: true,
42
+ tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo'),
43
+ },
44
+ });
45
+ }
46
+ else {
47
+ program = ts.createProgram(config.fileNames, compilerOptions);
48
+ }
49
+ const result = program.emit();
50
+ const allDiagnostics = ts
51
+ .getPreEmitDiagnostics(program)
52
+ .concat(result.diagnostics);
53
+ return getTypeCheckResult(ts, allDiagnostics, workspaceRoot, config.fileNames.length, program.getSourceFiles().length, incremental);
55
54
  }
56
55
  exports.runTypeCheck = runTypeCheck;
57
- function setupTypeScript(options) {
58
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
59
- const ts = yield Promise.resolve().then(() => require('typescript'));
60
- const { workspaceRoot, tsConfigPath, cacheDir, incremental, rootDir } = options;
61
- const config = (0, ts_config_1.readTsConfig)(tsConfigPath);
62
- if (config.errors.length) {
63
- const errorMessages = config.errors.map((e) => e.messageText).join('\n');
64
- throw new Error(`Invalid config file due to following: ${errorMessages}`);
65
- }
66
- const emitOptions = options.mode === 'emitDeclarationOnly'
67
- ? { emitDeclarationOnly: true, declaration: true, outDir: options.outDir }
68
- : { noEmit: true };
69
- const compilerOptions = Object.assign(Object.assign(Object.assign(Object.assign({}, config.options), { skipLibCheck: true }), emitOptions), { incremental, rootDir: rootDir || config.options.rootDir });
70
- return { ts, workspaceRoot, cacheDir, config, compilerOptions };
71
- });
56
+ async function setupTypeScript(options) {
57
+ const ts = await Promise.resolve().then(() => require('typescript'));
58
+ const { workspaceRoot, tsConfigPath, cacheDir, incremental, rootDir } = options;
59
+ const config = (0, ts_config_1.readTsConfig)(tsConfigPath);
60
+ if (config.errors.length) {
61
+ const errorMessages = config.errors.map((e) => e.messageText).join('\n');
62
+ throw new Error(`Invalid config file due to following: ${errorMessages}`);
63
+ }
64
+ const emitOptions = options.mode === 'emitDeclarationOnly'
65
+ ? { emitDeclarationOnly: true, declaration: true, outDir: options.outDir }
66
+ : { noEmit: true };
67
+ const compilerOptions = {
68
+ ...config.options,
69
+ skipLibCheck: true,
70
+ ...emitOptions,
71
+ incremental,
72
+ rootDir: rootDir || config.options.rootDir,
73
+ };
74
+ return { ts, workspaceRoot, cacheDir, config, compilerOptions };
72
75
  }
73
76
  function getTypeCheckResult(ts, allDiagnostics, workspaceRoot, inputFilesCount, totalFilesCount, incremental = false) {
74
77
  const errors = allDiagnostics
@@ -46,9 +46,8 @@ function getRootTsConfigFileName(tree) {
46
46
  exports.getRootTsConfigFileName = getRootTsConfigFileName;
47
47
  function addTsConfigPath(tree, importPath, lookupPaths) {
48
48
  (0, devkit_1.updateJson)(tree, getRootTsConfigPathInTree(tree), (json) => {
49
- var _a;
50
49
  const c = json.compilerOptions;
51
- (_a = c.paths) !== null && _a !== void 0 ? _a : (c.paths = {});
50
+ c.paths ??= {};
52
51
  if (c.paths[importPath]) {
53
52
  throw new Error(`You already have a library using the import path "${importPath}". Make sure to specify a unique one.`);
54
53
  }
@@ -58,8 +57,7 @@ function addTsConfigPath(tree, importPath, lookupPaths) {
58
57
  }
59
58
  exports.addTsConfigPath = addTsConfigPath;
60
59
  function readTsConfigPaths(tsConfig) {
61
- var _a;
62
- tsConfig !== null && tsConfig !== void 0 ? tsConfig : (tsConfig = getRootTsConfigPath());
60
+ tsConfig ??= getRootTsConfigPath();
63
61
  try {
64
62
  if (!tsModule) {
65
63
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
@@ -72,7 +70,7 @@ function readTsConfigPaths(tsConfig) {
72
70
  else {
73
71
  config = tsConfig;
74
72
  }
75
- if ((_a = config.options) === null || _a === void 0 ? void 0 : _a.paths) {
73
+ if (config.options?.paths) {
76
74
  return config.options.paths;
77
75
  }
78
76
  else {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsNodeRegister = void 0;
4
4
  function tsNodeRegister(file, tsConfig) {
5
- if (!(file === null || file === void 0 ? void 0 : file.endsWith('.ts')))
5
+ if (!file?.endsWith('.ts'))
6
6
  return;
7
7
  // Register TS compiler lazily
8
8
  require('ts-node').register({
@@ -1,26 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.watchForSingleFileChanges = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const client_1 = require("nx/src/daemon/client/client");
7
6
  const path_1 = require("path");
8
- function watchForSingleFileChanges(projectName, projectRoot, relativeFilePath, callback) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({ watchProjects: [projectName] }, (err, data) => {
11
- var _a;
12
- if (err === 'closed') {
13
- devkit_1.logger.error(`Watch error: Daemon closed the connection`);
14
- process.exit(1);
15
- }
16
- else if (err) {
17
- devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
18
- }
19
- else if (data.changedFiles.some((file) => file.path == (0, path_1.join)(projectRoot, relativeFilePath))) {
20
- callback();
21
- }
22
- });
23
- return () => unregisterFileWatcher();
7
+ async function watchForSingleFileChanges(projectName, projectRoot, relativeFilePath, callback) {
8
+ const unregisterFileWatcher = await client_1.daemonClient.registerFileWatcher({ watchProjects: [projectName] }, (err, data) => {
9
+ if (err === 'closed') {
10
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
11
+ process.exit(1);
12
+ }
13
+ else if (err) {
14
+ devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
15
+ }
16
+ else if (data.changedFiles.some((file) => file.path == (0, path_1.join)(projectRoot, relativeFilePath))) {
17
+ callback();
18
+ }
24
19
  });
20
+ return () => unregisterFileWatcher();
25
21
  }
26
22
  exports.watchForSingleFileChanges = watchForSingleFileChanges;