pnpm-ws-link 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/README.md ADDED
@@ -0,0 +1 @@
1
+ # pnpm-ws-link
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, writeFileSync } from 'fs';
3
+ import { resolve, join, dirname, relative } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { glob } from 'glob';
6
+ import * as yaml from 'js-yaml';
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ /* ------------------------------------------------------------------ */
9
+ /* helpers */
10
+ /* ------------------------------------------------------------------ */
11
+ const readJSON = (p) => JSON.parse(readFileSync(p, 'utf8'));
12
+ /* ------------------------------------------------------------------ */
13
+ /* main logic */
14
+ /* ------------------------------------------------------------------ */
15
+ const args = process.argv.slice(2);
16
+ const dry = args.includes('--dry');
17
+ const packageDirs = args.filter((arg) => arg !== '--dry');
18
+ if (packageDirs.length === 0) {
19
+ console.error('Usage: node dist/index.js [--dry] <package-dir> [more dirs...]');
20
+ process.exit(1);
21
+ }
22
+ const overrides = {};
23
+ for (const packageDir of packageDirs) {
24
+ const pkgPath = join(packageDir, 'package.json');
25
+ const pkg = readJSON(pkgPath);
26
+ // add the package itself
27
+ overrides[pkg.name] = `link:${relative(process.cwd(), resolve(packageDir))}`;
28
+ // collect workspace deps
29
+ let wsPkgs;
30
+ const deps = pkg.dependencies;
31
+ if (deps) {
32
+ if (!deps)
33
+ continue;
34
+ for (const [name, range] of Object.entries(deps)) {
35
+ if (range.startsWith('workspace:')) {
36
+ if (!wsPkgs) {
37
+ // find workspace root
38
+ let root = resolve(packageDir);
39
+ while (root !== dirname(root)) {
40
+ try {
41
+ readFileSync(join(root, 'pnpm-workspace.yaml'));
42
+ break;
43
+ }
44
+ catch {
45
+ root = dirname(root);
46
+ }
47
+ }
48
+ if (root === dirname(root))
49
+ throw new Error(`pnpm-workspace.yaml not found for ${packageDir}`);
50
+ // load workspace config
51
+ const wsFile = join(root, 'pnpm-workspace.yaml');
52
+ const wsConfig = yaml.load(readFileSync(wsFile, 'utf8'));
53
+ // find all package.json files
54
+ const pkgPaths = [];
55
+ for (const pattern of wsConfig.packages) {
56
+ const matches = glob.sync(join(root, pattern, 'package.json'));
57
+ pkgPaths.push(...matches);
58
+ }
59
+ // read packages
60
+ wsPkgs = pkgPaths.map((p) => ({ ...readJSON(p), dir: dirname(p) }));
61
+ }
62
+ const depPkg = wsPkgs.find((p) => p.name === name);
63
+ if (!depPkg)
64
+ throw new Error(`workspace dep "${name}" not found for ${packageDir}`);
65
+ overrides[name] = `link:${relative(process.cwd(), depPkg.dir)}`;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ if (dry) {
71
+ console.log('"pnpm": {');
72
+ console.log(' "overrides": {');
73
+ console.log(Object.entries(overrides)
74
+ .sort(([a], [b]) => a.localeCompare(b))
75
+ .map(([k, v]) => ` "${k}": "${v}"`)
76
+ .join(',\n'));
77
+ console.log(' }');
78
+ console.log('}');
79
+ }
80
+ else {
81
+ // modify current repo's package.json
82
+ const currentPkgPath = join(process.cwd(), 'package.json');
83
+ const currentPkg = readJSON(currentPkgPath);
84
+ if (!currentPkg.pnpm)
85
+ currentPkg.pnpm = {};
86
+ if (!currentPkg.pnpm.overrides)
87
+ currentPkg.pnpm.overrides = {};
88
+ Object.assign(currentPkg.pnpm.overrides, overrides);
89
+ writeFileSync(currentPkgPath, JSON.stringify(currentPkg, null, 2));
90
+ console.log('Overrides added to package.json');
91
+ }
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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AO,CAAC,GAAG,CAAC;SACrC,IAAI,CAAC,KAAK,CAAC,CACb,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC;KAAM,CAAC;IACP,qCAAqC;IACrC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAQ,CAAC;IAEnD,IAAI,CAAC,UAAU,CAAC,IAAI;QAAE,UAAU,CAAC,IAAI,GAAG,EAAE,CAAC;IAC3C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS;QAAE,UAAU,CAAC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IAE/D,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEpD,aAAa,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAEnE,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AAChD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "pnpm-ws-link",
3
+ "version": "0.0.0",
4
+ "description": "generate overrides from a folder, including monorepo packages",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "bin": {
13
+ "pnpm-ws-link": "dist/index.js"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "devDependencies": {
27
+ "@types/js-yaml": "^4.0.9",
28
+ "@types/node": "^25.0.3",
29
+ "as-soon": "^0.0.11",
30
+ "typescript": "^5.9.3",
31
+ "viem": "^2.41.2"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc --project tsconfig.json",
35
+ "dev": "as-soon -w src pnpm build"
36
+ },
37
+ "dependencies": {
38
+ "glob": "^10.4.5",
39
+ "js-yaml": "^4.1.1"
40
+ }
41
+ }