@pnpm/store.path 1000.0.5
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/LICENSE +22 -0
- package/README.md +26 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +104 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
+
Copyright (c) 2016-2026 Zoltan Kochan and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @pnpm/store-path
|
|
2
|
+
|
|
3
|
+
> Resolves the pnpm store path
|
|
4
|
+
|
|
5
|
+
<!--@shields('npm')-->
|
|
6
|
+
[](https://www.npmjs.com/package/@pnpm/store-path)
|
|
7
|
+
<!--/@-->
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
<pnpm|yarn|npm> add @pnpm/store-path
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import resolveStorePath from '@pnpm/store-path'
|
|
19
|
+
|
|
20
|
+
await resolveStorePath('F:\\project', 'pnpm-store')
|
|
21
|
+
//> F:\\pnpm-store\\2
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
[MIT](./LICENSE)
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { STORE_VERSION } from '@pnpm/constants';
|
|
5
|
+
import { PnpmError } from '@pnpm/error';
|
|
6
|
+
import { rimraf } from '@zkochan/rimraf';
|
|
7
|
+
import { canLink } from 'can-link';
|
|
8
|
+
import { pathAbsolute } from 'path-absolute';
|
|
9
|
+
import { pathTemp } from 'path-temp';
|
|
10
|
+
import { rootLinkTarget } from 'root-link-target';
|
|
11
|
+
import touch from 'touch';
|
|
12
|
+
export function getStorePath({ pkgRoot, storePath, pnpmHomeDir, }) {
|
|
13
|
+
if (!storePath) {
|
|
14
|
+
if (!pnpmHomeDir) {
|
|
15
|
+
throw new PnpmError('NO_PNPM_HOME_DIR', 'The pnpm home directory is unknown. Cannot calculate the store directory location.');
|
|
16
|
+
}
|
|
17
|
+
return storePathRelativeToHome(pkgRoot, 'store', pnpmHomeDir);
|
|
18
|
+
}
|
|
19
|
+
if (isHomepath(storePath)) {
|
|
20
|
+
const homedir = getHomedir();
|
|
21
|
+
return storePathRelativeToHome(pkgRoot, storePath.substring(2), homedir);
|
|
22
|
+
}
|
|
23
|
+
const storeBasePath = pathAbsolute(storePath, pkgRoot);
|
|
24
|
+
if (storeBasePath.endsWith(`${path.sep}${STORE_VERSION}`)) {
|
|
25
|
+
return storeBasePath;
|
|
26
|
+
}
|
|
27
|
+
return path.join(storeBasePath, STORE_VERSION);
|
|
28
|
+
}
|
|
29
|
+
async function storePathRelativeToHome(pkgRoot, relStore, homedir) {
|
|
30
|
+
const tempFile = pathTemp(pkgRoot);
|
|
31
|
+
if (path.parse(pkgRoot).root !== pkgRoot)
|
|
32
|
+
await fs.mkdir(path.dirname(tempFile), { recursive: true });
|
|
33
|
+
await touch(tempFile);
|
|
34
|
+
const storeInHomeDir = path.join(homedir, relStore, STORE_VERSION);
|
|
35
|
+
if (await canLinkToSubdir(tempFile, homedir)) {
|
|
36
|
+
await fs.unlink(tempFile);
|
|
37
|
+
// If the project is on the drive on which the OS home directory
|
|
38
|
+
// then the store is placed in the home directory
|
|
39
|
+
return storeInHomeDir;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
let mountpoint = await rootLinkTarget(tempFile);
|
|
43
|
+
// Usually, it is disallowed to write files into the drive's root.
|
|
44
|
+
// So we create an empty directory and try to link there.
|
|
45
|
+
// The store will be a directory anyway.
|
|
46
|
+
const mountpointParent = path.join(mountpoint, '..');
|
|
47
|
+
if (!dirsAreEqual(mountpointParent, mountpoint) && await canLinkToSubdir(tempFile, mountpointParent)) {
|
|
48
|
+
mountpoint = mountpointParent;
|
|
49
|
+
}
|
|
50
|
+
// If linking works only in the project folder
|
|
51
|
+
// then prefer to place the store inside the homedir
|
|
52
|
+
if (dirsAreEqual(pkgRoot, mountpoint)) {
|
|
53
|
+
return storeInHomeDir;
|
|
54
|
+
}
|
|
55
|
+
return path.join(mountpoint, '.pnpm-store', STORE_VERSION);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// this is an unlikely situation but if there is no way to find
|
|
59
|
+
// a linkable place on the disk, create the store in homedir
|
|
60
|
+
return storeInHomeDir;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await fs.unlink(tempFile);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function canLinkToSubdir(fileToLink, dir) {
|
|
67
|
+
let result = false;
|
|
68
|
+
const tmpDir = pathTemp(dir);
|
|
69
|
+
try {
|
|
70
|
+
await fs.mkdir(tmpDir, { recursive: true });
|
|
71
|
+
result = await canLink(fileToLink, pathTemp(tmpDir));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
result = false;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await safeRmdir(tmpDir);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
async function safeRmdir(dir) {
|
|
82
|
+
try {
|
|
83
|
+
// We cannot use just fs.rmdir here because can-link
|
|
84
|
+
// sometimes might not remove the temporary file in time
|
|
85
|
+
// and fs.rmdir can only remove an empty directory.
|
|
86
|
+
await rimraf(dir);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// ignore
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function dirsAreEqual(dir1, dir2) {
|
|
93
|
+
return path.relative(dir1, dir2) === '.';
|
|
94
|
+
}
|
|
95
|
+
function getHomedir() {
|
|
96
|
+
const home = os.homedir();
|
|
97
|
+
if (!home)
|
|
98
|
+
throw new Error('Could not find the homedir');
|
|
99
|
+
return home;
|
|
100
|
+
}
|
|
101
|
+
function isHomepath(filepath) {
|
|
102
|
+
return filepath.startsWith('~/') || filepath.startsWith('~\\');
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/store.path",
|
|
3
|
+
"version": "1000.0.5",
|
|
4
|
+
"description": "Resolves the pnpm store path",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11",
|
|
8
|
+
"store"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": "https://opencollective.com/pnpm",
|
|
12
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/store/path",
|
|
13
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/store/path#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"!*.map"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@zkochan/rimraf": "^4.0.0",
|
|
28
|
+
"can-link": "^3.0.0",
|
|
29
|
+
"path-absolute": "^2.0.0",
|
|
30
|
+
"path-temp": "^3.0.0",
|
|
31
|
+
"root-link-target": "^4.0.0",
|
|
32
|
+
"touch": "3.1.0",
|
|
33
|
+
"@pnpm/error": "1000.0.5",
|
|
34
|
+
"@pnpm/constants": "1001.3.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@jest/globals": "30.0.5",
|
|
38
|
+
"@types/is-windows": "^1.0.2",
|
|
39
|
+
"@types/node": "^22.19.11",
|
|
40
|
+
"@types/touch": "^3.1.5",
|
|
41
|
+
"is-windows": "^1.0.2",
|
|
42
|
+
"rimraf": "^6.1.2",
|
|
43
|
+
"@pnpm/store.path": "1000.0.5"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=22.13"
|
|
47
|
+
},
|
|
48
|
+
"jest": {
|
|
49
|
+
"preset": "@pnpm/jest-config"
|
|
50
|
+
},
|
|
51
|
+
"typings": "lib/index.d.ts",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
54
|
+
"_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
|
|
55
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
56
|
+
"compile": "tsgo --build && pnpm run lint --fix"
|
|
57
|
+
}
|
|
58
|
+
}
|