@nx/js 16.8.0-beta.3 → 16.8.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.js +7 -8
- package/package.json +5 -5
- package/src/executors/node/lib/kill-tree.js +42 -45
- package/src/executors/node/node.impl.js +190 -189
- package/src/executors/node/schema.json +1 -1
- package/src/executors/swc/swc.impl.js +82 -70
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
- package/src/executors/tsc/lib/batch/watch.js +42 -49
- package/src/executors/tsc/lib/get-task-options.js +8 -6
- package/src/executors/tsc/lib/get-tsconfig.js +16 -5
- package/src/executors/tsc/lib/normalize-options.js +9 -2
- package/src/executors/tsc/lib/typescript-compilation.js +21 -24
- package/src/executors/tsc/tsc.batch-impl.js +133 -132
- package/src/executors/tsc/tsc.impl.js +54 -50
- package/src/executors/verdaccio/verdaccio.impl.js +64 -55
- package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
- package/src/generators/init/init.js +86 -92
- package/src/generators/library/library.d.ts +1 -1
- package/src/generators/library/library.js +290 -203
- package/src/generators/setup-build/generator.js +120 -113
- package/src/generators/setup-verdaccio/generator.js +45 -50
- package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
- package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
- package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
- package/src/plugins/jest/start-local-registry.js +4 -6
- package/src/plugins/rollup/type-definitions.js +21 -24
- package/src/utils/add-babel-inputs.js +1 -2
- package/src/utils/assets/assets.js +1 -2
- package/src/utils/assets/copy-assets-handler.js +48 -59
- package/src/utils/assets/index.js +20 -23
- package/src/utils/buildable-libs-utils.js +9 -13
- package/src/utils/find-npm-dependencies.d.ts +1 -0
- package/src/utils/find-npm-dependencies.js +25 -15
- package/src/utils/generate-globs.js +3 -3
- package/src/utils/inline.js +5 -10
- package/src/utils/package-json/get-npm-scope.js +2 -2
- package/src/utils/package-json/index.js +22 -25
- package/src/utils/package-json/update-package-json.js +26 -23
- package/src/utils/prettier.js +21 -24
- package/src/utils/swc/compile-swc.js +101 -106
- package/src/utils/typescript/compile-typescript-files.js +7 -8
- package/src/utils/typescript/print-diagnostics.js +13 -16
- package/src/utils/typescript/run-type-check.js +62 -59
- package/src/utils/typescript/ts-config.js +3 -5
- package/src/utils/typescript/tsnode-register.js +1 -1
- package/src/utils/watch-for-single-file-changes.js +13 -17
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.librarySchematic = exports.addLint = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
7
6
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
@@ -13,82 +12,82 @@ const versions_1 = require("../../utils/versions");
|
|
|
13
12
|
const init_1 = require("../init/init");
|
|
14
13
|
const generator_1 = require("../setup-verdaccio/generator");
|
|
15
14
|
const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
|
|
16
|
-
function libraryGenerator(tree, schema) {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
async function libraryGenerator(tree, schema) {
|
|
16
|
+
return await libraryGeneratorInternal(tree, {
|
|
17
|
+
// provide a default projectNameAndRootFormat to avoid breaking changes
|
|
18
|
+
// to external generators invoking this one
|
|
19
|
+
projectNameAndRootFormat: 'derived',
|
|
20
|
+
...schema,
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
exports.libraryGenerator = libraryGenerator;
|
|
25
|
-
function libraryGeneratorInternal(tree, schema) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
options.bundler !== 'vite' // Test would have been set up already
|
|
63
|
-
) {
|
|
64
|
-
const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
65
|
-
const vitestTask = yield vitestGenerator(tree, {
|
|
66
|
-
project: options.name,
|
|
67
|
-
uiFramework: 'none',
|
|
68
|
-
coverageProvider: 'c8',
|
|
69
|
-
skipFormat: true,
|
|
70
|
-
testEnvironment: options.testEnvironment,
|
|
71
|
-
});
|
|
72
|
-
tasks.push(vitestTask);
|
|
73
|
-
}
|
|
74
|
-
if (!schema.skipTsConfig) {
|
|
75
|
-
(0, ts_config_1.addTsConfigPath)(tree, options.importPath, [
|
|
76
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
if (options.bundler !== 'none') {
|
|
80
|
-
addBundlerDependencies(tree, options);
|
|
81
|
-
}
|
|
82
|
-
if (!options.skipFormat) {
|
|
83
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
24
|
+
async function libraryGeneratorInternal(tree, schema) {
|
|
25
|
+
const filesDir = (0, path_1.join)(__dirname, './files');
|
|
26
|
+
const tasks = [];
|
|
27
|
+
tasks.push(await (0, init_1.default)(tree, {
|
|
28
|
+
...schema,
|
|
29
|
+
skipFormat: true,
|
|
30
|
+
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
31
|
+
}));
|
|
32
|
+
const options = await normalizeOptions(tree, schema);
|
|
33
|
+
createFiles(tree, options, `${filesDir}/lib`);
|
|
34
|
+
addProject(tree, options);
|
|
35
|
+
tasks.push(addProjectDependencies(tree, options));
|
|
36
|
+
if (options.publishable) {
|
|
37
|
+
tasks.push(await (0, generator_1.default)(tree, { ...options, skipFormat: true }));
|
|
38
|
+
}
|
|
39
|
+
if (options.bundler === 'vite') {
|
|
40
|
+
const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
41
|
+
const viteTask = await viteConfigurationGenerator(tree, {
|
|
42
|
+
project: options.name,
|
|
43
|
+
newProject: true,
|
|
44
|
+
uiFramework: 'none',
|
|
45
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
46
|
+
includeLib: true,
|
|
47
|
+
skipFormat: true,
|
|
48
|
+
testEnvironment: options.testEnvironment,
|
|
49
|
+
});
|
|
50
|
+
tasks.push(viteTask);
|
|
51
|
+
}
|
|
52
|
+
if (options.linter !== 'none') {
|
|
53
|
+
const lintCallback = await addLint(tree, options);
|
|
54
|
+
tasks.push(lintCallback);
|
|
55
|
+
}
|
|
56
|
+
if (options.unitTestRunner === 'jest') {
|
|
57
|
+
const jestCallback = await addJest(tree, options);
|
|
58
|
+
tasks.push(jestCallback);
|
|
59
|
+
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
60
|
+
replaceJestConfig(tree, options, `${filesDir}/jest-config`);
|
|
84
61
|
}
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
}
|
|
63
|
+
else if (options.unitTestRunner === 'vitest' &&
|
|
64
|
+
options.bundler !== 'vite' // Test would have been set up already
|
|
65
|
+
) {
|
|
66
|
+
const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
67
|
+
const vitestTask = await vitestGenerator(tree, {
|
|
68
|
+
project: options.name,
|
|
69
|
+
uiFramework: 'none',
|
|
70
|
+
coverageProvider: 'c8',
|
|
71
|
+
skipFormat: true,
|
|
72
|
+
testEnvironment: options.testEnvironment,
|
|
73
|
+
});
|
|
74
|
+
tasks.push(vitestTask);
|
|
75
|
+
}
|
|
76
|
+
if (!schema.skipTsConfig) {
|
|
77
|
+
(0, ts_config_1.addTsConfigPath)(tree, options.importPath, [
|
|
78
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
if (options.bundler !== 'none') {
|
|
82
|
+
addBundlerDependencies(tree, options);
|
|
83
|
+
}
|
|
84
|
+
if (!options.skipFormat) {
|
|
85
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
86
|
+
}
|
|
87
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
87
88
|
}
|
|
88
89
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
89
90
|
function addProject(tree, options) {
|
|
90
|
-
var _a;
|
|
91
|
-
var _b;
|
|
92
91
|
const projectConfiguration = {
|
|
93
92
|
root: options.projectRoot,
|
|
94
93
|
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
@@ -125,7 +124,7 @@ function addProject(tree, options) {
|
|
|
125
124
|
if (!options.minimal &&
|
|
126
125
|
// TODO(jack): assets for rollup have validation that we need to fix (assets must be under <project-root>/src)
|
|
127
126
|
options.bundler !== 'rollup') {
|
|
128
|
-
|
|
127
|
+
projectConfiguration.targets.build.options.assets ??= [];
|
|
129
128
|
projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
|
|
130
129
|
}
|
|
131
130
|
if (options.publishable) {
|
|
@@ -147,50 +146,94 @@ function addProject(tree, options) {
|
|
|
147
146
|
}, true);
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
function addLint(tree, options) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
// Also update the root ESLint config. The lintProjectGenerator will not generate it for root projects.
|
|
168
|
-
// But we need to set the package.json checks.
|
|
169
|
-
if (options.rootProject) {
|
|
170
|
-
const { addOverrideToLintConfig, isEslintConfigSupported,
|
|
171
|
-
// nx-ignore-next-line
|
|
172
|
-
} = require('@nx/linter/src/generators/utils/eslint-file');
|
|
173
|
-
if (isEslintConfigSupported(tree)) {
|
|
174
|
-
addOverrideToLintConfig(tree, '', {
|
|
175
|
-
files: ['*.json'],
|
|
176
|
-
parser: 'jsonc-eslint-parser',
|
|
177
|
-
rules: {
|
|
178
|
-
'@nx/dependency-checks': 'error',
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return task;
|
|
149
|
+
async function addLint(tree, options) {
|
|
150
|
+
const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
|
|
151
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
|
152
|
+
const task = lintProjectGenerator(tree, {
|
|
153
|
+
project: options.name,
|
|
154
|
+
linter: options.linter,
|
|
155
|
+
skipFormat: true,
|
|
156
|
+
tsConfigPaths: [
|
|
157
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
158
|
+
],
|
|
159
|
+
unitTestRunner: options.unitTestRunner,
|
|
160
|
+
eslintFilePatterns: [
|
|
161
|
+
`${options.projectRoot}/**/*.${options.js ? 'js' : 'ts'}`,
|
|
162
|
+
],
|
|
163
|
+
setParserOptionsProject: options.setParserOptionsProject,
|
|
164
|
+
rootProject: options.rootProject,
|
|
184
165
|
});
|
|
166
|
+
const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
|
|
167
|
+
// nx-ignore-next-line
|
|
168
|
+
} = require('@nx/linter/src/generators/utils/eslint-file');
|
|
169
|
+
// Also update the root ESLint config. The lintProjectGenerator will not generate it for root projects.
|
|
170
|
+
// But we need to set the package.json checks.
|
|
171
|
+
if (options.rootProject) {
|
|
172
|
+
if (isEslintConfigSupported(tree)) {
|
|
173
|
+
addOverrideToLintConfig(tree, '', {
|
|
174
|
+
files: ['*.json'],
|
|
175
|
+
parser: 'jsonc-eslint-parser',
|
|
176
|
+
rules: {
|
|
177
|
+
'@nx/dependency-checks': 'error',
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// If project lints package.json with @nx/dependency-checks, then add ignore files for
|
|
183
|
+
// build configuration files such as vite.config.ts. These config files need to be
|
|
184
|
+
// ignored, otherwise we will errors on missing dependencies that are for dev only.
|
|
185
|
+
if (lintConfigHasOverride(tree, projectConfiguration.root, (o) => Array.isArray(o.files)
|
|
186
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
187
|
+
: !!o.files?.match(/\.json$/), true)) {
|
|
188
|
+
updateOverrideInLintConfig(tree, projectConfiguration.root, (o) => o.rules?.['@nx/dependency-checks'], (o) => {
|
|
189
|
+
const value = o.rules['@nx/dependency-checks'];
|
|
190
|
+
let ruleSeverity;
|
|
191
|
+
let ruleOptions;
|
|
192
|
+
if (Array.isArray(value)) {
|
|
193
|
+
ruleSeverity = value[0];
|
|
194
|
+
ruleOptions = value[1];
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
ruleSeverity = value;
|
|
198
|
+
ruleOptions = {};
|
|
199
|
+
}
|
|
200
|
+
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
201
|
+
ruleOptions.ignoredFiles = [
|
|
202
|
+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
203
|
+
];
|
|
204
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
205
|
+
}
|
|
206
|
+
else if (options.bundler === 'rollup') {
|
|
207
|
+
ruleOptions.ignoredFiles = [
|
|
208
|
+
'{projectRoot}/rollup.config.{js,ts,mjs,mts}',
|
|
209
|
+
];
|
|
210
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
211
|
+
}
|
|
212
|
+
else if (options.bundler === 'esbuild') {
|
|
213
|
+
ruleOptions.ignoredFiles = [
|
|
214
|
+
'{projectRoot}/esbuild.config.{js,ts,mjs,mts}',
|
|
215
|
+
];
|
|
216
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
217
|
+
}
|
|
218
|
+
return o;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return task;
|
|
185
222
|
}
|
|
186
223
|
exports.addLint = addLint;
|
|
187
224
|
function addBundlerDependencies(tree, options) {
|
|
188
225
|
(0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
|
|
189
226
|
if (options.bundler === 'tsc') {
|
|
190
|
-
json.dependencies =
|
|
227
|
+
json.dependencies = {
|
|
228
|
+
...json.dependencies,
|
|
229
|
+
tslib: versions_1.tsLibVersion,
|
|
230
|
+
};
|
|
191
231
|
}
|
|
192
232
|
else if (options.bundler === 'swc') {
|
|
193
|
-
json.dependencies =
|
|
233
|
+
json.dependencies = {
|
|
234
|
+
...json.dependencies,
|
|
235
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
236
|
+
};
|
|
194
237
|
}
|
|
195
238
|
return json;
|
|
196
239
|
});
|
|
@@ -198,7 +241,15 @@ function addBundlerDependencies(tree, options) {
|
|
|
198
241
|
function updateTsConfig(tree, options) {
|
|
199
242
|
(0, devkit_1.updateJson)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.json'), (json) => {
|
|
200
243
|
if (options.strict) {
|
|
201
|
-
json.compilerOptions =
|
|
244
|
+
json.compilerOptions = {
|
|
245
|
+
...json.compilerOptions,
|
|
246
|
+
forceConsistentCasingInFileNames: true,
|
|
247
|
+
strict: true,
|
|
248
|
+
noImplicitOverride: true,
|
|
249
|
+
noPropertyAccessFromIndexSignature: true,
|
|
250
|
+
noImplicitReturns: true,
|
|
251
|
+
noFallthroughCasesInSwitch: true,
|
|
252
|
+
};
|
|
202
253
|
}
|
|
203
254
|
return json;
|
|
204
255
|
});
|
|
@@ -213,9 +264,20 @@ function addBabelRc(tree, options) {
|
|
|
213
264
|
function createFiles(tree, options, filesDir) {
|
|
214
265
|
const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
|
|
215
266
|
createProjectTsConfigJson(tree, options);
|
|
216
|
-
(0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot,
|
|
267
|
+
(0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, {
|
|
268
|
+
...options,
|
|
269
|
+
dot: '.',
|
|
270
|
+
className,
|
|
217
271
|
name,
|
|
218
|
-
propertyName,
|
|
272
|
+
propertyName,
|
|
273
|
+
js: !!options.js,
|
|
274
|
+
cliCommand: 'nx',
|
|
275
|
+
strict: undefined,
|
|
276
|
+
tmpl: '',
|
|
277
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
278
|
+
buildable: options.bundler && options.bundler !== 'none',
|
|
279
|
+
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
280
|
+
});
|
|
219
281
|
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
220
282
|
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
|
221
283
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
|
|
@@ -239,11 +301,23 @@ function createFiles(tree, options, filesDir) {
|
|
|
239
301
|
if (json.private && (options.publishable || options.rootProject)) {
|
|
240
302
|
delete json.private;
|
|
241
303
|
}
|
|
242
|
-
return
|
|
304
|
+
return {
|
|
305
|
+
...json,
|
|
306
|
+
dependencies: {
|
|
307
|
+
...json.dependencies,
|
|
308
|
+
...determineDependencies(options),
|
|
309
|
+
},
|
|
310
|
+
...determineEntryFields(options),
|
|
311
|
+
};
|
|
243
312
|
});
|
|
244
313
|
}
|
|
245
314
|
else {
|
|
246
|
-
(0, devkit_1.writeJson)(tree, packageJsonPath,
|
|
315
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, {
|
|
316
|
+
name: options.importPath,
|
|
317
|
+
version: '0.0.1',
|
|
318
|
+
dependencies: determineDependencies(options),
|
|
319
|
+
...determineEntryFields(options),
|
|
320
|
+
});
|
|
247
321
|
}
|
|
248
322
|
if (options.config === 'npm-scripts') {
|
|
249
323
|
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
@@ -263,14 +337,21 @@ function createFiles(tree, options, filesDir) {
|
|
|
263
337
|
}
|
|
264
338
|
updateTsConfig(tree, options);
|
|
265
339
|
}
|
|
266
|
-
function addJest(tree, options) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
340
|
+
async function addJest(tree, options) {
|
|
341
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
342
|
+
return await configurationGenerator(tree, {
|
|
343
|
+
...options,
|
|
344
|
+
project: options.name,
|
|
345
|
+
setupFile: 'none',
|
|
346
|
+
supportTsx: false,
|
|
347
|
+
skipSerializers: true,
|
|
348
|
+
testEnvironment: options.testEnvironment,
|
|
349
|
+
skipFormat: true,
|
|
350
|
+
compiler: options.bundler === 'swc' || options.bundler === 'tsc'
|
|
351
|
+
? options.bundler
|
|
352
|
+
: options.bundler === 'rollup'
|
|
353
|
+
? 'swc'
|
|
354
|
+
: undefined,
|
|
274
355
|
});
|
|
275
356
|
}
|
|
276
357
|
function replaceJestConfig(tree, options, filesDir) {
|
|
@@ -289,91 +370,93 @@ function replaceJestConfig(tree, options, filesDir) {
|
|
|
289
370
|
testEnvironment: options.testEnvironment,
|
|
290
371
|
});
|
|
291
372
|
}
|
|
292
|
-
function normalizeOptions(tree, options) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (!options.importPath) {
|
|
323
|
-
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
|
324
|
-
}
|
|
325
|
-
if (options.bundler === 'none') {
|
|
326
|
-
options.bundler = 'tsc';
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
// This is to preserve old behaviour, buildable: false
|
|
330
|
-
if (options.publishable === false && options.buildable === false) {
|
|
331
|
-
options.bundler = 'none';
|
|
332
|
-
}
|
|
333
|
-
const { Linter } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
|
|
334
|
-
if (options.config === 'npm-scripts') {
|
|
335
|
-
options.unitTestRunner = 'none';
|
|
336
|
-
options.linter = Linter.None;
|
|
337
|
-
options.bundler = 'none';
|
|
338
|
-
}
|
|
339
|
-
if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
|
|
340
|
-
options.skipTypeCheck == null) {
|
|
341
|
-
options.skipTypeCheck = false;
|
|
342
|
-
}
|
|
343
|
-
if (!options.unitTestRunner && options.bundler === 'vite') {
|
|
344
|
-
options.unitTestRunner = 'vitest';
|
|
345
|
-
}
|
|
346
|
-
else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
|
|
347
|
-
options.unitTestRunner = 'jest';
|
|
373
|
+
async function normalizeOptions(tree, options) {
|
|
374
|
+
/**
|
|
375
|
+
* We are deprecating the compiler and the buildable options.
|
|
376
|
+
* However, we want to keep the existing behavior for now.
|
|
377
|
+
*
|
|
378
|
+
* So, if the user has not provided a bundler, we will use the compiler option, if any.
|
|
379
|
+
*
|
|
380
|
+
* If the user has not provided a bundler and no compiler, but has set buildable to true,
|
|
381
|
+
* we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
|
|
382
|
+
* and no compiler was provided.
|
|
383
|
+
*
|
|
384
|
+
* If the user has not provided a bundler and no compiler, and has not set buildable to true, then
|
|
385
|
+
* set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
|
|
386
|
+
*
|
|
387
|
+
* If it's publishable, we need to build the code before publishing it, so again
|
|
388
|
+
* we default to `tsc`. In the previous version of this, it would set `buildable` to true
|
|
389
|
+
* and that would default to `tsc`.
|
|
390
|
+
*
|
|
391
|
+
* In the past, the only way to get a non-buildable library was to set buildable to false.
|
|
392
|
+
* Now, the only way to get a non-buildble library is to set bundler to none.
|
|
393
|
+
* By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
|
|
394
|
+
*/
|
|
395
|
+
options.bundler = options.bundler ?? options.compiler ?? 'tsc';
|
|
396
|
+
// ensure programmatic runs have an expected default
|
|
397
|
+
if (!options.config) {
|
|
398
|
+
options.config = 'project';
|
|
399
|
+
}
|
|
400
|
+
if (options.publishable) {
|
|
401
|
+
if (!options.importPath) {
|
|
402
|
+
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
|
348
403
|
}
|
|
349
|
-
if (
|
|
350
|
-
options.
|
|
404
|
+
if (options.bundler === 'none') {
|
|
405
|
+
options.bundler = 'tsc';
|
|
351
406
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
options.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
407
|
+
}
|
|
408
|
+
// This is to preserve old behaviour, buildable: false
|
|
409
|
+
if (options.publishable === false && options.buildable === false) {
|
|
410
|
+
options.bundler = 'none';
|
|
411
|
+
}
|
|
412
|
+
const { Linter } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
|
|
413
|
+
if (options.config === 'npm-scripts') {
|
|
414
|
+
options.unitTestRunner = 'none';
|
|
415
|
+
options.linter = Linter.None;
|
|
416
|
+
options.bundler = 'none';
|
|
417
|
+
}
|
|
418
|
+
if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
|
|
419
|
+
options.skipTypeCheck == null) {
|
|
420
|
+
options.skipTypeCheck = false;
|
|
421
|
+
}
|
|
422
|
+
if (!options.unitTestRunner && options.bundler === 'vite') {
|
|
423
|
+
options.unitTestRunner = 'vitest';
|
|
424
|
+
}
|
|
425
|
+
else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
|
|
426
|
+
options.unitTestRunner = 'jest';
|
|
427
|
+
}
|
|
428
|
+
if (!options.linter && options.config !== 'npm-scripts') {
|
|
429
|
+
options.linter = Linter.EsLint;
|
|
430
|
+
}
|
|
431
|
+
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
|
|
432
|
+
name: options.name,
|
|
433
|
+
projectType: 'library',
|
|
434
|
+
directory: options.directory,
|
|
435
|
+
importPath: options.importPath,
|
|
436
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
437
|
+
rootProject: options.rootProject,
|
|
438
|
+
callingGenerator: '@nx/js:library',
|
|
376
439
|
});
|
|
440
|
+
options.rootProject = projectRoot === '.';
|
|
441
|
+
const fileName = getCaseAwareFileName({
|
|
442
|
+
fileName: options.simpleName
|
|
443
|
+
? projectNames.projectSimpleName
|
|
444
|
+
: projectNames.projectFileName,
|
|
445
|
+
pascalCaseFiles: options.pascalCaseFiles,
|
|
446
|
+
});
|
|
447
|
+
const parsedTags = options.tags
|
|
448
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
449
|
+
: [];
|
|
450
|
+
options.minimal ??= false;
|
|
451
|
+
return {
|
|
452
|
+
...options,
|
|
453
|
+
fileName,
|
|
454
|
+
name: projectName,
|
|
455
|
+
projectNames,
|
|
456
|
+
projectRoot,
|
|
457
|
+
parsedTags,
|
|
458
|
+
importPath,
|
|
459
|
+
};
|
|
377
460
|
}
|
|
378
461
|
function getCaseAwareFileName(options) {
|
|
379
462
|
const normalized = (0, devkit_1.names)(options.fileName);
|
|
@@ -428,7 +511,11 @@ function createProjectTsConfigJson(tree, options) {
|
|
|
428
511
|
extends: options.rootProject
|
|
429
512
|
? undefined
|
|
430
513
|
: (0, ts_config_1.getRelativePathToRootTsConfig)(tree, options.projectRoot),
|
|
431
|
-
compilerOptions:
|
|
514
|
+
compilerOptions: {
|
|
515
|
+
...(options.rootProject ? create_ts_config_1.tsConfigBaseOptions : {}),
|
|
516
|
+
module: 'commonjs',
|
|
517
|
+
allowJs: options.js ? true : undefined,
|
|
518
|
+
},
|
|
432
519
|
files: [],
|
|
433
520
|
include: [],
|
|
434
521
|
references: [
|