@nx/js 20.4.0-beta.0 → 20.4.0-beta.1
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 +13 -0
- package/package.json +3 -3
- package/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +5 -3
- package/src/generators/init/init.js +2 -0
- package/src/generators/init/schema.d.ts +1 -0
- package/src/generators/library/library.js +61 -39
- package/src/utils/package-json/sort-fields.d.ts +2 -0
- package/src/utils/package-json/sort-fields.js +40 -0
- package/src/utils/typescript/ts-solution-setup.js +18 -12
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
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.
|
|
3
|
+
"version": "20.4.0-beta.1",
|
|
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.
|
|
43
|
-
"@nx/workspace": "20.4.0-beta.
|
|
42
|
+
"@nx/devkit": "20.4.0-beta.1",
|
|
43
|
+
"@nx/workspace": "20.4.0-beta.1",
|
|
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": "
|
|
10
|
-
"moduleResolution": "
|
|
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
|
}
|
|
@@ -23,6 +23,7 @@ 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");
|
|
26
27
|
const defaultOutputDirectory = 'dist';
|
|
27
28
|
async function libraryGenerator(tree, schema) {
|
|
28
29
|
return await libraryGeneratorInternal(tree, {
|
|
@@ -121,10 +122,19 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
121
122
|
// add project reference to the runtime tsconfig.lib.json file
|
|
122
123
|
json.references ??= [];
|
|
123
124
|
json.references.push({ path: './tsconfig.lib.json' });
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
const compilerOptions = getCompilerOptions(options);
|
|
126
|
+
// respect the module and moduleResolution set by the test runner generator
|
|
127
|
+
if (json.compilerOptions.module) {
|
|
128
|
+
compilerOptions.module = json.compilerOptions.module;
|
|
127
129
|
}
|
|
130
|
+
if (json.compilerOptions.moduleResolution) {
|
|
131
|
+
compilerOptions.moduleResolution =
|
|
132
|
+
json.compilerOptions.moduleResolution;
|
|
133
|
+
}
|
|
134
|
+
// filter out options already set with the same value in root tsconfig file that we're going to extend from
|
|
135
|
+
json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, { ...json.compilerOptions, ...compilerOptions },
|
|
136
|
+
// must have been created by now
|
|
137
|
+
(0, ts_config_1.getRootTsConfigFileName)(tree));
|
|
128
138
|
return json;
|
|
129
139
|
});
|
|
130
140
|
}
|
|
@@ -133,6 +143,7 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
133
143
|
if (options.isUsingTsSolutionConfig) {
|
|
134
144
|
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
|
|
135
145
|
}
|
|
146
|
+
(0, sort_fields_1.sortPackageJsonFields)(tree, options.projectRoot);
|
|
136
147
|
if (!options.skipFormat) {
|
|
137
148
|
await (0, devkit_1.formatFiles)(tree);
|
|
138
149
|
}
|
|
@@ -305,19 +316,21 @@ async function addLint(tree, options) {
|
|
|
305
316
|
ruleSeverity = value;
|
|
306
317
|
ruleOptions = {};
|
|
307
318
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
319
|
+
const ignoredFiles = new Set(ruleOptions.ignoredFiles ?? []);
|
|
320
|
+
if (options.bundler === 'vite') {
|
|
321
|
+
ignoredFiles.add('{projectRoot}/vite.config.{js,ts,mjs,mts}');
|
|
312
322
|
}
|
|
313
323
|
else if (options.bundler === 'rollup') {
|
|
314
|
-
|
|
315
|
-
ruleOptions.ignoredFiles.push('{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}');
|
|
316
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
324
|
+
ignoredFiles.add('{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}');
|
|
317
325
|
}
|
|
318
326
|
else if (options.bundler === 'esbuild') {
|
|
319
|
-
|
|
320
|
-
|
|
327
|
+
ignoredFiles.add('{projectRoot}/esbuild.config.{js,ts,mjs,mts}');
|
|
328
|
+
}
|
|
329
|
+
if (options.unitTestRunner === 'vitest') {
|
|
330
|
+
ignoredFiles.add('{projectRoot}/vite.config.{js,ts,mjs,mts}');
|
|
331
|
+
}
|
|
332
|
+
if (ignoredFiles.size) {
|
|
333
|
+
ruleOptions.ignoredFiles = Array.from(ignoredFiles);
|
|
321
334
|
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
322
335
|
}
|
|
323
336
|
return o;
|
|
@@ -478,6 +491,12 @@ function createFiles(tree, options) {
|
|
|
478
491
|
return json;
|
|
479
492
|
});
|
|
480
493
|
}
|
|
494
|
+
else if (!options.isUsingTsSolutionConfig &&
|
|
495
|
+
options.useProjectJson &&
|
|
496
|
+
(!options.bundler || options.bundler === 'none') &&
|
|
497
|
+
!(options.projectRoot === '.')) {
|
|
498
|
+
tree.delete(packageJsonPath);
|
|
499
|
+
}
|
|
481
500
|
if (options.minimal && !(options.projectRoot === '.')) {
|
|
482
501
|
tree.delete((0, path_1.join)(options.projectRoot, 'README.md'));
|
|
483
502
|
}
|
|
@@ -690,33 +709,8 @@ function getOutputPath(options) {
|
|
|
690
709
|
}
|
|
691
710
|
function createProjectTsConfigs(tree, options) {
|
|
692
711
|
const rootOffset = (0, devkit_1.offsetFromRoot)(options.projectRoot);
|
|
693
|
-
let compilerOptionOverrides =
|
|
694
|
-
|
|
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) {
|
|
712
|
+
let compilerOptionOverrides = getCompilerOptions(options);
|
|
713
|
+
if (options.isUsingTsSolutionConfig) {
|
|
720
714
|
// filter out options already set with the same value in root tsconfig file that we're going to extend from
|
|
721
715
|
compilerOptionOverrides = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, compilerOptionOverrides,
|
|
722
716
|
// must have been created by now
|
|
@@ -788,6 +782,34 @@ function createProjectTsConfigs(tree, options) {
|
|
|
788
782
|
};
|
|
789
783
|
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
790
784
|
}
|
|
785
|
+
function getCompilerOptions(options) {
|
|
786
|
+
return {
|
|
787
|
+
module: options.isUsingTsSolutionConfig
|
|
788
|
+
? options.bundler === 'rollup'
|
|
789
|
+
? 'esnext'
|
|
790
|
+
: 'nodenext'
|
|
791
|
+
: 'commonjs',
|
|
792
|
+
...(options.isUsingTsSolutionConfig
|
|
793
|
+
? {
|
|
794
|
+
moduleResolution: options.bundler === 'rollup' ? 'bundler' : 'nodenext',
|
|
795
|
+
}
|
|
796
|
+
: {}),
|
|
797
|
+
...(options.js ? { allowJs: true } : {}),
|
|
798
|
+
...(options.strict
|
|
799
|
+
? {
|
|
800
|
+
forceConsistentCasingInFileNames: true,
|
|
801
|
+
strict: true,
|
|
802
|
+
importHelpers: true,
|
|
803
|
+
noImplicitOverride: true,
|
|
804
|
+
noImplicitReturns: true,
|
|
805
|
+
noFallthroughCasesInSwitch: true,
|
|
806
|
+
...(!options.isUsingTsSolutionConfig
|
|
807
|
+
? { noPropertyAccessFromIndexSignature: true }
|
|
808
|
+
: {}),
|
|
809
|
+
}
|
|
810
|
+
: {}),
|
|
811
|
+
};
|
|
812
|
+
}
|
|
791
813
|
function determineDependencies(options) {
|
|
792
814
|
switch (options.bundler) {
|
|
793
815
|
case 'tsc':
|
|
@@ -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
|
+
}
|
|
@@ -10,6 +10,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
10
10
|
const posix_1 = require("node:path/posix");
|
|
11
11
|
const tree_1 = require("nx/src/generators/tree");
|
|
12
12
|
const package_manager_workspaces_1 = require("../package-manager-workspaces");
|
|
13
|
+
const configuration_1 = require("./configuration");
|
|
13
14
|
function isUsingTypeScriptPlugin(tree) {
|
|
14
15
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
15
16
|
return (nxJson?.plugins?.some((p) => typeof p === 'string'
|
|
@@ -77,15 +78,14 @@ function findRuntimeTsConfigName(tree, projectRoot) {
|
|
|
77
78
|
return null;
|
|
78
79
|
}
|
|
79
80
|
function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compilerOptions, exclude = [], rootDir = 'src') {
|
|
80
|
-
if (!isUsingTsSolutionSetup(tree))
|
|
81
|
+
if (!isUsingTsSolutionSetup(tree)) {
|
|
81
82
|
return;
|
|
83
|
+
}
|
|
82
84
|
const offset = (0, devkit_1.offsetFromRoot)(projectRoot);
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (tree.exists(tsconfig)) {
|
|
88
|
-
(0, devkit_1.updateJson)(tree, tsconfig, (json) => {
|
|
85
|
+
const runtimeTsconfigPath = `${projectRoot}/${runtimeTsconfigFileName}`;
|
|
86
|
+
const specTsconfigPath = `${projectRoot}/tsconfig.spec.json`;
|
|
87
|
+
if (tree.exists(runtimeTsconfigPath)) {
|
|
88
|
+
(0, devkit_1.updateJson)(tree, runtimeTsconfigPath, (json) => {
|
|
89
89
|
json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
|
|
90
90
|
json.compilerOptions = {
|
|
91
91
|
...json.compilerOptions,
|
|
@@ -100,13 +100,15 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
100
100
|
// at `<outDir>/<relative path to config from rootDir>/`, so we need
|
|
101
101
|
// to set it explicitly to ensure it's output to the outDir
|
|
102
102
|
// https://www.typescriptlang.org/tsconfig/#tsBuildInfoFile
|
|
103
|
-
json.compilerOptions.tsBuildInfoFile = (0, posix_1.join)(
|
|
103
|
+
json.compilerOptions.tsBuildInfoFile = (0, posix_1.join)(json.compilerOptions.outDir, (0, posix_1.basename)(runtimeTsconfigFileName, '.json') + '.tsbuildinfo');
|
|
104
104
|
}
|
|
105
105
|
else if (json.compilerOptions.tsBuildInfoFile) {
|
|
106
106
|
// when rootDir is '.' or not set, it would be output to the outDir, so
|
|
107
107
|
// we don't need to set it explicitly
|
|
108
108
|
delete json.compilerOptions.tsBuildInfoFile;
|
|
109
109
|
}
|
|
110
|
+
// don't duplicate compiler options from base tsconfig
|
|
111
|
+
json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, json.compilerOptions, 'tsconfig.base.json');
|
|
110
112
|
const excludeSet = json.exclude
|
|
111
113
|
? new Set(['out-tsc', 'dist', ...json.exclude, ...exclude])
|
|
112
114
|
: new Set(exclude);
|
|
@@ -114,17 +116,20 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
114
116
|
return json;
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
|
-
if (tree.exists(
|
|
118
|
-
(0, devkit_1.updateJson)(tree,
|
|
119
|
+
if (tree.exists(specTsconfigPath)) {
|
|
120
|
+
(0, devkit_1.updateJson)(tree, specTsconfigPath, (json) => {
|
|
119
121
|
json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
|
|
120
122
|
json.compilerOptions = {
|
|
121
123
|
...json.compilerOptions,
|
|
122
124
|
...compilerOptions,
|
|
123
125
|
};
|
|
126
|
+
// don't duplicate compiler options from base tsconfig
|
|
127
|
+
json.compilerOptions = (0, configuration_1.getNeededCompilerOptionOverrides)(tree, json.compilerOptions, 'tsconfig.base.json');
|
|
124
128
|
const runtimePath = `./${runtimeTsconfigFileName}`;
|
|
125
129
|
json.references ??= [];
|
|
126
|
-
if (!json.references.some((x) => x.path === runtimePath))
|
|
130
|
+
if (!json.references.some((x) => x.path === runtimePath)) {
|
|
127
131
|
json.references.push({ path: runtimePath });
|
|
132
|
+
}
|
|
128
133
|
return json;
|
|
129
134
|
});
|
|
130
135
|
}
|
|
@@ -132,8 +137,9 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
132
137
|
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
133
138
|
const projectPath = './' + projectRoot;
|
|
134
139
|
json.references ??= [];
|
|
135
|
-
if (!json.references.some((x) => x.path === projectPath))
|
|
140
|
+
if (!json.references.some((x) => x.path === projectPath)) {
|
|
136
141
|
json.references.push({ path: projectPath });
|
|
142
|
+
}
|
|
137
143
|
return json;
|
|
138
144
|
});
|
|
139
145
|
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
package/src/utils/versions.js
CHANGED
|
@@ -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.
|
|
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.
|