@pnpm/workspace.root-finder 1100.0.9 → 1100.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @pnpm/workspace.root-finder
2
2
 
3
+ ## 1100.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `findWorkspaceDirSync`, `findPackagesSync`, `findWorkspaceProjectsSync`, `findWorkspaceProjectsNoCheckSync`, `readWorkspaceManifestSync`, and `readExactProjectManifestSync`.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies:
12
+ - @pnpm/error@1100.2.0
13
+ - @pnpm/workspace.package-patterns@1100.0.1
14
+ - @pnpm/workspace.workspace-manifest-reader@1100.2.0
15
+
3
16
  ## 1100.0.9
4
17
 
5
18
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare function findWorkspaceDir(cwd: string): Promise<string | undefined>;
2
+ export declare function findWorkspaceDirSync(cwd: string): string | undefined;
package/lib/index.js CHANGED
@@ -4,7 +4,7 @@ import util from 'node:util';
4
4
  import { MANIFEST_BASE_NAMES } from '@pnpm/constants';
5
5
  import { PnpmError } from '@pnpm/error';
6
6
  import { isWorkspaceProjectDir } from '@pnpm/workspace.package-patterns';
7
- import { readWorkspaceManifest } from '@pnpm/workspace.workspace-manifest-reader';
7
+ import { readWorkspaceManifest, readWorkspaceManifestSync } from '@pnpm/workspace.workspace-manifest-reader';
8
8
  import * as find from 'empathic/find';
9
9
  const MANIFEST_BASE_NAMES_SET = new Set(MANIFEST_BASE_NAMES);
10
10
  const WORKSPACE_DIR_ENV_VAR = 'NPM_CONFIG_WORKSPACE_DIR';
@@ -33,6 +33,21 @@ export async function findWorkspaceDir(cwd) {
33
33
  const workspaceDir = path.dirname(workspaceManifestLocation);
34
34
  return await belongsToWorkspace(workspaceDir, realCwd) ? workspaceDir : undefined;
35
35
  }
36
+ export function findWorkspaceDirSync(cwd) {
37
+ const workspaceManifestDirEnvVar = process.env[WORKSPACE_DIR_ENV_VAR] ?? process.env[WORKSPACE_DIR_ENV_VAR.toLowerCase()];
38
+ if (workspaceManifestDirEnvVar) {
39
+ return path.dirname(path.join(workspaceManifestDirEnvVar, WORKSPACE_MANIFEST_FILENAME));
40
+ }
41
+ const realCwd = getRealPathSync(cwd);
42
+ const workspaceManifestLocation = find.any([WORKSPACE_MANIFEST_FILENAME, ...INVALID_WORKSPACE_MANIFEST_FILENAME], { cwd: realCwd });
43
+ if (!workspaceManifestLocation)
44
+ return undefined;
45
+ if (path.basename(workspaceManifestLocation) !== WORKSPACE_MANIFEST_FILENAME) {
46
+ throw new PnpmError('BAD_WORKSPACE_MANIFEST_NAME', `The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${workspaceManifestLocation}`);
47
+ }
48
+ const workspaceDir = path.dirname(workspaceManifestLocation);
49
+ return belongsToWorkspaceSync(workspaceDir, realCwd) ? workspaceDir : undefined;
50
+ }
36
51
  /**
37
52
  * A project that the workspace does not include stands on its own, so pnpm
38
53
  * runs it as a standalone project instead of acting on the whole workspace
@@ -48,6 +63,12 @@ async function belongsToWorkspace(workspaceDir, dir) {
48
63
  const workspaceManifest = await readWorkspaceManifest(workspaceDir);
49
64
  return isWorkspaceProjectDir({ workspaceDir, dir, patterns: workspaceManifest?.packages ?? ['.'] });
50
65
  }
66
+ function belongsToWorkspaceSync(workspaceDir, dir) {
67
+ if (path.relative(workspaceDir, dir) === '' || !hasProjectManifestSync(dir))
68
+ return true;
69
+ const workspaceManifest = readWorkspaceManifestSync(workspaceDir);
70
+ return isWorkspaceProjectDir({ workspaceDir, dir, patterns: workspaceManifest?.packages ?? ['.'] });
71
+ }
51
72
  async function hasProjectManifest(dir) {
52
73
  let entries;
53
74
  try {
@@ -62,6 +83,18 @@ async function hasProjectManifest(dir) {
62
83
  }
63
84
  return entries.some((entry) => MANIFEST_BASE_NAMES_SET.has(entry));
64
85
  }
86
+ function hasProjectManifestSync(dir) {
87
+ let entries;
88
+ try {
89
+ entries = fs.readdirSync(dir);
90
+ }
91
+ catch (err) {
92
+ if (util.types.isNativeError(err) && 'code' in err && (err.code === 'ENOENT' || err.code === 'ENOTDIR'))
93
+ return false;
94
+ throw err;
95
+ }
96
+ return entries.some((entry) => MANIFEST_BASE_NAMES_SET.has(entry));
97
+ }
65
98
  async function getRealPath(path) {
66
99
  return new Promise((resolve) => {
67
100
  // We need to resolve the real native path for case-insensitive file systems.
@@ -73,4 +106,12 @@ async function getRealPath(path) {
73
106
  });
74
107
  });
75
108
  }
109
+ function getRealPathSync(path) {
110
+ try {
111
+ return fs.realpathSync.native(path);
112
+ }
113
+ catch {
114
+ return path;
115
+ }
116
+ }
76
117
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/workspace.root-finder",
3
- "version": "1100.0.9",
3
+ "version": "1100.1.0",
4
4
  "description": "Finds the root of a pnpm workspace",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -28,14 +28,14 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@pnpm/constants": "1102.0.0",
31
- "@pnpm/error": "1100.1.4",
32
- "@pnpm/workspace.package-patterns": "1100.0.0",
33
- "@pnpm/workspace.workspace-manifest-reader": "1100.1.9",
31
+ "@pnpm/error": "1100.2.0",
32
+ "@pnpm/workspace.package-patterns": "1100.0.1",
33
+ "@pnpm/workspace.workspace-manifest-reader": "1100.2.0",
34
34
  "empathic": "^2.1.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@jest/globals": "30.4.1",
38
- "@pnpm/workspace.root-finder": "1100.0.9",
38
+ "@pnpm/workspace.root-finder": "1100.1.0",
39
39
  "tempy": "3.0.0"
40
40
  },
41
41
  "engines": {