@nx/workspace 0.0.0-pr-3-ec41644 → 0.0.0-pr-29993-91cbae3

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/workspace",
3
- "version": "0.0.0-pr-3-ec41644",
3
+ "version": "0.0.0-pr-29993-91cbae3",
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,14 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@nx/devkit": "0.0.0-pr-3-ec41644",
41
+ "@nx/devkit": "0.0.0-pr-29993-91cbae3",
42
+ "@zkochan/js-yaml": "0.0.7",
42
43
  "chalk": "^4.1.0",
43
44
  "enquirer": "~2.3.6",
45
+ "picomatch": "4.0.2",
44
46
  "tslib": "^2.3.0",
45
47
  "yargs-parser": "21.1.1",
46
- "nx": "0.0.0-pr-3-ec41644"
48
+ "nx": "0.0.0-pr-29993-91cbae3"
47
49
  },
48
50
  "publishConfig": {
49
51
  "access": "public"
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const default_base_1 = require("../../utilities/default-base");
6
6
  const path_1 = require("path");
7
7
  const nx_cloud_utils_1 = require("nx/src/utils/nx-cloud-utils");
8
+ const ts_solution_setup_1 = require("../../utilities/typescript/ts-solution-setup");
8
9
  async function ciWorkflowGenerator(tree, schema) {
9
10
  const ci = schema.ci;
10
11
  const options = normalizeOptions(schema, tree);
@@ -35,6 +36,7 @@ function normalizeOptions(options, tree) {
35
36
  const hasCypress = allDependencies['@nx/cypress'];
36
37
  const hasPlaywright = allDependencies['@nx/playwright'];
37
38
  const hasE2E = hasCypress || hasPlaywright;
39
+ const hasTypecheck = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
38
40
  const connectedToCloud = (0, nx_cloud_utils_1.isNxCloudUsed)((0, devkit_1.readJson)(tree, 'nx.json'));
39
41
  return {
40
42
  workflowName,
@@ -47,6 +49,7 @@ function normalizeOptions(options, tree) {
47
49
  hasCypress,
48
50
  hasE2E,
49
51
  hasPlaywright,
52
+ hasTypecheck,
50
53
  nxCloudHost,
51
54
  tmpl: '',
52
55
  connectedToCloud,
@@ -68,4 +68,4 @@ jobs:
68
68
  # - script: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
69
69
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
70
70
  # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
71
- - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build<% if(hasE2E){ %> e2e<% } %>
71
+ - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
@@ -33,7 +33,7 @@ pipelines:
33
33
  # <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
34
34
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
35
35
  # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
36
- - <%= packageManagerPrefix %> nx affected --base=origin/<%= mainBranch %> -t lint test build<% if(hasE2E){ %> e2e<% } %>
36
+ - <%= packageManagerPrefix %> nx affected --base=origin/<%= mainBranch %> -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
37
37
 
38
38
  branches:
39
39
  main:
@@ -59,4 +59,4 @@ pipelines:
59
59
  # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
60
60
  # - <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
61
61
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
62
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %> --base=HEAD~1
62
+ - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e-ci<% } %> --base=HEAD~1
@@ -37,7 +37,7 @@ jobs:
37
37
  # - run: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
38
38
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
39
39
  # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
40
- - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e<% } %>
40
+ - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
41
41
 
42
42
  workflows:
43
43
  version: 2
@@ -50,4 +50,4 @@ jobs:
50
50
  # - run: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
51
51
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
52
52
  # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
53
- - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e<% } %>
53
+ - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
@@ -31,4 +31,4 @@ variables:
31
31
  # - <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
32
32
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
33
33
  # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
34
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e<% } %>
34
+ - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
@@ -48,6 +48,12 @@ function createProjectConfigurationInNewDestination(tree, schema, projectConfig)
48
48
  if (isRootProject && projectConfig.sourceRoot) {
49
49
  newProject.sourceRoot = (0, devkit_1.joinPathFragments)(schema.relativeToRootDestination, projectConfig.sourceRoot);
50
50
  }
51
- // Create a new project with the root replaced
52
- (0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
51
+ if (schema.isNxConfiguredInPackageJson) {
52
+ // Update the existing project configuration in the package.json
53
+ (0, devkit_1.updateProjectConfiguration)(tree, schema.newProjectName, newProject);
54
+ }
55
+ else {
56
+ // Create a new project with the root replaced
57
+ (0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
58
+ }
53
59
  }
@@ -1,23 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSchema = normalizeSchema;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const get_import_path_1 = require("../../../utilities/get-import-path");
5
6
  const utils_1 = require("./utils");
6
7
  const ts_solution_setup_1 = require("../../../utils/ts-solution-setup");
7
8
  async function normalizeSchema(tree, schema, projectConfiguration) {
8
9
  const { destination, newProjectName, importPath } = await determineProjectNameAndRootOptions(tree, schema, projectConfiguration);
10
+ const isNxConfiguredInPackageJson = !tree.exists((0, devkit_1.joinPathFragments)(projectConfiguration.root, 'project.json'));
9
11
  return {
10
12
  ...schema,
11
13
  destination: (0, utils_1.normalizePathSlashes)(schema.destination),
12
14
  importPath,
13
15
  newProjectName,
14
16
  relativeToRootDestination: destination,
17
+ isNxConfiguredInPackageJson,
15
18
  };
16
19
  }
17
20
  async function determineProjectNameAndRootOptions(tree, options, projectConfiguration) {
18
21
  validateName(tree, options.newProjectName, projectConfiguration);
19
- const projectNameAndRootOptions = getProjectNameAndRootOptions(tree, options, projectConfiguration);
20
- return projectNameAndRootOptions;
22
+ let destination = (0, utils_1.normalizePathSlashes)(options.destination);
23
+ if (options.newProjectName &&
24
+ options.newProjectName.includes('/') &&
25
+ !options.newProjectName.startsWith('@')) {
26
+ throw new Error(`You can't specify a new project name with a directory path (${options.newProjectName}). ` +
27
+ `Please provide a valid name without path segments and the full destination with the "--destination" option.`);
28
+ }
29
+ const newProjectName = options.newProjectName ?? options.projectName;
30
+ if (projectConfiguration.projectType !== 'library') {
31
+ return { destination, newProjectName };
32
+ }
33
+ let importPath = options.importPath;
34
+ if (importPath) {
35
+ return { destination, newProjectName, importPath };
36
+ }
37
+ if (options.newProjectName?.startsWith('@')) {
38
+ // keep the existing import path if the name didn't change
39
+ importPath =
40
+ options.newProjectName && options.projectName !== options.newProjectName
41
+ ? newProjectName
42
+ : undefined;
43
+ }
44
+ else if (options.newProjectName) {
45
+ const npmScope = (0, get_import_path_1.getNpmScope)(tree);
46
+ importPath = npmScope
47
+ ? `${npmScope === '@' ? '' : '@'}${npmScope}/${newProjectName}`
48
+ : newProjectName;
49
+ }
50
+ return { destination, newProjectName, importPath };
21
51
  }
22
52
  function validateName(tree, name, projectConfiguration) {
23
53
  if (!name) {
@@ -49,39 +79,3 @@ function validateName(tree, name, projectConfiguration) {
49
79
  }
50
80
  }
51
81
  }
52
- function getProjectNameAndRootOptions(tree, options, projectConfiguration) {
53
- let destination = (0, utils_1.normalizePathSlashes)(options.destination);
54
- if (options.newProjectName &&
55
- options.newProjectName.includes('/') &&
56
- !options.newProjectName.startsWith('@')) {
57
- throw new Error(`You can't specify a new project name with a directory path (${options.newProjectName}). ` +
58
- `Please provide a valid name without path segments and the full destination with the "--destination" option.`);
59
- }
60
- const asProvidedOptions = getAsProvidedOptions(tree, { ...options, destination }, projectConfiguration);
61
- return asProvidedOptions;
62
- }
63
- function getAsProvidedOptions(tree, options, projectConfiguration) {
64
- const newProjectName = options.newProjectName ?? options.projectName;
65
- const destination = options.destination;
66
- if (projectConfiguration.projectType !== 'library') {
67
- return { destination, newProjectName };
68
- }
69
- let importPath = options.importPath;
70
- if (importPath) {
71
- return { destination, newProjectName, importPath };
72
- }
73
- if (options.newProjectName?.startsWith('@')) {
74
- // keep the existing import path if the name didn't change
75
- importPath =
76
- options.newProjectName && options.projectName !== options.newProjectName
77
- ? newProjectName
78
- : undefined;
79
- }
80
- else if (options.newProjectName) {
81
- const npmScope = (0, get_import_path_1.getNpmScope)(tree);
82
- importPath = npmScope
83
- ? `${npmScope === '@' ? '' : '@'}${npmScope}/${newProjectName}`
84
- : newProjectName;
85
- }
86
- return { destination, newProjectName, importPath };
87
- }
@@ -1,4 +1,4 @@
1
- import { Tree } from '@nx/devkit';
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
- export declare function moveGenerator(tree: Tree, rawSchema: Schema): Promise<void>;
3
+ export declare function moveGenerator(tree: Tree, rawSchema: Schema): Promise<GeneratorCallback>;
4
4
  export default moveGenerator;
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.moveGenerator = moveGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const package_manager_workspaces_1 = require("../../utilities/package-manager-workspaces");
6
+ const ts_solution_setup_1 = require("../../utilities/typescript/ts-solution-setup");
5
7
  const check_destination_1 = require("./lib/check-destination");
6
8
  const create_project_configuration_in_new_destination_1 = require("./lib/create-project-configuration-in-new-destination");
9
+ const extract_base_configs_1 = require("./lib/extract-base-configs");
7
10
  const move_project_files_1 = require("./lib/move-project-files");
8
11
  const normalize_schema_1 = require("./lib/normalize-schema");
9
12
  const run_angular_plugin_1 = require("./lib/run-angular-plugin");
@@ -18,9 +21,9 @@ const update_package_json_1 = require("./lib/update-package-json");
18
21
  const update_project_root_files_1 = require("./lib/update-project-root-files");
19
22
  const update_readme_1 = require("./lib/update-readme");
20
23
  const update_storybook_config_1 = require("./lib/update-storybook-config");
21
- const extract_base_configs_1 = require("./lib/extract-base-configs");
22
24
  async function moveGenerator(tree, rawSchema) {
23
25
  let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, rawSchema.projectName);
26
+ const wasIncludedInWorkspaces = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, projectConfig.root);
24
27
  const schema = await (0, normalize_schema_1.normalizeSchema)(tree, rawSchema, projectConfig);
25
28
  (0, check_destination_1.checkDestination)(tree, schema, rawSchema.destination);
26
29
  if (projectConfig.root === '.') {
@@ -48,8 +51,23 @@ async function moveGenerator(tree, rawSchema) {
48
51
  (0, extract_base_configs_1.maybeMigrateEslintConfigIfRootProject)(tree, projectConfig);
49
52
  }
50
53
  await (0, run_angular_plugin_1.runAngularPlugin)(tree, schema);
54
+ let task;
55
+ if (wasIncludedInWorkspaces) {
56
+ // check if the new destination is included in the package manager workspaces
57
+ const isIncludedInWorkspaces = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, schema.destination);
58
+ if (!isIncludedInWorkspaces) {
59
+ // the new destination is not included in the package manager workspaces
60
+ // so we need to add it and run a package install to ensure the symlink
61
+ // is created
62
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, schema.destination);
63
+ task = () => (0, devkit_1.installPackagesTask)(tree, true);
64
+ }
65
+ }
51
66
  if (!schema.skipFormat) {
52
67
  await (0, devkit_1.formatFiles)(tree);
53
68
  }
69
+ if (task) {
70
+ return task;
71
+ }
54
72
  }
55
73
  exports.default = moveGenerator;
@@ -9,4 +9,5 @@ export interface Schema {
9
9
 
10
10
  export interface NormalizedSchema extends Schema {
11
11
  relativeToRootDestination: string;
12
+ isNxConfiguredInPackageJson?: boolean;
12
13
  }
@@ -4,10 +4,9 @@ exports.npmPackageGenerator = npmPackageGenerator;
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
6
  const path_1 = require("path");
7
- const get_import_path_1 = require("../../utilities/get-import-path");
8
7
  async function normalizeOptions(tree, options) {
9
- await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
10
- const { projectName, projectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
8
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
9
+ const { projectName, projectRoot, importPath } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
11
10
  name: options.name,
12
11
  projectType: 'library',
13
12
  directory: options.directory,
@@ -16,12 +15,13 @@ async function normalizeOptions(tree, options) {
16
15
  ...options,
17
16
  name: projectName,
18
17
  projectRoot,
18
+ importPath,
19
19
  };
20
20
  }
21
21
  function addFiles(projectRoot, tree, options) {
22
22
  const packageJsonPath = (0, path_1.join)(projectRoot, 'package.json');
23
23
  (0, devkit_1.writeJson)(tree, packageJsonPath, {
24
- name: (0, get_import_path_1.getImportPath)(tree, options.name),
24
+ name: options.importPath,
25
25
  version: '0.0.0',
26
26
  scripts: {
27
27
  test: 'node index.js',
@@ -73,6 +73,7 @@ async function createPreset(tree, options) {
73
73
  nxCloudToken: options.nxCloudToken,
74
74
  useTsSolution: options.workspaces,
75
75
  formatter: options.formatter,
76
+ useProjectJson: !options.workspaces,
76
77
  });
77
78
  }
78
79
  else if (options.preset === presets_1.Preset.ReactStandalone) {
@@ -106,6 +107,7 @@ async function createPreset(tree, options) {
106
107
  nxCloudToken: options.nxCloudToken,
107
108
  useTsSolution: options.workspaces,
108
109
  formatter: options.formatter,
110
+ useProjectJson: !options.workspaces,
109
111
  });
110
112
  }
111
113
  else if (options.preset === presets_1.Preset.RemixStandalone) {
@@ -137,6 +139,7 @@ async function createPreset(tree, options) {
137
139
  nxCloudToken: options.nxCloudToken,
138
140
  useTsSolution: options.workspaces,
139
141
  formatter: options.formatter,
142
+ useProjectJson: !options.workspaces,
140
143
  });
141
144
  }
142
145
  else if (options.preset === presets_1.Preset.VueStandalone) {
@@ -168,6 +171,7 @@ async function createPreset(tree, options) {
168
171
  nxCloudToken: options.nxCloudToken,
169
172
  useTsSolution: options.workspaces,
170
173
  formatter: options.formatter,
174
+ useProjectJson: !options.workspaces,
171
175
  });
172
176
  }
173
177
  else if (options.preset === presets_1.Preset.NuxtStandalone) {
@@ -200,6 +204,7 @@ async function createPreset(tree, options) {
200
204
  addPlugin,
201
205
  useTsSolution: options.workspaces,
202
206
  formatter: options.formatter,
207
+ useProjectJson: !options.workspaces,
203
208
  });
204
209
  }
205
210
  else if (options.preset === presets_1.Preset.NextJsStandalone) {
@@ -245,6 +250,7 @@ async function createPreset(tree, options) {
245
250
  addPlugin,
246
251
  useTsSolution: options.workspaces,
247
252
  formatter: options.formatter,
253
+ useProjectJson: !options.workspaces,
248
254
  });
249
255
  }
250
256
  else if (options.preset === presets_1.Preset.Express) {
@@ -258,6 +264,7 @@ async function createPreset(tree, options) {
258
264
  addPlugin,
259
265
  useTsSolution: options.workspaces,
260
266
  formatter: options.formatter,
267
+ useProjectJson: !options.workspaces,
261
268
  });
262
269
  }
263
270
  else if (options.preset === presets_1.Preset.ReactNative) {
@@ -274,6 +281,7 @@ async function createPreset(tree, options) {
274
281
  bundler: options.bundler ?? 'webpack',
275
282
  useTsSolution: options.workspaces,
276
283
  formatter: options.formatter,
284
+ useProjectJson: !options.workspaces,
277
285
  });
278
286
  }
279
287
  else if (options.preset === presets_1.Preset.Expo) {
@@ -288,6 +296,7 @@ async function createPreset(tree, options) {
288
296
  nxCloudToken: options.nxCloudToken,
289
297
  useTsSolution: options.workspaces,
290
298
  formatter: options.formatter,
299
+ useProjectJson: !options.workspaces,
291
300
  });
292
301
  }
293
302
  else if (options.preset === presets_1.Preset.TS) {
@@ -346,6 +355,7 @@ async function createPreset(tree, options) {
346
355
  addPlugin,
347
356
  useTsSolution: options.workspaces,
348
357
  formatter: options.formatter,
358
+ useProjectJson: !options.workspaces,
349
359
  });
350
360
  }
351
361
  else {
@@ -0,0 +1,5 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function isProjectIncludedInPackageManagerWorkspaces(tree: Tree, projectRoot: string): boolean;
3
+ export declare function getPackageManagerWorkspacesPatterns(tree: Tree): string[];
4
+ export declare function isUsingPackageManagerWorkspaces(tree: Tree): boolean;
5
+ export declare function isWorkspacesEnabled(tree: Tree): boolean;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isProjectIncludedInPackageManagerWorkspaces = isProjectIncludedInPackageManagerWorkspaces;
4
+ exports.getPackageManagerWorkspacesPatterns = getPackageManagerWorkspacesPatterns;
5
+ exports.isUsingPackageManagerWorkspaces = isUsingPackageManagerWorkspaces;
6
+ exports.isWorkspacesEnabled = isWorkspacesEnabled;
7
+ const devkit_1 = require("@nx/devkit");
8
+ const posix_1 = require("node:path/posix");
9
+ const package_json_1 = require("nx/src/plugins/package-json");
10
+ const picomatch = require("picomatch");
11
+ function isProjectIncludedInPackageManagerWorkspaces(tree, projectRoot) {
12
+ if (!isUsingPackageManagerWorkspaces(tree)) {
13
+ return false;
14
+ }
15
+ const patterns = getPackageManagerWorkspacesPatterns(tree);
16
+ return patterns.some((p) => picomatch(p)((0, posix_1.join)(projectRoot, 'package.json')));
17
+ }
18
+ function getPackageManagerWorkspacesPatterns(tree) {
19
+ return (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
20
+ const content = tree.read(path, 'utf-8');
21
+ const { load } = require('@zkochan/js-yaml');
22
+ return load(content, { filename: path });
23
+ }, (path) => tree.exists(path));
24
+ }
25
+ function isUsingPackageManagerWorkspaces(tree) {
26
+ return isWorkspacesEnabled(tree);
27
+ }
28
+ function isWorkspacesEnabled(tree) {
29
+ const packageManager = (0, devkit_1.detectPackageManager)(tree.root);
30
+ if (packageManager === 'pnpm') {
31
+ return tree.exists('pnpm-workspace.yaml');
32
+ }
33
+ // yarn and npm both use the same 'workspaces' property in package.json
34
+ if (tree.exists('package.json')) {
35
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
36
+ return !!packageJson?.workspaces;
37
+ }
38
+ return false;
39
+ }
@@ -1,2 +1,3 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
3
+ export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): Promise<void>;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
4
+ exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
4
5
  const devkit_1 = require("@nx/devkit");
6
+ const posix_1 = require("node:path/posix");
5
7
  const tree_1 = require("nx/src/generators/tree");
8
+ const package_manager_workspaces_1 = require("../package-manager-workspaces");
6
9
  function isUsingPackageManagerWorkspaces(tree) {
7
10
  return isWorkspacesEnabled(tree);
8
11
  }
@@ -55,3 +58,48 @@ function isUsingTsSolutionSetup(tree) {
55
58
  return (isUsingPackageManagerWorkspaces(tree) &&
56
59
  isWorkspaceSetupWithTsSolution(tree));
57
60
  }
61
+ async function addProjectToTsSolutionWorkspace(tree, projectDir) {
62
+ const isIncluded = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, projectDir);
63
+ if (isIncluded) {
64
+ return;
65
+ }
66
+ // If dir is "libs/foo", we try to use "libs/*" but we only do it if it's
67
+ // safe to do so. So, we first check if adding that pattern doesn't result
68
+ // in extra projects being matched. If extra projects are matched, or the
69
+ // dir is just "foo" then we add it as is.
70
+ const baseDir = (0, posix_1.dirname)(projectDir);
71
+ let pattern = projectDir;
72
+ if (baseDir !== '.') {
73
+ const patterns = (0, package_manager_workspaces_1.getPackageManagerWorkspacesPatterns)(tree);
74
+ const projectsBefore = await (0, devkit_1.globAsync)(tree, patterns);
75
+ patterns.push(`${baseDir}/*/package.json`);
76
+ const projectsAfter = await (0, devkit_1.globAsync)(tree, patterns);
77
+ if (projectsBefore.length + 1 === projectsAfter.length) {
78
+ // Adding the pattern to the parent directory only results in one extra
79
+ // project being matched, which is the project we're adding. It's safe
80
+ // to add the pattern to the parent directory.
81
+ pattern = `${baseDir}/*`;
82
+ }
83
+ }
84
+ if (tree.exists('pnpm-workspace.yaml')) {
85
+ const { load, dump } = require('@zkochan/js-yaml');
86
+ const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
87
+ const yamlData = load(workspaceFile) ?? {};
88
+ yamlData.packages ??= [];
89
+ if (!yamlData.packages.includes(pattern)) {
90
+ yamlData.packages.push(pattern);
91
+ tree.write('pnpm-workspace.yaml', dump(yamlData, { indent: 2, quotingType: '"', forceQuotes: true }));
92
+ }
93
+ }
94
+ else {
95
+ // Update package.json
96
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
97
+ if (!packageJson.workspaces) {
98
+ packageJson.workspaces = [];
99
+ }
100
+ if (!packageJson.workspaces.includes(pattern)) {
101
+ packageJson.workspaces.push(pattern);
102
+ tree.write('package.json', JSON.stringify(packageJson, null, 2));
103
+ }
104
+ }
105
+ }
@@ -1,3 +1,3 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const typescriptVersion = "~5.7.2";
3
- export declare const angularCliVersion = "~19.1.0";
3
+ export declare const angularCliVersion = "~19.2.0";
@@ -5,4 +5,4 @@ exports.nxVersion = require('../../package.json').version;
5
5
  exports.typescriptVersion = '~5.7.2';
6
6
  // TODO: remove when preset generation is reworked and
7
7
  // deps are not installed from workspace
8
- exports.angularCliVersion = '~19.1.0';
8
+ exports.angularCliVersion = '~19.2.0';