Skip to content

Commit 8d2730e

Browse files
committed
fix: add symlink creation for bin entries in link mode
1 parent b164167 commit 8d2730e

File tree

6 files changed

+1311
-1251
lines changed

6 files changed

+1311
-1251
lines changed

.changeset/swift-eagles-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"zile": patch
3+
---
4+
5+
Added symlink creation for bin entries in link mode.

src/Package.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export async function decoratePackageJson(
226226
[pkgJson.name! + '.src']: bin,
227227
}
228228
} else {
229+
const originalBin = bin
229230
bin = Object.fromEntries(
230231
Object.entries(bin).flatMap((entry) => {
231232
const [key, value] = entry
@@ -238,6 +239,27 @@ export async function decoratePackageJson(
238239
]
239240
}),
240241
)
242+
// Create symlinks for bin entries in link mode
243+
if (link) {
244+
for (const [key, value] of Object.entries(bin)) {
245+
if (!key.endsWith('.src') && value.startsWith(relativeOutDir)) {
246+
// Find corresponding .src entry
247+
const srcKey = `${key}.src`
248+
const srcValue = originalBin[srcKey] ?? bin[srcKey]
249+
if (srcValue) {
250+
try {
251+
const destAbsolute = path.resolve(cwd, value)
252+
const dir = path.dirname(destAbsolute)
253+
if (!fsSync.existsSync(dir)) fsSync.mkdirSync(dir, { recursive: true })
254+
const srcAbsolute = path.resolve(cwd, srcValue)
255+
const srcRelative = path.relative(dir, srcAbsolute)
256+
if (fsSync.existsSync(destAbsolute)) fsSync.unlinkSync(destAbsolute)
257+
fsSync.symlinkSync(srcRelative, destAbsolute, 'file')
258+
} catch {}
259+
}
260+
}
261+
}
262+
}
241263
}
242264
}
243265

src/Packages.test.ts

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ describe('Packages.find', () => {
1717
expect(relative(result)).toMatchInlineSnapshot(`
1818
[
1919
"/",
20-
"/test/repos/wildcard-exports",
20+
"/src/internal",
21+
"/examples/basic",
22+
"/examples/monorepo",
23+
"/examples/monorepo/packages/bar",
24+
"/examples/monorepo/packages/foo",
25+
"/template",
26+
"/test/repos/error-exports-string-not-exists",
2127
"/test/repos/single-entrypoint",
2228
"/test/repos/multiple-entrypoint",
23-
"/test/repos/error-module-resolution",
24-
"/test/repos/error-missing-entry-fields",
25-
"/test/repos/error-main-not-exists",
26-
"/test/repos/error-exports-string-not-exists",
29+
"/test/repos/wildcard-exports",
30+
"/test/repos/dts-exports",
2731
"/test/repos/error-exports-object-not-exists",
28-
"/test/repos/error-bin-string-not-exists",
29-
"/test/repos/error-bin-object-not-exists",
3032
"/test/repos/dts-exports-object",
31-
"/test/repos/dts-exports",
32-
"/test/repos/bin-with-src",
33-
"/test/repos/basic-object-exports",
3433
"/test/repos/basic",
35-
"/template",
36-
"/src/internal",
37-
"/examples/monorepo",
38-
"/examples/monorepo/packages/foo",
39-
"/examples/monorepo/packages/bar",
40-
"/examples/basic",
34+
"/test/repos/basic-object-exports",
35+
"/test/repos/error-bin-string-not-exists",
36+
"/test/repos/bin-with-src",
37+
"/test/repos/error-main-not-exists",
38+
"/test/repos/error-missing-entry-fields",
39+
"/test/repos/error-module-resolution",
40+
"/test/repos/error-bin-object-not-exists",
4141
]
4242
`)
4343
})
@@ -49,21 +49,21 @@ describe('Packages.find', () => {
4949

5050
expect(relative(result)).toMatchInlineSnapshot(`
5151
[
52-
"/test/repos/wildcard-exports",
52+
"/test/repos/error-exports-string-not-exists",
5353
"/test/repos/single-entrypoint",
5454
"/test/repos/multiple-entrypoint",
55-
"/test/repos/error-module-resolution",
56-
"/test/repos/error-missing-entry-fields",
57-
"/test/repos/error-main-not-exists",
58-
"/test/repos/error-exports-string-not-exists",
55+
"/test/repos/wildcard-exports",
56+
"/test/repos/dts-exports",
5957
"/test/repos/error-exports-object-not-exists",
60-
"/test/repos/error-bin-string-not-exists",
61-
"/test/repos/error-bin-object-not-exists",
6258
"/test/repos/dts-exports-object",
63-
"/test/repos/dts-exports",
64-
"/test/repos/bin-with-src",
65-
"/test/repos/basic-object-exports",
6659
"/test/repos/basic",
60+
"/test/repos/basic-object-exports",
61+
"/test/repos/error-bin-string-not-exists",
62+
"/test/repos/bin-with-src",
63+
"/test/repos/error-main-not-exists",
64+
"/test/repos/error-missing-entry-fields",
65+
"/test/repos/error-module-resolution",
66+
"/test/repos/error-bin-object-not-exists",
6767
]
6868
`)
6969
})
@@ -102,21 +102,21 @@ describe('Packages.find', () => {
102102

103103
expect(relative(result)).toMatchInlineSnapshot(`
104104
[
105-
"/test/repos/wildcard-exports",
105+
"/test/repos/error-exports-string-not-exists",
106106
"/test/repos/single-entrypoint",
107107
"/test/repos/multiple-entrypoint",
108-
"/test/repos/error-module-resolution",
109-
"/test/repos/error-missing-entry-fields",
110-
"/test/repos/error-main-not-exists",
111-
"/test/repos/error-exports-string-not-exists",
108+
"/test/repos/wildcard-exports",
109+
"/test/repos/dts-exports",
112110
"/test/repos/error-exports-object-not-exists",
113-
"/test/repos/error-bin-string-not-exists",
114-
"/test/repos/error-bin-object-not-exists",
115111
"/test/repos/dts-exports-object",
116-
"/test/repos/dts-exports",
117-
"/test/repos/bin-with-src",
118-
"/test/repos/basic-object-exports",
119112
"/test/repos/basic",
113+
"/test/repos/basic-object-exports",
114+
"/test/repos/error-bin-string-not-exists",
115+
"/test/repos/bin-with-src",
116+
"/test/repos/error-main-not-exists",
117+
"/test/repos/error-missing-entry-fields",
118+
"/test/repos/error-module-resolution",
119+
"/test/repos/error-bin-object-not-exists",
120120
]
121121
`)
122122
})
@@ -178,27 +178,27 @@ describe('Packages.find', () => {
178178
expect(relative(result)).toMatchInlineSnapshot(`
179179
[
180180
"/",
181-
"/test/repos/wildcard-exports",
181+
"/src/internal",
182+
"/examples/basic",
183+
"/examples/monorepo",
184+
"/examples/monorepo/packages/bar",
185+
"/examples/monorepo/packages/foo",
186+
"/template",
187+
"/test/repos/error-exports-string-not-exists",
182188
"/test/repos/single-entrypoint",
183189
"/test/repos/multiple-entrypoint",
184-
"/test/repos/error-module-resolution",
185-
"/test/repos/error-missing-entry-fields",
186-
"/test/repos/error-main-not-exists",
187-
"/test/repos/error-exports-string-not-exists",
190+
"/test/repos/wildcard-exports",
191+
"/test/repos/dts-exports",
188192
"/test/repos/error-exports-object-not-exists",
189-
"/test/repos/error-bin-string-not-exists",
190-
"/test/repos/error-bin-object-not-exists",
191193
"/test/repos/dts-exports-object",
192-
"/test/repos/dts-exports",
193-
"/test/repos/bin-with-src",
194-
"/test/repos/basic-object-exports",
195194
"/test/repos/basic",
196-
"/template",
197-
"/src/internal",
198-
"/examples/monorepo",
199-
"/examples/monorepo/packages/foo",
200-
"/examples/monorepo/packages/bar",
201-
"/examples/basic",
195+
"/test/repos/basic-object-exports",
196+
"/test/repos/error-bin-string-not-exists",
197+
"/test/repos/bin-with-src",
198+
"/test/repos/error-main-not-exists",
199+
"/test/repos/error-missing-entry-fields",
200+
"/test/repos/error-module-resolution",
201+
"/test/repos/error-bin-object-not-exists",
202202
]
203203
`)
204204
})

0 commit comments

Comments
 (0)