pnpm-ws-link 0.0.0 → 0.0.2
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 +21 -0
- package/README.md +67 -0
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +17 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ronan Sandford
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
1
|
# pnpm-ws-link
|
|
2
|
+
|
|
3
|
+
A CLI tool to generate pnpm overrides for linking external workspace packages.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
`pnpm-ws-link` helps you link packages from external monorepos into your current project by automatically generating the necessary `pnpm.overrides` in your `package.json`. It scans the provided package directories, identifies their `workspace:` dependencies, resolves the paths, and adds link overrides.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g pnpm-ws-link
|
|
13
|
+
# or
|
|
14
|
+
pnpm add -g pnpm-ws-link
|
|
15
|
+
# or if you use volta
|
|
16
|
+
volta install pnpm-ws-link
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Run the command in the root of the repository where you want to add the overrides:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm-ws-link /path/to/external/package1 /path/to/external/package2
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This will:
|
|
28
|
+
|
|
29
|
+
- Read the `package.json` of each specified package directory.
|
|
30
|
+
- Add the packages themselves to the overrides.
|
|
31
|
+
- For any `workspace:` dependencies in their `dependencies` field, resolve their paths and add them to overrides.
|
|
32
|
+
- Update your `package.json` with the new `pnpm.overrides`.
|
|
33
|
+
|
|
34
|
+
### Options
|
|
35
|
+
|
|
36
|
+
- `--dry`: Preview the overrides without modifying `package.json`.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm-ws-link --dry /path/to/external/package
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Example
|
|
43
|
+
|
|
44
|
+
Suppose you have an external monorepo with packages `pkg-a` and `pkg-b`, where `pkg-a` depends on `pkg-b` via `workspace:*`.
|
|
45
|
+
|
|
46
|
+
Running:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm-ws-link /external/repo/packages/pkg-a
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Will add to your `package.json`:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"pnpm": {
|
|
57
|
+
"overrides": {
|
|
58
|
+
"pkg-a": "link:../external/repo/packages/pkg-a",
|
|
59
|
+
"pkg-b": "link:../external/repo/packages/pkg-b"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Requirements
|
|
66
|
+
|
|
67
|
+
- The external packages must be in directories containing `package.json`.
|
|
68
|
+
- If a package has `workspace:` dependencies, the tool will look for `pnpm-workspace.yaml` upward from the package directory to resolve the workspace packages.
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,37 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
9
9
|
/* helpers */
|
|
10
10
|
/* ------------------------------------------------------------------ */
|
|
11
11
|
const readJSON = (p) => JSON.parse(readFileSync(p, 'utf8'));
|
|
12
|
+
/**
|
|
13
|
+
* Detects the indentation used in a package.json file
|
|
14
|
+
* @param filePath Path to the package.json file
|
|
15
|
+
* @returns The detected indentation (spaces or tabs)
|
|
16
|
+
*/
|
|
17
|
+
function detectIndentation(filePath) {
|
|
18
|
+
const content = readFileSync(filePath, 'utf8');
|
|
19
|
+
const lines = content.split('\n');
|
|
20
|
+
// Find the first line that starts with indentation (after the opening brace)
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
if (line.trim().startsWith('"') && (line.startsWith(' ') || line.startsWith('\t'))) {
|
|
23
|
+
// Count the number of spaces or tabs at the beginning
|
|
24
|
+
const match = line.match(/^(\s+)/);
|
|
25
|
+
if (match) {
|
|
26
|
+
return match[1]; // Return the detected indentation
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Default to 2 spaces if no indentation is detected
|
|
31
|
+
return ' ';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Stringifies JSON with the same formatting as the original file
|
|
35
|
+
* @param data The data to stringify
|
|
36
|
+
* @param originalContent The original file content for indentation detection
|
|
37
|
+
* @returns Formatted JSON string
|
|
38
|
+
*/
|
|
39
|
+
function stringifyWithOriginalFormatting(data, originalContent) {
|
|
40
|
+
const detectedIndentation = detectIndentation(originalContent);
|
|
41
|
+
return JSON.stringify(data, null, detectedIndentation);
|
|
42
|
+
}
|
|
12
43
|
/* ------------------------------------------------------------------ */
|
|
13
44
|
/* main logic */
|
|
14
45
|
/* ------------------------------------------------------------------ */
|
|
@@ -86,7 +117,9 @@ else {
|
|
|
86
117
|
if (!currentPkg.pnpm.overrides)
|
|
87
118
|
currentPkg.pnpm.overrides = {};
|
|
88
119
|
Object.assign(currentPkg.pnpm.overrides, overrides);
|
|
89
|
-
|
|
120
|
+
// Preserve the original formatting by reading the file content first
|
|
121
|
+
const originalContent = readFileSync(currentPkgPath, 'utf8');
|
|
122
|
+
writeFileSync(currentPkgPath, stringifyWithOriginalFormatting(currentPkg, originalContent));
|
|
90
123
|
console.log('Overrides added to package.json');
|
|
91
124
|
}
|
|
92
125
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,MAAM,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAEhC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AACxE,MAAM,QAAQ,GAAG,CAAc,CAAS,EAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAA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E,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;IAEjD,qEAAqE;IACrE,MAAM,eAAe,GAAG,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC7D,aAAa,CAAC,cAAc,EAAE,+BAA+B,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC;IAE/F,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pnpm-ws-link",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "generate overrides
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "CLI tool to generate pnpm overrides for linking external workspace packages",
|
|
5
|
+
"keywords": ["pnpm", "workspace", "link", "overrides", "monorepo"],
|
|
6
|
+
"author": "wighawag",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/wighawag/pnpm-ws-link.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/wighawag/pnpm-ws-link#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/wighawag/pnpm-ws-link/issues"
|
|
15
|
+
},
|
|
5
16
|
"publishConfig": {
|
|
6
17
|
"access": "public"
|
|
7
18
|
},
|
|
@@ -23,6 +34,10 @@
|
|
|
23
34
|
"files": [
|
|
24
35
|
"dist"
|
|
25
36
|
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"glob": "^10.4.5",
|
|
39
|
+
"js-yaml": "^4.1.1"
|
|
40
|
+
},
|
|
26
41
|
"devDependencies": {
|
|
27
42
|
"@types/js-yaml": "^4.0.9",
|
|
28
43
|
"@types/node": "^25.0.3",
|
|
@@ -33,9 +48,5 @@
|
|
|
33
48
|
"scripts": {
|
|
34
49
|
"build": "tsc --project tsconfig.json",
|
|
35
50
|
"dev": "as-soon -w src pnpm build"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"glob": "^10.4.5",
|
|
39
|
-
"js-yaml": "^4.1.1"
|
|
40
51
|
}
|
|
41
52
|
}
|