@nx/js 19.8.0 → 20.0.0-beta.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "19.8.0",
3
+ "version": "20.0.0-beta.0",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,14 +39,15 @@
39
39
  "@babel/preset-env": "^7.23.2",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nx/devkit": "19.8.0",
43
- "@nx/workspace": "19.8.0",
42
+ "@nx/devkit": "20.0.0-beta.0",
43
+ "@nx/workspace": "20.0.0-beta.0",
44
44
  "babel-plugin-const-enum": "^1.0.1",
45
45
  "babel-plugin-macros": "^2.8.0",
46
46
  "babel-plugin-transform-typescript-metadata": "^0.3.1",
47
47
  "chalk": "^4.1.0",
48
48
  "columnify": "^1.6.0",
49
49
  "detect-port": "^1.5.1",
50
+ "enquirer": "~2.3.6",
50
51
  "fast-glob": "3.2.7",
51
52
  "ignore": "^5.0.4",
52
53
  "js-tokens": "^4.0.0",
@@ -60,7 +61,7 @@
60
61
  "ts-node": "10.9.1",
61
62
  "tsconfig-paths": "^4.1.2",
62
63
  "tslib": "^2.3.0",
63
- "@nrwl/js": "19.8.0"
64
+ "@nrwl/js": "20.0.0-beta.0"
64
65
  },
65
66
  "peerDependencies": {
66
67
  "verdaccio": "^5.0.4"
@@ -5,10 +5,5 @@
5
5
  "declaration": true,
6
6
  "types": ["node"]
7
7
  },
8
- "include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>],
9
- "exclude": [
10
- <% if (hasUnitTestRunner && unitTestRunner === 'jest') { %>"jest.config.ts",
11
- <% } else if (hasUnitTestRunner) { %>"vite.config.ts",
12
- <% } %>"src/**/*.spec.ts", "src/**/*.test.ts"<% if (js) { %>, "src/**/*.spec.js", "src/**/*.test.js"<% } %>
13
- ]
8
+ "include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>]
14
9
  }
@@ -20,9 +20,6 @@ const defaultOutputDirectory = 'dist';
20
20
  async function libraryGenerator(tree, schema) {
21
21
  return await libraryGeneratorInternal(tree, {
22
22
  addPlugin: false,
23
- // provide a default projectNameAndRootFormat to avoid breaking changes
24
- // to external generators invoking this one
25
- projectNameAndRootFormat: 'derived',
26
23
  ...schema,
27
24
  });
28
25
  }
@@ -91,6 +88,7 @@ async function libraryGeneratorInternal(tree, schema) {
91
88
  coverageProvider: 'v8',
92
89
  skipFormat: true,
93
90
  testEnvironment: options.testEnvironment,
91
+ runtimeTsconfigFileName: 'tsconfig.lib.json',
94
92
  });
95
93
  tasks.push(vitestTask);
96
94
  createOrEditViteConfig(tree, {
@@ -423,6 +421,7 @@ async function addJest(tree, options) {
423
421
  : options.bundler === 'rollup'
424
422
  ? 'swc'
425
423
  : undefined,
424
+ runtimeTsconfigFileName: 'tsconfig.lib.json',
426
425
  });
427
426
  }
428
427
  function replaceJestConfig(tree, options) {
@@ -513,15 +512,11 @@ async function normalizeOptions(tree, options) {
513
512
  importPath: options.importPath,
514
513
  projectNameAndRootFormat: options.projectNameAndRootFormat,
515
514
  rootProject: options.rootProject,
516
- callingGenerator: '@nx/js:library',
517
515
  });
518
516
  options.rootProject = projectRoot === '.';
519
- const fileName = getCaseAwareFileName({
520
- fileName: options.simpleName
521
- ? projectNames.projectSimpleName
522
- : projectNames.projectFileName,
523
- pascalCaseFiles: options.pascalCaseFiles,
524
- });
517
+ const fileName = (0, devkit_1.names)(options.simpleName
518
+ ? projectNames.projectSimpleName
519
+ : projectNames.projectFileName).fileName;
525
520
  const parsedTags = options.tags
526
521
  ? options.tags.split(',').map((s) => s.trim())
527
522
  : [];
@@ -536,10 +531,6 @@ async function normalizeOptions(tree, options) {
536
531
  importPath,
537
532
  };
538
533
  }
539
- function getCaseAwareFileName(options) {
540
- const normalized = (0, devkit_1.names)(options.fileName);
541
- return options.pascalCaseFiles ? normalized.className : normalized.fileName;
542
- }
543
534
  function addProjectDependencies(tree, options) {
544
535
  if (options.bundler == 'esbuild') {
545
536
  return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
@@ -70,12 +70,6 @@
70
70
  "description": "The test environment to use if unitTestRunner is set to jest or vitest.",
71
71
  "default": "node"
72
72
  },
73
- "pascalCaseFiles": {
74
- "type": "boolean",
75
- "description": "Use pascal case file names.",
76
- "alias": "P",
77
- "default": false
78
- },
79
73
  "js": {
80
74
  "type": "boolean",
81
75
  "description": "Generate JavaScript files rather than TypeScript files.",
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.releaseVersionGenerator = releaseVersionGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const chalk = require("chalk");
6
+ const enquirer_1 = require("enquirer");
6
7
  const node_child_process_1 = require("node:child_process");
7
8
  const promises_1 = require("node:fs/promises");
8
9
  const node_path_1 = require("node:path");
@@ -134,9 +135,23 @@ To fix this you will either need to add a package.json file at that location, or
134
135
  catch (e) {
135
136
  spinner.stop();
136
137
  if (options.fallbackCurrentVersionResolver === 'disk') {
137
- logger.buffer(`📄 Unable to resolve the current version from the registry ${registry}. Falling back to the version on disk of ${currentVersionFromDisk}`);
138
- currentVersion = currentVersionFromDisk;
139
- currentVersionResolvedFromFallback = true;
138
+ if (!currentVersionFromDisk &&
139
+ (options.specifierSource === 'conventional-commits' ||
140
+ options.specifierSource === 'version-plans')) {
141
+ currentVersion = await handleNoAvailableDiskFallback({
142
+ logger,
143
+ projectName,
144
+ packageJsonPath,
145
+ specifierSource: options.specifierSource,
146
+ currentVersionSourceMessage: `from the registry ${registry}`,
147
+ resolutionSuggestion: `you should publish an initial version to the registry`,
148
+ });
149
+ }
150
+ else {
151
+ logger.buffer(`📄 Unable to resolve the current version from the registry ${registry}. Falling back to the version on disk of ${currentVersionFromDisk}`);
152
+ currentVersion = currentVersionFromDisk;
153
+ currentVersionResolvedFromFallback = true;
154
+ }
140
155
  }
141
156
  else {
142
157
  throw new Error(`Unable to resolve the current version from the registry ${registry}. Please ensure that the package exists in the registry in order to use the "registry" currentVersionResolver. Alternatively, you can use the --first-release option or set "release.version.generatorOptions.fallbackCurrentVersionResolver" to "disk" in order to fallback to the version on disk when the registry lookup fails.`);
@@ -156,7 +171,7 @@ To fix this you will either need to add a package.json file at that location, or
156
171
  case 'disk':
157
172
  currentVersion = currentVersionFromDisk;
158
173
  if (!currentVersion) {
159
- throw new Error(`Unable to determine the current version for project "${project.name}" from ${packageJsonPath}`);
174
+ throw new Error(`Unable to determine the current version for project "${project.name}" from ${packageJsonPath}, please ensure that the "version" field is set within the file`);
160
175
  }
161
176
  logger.buffer(`📄 Resolved the current version as ${currentVersion} from ${packageJsonPath}`);
162
177
  break;
@@ -170,9 +185,23 @@ To fix this you will either need to add a package.json file at that location, or
170
185
  });
171
186
  if (!latestMatchingGitTag) {
172
187
  if (options.fallbackCurrentVersionResolver === 'disk') {
173
- logger.buffer(`📄 Unable to resolve the current version from git tag using pattern "${releaseTagPattern}". Falling back to the version on disk of ${currentVersionFromDisk}`);
174
- currentVersion = currentVersionFromDisk;
175
- currentVersionResolvedFromFallback = true;
188
+ if (!currentVersionFromDisk &&
189
+ (options.specifierSource === 'conventional-commits' ||
190
+ options.specifierSource === 'version-plans')) {
191
+ currentVersion = await handleNoAvailableDiskFallback({
192
+ logger,
193
+ projectName,
194
+ packageJsonPath,
195
+ specifierSource: options.specifierSource,
196
+ currentVersionSourceMessage: `from git tag using pattern "${releaseTagPattern}"`,
197
+ resolutionSuggestion: `you should set an initial git tag on a relevant commit`,
198
+ });
199
+ }
200
+ else {
201
+ logger.buffer(`📄 Unable to resolve the current version from git tag using pattern "${releaseTagPattern}". Falling back to the version on disk of ${currentVersionFromDisk}`);
202
+ currentVersion = currentVersionFromDisk;
203
+ currentVersionResolvedFromFallback = true;
204
+ }
176
205
  }
177
206
  else {
178
207
  throw new Error(`No git tags matching pattern "${releaseTagPattern}" for project "${project.name}" were found. You will need to create an initial matching tag to use as a base for determining the next version. Alternatively, you can use the --first-release option or set "release.version.generatorOptions.fallbackCurrentVersionResolver" to "disk" in order to fallback to the version on disk when no matching git tags are found.`);
@@ -675,3 +704,35 @@ class ProjectLogger {
675
704
  });
676
705
  }
677
706
  }
707
+ /**
708
+ * Allow users to be unblocked when locally running releases for the very first time with certain combinations that require an initial
709
+ * version in order to function (e.g. a relative semver bump derived via conventional commits or version plans) by providing an interactive
710
+ * prompt to let them opt into using 0.0.0 as the implied current version.
711
+ */
712
+ async function handleNoAvailableDiskFallback({ logger, projectName, packageJsonPath, specifierSource, currentVersionSourceMessage, resolutionSuggestion, }) {
713
+ const unresolvableCurrentVersionError = new Error(`Unable to resolve the current version ${currentVersionSourceMessage} and there is no version on disk to fall back to. This is invalid with ${specifierSource} because the new version is determined by relatively bumping the current version. To resolve this, ${resolutionSuggestion}, or set an appropriate value for "version" in ${packageJsonPath}`);
714
+ if (process.env.CI === 'true') {
715
+ // We can't prompt in CI, so error immediately
716
+ throw unresolvableCurrentVersionError;
717
+ }
718
+ try {
719
+ const reply = await (0, enquirer_1.prompt)([
720
+ {
721
+ name: 'useZero',
722
+ message: `\n${chalk.yellow(`Warning: Unable to resolve the current version for "${projectName}" ${currentVersionSourceMessage} and there is no version on disk to fall back to. This is invalid with ${specifierSource} because the new version is determined by relatively bumping the current version.\n\nTo resolve this, ${resolutionSuggestion}, or set an appropriate value for "version" in ${packageJsonPath}`)}. \n\nAlternatively, would you like to continue now by using 0.0.0 as the current version?`,
723
+ type: 'confirm',
724
+ initial: false,
725
+ },
726
+ ]);
727
+ if (!reply.useZero) {
728
+ // Throw any error to skip the fallback to 0.0.0, may as well use the one we already have
729
+ throw unresolvableCurrentVersionError;
730
+ }
731
+ const currentVersion = '0.0.0';
732
+ logger.buffer(`📄 Forcibly resolved the current version as "${currentVersion}" based on your response to the prompt above.`);
733
+ return currentVersion;
734
+ }
735
+ catch {
736
+ throw unresolvableCurrentVersionError;
737
+ }
738
+ }
@@ -21,7 +21,6 @@ export interface LibraryGeneratorSchema {
21
21
  testEnvironment?: 'jsdom' | 'node';
22
22
  importPath?: string;
23
23
  js?: boolean;
24
- pascalCaseFiles?: boolean;
25
24
  strict?: boolean;
26
25
  publishable?: boolean;
27
26
  buildable?: boolean;