@nx/js 0.0.0-pr-29314-bfd9d0c → 0.0.0-pr-29636-b148ccc

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2025 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "0.0.0-pr-29314-bfd9d0c",
3
+ "version": "0.0.0-pr-29636-b148ccc",
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": "0.0.0-pr-29314-bfd9d0c",
43
- "@nx/workspace": "0.0.0-pr-29314-bfd9d0c",
42
+ "@nx/devkit": "0.0.0-pr-29636-b148ccc",
43
+ "@nx/workspace": "0.0.0-pr-29636-b148ccc",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^2.8.0",
@@ -29,9 +29,7 @@ function normalizeOptions(options, root, sourceRoot, projectRoot) {
29
29
  }
30
30
  }
31
31
  const outputPath = (0, path_1.join)(root, options.outputPath);
32
- if (options.skipTypeCheck == null && !isTsSolutionSetup) {
33
- options.skipTypeCheck = false;
34
- }
32
+ options.skipTypeCheck ??= !isTsSolutionSetup;
35
33
  if (options.watch == null) {
36
34
  options.watch = false;
37
35
  }
@@ -1,17 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "allowJs": false,
4
- "allowSyntheticDefaultImports": true,
5
3
  "composite": true,
6
- "declaration": true,
7
4
  "declarationMap": true,
8
5
  "emitDeclarationOnly": true,
9
- "emitDecoratorMetadata": false,
10
- "esModuleInterop": true,
11
- "experimentalDecorators": false,
12
- "forceConsistentCasingInFileNames": true,
13
6
  "importHelpers": true,
14
- "incremental": true,
15
7
  "isolatedModules": true,
16
8
  "lib": ["es2022"],
17
9
  "module": "NodeNext",
@@ -21,14 +13,8 @@
21
13
  "noImplicitOverride": true,
22
14
  "noImplicitReturns": true,
23
15
  "noUnusedLocals": true,
24
- "pretty": true,
25
- "removeComments": false,
26
- "resolveJsonModule": false,
27
- "skipDefaultLibCheck": false,
28
16
  "skipLibCheck": true,
29
- "sourceMap": false,
30
17
  "strict": true,
31
- "target": "es2022",
32
- "verbatimModuleSyntax": false
18
+ "target": "es2022"
33
19
  }
34
20
  }
@@ -64,9 +64,24 @@ async function initGeneratorInternal(tree, schema) {
64
64
  { targetName: 'tsc-typecheck' },
65
65
  ],
66
66
  build: [
67
- { targetName: 'build', configName: 'tsconfig.lib.json' },
68
- { targetName: 'tsc:build', configName: 'tsconfig.lib.json' },
69
- { targetName: 'tsc-build', configName: 'tsconfig.lib.json' },
67
+ {
68
+ targetName: 'build',
69
+ configName: 'tsconfig.lib.json',
70
+ buildDepsName: 'build-deps',
71
+ watchDepsName: 'watch-deps',
72
+ },
73
+ {
74
+ targetName: 'tsc:build',
75
+ configName: 'tsconfig.lib.json',
76
+ buildDepsName: 'tsc:build-deps',
77
+ watchDepsName: 'tsc:watch-deps',
78
+ },
79
+ {
80
+ targetName: 'tsc-build',
81
+ configName: 'tsconfig.lib.json',
82
+ buildDepsName: 'tsc-build-deps',
83
+ watchDepsName: 'tsc-watch-deps',
84
+ },
70
85
  ],
71
86
  }, schema.updatePackageScripts);
72
87
  }
@@ -1,4 +1,4 @@
1
- import { <%= propertyName %> } from './<%= fileName %>';
1
+ import { <%= propertyName %> } from './<%= fileNameImport %>';
2
2
 
3
3
  describe('<%= propertyName %>', () => {
4
4
  it('should work', () => {
@@ -11,18 +11,18 @@ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-projec
11
11
  const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
12
12
  const path_1 = require("path");
13
13
  const generator_prompts_1 = require("../../utils/generator-prompts");
14
- const package_manager_workspaces_1 = require("../../utils/package-manager-workspaces");
14
+ const update_package_json_1 = require("../../utils/package-json/update-package-json");
15
15
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
16
16
  const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
17
17
  const configuration_1 = require("../../utils/typescript/configuration");
18
18
  const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
19
+ const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
19
20
  const plugin_1 = require("../../utils/typescript/plugin");
20
21
  const ts_config_1 = require("../../utils/typescript/ts-config");
21
22
  const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
22
23
  const versions_1 = require("../../utils/versions");
23
24
  const init_1 = require("../init/init");
24
25
  const generator_1 = require("../setup-verdaccio/generator");
25
- const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
26
26
  const defaultOutputDirectory = 'dist';
27
27
  async function libraryGenerator(tree, schema) {
28
28
  return await libraryGeneratorInternal(tree, {
@@ -55,7 +55,7 @@ async function libraryGeneratorInternal(tree, schema) {
55
55
  await configurationGenerator(tree, {
56
56
  project: options.name,
57
57
  compiler: 'swc',
58
- format: ['cjs', 'esm'],
58
+ format: options.isUsingTsSolutionConfig ? ['esm'] : ['cjs', 'esm'],
59
59
  });
60
60
  }
61
61
  if (options.bundler === 'vite') {
@@ -101,6 +101,7 @@ async function libraryGeneratorInternal(tree, schema) {
101
101
  testEnvironment: options.testEnvironment,
102
102
  runtimeTsconfigFileName: 'tsconfig.lib.json',
103
103
  compiler: options.compiler === 'swc' ? 'swc' : 'babel',
104
+ addPlugin: options.addPlugin,
104
105
  });
105
106
  tasks.push(vitestTask);
106
107
  createOrEditViteConfig(tree, {
@@ -120,17 +121,21 @@ async function libraryGeneratorInternal(tree, schema) {
120
121
  // add project reference to the runtime tsconfig.lib.json file
121
122
  json.references ??= [];
122
123
  json.references.push({ path: './tsconfig.lib.json' });
124
+ if (options.isUsingTsSolutionConfig && options.bundler === 'rollup') {
125
+ json.compilerOptions.module = 'esnext';
126
+ json.compilerOptions.moduleResolution = 'bundler';
127
+ }
123
128
  return json;
124
129
  });
125
130
  }
131
+ // If we are using the new TS solution
132
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
133
+ if (options.isUsingTsSolutionConfig) {
134
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
135
+ }
126
136
  if (!options.skipFormat) {
127
137
  await (0, devkit_1.formatFiles)(tree);
128
138
  }
129
- if (!options.skipWorkspacesWarning &&
130
- options.isUsingTsSolutionConfig &&
131
- options.projectPackageManagerWorkspaceState !== 'included') {
132
- tasks.push((0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceStateWarningTask)(options.projectPackageManagerWorkspaceState, tree.root));
133
- }
134
139
  if (options.publishable) {
135
140
  tasks.push(() => {
136
141
  logNxReleaseDocsInfo();
@@ -138,7 +143,7 @@ async function libraryGeneratorInternal(tree, schema) {
138
143
  }
139
144
  // Always run install to link packages.
140
145
  if (options.isUsingTsSolutionConfig) {
141
- tasks.push(() => (0, devkit_1.installPackagesTask)(tree));
146
+ tasks.push(() => (0, devkit_1.installPackagesTask)(tree, true));
142
147
  }
143
148
  tasks.push(() => {
144
149
  (0, log_show_project_command_1.logShowProjectCommand)(options.name);
@@ -148,12 +153,7 @@ async function libraryGeneratorInternal(tree, schema) {
148
153
  async function configureProject(tree, options) {
149
154
  if (options.hasPlugin) {
150
155
  const nxJson = (0, devkit_1.readNxJson)(tree);
151
- if (options.bundler === 'none') {
152
- (0, plugin_1.ensureProjectIsExcludedFromPluginRegistrations)(nxJson, options.projectRoot);
153
- }
154
- else {
155
- (0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
156
- }
156
+ (0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
157
157
  (0, devkit_1.updateNxJson)(tree, nxJson);
158
158
  }
159
159
  const projectConfiguration = {
@@ -180,15 +180,13 @@ async function configureProject(tree, options) {
180
180
  tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
181
181
  },
182
182
  };
183
- if (options.bundler === 'esbuild') {
184
- projectConfiguration.targets.build.options.format = ['cjs'];
185
- }
186
183
  if (options.bundler === 'swc' &&
187
184
  (options.skipTypeCheck || options.isUsingTsSolutionConfig)) {
188
185
  projectConfiguration.targets.build.options.skipTypeCheck = true;
189
186
  }
190
187
  if (options.isUsingTsSolutionConfig) {
191
188
  if (options.bundler === 'esbuild') {
189
+ projectConfiguration.targets.build.options.format = ['esm'];
192
190
  projectConfiguration.targets.build.options.declarationRootDir = `${options.projectRoot}/src`;
193
191
  }
194
192
  else if (options.bundler === 'swc') {
@@ -198,6 +196,7 @@ async function configureProject(tree, options) {
198
196
  else {
199
197
  projectConfiguration.targets.build.options.assets = [];
200
198
  if (options.bundler === 'esbuild') {
199
+ projectConfiguration.targets.build.options.format = ['cjs'];
201
200
  projectConfiguration.targets.build.options.generatePackageJson = true;
202
201
  }
203
202
  if (!options.minimal) {
@@ -313,7 +312,7 @@ async function addLint(tree, options) {
313
312
  }
314
313
  else if (options.bundler === 'rollup') {
315
314
  ruleOptions.ignoredFiles ??= [];
316
- ruleOptions.ignoredFiles.push('{projectRoot}/rollup.config.{js,ts,mjs,mts}');
315
+ ruleOptions.ignoredFiles.push('{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}');
317
316
  o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
318
317
  }
319
318
  else if (options.bundler === 'esbuild') {
@@ -337,7 +336,7 @@ function createFiles(tree, options) {
337
336
  const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
338
337
  createProjectTsConfigs(tree, options);
339
338
  let fileNameImport = options.fileName;
340
- if (options.bundler === 'vite') {
339
+ if (options.bundler === 'vite' || options.isUsingTsSolutionConfig) {
341
340
  const tsConfig = (0, ts_config_1.readTsConfigFromTree)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.lib.json'));
342
341
  const ts = (0, ensure_typescript_1.ensureTypescript)();
343
342
  if (tsConfig.options.moduleResolution === ts.ModuleResolutionKind.Node16 ||
@@ -381,7 +380,9 @@ function createFiles(tree, options) {
381
380
  });
382
381
  }
383
382
  if (options.bundler === 'swc' || options.bundler === 'rollup') {
384
- (0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
383
+ (0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' && !options.isUsingTsSolutionConfig
384
+ ? 'commonjs'
385
+ : 'es6');
385
386
  }
386
387
  else if (options.includeBabelRc) {
387
388
  addBabelRc(tree, options);
@@ -410,7 +411,7 @@ function createFiles(tree, options) {
410
411
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
411
412
  json.files = ['dist', '!**/*.tsbuildinfo'];
412
413
  }
413
- return {
414
+ const updatedPackageJson = {
414
415
  ...json,
415
416
  dependencies: {
416
417
  ...json.dependencies,
@@ -418,10 +419,25 @@ function createFiles(tree, options) {
418
419
  },
419
420
  ...determineEntryFields(options),
420
421
  };
422
+ if (options.bundler === 'none') {
423
+ updatedPackageJson.type = 'module';
424
+ }
425
+ else if (options.bundler !== 'vite' && options.bundler !== 'rollup') {
426
+ return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
427
+ main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
428
+ outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
429
+ projectRoot: options.projectRoot,
430
+ rootDir: (0, path_1.join)(options.projectRoot, 'src'),
431
+ generateExportsField: true,
432
+ packageJsonPath,
433
+ format: ['esm'],
434
+ });
435
+ }
436
+ return updatedPackageJson;
421
437
  });
422
438
  }
423
439
  else {
424
- const packageJson = {
440
+ let packageJson = {
425
441
  name: options.importPath,
426
442
  version: '0.0.1',
427
443
  dependencies: determineDependencies(options),
@@ -435,6 +451,22 @@ function createFiles(tree, options) {
435
451
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
436
452
  packageJson.files = ['dist', '!**/*.tsbuildinfo'];
437
453
  }
454
+ if (options.isUsingTsSolutionConfig) {
455
+ if (options.bundler === 'none') {
456
+ packageJson.type = 'module';
457
+ }
458
+ else if (options.bundler !== 'vite' && options.bundler !== 'rollup') {
459
+ packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
460
+ main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
461
+ outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
462
+ projectRoot: options.projectRoot,
463
+ rootDir: (0, path_1.join)(options.projectRoot, 'src'),
464
+ generateExportsField: true,
465
+ packageJsonPath,
466
+ format: ['esm'],
467
+ });
468
+ }
469
+ }
438
470
  (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
439
471
  }
440
472
  if (options.config === 'npm-scripts') {
@@ -582,7 +614,6 @@ async function normalizeOptions(tree, options) {
582
614
  ? options.tags.split(',').map((s) => s.trim())
583
615
  : [];
584
616
  options.minimal ??= false;
585
- const projectPackageManagerWorkspaceState = (0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceState)(tree, projectRoot);
586
617
  // We default to generate a project.json file if the new setup is not being used
587
618
  options.useProjectJson ??= !isUsingTsSolutionConfig;
588
619
  return {
@@ -595,7 +626,6 @@ async function normalizeOptions(tree, options) {
595
626
  importPath,
596
627
  hasPlugin,
597
628
  isUsingTsSolutionConfig,
598
- projectPackageManagerWorkspaceState,
599
629
  };
600
630
  }
601
631
  function addProjectDependencies(tree, options) {
@@ -779,75 +809,87 @@ function determineDependencies(options) {
779
809
  function determineEntryFields(options) {
780
810
  switch (options.bundler) {
781
811
  case 'tsc':
782
- return {
783
- type: 'commonjs',
784
- main: options.isUsingTsSolutionConfig
785
- ? './dist/index.js'
786
- : './src/index.js',
787
- typings: options.isUsingTsSolutionConfig
788
- ? './dist/index.d.ts'
789
- : './src/index.d.ts',
790
- };
791
812
  case 'swc':
792
- return {
793
- type: 'commonjs',
794
- main: options.isUsingTsSolutionConfig
795
- ? './dist/index.js'
796
- : './src/index.js',
797
- typings: options.isUsingTsSolutionConfig
798
- ? './dist/index.d.ts'
799
- : './src/index.d.ts',
800
- };
813
+ if (options.isUsingTsSolutionConfig) {
814
+ return {
815
+ type: 'module',
816
+ main: './dist/index.js',
817
+ types: './dist/index.d.ts',
818
+ };
819
+ }
820
+ else {
821
+ return {
822
+ type: 'commonjs',
823
+ main: './src/index.js',
824
+ types: './src/index.d.ts',
825
+ };
826
+ }
801
827
  case 'rollup':
802
- return {
803
- // Since we're publishing both formats, skip the type field.
804
- // Bundlers or Node will determine the entry point to use.
805
- main: options.isUsingTsSolutionConfig
806
- ? './dist/index.cjs'
807
- : './index.cjs',
808
- module: options.isUsingTsSolutionConfig
809
- ? './dist/index.js'
810
- : './index.js',
811
- };
828
+ if (options.isUsingTsSolutionConfig) {
829
+ // the rollup configuration generator already handles this
830
+ return {};
831
+ }
832
+ else {
833
+ return {
834
+ // Since we're publishing both formats, skip the type field.
835
+ // Bundlers or Node will determine the entry point to use.
836
+ main: './index.cjs',
837
+ module: './index.js',
838
+ };
839
+ }
812
840
  case 'vite':
813
- return {
814
- type: 'module',
815
- main: options.isUsingTsSolutionConfig
816
- ? './dist/index.js'
817
- : './index.js',
818
- typings: options.isUsingTsSolutionConfig
819
- ? './dist/index.d.ts'
820
- : './index.d.ts',
821
- };
841
+ if (options.isUsingTsSolutionConfig) {
842
+ // the vite configuration generator already handle this
843
+ return {};
844
+ }
845
+ else {
846
+ return {
847
+ type: 'module',
848
+ main: './index.js',
849
+ types: './index.d.ts',
850
+ };
851
+ }
822
852
  case 'esbuild':
823
- // For libraries intended for Node, use CJS.
824
- return {
825
- type: 'commonjs',
826
- main: options.isUsingTsSolutionConfig
827
- ? './dist/index.cjs'
828
- : './index.cjs',
829
- typings: options.isUsingTsSolutionConfig
830
- ? './dist/index.d.ts'
831
- : './index.d.ts',
832
- };
833
- default: {
853
+ if (options.isUsingTsSolutionConfig) {
854
+ return {
855
+ type: 'module',
856
+ main: './dist/index.js',
857
+ types: './dist/index.d.ts',
858
+ };
859
+ }
860
+ else {
861
+ return {
862
+ type: 'commonjs',
863
+ main: './index.cjs',
864
+ types: './index.d.ts',
865
+ };
866
+ }
867
+ case 'none': {
868
+ if (options.isUsingTsSolutionConfig) {
869
+ return {
870
+ main: options.js ? './src/index.js' : './src/index.ts',
871
+ types: options.js ? './src/index.js' : './src/index.ts',
872
+ exports: {
873
+ '.': options.js
874
+ ? './src/index.js'
875
+ : {
876
+ types: './src/index.ts',
877
+ import: './src/index.ts',
878
+ default: './src/index.ts',
879
+ },
880
+ './package.json': './package.json',
881
+ },
882
+ };
883
+ }
834
884
  return {
835
885
  // Safest option is to not set a type field.
836
886
  // Allow the user to decide which module format their library is using
837
887
  type: undefined,
838
- // For non-buildable libraries, point to source so we can still use them in apps via bundlers like Vite.
839
- main: options.isUsingTsSolutionConfig
840
- ? options.js
841
- ? './src/index.js'
842
- : './src/index.ts'
843
- : undefined,
844
- types: options.isUsingTsSolutionConfig
845
- ? options.js
846
- ? './src/index.js'
847
- : './src/index.ts'
848
- : undefined,
849
888
  };
850
889
  }
890
+ default: {
891
+ return {};
892
+ }
851
893
  }
852
894
  }
853
895
  function projectsConfigMatchesProject(projectsConfig, project) {
@@ -33,7 +33,6 @@ export interface LibraryGeneratorSchema {
33
33
  simpleName?: boolean;
34
34
  addPlugin?: boolean;
35
35
  useProjectJson?: boolean;
36
- skipWorkspacesWarning?: boolean;
37
36
  useTscExecutor?: boolean;
38
37
  }
39
38
 
@@ -47,5 +46,4 @@ export interface NormalizedLibraryGeneratorOptions
47
46
  importPath?: string;
48
47
  hasPlugin: boolean;
49
48
  isUsingTsSolutionConfig: boolean;
50
- projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState;
51
49
  }
@@ -99,7 +99,7 @@ function execLockFileUpdate(command, cwd, env = {}) {
99
99
  `Verify that '${command}' succeeds when run from the workspace root.`,
100
100
  `To configure a string of arguments to be passed to this command, set the 'release.version.generatorOptions.installArgs' property in nx.json.`,
101
101
  `To ignore install lifecycle scripts, set 'release.version.generatorOptions.installIgnoreScripts' to true in nx.json.`,
102
- `To disable this step entirely, set 'release.version.skipLockFileUpdate' to true in nx.json.`,
102
+ `To disable this step entirely, set 'release.version.generatorOptions.skipLockFileUpdate' to true in nx.json.`,
103
103
  ],
104
104
  });
105
105
  throw e;
@@ -98,7 +98,7 @@ async function setupBuildGenerator(tree, options) {
98
98
  project: options.project,
99
99
  skipFormat: true,
100
100
  skipValidation: true,
101
- format: ['cjs'],
101
+ format: isTsSolutionSetup ? ['esm'] : ['cjs'],
102
102
  });
103
103
  tasks.push(task);
104
104
  break;
@@ -111,7 +111,7 @@ async function setupBuildGenerator(tree, options) {
111
111
  tsConfig: tsConfigFile,
112
112
  project: options.project,
113
113
  compiler: 'tsc',
114
- format: ['cjs', 'esm'],
114
+ format: isTsSolutionSetup ? ['esm'] : ['cjs', 'esm'],
115
115
  addPlugin,
116
116
  skipFormat: true,
117
117
  skipValidation: true,
@@ -165,7 +165,7 @@ async function setupBuildGenerator(tree, options) {
165
165
  }
166
166
  (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
167
167
  tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(tree));
168
- (0, add_swc_config_1.addSwcConfig)(tree, project.root, 'commonjs');
168
+ (0, add_swc_config_1.addSwcConfig)(tree, project.root, isTsSolutionSetup ? 'es6' : 'commonjs');
169
169
  if (isTsSolutionSetup) {
170
170
  updatePackageJsonForSwc(tree, options, project);
171
171
  }
@@ -55,10 +55,20 @@ async function syncGenerator(tree) {
55
55
  const tsSysFromTree = {
56
56
  ...ts.sys,
57
57
  fileExists(path) {
58
- return tsconfigExists(tree, tsconfigInfoCaches, path);
58
+ // Given ts.System.resolve resolve full path for tsconfig within node_modules
59
+ // We need to remove the workspace root to ensure we don't have double workspace root within the Tree
60
+ const correctPath = path.startsWith(tree.root)
61
+ ? (0, posix_1.relative)(tree.root, path)
62
+ : path;
63
+ return tsconfigExists(tree, tsconfigInfoCaches, correctPath);
59
64
  },
60
65
  readFile(path) {
61
- return readRawTsconfigContents(tree, tsconfigInfoCaches, path);
66
+ // Given ts.System.resolve resolve full path for tsconfig within node_modules
67
+ // We need to remove the workspace root to ensure we don't have double workspace root within the Tree
68
+ const correctPath = path.startsWith(tree.root)
69
+ ? (0, posix_1.relative)(tree.root, path)
70
+ : path;
71
+ return readRawTsconfigContents(tree, tsconfigInfoCaches, correctPath);
62
72
  },
63
73
  };
64
74
  // Track if any changes were made to the tsconfig files. We check the changes
@@ -189,8 +199,9 @@ function updateTsConfigReferences(tree, tsSysFromTree, tsconfigInfoCaches, tsCon
189
199
  }
190
200
  let hasChanges = false;
191
201
  for (const dep of dependencies) {
192
- // Ensure the project reference for the target is set
193
- let referencePath = dep.data.root;
202
+ // Ensure the project reference for the target is set if we can find the
203
+ // relevant tsconfig file
204
+ let referencePath;
194
205
  if (runtimeTsConfigFileName) {
195
206
  const runtimeTsConfigPath = (0, devkit_1.joinPathFragments)(dep.data.root, runtimeTsConfigFileName);
196
207
  if (tsconfigExists(tree, tsconfigInfoCaches, runtimeTsConfigPath)) {
@@ -223,6 +234,14 @@ function updateTsConfigReferences(tree, tsSysFromTree, tsconfigInfoCaches, tsCon
223
234
  continue;
224
235
  }
225
236
  }
237
+ if (!referencePath) {
238
+ if (tsconfigExists(tree, tsconfigInfoCaches, (0, devkit_1.joinPathFragments)(dep.data.root, 'tsconfig.json'))) {
239
+ referencePath = dep.data.root;
240
+ }
241
+ else {
242
+ continue;
243
+ }
244
+ }
226
245
  const relativePathToTargetRoot = (0, posix_1.relative)(projectRoot, referencePath);
227
246
  if (!newReferencesSet.has(relativePathToTargetRoot)) {
228
247
  newReferencesSet.add(relativePathToTargetRoot);
@@ -250,8 +269,8 @@ function collectProjectDependencies(tree, projectName, projectGraph, collectedDe
250
269
  collectedDependencies.set(projectName, []);
251
270
  for (const dep of projectGraph.dependencies[projectName]) {
252
271
  const targetProjectNode = projectGraph.nodes[dep.target];
253
- if (!targetProjectNode) {
254
- // It's an npm dependency
272
+ if (!targetProjectNode || dep.type === 'implicit') {
273
+ // It's an npm or an implicit dependency
255
274
  continue;
256
275
  }
257
276
  // Add the target project node to the list of dependencies for the current project
@@ -260,7 +279,7 @@ function collectProjectDependencies(tree, projectName, projectGraph, collectedDe
260
279
  .some((d) => d.name === targetProjectNode.name)) {
261
280
  collectedDependencies.get(projectName).push(targetProjectNode);
262
281
  }
263
- if (process.env.NX_DISABLE_TS_SYNC_TRANSITIVE_DEPENDENCIES === 'true') {
282
+ if (process.env.NX_ENABLE_TS_SYNC_TRANSITIVE_DEPENDENCIES !== 'true') {
264
283
  continue;
265
284
  }
266
285
  // Recursively get the dependencies of the target project
@@ -6,6 +6,8 @@ export interface TscPluginOptions {
6
6
  build?: boolean | {
7
7
  targetName?: string;
8
8
  configName?: string;
9
+ buildDepsName?: string;
10
+ watchDepsName?: string;
9
11
  };
10
12
  }
11
13
  /**
@@ -11,6 +11,7 @@ const file_hasher_1 = require("nx/src/hasher/file-hasher");
11
11
  const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
12
12
  const cache_directory_1 = require("nx/src/utils/cache-directory");
13
13
  const ts_config_1 = require("../../utils/typescript/ts-config");
14
+ const util_1 = require("./util");
14
15
  const pmc = (0, devkit_1.getPackageManagerCommand)();
15
16
  function readTargetsCache(cachePath) {
16
17
  return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
@@ -94,6 +95,10 @@ async function createNodesInternal(configFilePath, options, context, lockFileNam
94
95
  const extendedConfigFiles = getExtendedConfigFiles(fullConfigPath, tsConfig);
95
96
  const internalReferencedFiles = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
96
97
  const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
98
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
99
+ const packageJson = (0, node_fs_1.existsSync)(packageJsonPath)
100
+ ? (0, devkit_1.readJsonFile)(packageJsonPath)
101
+ : null;
97
102
  const nodeHash = (0, file_hasher_1.hashArray)([
98
103
  ...[
99
104
  fullConfigPath,
@@ -103,6 +108,7 @@ async function createNodesInternal(configFilePath, options, context, lockFileNam
103
108
  (0, node_path_1.join)(context.workspaceRoot, lockFileName),
104
109
  ].map(file_hasher_1.hashFile),
105
110
  (0, file_hasher_1.hashObject)(options),
111
+ ...(packageJson ? [(0, file_hasher_1.hashObject)(packageJson)] : []),
106
112
  ]);
107
113
  const cacheKey = `${nodeHash}_${configFilePath}`;
108
114
  targetsCache[cacheKey] ??= buildTscTargets(fullConfigPath, projectRoot, options, context);
@@ -161,7 +167,9 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
161
167
  }
162
168
  }
163
169
  // Build target
164
- if (options.build && (0, node_path_1.basename)(configFilePath) === options.build.configName) {
170
+ if (options.build &&
171
+ (0, node_path_1.basename)(configFilePath) === options.build.configName &&
172
+ isValidPackageJsonBuildConfig(tsConfig, context.workspaceRoot, projectRoot)) {
165
173
  internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
166
174
  const targetName = options.build.targetName;
167
175
  targets[targetName] = {
@@ -183,6 +191,10 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
183
191
  },
184
192
  },
185
193
  };
194
+ (0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, {
195
+ buildDepsTargetName: options.build.buildDepsName,
196
+ watchDepsTargetName: options.build.watchDepsName,
197
+ }, pmc);
186
198
  }
187
199
  return { targets };
188
200
  }
@@ -228,6 +240,9 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
228
240
  });
229
241
  const inputs = [];
230
242
  if (includePaths.size) {
243
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRoot, projectRoot, 'package.json'))) {
244
+ inputs.push('{projectRoot}/package.json');
245
+ }
231
246
  inputs.push(...Array.from(configFiles).map((p) => pathToInputOrOutput(p, workspaceRoot, projectRoot)), ...Array.from(includePaths).map((p) => pathToInputOrOutput((0, devkit_1.joinPathFragments)(projectRoot, p), workspaceRoot, projectRoot)));
232
247
  }
233
248
  else {
@@ -272,10 +287,16 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
272
287
  }
273
288
  else if (config.options.outDir) {
274
289
  outputs.add(pathToInputOrOutput(config.options.outDir, workspaceRoot, projectRoot));
275
- if (config.options.tsBuildInfoFile &&
276
- !(0, node_path_1.normalize)(config.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(config.options.outDir)}${node_path_1.sep}`)) {
277
- // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
278
- outputs.add(pathToInputOrOutput(config.options.tsBuildInfoFile, workspaceRoot, projectRoot));
290
+ if (config.options.tsBuildInfoFile) {
291
+ if (!(0, node_path_1.normalize)(config.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(config.options.outDir)}${node_path_1.sep}`)) {
292
+ // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
293
+ outputs.add(pathToInputOrOutput(config.options.tsBuildInfoFile, workspaceRoot, projectRoot));
294
+ }
295
+ }
296
+ else if (config.options.rootDir && config.options.rootDir !== '.') {
297
+ // If rootDir is set, then the tsbuildinfo file will be outside the outDir so we need to add it.
298
+ const relativeRootDir = (0, node_path_1.relative)(config.options.rootDir, (0, node_path_1.join)(workspaceRoot, projectRoot));
299
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, relativeRootDir, `*.tsbuildinfo`), workspaceRoot, projectRoot));
279
300
  }
280
301
  }
281
302
  else if (config.fileNames.length) {
@@ -301,10 +322,93 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
301
322
  });
302
323
  return Array.from(outputs);
303
324
  }
325
+ /**
326
+ * Validates the build configuration of a `package.json` file by ensuring that paths in the `exports`, `module`,
327
+ * and `main` fields reference valid output paths within the `outDir` defined in the TypeScript configuration.
328
+ * Priority is given to the `exports` field, specifically the `.` export if defined. If `exports` is not defined,
329
+ * the function falls back to validating `main` and `module` fields. If `outFile` is specified, it validates that the file
330
+ * is located within the output directory.
331
+ * If no `package.json` file exists, it assumes the configuration is valid.
332
+ *
333
+ * @param tsConfig The TypeScript configuration object.
334
+ * @param workspaceRoot The workspace root path.
335
+ * @param projectRoot The project root path.
336
+ * @returns `true` if the package has a valid build configuration; otherwise, `false`.
337
+ */
338
+ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
339
+ const packageJsonPath = (0, node_path_1.join)(workspaceRoot, projectRoot, 'package.json');
340
+ if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
341
+ // If the package.json file does not exist.
342
+ // Assume it's valid because it would be using `project.json` instead.
343
+ return true;
344
+ }
345
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
346
+ const outDir = tsConfig.options.outFile
347
+ ? (0, node_path_1.dirname)(tsConfig.options.outFile)
348
+ : tsConfig.options.outDir;
349
+ const resolvedOutDir = outDir
350
+ ? (0, node_path_1.resolve)(workspaceRoot, projectRoot, outDir)
351
+ : undefined;
352
+ const isPathSourceFile = (path) => {
353
+ if (resolvedOutDir) {
354
+ const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, projectRoot, path);
355
+ return !pathToCheck.startsWith(resolvedOutDir);
356
+ }
357
+ const ext = (0, node_path_1.extname)(path);
358
+ // Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
359
+ return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
360
+ };
361
+ // Checks if the value is a path within the `src` directory.
362
+ const containsInvalidPath = (value) => {
363
+ if (typeof value === 'string') {
364
+ return isPathSourceFile(value);
365
+ }
366
+ else if (typeof value === 'object') {
367
+ return Object.entries(value).some(([currentKey, subValue]) => {
368
+ // Skip types field
369
+ if (currentKey === 'types') {
370
+ return false;
371
+ }
372
+ if (typeof subValue === 'string') {
373
+ return isPathSourceFile(subValue);
374
+ }
375
+ return false;
376
+ });
377
+ }
378
+ return false;
379
+ };
380
+ const exports = packageJson?.exports;
381
+ // Check the `.` export if `exports` is defined.
382
+ if (exports) {
383
+ if (typeof exports === 'string') {
384
+ return !isPathSourceFile(exports);
385
+ }
386
+ if (typeof exports === 'object' && '.' in exports) {
387
+ return !containsInvalidPath(exports['.']);
388
+ }
389
+ // Check other exports if `.` is not defined or valid.
390
+ for (const key in exports) {
391
+ if (key !== '.' && containsInvalidPath(exports[key])) {
392
+ return false;
393
+ }
394
+ }
395
+ return true;
396
+ }
397
+ // If `exports` is not defined, fallback to `main` and `module` fields.
398
+ const buildPaths = ['main', 'module'];
399
+ for (const field of buildPaths) {
400
+ if (packageJson[field] && isPathSourceFile(packageJson[field])) {
401
+ return false;
402
+ }
403
+ }
404
+ return true;
405
+ }
304
406
  function pathToInputOrOutput(path, workspaceRoot, projectRoot) {
305
- const pathRelativeToProjectRoot = (0, devkit_1.normalizePath)((0, node_path_1.relative)(projectRoot, path));
407
+ const fullProjectRoot = (0, node_path_1.resolve)(workspaceRoot, projectRoot);
408
+ const fullPath = (0, node_path_1.resolve)(workspaceRoot, path);
409
+ const pathRelativeToProjectRoot = (0, devkit_1.normalizePath)((0, node_path_1.relative)(fullProjectRoot, fullPath));
306
410
  if (pathRelativeToProjectRoot.startsWith('..')) {
307
- return (0, devkit_1.joinPathFragments)('{workspaceRoot}', (0, node_path_1.relative)(workspaceRoot, path));
411
+ return (0, devkit_1.joinPathFragments)('{workspaceRoot}', (0, node_path_1.relative)(workspaceRoot, fullPath));
308
412
  }
309
413
  return (0, devkit_1.joinPathFragments)('{projectRoot}', pathRelativeToProjectRoot);
310
414
  }
@@ -462,6 +566,8 @@ function normalizePluginOptions(pluginOptions = {}) {
462
566
  let build = {
463
567
  targetName: defaultBuildTargetName,
464
568
  configName: defaultBuildConfigName,
569
+ buildDepsName: 'build-deps',
570
+ watchDepsName: 'watch-deps',
465
571
  };
466
572
  // Build target is not enabled by default
467
573
  if (!pluginOptions.build) {
@@ -471,6 +577,8 @@ function normalizePluginOptions(pluginOptions = {}) {
471
577
  build = {
472
578
  targetName: pluginOptions.build.targetName ?? defaultBuildTargetName,
473
579
  configName: pluginOptions.build.configName ?? defaultBuildConfigName,
580
+ buildDepsName: pluginOptions.build.buildDepsName ?? 'build-deps',
581
+ watchDepsName: pluginOptions.build.watchDepsName ?? 'watch-deps',
474
582
  };
475
583
  }
476
584
  return {
@@ -0,0 +1,9 @@
1
+ import { type TargetConfiguration } from '@nx/devkit';
2
+ import { type PackageManagerCommands } from 'nx/src/utils/package-manager';
3
+ /**
4
+ * Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
5
+ */
6
+ export declare function addBuildAndWatchDepsTargets(workspaceRoot: string, projectRoot: string, targets: Record<string, TargetConfiguration>, options: {
7
+ buildDepsTargetName?: string;
8
+ watchDepsTargetName?: string;
9
+ }, pmc: PackageManagerCommands): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addBuildAndWatchDepsTargets = addBuildAndWatchDepsTargets;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const node_fs_1 = require("node:fs");
6
+ const path_1 = require("path");
7
+ /**
8
+ * Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
9
+ */
10
+ function addBuildAndWatchDepsTargets(workspaceRoot, projectRoot, targets, options, pmc) {
11
+ let projectName;
12
+ const projectJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'project.json');
13
+ const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
14
+ if ((0, node_fs_1.existsSync)(projectJsonPath)) {
15
+ const projectJson = (0, devkit_1.readJsonFile)(projectJsonPath);
16
+ projectName = projectJson.name;
17
+ }
18
+ else if ((0, node_fs_1.existsSync)(packageJsonPath)) {
19
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
20
+ projectName = packageJson.nx?.name ?? packageJson.name;
21
+ }
22
+ if (!projectName)
23
+ return;
24
+ if (projectName) {
25
+ const buildDepsTargetName = options.buildDepsTargetName ?? 'build-deps';
26
+ targets[buildDepsTargetName] = {
27
+ dependsOn: ['^build'],
28
+ };
29
+ targets[options.watchDepsTargetName ?? 'watch-deps'] = {
30
+ dependsOn: [buildDepsTargetName],
31
+ command: `${pmc.exec} nx watch --projects ${projectName} --includeDependentProjects -- ${pmc.exec} nx ${buildDepsTargetName} ${projectName}`,
32
+ };
33
+ }
34
+ }
@@ -230,6 +230,9 @@ function computeCompilerOptionsPaths(tsConfig, dependencies) {
230
230
  }
231
231
  function createTmpTsConfig(tsconfigPath, workspaceRoot, projectRoot, dependencies, useWorkspaceAsBaseUrl = false) {
232
232
  const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json');
233
+ if (tsconfigPath === tmpTsConfigPath) {
234
+ return tsconfigPath;
235
+ }
233
236
  const parsedTSConfig = readTsConfigWithRemappedPaths(tsconfigPath, tmpTsConfigPath, dependencies, workspaceRoot);
234
237
  process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath));
235
238
  if (useWorkspaceAsBaseUrl) {
@@ -181,6 +181,9 @@ function getUpdatedPackageJsonContent(packageJson, options) {
181
181
  }
182
182
  else if (typeof packageJson.exports[exportEntry] === 'object') {
183
183
  packageJson.exports[exportEntry].import ??= filePath;
184
+ if (!hasCjsFormat) {
185
+ packageJson.exports[exportEntry].default ??= filePath;
186
+ }
184
187
  }
185
188
  }
186
189
  }
@@ -52,6 +52,9 @@ function getTypeCheckOptions(normalizedOptions) {
52
52
  typeCheckOptions.incremental = true;
53
53
  typeCheckOptions.cacheDir = devkit_1.cacheDir;
54
54
  }
55
+ if (normalizedOptions.isTsSolutionSetup && normalizedOptions.skipTypeCheck) {
56
+ typeCheckOptions.ignoreDiagnostics = true;
57
+ }
55
58
  return typeCheckOptions;
56
59
  }
57
60
  async function compileSwc(context, normalizedOptions, postCompilationCallback) {
@@ -59,16 +62,25 @@ async function compileSwc(context, normalizedOptions, postCompilationCallback) {
59
62
  if (normalizedOptions.clean) {
60
63
  (0, node_fs_1.rmSync)(normalizedOptions.outputPath, { recursive: true, force: true });
61
64
  }
62
- const swcCmdLog = (0, node_child_process_1.execSync)(getSwcCmd(normalizedOptions), {
63
- encoding: 'utf8',
64
- cwd: normalizedOptions.swcCliOptions.swcCwd,
65
- windowsHide: false,
66
- });
67
- devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
68
- const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
69
- if (normalizedOptions.skipTypeCheck || normalizedOptions.isTsSolutionSetup) {
65
+ try {
66
+ const swcCmdLog = (0, node_child_process_1.execSync)(getSwcCmd(normalizedOptions), {
67
+ encoding: 'utf8',
68
+ cwd: normalizedOptions.swcCliOptions.swcCwd,
69
+ windowsHide: false,
70
+ stdio: 'pipe',
71
+ });
72
+ devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
73
+ }
74
+ catch (error) {
75
+ devkit_1.logger.error('SWC compilation failed');
76
+ if (error.stderr) {
77
+ devkit_1.logger.error(error.stderr.toString());
78
+ }
79
+ return { success: false };
80
+ }
81
+ if (normalizedOptions.skipTypeCheck && !normalizedOptions.isTsSolutionSetup) {
70
82
  await postCompilationCallback();
71
- return { success: isCompileSuccess };
83
+ return { success: true };
72
84
  }
73
85
  const { errors, warnings } = await (0, run_type_check_1.runTypeCheck)(getTypeCheckOptions(normalizedOptions));
74
86
  const hasErrors = errors.length > 0;
@@ -78,7 +90,7 @@ async function compileSwc(context, normalizedOptions, postCompilationCallback) {
78
90
  }
79
91
  await postCompilationCallback();
80
92
  return {
81
- success: !hasErrors && isCompileSuccess,
93
+ success: !hasErrors,
82
94
  outfile: normalizedOptions.mainOutputPath,
83
95
  };
84
96
  }
@@ -14,6 +14,7 @@ interface BaseTypeCheckOptions {
14
14
  incremental?: boolean;
15
15
  rootDir?: string;
16
16
  projectRoot?: string;
17
+ ignoreDiagnostics?: boolean;
17
18
  }
18
19
  type Mode = NoEmitMode | EmitDeclarationOnlyMode;
19
20
  interface NoEmitMode {
@@ -18,7 +18,9 @@ async function runTypeCheckWatch(options, callback) {
18
18
  };
19
19
  const watchProgram = ts.createWatchProgram(host);
20
20
  const program = watchProgram.getProgram().getProgram();
21
- const diagnostics = ts.getPreEmitDiagnostics(program);
21
+ const diagnostics = options.ignoreDiagnostics
22
+ ? []
23
+ : ts.getPreEmitDiagnostics(program);
22
24
  return {
23
25
  close: watchProgram.close.bind(watchProgram),
24
26
  preEmitErrors: diagnostics
@@ -48,9 +50,9 @@ async function runTypeCheck(options) {
48
50
  program = ts.createProgram(config.fileNames, compilerOptions);
49
51
  }
50
52
  const result = program.emit();
51
- const allDiagnostics = ts
52
- .getPreEmitDiagnostics(program)
53
- .concat(result.diagnostics);
53
+ const allDiagnostics = options.ignoreDiagnostics
54
+ ? []
55
+ : ts.getPreEmitDiagnostics(program).concat(result.diagnostics);
54
56
  return getTypeCheckResult(ts, allDiagnostics, workspaceRoot, config.fileNames.length, program.getSourceFiles().length, incremental);
55
57
  }
56
58
  async function setupTypeScript(options) {
@@ -7,9 +7,9 @@ exports.findRuntimeTsConfigName = findRuntimeTsConfigName;
7
7
  exports.updateTsconfigFiles = updateTsconfigFiles;
8
8
  exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
9
9
  const devkit_1 = require("@nx/devkit");
10
+ const posix_1 = require("node:path/posix");
10
11
  const tree_1 = require("nx/src/generators/tree");
11
12
  const package_manager_workspaces_1 = require("../package-manager-workspaces");
12
- const posix_1 = require("node:path/posix");
13
13
  function isUsingTypeScriptPlugin(tree) {
14
14
  const nxJson = (0, devkit_1.readNxJson)(tree);
15
15
  return (nxJson?.plugins?.some((p) => typeof p === 'string'
@@ -44,7 +44,7 @@ function isWorkspaceSetupWithTsSolution(tree) {
44
44
  const baseTsconfigJson = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
45
45
  if (!baseTsconfigJson.compilerOptions ||
46
46
  !baseTsconfigJson.compilerOptions.composite ||
47
- !baseTsconfigJson.compilerOptions.declaration) {
47
+ baseTsconfigJson.compilerOptions.declaration === false) {
48
48
  return false;
49
49
  }
50
50
  const { compilerOptions, ...rest } = baseTsconfigJson;
@@ -128,16 +128,6 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
128
128
  return json;
129
129
  });
130
130
  }
131
- if (tree.exists(tsconfigE2E)) {
132
- // tsconfig.json for e2e projects need to have references array
133
- (0, devkit_1.updateJson)(tree, tsconfigE2E, (json) => {
134
- json.references ??= [];
135
- const projectPath = (0, posix_1.relative)(e2eRoot, projectRoot);
136
- if (!json.references.some((x) => x.path === projectPath))
137
- json.references.push({ path: projectPath });
138
- return json;
139
- });
140
- }
141
131
  if (tree.exists('tsconfig.json')) {
142
132
  (0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
143
133
  const projectPath = './' + projectRoot;
@@ -149,17 +139,16 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
149
139
  }
150
140
  }
151
141
  function addProjectToTsSolutionWorkspace(tree, projectDir) {
152
- // If dir is "libs/foo" then use "libs/**" so we don't need so many entries in the workspace file.
142
+ // If dir is "libs/foo" then use "libs/*" so we don't need so many entries in the workspace file.
143
+ // If dir is nested like "libs/shared/foo" then we add "libs/shared/*".
153
144
  // If the dir is just "foo" then we have to add it as is.
154
145
  const baseDir = (0, posix_1.dirname)(projectDir);
155
- const pattern = baseDir === '.' ? projectDir : `${baseDir}/**`;
146
+ const pattern = baseDir === '.' ? projectDir : `${baseDir}/*`;
156
147
  if (tree.exists('pnpm-workspace.yaml')) {
157
148
  const { load, dump } = require('@zkochan/js-yaml');
158
149
  const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
159
- const yamlData = load(workspaceFile);
160
- if (!yamlData?.packages) {
161
- yamlData.packages = [];
162
- }
150
+ const yamlData = load(workspaceFile) ?? {};
151
+ yamlData.packages ??= [];
163
152
  if (!yamlData.packages.includes(pattern)) {
164
153
  yamlData.packages.push(pattern);
165
154
  tree.write('pnpm-workspace.yaml', dump(yamlData, { indent: 2, quotingType: '"', forceQuotes: true }));