@nx/workspace 20.0.0-canary.20241001-8fa7065 → 20.0.0-canary.20241003-84a5c7a

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/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.20241001-8fa7065",
3
+ "version": "20.0.0-canary.20241003-84a5c7a",
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.20241001-8fa7065",
41
+ "@nx/devkit": "20.0.0-canary.20241003-84a5c7a",
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.20241001-8fa7065"
46
+ "nx": "20.0.0-canary.20241003-84a5c7a"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -45,7 +45,6 @@ async function monorepoGenerator(tree, options) {
45
45
  ? (0, devkit_1.joinPathFragments)(appsDir, project.root === '.' ? project.name : project.root)
46
46
  : (0, devkit_1.joinPathFragments)(libsDir, project.root === '.' ? project.name : project.root),
47
47
  updateImportPath: project.projectType === 'library',
48
- projectNameAndRootFormat: 'as-provided',
49
48
  });
50
49
  }
51
50
  }
@@ -1,5 +1,3 @@
1
- import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
-
3
1
  export interface Schema {
4
2
  projectName: string;
5
3
  destination: string;
@@ -7,7 +5,6 @@ export interface Schema {
7
5
  updateImportPath: boolean;
8
6
  skipFormat?: boolean;
9
7
  newProjectName?: string;
10
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
8
  }
12
9
 
13
10
  export interface NormalizedSchema extends Schema {
@@ -33,11 +33,6 @@
33
33
  "index": 0
34
34
  }
35
35
  },
36
- "projectNameAndRootFormat": {
37
- "description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
38
- "type": "string",
39
- "enum": ["as-provided", "derived"]
40
- },
41
36
  "importPath": {
42
37
  "type": "string",
43
38
  "description": "The new import path to use in the `tsconfig.base.json`."
@@ -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
  }
@@ -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/*'
@@ -1,8 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
- import { type ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
3
2
  export interface ProjectOptions {
4
- name: string;
5
- directory?: string;
6
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
3
+ directory: string;
4
+ name?: string;
7
5
  }
8
6
  export declare function npmPackageGenerator(tree: Tree, _options: ProjectOptions): Promise<void>;
@@ -6,11 +6,11 @@ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project
6
6
  const path_1 = require("path");
7
7
  const get_import_path_1 = require("../../utilities/get-import-path");
8
8
  async function normalizeOptions(tree, options) {
9
+ await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
9
10
  const { projectName, projectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
10
11
  name: options.name,
11
12
  projectType: 'library',
12
13
  directory: options.directory,
13
- projectNameAndRootFormat: options.projectNameAndRootFormat,
14
14
  });
15
15
  return {
16
16
  ...options,
@@ -6,26 +6,20 @@
6
6
  "cli": "nx",
7
7
  "type": "object",
8
8
  "properties": {
9
- "name": {
9
+ "directory": {
10
10
  "type": "string",
11
- "description": "Package name.",
11
+ "description": "A directory where the package is placed.",
12
+ "alias": "dir",
12
13
  "$default": {
13
14
  "$source": "argv",
14
15
  "index": 0
15
16
  },
16
- "x-prompt": "What name of your npm package?",
17
- "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
18
- },
19
- "directory": {
20
- "type": "string",
21
- "description": "A directory where the package is placed.",
22
- "alias": "dir"
17
+ "x-prompt": "Which directory do you want to create the package in?"
23
18
  },
24
- "projectNameAndRootFormat": {
25
- "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`).",
19
+ "name": {
26
20
  "type": "string",
27
- "enum": ["as-provided", "derived"]
21
+ "description": "Package name."
28
22
  }
29
23
  },
30
- "required": ["name"]
24
+ "required": ["directory"]
31
25
  }
@@ -25,7 +25,6 @@ async function createPreset(tree, options) {
25
25
  return angularApplicationGenerator(tree, {
26
26
  name: options.name,
27
27
  directory: (0, path_1.join)('apps', options.name),
28
- projectNameAndRootFormat: 'as-provided',
29
28
  style: options.style,
30
29
  linter: options.linter,
31
30
  standalone: options.standaloneApi,
@@ -42,7 +41,6 @@ async function createPreset(tree, options) {
42
41
  return angularApplicationGenerator(tree, {
43
42
  name: options.name,
44
43
  directory: '.',
45
- projectNameAndRootFormat: 'as-provided',
46
44
  style: options.style,
47
45
  linter: options.linter,
48
46
  routing: options.routing,
@@ -61,7 +59,6 @@ async function createPreset(tree, options) {
61
59
  return reactApplicationGenerator(tree, {
62
60
  name: options.name,
63
61
  directory: (0, path_1.join)('apps', options.name),
64
- projectNameAndRootFormat: 'as-provided',
65
62
  style: options.style,
66
63
  linter: options.linter,
67
64
  bundler: options.bundler ?? 'webpack',
@@ -76,7 +73,6 @@ async function createPreset(tree, options) {
76
73
  return reactApplicationGenerator(tree, {
77
74
  name: options.name,
78
75
  directory: '.',
79
- projectNameAndRootFormat: 'as-provided',
80
76
  style: options.style,
81
77
  linter: options.linter,
82
78
  rootProject: true,
@@ -93,7 +89,6 @@ async function createPreset(tree, options) {
93
89
  return remixApplicationGenerator(tree, {
94
90
  name: options.name,
95
91
  directory: (0, path_1.join)('apps', options.name),
96
- projectNameAndRootFormat: 'as-provided',
97
92
  linter: options.linter,
98
93
  e2eTestRunner: options.e2eTestRunner ?? 'playwright',
99
94
  unitTestRunner: 'vitest',
@@ -107,7 +102,6 @@ async function createPreset(tree, options) {
107
102
  return remixApplicationGenerator(tree, {
108
103
  name: options.name,
109
104
  directory: '.',
110
- projectNameAndRootFormat: 'as-provided',
111
105
  linter: options.linter,
112
106
  e2eTestRunner: options.e2eTestRunner ?? 'playwright',
113
107
  rootProject: true,
@@ -122,7 +116,6 @@ async function createPreset(tree, options) {
122
116
  return vueApplicationGenerator(tree, {
123
117
  name: options.name,
124
118
  directory: (0, path_1.join)('apps', options.name),
125
- projectNameAndRootFormat: 'as-provided',
126
119
  style: options.style,
127
120
  linter: options.linter,
128
121
  e2eTestRunner: options.e2eTestRunner ?? 'playwright',
@@ -136,7 +129,6 @@ async function createPreset(tree, options) {
136
129
  return vueApplicationGenerator(tree, {
137
130
  name: options.name,
138
131
  directory: '.',
139
- projectNameAndRootFormat: 'as-provided',
140
132
  style: options.style,
141
133
  linter: options.linter,
142
134
  rootProject: true,
@@ -152,7 +144,6 @@ async function createPreset(tree, options) {
152
144
  return nuxtApplicationGenerator(tree, {
153
145
  name: options.name,
154
146
  directory: (0, path_1.join)('apps', options.name),
155
- projectNameAndRootFormat: 'as-provided',
156
147
  style: options.style,
157
148
  linter: options.linter,
158
149
  e2eTestRunner: options.e2eTestRunner ?? 'playwright',
@@ -166,7 +157,6 @@ async function createPreset(tree, options) {
166
157
  return nuxtApplicationGenerator(tree, {
167
158
  name: options.name,
168
159
  directory: '.',
169
- projectNameAndRootFormat: 'as-provided',
170
160
  style: options.style,
171
161
  linter: options.linter,
172
162
  rootProject: true,
@@ -182,7 +172,6 @@ async function createPreset(tree, options) {
182
172
  return nextApplicationGenerator(tree, {
183
173
  name: options.name,
184
174
  directory: (0, path_1.join)('apps', options.name),
185
- projectNameAndRootFormat: 'as-provided',
186
175
  style: options.style,
187
176
  linter: options.linter,
188
177
  appDir: options.nextAppDir,
@@ -197,7 +186,6 @@ async function createPreset(tree, options) {
197
186
  return nextApplicationGenerator(tree, {
198
187
  name: options.name,
199
188
  directory: '.',
200
- projectNameAndRootFormat: 'as-provided',
201
189
  style: options.style,
202
190
  linter: options.linter,
203
191
  appDir: options.nextAppDir,
@@ -213,7 +201,6 @@ async function createPreset(tree, options) {
213
201
  return webApplicationGenerator(tree, {
214
202
  name: options.name,
215
203
  directory: (0, path_1.join)('apps', options.name),
216
- projectNameAndRootFormat: 'as-provided',
217
204
  style: options.style,
218
205
  linter: options.linter,
219
206
  bundler: 'vite',
@@ -228,7 +215,6 @@ async function createPreset(tree, options) {
228
215
  return nestApplicationGenerator(tree, {
229
216
  name: options.name,
230
217
  directory: (0, path_1.join)('apps', options.name),
231
- projectNameAndRootFormat: 'as-provided',
232
218
  linter: options.linter,
233
219
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
234
220
  addPlugin,
@@ -239,7 +225,6 @@ async function createPreset(tree, options) {
239
225
  return expressApplicationGenerator(tree, {
240
226
  name: options.name,
241
227
  directory: (0, path_1.join)('apps', options.name),
242
- projectNameAndRootFormat: 'as-provided',
243
228
  linter: options.linter,
244
229
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
245
230
  addPlugin,
@@ -251,7 +236,6 @@ async function createPreset(tree, options) {
251
236
  return reactNativeApplicationGenerator(tree, {
252
237
  name: options.name,
253
238
  directory: (0, path_1.join)('apps', options.name),
254
- projectNameAndRootFormat: 'as-provided',
255
239
  linter: options.linter,
256
240
  e2eTestRunner: options.e2eTestRunner ?? 'detox',
257
241
  addPlugin,
@@ -263,7 +247,6 @@ async function createPreset(tree, options) {
263
247
  return expoApplicationGenerator(tree, {
264
248
  name: options.name,
265
249
  directory: (0, path_1.join)('apps', options.name),
266
- projectNameAndRootFormat: 'as-provided',
267
250
  linter: options.linter,
268
251
  e2eTestRunner: options.e2eTestRunner ?? 'detox',
269
252
  addPlugin,
@@ -275,7 +258,7 @@ async function createPreset(tree, options) {
275
258
  return initGenerator(tree, {
276
259
  formatter: options.formatter,
277
260
  addTsPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
278
- process.env.NX_ADD_TS_PLUGIN === 'true',
261
+ process.env.NX_ADD_TS_PLUGIN !== 'false',
279
262
  });
280
263
  }
281
264
  else if (options.preset === presets_1.Preset.TsStandalone) {
@@ -283,7 +266,6 @@ async function createPreset(tree, options) {
283
266
  return libraryGenerator(tree, {
284
267
  name: options.name,
285
268
  directory: '.',
286
- projectNameAndRootFormat: 'as-provided',
287
269
  bundler: 'tsc',
288
270
  unitTestRunner: 'vitest',
289
271
  testEnvironment: 'node',
@@ -300,7 +282,6 @@ async function createPreset(tree, options) {
300
282
  bundler,
301
283
  name: options.name,
302
284
  directory: '.',
303
- projectNameAndRootFormat: 'as-provided',
304
285
  linter: options.linter,
305
286
  standaloneConfig: options.standaloneConfig,
306
287
  framework: options.framework,
@@ -318,7 +299,6 @@ async function createPreset(tree, options) {
318
299
  bundler,
319
300
  name: options.name,
320
301
  directory: (0, path_1.join)('apps', options.name),
321
- projectNameAndRootFormat: 'as-provided',
322
302
  linter: options.linter,
323
303
  framework: options.framework,
324
304
  docker: options.docker,
@@ -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,187 +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
- name: 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
- projectNameAndRootFormat: 'as-provided',
146
- });
147
- }
148
- }
149
- function updateExistingPlugin(tree, project) {
150
- const packageJson = (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
151
- const defaultGeneratorsPath = (0, devkit_1.joinPathFragments)(project.root, 'generators.json');
152
- let generatorsJsonPath = packageJson.generators ||
153
- packageJson.schematics ||
154
- tree.exists(defaultGeneratorsPath)
155
- ? defaultGeneratorsPath
156
- : null;
157
- if (!generatorsJsonPath) {
158
- getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
159
- generatorsJsonPath = defaultGeneratorsPath;
160
- }
161
- (0, devkit_1.updateJson)(tree, generatorsJsonPath, (json) => {
162
- const generators = collectAndMoveGenerators(tree, project.root);
163
- json.generators ??= {};
164
- for (const generator in generators) {
165
- if (json.generators[generator]) {
166
- devkit_1.output.warn({
167
- title: `Generator ${generator} already exists in ${project.name}`,
168
- bodyLines: [
169
- 'Since you have a generator with the same name in your plugin, the generator from workspace-generators has been discarded.',
170
- ],
171
- });
172
- }
173
- else {
174
- json.generators[generator] = generators[generator];
175
- }
176
- }
177
- return json;
178
- });
179
- }
180
- function getCreateGeneratorsJson() {
181
- // We cant use `as typeof import('@nx/plugin/src/generators/generator/generator');` here
182
- // because it will cause a typescript error at build time.
183
- const { createGeneratorsJson } =
184
- // nx-ignore-next-line
185
- require('@nx/plugin/src/generators/generator/generator');
186
- return createGeneratorsJson;
187
- }
@@ -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
- }