@pnpm/workspace.root-finder 1100.0.8 → 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 +19 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +85 -5
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
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
|
+
|
|
16
|
+
## 1100.0.9
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- A command run in a project that the workspace does not include now acts on that project alone. A project is outside the workspace when it has a manifest of its own and no pattern in the `packages` setting selects it, or when a `!` pattern excludes it. A directory with no manifest of its own, such as a package's source directory, still belongs to the workspace. `pnpm install` in an excluded project used to install every project in the workspace [#3561](https://github.com/pnpm/pnpm/issues/3561).
|
|
21
|
+
|
|
3
22
|
## 1100.0.8
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import util from 'node:util';
|
|
4
|
+
import { MANIFEST_BASE_NAMES } from '@pnpm/constants';
|
|
3
5
|
import { PnpmError } from '@pnpm/error';
|
|
6
|
+
import { isWorkspaceProjectDir } from '@pnpm/workspace.package-patterns';
|
|
7
|
+
import { readWorkspaceManifest, readWorkspaceManifestSync } from '@pnpm/workspace.workspace-manifest-reader';
|
|
4
8
|
import * as find from 'empathic/find';
|
|
9
|
+
const MANIFEST_BASE_NAMES_SET = new Set(MANIFEST_BASE_NAMES);
|
|
5
10
|
const WORKSPACE_DIR_ENV_VAR = 'NPM_CONFIG_WORKSPACE_DIR';
|
|
6
11
|
const WORKSPACE_MANIFEST_FILENAME = 'pnpm-workspace.yaml';
|
|
7
12
|
const INVALID_WORKSPACE_MANIFEST_FILENAME = [
|
|
@@ -15,13 +20,80 @@ const INVALID_WORKSPACE_MANIFEST_FILENAME = [
|
|
|
15
20
|
];
|
|
16
21
|
export async function findWorkspaceDir(cwd) {
|
|
17
22
|
const workspaceManifestDirEnvVar = process.env[WORKSPACE_DIR_ENV_VAR] ?? process.env[WORKSPACE_DIR_ENV_VAR.toLowerCase()];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
if (workspaceManifestDirEnvVar) {
|
|
24
|
+
return path.dirname(path.join(workspaceManifestDirEnvVar, WORKSPACE_MANIFEST_FILENAME));
|
|
25
|
+
}
|
|
26
|
+
const realCwd = await getRealPath(cwd);
|
|
27
|
+
const workspaceManifestLocation = find.any([WORKSPACE_MANIFEST_FILENAME, ...INVALID_WORKSPACE_MANIFEST_FILENAME], { cwd: realCwd });
|
|
28
|
+
if (!workspaceManifestLocation)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (path.basename(workspaceManifestLocation) !== WORKSPACE_MANIFEST_FILENAME) {
|
|
22
31
|
throw new PnpmError('BAD_WORKSPACE_MANIFEST_NAME', `The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${workspaceManifestLocation}`);
|
|
23
32
|
}
|
|
24
|
-
|
|
33
|
+
const workspaceDir = path.dirname(workspaceManifestLocation);
|
|
34
|
+
return await belongsToWorkspace(workspaceDir, realCwd) ? workspaceDir : undefined;
|
|
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
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A project that the workspace does not include stands on its own, so pnpm
|
|
53
|
+
* runs it as a standalone project instead of acting on the whole workspace
|
|
54
|
+
* (https://github.com/pnpm/pnpm/issues/3561).
|
|
55
|
+
*
|
|
56
|
+
* A directory without a manifest of its own is not such a project. It is some
|
|
57
|
+
* place inside the workspace, like a package's source directory, and a command
|
|
58
|
+
* run from there still acts on the workspace.
|
|
59
|
+
*/
|
|
60
|
+
async function belongsToWorkspace(workspaceDir, dir) {
|
|
61
|
+
if (path.relative(workspaceDir, dir) === '' || !await hasProjectManifest(dir))
|
|
62
|
+
return true;
|
|
63
|
+
const workspaceManifest = await readWorkspaceManifest(workspaceDir);
|
|
64
|
+
return isWorkspaceProjectDir({ workspaceDir, dir, patterns: workspaceManifest?.packages ?? ['.'] });
|
|
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
|
+
}
|
|
72
|
+
async function hasProjectManifest(dir) {
|
|
73
|
+
let entries;
|
|
74
|
+
try {
|
|
75
|
+
entries = await fs.promises.readdir(dir);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
// The directory pnpm was pointed at may not exist. Reporting that is the
|
|
79
|
+
// job of the command that needs it, not of the workspace lookup.
|
|
80
|
+
if (util.types.isNativeError(err) && 'code' in err && (err.code === 'ENOENT' || err.code === 'ENOTDIR'))
|
|
81
|
+
return false;
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
return entries.some((entry) => MANIFEST_BASE_NAMES_SET.has(entry));
|
|
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));
|
|
25
97
|
}
|
|
26
98
|
async function getRealPath(path) {
|
|
27
99
|
return new Promise((resolve) => {
|
|
@@ -34,4 +106,12 @@ async function getRealPath(path) {
|
|
|
34
106
|
});
|
|
35
107
|
});
|
|
36
108
|
}
|
|
109
|
+
function getRealPathSync(path) {
|
|
110
|
+
try {
|
|
111
|
+
return fs.realpathSync.native(path);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return path;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
37
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
|
|
3
|
+
"version": "1100.1.0",
|
|
4
4
|
"description": "Finds the root of a pnpm workspace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -27,12 +27,16 @@
|
|
|
27
27
|
"!*.map"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pnpm/
|
|
31
|
-
"
|
|
30
|
+
"@pnpm/constants": "1102.0.0",
|
|
31
|
+
"@pnpm/error": "1100.2.0",
|
|
32
|
+
"@pnpm/workspace.package-patterns": "1100.0.1",
|
|
33
|
+
"@pnpm/workspace.workspace-manifest-reader": "1100.2.0",
|
|
34
|
+
"empathic": "^2.1.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@jest/globals": "30.4.1",
|
|
35
|
-
"@pnpm/workspace.root-finder": "1100.0
|
|
38
|
+
"@pnpm/workspace.root-finder": "1100.1.0",
|
|
39
|
+
"tempy": "3.0.0"
|
|
36
40
|
},
|
|
37
41
|
"engines": {
|
|
38
42
|
"node": ">=22.13"
|