Skip to content

Commit

Permalink
Merge pull request #16 from edivados/dynimport-win
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf authored Nov 5, 2023
2 parents 52bc505 + 5ee5762 commit df053f2
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 62 deletions.
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

0 comments on commit df053f2

Please sign in to comment.