Skip to content

Commit

Permalink
Merge branch 'dev' into fix-vite-handle-export-hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Nov 21, 2023
2 parents 0f4fcac + acee744 commit 43f9621
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-balloons-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Vite: fix access to default `entry.{client,server}.tsx` within pnpm workspace on Windows
21 changes: 9 additions & 12 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ let remixReactProxyId = VirtualModule.id("remix-react-proxy");
let hmrRuntimeId = VirtualModule.id("hmr-runtime");
let injectHmrRuntimeId = VirtualModule.id("inject-hmr-runtime");

const normalizePath = (p: string) => {
let unixPath = p.replace(/[\\/]+/g, "/").replace(/^([a-zA-Z]+:|\.\/)/, "");
return vite.normalizePath(unixPath);
};

const resolveFileUrl = (
{ rootDirectory }: Pick<ResolvedRemixVitePluginConfig, "rootDirectory">,
filePath: string
Expand All @@ -88,12 +83,14 @@ const resolveFileUrl = (
let isWithinRoot =
!relativePath.startsWith("..") && !path.isAbsolute(relativePath);

// Vite will prevent serving files outside of the workspace
// unless user explictly opts in with `server.fs.allow`
// https://vitejs.dev/config/server-options.html#server-fs-allow
if (!isWithinRoot) return `/@fs` + filePath;
if (!isWithinRoot) {
// Vite will prevent serving files outside of the workspace
// unless user explictly opts in with `server.fs.allow`
// https://vitejs.dev/config/server-options.html#server-fs-allow
return path.posix.join("/@fs", vite.normalizePath(filePath));
}

return `/${normalizePath(relativePath)}`;
return "/" + vite.normalizePath(relativePath);
};

const isJsFile = (filePath: string) => /\.[cm]?[jt]sx?$/i.test(filePath);
Expand All @@ -106,7 +103,7 @@ const resolveRelativeRouteFilePath = (
let file = route.file;
let fullPath = path.resolve(pluginConfig.appDirectory, file);

return normalizePath(fullPath);
return vite.normalizePath(fullPath);
};

let vmods = [serverEntryId, serverManifestId, browserManifestId];
Expand All @@ -125,7 +122,7 @@ const resolveBuildAssetPaths = (
pluginConfig.rootDirectory,
absoluteFilePath
);
let manifestKey = normalizePath(rootRelativeFilePath);
let manifestKey = vite.normalizePath(rootRelativeFilePath);
let entryChunk = viteManifest[manifestKey];

if (!entryChunk) {
Expand Down

0 comments on commit 43f9621

Please sign in to comment.