@pnpm/workspace.injected-deps-syncer 1000.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 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-2025 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/workspace.injected-deps-syncer
2
+
3
+ > Update all injected replica of a workspace package
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pnpm/workspace.injected-deps-syncer.svg)](https://www.npmjs.com/package/@pnpm/workspace.injected-deps-syncer)
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @pnpm/workspace.injected-deps-syncer
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT
@@ -0,0 +1,66 @@
1
+ import fs from 'fs';
2
+ export declare const DIR: unique symbol;
3
+ export type File = number;
4
+ export type Dir = typeof DIR;
5
+ export type Value = File | Dir;
6
+ export type InodeMap = Record<string, Value>;
7
+ export interface DiffItemBase {
8
+ path: string;
9
+ oldValue?: Value;
10
+ newValue?: Value;
11
+ }
12
+ export interface AddedItem extends DiffItemBase {
13
+ path: string;
14
+ oldValue?: undefined;
15
+ newValue: Value;
16
+ }
17
+ export interface RemovedItem extends DiffItemBase {
18
+ path: string;
19
+ oldValue: Value;
20
+ newValue?: undefined;
21
+ }
22
+ export interface ModifiedItem extends DiffItemBase {
23
+ path: string;
24
+ oldValue: Value;
25
+ newValue: Value;
26
+ }
27
+ export interface DirDiff {
28
+ added: AddedItem[];
29
+ removed: RemovedItem[];
30
+ modified: ModifiedItem[];
31
+ }
32
+ /**
33
+ * Get the difference between 2 files tree.
34
+ *
35
+ * The arrays in the resulting object are sorted in such a way that every directory paths are placed before
36
+ * the files it contains. This way, it would allow optimization for operations upon this diff.
37
+ * Note that when performing removal of removed files according to this diff, the `removed` array should be reversed first.
38
+ */
39
+ export declare function diffDir(oldIndex: InodeMap, newIndex: InodeMap): DirDiff;
40
+ /**
41
+ * Apply a patch on a directory.
42
+ *
43
+ * The {@link optimizedDirPatch} is assumed to be already optimized (i.e. `removed` is already reversed).
44
+ */
45
+ export declare function applyPatch(optimizedDirPatch: DirDiff, sourceDir: string, targetDir: string): Promise<void>;
46
+ export type ExtendFilesMapStats = Pick<fs.Stats, 'ino' | 'isFile' | 'isDirectory'>;
47
+ export interface ExtendFilesMapOptions {
48
+ /** Map relative path of each file to their real path */
49
+ filesIndex: Record<string, string>;
50
+ /** Map relative path of each file to their stats */
51
+ filesStats?: Record<string, ExtendFilesMapStats | null>;
52
+ }
53
+ /**
54
+ * Convert a pair of a files index map, which is a map from relative path of each file to their real paths,
55
+ * and an optional file stats map, which is a map from relative path of each file to their stats,
56
+ * into an inodes map, which is a map from relative path of every file and directory to their inode type.
57
+ */
58
+ export declare function extendFilesMap({ filesIndex, filesStats }: ExtendFilesMapOptions): Promise<InodeMap>;
59
+ export declare class DirPatcher {
60
+ private readonly sourceDir;
61
+ private readonly targetDir;
62
+ private readonly patch;
63
+ private constructor();
64
+ static fromMultipleTargets(sourceDir: string, targetDirs: string[]): Promise<DirPatcher[]>;
65
+ apply(): Promise<void>;
66
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DirPatcher = exports.DIR = void 0;
7
+ exports.diffDir = diffDir;
8
+ exports.applyPatch = applyPatch;
9
+ exports.extendFilesMap = extendFilesMap;
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const util_1 = __importDefault(require("util"));
13
+ const directory_fetcher_1 = require("@pnpm/directory-fetcher");
14
+ const error_1 = require("@pnpm/error");
15
+ exports.DIR = Symbol('Path is a directory');
16
+ // length comparison should place every directory before the files it contains because
17
+ // a directory path is always shorter than any file path it contains
18
+ const comparePaths = (a, b) => (a.split(/\\|\//).length - b.split(/\\|\//).length) || a.localeCompare(b);
19
+ /**
20
+ * Get the difference between 2 files tree.
21
+ *
22
+ * The arrays in the resulting object are sorted in such a way that every directory paths are placed before
23
+ * the files it contains. This way, it would allow optimization for operations upon this diff.
24
+ * Note that when performing removal of removed files according to this diff, the `removed` array should be reversed first.
25
+ */
26
+ function diffDir(oldIndex, newIndex) {
27
+ const oldPaths = Object.keys(oldIndex).sort(comparePaths);
28
+ const newPaths = Object.keys(newIndex).sort(comparePaths);
29
+ const removed = oldPaths
30
+ .filter(path => !(path in newIndex))
31
+ .map(path => ({ path, oldValue: oldIndex[path] }));
32
+ const added = newPaths
33
+ .filter(path => !(path in oldIndex))
34
+ .map(path => ({ path, newValue: newIndex[path] }));
35
+ const modified = oldPaths
36
+ .filter(path => path in newIndex && oldIndex[path] !== newIndex[path])
37
+ .map(path => ({ path, oldValue: oldIndex[path], newValue: newIndex[path] }));
38
+ return { added, removed, modified };
39
+ }
40
+ /**
41
+ * Apply a patch on a directory.
42
+ *
43
+ * The {@link optimizedDirPatch} is assumed to be already optimized (i.e. `removed` is already reversed).
44
+ */
45
+ async function applyPatch(optimizedDirPatch, sourceDir, targetDir) {
46
+ async function addRecursive(sourcePath, targetPath, value) {
47
+ if (value === exports.DIR) {
48
+ await fs_1.default.promises.mkdir(targetPath, { recursive: true });
49
+ }
50
+ else if (typeof value === 'number') {
51
+ fs_1.default.mkdirSync(path_1.default.dirname(targetPath), { recursive: true });
52
+ await fs_1.default.promises.link(sourcePath, targetPath);
53
+ }
54
+ else {
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
56
+ const _ = value; // static type guard
57
+ }
58
+ }
59
+ async function removeRecursive(targetPath) {
60
+ try {
61
+ await fs_1.default.promises.rm(targetPath, { recursive: true, force: true });
62
+ }
63
+ catch (error) {
64
+ if (!util_1.default.types.isNativeError(error) || !('code' in error) || (error.code !== 'ENOENT')) {
65
+ throw error;
66
+ }
67
+ }
68
+ }
69
+ const adding = Promise.all(optimizedDirPatch.added.map(async (item) => {
70
+ const sourcePath = path_1.default.join(sourceDir, item.path);
71
+ const targetPath = path_1.default.join(targetDir, item.path);
72
+ await addRecursive(sourcePath, targetPath, item.newValue);
73
+ }));
74
+ const removing = Promise.all(optimizedDirPatch.removed.map(async (item) => {
75
+ const targetPath = path_1.default.join(targetDir, item.path);
76
+ await removeRecursive(targetPath);
77
+ }));
78
+ const modifying = Promise.all(optimizedDirPatch.modified.map(async (item) => {
79
+ const sourcePath = path_1.default.join(sourceDir, item.path);
80
+ const targetPath = path_1.default.join(targetDir, item.path);
81
+ if (item.oldValue === item.newValue)
82
+ return;
83
+ await removeRecursive(targetPath);
84
+ await addRecursive(sourcePath, targetPath, item.newValue);
85
+ }));
86
+ await Promise.all([adding, removing, modifying]);
87
+ }
88
+ /**
89
+ * Convert a pair of a files index map, which is a map from relative path of each file to their real paths,
90
+ * and an optional file stats map, which is a map from relative path of each file to their stats,
91
+ * into an inodes map, which is a map from relative path of every file and directory to their inode type.
92
+ */
93
+ async function extendFilesMap({ filesIndex, filesStats }) {
94
+ const result = {
95
+ '.': exports.DIR,
96
+ };
97
+ function addInodeAndAncestors(relativePath, value) {
98
+ if (relativePath && relativePath !== '.' && !result[relativePath]) {
99
+ result[relativePath] = value;
100
+ addInodeAndAncestors(path_1.default.dirname(relativePath), exports.DIR);
101
+ }
102
+ }
103
+ await Promise.all(Object.entries(filesIndex).map(async ([relativePath, realPath]) => {
104
+ const stats = filesStats?.[relativePath] ?? await fs_1.default.promises.stat(realPath);
105
+ if (stats.isFile()) {
106
+ addInodeAndAncestors(relativePath, stats.ino);
107
+ }
108
+ else if (stats.isDirectory()) {
109
+ addInodeAndAncestors(relativePath, exports.DIR);
110
+ }
111
+ else {
112
+ throw new error_1.PnpmError('UNSUPPORTED_INODE_TYPE', `Filesystem inode at ${realPath} is neither a file, a directory, or a symbolic link`);
113
+ }
114
+ }));
115
+ return result;
116
+ }
117
+ class DirPatcher {
118
+ constructor(patch, sourceDir, targetDir) {
119
+ this.patch = patch;
120
+ this.sourceDir = sourceDir;
121
+ this.targetDir = targetDir;
122
+ }
123
+ static async fromMultipleTargets(sourceDir, targetDirs) {
124
+ const fetchOptions = {
125
+ resolveSymlinks: false,
126
+ };
127
+ async function loadMap(dir) {
128
+ const fetchResult = await (0, directory_fetcher_1.fetchFromDir)(dir, fetchOptions);
129
+ return [await extendFilesMap(fetchResult), dir];
130
+ }
131
+ const [[sourceMap], targetPairs] = await Promise.all([
132
+ loadMap(sourceDir),
133
+ Promise.all(targetDirs.map(loadMap)),
134
+ ]);
135
+ return targetPairs.map(([targetMap, targetDir]) => {
136
+ const diff = diffDir(targetMap, sourceMap);
137
+ // Before reversal, every directory in `diff.removed` are placed before its files.
138
+ // After reversal, every file is place before its ancestors,
139
+ // leading to children being deleted before parents, optimizing performance.
140
+ diff.removed.reverse();
141
+ return new this(diff, sourceDir, targetDir);
142
+ });
143
+ }
144
+ async apply() {
145
+ await applyPatch(this.patch, this.sourceDir, this.targetDir);
146
+ }
147
+ }
148
+ exports.DirPatcher = DirPatcher;
149
+ //# sourceMappingURL=DirPatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirPatcher.js","sourceRoot":"","sources":["../src/DirPatcher.ts"],"names":[],"mappings":";;;;;;AAyDA,0BAiBC;AAOD,gCA2CC;AAgBD,wCAwBC;AApKD,4CAAmB;AACnB,gDAAuB;AACvB,gDAAuB;AACvB,+DAAgF;AAChF,uCAAuC;AAE1B,QAAA,GAAG,GAAkB,MAAM,CAAC,qBAAqB,CAAC,CAAA;AAwC/D,sFAAsF;AACtF,oEAAoE;AACpE,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;AAEhI;;;;;;GAMG;AACH,SAAgB,OAAO,CAAE,QAAkB,EAAE,QAAkB;IAC7D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACzD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAEzD,MAAM,OAAO,GAAkB,QAAQ;SACpC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC;SACnC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC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EF,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE;YAChD,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YAE1C,kFAAkF;YAClF,4DAA4D;YAC5D,4EAA4E;YAC5E,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;YAEtB,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IAC9D,CAAC;CACF;AAzCD,gCAyCC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export interface SyncInjectedDepsOptions {
2
+ pkgName: string | undefined;
3
+ pkgRootDir: string;
4
+ workspaceDir: string | undefined;
5
+ }
6
+ export declare function syncInjectedDeps(opts: SyncInjectedDepsOptions): Promise<void>;
package/lib/index.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.syncInjectedDeps = syncInjectedDeps;
7
+ const path_1 = __importDefault(require("path"));
8
+ const error_1 = require("@pnpm/error");
9
+ const logger_1 = require("@pnpm/logger");
10
+ const modules_yaml_1 = require("@pnpm/modules-yaml");
11
+ const normalize_path_1 = __importDefault(require("normalize-path"));
12
+ const DirPatcher_1 = require("./DirPatcher");
13
+ const logger = (0, logger_1.logger)('skip-sync-injected-deps');
14
+ async function syncInjectedDeps(opts) {
15
+ if (!opts.pkgName) {
16
+ logger.debug({
17
+ reason: 'no-name',
18
+ message: `Skipping sync of ${opts.pkgRootDir} as an injected dependency because, without a name, it cannot be a dependency`,
19
+ opts,
20
+ });
21
+ return;
22
+ }
23
+ if (!opts.workspaceDir) {
24
+ throw new error_1.PnpmError('NO_WORKSPACE_DIR', 'Cannot update injected dependencies without workspace dir');
25
+ }
26
+ const pkgRootDir = path_1.default.resolve(opts.workspaceDir, opts.pkgRootDir);
27
+ const modulesDir = path_1.default.resolve(opts.workspaceDir, 'node_modules');
28
+ const modules = await (0, modules_yaml_1.readModulesManifest)(modulesDir);
29
+ if (!modules?.injectedDeps) {
30
+ logger.debug({
31
+ reason: 'no-injected-deps',
32
+ message: 'Skipping sync of injected dependencies because none were detected',
33
+ opts,
34
+ });
35
+ return;
36
+ }
37
+ const injectedDepKey = (0, normalize_path_1.default)(path_1.default.relative(opts.workspaceDir, pkgRootDir), true);
38
+ const targetDirs = modules.injectedDeps[injectedDepKey];
39
+ if (!targetDirs || targetDirs.length === 0) {
40
+ logger.debug({
41
+ reason: 'no-injected-deps',
42
+ message: `There are no injected dependencies from ${opts.pkgRootDir}`,
43
+ opts,
44
+ });
45
+ return;
46
+ }
47
+ const patchers = await DirPatcher_1.DirPatcher.fromMultipleTargets(pkgRootDir, targetDirs.map(targetDir => path_1.default.resolve(opts.workspaceDir, targetDir)));
48
+ await Promise.all(patchers.map(patcher => patcher.apply()));
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAqBA,4CAsCC;AA3DD,gDAAuB;AACvB,uCAAuC;AACvC,yCAAqD;AACrD,qDAAwD;AACxD,oEAA0C;AAC1C,6CAAyC;AAQzC,MAAM,MAAM,GAAG,IAAA,eAAY,EAA8B,yBAAyB,CAAC,CAAA;AAQ5E,KAAK,UAAU,gBAAgB,CAAE,IAA6B;IACnE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC;YACX,MAAM,EAAE,SAAS;YACjB,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AC,IAAI,CAAC,YAAa,EAAE,SAAS,CAAC,CAAC,CACzE,CAAA;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AAC7D,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@pnpm/workspace.injected-deps-syncer",
3
+ "version": "1000.0.0",
4
+ "description": "Update all injected replica of a workspace package",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "!*.map"
10
+ ],
11
+ "engines": {
12
+ "node": ">=18.12"
13
+ },
14
+ "repository": "https://github.com/pnpm/pnpm/blob/main/workspace/injected-deps-syncer",
15
+ "keywords": [
16
+ "pnpm10",
17
+ "pnpm"
18
+ ],
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://github.com/pnpm/pnpm/issues"
22
+ },
23
+ "homepage": "https://github.com/pnpm/pnpm/blob/main/workspace/injected-deps-syncer#readme",
24
+ "funding": "https://opencollective.com/pnpm",
25
+ "dependencies": {
26
+ "@types/normalize-path": "^3.0.2",
27
+ "normalize-path": "^3.0.0",
28
+ "@pnpm/error": "1000.0.2",
29
+ "@pnpm/modules-yaml": "1000.1.3",
30
+ "@pnpm/logger": "1000.0.0",
31
+ "@pnpm/directory-fetcher": "1000.1.0"
32
+ },
33
+ "devDependencies": {
34
+ "@pnpm/prepare": "0.0.112",
35
+ "@pnpm/workspace.injected-deps-syncer": "1000.0.0"
36
+ },
37
+ "exports": {
38
+ ".": "./lib/index.js"
39
+ },
40
+ "jest": {
41
+ "preset": "@pnpm/jest-config"
42
+ },
43
+ "scripts": {
44
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
45
+ "test": "pnpm run compile && pnpm run _test",
46
+ "compile": "tsc --build && pnpm run lint --fix",
47
+ "_test": "jest"
48
+ }
49
+ }