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

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,62 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const tsquery_1 = require("@phenomnomnominal/tsquery");
7
- function default_1(tree) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- let changesMade = false;
10
- const projects = (0, devkit_1.getProjects)(tree);
11
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/js:swc', (_, projectName, target, configurationName) => {
12
- const projectConfiguration = projects.get(projectName);
13
- const executorOptions = configurationName
14
- ? projectConfiguration.targets[target].configurations[configurationName]
15
- : projectConfiguration.targets[target].options;
16
- // if the project uses a custom path to swcrc file
17
- // and only if it's the default name
18
- if (executorOptions.swcrc &&
19
- executorOptions.swcrc.includes('.lib.swcrc')) {
20
- const newSwcrc = executorOptions.swcrc.replace('.lib.swcrc', '.swcrc');
21
- // rename the swcrc file first
22
- tree.rename(executorOptions.swcrc, newSwcrc);
23
- // then update the executor options
24
- executorOptions.swcrc = newSwcrc;
25
- changesMade = true;
26
- }
27
- const libSwcrcPath = (0, devkit_1.joinPathFragments)(projectConfiguration.root, '.lib.swcrc') ||
28
- (0, devkit_1.joinPathFragments)(projectConfiguration.sourceRoot, '.lib.swcrc');
29
- const isLibSwcrcExist = tree.exists(libSwcrcPath);
30
- if (isLibSwcrcExist) {
31
- tree.rename(libSwcrcPath, libSwcrcPath.replace('.lib.swcrc', '.swcrc'));
32
- changesMade = true;
33
- }
34
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
35
- });
36
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (_, projectName, target, configurationName) => {
37
- const projectConfiguration = projects.get(projectName);
38
- const executorOptions = configurationName
39
- ? projectConfiguration.targets[target].configurations[configurationName]
40
- : projectConfiguration.targets[target].options;
41
- const isJestConfigExist = executorOptions.jestConfig && tree.exists(executorOptions.jestConfig);
42
- if (isJestConfigExist) {
43
- const jestConfig = tree.read(executorOptions.jestConfig, 'utf-8');
44
- const jsonParseNodes = tsquery_1.tsquery.query(jestConfig, ':matches(CallExpression:has(Identifier[name="JSON"]):has(Identifier[name="parse"]))');
45
- if (jsonParseNodes.length) {
46
- // if we already assign false to swcrc, skip
47
- if (jestConfig.includes('.swcrc = false')) {
48
- return;
6
+ async function default_1(tree) {
7
+ let changesMade = false;
8
+ const projects = (0, devkit_1.getProjects)(tree);
9
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/js:swc', (_, projectName, target, configurationName) => {
10
+ const projectConfiguration = projects.get(projectName);
11
+ const executorOptions = configurationName
12
+ ? projectConfiguration.targets[target].configurations[configurationName]
13
+ : projectConfiguration.targets[target].options;
14
+ // if the project uses a custom path to swcrc file
15
+ // and only if it's the default name
16
+ if (executorOptions.swcrc &&
17
+ executorOptions.swcrc.includes('.lib.swcrc')) {
18
+ const newSwcrc = executorOptions.swcrc.replace('.lib.swcrc', '.swcrc');
19
+ // rename the swcrc file first
20
+ tree.rename(executorOptions.swcrc, newSwcrc);
21
+ // then update the executor options
22
+ executorOptions.swcrc = newSwcrc;
23
+ changesMade = true;
24
+ }
25
+ const libSwcrcPath = (0, devkit_1.joinPathFragments)(projectConfiguration.root, '.lib.swcrc') ||
26
+ (0, devkit_1.joinPathFragments)(projectConfiguration.sourceRoot, '.lib.swcrc');
27
+ const isLibSwcrcExist = tree.exists(libSwcrcPath);
28
+ if (isLibSwcrcExist) {
29
+ tree.rename(libSwcrcPath, libSwcrcPath.replace('.lib.swcrc', '.swcrc'));
30
+ changesMade = true;
31
+ }
32
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
33
+ });
34
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (_, projectName, target, configurationName) => {
35
+ const projectConfiguration = projects.get(projectName);
36
+ const executorOptions = configurationName
37
+ ? projectConfiguration.targets[target].configurations[configurationName]
38
+ : projectConfiguration.targets[target].options;
39
+ const isJestConfigExist = executorOptions.jestConfig && tree.exists(executorOptions.jestConfig);
40
+ if (isJestConfigExist) {
41
+ const jestConfig = tree.read(executorOptions.jestConfig, 'utf-8');
42
+ const jsonParseNodes = tsquery_1.tsquery.query(jestConfig, ':matches(CallExpression:has(Identifier[name="JSON"]):has(Identifier[name="parse"]))');
43
+ if (jsonParseNodes.length) {
44
+ // if we already assign false to swcrc, skip
45
+ if (jestConfig.includes('.swcrc = false')) {
46
+ return;
47
+ }
48
+ let updatedJestConfig = tsquery_1.tsquery.replace(jestConfig, 'CallExpression:has(Identifier[name="JSON"]):has(Identifier[name="parse"]) TemplateSpan', (templateSpan) => {
49
+ if (templateSpan.literal.text === '/.lib.swcrc') {
50
+ return templateSpan
51
+ .getFullText()
52
+ .replace('.lib.swcrc', '.swcrc');
49
53
  }
50
- let updatedJestConfig = tsquery_1.tsquery.replace(jestConfig, 'CallExpression:has(Identifier[name="JSON"]):has(Identifier[name="parse"]) TemplateSpan', (templateSpan) => {
51
- if (templateSpan.literal.text === '/.lib.swcrc') {
52
- return templateSpan
53
- .getFullText()
54
- .replace('.lib.swcrc', '.swcrc');
55
- }
56
- return '';
57
- });
58
- updatedJestConfig = tsquery_1.tsquery.replace(updatedJestConfig, ':matches(ExportAssignment, BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"]))', (node) => {
59
- return `
54
+ return '';
55
+ });
56
+ updatedJestConfig = tsquery_1.tsquery.replace(updatedJestConfig, ':matches(ExportAssignment, BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"]))', (node) => {
57
+ return `
60
58
 
61
59
  // disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
62
60
  // If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
@@ -66,15 +64,14 @@ if (swcJestConfig.swcrc === undefined) {
66
64
 
67
65
  ${node.getFullText()}
68
66
  `;
69
- });
70
- tree.write(executorOptions.jestConfig, updatedJestConfig);
71
- changesMade = true;
72
- }
67
+ });
68
+ tree.write(executorOptions.jestConfig, updatedJestConfig);
69
+ changesMade = true;
73
70
  }
74
- });
75
- if (changesMade) {
76
- yield (0, devkit_1.formatFiles)(tree);
77
71
  }
78
72
  });
73
+ if (changesMade) {
74
+ await (0, devkit_1.formatFiles)(tree);
75
+ }
79
76
  }
80
77
  exports.default = default_1;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- function replacePackage(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- yield (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/js', '@nx/js');
9
- yield (0, devkit_1.formatFiles)(tree);
10
- });
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/js', '@nx/js');
7
+ await (0, devkit_1.formatFiles)(tree);
11
8
  }
12
9
  exports.default = replacePackage;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executors = new Set([
6
5
  '@nx/js:swc',
@@ -8,32 +7,28 @@ const executors = new Set([
8
7
  '@nx/js:tsc',
9
8
  '@nrwl/js:tsc',
10
9
  ]);
11
- function default_1(tree) {
12
- var _a;
13
- var _b;
14
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- // use project graph to get the expanded target configurations
16
- const projectGraph = yield (0, devkit_1.createProjectGraphAsync)();
17
- for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
18
- if (projectData.projectType !== 'library') {
10
+ async function default_1(tree) {
11
+ // use project graph to get the expanded target configurations
12
+ const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
13
+ for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
14
+ if (projectData.projectType !== 'library') {
15
+ continue;
16
+ }
17
+ for (const [targetName, target] of Object.entries(projectData.targets || {})) {
18
+ if (!executors.has(target.executor)) {
19
19
  continue;
20
20
  }
21
- for (const [targetName, target] of Object.entries(projectData.targets || {})) {
22
- if (!executors.has(target.executor)) {
23
- continue;
24
- }
25
- if (!target.options ||
26
- target.options.updateBuildableProjectDepsInPackageJson === undefined) {
27
- // read the project configuration to write the explicit project configuration
28
- // and avoid writing the expanded target configuration
29
- const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
30
- (_a = (_b = project.targets[targetName]).options) !== null && _a !== void 0 ? _a : (_b.options = {});
31
- project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
32
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
33
- }
21
+ if (!target.options ||
22
+ target.options.updateBuildableProjectDepsInPackageJson === undefined) {
23
+ // read the project configuration to write the explicit project configuration
24
+ // and avoid writing the expanded target configuration
25
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
26
+ project.targets[targetName].options ??= {};
27
+ project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
28
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
34
29
  }
35
30
  }
36
- yield (0, devkit_1.formatFiles)(tree);
37
- });
31
+ }
32
+ await (0, devkit_1.formatFiles)(tree);
38
33
  }
39
34
  exports.default = default_1;
@@ -13,18 +13,16 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, }) {
13
13
  throw new Error(`localRegistryTarget is required`);
14
14
  }
15
15
  return new Promise((resolve, reject) => {
16
- var _a, _b;
17
16
  const childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
18
17
  ...`run ${localRegistryTarget} --location none --clear true`.split(' '),
19
18
  ...(storage ? [`--storage`, storage] : []),
20
19
  ], { stdio: 'pipe' });
21
20
  const listener = (data) => {
22
- var _a, _b, _c;
23
21
  if (verbose) {
24
22
  process.stdout.write(data);
25
23
  }
26
24
  if (data.toString().includes('http://localhost:')) {
27
- const port = parseInt((_b = (_a = data.toString().match(/localhost:(?<port>\d+)/)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.port);
25
+ const port = parseInt(data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port);
28
26
  console.log('Local registry started on port ' + port);
29
27
  const registry = `http://localhost:${port}`;
30
28
  process.env.npm_config_registry = registry;
@@ -39,11 +37,11 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, }) {
39
37
  childProcess.kill();
40
38
  (0, child_process_1.execSync)(`npm config delete //localhost:${port}/:_authToken`);
41
39
  });
42
- (_c = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stdout) === null || _c === void 0 ? void 0 : _c.off('data', listener);
40
+ childProcess?.stdout?.off('data', listener);
43
41
  }
44
42
  };
45
- (_a = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', listener);
46
- (_b = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
43
+ childProcess?.stdout?.on('data', listener);
44
+ childProcess?.stderr?.on('data', (data) => {
47
45
  process.stderr.write(data);
48
46
  });
49
47
  childProcess.on('error', (err) => {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typeDefinitions = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const path_1 = require("path");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  //NOTE: This is here so we can share between `@nx/rollup` and `@nx/vite`.
@@ -19,32 +18,30 @@ const devkit_1 = require("@nx/devkit");
19
18
  function typeDefinitions(options) {
20
19
  return {
21
20
  name: 'dts-bundle',
22
- generateBundle(_opts, bundle) {
23
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
- for (const [name, file] of Object.entries(bundle)) {
25
- if (file.type === 'asset' ||
26
- !file.isEntry ||
27
- file.facadeModuleId == null) {
28
- continue;
29
- }
30
- const hasDefaultExport = file.exports.includes('default');
31
- const entrySourceFileName = (0, path_1.relative)(options.projectRoot, file.facadeModuleId);
32
- const entrySourceDtsName = entrySourceFileName.replace(/\.[cm]?[jt]sx?$/, '');
33
- const dtsFileName = file.fileName.replace(/\.[cm]?js$/, '.d.ts');
34
- const relativeSourceDtsName = JSON.stringify('./' + entrySourceDtsName);
35
- const dtsFileSource = hasDefaultExport
36
- ? (0, devkit_1.stripIndents) `
21
+ async generateBundle(_opts, bundle) {
22
+ for (const [name, file] of Object.entries(bundle)) {
23
+ if (file.type === 'asset' ||
24
+ !file.isEntry ||
25
+ file.facadeModuleId == null) {
26
+ continue;
27
+ }
28
+ const hasDefaultExport = file.exports.includes('default');
29
+ const entrySourceFileName = (0, path_1.relative)(options.projectRoot, file.facadeModuleId);
30
+ const entrySourceDtsName = entrySourceFileName.replace(/\.[cm]?[jt]sx?$/, '');
31
+ const dtsFileName = file.fileName.replace(/\.[cm]?js$/, '.d.ts');
32
+ const relativeSourceDtsName = JSON.stringify('./' + entrySourceDtsName);
33
+ const dtsFileSource = hasDefaultExport
34
+ ? (0, devkit_1.stripIndents) `
37
35
  export * from ${relativeSourceDtsName};
38
36
  export { default } from ${relativeSourceDtsName};
39
37
  `
40
- : `export * from ${relativeSourceDtsName};\n`;
41
- this.emitFile({
42
- type: 'asset',
43
- fileName: dtsFileName,
44
- source: dtsFileSource,
45
- });
46
- }
47
- });
38
+ : `export * from ${relativeSourceDtsName};\n`;
39
+ this.emitFile({
40
+ type: 'asset',
41
+ fileName: dtsFileName,
42
+ source: dtsFileSource,
43
+ });
44
+ }
48
45
  },
49
46
  };
50
47
  }
@@ -5,7 +5,6 @@ const devkit_1 = require("@nx/devkit");
5
5
  /** @deprecated Do not use this function as the root babel.config.json file is no longer needed */
6
6
  // TODO(jack): Remove This in Nx 17 once we don't need to support Nx 15 anymore. Currently this function is used in v15 migrations.
7
7
  function addBabelInputs(tree) {
8
- var _a;
9
8
  const nxJson = (0, devkit_1.readNxJson)(tree);
10
9
  let globalBabelFile = ['babel.config.js', 'babel.config.json'].find((file) => tree.exists(file));
11
10
  if (!globalBabelFile) {
@@ -14,7 +13,7 @@ function addBabelInputs(tree) {
14
13
  });
15
14
  globalBabelFile = 'babel.config.json';
16
15
  }
17
- if ((_a = nxJson.namedInputs) === null || _a === void 0 ? void 0 : _a.sharedGlobals) {
16
+ if (nxJson.namedInputs?.sharedGlobals) {
18
17
  const sharedGlobalFileset = new Set(nxJson.namedInputs.sharedGlobals);
19
18
  sharedGlobalFileset.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', globalBabelFile));
20
19
  nxJson.namedInputs.sharedGlobals = Array.from(sharedGlobalFileset);
@@ -14,7 +14,6 @@ function assetGlobsToFiles(assets, rootDir, outDir) {
14
14
  });
15
15
  };
16
16
  assets.forEach((asset) => {
17
- var _a;
18
17
  if (typeof asset === 'string') {
19
18
  globbedFiles(asset, rootDir).forEach((globbedFile) => {
20
19
  files.push({
@@ -24,7 +23,7 @@ function assetGlobsToFiles(assets, rootDir, outDir) {
24
23
  });
25
24
  }
26
25
  else {
27
- globbedFiles(asset.glob, (0, path_1.join)(rootDir, asset.input), asset.ignore, (_a = asset.dot) !== null && _a !== void 0 ? _a : false).forEach((globbedFile) => {
26
+ globbedFiles(asset.glob, (0, path_1.join)(rootDir, asset.input), asset.ignore, asset.dot ?? false).forEach((globbedFile) => {
28
27
  files.push({
29
28
  input: (0, path_1.join)(rootDir, asset.input, globbedFile),
30
29
  output: (0, path_1.join)(outDir, asset.output, globbedFile),
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CopyAssetsHandler = exports.defaultFileEventHandler = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const minimatch = require("minimatch");
6
5
  const path = require("path");
7
6
  const fse = require("fs-extra");
@@ -29,11 +28,10 @@ const defaultFileEventHandler = (events) => {
29
28
  exports.defaultFileEventHandler = defaultFileEventHandler;
30
29
  class CopyAssetsHandler {
31
30
  constructor(opts) {
32
- var _a;
33
31
  this.rootDir = opts.rootDir;
34
32
  this.projectDir = opts.projectDir;
35
33
  this.outputDir = opts.outputDir;
36
- this.callback = (_a = opts.callback) !== null && _a !== void 0 ? _a : exports.defaultFileEventHandler;
34
+ this.callback = opts.callback ?? exports.defaultFileEventHandler;
37
35
  // TODO(jack): Should handle nested .gitignore files
38
36
  this.ignore = (0, ignore_1.default)();
39
37
  const gitignore = path.join(opts.rootDir, '.gitignore');
@@ -71,18 +69,16 @@ class CopyAssetsHandler {
71
69
  };
72
70
  });
73
71
  }
74
- processAllAssetsOnce() {
75
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- yield Promise.all(this.assetGlobs.map((ag) => tslib_1.__awaiter(this, void 0, void 0, function* () {
77
- const pattern = this.normalizeAssetPattern(ag);
78
- // fast-glob only supports Unix paths
79
- const files = yield fg(pattern.replace(/\\/g, '/'), {
80
- cwd: this.rootDir,
81
- dot: true, // enable hidden files
82
- });
83
- this.callback(this.filesToEvent(files, ag));
84
- })));
85
- });
72
+ async processAllAssetsOnce() {
73
+ await Promise.all(this.assetGlobs.map(async (ag) => {
74
+ const pattern = this.normalizeAssetPattern(ag);
75
+ // fast-glob only supports Unix paths
76
+ const files = await fg(pattern.replace(/\\/g, '/'), {
77
+ cwd: this.rootDir,
78
+ dot: true, // enable hidden files
79
+ });
80
+ this.callback(this.filesToEvent(files, ag));
81
+ }));
86
82
  }
87
83
  processAllAssetsOnceSync() {
88
84
  this.assetGlobs.forEach((ag) => {
@@ -95,57 +91,50 @@ class CopyAssetsHandler {
95
91
  this.callback(this.filesToEvent(files, ag));
96
92
  });
97
93
  }
98
- watchAndProcessOnAssetChange() {
99
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
100
- const unregisterFileWatcher = yield client_1.daemonClient.registerFileWatcher({
101
- watchProjects: 'all',
102
- includeGlobalWorkspaceFiles: true,
103
- }, (err, data) => {
104
- var _a;
105
- if (err === 'closed') {
106
- devkit_1.logger.error(`Watch error: Daemon closed the connection`);
107
- process.exit(1);
108
- }
109
- else if (err) {
110
- devkit_1.logger.error(`Watch error: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown'}`);
111
- }
112
- else {
113
- this.processWatchEvents(data.changedFiles);
114
- }
115
- });
116
- return () => unregisterFileWatcher();
94
+ async watchAndProcessOnAssetChange() {
95
+ const unregisterFileWatcher = await client_1.daemonClient.registerFileWatcher({
96
+ watchProjects: 'all',
97
+ includeGlobalWorkspaceFiles: true,
98
+ }, (err, data) => {
99
+ if (err === 'closed') {
100
+ devkit_1.logger.error(`Watch error: Daemon closed the connection`);
101
+ process.exit(1);
102
+ }
103
+ else if (err) {
104
+ devkit_1.logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
105
+ }
106
+ else {
107
+ this.processWatchEvents(data.changedFiles);
108
+ }
117
109
  });
110
+ return () => unregisterFileWatcher();
118
111
  }
119
- processWatchEvents(events) {
120
- var _a;
121
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
122
- const fileEvents = [];
123
- for (const event of events) {
124
- const pathFromRoot = path.relative(this.rootDir, event.path);
125
- for (const ag of this.assetGlobs) {
126
- if (minimatch(pathFromRoot, ag.pattern) &&
127
- !((_a = ag.ignore) === null || _a === void 0 ? void 0 : _a.some((ig) => minimatch(pathFromRoot, ig))) &&
128
- !this.ignore.ignores(pathFromRoot)) {
129
- const relPath = path.relative(ag.input, pathFromRoot);
130
- const destPath = relPath.startsWith('..') ? pathFromRoot : relPath;
131
- fileEvents.push({
132
- type: event.type,
133
- src: path.join(this.rootDir, pathFromRoot),
134
- dest: path.join(this.rootDir, ag.output, destPath),
135
- });
136
- // Match first entry and skip the rest for this file.
137
- break;
138
- }
112
+ async processWatchEvents(events) {
113
+ const fileEvents = [];
114
+ for (const event of events) {
115
+ const pathFromRoot = path.relative(this.rootDir, event.path);
116
+ for (const ag of this.assetGlobs) {
117
+ if (minimatch(pathFromRoot, ag.pattern) &&
118
+ !ag.ignore?.some((ig) => minimatch(pathFromRoot, ig)) &&
119
+ !this.ignore.ignores(pathFromRoot)) {
120
+ const relPath = path.relative(ag.input, pathFromRoot);
121
+ const destPath = relPath.startsWith('..') ? pathFromRoot : relPath;
122
+ fileEvents.push({
123
+ type: event.type,
124
+ src: path.join(this.rootDir, pathFromRoot),
125
+ dest: path.join(this.rootDir, ag.output, destPath),
126
+ });
127
+ // Match first entry and skip the rest for this file.
128
+ break;
139
129
  }
140
130
  }
141
- if (fileEvents.length > 0)
142
- this.callback(fileEvents);
143
- });
131
+ }
132
+ if (fileEvents.length > 0)
133
+ this.callback(fileEvents);
144
134
  }
145
135
  filesToEvent(files, assetGlob) {
146
136
  return files.reduce((acc, src) => {
147
- var _a;
148
- if (!((_a = assetGlob.ignore) === null || _a === void 0 ? void 0 : _a.some((ig) => minimatch(src, ig))) &&
137
+ if (!assetGlob.ignore?.some((ig) => minimatch(src, ig)) &&
149
138
  !this.ignore.ignores(src)) {
150
139
  const relPath = path.relative(assetGlob.input, src);
151
140
  const dest = relPath.startsWith('..') ? src : relPath;
@@ -1,30 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.copyAssets = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const copy_assets_handler_1 = require("./copy-assets-handler");
6
- function copyAssets(options, context) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const assetHandler = new copy_assets_handler_1.CopyAssetsHandler({
9
- projectDir: context.projectsConfigurations.projects[context.projectName].root,
10
- rootDir: context.root,
11
- outputDir: options.outputPath,
12
- assets: options.assets,
13
- callback: typeof (options === null || options === void 0 ? void 0 : options.watch) === 'object' ? options.watch.onCopy : undefined,
14
- });
15
- const result = {
16
- success: true,
17
- };
18
- if (options.watch) {
19
- result.stop = yield assetHandler.watchAndProcessOnAssetChange();
20
- }
21
- try {
22
- yield assetHandler.processAllAssetsOnce();
23
- }
24
- catch (_a) {
25
- result.success = false;
26
- }
27
- return result;
5
+ async function copyAssets(options, context) {
6
+ const assetHandler = new copy_assets_handler_1.CopyAssetsHandler({
7
+ projectDir: context.projectsConfigurations.projects[context.projectName].root,
8
+ rootDir: context.root,
9
+ outputDir: options.outputPath,
10
+ assets: options.assets,
11
+ callback: typeof options?.watch === 'object' ? options.watch.onCopy : undefined,
28
12
  });
13
+ const result = {
14
+ success: true,
15
+ };
16
+ if (options.watch) {
17
+ result.stop = await assetHandler.watchAndProcessOnAssetChange();
18
+ }
19
+ try {
20
+ await assetHandler.processAllAssetsOnce();
21
+ }
22
+ catch {
23
+ result.success = false;
24
+ }
25
+ return result;
29
26
  }
30
27
  exports.copyAssets = copyAssets;
@@ -115,7 +115,6 @@ function readTsConfigWithRemappedPaths(tsConfig, generatedTsConfigPath, dependen
115
115
  return generatedTsConfig;
116
116
  }
117
117
  function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, projectName, targetName, configurationName, shallow) {
118
- var _a;
119
118
  const target = projectGraph.nodes[projectName];
120
119
  const nonBuildableDependencies = [];
121
120
  const topLevelDependencies = [];
@@ -125,8 +124,8 @@ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, proje
125
124
  for (const [taskName, { isTopLevel }] of dependentTasks) {
126
125
  let project = null;
127
126
  const depTask = taskGraph.tasks[taskName];
128
- const depProjectNode = (_a = projectGraph.nodes) === null || _a === void 0 ? void 0 : _a[depTask.target.project];
129
- if ((depProjectNode === null || depProjectNode === void 0 ? void 0 : depProjectNode.type) !== 'lib') {
127
+ const depProjectNode = projectGraph.nodes?.[depTask.target.project];
128
+ if (depProjectNode?.type !== 'lib') {
130
129
  return null;
131
130
  }
132
131
  let outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)(depTask, depProjectNode);
@@ -165,9 +164,9 @@ exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
165
164
  function collectNpmDependencies(projectName, projectGraph, dependentTasks, collectedPackages = new Set(), isTopLevel = true) {
166
165
  const dependencies = projectGraph.dependencies[projectName]
167
166
  .map((dep) => {
168
- var _a, _b, _c;
169
- const projectNode = (_b = (_a = projectGraph.nodes) === null || _a === void 0 ? void 0 : _a[dep.target]) !== null && _b !== void 0 ? _b : (_c = projectGraph.externalNodes) === null || _c === void 0 ? void 0 : _c[dep.target];
170
- if ((projectNode === null || projectNode === void 0 ? void 0 : projectNode.type) !== 'npm' ||
167
+ const projectNode = projectGraph.nodes?.[dep.target] ??
168
+ projectGraph.externalNodes?.[dep.target];
169
+ if (projectNode?.type !== 'npm' ||
171
170
  collectedPackages.has(projectNode.data.packageName)) {
172
171
  return null;
173
172
  }
@@ -180,7 +179,7 @@ function collectNpmDependencies(projectName, projectGraph, dependentTasks, colle
180
179
  return { project, isTopLevel };
181
180
  })
182
181
  .filter((x) => !!x);
183
- if (dependentTasks === null || dependentTasks === void 0 ? void 0 : dependentTasks.size) {
182
+ if (dependentTasks?.size) {
184
183
  for (const [, { project: projectName }] of dependentTasks) {
185
184
  dependencies.push(...collectNpmDependencies(projectName, projectGraph, undefined, collectedPackages, false));
186
185
  }
@@ -188,8 +187,7 @@ function collectNpmDependencies(projectName, projectGraph, dependentTasks, colle
188
187
  return dependencies;
189
188
  }
190
189
  function collectDependentTasks(project, task, taskGraph, projectGraph, shallow, areTopLevelDeps = true, dependentTasks = new Map()) {
191
- var _a;
192
- for (const depTask of (_a = taskGraph.dependencies[task]) !== null && _a !== void 0 ? _a : []) {
190
+ for (const depTask of taskGraph.dependencies[task] ?? []) {
193
191
  if (dependentTasks.has(depTask)) {
194
192
  if (!dependentTasks.get(depTask).isTopLevel && areTopLevelDeps) {
195
193
  dependentTasks.get(depTask).isTopLevel = true;
@@ -275,7 +273,6 @@ function updatePaths(dependencies, paths) {
275
273
  const pathsKeys = Object.keys(paths);
276
274
  // For each registered dependency
277
275
  dependencies.forEach((dep) => {
278
- var _a;
279
276
  // If there are outputs
280
277
  if (dep.outputs && dep.outputs.length > 0) {
281
278
  // Directly map the dependency name to the output paths (dist/packages/..., etc.)
@@ -290,7 +287,7 @@ function updatePaths(dependencies, paths) {
290
287
  // Bind secondary endpoints for ng-packagr projects
291
288
  let mappedPaths = dep.outputs.map((output) => `${output}/${nestedPart}`);
292
289
  // Get the dependency's package name
293
- const { root } = (((_a = dep.node) === null || _a === void 0 ? void 0 : _a.data) || {});
290
+ const { root } = (dep.node?.data || {});
294
291
  if (root) {
295
292
  // Update nested mappings to point to the dependency's output paths
296
293
  mappedPaths = mappedPaths.concat(paths[path].flatMap((path) => dep.outputs.map((output) => path.replace(root, output))));
@@ -330,7 +327,6 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
330
327
  packageJson.peerDependencies = packageJson.peerDependencies || {};
331
328
  let updatePackageJson = false;
332
329
  dependencies.forEach((entry) => {
333
- var _a;
334
330
  const packageName = (0, operators_1.isNpmProject)(entry.node)
335
331
  ? entry.node.data.packageName
336
332
  : entry.name;
@@ -354,7 +350,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
354
350
  }
355
351
  else if ((0, operators_1.isNpmProject)(entry.node)) {
356
352
  // If an npm dep is part of the workspace devDependencies, do not include it the library
357
- if (!!((_a = workspacePackageJson.devDependencies) === null || _a === void 0 ? void 0 : _a[entry.node.data.packageName])) {
353
+ if (!!workspacePackageJson.devDependencies?.[entry.node.data.packageName]) {
358
354
  return;
359
355
  }
360
356
  depVersion = entry.node.data.version;