@nx/js 20.5.0 → 20.6.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": "20.5.0",
3
+ "version": "20.6.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,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.5.0",
43
- "@nx/workspace": "20.5.0",
42
+ "@nx/devkit": "20.6.0-beta.0",
43
+ "@nx/workspace": "20.6.0-beta.0",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^3.1.0",
@@ -42,16 +42,16 @@ async function libraryGeneratorInternal(tree, schema) {
42
42
  formatter: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'none' : 'prettier',
43
43
  }));
44
44
  const options = await normalizeOptions(tree, schema);
45
- // If we are using the new TS solution
46
- // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
47
- if (options.isUsingTsSolutionConfig) {
48
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
49
- }
50
45
  createFiles(tree, options);
51
46
  await configureProject(tree, options);
52
47
  if (!options.skipPackageJson) {
53
48
  tasks.push(addProjectDependencies(tree, options));
54
49
  }
50
+ // If we are using the new TS solution
51
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
52
+ if (options.isUsingTsSolutionConfig) {
53
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
54
+ }
55
55
  if (options.bundler === 'rollup') {
56
56
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
57
57
  await configurationGenerator(tree, {
@@ -1,6 +1,7 @@
1
1
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
2
  export type ProjectPackageManagerWorkspaceState = 'included' | 'excluded' | 'no-workspaces';
3
3
  export declare function getProjectPackageManagerWorkspaceState(tree: Tree, projectRoot: string): ProjectPackageManagerWorkspaceState;
4
+ export declare function getPackageManagerWorkspacesPatterns(tree: Tree): string[];
4
5
  export declare function isUsingPackageManagerWorkspaces(tree: Tree): boolean;
5
6
  export declare function isWorkspacesEnabled(tree: Tree): boolean;
6
7
  export declare function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState, workspaceRoot: string): GeneratorCallback;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProjectPackageManagerWorkspaceState = getProjectPackageManagerWorkspaceState;
4
+ exports.getPackageManagerWorkspacesPatterns = getPackageManagerWorkspacesPatterns;
4
5
  exports.isUsingPackageManagerWorkspaces = isUsingPackageManagerWorkspaces;
5
6
  exports.isWorkspacesEnabled = isWorkspacesEnabled;
6
7
  exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageManagerWorkspaceStateWarningTask;
@@ -13,13 +14,16 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
13
14
  if (!isUsingPackageManagerWorkspaces(tree)) {
14
15
  return 'no-workspaces';
15
16
  }
16
- const patterns = (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
17
+ const patterns = getPackageManagerWorkspacesPatterns(tree);
18
+ const isIncluded = patterns.some((p) => picomatch(p)((0, posix_1.join)(projectRoot, 'package.json')));
19
+ return isIncluded ? 'included' : 'excluded';
20
+ }
21
+ function getPackageManagerWorkspacesPatterns(tree) {
22
+ return (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
17
23
  const content = tree.read(path, 'utf-8');
18
24
  const { load } = require('@zkochan/js-yaml');
19
25
  return load(content, { filename: path });
20
26
  }, (path) => tree.exists(path));
21
- const isIncluded = patterns.some((p) => picomatch(p)((0, posix_1.join)(projectRoot, 'package.json')));
22
- return isIncluded ? 'included' : 'excluded';
23
27
  }
24
28
  function isUsingPackageManagerWorkspaces(tree) {
25
29
  return isWorkspacesEnabled(tree);
@@ -4,6 +4,6 @@ export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
4
4
  export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: string, generatorName: string): void;
5
5
  export declare function findRuntimeTsConfigName(projectRoot: string, tree?: Tree): string | null;
6
6
  export declare function updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
7
- export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): void;
7
+ export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): Promise<void>;
8
8
  export declare function getProjectType(tree: Tree, projectRoot: string, projectType?: 'library' | 'application'): 'library' | 'application';
9
9
  export declare function getProjectSourceRoot(tree: Tree, projectSourceRoot: string | undefined, projectRoot: string): string | undefined;
@@ -145,16 +145,29 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
145
145
  });
146
146
  }
147
147
  }
148
- function addProjectToTsSolutionWorkspace(tree, projectDir) {
148
+ async function addProjectToTsSolutionWorkspace(tree, projectDir) {
149
149
  const state = (0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceState)(tree, projectDir);
150
150
  if (state === 'included') {
151
151
  return;
152
152
  }
153
- // If dir is "libs/foo" then use "libs/*" so we don't need so many entries in the workspace file.
154
- // If dir is nested like "libs/shared/foo" then we add "libs/shared/*".
155
- // If the dir is just "foo" then we have to add it as is.
153
+ // If dir is "libs/foo", we try to use "libs/*" but we only do it if it's
154
+ // safe to do so. So, we first check if adding that pattern doesn't result
155
+ // in extra projects being matched. If extra projects are matched, or the
156
+ // dir is just "foo" then we add it as is.
156
157
  const baseDir = (0, posix_1.dirname)(projectDir);
157
- const pattern = baseDir === '.' ? projectDir : `${baseDir}/*`;
158
+ let pattern = projectDir;
159
+ if (baseDir !== '.') {
160
+ const patterns = (0, package_manager_workspaces_1.getPackageManagerWorkspacesPatterns)(tree);
161
+ const projectsBefore = await (0, devkit_1.globAsync)(tree, patterns);
162
+ patterns.push(`${baseDir}/*/package.json`);
163
+ const projectsAfter = await (0, devkit_1.globAsync)(tree, patterns);
164
+ if (projectsBefore.length + 1 === projectsAfter.length) {
165
+ // Adding the pattern to the parent directory only results in one extra
166
+ // project being matched, which is the project we're adding. It's safe
167
+ // to add the pattern to the parent directory.
168
+ pattern = `${baseDir}/*`;
169
+ }
170
+ }
158
171
  if (tree.exists('pnpm-workspace.yaml')) {
159
172
  const { load, dump } = require('@zkochan/js-yaml');
160
173
  const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');