Skip to content

Commit

Permalink
fix: Code frame w/ yalc (and other symlinks)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Dec 30, 2024
1 parent 4b34c4c commit 385c41e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/plugins/prerender-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
const preloadHelperId = 'vite/preload-helper';
const preloadPolyfillId = 'vite/modulepreload-polyfill';

// PNPM, Yalc, and anything else utilizing symlinks mangle the file
// path a bit so we need a minimal, fairly unique ID to check against
const tmpDirId = 'headless-prerender';

/**
* From the non-external scripts in entry HTML document, find the one (if any)
* that provides a `prerender` export
Expand Down Expand Up @@ -231,16 +235,14 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
);
let htmlDoc = htmlParse(tpl);

// Workaround for PNPM mangling file paths with their symlinks
const tmpDirRelative = path.join(
// Create a tmp dir to allow importing & consuming the built modules,
// before Rollup writes them to the disk
const tmpDir = path.join(
viteConfig.root,
'node_modules',
'vite-prerender-plugin',
'headless-prerender',
tmpDirId
);

// Create a tmp dir to allow importing & consuming the built modules,
// before Rollup writes them to the disk
const tmpDir = path.join(viteConfig.root, tmpDirRelative);
try {
await fs.rm(tmpDir, { recursive: true });
} catch (e) {
Expand Down Expand Up @@ -298,7 +300,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
`.replace(/^\t{5}/gm, '');

const stack = StackTraceParse(e).find((s) =>
s.getFileName().includes(tmpDirRelative),
s.getFileName().includes(tmpDirId),
);

const sourceMapContent = prerenderEntry.map;
Expand Down

0 comments on commit 385c41e

Please sign in to comment.