lllink 1.1.430
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/dist/index.mjs +70 -0
- package/package.json +31 -0
- package/src/index.ts +92 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readdir, readFile, stat, rm, symlink } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, relative, resolve } from "node:path";
|
|
5
|
+
const IGNORE_DIR = "node_modules";
|
|
6
|
+
async function findLocalPackages(rootDir) {
|
|
7
|
+
const results = {};
|
|
8
|
+
async function recurse(dir) {
|
|
9
|
+
let entries;
|
|
10
|
+
try {
|
|
11
|
+
entries = await readdir(dir);
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
await Promise.all(entries.map(async entry => {
|
|
16
|
+
if (entry === IGNORE_DIR) return;
|
|
17
|
+
const fullPath = join(dir, entry);
|
|
18
|
+
let entryStat;
|
|
19
|
+
try {
|
|
20
|
+
entryStat = await stat(fullPath);
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (entryStat.isDirectory()) {
|
|
25
|
+
const pkgJsonPath = join(fullPath, "package.json");
|
|
26
|
+
try {
|
|
27
|
+
if ((await stat(pkgJsonPath)).isFile()) {
|
|
28
|
+
const raw = await readFile(pkgJsonPath, "utf-8"),
|
|
29
|
+
pkgData = JSON.parse(raw);
|
|
30
|
+
pkgData.name && (results[pkgData.name] = fullPath);
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
await recurse(fullPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
return await recurse(rootDir), results;
|
|
39
|
+
}
|
|
40
|
+
async function linkPackages(localPackages) {
|
|
41
|
+
for (const pkgName of Object.keys(localPackages)) {
|
|
42
|
+
const nmPath = join(process.cwd(), "node_modules", ...pkgName.split("/"));
|
|
43
|
+
try {
|
|
44
|
+
if (await stat(nmPath)) {
|
|
45
|
+
await rm(nmPath, {
|
|
46
|
+
recursive: !0,
|
|
47
|
+
force: !0
|
|
48
|
+
});
|
|
49
|
+
const localPath = localPackages[pkgName];
|
|
50
|
+
console.info(`${relative(process.cwd(), nmPath)} -> ${localPath.replace(homedir(), "~")}`), await symlink(localPath, nmPath, "dir");
|
|
51
|
+
}
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function main() {
|
|
56
|
+
const args = process.argv.slice(2);
|
|
57
|
+
args.length === 0 && (console.info("No workspace directories provided."), process.exit(0));
|
|
58
|
+
const allLocalPackages = {};
|
|
59
|
+
for (const workspaceDir of args) {
|
|
60
|
+
const resolved = resolve(workspaceDir),
|
|
61
|
+
found = await findLocalPackages(resolved);
|
|
62
|
+
Object.assign(allLocalPackages, found);
|
|
63
|
+
}
|
|
64
|
+
await linkPackages(allLocalPackages), console.info(`
|
|
65
|
+
\u2713 linked ${Object.keys(allLocalPackages).length} packages`);
|
|
66
|
+
}
|
|
67
|
+
main().catch(err => {
|
|
68
|
+
console.error("Error:", err), process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=index.mjs.map
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lllink",
|
|
3
|
+
"version": "1.1.430",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"module": "dist",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"bin": "./dist/index.mjs",
|
|
13
|
+
"files": [
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tamagui-build --skip-types --skip-native",
|
|
18
|
+
"watch": "yarn build --watch",
|
|
19
|
+
"clean": "tamagui-build clean",
|
|
20
|
+
"clean:build": "tamagui-build clean:build",
|
|
21
|
+
"lint": "../../node_modules/.bin/biome check src",
|
|
22
|
+
"lint:fix": "../../node_modules/.bin/biome check --write --unsafe src"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@biomejs/biome": "^1.8.3",
|
|
26
|
+
"@tamagui/build": "^1.123.10"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Usage:
|
|
5
|
+
* bun run link-workspaces.ts <workspaceDir1> <workspaceDir2> ...
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readdir, readFile, stat, rm, symlink } from 'node:fs/promises'
|
|
9
|
+
import { homedir } from 'node:os'
|
|
10
|
+
import { join, relative, resolve } from 'node:path'
|
|
11
|
+
|
|
12
|
+
const IGNORE_DIR = 'node_modules'
|
|
13
|
+
|
|
14
|
+
async function findLocalPackages(rootDir: string): Promise<Record<string, string>> {
|
|
15
|
+
const results: Record<string, string> = {}
|
|
16
|
+
|
|
17
|
+
async function recurse(dir: string) {
|
|
18
|
+
let entries: string[]
|
|
19
|
+
try {
|
|
20
|
+
entries = await readdir(dir)
|
|
21
|
+
} catch {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await Promise.all(
|
|
26
|
+
entries.map(async (entry) => {
|
|
27
|
+
if (entry === IGNORE_DIR) return
|
|
28
|
+
const fullPath = join(dir, entry)
|
|
29
|
+
let entryStat
|
|
30
|
+
try {
|
|
31
|
+
entryStat = await stat(fullPath)
|
|
32
|
+
} catch {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
if (entryStat.isDirectory()) {
|
|
36
|
+
const pkgJsonPath = join(fullPath, 'package.json')
|
|
37
|
+
try {
|
|
38
|
+
const pkgJsonStat = await stat(pkgJsonPath)
|
|
39
|
+
if (pkgJsonStat.isFile()) {
|
|
40
|
+
const raw = await readFile(pkgJsonPath, 'utf-8')
|
|
41
|
+
const pkgData = JSON.parse(raw)
|
|
42
|
+
if (pkgData.name) {
|
|
43
|
+
results[pkgData.name] = fullPath
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
await recurse(fullPath)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await recurse(rootDir)
|
|
55
|
+
return results
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function linkPackages(localPackages: Record<string, string>) {
|
|
59
|
+
for (const pkgName of Object.keys(localPackages)) {
|
|
60
|
+
const nmPath = join(process.cwd(), 'node_modules', ...pkgName.split('/'))
|
|
61
|
+
try {
|
|
62
|
+
const existingStat = await stat(nmPath)
|
|
63
|
+
if (existingStat) {
|
|
64
|
+
await rm(nmPath, { recursive: true, force: true })
|
|
65
|
+
const localPath = localPackages[pkgName]
|
|
66
|
+
console.info(`${relative(process.cwd(), nmPath)} -> ${localPath.replace(homedir(), '~')}`)
|
|
67
|
+
await symlink(localPath, nmPath, 'dir')
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function main() {
|
|
74
|
+
const args = process.argv.slice(2)
|
|
75
|
+
if (args.length === 0) {
|
|
76
|
+
console.info('No workspace directories provided.')
|
|
77
|
+
process.exit(0)
|
|
78
|
+
}
|
|
79
|
+
const allLocalPackages: Record<string, string> = {}
|
|
80
|
+
for (const workspaceDir of args) {
|
|
81
|
+
const resolved = resolve(workspaceDir)
|
|
82
|
+
const found = await findLocalPackages(resolved)
|
|
83
|
+
Object.assign(allLocalPackages, found)
|
|
84
|
+
}
|
|
85
|
+
await linkPackages(allLocalPackages)
|
|
86
|
+
console.info(`\n ✓ linked ${Object.keys(allLocalPackages).length} packages`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main().catch((err) => {
|
|
90
|
+
console.error('Error:', err)
|
|
91
|
+
process.exit(1)
|
|
92
|
+
})
|