@pnpm/installing.modules-yaml 1000.3.6

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,45 @@
1
+ # @pnpm/modules-yaml
2
+
3
+ > Reads/writes \`node_modules/.modules.yaml\`
4
+
5
+ <!--@shields('npm')-->
6
+ [![npm version](https://img.shields.io/npm/v/@pnpm/modules-yaml.svg)](https://www.npmjs.com/package/@pnpm/modules-yaml)
7
+ <!--/@-->
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ pnpm add @pnpm/modules-yaml
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import {write, read} from '@pnpm/modules-yaml'
19
+
20
+ await write('node_modules', {
21
+ hoistedAliases: {},
22
+ layoutVersion: 1,
23
+ packageManager: 'pnpm@1.0.0',
24
+ pendingBuilds: [],
25
+ shamefullyFlatten: false,
26
+ skipped: [],
27
+ storeDir: '/home/user/.pnpm-store',
28
+ })
29
+
30
+ const modulesYaml = await read(`node_modules`)
31
+ ```
32
+
33
+ ## API
34
+
35
+ ### `read(pathToDir): Promise<ModulesObject>`
36
+
37
+ Reads `.modules.yaml` from the specified directory.
38
+
39
+ ### `write(pathToDir, ModulesObject): Promise<void>`
40
+
41
+ Writes a `.modules.yaml` file to the specified directory.
42
+
43
+ ## License
44
+
45
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { DependenciesField, DepPath, HoistedDependencies, IgnoredBuilds, Registries } from '@pnpm/types';
2
+ export type IncludedDependencies = {
3
+ [dependenciesField in DependenciesField]: boolean;
4
+ };
5
+ interface ModulesRaw {
6
+ hoistedAliases?: {
7
+ [depPath: DepPath]: string[];
8
+ };
9
+ hoistedDependencies: HoistedDependencies;
10
+ hoistPattern?: string[];
11
+ included: IncludedDependencies;
12
+ layoutVersion: number;
13
+ nodeLinker?: 'hoisted' | 'isolated' | 'pnp';
14
+ packageManager: string;
15
+ pendingBuilds: string[];
16
+ ignoredBuilds?: DepPath[];
17
+ prunedAt: string;
18
+ registries?: Registries;
19
+ shamefullyHoist?: boolean;
20
+ publicHoistPattern?: string[];
21
+ skipped: string[];
22
+ storeDir: string;
23
+ virtualStoreDir: string;
24
+ virtualStoreDirMaxLength: number;
25
+ injectedDeps?: Record<string, string[]>;
26
+ hoistedLocations?: Record<string, string[]>;
27
+ allowBuilds?: Record<string, boolean | string>;
28
+ }
29
+ export type Modules = Omit<ModulesRaw, 'ignoredBuilds'> & {
30
+ ignoredBuilds?: IgnoredBuilds;
31
+ };
32
+ export declare function readModulesManifest(modulesDir: string): Promise<Modules | null>;
33
+ export interface StrictModules extends Modules {
34
+ registries: Registries;
35
+ }
36
+ export declare function writeModulesManifest(modulesDir: string, modules: StrictModules): Promise<void>;
37
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,90 @@
1
+ import path from 'node:path';
2
+ import fs from '@pnpm/fs.graceful-fs';
3
+ import isWindows from 'is-windows';
4
+ import { map as mapValues } from 'ramda';
5
+ import { readYamlFile } from 'read-yaml-file';
6
+ // The dot prefix is needed because otherwise `npm shrinkwrap`
7
+ // thinks that it is an extraneous package.
8
+ const MODULES_FILENAME = '.modules.yaml';
9
+ export async function readModulesManifest(modulesDir) {
10
+ const modulesYamlPath = path.join(modulesDir, MODULES_FILENAME);
11
+ let modulesRaw;
12
+ try {
13
+ modulesRaw = await readYamlFile(modulesYamlPath);
14
+ if (!modulesRaw)
15
+ return modulesRaw;
16
+ }
17
+ catch (err) { // eslint-disable-line
18
+ if (err.code !== 'ENOENT') {
19
+ throw err;
20
+ }
21
+ return null;
22
+ }
23
+ const modules = {
24
+ ...modulesRaw,
25
+ ignoredBuilds: modulesRaw.ignoredBuilds ? new Set(modulesRaw.ignoredBuilds) : undefined,
26
+ };
27
+ if (!modules.virtualStoreDir) {
28
+ modules.virtualStoreDir = path.join(modulesDir, '.pnpm');
29
+ }
30
+ else if (!path.isAbsolute(modules.virtualStoreDir)) {
31
+ modules.virtualStoreDir = path.join(modulesDir, modules.virtualStoreDir);
32
+ }
33
+ switch (modules.shamefullyHoist) {
34
+ case true:
35
+ if (modules.publicHoistPattern == null) {
36
+ modules.publicHoistPattern = ['*'];
37
+ }
38
+ if ((modules.hoistedAliases != null) && !modules.hoistedDependencies) {
39
+ modules.hoistedDependencies = mapValues((aliases) => Object.fromEntries(aliases.map((alias) => [alias, 'public'])), modules.hoistedAliases);
40
+ }
41
+ break;
42
+ case false:
43
+ if (modules.publicHoistPattern == null) {
44
+ modules.publicHoistPattern = [];
45
+ }
46
+ if ((modules.hoistedAliases != null) && !modules.hoistedDependencies) {
47
+ modules.hoistedDependencies = {};
48
+ for (const depPath of Object.keys(modules.hoistedAliases)) {
49
+ modules.hoistedDependencies[depPath] = {};
50
+ for (const alias of modules.hoistedAliases[depPath]) {
51
+ modules.hoistedDependencies[depPath][alias] = 'private';
52
+ }
53
+ }
54
+ }
55
+ break;
56
+ }
57
+ if (!modules.prunedAt) {
58
+ modules.prunedAt = new Date().toUTCString();
59
+ }
60
+ if (!modules.virtualStoreDirMaxLength) {
61
+ modules.virtualStoreDirMaxLength = 120;
62
+ }
63
+ return modules;
64
+ }
65
+ export async function writeModulesManifest(modulesDir, modules) {
66
+ const modulesYamlPath = path.join(modulesDir, MODULES_FILENAME);
67
+ const saveModules = { ...modules, ignoredBuilds: modules.ignoredBuilds ? Array.from(modules.ignoredBuilds) : undefined };
68
+ if (saveModules.skipped)
69
+ saveModules.skipped.sort();
70
+ if (saveModules.hoistPattern == null || saveModules.hoistPattern === '') {
71
+ // Because the YAML writer fails on undefined fields
72
+ delete saveModules.hoistPattern;
73
+ }
74
+ if (saveModules.publicHoistPattern == null) {
75
+ delete saveModules.publicHoistPattern;
76
+ }
77
+ if ((saveModules.hoistedAliases == null) || (saveModules.hoistPattern == null) && (saveModules.publicHoistPattern == null)) {
78
+ delete saveModules.hoistedAliases;
79
+ }
80
+ // We should store the absolute virtual store directory path on Windows
81
+ // because junctions are used on Windows. Junctions will break even if
82
+ // the relative path to the virtual store remains the same after moving
83
+ // a project.
84
+ if (!isWindows()) {
85
+ saveModules.virtualStoreDir = path.relative(modulesDir, saveModules.virtualStoreDir);
86
+ }
87
+ await fs.mkdir(modulesDir, { recursive: true });
88
+ await fs.writeFile(modulesYamlPath, JSON.stringify(saveModules, null, 2));
89
+ }
90
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@pnpm/installing.modules-yaml",
3
+ "version": "1000.3.6",
4
+ "description": "Reads/writes `node_modules/.modules.yaml`",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "modules.yaml"
9
+ ],
10
+ "license": "MIT",
11
+ "funding": "https://opencollective.com/pnpm",
12
+ "repository": "https://github.com/pnpm/pnpm/tree/main/installing/modules-yaml",
13
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/installing/modules-yaml#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
+ "is-windows": "^1.0.2",
29
+ "ramda": "npm:@pnpm/ramda@0.28.1",
30
+ "read-yaml-file": "^3.0.0",
31
+ "@pnpm/types": "1000.9.0",
32
+ "@pnpm/fs.graceful-fs": "1000.0.1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/is-windows": "^1.0.2",
36
+ "@types/ramda": "0.29.12",
37
+ "tempy": "3.0.0",
38
+ "@pnpm/installing.modules-yaml": "1000.3.6"
39
+ },
40
+ "engines": {
41
+ "node": ">=22.13"
42
+ },
43
+ "jest": {
44
+ "preset": "@pnpm/jest-config"
45
+ },
46
+ "scripts": {
47
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
48
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
49
+ "test": "pnpm run compile && pnpm run _test",
50
+ "fix": "tslint -c tslint.json src/**/*.ts test/**/*.ts --fix",
51
+ "compile": "tsgo --build && pnpm run lint --fix"
52
+ }
53
+ }