@nx/js 22.6.0-beta.10 → 22.6.0-beta.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "22.6.0-beta.10",
3
+ "version": "22.6.0-beta.12",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,8 +39,8 @@
39
39
  "@babel/preset-env": "^7.23.2",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nx/devkit": "22.6.0-beta.10",
43
- "@nx/workspace": "22.6.0-beta.10",
42
+ "@nx/devkit": "22.6.0-beta.12",
43
+ "@nx/workspace": "22.6.0-beta.12",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^3.1.0",
@@ -60,7 +60,7 @@
60
60
  "tslib": "^2.3.0"
61
61
  },
62
62
  "devDependencies": {
63
- "nx": "22.6.0-beta.10"
63
+ "nx": "22.6.0-beta.12"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "verdaccio": "^6.0.5"
@@ -456,28 +456,42 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
456
456
  if (excludePaths.size) {
457
457
  inputs.push(...Array.from(excludePaths).map((p) => `!${pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.project.root, p), workspaceRoot, config.project)}`));
458
458
  }
459
- if (hasExternalProjectReferences(config.originalPath, tsConfig, workspaceRoot, config.project, cache)) {
460
- // Importing modules from a referenced project will load its output declaration files (d.ts)
461
- // https://www.typescriptlang.org/docs/handbook/project-references.html#what-is-a-project-reference
462
- inputs.push({ dependentTasksOutputFiles: '**/*.d.ts' });
463
- }
464
- else {
465
- inputs.push('production' in namedInputs ? '^production' : '^default');
459
+ // tsc --build reads .d.ts and .tsbuildinfo files from dependent tasks, not
460
+ // the source files of dependencies. This correctly tracks build outputs from
461
+ // both external project references and same-project task dependencies (e.g.
462
+ // build-native producing .d.ts files that may be excluded from file watching
463
+ // via .nxignore).
464
+ inputs.push({
465
+ dependentTasksOutputFiles: '**/*.{d.ts,tsbuildinfo}',
466
+ transitive: true,
467
+ });
468
+ const externalRefConfigFiles = getExternalProjectReferenceConfigFiles(tsConfig, internalProjectReferences, workspaceRoot, config.project, cache, configFiles);
469
+ if (externalRefConfigFiles.length > 0) {
470
+ // tsc --build also reads the tsconfig files from external project
471
+ // references (and their extended configs) when processing project
472
+ // references, so we need to add them as inputs
473
+ inputs.push(...externalRefConfigFiles.map((p) => pathToInputOrOutput(p, workspaceRoot, config.project)));
466
474
  }
467
475
  // inputs.push({ externalDependencies });
468
476
  return inputs;
469
477
  }
470
- function getOutputs(config, tsConfig, internalProjectReferences, workspaceRoot, emitDeclarationOnly) {
478
+ function getOutputs(config, rootTsConfig, internalProjectReferences, workspaceRoot, emitDeclarationOnly) {
471
479
  const outputs = new Set();
472
480
  // We could have more surgical outputs based on the tsconfig options, but the
473
481
  // user could override them through the command line and that wouldn't be
474
482
  // reflected in the outputs. So, we just include everything that could be
475
483
  // produced by the tsc command.
476
- [tsConfig, ...Object.values(internalProjectReferences)].forEach((tsconfig) => {
477
- if (tsconfig.options.outFile) {
478
- const outFileName = (0, node_path_1.basename)(tsconfig.options.outFile, '.js');
479
- const outFileDir = (0, node_path_1.dirname)(tsconfig.options.outFile);
480
- outputs.add(pathToInputOrOutput(tsconfig.options.outFile, workspaceRoot, config.project));
484
+ [
485
+ { configBaseNameNoExt: config.basenameNoExt, tsConfig: rootTsConfig },
486
+ ...Object.entries(internalProjectReferences).map(([internalConfigPath, internalConfig]) => ({
487
+ configBaseNameNoExt: (0, node_path_1.basename)(internalConfigPath, '.json'),
488
+ tsConfig: internalConfig,
489
+ })),
490
+ ].forEach(({ configBaseNameNoExt, tsConfig }) => {
491
+ if (tsConfig.options.outFile) {
492
+ const outFileName = (0, node_path_1.basename)(tsConfig.options.outFile, '.js');
493
+ const outFileDir = (0, node_path_1.dirname)(tsConfig.options.outFile);
494
+ outputs.add(pathToInputOrOutput(tsConfig.options.outFile, workspaceRoot, config.project));
481
495
  // outFile is not be used with .cjs, .mjs, .jsx, so the list is simpler
482
496
  const outDir = (0, node_path_1.relative)(workspaceRoot, outFileDir);
483
497
  outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.js.map`), workspaceRoot, config.project));
@@ -488,38 +502,36 @@ function getOutputs(config, tsConfig, internalProjectReferences, workspaceRoot,
488
502
  ? pathToInputOrOutput(tsConfig.options.tsBuildInfoFile, workspaceRoot, config.project)
489
503
  : pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.tsbuildinfo`), workspaceRoot, config.project));
490
504
  }
491
- else if (tsconfig.options.outDir) {
505
+ else if (tsConfig.options.outDir) {
492
506
  if (emitDeclarationOnly) {
493
- outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsconfig.options.outDir, '**/*.d.ts'), workspaceRoot, config.project));
507
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsConfig.options.outDir, '**/*.d.ts'), workspaceRoot, config.project));
494
508
  if (tsConfig.options.declarationMap) {
495
- outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsconfig.options.outDir, '**/*.d.ts.map'), workspaceRoot, config.project));
509
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsConfig.options.outDir, '**/*.d.ts.map'), workspaceRoot, config.project));
496
510
  }
497
511
  }
498
512
  else {
499
- outputs.add(pathToInputOrOutput(tsconfig.options.outDir, workspaceRoot, config.project));
513
+ outputs.add(pathToInputOrOutput(tsConfig.options.outDir, workspaceRoot, config.project));
500
514
  }
501
- if (tsconfig.options.tsBuildInfoFile) {
515
+ if (tsConfig.options.tsBuildInfoFile) {
502
516
  if (emitDeclarationOnly ||
503
- !(0, node_path_1.normalize)(tsconfig.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(tsconfig.options.outDir)}${node_path_1.sep}`)) {
517
+ !(0, node_path_1.normalize)(tsConfig.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(tsConfig.options.outDir)}${node_path_1.sep}`)) {
504
518
  // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
505
- outputs.add(pathToInputOrOutput(tsconfig.options.tsBuildInfoFile, workspaceRoot, config.project));
519
+ outputs.add(pathToInputOrOutput(tsConfig.options.tsBuildInfoFile, workspaceRoot, config.project));
506
520
  }
507
521
  }
508
- else if (tsconfig.options.rootDir &&
509
- tsconfig.options.rootDir !== '.') {
522
+ else if (tsConfig.options.rootDir && tsConfig.options.rootDir !== '.') {
510
523
  // If rootDir is set, then the tsbuildinfo file will be outside the outDir so we need to add it.
511
- const relativeRootDir = (0, node_path_1.relative)(tsconfig.options.rootDir, (0, node_path_1.join)(workspaceRoot, config.project.root));
512
- outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsconfig.options.outDir, relativeRootDir, `*.tsbuildinfo`), workspaceRoot, config.project));
524
+ const relativeRootDir = (0, node_path_1.relative)(tsConfig.options.rootDir, (0, node_path_1.join)(workspaceRoot, config.project.root));
525
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsConfig.options.outDir, relativeRootDir, `*.tsbuildinfo`), workspaceRoot, config.project));
513
526
  }
514
527
  else if (emitDeclarationOnly) {
515
528
  // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
516
- const name = config.basenameNoExt;
517
- outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsconfig.options.outDir, `${name}.tsbuildinfo`), workspaceRoot, config.project));
529
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(tsConfig.options.outDir, `${configBaseNameNoExt}.tsbuildinfo`), workspaceRoot, config.project));
518
530
  }
519
531
  }
520
- else if (tsconfig.raw?.include?.length ||
521
- tsconfig.raw?.files?.length ||
522
- (!tsconfig.raw?.include && !tsconfig.raw?.files)) {
532
+ else if (tsConfig.raw?.include?.length ||
533
+ tsConfig.raw?.files?.length ||
534
+ (!tsConfig.raw?.include && !tsConfig.raw?.files)) {
523
535
  // tsc produce files in place when no outDir or outFile is set
524
536
  outputs.add((0, devkit_1.joinPathFragments)('{projectRoot}', '**/*.js'));
525
537
  outputs.add((0, devkit_1.joinPathFragments)('{projectRoot}', '**/*.cjs'));
@@ -534,10 +546,9 @@ function getOutputs(config, tsConfig, internalProjectReferences, workspaceRoot,
534
546
  outputs.add((0, devkit_1.joinPathFragments)('{projectRoot}', '**/*.d.cts.map'));
535
547
  outputs.add((0, devkit_1.joinPathFragments)('{projectRoot}', '**/*.d.mts.map'));
536
548
  // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
537
- const name = config.basenameNoExt;
538
549
  outputs.add(tsConfig.options.tsBuildInfoFile
539
550
  ? pathToInputOrOutput(tsConfig.options.tsBuildInfoFile, workspaceRoot, config.project)
540
- : (0, devkit_1.joinPathFragments)('{projectRoot}', `${name}.tsbuildinfo`));
551
+ : (0, devkit_1.joinPathFragments)('{projectRoot}', `${configBaseNameNoExt}.tsbuildinfo`));
541
552
  }
542
553
  });
543
554
  return Array.from(outputs);
@@ -612,33 +623,35 @@ function resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, projec
612
623
  }
613
624
  return projectReferences;
614
625
  }
615
- function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, project, cache, seen = new Set()) {
616
- if (!tsConfig.projectReferences?.length) {
617
- return false;
618
- }
619
- seen.add(tsConfigPath);
620
- for (const ref of tsConfig.projectReferences) {
621
- let refConfigPath = ref.path;
622
- if (seen.has(refConfigPath)) {
623
- continue;
624
- }
625
- if (!(0, node_fs_1.existsSync)(refConfigPath)) {
626
- continue;
627
- }
628
- if (!refConfigPath.endsWith('.json')) {
629
- refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
630
- }
631
- const refContext = getConfigContext(refConfigPath, workspaceRoot, cache);
632
- if (isExternalProjectReference(refContext, project, workspaceRoot, cache)) {
633
- return true;
634
- }
635
- const refTsConfig = retrieveTsConfigFromCache(refConfigPath, workspaceRoot, cache);
636
- const result = hasExternalProjectReferences(refConfigPath, refTsConfig, workspaceRoot, project, cache, seen);
637
- if (result) {
638
- return true;
626
+ /**
627
+ * Collects config file paths from external project references, including their
628
+ * extended config files. It checks the root tsconfig and all internal project
629
+ * references for their direct external references.
630
+ */
631
+ function getExternalProjectReferenceConfigFiles(tsConfig, internalProjectReferences, workspaceRoot, project, cache, existingConfigFiles) {
632
+ const externalRefs = {};
633
+ // Collect direct external references from the root tsconfig
634
+ resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, project, cache, externalRefs);
635
+ // Collect external references from internal project references
636
+ for (const refTsConfig of Object.values(internalProjectReferences)) {
637
+ resolveShallowExternalProjectReferences(refTsConfig, workspaceRoot, project, cache, externalRefs);
638
+ }
639
+ const result = [];
640
+ const seen = new Set();
641
+ for (const [refConfigPath, refTsConfig] of Object.entries(externalRefs)) {
642
+ if (!existingConfigFiles.has(refConfigPath) && !seen.has(refConfigPath)) {
643
+ result.push(refConfigPath);
644
+ seen.add(refConfigPath);
645
+ }
646
+ const extendedFiles = getExtendedConfigFiles(refTsConfig, workspaceRoot, cache);
647
+ for (const extFile of extendedFiles.files) {
648
+ if (!existingConfigFiles.has(extFile) && !seen.has(extFile)) {
649
+ result.push(extFile);
650
+ seen.add(extFile);
651
+ }
639
652
  }
640
653
  }
641
- return false;
654
+ return result;
642
655
  }
643
656
  function isExternalProjectReference(refConfig, project, workspaceRoot, cache) {
644
657
  const owner = cache.configOwners.get(refConfig.relativePath);