Skip to content

Commit b0ae4f7

Browse files
committed
input: fix(zip-it-and-ship-it): create missing symlinks when archiveFormat=none
This change updates zisi's node bundler to create missing symlinks in when `archiveFormat: 'none'` (the code path used by `netlify dev`). Currently, in projects where two or more symlinks resolve to the same target, we only ever create one symlink. In practice, how this usually presents a problem is when a package manager dedupes a dependency by symlinking it into two different packages; users end up getting a runtime error when their code hits the code path that tries to resolve the missing symlink. For example, given this scenario (which I took from a project that exhibits this issue): ``` { targetPath: '../../../@netlify[email protected]/node_modules/@netlify/sdk--extension-api-client', absoluteDestPath: '/home/ndhoule/dev/src/github.com/netlify/integration-csp/.netlify/functions-serve/trpc/node_modules/.pnpm/@netlify[email protected]_@[email protected]/node_modules/@netlify/sdk--extension-api-client' } { targetPath: '../../../@netlify[email protected]/node_modules/@netlify/sdk--extension-api-client', absoluteDestPath: '/home/ndhoule/dev/src/github.com/netlify/integration-csp/.netlify/functions-serve/trpc/node_modules/.pnpm/@netlify[email protected]_@[email protected]_@[email protected]_@[email protected]._vp3jgimrs3u5kdeagmtefgn5zi/node_modules/@netlify/sdk--extension-api-client' } ``` ...only the second symlink is created. This is because as we walk through the list of files to output to the build directory, we only track a single symlink destination per target. Many symlinks can point at the same target, though, so we need to track multiple symlink destinations per target. I tested this out in my problem projects and it solved the problem. I took a stab at adding a test for this, but got a little lost in the test setup, which seems to have the `.zip` code path in mind rather than the `'none'` path. Happy to write some tests if someone can point me at a test setup.
1 parent 22f4965 commit b0ae4f7

File tree

1 file changed

+8
-5
lines changed
  • packages/zip-it-and-ship-it/src/runtimes/node/utils

1 file changed

+8
-5
lines changed

packages/zip-it-and-ship-it/src/runtimes/node/utils/zip.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const createDirectory = async function ({
129129
addBootstrapFile(srcFiles, aliases)
130130
}
131131

132-
const symlinks = new Map<string, string>()
132+
const symlinks = new Map<string, Set<string>>()
133133

134134
// Copying source files.
135135
await pMap(
@@ -156,7 +156,8 @@ const createDirectory = async function ({
156156
if (stat.isSymbolicLink()) {
157157
const targetPath = await readLink(srcFile)
158158

159-
symlinks.set(targetPath, absoluteDestPath)
159+
// Two symlinks may point at the same target path, so keep a list of symlinks to create.
160+
symlinks.set(targetPath, (symlinks.get(targetPath) ?? new Set()).add(absoluteDestPath))
160161

161162
return
162163
}
@@ -168,9 +169,11 @@ const createDirectory = async function ({
168169

169170
await pMap(
170171
[...symlinks.entries()],
171-
async ([target, path]) => {
172-
await mkdir(dirname(path), { recursive: true })
173-
await symlink(target, path)
172+
async ([target, paths]) => {
173+
for (const path of paths) {
174+
await mkdir(dirname(path), { recursive: true })
175+
await symlink(target, path)
176+
}
174177
},
175178
{
176179
concurrency: COPY_FILE_CONCURRENCY,

0 commit comments

Comments
 (0)