@nx/js 20.4.0-beta.0 → 20.4.0-beta.2

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/migrations.json CHANGED
@@ -124,6 +124,19 @@
124
124
  "alwaysAddToPackageJson": false
125
125
  }
126
126
  }
127
+ },
128
+ "20.4.0": {
129
+ "version": "20.4.0-beta.1",
130
+ "x-prompt": "Do you want to update to TypeScript v5.7?",
131
+ "requires": {
132
+ "typescript": ">=5.6.0 <5.7.0"
133
+ },
134
+ "packages": {
135
+ "typescript": {
136
+ "version": "~5.7.2",
137
+ "alwaysAddToPackageJson": false
138
+ }
139
+ }
127
140
  }
128
141
  }
129
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "20.4.0-beta.0",
3
+ "version": "20.4.0-beta.2",
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": "20.4.0-beta.0",
43
- "@nx/workspace": "20.4.0-beta.0",
42
+ "@nx/devkit": "20.4.0-beta.2",
43
+ "@nx/workspace": "20.4.0-beta.2",
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",
@@ -5,9 +5,11 @@
5
5
  "emitDeclarationOnly": true,
6
6
  "importHelpers": true,
7
7
  "isolatedModules": true,
8
- "lib": ["es2022"],
9
- "module": "NodeNext",
10
- "moduleResolution": "NodeNext",
8
+ "lib": ["es2022"],<% if (platform === 'node') { %>
9
+ "module": "nodenext",
10
+ "moduleResolution": "nodenext",<% } else { %>
11
+ "module": "esnext",
12
+ "moduleResolution": "bundler",<% } %>
11
13
  "noEmitOnError": true,
12
14
  "noFallthroughCasesInSwitch": true,
13
15
  "noImplicitOverride": true,
@@ -87,7 +87,9 @@ async function initGeneratorInternal(tree, schema) {
87
87
  }
88
88
  if (schema.addTsConfigBase && !(0, ts_config_1.getRootTsConfigFileName)(tree)) {
89
89
  if (schema.addTsPlugin) {
90
+ const platform = schema.platform ?? 'node';
90
91
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/ts-solution'), '.', {
92
+ platform,
91
93
  tmpl: '',
92
94
  });
93
95
  }
@@ -9,4 +9,5 @@ export interface InitSchema {
9
9
  addPlugin?: boolean;
10
10
  updatePackageScripts?: boolean;
11
11
  addTsPlugin?: boolean;
12
+ platform?: 'web' | 'node';
12
13
  }
@@ -5,7 +5,7 @@
5
5
  "rootDir": "src",
6
6
  "outDir": "dist",
7
7
  "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
8
- "emitDeclarationOnly": false,<% if (compilerOptions.length) { %>
8
+ "emitDeclarationOnly": <%= emitDeclarationOnly %>,<% if (compilerOptions.length) { %>
9
9
  <%- compilerOptions %>,<% } %>
10
10
  "types": ["node"]
11
11
  },
@@ -23,6 +23,8 @@ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
23
23
  const versions_1 = require("../../utils/versions");
24
24
  const init_1 = require("../init/init");
25
25
  const generator_1 = require("../setup-verdaccio/generator");
26
+ const sort_fields_1 = require("../../utils/package-json/sort-fields");
27
+ const get_import_path_1 = require("../../utils/get-import-path");
26
28
  const defaultOutputDirectory = 'dist';
27
29
  async function libraryGenerator(tree, schema) {
28
30
  return await libraryGeneratorInternal(tree, {
@@ -42,6 +44,11 @@ async function libraryGeneratorInternal(tree, schema) {
42
44
  formatter: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'none' : 'prettier',
43
45
  }));
44
46
  const options = await normalizeOptions(tree, schema);
47
+ // If we are using the new TS solution
48
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
49
+ if (options.isUsingTsSolutionConfig) {
50
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
51
+ }
45
52
  createFiles(tree, options);
46
53
  await configureProject(tree, options);
47
54
  if (!options.skipPackageJson) {
@@ -85,7 +92,8 @@ async function libraryGeneratorInternal(tree, schema) {
85
92
  if (options.unitTestRunner === 'jest') {
86
93
  const jestCallback = await addJest(tree, options);
87
94
  tasks.push(jestCallback);
88
- if (options.bundler === 'swc' || options.bundler === 'rollup') {
95
+ if (!options.isUsingTsSolutionConfig &&
96
+ (options.bundler === 'swc' || options.bundler === 'rollup')) {
89
97
  replaceJestConfig(tree, options);
90
98
  }
91
99
  }
@@ -121,18 +129,23 @@ async function libraryGeneratorInternal(tree, schema) {
121
129
  // add project reference to the runtime tsconfig.lib.json file
122
130
  json.references ??= [];
123
131
  json.references.push({ path: './tsconfig.lib.json' });
124
- if (options.isUsingTsSolutionConfig && options.bundler === 'rollup') {
125
- json.compilerOptions.module = 'esnext';
126
- json.compilerOptions.moduleResolution = 'bundler';
132
+ const compilerOptions = getCompilerOptions(options);
133
+ // respect the module and moduleResolution set by the test runner generator
134
+ if (json.compilerOptions.module) {
135
+ compilerOptions.module = json.compilerOptions.module;
136
+ }
137
+ if (json.compilerOptions.moduleResolution) {
138
+ compilerOptions.moduleResolution =
139
+ json.compilerOptions.moduleResolution;
127
140
  }
141
+ // filter out options already set with the same value in root tsconfig file that we're going to extend from
142
+ json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, { ...json.compilerOptions, ...compilerOptions },
143
+ // must have been created by now
144
+ (0, ts_config_1.getRootTsConfigFileName)(tree));
128
145
  return json;
129
146
  });
130
147
  }
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
- }
148
+ (0, sort_fields_1.sortPackageJsonFields)(tree, options.projectRoot);
136
149
  if (!options.skipFormat) {
137
150
  await (0, devkit_1.formatFiles)(tree);
138
151
  }
@@ -232,8 +245,19 @@ async function configureProject(tree, options) {
232
245
  if (!projectConfiguration.tags?.length) {
233
246
  delete projectConfiguration.tags;
234
247
  }
248
+ // We want a minimal setup, so unless targets and tags are set, just skip the `nx` property in `package.json`.
249
+ if (options.isUsingTsSolutionConfig) {
250
+ delete projectConfiguration.projectType;
251
+ // SWC executor has logic around sourceRoot and `--strip-leading-paths`. If it is not set then dist will contain the `src` folder rather than being flat.
252
+ // TODO(leo): Look at how we can remove the dependency on sourceRoot for SWC.
253
+ if (options.bundler !== 'swc') {
254
+ delete projectConfiguration.sourceRoot;
255
+ }
256
+ }
235
257
  // empty targets are cleaned up automatically by `updateProjectConfiguration`
236
- (0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfiguration);
258
+ (0, devkit_1.updateProjectConfiguration)(tree, options.isUsingTsSolutionConfig
259
+ ? options.importPath ?? options.name
260
+ : options.name, projectConfiguration);
237
261
  }
238
262
  else if (options.config === 'workspace' || options.config === 'project') {
239
263
  (0, devkit_1.addProjectConfiguration)(tree, options.name, projectConfiguration);
@@ -305,19 +329,21 @@ async function addLint(tree, options) {
305
329
  ruleSeverity = value;
306
330
  ruleOptions = {};
307
331
  }
308
- if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
309
- ruleOptions.ignoredFiles ??= [];
310
- ruleOptions.ignoredFiles.push('{projectRoot}/vite.config.{js,ts,mjs,mts}');
311
- o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
332
+ const ignoredFiles = new Set(ruleOptions.ignoredFiles ?? []);
333
+ if (options.bundler === 'vite') {
334
+ ignoredFiles.add('{projectRoot}/vite.config.{js,ts,mjs,mts}');
312
335
  }
313
336
  else if (options.bundler === 'rollup') {
314
- ruleOptions.ignoredFiles ??= [];
315
- ruleOptions.ignoredFiles.push('{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}');
316
- o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
337
+ ignoredFiles.add('{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}');
317
338
  }
318
339
  else if (options.bundler === 'esbuild') {
319
- ruleOptions.ignoredFiles ??= [];
320
- ruleOptions.ignoredFiles.push('{projectRoot}/esbuild.config.{js,ts,mjs,mts}');
340
+ ignoredFiles.add('{projectRoot}/esbuild.config.{js,ts,mjs,mts}');
341
+ }
342
+ if (options.unitTestRunner === 'vitest') {
343
+ ignoredFiles.add('{projectRoot}/vite.config.{js,ts,mjs,mts}');
344
+ }
345
+ if (ignoredFiles.size) {
346
+ ruleOptions.ignoredFiles = Array.from(ignoredFiles);
321
347
  o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
322
348
  }
323
349
  return o;
@@ -419,10 +445,8 @@ function createFiles(tree, options) {
419
445
  },
420
446
  ...determineEntryFields(options),
421
447
  };
422
- if (options.bundler === 'none') {
423
- updatedPackageJson.type = 'module';
424
- }
425
- else if (options.bundler !== 'vite' && options.bundler !== 'rollup') {
448
+ if (options.isUsingTsSolutionConfig &&
449
+ !['none', 'rollup', 'vite'].includes(options.bundler)) {
426
450
  return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
427
451
  main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
428
452
  outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
@@ -451,21 +475,17 @@ function createFiles(tree, options) {
451
475
  // https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
452
476
  packageJson.files = ['dist', '!**/*.tsbuildinfo'];
453
477
  }
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
- }
478
+ if (options.isUsingTsSolutionConfig &&
479
+ !['none', 'rollup', 'vite'].includes(options.bundler)) {
480
+ packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
481
+ main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
482
+ outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
483
+ projectRoot: options.projectRoot,
484
+ rootDir: (0, path_1.join)(options.projectRoot, 'src'),
485
+ generateExportsField: true,
486
+ packageJsonPath,
487
+ format: ['esm'],
488
+ });
469
489
  }
470
490
  (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
471
491
  }
@@ -478,6 +498,12 @@ function createFiles(tree, options) {
478
498
  return json;
479
499
  });
480
500
  }
501
+ else if (!options.isUsingTsSolutionConfig &&
502
+ options.useProjectJson &&
503
+ (!options.bundler || options.bundler === 'none') &&
504
+ !(options.projectRoot === '.')) {
505
+ tree.delete(packageJsonPath);
506
+ }
481
507
  if (options.minimal && !(options.projectRoot === '.')) {
482
508
  tree.delete((0, path_1.join)(options.projectRoot, 'README.md'));
483
509
  }
@@ -490,12 +516,12 @@ async function addJest(tree, options) {
490
516
  setupFile: 'none',
491
517
  supportTsx: false,
492
518
  skipSerializers: true,
493
- testEnvironment: options.testEnvironment,
519
+ testEnvironment: options.testEnvironment ?? 'node',
494
520
  skipFormat: true,
495
- compiler: options.bundler === 'swc' || options.bundler === 'tsc'
496
- ? options.bundler
497
- : options.bundler === 'rollup'
498
- ? 'swc'
521
+ compiler: options.shouldUseSwcJest
522
+ ? 'swc'
523
+ : options.bundler === 'tsc'
524
+ ? 'tsc'
499
525
  : undefined,
500
526
  runtimeTsconfigFileName: 'tsconfig.lib.json',
501
527
  });
@@ -616,16 +642,22 @@ async function normalizeOptions(tree, options) {
616
642
  options.minimal ??= false;
617
643
  // We default to generate a project.json file if the new setup is not being used
618
644
  options.useProjectJson ??= !isUsingTsSolutionConfig;
645
+ const shouldUseSwcJest = options.bundler === 'swc' ||
646
+ options.bundler === 'rollup' ||
647
+ isUsingTsSolutionConfig;
619
648
  return {
620
649
  ...options,
621
650
  fileName,
622
- name: projectName,
651
+ name: isUsingTsSolutionConfig
652
+ ? (0, get_import_path_1.getImportPath)(tree, projectName)
653
+ : projectName,
623
654
  projectNames,
624
655
  projectRoot,
625
656
  parsedTags,
626
657
  importPath,
627
658
  hasPlugin,
628
659
  isUsingTsSolutionConfig,
660
+ shouldUseSwcJest,
629
661
  };
630
662
  }
631
663
  function addProjectDependencies(tree, options) {
@@ -690,33 +722,8 @@ function getOutputPath(options) {
690
722
  }
691
723
  function createProjectTsConfigs(tree, options) {
692
724
  const rootOffset = (0, devkit_1.offsetFromRoot)(options.projectRoot);
693
- let compilerOptionOverrides = {
694
- module: options.isUsingTsSolutionConfig
695
- ? options.bundler === 'rollup'
696
- ? 'esnext'
697
- : 'nodenext'
698
- : 'commonjs',
699
- ...(options.isUsingTsSolutionConfig
700
- ? options.bundler === 'rollup'
701
- ? { moduleResolution: 'bundler' }
702
- : { moduleResolution: 'nodenext' }
703
- : {}),
704
- ...(options.js ? { allowJs: true } : {}),
705
- ...(options.strict
706
- ? {
707
- forceConsistentCasingInFileNames: true,
708
- strict: true,
709
- importHelpers: true,
710
- noImplicitOverride: true,
711
- noImplicitReturns: true,
712
- noFallthroughCasesInSwitch: true,
713
- ...(!options.isUsingTsSolutionConfig
714
- ? { noPropertyAccessFromIndexSignature: true }
715
- : {}),
716
- }
717
- : {}),
718
- };
719
- if (!options.rootProject || options.isUsingTsSolutionConfig) {
725
+ let compilerOptionOverrides = getCompilerOptions(options);
726
+ if (options.isUsingTsSolutionConfig) {
720
727
  // filter out options already set with the same value in root tsconfig file that we're going to extend from
721
728
  compilerOptionOverrides = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, compilerOptionOverrides,
722
729
  // must have been created by now
@@ -734,6 +741,7 @@ function createProjectTsConfigs(tree, options) {
734
741
  outDir: options.bundler === 'tsc'
735
742
  ? 'dist'
736
743
  : `out-tsc/${options.projectRoot.split('/').pop()}`,
744
+ emitDeclarationOnly: options.bundler === 'tsc' ? false : true,
737
745
  });
738
746
  // tsconfig.json
739
747
  if (options.isUsingTsSolutionConfig) {
@@ -788,6 +796,34 @@ function createProjectTsConfigs(tree, options) {
788
796
  };
789
797
  (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
790
798
  }
799
+ function getCompilerOptions(options) {
800
+ return {
801
+ module: options.isUsingTsSolutionConfig
802
+ ? options.bundler === 'rollup'
803
+ ? 'esnext'
804
+ : 'nodenext'
805
+ : 'commonjs',
806
+ ...(options.isUsingTsSolutionConfig
807
+ ? {
808
+ moduleResolution: options.bundler === 'rollup' ? 'bundler' : 'nodenext',
809
+ }
810
+ : {}),
811
+ ...(options.js ? { allowJs: true } : {}),
812
+ ...(options.strict
813
+ ? {
814
+ forceConsistentCasingInFileNames: true,
815
+ strict: true,
816
+ importHelpers: true,
817
+ noImplicitOverride: true,
818
+ noImplicitReturns: true,
819
+ noFallthroughCasesInSwitch: true,
820
+ ...(!options.isUsingTsSolutionConfig
821
+ ? { noPropertyAccessFromIndexSignature: true }
822
+ : {}),
823
+ }
824
+ : {}),
825
+ };
826
+ }
791
827
  function determineDependencies(options) {
792
828
  switch (options.bundler) {
793
829
  case 'tsc':
@@ -867,6 +903,7 @@ function determineEntryFields(options) {
867
903
  case 'none': {
868
904
  if (options.isUsingTsSolutionConfig) {
869
905
  return {
906
+ type: 'module',
870
907
  main: options.js ? './src/index.js' : './src/index.ts',
871
908
  types: options.js ? './src/index.js' : './src/index.ts',
872
909
  exports: {
@@ -46,4 +46,5 @@ export interface NormalizedLibraryGeneratorOptions
46
46
  importPath?: string;
47
47
  hasPlugin: boolean;
48
48
  isUsingTsSolutionConfig: boolean;
49
+ shouldUseSwcJest: boolean;
49
50
  }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function sortPackageJsonFields(tree: Tree, projectRoot: string): void;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortPackageJsonFields = sortPackageJsonFields;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function sortPackageJsonFields(tree, projectRoot) {
6
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
7
+ if (!tree.exists(packageJsonPath))
8
+ return;
9
+ (0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
10
+ // Note that these are fields that our generators may use, so it's not exhaustive.
11
+ const orderedTopFields = new Set([
12
+ 'name',
13
+ 'version',
14
+ 'private',
15
+ 'description',
16
+ 'type',
17
+ 'main',
18
+ 'module',
19
+ 'types',
20
+ 'exports',
21
+ ]);
22
+ const orderedBottomFields = new Set([
23
+ 'dependencies',
24
+ 'devDependencies',
25
+ 'peerDependencies',
26
+ 'optionalDependencies',
27
+ ]);
28
+ const otherFields = new Set(Object.keys(json).filter((k) => !orderedTopFields.has(k) && !orderedBottomFields.has(k)));
29
+ const allFields = [
30
+ ...orderedTopFields,
31
+ ...otherFields,
32
+ ...orderedBottomFields,
33
+ ];
34
+ const sortedJson = {};
35
+ for (const k of allFields) {
36
+ sortedJson[k] = json[k];
37
+ }
38
+ return sortedJson;
39
+ });
40
+ }
@@ -1,3 +1,4 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare const defaultExclude: string[];
3
- export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6'): void;
3
+ export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
4
+ export declare function addSwcTestConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultExclude = void 0;
4
4
  exports.addSwcConfig = addSwcConfig;
5
+ exports.addSwcTestConfig = addSwcTestConfig;
5
6
  const path_1 = require("path");
6
7
  exports.defaultExclude = [
7
8
  'jest.config.ts',
@@ -11,17 +12,25 @@ exports.defaultExclude = [
11
12
  './**/jest-setup.ts$',
12
13
  '.*.js$',
13
14
  ];
14
- const swcOptionsString = (type = 'commonjs') => `{
15
+ const swcOptionsString = (type = 'commonjs', exclude, supportTsx) => `{
15
16
  "jsc": {
16
17
  "target": "es2017",
17
18
  "parser": {
18
19
  "syntax": "typescript",
19
20
  "decorators": true,
20
- "dynamicImport": true
21
+ "dynamicImport": true${supportTsx
22
+ ? `,
23
+ "tsx": true`
24
+ : ''}
21
25
  },
22
26
  "transform": {
23
27
  "decoratorMetadata": true,
24
- "legacyDecorator": true
28
+ "legacyDecorator": true${supportTsx
29
+ ? `,
30
+ "react": {
31
+ "runtime": "automatic"
32
+ }`
33
+ : ''}
25
34
  },
26
35
  "keepClassNames": true,
27
36
  "externalHelpers": true,
@@ -31,11 +40,18 @@ const swcOptionsString = (type = 'commonjs') => `{
31
40
  "type": "${type}"
32
41
  },
33
42
  "sourceMaps": true,
34
- "exclude": ${JSON.stringify(exports.defaultExclude)}
35
- }`;
36
- function addSwcConfig(tree, projectDir, type = 'commonjs') {
43
+ "exclude": ${JSON.stringify(exclude)}
44
+ }
45
+ `;
46
+ function addSwcConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
37
47
  const swcrcPath = (0, path_1.join)(projectDir, '.swcrc');
38
48
  if (tree.exists(swcrcPath))
39
49
  return;
40
- tree.write(swcrcPath, swcOptionsString(type));
50
+ tree.write(swcrcPath, swcOptionsString(type, exports.defaultExclude, supportTsx));
51
+ }
52
+ function addSwcTestConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
53
+ const swcrcPath = (0, path_1.join)(projectDir, '.spec.swcrc');
54
+ if (tree.exists(swcrcPath))
55
+ return;
56
+ tree.write(swcrcPath, swcOptionsString(type, [], supportTsx));
41
57
  }
@@ -5,3 +5,4 @@ export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: st
5
5
  export declare function findRuntimeTsConfigName(tree: Tree, projectRoot: string): string | null;
6
6
  export declare function updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
7
7
  export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): void;
8
+ export declare function getProjectType(tree: Tree, projectRoot: string, projectType?: 'library' | 'application'): 'library' | 'application';
@@ -6,10 +6,12 @@ exports.assertNotUsingTsSolutionSetup = assertNotUsingTsSolutionSetup;
6
6
  exports.findRuntimeTsConfigName = findRuntimeTsConfigName;
7
7
  exports.updateTsconfigFiles = updateTsconfigFiles;
8
8
  exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
9
+ exports.getProjectType = getProjectType;
9
10
  const devkit_1 = require("@nx/devkit");
10
11
  const posix_1 = require("node:path/posix");
11
12
  const tree_1 = require("nx/src/generators/tree");
12
13
  const package_manager_workspaces_1 = require("../package-manager-workspaces");
14
+ const configuration_1 = require("./configuration");
13
15
  function isUsingTypeScriptPlugin(tree) {
14
16
  const nxJson = (0, devkit_1.readNxJson)(tree);
15
17
  return (nxJson?.plugins?.some((p) => typeof p === 'string'
@@ -77,15 +79,14 @@ function findRuntimeTsConfigName(tree, projectRoot) {
77
79
  return null;
78
80
  }
79
81
  function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compilerOptions, exclude = [], rootDir = 'src') {
80
- if (!isUsingTsSolutionSetup(tree))
82
+ if (!isUsingTsSolutionSetup(tree)) {
81
83
  return;
84
+ }
82
85
  const offset = (0, devkit_1.offsetFromRoot)(projectRoot);
83
- const tsconfig = `${projectRoot}/${runtimeTsconfigFileName}`;
84
- const tsconfigSpec = `${projectRoot}/tsconfig.spec.json`;
85
- const e2eRoot = `${projectRoot}-e2e`;
86
- const tsconfigE2E = `${e2eRoot}/tsconfig.json`;
87
- if (tree.exists(tsconfig)) {
88
- (0, devkit_1.updateJson)(tree, tsconfig, (json) => {
86
+ const runtimeTsconfigPath = `${projectRoot}/${runtimeTsconfigFileName}`;
87
+ const specTsconfigPath = `${projectRoot}/tsconfig.spec.json`;
88
+ if (tree.exists(runtimeTsconfigPath)) {
89
+ (0, devkit_1.updateJson)(tree, runtimeTsconfigPath, (json) => {
89
90
  json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
90
91
  json.compilerOptions = {
91
92
  ...json.compilerOptions,
@@ -100,13 +101,15 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
100
101
  // at `<outDir>/<relative path to config from rootDir>/`, so we need
101
102
  // to set it explicitly to ensure it's output to the outDir
102
103
  // https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile
103
- json.compilerOptions.tsBuildInfoFile = (0, posix_1.join)('out-tsc', projectRoot.split('/').at(-1), (0, posix_1.basename)(runtimeTsconfigFileName, '.json') + '.tsbuildinfo');
104
+ json.compilerOptions.tsBuildInfoFile = (0, posix_1.join)(json.compilerOptions.outDir, (0, posix_1.basename)(runtimeTsconfigFileName, '.json') + '.tsbuildinfo');
104
105
  }
105
106
  else if (json.compilerOptions.tsBuildInfoFile) {
106
107
  // when rootDir is '.' or not set, it would be output to the outDir, so
107
108
  // we don't need to set it explicitly
108
109
  delete json.compilerOptions.tsBuildInfoFile;
109
110
  }
111
+ // don't duplicate compiler options from base tsconfig
112
+ json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, json.compilerOptions, 'tsconfig.base.json');
110
113
  const excludeSet = json.exclude
111
114
  ? new Set(['out-tsc', 'dist', ...json.exclude, ...exclude])
112
115
  : new Set(exclude);
@@ -114,17 +117,20 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
114
117
  return json;
115
118
  });
116
119
  }
117
- if (tree.exists(tsconfigSpec)) {
118
- (0, devkit_1.updateJson)(tree, tsconfigSpec, (json) => {
120
+ if (tree.exists(specTsconfigPath)) {
121
+ (0, devkit_1.updateJson)(tree, specTsconfigPath, (json) => {
119
122
  json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
120
123
  json.compilerOptions = {
121
124
  ...json.compilerOptions,
122
125
  ...compilerOptions,
123
126
  };
127
+ // don't duplicate compiler options from base tsconfig
128
+ json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, json.compilerOptions, 'tsconfig.base.json');
124
129
  const runtimePath = `./${runtimeTsconfigFileName}`;
125
130
  json.references ??= [];
126
- if (!json.references.some((x) => x.path === runtimePath))
131
+ if (!json.references.some((x) => x.path === runtimePath)) {
127
132
  json.references.push({ path: runtimePath });
133
+ }
128
134
  return json;
129
135
  });
130
136
  }
@@ -132,8 +138,9 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
132
138
  (0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
133
139
  const projectPath = './' + projectRoot;
134
140
  json.references ??= [];
135
- if (!json.references.some((x) => x.path === projectPath))
141
+ if (!json.references.some((x) => x.path === projectPath)) {
136
142
  json.references.push({ path: projectPath });
143
+ }
137
144
  return json;
138
145
  });
139
146
  }
@@ -166,3 +173,19 @@ function addProjectToTsSolutionWorkspace(tree, projectDir) {
166
173
  }
167
174
  }
168
175
  }
176
+ function getProjectType(tree, projectRoot, projectType) {
177
+ if (projectType)
178
+ return projectType;
179
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.lib.json')))
180
+ return 'library';
181
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json')))
182
+ return 'application';
183
+ // If there are no exports, assume it is an application since both buildable and non-buildable libraries have exports.
184
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
185
+ const packageJson = tree.exists(packageJsonPath)
186
+ ? (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))
187
+ : null;
188
+ if (!packageJson?.exports)
189
+ return 'application';
190
+ return 'library';
191
+ }
@@ -8,7 +8,7 @@ export declare const swcNodeVersion = "~1.9.1";
8
8
  export declare const tsLibVersion = "^2.3.0";
9
9
  export declare const typesNodeVersion = "18.16.9";
10
10
  export declare const verdaccioVersion = "^5.0.4";
11
- export declare const typescriptVersion = "~5.6.2";
11
+ export declare const typescriptVersion = "~5.7.2";
12
12
  /**
13
13
  * The minimum version is currently determined from the lowest version
14
14
  * that's supported by the lowest Angular supported version, e.g.
@@ -12,7 +12,7 @@ exports.tsLibVersion = '^2.3.0';
12
12
  exports.typesNodeVersion = '18.16.9';
13
13
  exports.verdaccioVersion = '^5.0.4';
14
14
  // Typescript
15
- exports.typescriptVersion = '~5.6.2';
15
+ exports.typescriptVersion = '~5.7.2';
16
16
  /**
17
17
  * The minimum version is currently determined from the lowest version
18
18
  * that's supported by the lowest Angular supported version, e.g.