@nx/js 17.0.4 → 17.0.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.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/babel.js +16 -36
  4. package/executors.json +1 -1
  5. package/migrations.json +0 -56
  6. package/package.json +9 -9
  7. package/src/executors/node/node.impl.js +1 -1
  8. package/src/executors/node/schema.json +1 -1
  9. package/src/executors/release-publish/release-publish.impl.js +32 -135
  10. package/src/executors/release-publish/schema.d.ts +0 -2
  11. package/src/executors/release-publish/schema.json +1 -1
  12. package/src/executors/swc/schema.json +1 -1
  13. package/src/executors/swc/swc.impl.js +7 -6
  14. package/src/executors/verdaccio/schema.json +1 -1
  15. package/src/executors/verdaccio/verdaccio.impl.js +1 -1
  16. package/src/generators/convert-to-swc/schema.json +1 -1
  17. package/src/generators/init/init.js +2 -3
  18. package/src/generators/init/schema.d.ts +0 -1
  19. package/src/generators/init/schema.json +1 -7
  20. package/src/generators/library/files/{readme → lib}/README.md +1 -1
  21. package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +1 -5
  22. package/src/generators/library/library.d.ts +1 -1
  23. package/src/generators/library/library.js +29 -171
  24. package/src/generators/library/schema.json +2 -8
  25. package/src/generators/release-version/release-version.d.ts +1 -2
  26. package/src/generators/release-version/release-version.js +86 -341
  27. package/src/generators/release-version/schema.json +4 -26
  28. package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +1 -7
  29. package/src/generators/release-version/utils/resolve-local-package-dependencies.js +4 -14
  30. package/src/generators/release-version/utils/resolve-version-spec.js +1 -4
  31. package/src/generators/setup-build/generator.js +0 -3
  32. package/src/generators/setup-build/schema.json +1 -1
  33. package/src/generators/setup-verdaccio/schema.json +1 -1
  34. package/src/utils/add-local-registry-scripts.js +6 -26
  35. package/src/utils/assets/copy-assets-handler.js +4 -4
  36. package/src/utils/buildable-libs-utils.js +2 -6
  37. package/src/utils/find-npm-dependencies.d.ts +1 -2
  38. package/src/utils/find-npm-dependencies.js +11 -28
  39. package/src/utils/inline.js +4 -6
  40. package/src/utils/minimal-publish-script.d.ts +2 -0
  41. package/src/utils/minimal-publish-script.js +74 -0
  42. package/src/utils/schema.d.ts +0 -3
  43. package/src/utils/swc/get-swcrc-path.d.ts +1 -4
  44. package/src/utils/swc/get-swcrc-path.js +1 -6
  45. package/src/utils/swc/inline.d.ts +1 -1
  46. package/src/utils/swc/inline.js +2 -1
  47. package/src/utils/typescript/ast-utils.js +3 -2
  48. package/src/utils/typescript/ts-config.js +0 -1
  49. package/src/utils/versions.d.ts +4 -4
  50. package/src/utils/versions.js +4 -4
  51. package/src/generators/release-version/utils/update-lock-file.d.ts +0 -5
  52. package/src/generators/release-version/utils/update-lock-file.js +0 -105
  53. package/src/utils/npm-config.d.ts +0 -25
  54. package/src/utils/npm-config.js +0 -90
@@ -3,21 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLint = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
- const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
7
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
8
- const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
6
+ const ts_config_1 = require("../../utils/typescript/ts-config");
9
7
  const path_1 = require("path");
8
+ const minimal_publish_script_1 = require("../../utils/minimal-publish-script");
10
9
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
11
10
  const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
12
- const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
13
- const ts_config_1 = require("../../utils/typescript/ts-config");
14
11
  const versions_1 = require("../../utils/versions");
15
12
  const init_1 = require("../init/init");
16
13
  const generator_1 = require("../setup-verdaccio/generator");
17
- const defaultOutputDirectory = 'dist';
14
+ const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
18
15
  async function libraryGenerator(tree, schema) {
19
16
  return await libraryGeneratorInternal(tree, {
20
- addPlugin: false,
21
17
  // provide a default projectNameAndRootFormat to avoid breaking changes
22
18
  // to external generators invoking this one
23
19
  projectNameAndRootFormat: 'derived',
@@ -26,6 +22,7 @@ async function libraryGenerator(tree, schema) {
26
22
  }
27
23
  exports.libraryGenerator = libraryGenerator;
28
24
  async function libraryGeneratorInternal(tree, schema) {
25
+ const filesDir = (0, path_1.join)(__dirname, './files');
29
26
  const tasks = [];
30
27
  tasks.push(await (0, init_1.default)(tree, {
31
28
  ...schema,
@@ -33,11 +30,9 @@ async function libraryGeneratorInternal(tree, schema) {
33
30
  tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
34
31
  }));
35
32
  const options = await normalizeOptions(tree, schema);
36
- createFiles(tree, options);
37
- await addProject(tree, options);
38
- if (!options.skipPackageJson) {
39
- tasks.push(addProjectDependencies(tree, options));
40
- }
33
+ createFiles(tree, options, `${filesDir}/lib`);
34
+ addProject(tree, options);
35
+ tasks.push(addProjectDependencies(tree, options));
41
36
  if (options.publishable) {
42
37
  tasks.push(await (0, generator_1.default)(tree, { ...options, skipFormat: true }));
43
38
  }
@@ -51,7 +46,6 @@ async function libraryGeneratorInternal(tree, schema) {
51
46
  includeLib: true,
52
47
  skipFormat: true,
53
48
  testEnvironment: options.testEnvironment,
54
- addPlugin: options.addPlugin,
55
49
  });
56
50
  tasks.push(viteTask);
57
51
  createOrEditViteConfig(tree, {
@@ -69,7 +63,7 @@ async function libraryGeneratorInternal(tree, schema) {
69
63
  const jestCallback = await addJest(tree, options);
70
64
  tasks.push(jestCallback);
71
65
  if (options.bundler === 'swc' || options.bundler === 'rollup') {
72
- replaceJestConfig(tree, options);
66
+ replaceJestConfig(tree, options, `${filesDir}/jest-config`);
73
67
  }
74
68
  }
75
69
  else if (options.unitTestRunner === 'vitest' &&
@@ -79,7 +73,7 @@ async function libraryGeneratorInternal(tree, schema) {
79
73
  const vitestTask = await vitestGenerator(tree, {
80
74
  project: options.name,
81
75
  uiFramework: 'none',
82
- coverageProvider: 'v8',
76
+ coverageProvider: 'c8',
83
77
  skipFormat: true,
84
78
  testEnvironment: options.testEnvironment,
85
79
  });
@@ -102,18 +96,10 @@ async function libraryGeneratorInternal(tree, schema) {
102
96
  if (!options.skipFormat) {
103
97
  await (0, devkit_1.formatFiles)(tree);
104
98
  }
105
- if (options.publishable) {
106
- tasks.push(() => {
107
- logNxReleaseDocsInfo();
108
- });
109
- }
110
- tasks.push(() => {
111
- (0, log_show_project_command_1.logShowProjectCommand)(options.name);
112
- });
113
99
  return (0, devkit_1.runTasksInSerial)(...tasks);
114
100
  }
115
101
  exports.libraryGeneratorInternal = libraryGeneratorInternal;
116
- async function addProject(tree, options) {
102
+ function addProject(tree, options) {
117
103
  const projectConfiguration = {
118
104
  root: options.projectRoot,
119
105
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
@@ -125,10 +111,8 @@ async function addProject(tree, options) {
125
111
  options.bundler !== 'none' &&
126
112
  options.config !== 'npm-scripts') {
127
113
  const outputPath = getOutputPath(options);
128
- const executor = getBuildExecutor(options.bundler);
129
- (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, executor);
130
114
  projectConfiguration.targets.build = {
131
- executor,
115
+ executor: getBuildExecutor(options.bundler),
132
116
  outputs: ['{options.outputPath}'],
133
117
  options: {
134
118
  outputPath,
@@ -156,24 +140,11 @@ async function addProject(tree, options) {
156
140
  projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
157
141
  }
158
142
  if (options.publishable) {
159
- const packageRoot = (0, path_1.join)(defaultOutputDirectory, '{projectRoot}');
160
- projectConfiguration.targets ??= {};
161
- projectConfiguration.targets['nx-release-publish'] = {
162
- options: {
163
- packageRoot,
164
- },
165
- };
166
- projectConfiguration.release = {
167
- version: {
168
- generatorOptions: {
169
- packageRoot,
170
- // using git tags to determine the current version is required here because
171
- // the version in the package root is overridden with every build
172
- currentVersionResolver: 'git-tag',
173
- },
174
- },
143
+ const publishScriptPath = (0, minimal_publish_script_1.addMinimalPublishScript)(tree);
144
+ projectConfiguration.targets.publish = {
145
+ command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
146
+ dependsOn: ['build'],
175
147
  };
176
- await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
177
148
  }
178
149
  }
179
150
  if (options.config === 'workspace' || options.config === 'project') {
@@ -189,8 +160,11 @@ async function addProject(tree, options) {
189
160
  }
190
161
  async function addLint(tree, options) {
191
162
  const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
163
+ const { mapLintPattern } =
164
+ // nx-ignore-next-line
165
+ require('@nx/eslint/src/generators/lint-project/lint-project');
192
166
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
193
- const task = await lintProjectGenerator(tree, {
167
+ const task = lintProjectGenerator(tree, {
194
168
  project: options.name,
195
169
  linter: options.linter,
196
170
  skipFormat: true,
@@ -198,9 +172,11 @@ async function addLint(tree, options) {
198
172
  (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
199
173
  ],
200
174
  unitTestRunner: options.unitTestRunner,
175
+ eslintFilePatterns: [
176
+ mapLintPattern(options.projectRoot, options.js ? 'js' : 'ts', options.rootProject),
177
+ ],
201
178
  setParserOptionsProject: options.setParserOptionsProject,
202
179
  rootProject: options.rootProject,
203
- addPlugin: options.addPlugin,
204
180
  });
205
181
  const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig,
206
182
  // nx-ignore-next-line
@@ -302,10 +278,10 @@ function addBabelRc(tree, options) {
302
278
  };
303
279
  (0, devkit_1.writeJson)(tree, (0, path_1.join)(options.projectRoot, filename), babelrc);
304
280
  }
305
- function createFiles(tree, options) {
281
+ function createFiles(tree, options, filesDir) {
306
282
  const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
307
283
  createProjectTsConfigJson(tree, options);
308
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/lib'), options.projectRoot, {
284
+ (0, devkit_1.generateFiles)(tree, filesDir, options.projectRoot, {
309
285
  ...options,
310
286
  dot: '.',
311
287
  className,
@@ -319,22 +295,6 @@ function createFiles(tree, options) {
319
295
  buildable: options.bundler && options.bundler !== 'none',
320
296
  hasUnitTestRunner: options.unitTestRunner !== 'none',
321
297
  });
322
- if (!options.rootProject) {
323
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/readme'), options.projectRoot, {
324
- ...options,
325
- dot: '.',
326
- className,
327
- name,
328
- propertyName,
329
- js: !!options.js,
330
- cliCommand: 'nx',
331
- strict: undefined,
332
- tmpl: '',
333
- offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
334
- buildable: options.bundler && options.bundler !== 'none',
335
- hasUnitTestRunner: options.unitTestRunner !== 'none',
336
- });
337
- }
338
298
  if (options.bundler === 'swc' || options.bundler === 'rollup') {
339
299
  (0, add_swc_dependencies_1.addSwcDependencies)(tree);
340
300
  (0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
@@ -358,9 +318,6 @@ function createFiles(tree, options) {
358
318
  if (json.private && (options.publishable || options.rootProject)) {
359
319
  delete json.private;
360
320
  }
361
- if (!options.publishable && !options.rootProject) {
362
- json.private = true;
363
- }
364
321
  return {
365
322
  ...json,
366
323
  dependencies: {
@@ -372,16 +329,12 @@ function createFiles(tree, options) {
372
329
  });
373
330
  }
374
331
  else {
375
- const packageJson = {
332
+ (0, devkit_1.writeJson)(tree, packageJsonPath, {
376
333
  name: options.importPath,
377
334
  version: '0.0.1',
378
335
  dependencies: determineDependencies(options),
379
336
  ...determineEntryFields(options),
380
- };
381
- if (!options.publishable && !options.rootProject) {
382
- packageJson.private = true;
383
- }
384
- (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
337
+ });
385
338
  }
386
339
  if (options.config === 'npm-scripts') {
387
340
  (0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
@@ -418,8 +371,7 @@ async function addJest(tree, options) {
418
371
  : undefined,
419
372
  });
420
373
  }
421
- function replaceJestConfig(tree, options) {
422
- const filesDir = (0, path_1.join)(__dirname, './files/jest-config');
374
+ function replaceJestConfig(tree, options, filesDir) {
423
375
  // the existing config has to be deleted otherwise the new config won't overwrite it
424
376
  const existingJestConfig = (0, devkit_1.joinPathFragments)(filesDir, `jest.config.${options.js ? 'js' : 'ts'}`);
425
377
  if (tree.exists(existingJestConfig)) {
@@ -436,10 +388,6 @@ function replaceJestConfig(tree, options) {
436
388
  });
437
389
  }
438
390
  async function normalizeOptions(tree, options) {
439
- const nxJson = (0, devkit_1.readNxJson)(tree);
440
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
441
- nxJson.useInferencePlugins !== false;
442
- options.addPlugin ??= addPlugin;
443
391
  /**
444
392
  * We are deprecating the compiler and the buildable options.
445
393
  * However, we want to keep the existing behavior for now.
@@ -474,7 +422,7 @@ async function normalizeOptions(tree, options) {
474
422
  options.bundler = 'tsc';
475
423
  }
476
424
  }
477
- // This is to preserve old behavior, buildable: false
425
+ // This is to preserve old behaviour, buildable: false
478
426
  if (options.publishable === false && options.buildable === false) {
479
427
  options.bundler = 'none';
480
428
  }
@@ -566,7 +514,7 @@ function getBuildExecutor(bundler) {
566
514
  }
567
515
  }
568
516
  function getOutputPath(options) {
569
- const parts = [defaultOutputDirectory];
517
+ const parts = ['dist'];
570
518
  if (options.projectRoot === '.') {
571
519
  parts.push(options.name);
572
520
  }
@@ -658,94 +606,4 @@ function determineEntryFields(options) {
658
606
  }
659
607
  }
660
608
  }
661
- function projectsConfigMatchesProject(projectsConfig, project) {
662
- if (!projectsConfig) {
663
- return false;
664
- }
665
- if (typeof projectsConfig === 'string') {
666
- projectsConfig = [projectsConfig];
667
- }
668
- const graph = {
669
- [project.name]: project,
670
- };
671
- const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
672
- return matchingProjects.includes(project.name);
673
- }
674
- async function addProjectToNxReleaseConfig(tree, options, projectConfiguration) {
675
- const nxJson = (0, devkit_1.readNxJson)(tree);
676
- const addPreVersionCommand = () => {
677
- const pmc = (0, devkit_1.getPackageManagerCommand)();
678
- nxJson.release = {
679
- ...nxJson.release,
680
- version: {
681
- preVersionCommand: `${pmc.dlx} nx run-many -t build`,
682
- ...nxJson.release?.version,
683
- },
684
- };
685
- };
686
- if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
687
- // skip adding any projects configuration since the new project should be
688
- // automatically included by nx release's default project detection logic
689
- addPreVersionCommand();
690
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
691
- return;
692
- }
693
- const project = {
694
- name: options.name,
695
- type: 'lib',
696
- data: {
697
- root: projectConfiguration.root,
698
- tags: projectConfiguration.tags,
699
- },
700
- };
701
- if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
702
- devkit_1.output.log({
703
- title: `Project already included in existing release configuration`,
704
- });
705
- addPreVersionCommand();
706
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
707
- return;
708
- }
709
- if (Array.isArray(nxJson.release.projects)) {
710
- nxJson.release.projects.push(options.name);
711
- addPreVersionCommand();
712
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
713
- devkit_1.output.log({
714
- title: `Added project to existing release configuration`,
715
- });
716
- }
717
- if (nxJson.release.groups) {
718
- const allGroups = Object.entries(nxJson.release.groups);
719
- for (const [name, group] of allGroups) {
720
- if (projectsConfigMatchesProject(group.projects, project)) {
721
- addPreVersionCommand();
722
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
723
- return `Project already included in existing release configuration for group ${name}`;
724
- }
725
- }
726
- devkit_1.output.warn({
727
- title: `Could not find a release group that includes ${options.name}`,
728
- bodyLines: [
729
- `Ensure that ${options.name} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
730
- ],
731
- });
732
- addPreVersionCommand();
733
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
734
- return;
735
- }
736
- if (typeof nxJson.release.projects === 'string') {
737
- nxJson.release.projects = [nxJson.release.projects, options.name];
738
- addPreVersionCommand();
739
- (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
740
- devkit_1.output.log({
741
- title: `Added project to existing release configuration`,
742
- });
743
- return;
744
- }
745
- }
746
- function logNxReleaseDocsInfo() {
747
- devkit_1.output.log({
748
- title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
749
- });
750
- }
751
609
  exports.default = libraryGenerator;
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxTypescriptLibrary",
4
4
  "cli": "nx",
5
5
  "title": "Create a TypeScript Library",
@@ -48,12 +48,6 @@
48
48
  "default": false,
49
49
  "x-priority": "internal"
50
50
  },
51
- "skipPackageJson": {
52
- "description": "Do not add dependencies to `package.json`.",
53
- "type": "boolean",
54
- "default": false,
55
- "x-priority": "internal"
56
- },
57
51
  "skipTsConfig": {
58
52
  "type": "boolean",
59
53
  "description": "Do not update tsconfig.json for development experience.",
@@ -89,7 +83,7 @@
89
83
  "publishable": {
90
84
  "type": "boolean",
91
85
  "default": false,
92
- "description": "Configure the library ready for use with `nx release` (https://nx.dev/core-features/manage-releases).",
86
+ "description": "Generate a publishable library.",
93
87
  "x-priority": "important"
94
88
  },
95
89
  "importPath": {
@@ -1,5 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
- import { ReleaseVersionGeneratorResult } from 'nx/src/command-line/release/version';
3
2
  import { ReleaseVersionGeneratorSchema } from './schema';
4
- export declare function releaseVersionGenerator(tree: Tree, options: ReleaseVersionGeneratorSchema): Promise<ReleaseVersionGeneratorResult>;
3
+ export declare function releaseVersionGenerator(tree: Tree, options: ReleaseVersionGeneratorSchema): Promise<void>;
5
4
  export default releaseVersionGenerator;