@pnpm/store.create-cafs-store 1000.0.20

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 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,13 @@
1
+ # @pnpm/create-cafs-store
2
+
3
+ > Create a CAFS store controller
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ pnpm add @pnpm/create-cafs-store
9
+ ```
10
+
11
+ ## License
12
+
13
+ [MIT](LICENSE)
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type CafsLocker } from '@pnpm/store.cafs';
2
+ import type { Cafs } from '@pnpm/store.cafs-types';
3
+ import type { ImportIndexedPackage, ImportIndexedPackageAsync, ImportPackageFunctionAsync } from '@pnpm/store.controller-types';
4
+ export { type CafsLocker };
5
+ export declare function createPackageImporterAsync(opts: {
6
+ importIndexedPackage?: ImportIndexedPackageAsync;
7
+ packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy';
8
+ storeDir: string;
9
+ }): ImportPackageFunctionAsync;
10
+ export declare function createCafsStore(storeDir: string, opts?: {
11
+ ignoreFile?: (filename: string) => boolean;
12
+ importPackage?: ImportIndexedPackage;
13
+ packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy';
14
+ cafsLocker?: CafsLocker;
15
+ }): Cafs;
package/lib/index.js ADDED
@@ -0,0 +1,105 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createIndexedPkgImporter } from '@pnpm/fs.indexed-pkg-importer';
4
+ import { createCafs, } from '@pnpm/store.cafs';
5
+ import memoize from 'memoize';
6
+ import { pathTemp } from 'path-temp';
7
+ export {};
8
+ export function createPackageImporterAsync(opts) {
9
+ const cachedImporterCreator = opts.importIndexedPackage
10
+ ? () => opts.importIndexedPackage
11
+ : memoize(createIndexedPkgImporter);
12
+ const packageImportMethod = opts.packageImportMethod;
13
+ const gfm = getFlatMap.bind(null, opts.storeDir);
14
+ return async (to, opts) => {
15
+ const { filesMap, isBuilt } = gfm(opts.filesResponse, opts.sideEffectsCacheKey);
16
+ const willBeBuilt = !isBuilt && opts.requiresBuild;
17
+ const pkgImportMethod = willBeBuilt
18
+ ? 'clone-or-copy'
19
+ : (opts.filesResponse.packageImportMethod ?? packageImportMethod);
20
+ const impPkg = cachedImporterCreator(pkgImportMethod);
21
+ const importMethod = await impPkg(to, {
22
+ disableRelinkLocalDirDeps: opts.disableRelinkLocalDirDeps,
23
+ filesMap,
24
+ resolvedFrom: opts.filesResponse.resolvedFrom,
25
+ force: opts.force,
26
+ keepModulesDir: Boolean(opts.keepModulesDir),
27
+ safeToSkip: opts.safeToSkip,
28
+ });
29
+ return { importMethod, isBuilt };
30
+ };
31
+ }
32
+ function createPackageImporter(opts) {
33
+ const cachedImporterCreator = opts.importIndexedPackage
34
+ ? () => opts.importIndexedPackage
35
+ : memoize(createIndexedPkgImporter);
36
+ const packageImportMethod = opts.packageImportMethod;
37
+ const gfm = getFlatMap.bind(null, opts.storeDir);
38
+ return (to, opts) => {
39
+ const { filesMap, isBuilt } = gfm(opts.filesResponse, opts.sideEffectsCacheKey);
40
+ const willBeBuilt = !isBuilt && opts.requiresBuild;
41
+ const pkgImportMethod = willBeBuilt
42
+ ? 'clone-or-copy'
43
+ : (opts.filesResponse.packageImportMethod ?? packageImportMethod);
44
+ const impPkg = cachedImporterCreator(pkgImportMethod);
45
+ const importMethod = impPkg(to, {
46
+ disableRelinkLocalDirDeps: opts.disableRelinkLocalDirDeps,
47
+ filesMap,
48
+ resolvedFrom: opts.filesResponse.resolvedFrom,
49
+ force: opts.force,
50
+ keepModulesDir: Boolean(opts.keepModulesDir),
51
+ safeToSkip: opts.safeToSkip,
52
+ });
53
+ return { importMethod, isBuilt };
54
+ };
55
+ }
56
+ function getFlatMap(storeDir, filesResponse, targetEngine) {
57
+ if (targetEngine && filesResponse.sideEffectsMaps?.has(targetEngine)) {
58
+ const sideEffectMap = filesResponse.sideEffectsMaps.get(targetEngine);
59
+ const filesMap = applySideEffectsDiffWithMaps(filesResponse.filesMap, sideEffectMap);
60
+ return {
61
+ filesMap,
62
+ isBuilt: true,
63
+ };
64
+ }
65
+ return {
66
+ filesMap: filesResponse.filesMap,
67
+ isBuilt: false,
68
+ };
69
+ }
70
+ // Apply side effects when we already have file location maps (fast path)
71
+ function applySideEffectsDiffWithMaps(baseFiles, { added, deleted }) {
72
+ const filesWithSideEffects = new Map();
73
+ // Add side effect files (already have file paths)
74
+ if (added) {
75
+ for (const [name, filePath] of added.entries()) {
76
+ filesWithSideEffects.set(name, filePath);
77
+ }
78
+ }
79
+ // Add base files that weren't deleted
80
+ for (const [fileName, filePath] of baseFiles) {
81
+ if (!deleted?.includes(fileName) && !filesWithSideEffects.has(fileName)) {
82
+ filesWithSideEffects.set(fileName, filePath);
83
+ }
84
+ }
85
+ return filesWithSideEffects;
86
+ }
87
+ export function createCafsStore(storeDir, opts) {
88
+ const baseTempDir = path.join(storeDir, 'tmp');
89
+ const importPackage = createPackageImporter({
90
+ importIndexedPackage: opts?.importPackage,
91
+ packageImportMethod: opts?.packageImportMethod,
92
+ storeDir,
93
+ });
94
+ return {
95
+ ...createCafs(storeDir, opts),
96
+ storeDir,
97
+ importPackage,
98
+ tempDir: async () => {
99
+ const tmpDir = pathTemp(baseTempDir);
100
+ await fs.mkdir(tmpDir, { recursive: true });
101
+ return tmpDir;
102
+ },
103
+ };
104
+ }
105
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@pnpm/store.create-cafs-store",
3
+ "version": "1000.0.20",
4
+ "description": "Create a CAFS store controller",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "cache",
9
+ "central storage",
10
+ "global store",
11
+ "maching store",
12
+ "packages",
13
+ "storage",
14
+ "store"
15
+ ],
16
+ "license": "MIT",
17
+ "funding": "https://opencollective.com/pnpm",
18
+ "repository": "https://github.com/pnpm/pnpm/tree/main/store/create-cafs-store",
19
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/store/create-cafs-store#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/pnpm/pnpm/issues"
22
+ },
23
+ "type": "module",
24
+ "main": "lib/index.js",
25
+ "types": "lib/index.d.ts",
26
+ "exports": {
27
+ ".": "./lib/index.js"
28
+ },
29
+ "files": [
30
+ "lib",
31
+ "!*.map"
32
+ ],
33
+ "directories": {
34
+ "test": "test"
35
+ },
36
+ "dependencies": {
37
+ "memoize": "^10.2.0",
38
+ "path-temp": "^3.0.0",
39
+ "ramda": "npm:@pnpm/ramda@0.28.1",
40
+ "@pnpm/building.pkg-requires-build": "1000.0.0-0",
41
+ "@pnpm/fetching.fetcher-base": "1001.0.2",
42
+ "@pnpm/store.cafs": "1000.0.19",
43
+ "@pnpm/store.controller-types": "1004.1.0",
44
+ "@pnpm/fs.indexed-pkg-importer": "1000.1.14"
45
+ },
46
+ "peerDependencies": {
47
+ "@pnpm/logger": ">=1001.0.0 <1002.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/ramda": "0.29.12",
51
+ "@pnpm/logger": "1001.0.1",
52
+ "@pnpm/prepare": "1000.0.4",
53
+ "@pnpm/store.create-cafs-store": "1000.0.20",
54
+ "@pnpm/store.cafs-types": "1000.0.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=22.13"
58
+ },
59
+ "jest": {
60
+ "preset": "@pnpm/jest-config"
61
+ },
62
+ "scripts": {
63
+ "start": "tsgo --watch",
64
+ "fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix",
65
+ "lint": "eslint \"src/**/*.ts\"",
66
+ "test": "pnpm run compile",
67
+ "compile": "tsgo --build && pnpm run lint --fix"
68
+ }
69
+ }