@nx/js 16.8.0-beta.4 → 16.8.0-beta.6
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/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.js +289 -245
- package/src/generators/setup-build/generator.js +119 -123
- 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.js +9 -11
- 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 +23 -21
- 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,93 +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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// If project lints package.json with @nx/dependency-checks, then add ignore files for
|
|
185
|
-
// build configuration files such as vite.config.ts. These config files need to be
|
|
186
|
-
// ignored, otherwise we will errors on missing dependencies that are for dev only.
|
|
187
|
-
if (lintConfigHasOverride(tree, projectConfiguration.root, (o) => {
|
|
188
|
-
var _a;
|
|
189
|
-
return Array.isArray(o.files)
|
|
190
|
-
? o.files.some((f) => f.match(/\.json$/))
|
|
191
|
-
: !!((_a = o.files) === null || _a === void 0 ? void 0 : _a.match(/\.json$/));
|
|
192
|
-
}, true)) {
|
|
193
|
-
updateOverrideInLintConfig(tree, projectConfiguration.root, (o) => { var _a; return (_a = o.rules) === null || _a === void 0 ? void 0 : _a['@nx/dependency-checks']; }, (o) => {
|
|
194
|
-
const value = o.rules['@nx/dependency-checks'];
|
|
195
|
-
let ruleSeverity;
|
|
196
|
-
let ruleOptions;
|
|
197
|
-
if (Array.isArray(value)) {
|
|
198
|
-
ruleSeverity = value[0];
|
|
199
|
-
ruleOptions = value[1];
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
ruleSeverity = value;
|
|
203
|
-
ruleOptions = {};
|
|
204
|
-
}
|
|
205
|
-
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
206
|
-
ruleOptions.ignoredFiles = [
|
|
207
|
-
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
|
|
208
|
-
];
|
|
209
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
210
|
-
}
|
|
211
|
-
else if (options.bundler === 'rollup') {
|
|
212
|
-
ruleOptions.ignoredFiles = [
|
|
213
|
-
'{projectRoot}/rollup.config.{js,ts,mjs,mts}',
|
|
214
|
-
];
|
|
215
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
216
|
-
}
|
|
217
|
-
else if (options.bundler === 'esbuild') {
|
|
218
|
-
ruleOptions.ignoredFiles = [
|
|
219
|
-
'{projectRoot}/esbuild.config.{js,ts,mjs,mts}',
|
|
220
|
-
];
|
|
221
|
-
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
222
|
-
}
|
|
223
|
-
return o;
|
|
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,
|
|
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
|
+
},
|
|
224
179
|
});
|
|
225
180
|
}
|
|
226
|
-
|
|
227
|
-
|
|
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;
|
|
228
222
|
}
|
|
229
223
|
exports.addLint = addLint;
|
|
230
224
|
function addBundlerDependencies(tree, options) {
|
|
231
225
|
(0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
|
|
232
226
|
if (options.bundler === 'tsc') {
|
|
233
|
-
json.dependencies =
|
|
227
|
+
json.dependencies = {
|
|
228
|
+
...json.dependencies,
|
|
229
|
+
tslib: versions_1.tsLibVersion,
|
|
230
|
+
};
|
|
234
231
|
}
|
|
235
232
|
else if (options.bundler === 'swc') {
|
|
236
|
-
json.dependencies =
|
|
233
|
+
json.dependencies = {
|
|
234
|
+
...json.dependencies,
|
|
235
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
236
|
+
};
|
|
237
237
|
}
|
|
238
238
|
return json;
|
|
239
239
|
});
|
|
@@ -241,7 +241,15 @@ function addBundlerDependencies(tree, options) {
|
|
|
241
241
|
function updateTsConfig(tree, options) {
|
|
242
242
|
(0, devkit_1.updateJson)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.json'), (json) => {
|
|
243
243
|
if (options.strict) {
|
|
244
|
-
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
|
+
};
|
|
245
253
|
}
|
|
246
254
|
return json;
|
|
247
255
|
});
|
|
@@ -256,9 +264,20 @@ function addBabelRc(tree, options) {
|
|
|
256
264
|
function createFiles(tree, options, filesDir) {
|
|
257
265
|
const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
|
|
258
266
|
createProjectTsConfigJson(tree, options);
|
|
259
|
-
(0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot,
|
|
267
|
+
(0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, {
|
|
268
|
+
...options,
|
|
269
|
+
dot: '.',
|
|
270
|
+
className,
|
|
260
271
|
name,
|
|
261
|
-
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
|
+
});
|
|
262
281
|
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
263
282
|
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
|
264
283
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
|
|
@@ -282,11 +301,23 @@ function createFiles(tree, options, filesDir) {
|
|
|
282
301
|
if (json.private && (options.publishable || options.rootProject)) {
|
|
283
302
|
delete json.private;
|
|
284
303
|
}
|
|
285
|
-
return
|
|
304
|
+
return {
|
|
305
|
+
...json,
|
|
306
|
+
dependencies: {
|
|
307
|
+
...json.dependencies,
|
|
308
|
+
...determineDependencies(options),
|
|
309
|
+
},
|
|
310
|
+
...determineEntryFields(options),
|
|
311
|
+
};
|
|
286
312
|
});
|
|
287
313
|
}
|
|
288
314
|
else {
|
|
289
|
-
(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
|
+
});
|
|
290
321
|
}
|
|
291
322
|
if (options.config === 'npm-scripts') {
|
|
292
323
|
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
@@ -306,14 +337,21 @@ function createFiles(tree, options, filesDir) {
|
|
|
306
337
|
}
|
|
307
338
|
updateTsConfig(tree, options);
|
|
308
339
|
}
|
|
309
|
-
function addJest(tree, options) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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,
|
|
317
355
|
});
|
|
318
356
|
}
|
|
319
357
|
function replaceJestConfig(tree, options, filesDir) {
|
|
@@ -332,91 +370,93 @@ function replaceJestConfig(tree, options, filesDir) {
|
|
|
332
370
|
testEnvironment: options.testEnvironment,
|
|
333
371
|
});
|
|
334
372
|
}
|
|
335
|
-
function normalizeOptions(tree, options) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (!options.importPath) {
|
|
366
|
-
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)`);
|
|
367
|
-
}
|
|
368
|
-
if (options.bundler === 'none') {
|
|
369
|
-
options.bundler = 'tsc';
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
// This is to preserve old behaviour, buildable: false
|
|
373
|
-
if (options.publishable === false && options.buildable === false) {
|
|
374
|
-
options.bundler = 'none';
|
|
375
|
-
}
|
|
376
|
-
const { Linter } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
|
|
377
|
-
if (options.config === 'npm-scripts') {
|
|
378
|
-
options.unitTestRunner = 'none';
|
|
379
|
-
options.linter = Linter.None;
|
|
380
|
-
options.bundler = 'none';
|
|
381
|
-
}
|
|
382
|
-
if ((options.bundler === 'swc' || options.bundler === 'rollup') &&
|
|
383
|
-
options.skipTypeCheck == null) {
|
|
384
|
-
options.skipTypeCheck = false;
|
|
385
|
-
}
|
|
386
|
-
if (!options.unitTestRunner && options.bundler === 'vite') {
|
|
387
|
-
options.unitTestRunner = 'vitest';
|
|
388
|
-
}
|
|
389
|
-
else if (!options.unitTestRunner && options.config !== 'npm-scripts') {
|
|
390
|
-
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)`);
|
|
391
403
|
}
|
|
392
|
-
if (
|
|
393
|
-
options.
|
|
404
|
+
if (options.bundler === 'none') {
|
|
405
|
+
options.bundler = 'tsc';
|
|
394
406
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
options.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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',
|
|
419
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
|
+
};
|
|
420
460
|
}
|
|
421
461
|
function getCaseAwareFileName(options) {
|
|
422
462
|
const normalized = (0, devkit_1.names)(options.fileName);
|
|
@@ -471,7 +511,11 @@ function createProjectTsConfigJson(tree, options) {
|
|
|
471
511
|
extends: options.rootProject
|
|
472
512
|
? undefined
|
|
473
513
|
: (0, ts_config_1.getRelativePathToRootTsConfig)(tree, options.projectRoot),
|
|
474
|
-
compilerOptions:
|
|
514
|
+
compilerOptions: {
|
|
515
|
+
...(options.rootProject ? create_ts_config_1.tsConfigBaseOptions : {}),
|
|
516
|
+
module: 'commonjs',
|
|
517
|
+
allowJs: options.js ? true : undefined,
|
|
518
|
+
},
|
|
475
519
|
files: [],
|
|
476
520
|
include: [],
|
|
477
521
|
references: [
|