@pnpm/store.pkg-finder 1000.0.0-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/LICENSE +22 -0
- package/README.md +40 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +49 -0
- package/lib/index.js.map +1 -0
- package/package.json +47 -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,40 @@
|
|
|
1
|
+
# @pnpm/store.pkg-finder
|
|
2
|
+
|
|
3
|
+
Resolves a package's file index from the content-addressable store (CAFS) and returns a uniform `Map<string, string>` mapping filenames to absolute paths on disk.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { readPackageFileMap } from '@pnpm/store.pkg-finder'
|
|
9
|
+
|
|
10
|
+
const files = await readPackageFileMap(
|
|
11
|
+
resolution, // { integrity?, tarball?, directory?, type? }
|
|
12
|
+
packageId,
|
|
13
|
+
{
|
|
14
|
+
storeDir: '/home/user/.local/share/pnpm/store/v10',
|
|
15
|
+
lockfileDir: '/home/user/project',
|
|
16
|
+
virtualStoreDirMaxLength: 120,
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
if (files) {
|
|
21
|
+
const manifestPath = files.get('package.json')
|
|
22
|
+
const licensePath = files.get('LICENSE')
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Supported resolution types
|
|
27
|
+
|
|
28
|
+
- **Directory** (`type: 'directory'`): fetches the file list from the local directory.
|
|
29
|
+
- **Integrity** (`integrity` field): looks up the index file in CAFS by integrity hash.
|
|
30
|
+
- **Tarball** (`tarball` field): looks up the index file by package directory name.
|
|
31
|
+
|
|
32
|
+
Returns `undefined` for unsupported resolution types.
|
|
33
|
+
|
|
34
|
+
## Note on side effects
|
|
35
|
+
|
|
36
|
+
This function returns only the original package files. Files added or removed by post-install scripts (side effects) are not included. Use the raw `PackageFilesIndex` from `@pnpm/store.cafs` if you need side-effect files.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Resolution } from '@pnpm/resolver-base';
|
|
2
|
+
export interface ReadPackageFileMapOptions {
|
|
3
|
+
storeDir: string;
|
|
4
|
+
lockfileDir: string;
|
|
5
|
+
virtualStoreDirMaxLength: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reads the file index for a package and returns a `Map<string, string>`
|
|
9
|
+
* mapping filenames to absolute paths on disk.
|
|
10
|
+
*
|
|
11
|
+
* Handles three types of package resolutions:
|
|
12
|
+
* - Directory packages: fetches the file list from the local directory
|
|
13
|
+
* - Packages with integrity: looks up the index file in the CAFS by integrity hash
|
|
14
|
+
* - Tarball packages: looks up the index file by package directory name
|
|
15
|
+
*
|
|
16
|
+
* For CAFS packages, the content-addressed digests are resolved to file
|
|
17
|
+
* paths upfront, so callers get a uniform map regardless of resolution type.
|
|
18
|
+
*
|
|
19
|
+
* Note: this function does not include files from side effects (post-install
|
|
20
|
+
* scripts). Use the raw `PackageFilesIndex` if you need side-effect files.
|
|
21
|
+
*
|
|
22
|
+
* Returns `undefined` if the resolution type is unsupported, letting callers
|
|
23
|
+
* decide how to handle this case. Throws if the index file cannot be read.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readPackageFileMap(packageResolution: Resolution, packageId: string, opts: ReadPackageFileMapOptions): Promise<Map<string, string> | undefined>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { depPathToFilename, parse } from '@pnpm/dependency-path';
|
|
3
|
+
import { fetchFromDir } from '@pnpm/directory-fetcher';
|
|
4
|
+
import { readMsgpackFile } from '@pnpm/fs.msgpack-file';
|
|
5
|
+
import { getFilePathByModeInCafs, getIndexFilePathInCafs } from '@pnpm/store.cafs';
|
|
6
|
+
/**
|
|
7
|
+
* Reads the file index for a package and returns a `Map<string, string>`
|
|
8
|
+
* mapping filenames to absolute paths on disk.
|
|
9
|
+
*
|
|
10
|
+
* Handles three types of package resolutions:
|
|
11
|
+
* - Directory packages: fetches the file list from the local directory
|
|
12
|
+
* - Packages with integrity: looks up the index file in the CAFS by integrity hash
|
|
13
|
+
* - Tarball packages: looks up the index file by package directory name
|
|
14
|
+
*
|
|
15
|
+
* For CAFS packages, the content-addressed digests are resolved to file
|
|
16
|
+
* paths upfront, so callers get a uniform map regardless of resolution type.
|
|
17
|
+
*
|
|
18
|
+
* Note: this function does not include files from side effects (post-install
|
|
19
|
+
* scripts). Use the raw `PackageFilesIndex` if you need side-effect files.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` if the resolution type is unsupported, letting callers
|
|
22
|
+
* decide how to handle this case. Throws if the index file cannot be read.
|
|
23
|
+
*/
|
|
24
|
+
export async function readPackageFileMap(packageResolution, packageId, opts) {
|
|
25
|
+
if (packageResolution.type === 'directory') {
|
|
26
|
+
const localInfo = await fetchFromDir(path.join(opts.lockfileDir, packageResolution.directory), {});
|
|
27
|
+
return localInfo.filesMap;
|
|
28
|
+
}
|
|
29
|
+
const isPackageWithIntegrity = 'integrity' in packageResolution;
|
|
30
|
+
let pkgIndexFilePath;
|
|
31
|
+
if (isPackageWithIntegrity) {
|
|
32
|
+
const parsedId = parse(packageId);
|
|
33
|
+
pkgIndexFilePath = getIndexFilePathInCafs(opts.storeDir, packageResolution.integrity, parsedId.nonSemverVersion ?? `${parsedId.name}@${parsedId.version}`);
|
|
34
|
+
}
|
|
35
|
+
else if (!packageResolution.type && 'tarball' in packageResolution && packageResolution.tarball) {
|
|
36
|
+
const packageDirInStore = depPathToFilename(parse(packageId).nonSemverVersion ?? packageId, opts.virtualStoreDirMaxLength);
|
|
37
|
+
pkgIndexFilePath = path.join(opts.storeDir, packageDirInStore, 'integrity.mpk');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const { files: indexFiles } = await readMsgpackFile(pkgIndexFilePath);
|
|
43
|
+
const files = new Map();
|
|
44
|
+
for (const [name, info] of indexFiles) {
|
|
45
|
+
files.set(name, getFilePathByModeInCafs(opts.storeDir, info.digest, info.mode));
|
|
46
|
+
}
|
|
47
|
+
return files;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js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iBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,gBAAgB,IAAI,SAAS,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAA;QAC1H,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAC1B,IAAI,CAAC,QAAQ,EACb,iBAAiB,EACjB,eAAe,CAChB,CAAA;IACH,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,eAAe,CAAoB,gBAAgB,CAAC,CAAA;IACxF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAA;IACvC,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;QACtC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,uBAAuB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACjF,CAAC;IACD,OAAO,KAAK,CAAA;AAAA,CACb"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/store.pkg-finder",
|
|
3
|
+
"version": "1000.0.0-0",
|
|
4
|
+
"description": "Read a package's file map from the content-addressable store",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"funding": "https://opencollective.com/pnpm",
|
|
11
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/store/pkg-finder",
|
|
12
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/store/pkg-finder#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"!*.map"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@pnpm/directory-fetcher": "1000.1.14",
|
|
28
|
+
"@pnpm/fs.msgpack-file": "1100.0.0-0",
|
|
29
|
+
"@pnpm/resolver-base": "1005.1.0",
|
|
30
|
+
"@pnpm/dependency-path": "1001.1.3",
|
|
31
|
+
"@pnpm/store.cafs": "1000.0.19"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@pnpm/store.pkg-finder": "1000.0.0-0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22.13"
|
|
38
|
+
},
|
|
39
|
+
"jest": {
|
|
40
|
+
"preset": "@pnpm/jest-config"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
44
|
+
"compile": "tsgo --build && pnpm run lint --fix",
|
|
45
|
+
"test": "pnpm run compile"
|
|
46
|
+
}
|
|
47
|
+
}
|