@nx/js 20.0.0-beta.5 → 20.0.0-beta.7

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 CHANGED
@@ -13,7 +13,7 @@ module.exports = function (api, options = {}) {
13
13
  const emitDecoratorMetadata = api.caller((caller) => caller?.emitDecoratorMetadata ?? true);
14
14
  // Determine settings for `@babel//babel-plugin-transform-class-properties`,
15
15
  // so that we can sync the `loose` option with `@babel/preset-env`.
16
- // TODO(v20): Remove classProperties since it's no longer needed, now that the class props transform is in preset-env.
16
+ // TODO(v21): Remove classProperties since it's no longer needed, now that the class props transform is in preset-env.
17
17
  const loose = options.classProperties?.loose ?? options.loose ?? true;
18
18
  if (options.classProperties) {
19
19
  devkit_1.logger.warn(`Use =\`loose\` option instead of \`classProperties.loose\`. The \`classProperties\` option will be removed in Nx 20`);
package/migrations.json CHANGED
@@ -1,23 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "update-16-0-0-add-nx-packages": {
4
- "cli": "nx",
5
- "version": "16.0.0-beta.1",
6
- "description": "Replace @nrwl/js with @nx/js",
7
- "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
8
- },
9
- "explicitly-set-projects-to-update-buildable-deps": {
10
- "cli": "nx",
11
- "version": "16.6.0-beta.0",
12
- "description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
13
- "factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
14
- },
15
- "16-8-2-update-swcrc": {
16
- "cli": "nx",
17
- "version": "16.8.2-beta.0",
18
- "description": "Remove invalid options (strict, noInterop) for ES6 type modules.",
19
- "factory": "./src/migrations/update-16-8-2/update-swcrc"
20
- },
21
3
  "update-17-0-0-remove-deprecated-build-options": {
22
4
  "cli": "nx",
23
5
  "version": "17.0.2",
@@ -26,65 +8,6 @@
26
8
  }
27
9
  },
28
10
  "packageJsonUpdates": {
29
- "16.0.0": {
30
- "version": "16.0.0-beta.3",
31
- "packages": {
32
- "@swc/cli": {
33
- "version": "~0.1.62",
34
- "alwaysAddToPackageJson": false
35
- },
36
- "@swc/helpers": {
37
- "version": "~0.5.0",
38
- "alwaysAddToPackageJson": false
39
- }
40
- }
41
- },
42
- "16.1.0": {
43
- "version": "16.1.0-beta.0",
44
- "x-prompt": "Do you want to update to TypeScript v5.0?",
45
- "requires": {
46
- "typescript": ">=4.9.5 <5.0.0"
47
- },
48
- "packages": {
49
- "typescript": {
50
- "version": "~5.0.2"
51
- }
52
- }
53
- },
54
- "16.4.0": {
55
- "version": "16.4.0-beta.11",
56
- "x-prompt": "Do you want to update to TypeScript v5.1?",
57
- "requires": {
58
- "typescript": ">=5.0.0 <5.1.0"
59
- },
60
- "packages": {
61
- "typescript": {
62
- "version": "~5.1.3"
63
- }
64
- }
65
- },
66
- "16.8.2": {
67
- "version": "16.8.2-beta.0",
68
- "packages": {
69
- "@swc/core": {
70
- "version": "~1.3.85",
71
- "alwaysAddToPackageJson": false
72
- },
73
- "@swc/helpers": {
74
- "version": "~0.5.2",
75
- "alwaysAddToPackageJson": false
76
- }
77
- }
78
- },
79
- "16.9.2": {
80
- "version": "16.9.2-beta.0",
81
- "packages": {
82
- "@swc-node/register": {
83
- "version": "~1.6.7",
84
- "alwaysAddToPackageJson": false
85
- }
86
- }
87
- },
88
11
  "17.0.0": {
89
12
  "version": "17.0.0-rc.2",
90
13
  "packages": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "20.0.0-beta.5",
3
+ "version": "20.0.0-beta.7",
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,8 +39,8 @@
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": "20.0.0-beta.5",
43
- "@nx/workspace": "20.0.0-beta.5",
42
+ "@nx/devkit": "20.0.0-beta.7",
43
+ "@nx/workspace": "20.0.0-beta.7",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^2.8.0",
@@ -55,7 +55,7 @@ async function initGeneratorInternal(tree, schema) {
55
55
  process.env.NX_ADD_PLUGINS !== 'false' &&
56
56
  nxJson.useInferencePlugins !== false;
57
57
  schema.addTsPlugin ??=
58
- schema.addPlugin && process.env.NX_ADD_TS_PLUGIN === 'true';
58
+ schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';
59
59
  if (schema.addTsPlugin) {
60
60
  await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
61
61
  typecheck: [
@@ -100,6 +100,7 @@ async function libraryGeneratorInternal(tree, schema) {
100
100
  skipFormat: true,
101
101
  testEnvironment: options.testEnvironment,
102
102
  runtimeTsconfigFileName: 'tsconfig.lib.json',
103
+ compiler: options.compiler === 'swc' ? 'swc' : 'babel',
103
104
  });
104
105
  tasks.push(vitestTask);
105
106
  createOrEditViteConfig(tree, {
@@ -157,14 +158,22 @@ async function configureProject(tree, options) {
157
158
  (0, devkit_1.updateNxJson)(tree, nxJson);
158
159
  }
159
160
  if (!options.useProjectJson) {
161
+ // we create a cleaner project configuration for the package.json file
162
+ const projectConfiguration = {
163
+ root: options.projectRoot,
164
+ };
160
165
  if (options.name !== options.importPath) {
161
166
  // if the name is different than the package.json name, we need to set
162
167
  // the proper name in the configuration
163
- (0, devkit_1.updateProjectConfiguration)(tree, options.name, {
164
- name: options.name,
165
- root: options.projectRoot,
166
- });
168
+ projectConfiguration.name = options.name;
169
+ }
170
+ if (options.parsedTags?.length) {
171
+ projectConfiguration.tags = options.parsedTags;
172
+ }
173
+ if (options.publishable) {
174
+ await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
167
175
  }
176
+ (0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfiguration);
168
177
  return;
169
178
  }
170
179
  const projectConfiguration = {
@@ -471,6 +480,7 @@ async function promptWhenInteractive(questions, defaultValue) {
471
480
  return await (0, enquirer_1.prompt)(questions);
472
481
  }
473
482
  async function normalizeOptions(tree, options) {
483
+ await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
474
484
  const nxJson = (0, devkit_1.readNxJson)(tree);
475
485
  options.addPlugin ??=
476
486
  process.env.NX_ADD_PLUGINS !== 'false' &&
@@ -581,7 +591,7 @@ async function normalizeOptions(tree, options) {
581
591
  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)`);
582
592
  }
583
593
  if (options.bundler === 'none') {
584
- options.bundler = 'tsc';
594
+ throw new Error(`Publishable libraries can't be generated with "--bundler=none". Please select a valid bundler.`);
585
595
  }
586
596
  }
587
597
  // This is to preserve old behavior, buildable: false
@@ -602,7 +612,6 @@ async function normalizeOptions(tree, options) {
602
612
  projectType: 'library',
603
613
  directory: options.directory,
604
614
  importPath: options.importPath,
605
- projectNameAndRootFormat: options.projectNameAndRootFormat,
606
615
  rootProject: options.rootProject,
607
616
  });
608
617
  options.rootProject = projectRoot === '.';
@@ -10,8 +10,8 @@ export type Compiler = 'tsc' | 'swc';
10
10
  export type Bundler = 'swc' | 'tsc' | 'rollup' | 'vite' | 'esbuild' | 'none';
11
11
 
12
12
  export interface LibraryGeneratorSchema {
13
- name: string;
14
- directory?: string;
13
+ directory: string;
14
+ name?: string;
15
15
  projectNameAndRootFormat?: ProjectNameAndRootFormat;
16
16
  skipFormat?: boolean;
17
17
  tags?: string;
@@ -6,19 +6,18 @@
6
6
  "description": "Create a TypeScript Library.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "name": {
9
+ "directory": {
10
10
  "type": "string",
11
- "description": "Library name.",
11
+ "description": "A directory where the lib is placed.",
12
12
  "$default": {
13
13
  "$source": "argv",
14
14
  "index": 0
15
15
  },
16
- "x-prompt": "What name would you like to use for the library?",
17
- "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
16
+ "x-prompt": "Which directory do you want to create the library in?"
18
17
  },
19
- "directory": {
18
+ "name": {
20
19
  "type": "string",
21
- "description": "A directory where the lib is placed.",
20
+ "description": "Library name.",
22
21
  "x-priority": "important"
23
22
  },
24
23
  "bundler": {
@@ -39,11 +38,6 @@
39
38
  "enum": ["none", "jest", "vitest"],
40
39
  "x-priority": "important"
41
40
  },
42
- "projectNameAndRootFormat": {
43
- "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
44
- "type": "string",
45
- "enum": ["as-provided", "derived"]
46
- },
47
41
  "tags": {
48
42
  "type": "string",
49
43
  "description": "Add tags to the library (used for linting)."
@@ -141,6 +135,6 @@
141
135
  "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
142
136
  }
143
137
  },
144
- "required": ["name"],
138
+ "required": ["directory"],
145
139
  "examplesFile": "../../../docs/library-examples.md"
146
140
  }
@@ -45,7 +45,7 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
45
45
  options.fallbackCurrentVersionResolver = 'disk';
46
46
  }
47
47
  // Set default for updateDependents
48
- const updateDependents = options.updateDependents ?? 'never';
48
+ const updateDependents = options.updateDependents ?? 'auto';
49
49
  const updateDependentsBump = 'patch';
50
50
  // Sort the projects topologically if update dependents is enabled
51
51
  // TODO: maybe move this sorting to the command level?
@@ -395,7 +395,7 @@ To fix this you will either need to add a package.json file at that location, or
395
395
  .filter((localPackageDependency) => {
396
396
  return localPackageDependency.target === project.name;
397
397
  });
398
- const includeTransitiveDependents = updateDependents === 'auto';
398
+ const includeTransitiveDependents = updateDependents !== 'never';
399
399
  const transitiveLocalPackageDependents = [];
400
400
  if (includeTransitiveDependents) {
401
401
  for (const directDependent of allDependentProjects) {
@@ -453,7 +453,7 @@ To fix this you will either need to add a package.json file at that location, or
453
453
  logMsg += `\n${dependentProjectsOutsideCurrentBatch
454
454
  .map((dependentProject) => `${indent}- ${dependentProject.source}`)
455
455
  .join('\n')}`;
456
- logMsg += `\n${indent}=> You can adjust this behavior by setting \`version.generatorOptions.updateDependents\` to "auto"`;
456
+ logMsg += `\n${indent}=> You can adjust this behavior by removing the usage of \`version.generatorOptions.updateDependents\` with "never"`;
457
457
  logger.buffer(logMsg);
458
458
  }
459
459
  }
@@ -19,7 +19,7 @@ packages:
19
19
  proxy: npmjs
20
20
 
21
21
  # log settings
22
- logs:
22
+ log:
23
23
  type: stdout
24
24
  format: pretty
25
25
  level: warn
@@ -54,6 +54,6 @@ export interface NormalizedSwcExecutorOptions
54
54
  swcCliOptions: SwcCliOptions;
55
55
  tmpSwcrcPath: string;
56
56
  sourceRoot?: string;
57
- // TODO(v20): remove inline feature
57
+ // TODO(v21): remove inline feature
58
58
  inline?: boolean;
59
59
  }
@@ -13,7 +13,7 @@ const path_1 = require("path");
13
13
  function getSwcCmd({ swcCliOptions: { swcrcPath, destPath, stripLeadingPaths }, root, projectRoot, originalProjectRoot, sourceRoot, inline, }, watch = false) {
14
14
  const swcCLI = require.resolve('@swc/cli/bin/swc.js');
15
15
  let inputDir;
16
- // TODO(v20): remove inline feature
16
+ // TODO(v21): remove inline feature
17
17
  if (inline) {
18
18
  inputDir = originalProjectRoot.split('/')[0];
19
19
  }
@@ -1,3 +1,4 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare function isUsingTypeScriptPlugin(tree: Tree): boolean;
3
3
  export declare function isUsingTsSolutionSetup(tree: Tree): boolean;
4
+ export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: string, generatorName: string): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUsingTypeScriptPlugin = isUsingTypeScriptPlugin;
4
4
  exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
5
+ exports.assertNotUsingTsSolutionSetup = assertNotUsingTsSolutionSetup;
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  const package_manager_workspaces_1 = require("../package-manager-workspaces");
7
8
  function isUsingTypeScriptPlugin(tree) {
@@ -46,3 +47,19 @@ function isWorkspaceSetupWithTsSolution(tree) {
46
47
  }
47
48
  return true;
48
49
  }
50
+ function assertNotUsingTsSolutionSetup(tree, pluginName, generatorName) {
51
+ if (process.env.NX_IGNORE_UNSUPPORTED_TS_SETUP === 'true' ||
52
+ !isUsingTsSolutionSetup(tree)) {
53
+ return;
54
+ }
55
+ const artifactString = generatorName === 'init'
56
+ ? `"@nx/${pluginName}" plugin`
57
+ : `"@nx/${pluginName}:${generatorName}" generator`;
58
+ devkit_1.output.error({
59
+ title: `The ${artifactString} doesn't yet support the existing TypeScript setup`,
60
+ bodyLines: [
61
+ `We're working hard to support the existing TypeScript setup with the ${artifactString}. We'll soon release a new version of Nx with support for it.`,
62
+ ],
63
+ });
64
+ process.exit(1);
65
+ }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function replacePackage(tree: Tree): Promise<void>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = replacePackage;
4
- const devkit_1 = require("@nx/devkit");
5
- const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- async function replacePackage(tree) {
7
- await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/js', '@nx/js');
8
- await (0, devkit_1.formatFiles)(tree);
9
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const devkit_1 = require("@nx/devkit");
5
- const executors = new Set([
6
- '@nx/js:swc',
7
- '@nrwl/js:swc',
8
- '@nx/js:tsc',
9
- '@nrwl/js:tsc',
10
- ]);
11
- async function default_1(tree) {
12
- // use project graph to get the expanded target configurations
13
- const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
14
- for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
15
- if (projectData.projectType !== 'library') {
16
- continue;
17
- }
18
- for (const [targetName, target] of Object.entries(projectData.targets || {})) {
19
- if (!executors.has(target.executor)) {
20
- continue;
21
- }
22
- if (!target.options ||
23
- target.options.updateBuildableProjectDepsInPackageJson === undefined) {
24
- // read the project configuration to write the explicit project configuration
25
- // and avoid writing the expanded target configuration
26
- const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
27
- project.targets[targetName].options ??= {};
28
- project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
29
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
30
- }
31
- }
32
- }
33
- await (0, devkit_1.formatFiles)(tree);
34
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): Promise<void>;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = update;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- async function update(tree) {
7
- const projects = (0, devkit_1.getProjects)(tree);
8
- for (const config of projects.values()) {
9
- const swcrcPath = (0, path_1.join)(config.root, '.swcrc');
10
- if (!tree.exists(swcrcPath))
11
- continue;
12
- const json = (0, devkit_1.readJson)(tree, swcrcPath);
13
- // No longer need strict or noInterop for es6 modules
14
- // See: https://github.com/swc-project/swc/commit/7e8d72d
15
- if (json.module?.type === 'es6' &&
16
- (json.module?.strict || json.module?.noInterop)) {
17
- delete json.module.noInterop;
18
- delete json.module.strict;
19
- (0, devkit_1.writeJson)(tree, swcrcPath, json);
20
- }
21
- }
22
- await (0, devkit_1.formatFiles)(tree);
23
- }