[remix] Ensure the symlink directory exists in ensureSymlink() (#11205)

Customer reported an edge case where (in a monorepo) their project's
`package.json` did not list any dependencies (instead they are listed at
the root-level `package.json`) and this caused the `node_modules`
directory to not exist in the app subdirectory, causing
`ensureSymlink()` to fail.
This commit is contained in:
Nathan Rajlich
2024-02-29 10:44:18 -08:00
committed by GitHub
parent de2738ba06
commit 6ed0fe6fb1
3 changed files with 19 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'@vercel/remix-builder': patch
---
Ensure the symlink directory exists in `ensureSymlink()`

View File

@@ -359,6 +359,7 @@ async function ensureSymlink(
}
}
await fs.mkdir(symlinkDir, { recursive: true });
await fs.symlink(relativeTarget, symlinkPath);
debug(`Created symlink for "${pkgName}"`);
}

View File

@@ -17,4 +17,17 @@ describe('ensureResolvable()', () => {
await fs.rm(start, { recursive: true });
}
});
it('should create a symlink when the node_modules directory does not exist', async () => {
const FIXTURE = join(FIXTURES_DIR, '00-pnpm');
const start = join(FIXTURE, 'apps/a');
try {
await fs.mkdir(start, { recursive: true });
await ensureResolvable(start, FIXTURE, 'ms');
const stat = await fs.lstat(join(start, 'node_modules/ms'));
expect(stat.isSymbolicLink()).toEqual(true);
} finally {
await fs.rm(start, { recursive: true });
}
});
});