@nx/js 16.8.0-beta.4 → 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.
Files changed (46) hide show
  1. package/babel.js +7 -8
  2. package/package.json +5 -5
  3. package/src/executors/node/lib/kill-tree.js +42 -45
  4. package/src/executors/node/node.impl.js +190 -189
  5. package/src/executors/swc/swc.impl.js +82 -70
  6. package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +7 -4
  7. package/src/executors/tsc/lib/batch/watch.js +42 -49
  8. package/src/executors/tsc/lib/get-task-options.js +8 -6
  9. package/src/executors/tsc/lib/get-tsconfig.js +16 -5
  10. package/src/executors/tsc/lib/normalize-options.js +9 -2
  11. package/src/executors/tsc/lib/typescript-compilation.js +21 -24
  12. package/src/executors/tsc/tsc.batch-impl.js +133 -132
  13. package/src/executors/tsc/tsc.impl.js +54 -50
  14. package/src/executors/verdaccio/verdaccio.impl.js +64 -55
  15. package/src/generators/convert-to-swc/convert-to-swc.js +6 -9
  16. package/src/generators/init/init.js +86 -92
  17. package/src/generators/library/library.js +289 -245
  18. package/src/generators/setup-build/generator.js +119 -123
  19. package/src/generators/setup-verdaccio/generator.js +45 -50
  20. package/src/migrations/update-13-8-5/update-node-executor.js +17 -21
  21. package/src/migrations/update-13-8-5/update-swcrc.js +23 -27
  22. package/src/migrations/update-14-1-5/update-swcrc-path.js +17 -20
  23. package/src/migrations/update-15-8-0/rename-swcrc-config.js +57 -60
  24. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  25. package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +19 -24
  26. package/src/plugins/jest/start-local-registry.js +4 -6
  27. package/src/plugins/rollup/type-definitions.js +21 -24
  28. package/src/utils/add-babel-inputs.js +1 -2
  29. package/src/utils/assets/assets.js +1 -2
  30. package/src/utils/assets/copy-assets-handler.js +48 -59
  31. package/src/utils/assets/index.js +20 -23
  32. package/src/utils/buildable-libs-utils.js +9 -13
  33. package/src/utils/find-npm-dependencies.js +9 -11
  34. package/src/utils/generate-globs.js +3 -3
  35. package/src/utils/inline.js +5 -10
  36. package/src/utils/package-json/get-npm-scope.js +2 -2
  37. package/src/utils/package-json/index.js +22 -25
  38. package/src/utils/package-json/update-package-json.js +23 -21
  39. package/src/utils/prettier.js +21 -24
  40. package/src/utils/swc/compile-swc.js +101 -106
  41. package/src/utils/typescript/compile-typescript-files.js +7 -8
  42. package/src/utils/typescript/print-diagnostics.js +13 -16
  43. package/src/utils/typescript/run-type-check.js +62 -59
  44. package/src/utils/typescript/ts-config.js +3 -5
  45. package/src/utils/typescript/tsnode-register.js +1 -1
  46. 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 tslib_1.__awaiter(this, void 0, void 0, function* () {
18
- return yield libraryGeneratorInternal(tree, Object.assign({
19
- // provide a default projectNameAndRootFormat to avoid breaking changes
20
- // to external generators invoking this one
21
- projectNameAndRootFormat: 'derived' }, schema));
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
- const filesDir = (0, path_1.join)(__dirname, './files');
28
- const tasks = [];
29
- tasks.push(yield (0, init_1.default)(tree, Object.assign(Object.assign({}, schema), { skipFormat: true, tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json' })));
30
- const options = yield normalizeOptions(tree, schema);
31
- createFiles(tree, options, `${filesDir}/lib`);
32
- addProject(tree, options);
33
- tasks.push(addProjectDependencies(tree, options));
34
- if (options.publishable) {
35
- tasks.push(yield (0, generator_1.default)(tree, Object.assign(Object.assign({}, options), { skipFormat: true })));
36
- }
37
- if (options.bundler === 'vite') {
38
- const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
39
- const viteTask = yield viteConfigurationGenerator(tree, {
40
- project: options.name,
41
- newProject: true,
42
- uiFramework: 'none',
43
- includeVitest: options.unitTestRunner === 'vitest',
44
- includeLib: true,
45
- skipFormat: true,
46
- testEnvironment: options.testEnvironment,
47
- });
48
- tasks.push(viteTask);
49
- }
50
- if (options.linter !== 'none') {
51
- const lintCallback = yield addLint(tree, options);
52
- tasks.push(lintCallback);
53
- }
54
- if (options.unitTestRunner === 'jest') {
55
- const jestCallback = yield addJest(tree, options);
56
- tasks.push(jestCallback);
57
- if (options.bundler === 'swc' || options.bundler === 'rollup') {
58
- replaceJestConfig(tree, options, `${filesDir}/jest-config`);
59
- }
60
- }
61
- else if (options.unitTestRunner === 'vitest' &&
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
- return (0, devkit_1.runTasksInSerial)(...tasks);
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
- (_a = (_b = projectConfiguration.targets.build.options).assets) !== null && _a !== void 0 ? _a : (_b.assets = []);
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
152
- const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_1.nxVersion);
153
- const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
154
- const task = lintProjectGenerator(tree, {
155
- project: options.name,
156
- linter: options.linter,
157
- skipFormat: true,
158
- tsConfigPaths: [
159
- (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
160
- ],
161
- unitTestRunner: options.unitTestRunner,
162
- eslintFilePatterns: [
163
- `${options.projectRoot}/**/*.${options.js ? 'js' : 'ts'}`,
164
- ],
165
- setParserOptionsProject: options.setParserOptionsProject,
166
- rootProject: options.rootProject,
167
- });
168
- const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
169
- // nx-ignore-next-line
170
- } = require('@nx/linter/src/generators/utils/eslint-file');
171
- // Also update the root ESLint config. The lintProjectGenerator will not generate it for root projects.
172
- // But we need to set the package.json checks.
173
- if (options.rootProject) {
174
- if (isEslintConfigSupported(tree)) {
175
- addOverrideToLintConfig(tree, '', {
176
- files: ['*.json'],
177
- parser: 'jsonc-eslint-parser',
178
- rules: {
179
- '@nx/dependency-checks': 'error',
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
- return task;
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 = Object.assign(Object.assign({}, json.dependencies), { tslib: versions_1.tsLibVersion });
227
+ json.dependencies = {
228
+ ...json.dependencies,
229
+ tslib: versions_1.tsLibVersion,
230
+ };
234
231
  }
235
232
  else if (options.bundler === 'swc') {
236
- json.dependencies = Object.assign(Object.assign({}, json.dependencies), { '@swc/helpers': versions_1.swcHelpersVersion });
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 = Object.assign(Object.assign({}, json.compilerOptions), { forceConsistentCasingInFileNames: true, strict: true, noImplicitOverride: true, noPropertyAccessFromIndexSignature: true, noImplicitReturns: true, noFallthroughCasesInSwitch: true });
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, Object.assign(Object.assign({}, options), { dot: '.', className,
267
+ (0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, {
268
+ ...options,
269
+ dot: '.',
270
+ className,
260
271
  name,
261
- propertyName, js: !!options.js, cliCommand: 'nx', strict: undefined, tmpl: '', offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot), buildable: options.bundler && options.bundler !== 'none', hasUnitTestRunner: options.unitTestRunner !== 'none' }));
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 Object.assign(Object.assign(Object.assign({}, json), { dependencies: Object.assign(Object.assign({}, json.dependencies), determineDependencies(options)) }), determineEntryFields(options));
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, Object.assign({ name: options.importPath, version: '0.0.1', dependencies: determineDependencies(options) }, determineEntryFields(options)));
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
311
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
312
- return yield configurationGenerator(tree, Object.assign(Object.assign({}, options), { project: options.name, setupFile: 'none', supportTsx: false, skipSerializers: true, testEnvironment: options.testEnvironment, skipFormat: true, compiler: options.bundler === 'swc' || options.bundler === 'tsc'
313
- ? options.bundler
314
- : options.bundler === 'rollup'
315
- ? 'swc'
316
- : undefined }));
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
- var _a, _b, _c;
337
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
338
- /**
339
- * We are deprecating the compiler and the buildable options.
340
- * However, we want to keep the existing behavior for now.
341
- *
342
- * So, if the user has not provided a bundler, we will use the compiler option, if any.
343
- *
344
- * If the user has not provided a bundler and no compiler, but has set buildable to true,
345
- * we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
346
- * and no compiler was provided.
347
- *
348
- * If the user has not provided a bundler and no compiler, and has not set buildable to true, then
349
- * set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
350
- *
351
- * If it's publishable, we need to build the code before publishing it, so again
352
- * we default to `tsc`. In the previous version of this, it would set `buildable` to true
353
- * and that would default to `tsc`.
354
- *
355
- * In the past, the only way to get a non-buildable library was to set buildable to false.
356
- * Now, the only way to get a non-buildble library is to set bundler to none.
357
- * By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
358
- */
359
- options.bundler = (_b = (_a = options.bundler) !== null && _a !== void 0 ? _a : options.compiler) !== null && _b !== void 0 ? _b : 'tsc';
360
- // ensure programmatic runs have an expected default
361
- if (!options.config) {
362
- options.config = 'project';
363
- }
364
- if (options.publishable) {
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 (!options.linter && options.config !== 'npm-scripts') {
393
- options.linter = Linter.EsLint;
404
+ if (options.bundler === 'none') {
405
+ options.bundler = 'tsc';
394
406
  }
395
- const { projectName, names: projectNames, projectRoot, importPath, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
396
- name: options.name,
397
- projectType: 'library',
398
- directory: options.directory,
399
- importPath: options.importPath,
400
- projectNameAndRootFormat: options.projectNameAndRootFormat,
401
- rootProject: options.rootProject,
402
- callingGenerator: '@nx/js:library',
403
- });
404
- options.rootProject = projectRoot === '.';
405
- const fileName = getCaseAwareFileName({
406
- fileName: options.simpleName
407
- ? projectNames.projectSimpleName
408
- : projectNames.projectFileName,
409
- pascalCaseFiles: options.pascalCaseFiles,
410
- });
411
- const parsedTags = options.tags
412
- ? options.tags.split(',').map((s) => s.trim())
413
- : [];
414
- (_c = options.minimal) !== null && _c !== void 0 ? _c : (options.minimal = false);
415
- return Object.assign(Object.assign({}, options), { fileName, name: projectName, projectNames,
416
- projectRoot,
417
- parsedTags,
418
- importPath });
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: Object.assign(Object.assign({}, (options.rootProject ? create_ts_config_1.tsConfigBaseOptions : {})), { module: 'commonjs', allowJs: options.js ? true : undefined }),
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: [