@nx/workspace 20.0.0-canary.20241002-1d10a19 → 20.0.0-canary.20241005-75c1da3

Sign up to get free protection for your applications and to get access to all the features.
package/migrations.json CHANGED
@@ -1,49 +1,6 @@
1
1
  {
2
- "generators": {
3
- "update-16-0-0-add-nx-packages": {
4
- "cli": "nx",
5
- "version": "16.0.0-beta.1",
6
- "description": "Replace @nrwl/workspace with @nx/workspace",
7
- "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
8
- },
9
- "16-0-0-move-workspace-generators-into-local-plugin": {
10
- "version": "16.0.0-beta.4",
11
- "description": "Generates a plugin called 'workspace-plugin' containing your workspace generators.",
12
- "cli": "nx",
13
- "implementation": "./src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin"
14
- },
15
- "16-0-0-fix-invalid-babelrc": {
16
- "version": "16.0.0-beta.9",
17
- "description": "Fix .babelrc presets if it contains an invalid entry for @nx/web/babel.",
18
- "cli": "nx",
19
- "implementation": "./src/migrations/update-16-0-0/fix-invalid-babelrc"
20
- }
21
- },
2
+ "generators": {},
22
3
  "packageJsonUpdates": {
23
- "16.1.0": {
24
- "version": "16.1.0-beta.0",
25
- "x-prompt": "Do you want to update to TypeScript v5.0?",
26
- "requires": {
27
- "typescript": ">=4.9.5 <5.0.0"
28
- },
29
- "packages": {
30
- "typescript": {
31
- "version": "~5.0.2"
32
- }
33
- }
34
- },
35
- "16.4.0": {
36
- "version": "16.4.0-beta.11",
37
- "x-prompt": "Do you want to update to TypeScript v5.1?",
38
- "requires": {
39
- "typescript": ">=5.0.0 <5.1.0"
40
- },
41
- "packages": {
42
- "typescript": {
43
- "version": "~5.1.3"
44
- }
45
- }
46
- },
47
4
  "17.1.0": {
48
5
  "version": "17.1.0-beta.4",
49
6
  "x-prompt": "Do you want to update to TypeScript v5.2?",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/workspace",
3
- "version": "20.0.0-canary.20241002-1d10a19",
3
+ "version": "20.0.0-canary.20241005-75c1da3",
4
4
  "private": false,
5
5
  "description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
6
6
  "repository": {
@@ -38,12 +38,12 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@nx/devkit": "20.0.0-canary.20241002-1d10a19",
41
+ "@nx/devkit": "20.0.0-canary.20241005-75c1da3",
42
42
  "chalk": "^4.1.0",
43
43
  "enquirer": "~2.3.6",
44
44
  "tslib": "^2.3.0",
45
45
  "yargs-parser": "21.1.1",
46
- "nx": "20.0.0-canary.20241002-1d10a19"
46
+ "nx": "20.0.0-canary.20241005-75c1da3"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -1,8 +1,6 @@
1
1
  {
2
- "recommendations": [
3
- <% if(cliCommand === 'ng') { %>
4
- "angular.ng-template",<% }
5
- %>
2
+ "recommendations": [<% if(cliCommand === 'ng') { %>
3
+ "angular.ng-template",<% } %>
6
4
  "nrwl.angular-console"
7
5
  ]
8
6
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "<%= formattedNames.fileName %>",
2
+ "name": "@<%= formattedNames.fileName %>/source",
3
3
  "version": "0.0.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
@@ -212,7 +212,7 @@ function createFiles(tree, options) {
212
212
  ? './files-root-app'
213
213
  : (options.preset === presets_1.Preset.TS &&
214
214
  process.env.NX_ADD_PLUGINS !== 'false' &&
215
- process.env.NX_ADD_TS_PLUGIN === 'true') ||
215
+ process.env.NX_ADD_TS_PLUGIN !== 'false') ||
216
216
  options.preset === presets_1.Preset.NPM
217
217
  ? './files-package-based-repo'
218
218
  : './files-integrated-repo';
@@ -242,7 +242,7 @@ async function createReadme(tree, { name, appName, directory, preset, nxCloud },
242
242
  isJsStandalone: preset === presets_1.Preset.TsStandalone,
243
243
  isTsPreset: preset === presets_1.Preset.TS,
244
244
  isUsingNewTsSolutionSetup: process.env.NX_ADD_PLUGINS !== 'false' &&
245
- process.env.NX_ADD_TS_PLUGIN === 'true',
245
+ process.env.NX_ADD_TS_PLUGIN !== 'false',
246
246
  isEmptyRepo: !appName,
247
247
  appName,
248
248
  generateAppCmd: presetInfo.generateAppCmd,
@@ -325,7 +325,7 @@ function setUpWorkspacesInPackageJson(tree, options) {
325
325
  if (options.preset === presets_1.Preset.NPM ||
326
326
  (options.preset === presets_1.Preset.TS &&
327
327
  process.env.NX_ADD_PLUGINS !== 'false' &&
328
- process.env.NX_ADD_TS_PLUGIN === 'true')) {
328
+ process.env.NX_ADD_TS_PLUGIN !== 'false')) {
329
329
  if (options.packageManager === 'pnpm') {
330
330
  tree.write((0, path_1.join)(options.directory, 'pnpm-workspace.yaml'), `packages:
331
331
  - 'packages/*'
@@ -258,7 +258,7 @@ async function createPreset(tree, options) {
258
258
  return initGenerator(tree, {
259
259
  formatter: options.formatter,
260
260
  addTsPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
261
- process.env.NX_ADD_TS_PLUGIN === 'true',
261
+ process.env.NX_ADD_TS_PLUGIN !== 'false',
262
262
  });
263
263
  }
264
264
  else if (options.preset === presets_1.Preset.TsStandalone) {
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): void;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = update;
4
- const devkit_1 = require("@nx/devkit");
5
- function update(tree) {
6
- const projects = (0, devkit_1.getProjects)(tree);
7
- const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
8
- // In case user installed as prod dep.
9
- const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
10
- // If web package is installed, skip update.
11
- if (deps['@nrwl/web'] || deps['@nx/web']) {
12
- return;
13
- }
14
- projects.forEach((config, name) => {
15
- const babelRcPath = (0, devkit_1.joinPathFragments)(config.root, '.babelrc');
16
- if (!tree.exists(babelRcPath))
17
- return;
18
- const babelRc = (0, devkit_1.readJson)(tree, babelRcPath);
19
- const nrwlWebBabelPresetIdx = babelRc.presets?.findIndex((p) =>
20
- // Babel preset could be specified as a string or a tuple with options.
21
- // Account for rescope migration running before or after this one.
22
- Array.isArray(p)
23
- ? p[0] === '@nrwl/web/babel' || p[0] === '@nx/web/babel'
24
- : p === '@nrwl/web/babel' || p === '@nx/web/babel');
25
- if (nrwlWebBabelPresetIdx === undefined || nrwlWebBabelPresetIdx === -1) {
26
- return;
27
- }
28
- if (deps['@nrwl/js'] || deps['@nx/js']) {
29
- // If JS plugin is installed, then rename to @nx/js/babel.
30
- const found = babelRc.presets[nrwlWebBabelPresetIdx];
31
- babelRc.presets[nrwlWebBabelPresetIdx] = Array.isArray(found)
32
- ? ['@nx/js/babel', found[1]]
33
- : '@nx/js/babel';
34
- }
35
- else {
36
- // Otherwise, remove from config.
37
- babelRc.presets.splice(nrwlWebBabelPresetIdx, 1);
38
- }
39
- (0, devkit_1.writeJson)(tree, babelRcPath, babelRc);
40
- });
41
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<() => void>;
@@ -1,186 +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
- // nx-ignore-next-line
6
- const path = require("path");
7
- const move_1 = require("../../generators/move/move");
8
- const versions_1 = require("../../utils/versions");
9
- const path_1 = require("path");
10
- const get_import_path_1 = require("../../utilities/get-import-path");
11
- const PROJECT_NAME = 'workspace-plugin';
12
- const DESTINATION = `tools/${PROJECT_NAME}`;
13
- async function default_1(tree) {
14
- if (!tree.exists('tools/generators')) {
15
- return;
16
- }
17
- const tasks = [];
18
- if (hasWorkspaceGenerators(tree)) {
19
- tasks.push(...(await moveWorkspaceGeneratorsToLocalPlugin(tree)));
20
- }
21
- removeToolsGeneratorsIfEmpty(tree);
22
- await (0, devkit_1.formatFiles)(tree);
23
- return () => {
24
- for (const task of tasks) {
25
- task();
26
- }
27
- };
28
- }
29
- async function moveWorkspaceGeneratorsToLocalPlugin(tree) {
30
- const tasks = [];
31
- let project = (0, devkit_1.getProjects)(tree).get(PROJECT_NAME);
32
- if (!project) {
33
- await createNewPlugin(tree);
34
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
35
- '@nx/plugin': versions_1.nxVersion,
36
- }));
37
- project = (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME);
38
- }
39
- updateExistingPlugin(tree, project);
40
- return tasks;
41
- }
42
- function hasWorkspaceGenerators(tree) {
43
- const children = tree.children('tools/generators');
44
- return (children.length > 0 &&
45
- !(children.length === 1 && children[0] === '.gitkeep'));
46
- }
47
- function removeToolsGeneratorsIfEmpty(tree) {
48
- if (!hasWorkspaceGenerators(tree)) {
49
- tree.delete('tools/generators');
50
- }
51
- }
52
- // Inspired by packages/nx/src/command-line/workspace-generators.ts
53
- function collectAndMoveGenerators(tree, destinationProjectRoot) {
54
- const generators = {};
55
- const generatorsDir = 'tools/generators';
56
- const destinationDir = (0, devkit_1.joinPathFragments)(destinationProjectRoot, 'src', 'generators');
57
- for (const c of tree.children('tools/generators')) {
58
- const childDir = path.join(generatorsDir, c);
59
- const schemaPath = (0, devkit_1.joinPathFragments)(childDir, 'schema.json');
60
- if (tree.exists(schemaPath)) {
61
- const schema = (0, devkit_1.readJson)(tree, schemaPath);
62
- generators[c] = {
63
- implementation: `./src/generators/${c}`,
64
- schema: `./src/generators/${(0, devkit_1.joinPathFragments)(c, 'schema.json')}`,
65
- description: schema.description ?? `Generator ${c}`,
66
- };
67
- moveFilesInDirectory(tree, childDir, (0, devkit_1.joinPathFragments)(destinationDir, c));
68
- }
69
- }
70
- return generators;
71
- }
72
- function moveFilesInDirectory(tree, source, destination) {
73
- const relative = path_1.posix.relative(source, path_1.posix.dirname(destination));
74
- if (!relative.startsWith('../')) {
75
- // If the destination is in the same directory or a subdirectory of the source
76
- // we can just move the files. If it is not, we need to update the relative imports.
77
- return;
78
- }
79
- let offsetLevel = 0;
80
- const pathParts = relative.split('/');
81
- for (const part of pathParts) {
82
- if (part === '..') {
83
- offsetLevel++;
84
- }
85
- else {
86
- break;
87
- }
88
- }
89
- for (const c of tree.children(source)) {
90
- if (!tree.isFile(c)) {
91
- moveFilesInDirectory(tree, (0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
92
- }
93
- tree.rename((0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
94
- // If its a TS file we can update relative imports with find + replace
95
- // This could be done with AST, but since we are only looking at relative
96
- // imports its easy to do via string replace. We replace any strings starting
97
- // with a relative path outside of their own directory.
98
- if (c.endsWith('.ts')) {
99
- let content = tree.read((0, devkit_1.joinPathFragments)(destination, c)).toString();
100
- // +2 is a bit of a magic number here - represents extra directory levels in a normal
101
- // plugin structure compared to the workspace-generator layout
102
- const extraDirectoriesInPluginStructure = 2;
103
- content = content.replace(new RegExp(`'` + `\.\.\/`.repeat(offsetLevel), 'g'), "'" + '../'.repeat(offsetLevel + extraDirectoriesInPluginStructure));
104
- content = content.replace(new RegExp(`"` + `\.\.\/`.repeat(offsetLevel), 'g'), '"' + '../'.repeat(offsetLevel + extraDirectoriesInPluginStructure));
105
- // We write it back in the same spot, since it is moved as if it was a regular file after this
106
- tree.write((0, devkit_1.joinPathFragments)(source, c), content);
107
- }
108
- tree.rename((0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
109
- }
110
- }
111
- async function createNewPlugin(tree) {
112
- (0, devkit_1.ensurePackage)('@nx/plugin', versions_1.nxVersion);
113
- const { pluginGenerator } =
114
- // nx-ignore-next-line
115
- require('@nx/plugin/src/generators/plugin/plugin');
116
- // nx-ignore-next-line
117
- const { Linter } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
118
- const npmScope = (0, get_import_path_1.getNpmScope)(tree);
119
- const importPath = npmScope ? `@${npmScope}/${PROJECT_NAME}` : PROJECT_NAME;
120
- await pluginGenerator(tree, {
121
- minimal: true,
122
- directory: PROJECT_NAME,
123
- importPath: importPath,
124
- skipTsConfig: false,
125
- compiler: 'tsc',
126
- linter: Linter.EsLint,
127
- skipFormat: true,
128
- skipLintChecks: false,
129
- unitTestRunner: 'jest',
130
- e2eTestRunner: 'none',
131
- publishable: false,
132
- });
133
- await getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
134
- await moveGeneratedPlugin(tree, DESTINATION, importPath);
135
- }
136
- function moveGeneratedPlugin(tree, destination, importPath) {
137
- const config = (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME);
138
- if (config.root !== DESTINATION) {
139
- return (0, move_1.moveGenerator)(tree, {
140
- destination,
141
- projectName: PROJECT_NAME,
142
- newProjectName: PROJECT_NAME,
143
- updateImportPath: true,
144
- importPath: importPath,
145
- });
146
- }
147
- }
148
- function updateExistingPlugin(tree, project) {
149
- const packageJson = (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
150
- const defaultGeneratorsPath = (0, devkit_1.joinPathFragments)(project.root, 'generators.json');
151
- let generatorsJsonPath = packageJson.generators ||
152
- packageJson.schematics ||
153
- tree.exists(defaultGeneratorsPath)
154
- ? defaultGeneratorsPath
155
- : null;
156
- if (!generatorsJsonPath) {
157
- getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
158
- generatorsJsonPath = defaultGeneratorsPath;
159
- }
160
- (0, devkit_1.updateJson)(tree, generatorsJsonPath, (json) => {
161
- const generators = collectAndMoveGenerators(tree, project.root);
162
- json.generators ??= {};
163
- for (const generator in generators) {
164
- if (json.generators[generator]) {
165
- devkit_1.output.warn({
166
- title: `Generator ${generator} already exists in ${project.name}`,
167
- bodyLines: [
168
- 'Since you have a generator with the same name in your plugin, the generator from workspace-generators has been discarded.',
169
- ],
170
- });
171
- }
172
- else {
173
- json.generators[generator] = generators[generator];
174
- }
175
- }
176
- return json;
177
- });
178
- }
179
- function getCreateGeneratorsJson() {
180
- // We cant use `as typeof import('@nx/plugin/src/generators/generator/generator');` here
181
- // because it will cause a typescript error at build time.
182
- const { createGeneratorsJson } =
183
- // nx-ignore-next-line
184
- require('@nx/plugin/src/generators/generator/generator');
185
- return createGeneratorsJson;
186
- }
@@ -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/workspace', '@nx/workspace');
8
- await (0, devkit_1.formatFiles)(tree);
9
- }