Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle dynamic imports on windows #16

Merged
merged 9 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions packages/vinxi-server-functions/server-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@
import invariant from "vinxi/lib/invariant";
import { eventHandler, toWebRequest } from "vinxi/server";

async function loadModule(id) {
if (import.meta.env.DEV) {
const mod = await import(
/* @vite-ignore */
import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[id].output
.path
);
return mod;
}

if (globalThis.$$chunks[id + ".js"]) {
return globalThis.$$chunks[id + ".js"];
}
return await import(
/* @vite-ignore */
import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[id].output.path
);
}

export async function handleServerAction(event) {
invariant(event.method === "POST", "Invalid method");

Expand All @@ -29,7 +10,7 @@ export async function handleServerAction(event) {
invariant(typeof serverReference === "string", "Invalid server action");
// This is the client-side case
const [filepath, name] = serverReference.split("#");
const action = (await loadModule(filepath))[name];
const action = (await import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[filepath].import())[name];
const text = await new Promise((resolve) => {
const requestBody = [];
event.node.req.on("data", (chunks) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/vinxi/lib/manifest/prod-server-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import invariant from "vinxi/lib/invariant";
import { handlerModule, join, virtualId } from "vinxi/lib/path";

import findAssetsInViteManifest from "./vite-manifest.js";
import { pathToFileURL } from "node:url";

/** @typedef {import("../app.js").App & { config: { buildManifest: { [key:string]: any } }}} ProdApp */

Expand Down Expand Up @@ -66,7 +67,7 @@ export function createProdManifest(app) {
if (globalThis.$$chunks[chunk + ".js"]) {
return globalThis.$$chunks[chunk + ".js"];
}
return import(/* @vite-ignore */ chunkPath);
return import(/* @vite-ignore */ pathToFileURL(chunkPath).href);
},
output: {
path: chunkPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/vinxi/types/manifest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type Manifest = {
[key: string]: {
/** Assets needed by this entry point */
assets(): Promise<Asset[]>;

import<T = { default: any; [k: string]: any }>(): Promise<T>;
output: {
/** Path to built artifact for this entry point. */
path: string;
Expand Down
Loading
Loading