@pnpm/fetching.directory-fetcher 1000.1.14
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 +15 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +120 -0
- package/package.json +59 -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,15 @@
|
|
|
1
|
+
# @pnpm/directory-fetcher
|
|
2
|
+
|
|
3
|
+
> Fetcher for local directory packages
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@pnpm/directory-fetcher)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pnpm add @pnpm/directory-fetcher
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Stats } from 'node:fs';
|
|
2
|
+
import type { DirectoryFetcher, DirectoryFetcherOptions } from '@pnpm/fetching.fetcher-base';
|
|
3
|
+
import type { FilesMap } from '@pnpm/store.cafs-types';
|
|
4
|
+
import type { DependencyManifest } from '@pnpm/types';
|
|
5
|
+
export interface CreateDirectoryFetcherOptions {
|
|
6
|
+
includeOnlyPackageFiles?: boolean;
|
|
7
|
+
resolveSymlinks?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createDirectoryFetcher(opts?: CreateDirectoryFetcherOptions): {
|
|
10
|
+
directory: DirectoryFetcher;
|
|
11
|
+
};
|
|
12
|
+
export type FetchFromDirOptions = Omit<DirectoryFetcherOptions, 'lockfileDir'> & CreateDirectoryFetcherOptions;
|
|
13
|
+
export interface FetchResult {
|
|
14
|
+
local: true;
|
|
15
|
+
filesMap: FilesMap;
|
|
16
|
+
filesStats?: Record<string, Stats | null>;
|
|
17
|
+
packageImportMethod: 'hardlink';
|
|
18
|
+
manifest: DependencyManifest;
|
|
19
|
+
requiresBuild: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function fetchFromDir(dir: string, opts: FetchFromDirOptions): Promise<FetchResult>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import util from 'node:util';
|
|
4
|
+
import { pkgRequiresBuild } from '@pnpm/building.pkg-requires-build';
|
|
5
|
+
import { packlist } from '@pnpm/fs.packlist';
|
|
6
|
+
import { logger } from '@pnpm/logger';
|
|
7
|
+
import { safeReadProjectManifestOnly } from '@pnpm/workspace.project-manifest-reader';
|
|
8
|
+
const directoryFetcherLogger = logger('directory-fetcher');
|
|
9
|
+
export function createDirectoryFetcher(opts) {
|
|
10
|
+
const readFileStat = opts?.resolveSymlinks === true ? realFileStat : fileStat;
|
|
11
|
+
const fetchFromDir = opts?.includeOnlyPackageFiles ? fetchPackageFilesFromDir : fetchAllFilesFromDir.bind(null, readFileStat);
|
|
12
|
+
const directoryFetcher = (cafs, resolution, opts) => {
|
|
13
|
+
const dir = path.join(opts.lockfileDir, resolution.directory);
|
|
14
|
+
return fetchFromDir(dir);
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
directory: directoryFetcher,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function fetchFromDir(dir, opts) {
|
|
21
|
+
if (opts.includeOnlyPackageFiles) {
|
|
22
|
+
return fetchPackageFilesFromDir(dir);
|
|
23
|
+
}
|
|
24
|
+
const readFileStat = opts?.resolveSymlinks === true ? realFileStat : fileStat;
|
|
25
|
+
return fetchAllFilesFromDir(readFileStat, dir);
|
|
26
|
+
}
|
|
27
|
+
async function fetchAllFilesFromDir(readFileStat, dir) {
|
|
28
|
+
const { filesMap, filesStats } = await _fetchAllFilesFromDir(readFileStat, dir);
|
|
29
|
+
// In a regular pnpm workspace it will probably never happen that a dependency has no package.json file.
|
|
30
|
+
// Safe read was added to support the Bit workspace in which the components have no package.json files.
|
|
31
|
+
// Related PR in Bit: https://github.com/teambit/bit/pull/5251
|
|
32
|
+
const manifest = await safeReadProjectManifestOnly(dir) ?? undefined;
|
|
33
|
+
const requiresBuild = pkgRequiresBuild(manifest, filesMap);
|
|
34
|
+
return {
|
|
35
|
+
local: true,
|
|
36
|
+
filesMap,
|
|
37
|
+
filesStats,
|
|
38
|
+
packageImportMethod: 'hardlink',
|
|
39
|
+
manifest,
|
|
40
|
+
requiresBuild,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function _fetchAllFilesFromDir(readFileStat, dir, relativeDir = '') {
|
|
44
|
+
const filesMap = new Map();
|
|
45
|
+
const filesStats = {};
|
|
46
|
+
const files = await fs.readdir(dir);
|
|
47
|
+
await Promise.all(files
|
|
48
|
+
.filter((file) => file !== 'node_modules')
|
|
49
|
+
.map(async (file) => {
|
|
50
|
+
const fileStatResult = await readFileStat(path.join(dir, file));
|
|
51
|
+
if (!fileStatResult)
|
|
52
|
+
return;
|
|
53
|
+
const { filePath, stat } = fileStatResult;
|
|
54
|
+
const relativeSubdir = `${relativeDir}${relativeDir ? '/' : ''}${file}`;
|
|
55
|
+
if (stat.isDirectory()) {
|
|
56
|
+
const subFetchResult = await _fetchAllFilesFromDir(readFileStat, filePath, relativeSubdir);
|
|
57
|
+
for (const [key, value] of subFetchResult.filesMap) {
|
|
58
|
+
filesMap.set(key, value);
|
|
59
|
+
}
|
|
60
|
+
Object.assign(filesStats, subFetchResult.filesStats);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
filesMap.set(relativeSubdir, filePath);
|
|
64
|
+
filesStats[relativeSubdir] = fileStatResult.stat;
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
return { filesMap, filesStats };
|
|
68
|
+
}
|
|
69
|
+
async function realFileStat(filePath) {
|
|
70
|
+
let stat = await fs.lstat(filePath);
|
|
71
|
+
if (!stat.isSymbolicLink()) {
|
|
72
|
+
return { filePath, stat };
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
filePath = await fs.realpath(filePath);
|
|
76
|
+
stat = await fs.stat(filePath);
|
|
77
|
+
return { filePath, stat };
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
// Broken symlinks are skipped
|
|
81
|
+
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
|
|
82
|
+
directoryFetcherLogger.debug({ brokenSymlink: filePath });
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function fileStat(filePath) {
|
|
89
|
+
try {
|
|
90
|
+
return {
|
|
91
|
+
filePath,
|
|
92
|
+
stat: await fs.stat(filePath),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
// Broken symlinks are skipped
|
|
97
|
+
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
|
|
98
|
+
directoryFetcherLogger.debug({ brokenSymlink: filePath });
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function fetchPackageFilesFromDir(dir) {
|
|
105
|
+
const files = await packlist(dir);
|
|
106
|
+
const filesMap = new Map(files.map((file) => [file, path.join(dir, file)]));
|
|
107
|
+
// In a regular pnpm workspace it will probably never happen that a dependency has no package.json file.
|
|
108
|
+
// Safe read was added to support the Bit workspace in which the components have no package.json files.
|
|
109
|
+
// Related PR in Bit: https://github.com/teambit/bit/pull/5251
|
|
110
|
+
const manifest = await safeReadProjectManifestOnly(dir) ?? undefined;
|
|
111
|
+
const requiresBuild = pkgRequiresBuild(manifest, filesMap);
|
|
112
|
+
return {
|
|
113
|
+
local: true,
|
|
114
|
+
filesMap,
|
|
115
|
+
packageImportMethod: 'hardlink',
|
|
116
|
+
manifest,
|
|
117
|
+
requiresBuild,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/fetching.directory-fetcher",
|
|
3
|
+
"version": "1000.1.14",
|
|
4
|
+
"description": "A fetcher for local directory packages",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11",
|
|
8
|
+
"fetcher"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": "https://opencollective.com/pnpm",
|
|
12
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/fetching/directory-fetcher",
|
|
13
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/fetching/directory-fetcher#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"types": "lib/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./lib/index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib",
|
|
25
|
+
"!*.map"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@pnpm/building.pkg-requires-build": "1000.0.0-0",
|
|
29
|
+
"@pnpm/fetching.fetcher-base": "1001.0.2",
|
|
30
|
+
"@pnpm/fs.packlist": "1000.0.0",
|
|
31
|
+
"@pnpm/resolving.resolver-base": "1005.1.0",
|
|
32
|
+
"@pnpm/store.cafs-types": "1000.0.0",
|
|
33
|
+
"@pnpm/types": "1000.9.0",
|
|
34
|
+
"@pnpm/workspace.project-manifest-reader": "1001.1.4"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@pnpm/logger": ">=1001.0.0 <1002.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@jest/globals": "30.0.5",
|
|
41
|
+
"@pnpm/util.lex-comparator": "^3.0.2",
|
|
42
|
+
"@zkochan/rimraf": "^4.0.0",
|
|
43
|
+
"@pnpm/fetching.directory-fetcher": "1000.1.14",
|
|
44
|
+
"@pnpm/test-fixtures": "1000.0.0",
|
|
45
|
+
"@pnpm/logger": "1001.0.1"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22.13"
|
|
49
|
+
},
|
|
50
|
+
"jest": {
|
|
51
|
+
"preset": "@pnpm/jest-config"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
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
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
57
|
+
"compile": "tsgo --build && pnpm run lint --fix"
|
|
58
|
+
}
|
|
59
|
+
}
|