vite-plugin-kiru 0.32.0-preview.0 → 0.32.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +38 -15
- package/dist/server.js +85 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js
|
|
28
28
|
var require_sourcemap_codec_umd = __commonJS({
|
|
29
29
|
"../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js"(exports, module) {
|
|
30
|
-
(function(
|
|
30
|
+
(function(global2, factory) {
|
|
31
31
|
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
32
32
|
factory(module);
|
|
33
33
|
module.exports = def(module);
|
|
@@ -39,8 +39,8 @@ var require_sourcemap_codec_umd = __commonJS({
|
|
|
39
39
|
} else {
|
|
40
40
|
const mod = { exports: {} };
|
|
41
41
|
factory(mod);
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self;
|
|
43
|
+
global2.sourcemapCodec = def(mod);
|
|
44
44
|
}
|
|
45
45
|
function def(m) {
|
|
46
46
|
return "default" in m.exports ? m.exports.default : m.exports;
|
|
@@ -8861,13 +8861,14 @@ export { dir, baseUrl, pages, layouts, guards, transition }
|
|
|
8861
8861
|
`;
|
|
8862
8862
|
}
|
|
8863
8863
|
function createEntryServerModule() {
|
|
8864
|
+
const documentModuleId = userDoc.substring(projectRoot.length);
|
|
8864
8865
|
if (mode === "ssr") {
|
|
8865
8866
|
return `
|
|
8866
8867
|
import { render as kiruServerRender } from "kiru/router/ssr"
|
|
8867
8868
|
import Document from "${userDoc}"
|
|
8868
8869
|
import * as config from "${VIRTUAL_CONFIG_ID}"
|
|
8869
8870
|
|
|
8870
|
-
export const documentModuleId = "${
|
|
8871
|
+
export const documentModuleId = "${documentModuleId}"
|
|
8871
8872
|
|
|
8872
8873
|
export async function render(url, ctx) {
|
|
8873
8874
|
return kiruServerRender(url, { ...ctx, ...config, Document })
|
|
@@ -8882,7 +8883,7 @@ import {
|
|
|
8882
8883
|
import Document from "${userDoc}"
|
|
8883
8884
|
import * as config from "${VIRTUAL_CONFIG_ID}"
|
|
8884
8885
|
|
|
8885
|
-
export const documentModuleId = "${
|
|
8886
|
+
export const documentModuleId = "${documentModuleId}"
|
|
8886
8887
|
|
|
8887
8888
|
export async function render(url, ctx) {
|
|
8888
8889
|
return kiruStaticRender(url, { ...ctx, ...config, Document })
|
|
@@ -11614,15 +11615,30 @@ ${code}`, "utf-8");
|
|
|
11614
11615
|
import { build } from "vite";
|
|
11615
11616
|
|
|
11616
11617
|
// src/globals.ts
|
|
11618
|
+
var $KIRU_HEADLESS_GLOBAL = Symbol.for("kiru.headlessGlobal");
|
|
11619
|
+
var global = globalThis[$KIRU_HEADLESS_GLOBAL] ??= {
|
|
11620
|
+
viteDevServer: null,
|
|
11621
|
+
server: null
|
|
11622
|
+
};
|
|
11617
11623
|
var VITE_DEV_SERVER_INSTANCE = {
|
|
11618
11624
|
get current() {
|
|
11619
|
-
return
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11625
|
+
return global.viteDevServer;
|
|
11626
|
+
},
|
|
11627
|
+
set current(server) {
|
|
11628
|
+
global.viteDevServer = server;
|
|
11629
|
+
}
|
|
11630
|
+
};
|
|
11631
|
+
var entryServerResolvers = [];
|
|
11632
|
+
var KIRU_SERVER_ENTRY = {
|
|
11633
|
+
get current() {
|
|
11634
|
+
return global.serverEntry;
|
|
11623
11635
|
},
|
|
11624
11636
|
set current(server) {
|
|
11625
|
-
|
|
11637
|
+
global.serverEntry = server;
|
|
11638
|
+
if (server) {
|
|
11639
|
+
entryServerResolvers.forEach((fn) => fn());
|
|
11640
|
+
entryServerResolvers = [];
|
|
11641
|
+
}
|
|
11626
11642
|
}
|
|
11627
11643
|
};
|
|
11628
11644
|
|
|
@@ -11669,11 +11685,12 @@ function kiru(opts = {}) {
|
|
|
11669
11685
|
createPreviewMiddleware(state.projectRoot, state.baseOutDir)
|
|
11670
11686
|
);
|
|
11671
11687
|
},
|
|
11672
|
-
configureServer(server) {
|
|
11688
|
+
async configureServer(server) {
|
|
11673
11689
|
VITE_DEV_SERVER_INSTANCE.current = server;
|
|
11674
11690
|
if (state.isProduction || state.isBuild) return;
|
|
11675
11691
|
const {
|
|
11676
11692
|
ssgOptions,
|
|
11693
|
+
ssrOptions,
|
|
11677
11694
|
devtoolsEnabled,
|
|
11678
11695
|
dtClientPathname,
|
|
11679
11696
|
dtHostScriptPath,
|
|
@@ -11723,6 +11740,12 @@ ${ANSI.yellow("Error:")} ${error.message}`
|
|
|
11723
11740
|
next(e);
|
|
11724
11741
|
}
|
|
11725
11742
|
});
|
|
11743
|
+
} else if (ssrOptions) {
|
|
11744
|
+
queueMicrotask(() => {
|
|
11745
|
+
server.ssrLoadModule(VIRTUAL_ENTRY_SERVER_ID).then((mod) => {
|
|
11746
|
+
KIRU_SERVER_ENTRY.current = mod;
|
|
11747
|
+
});
|
|
11748
|
+
});
|
|
11726
11749
|
}
|
|
11727
11750
|
},
|
|
11728
11751
|
resolveId(id) {
|
|
@@ -11827,10 +11850,10 @@ ${ANSI.yellow("Error:")} ${error.message}`
|
|
|
11827
11850
|
...inlineConfig?.build,
|
|
11828
11851
|
ssr: true,
|
|
11829
11852
|
rollupOptions: {
|
|
11830
|
-
input:
|
|
11831
|
-
state.projectRoot,
|
|
11832
|
-
|
|
11833
|
-
|
|
11853
|
+
input: [
|
|
11854
|
+
path7.resolve(state.projectRoot, state.ssrOptions.runtimeEntry),
|
|
11855
|
+
VIRTUAL_ENTRY_SERVER_ID
|
|
11856
|
+
]
|
|
11834
11857
|
}
|
|
11835
11858
|
}
|
|
11836
11859
|
});
|
package/dist/server.js
CHANGED
|
@@ -6658,20 +6658,51 @@ function tEntries(obj) {
|
|
|
6658
6658
|
}
|
|
6659
6659
|
|
|
6660
6660
|
// src/virtual-modules.ts
|
|
6661
|
+
var VIRTUAL_ENTRY_SERVER_ID = "virtual:kiru:entry-server";
|
|
6661
6662
|
var VIRTUAL_ENTRY_CLIENT_ID = "virtual:kiru:entry-client";
|
|
6662
6663
|
|
|
6663
6664
|
// src/globals.ts
|
|
6665
|
+
var $KIRU_HEADLESS_GLOBAL = Symbol.for("kiru.headlessGlobal");
|
|
6666
|
+
var global = globalThis[$KIRU_HEADLESS_GLOBAL] ??= {
|
|
6667
|
+
viteDevServer: null,
|
|
6668
|
+
server: null
|
|
6669
|
+
};
|
|
6664
6670
|
var VITE_DEV_SERVER_INSTANCE = {
|
|
6665
6671
|
get current() {
|
|
6666
|
-
return
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6672
|
+
return global.viteDevServer;
|
|
6673
|
+
},
|
|
6674
|
+
set current(server) {
|
|
6675
|
+
global.viteDevServer = server;
|
|
6676
|
+
}
|
|
6677
|
+
};
|
|
6678
|
+
var entryServerResolvers = [];
|
|
6679
|
+
var KIRU_SERVER_ENTRY = {
|
|
6680
|
+
get current() {
|
|
6681
|
+
return global.serverEntry;
|
|
6670
6682
|
},
|
|
6671
6683
|
set current(server) {
|
|
6672
|
-
|
|
6684
|
+
global.serverEntry = server;
|
|
6685
|
+
if (server) {
|
|
6686
|
+
entryServerResolvers.forEach((fn) => fn());
|
|
6687
|
+
entryServerResolvers = [];
|
|
6688
|
+
}
|
|
6673
6689
|
}
|
|
6674
6690
|
};
|
|
6691
|
+
async function awaitServerRendererInitialized_Dev() {
|
|
6692
|
+
if (KIRU_SERVER_ENTRY.current) {
|
|
6693
|
+
return Promise.resolve(KIRU_SERVER_ENTRY.current);
|
|
6694
|
+
}
|
|
6695
|
+
return new Promise((resolve, reject) => {
|
|
6696
|
+
const timeout = setTimeout(() => {
|
|
6697
|
+
entryServerResolvers = entryServerResolvers.filter((r) => r !== resolve);
|
|
6698
|
+
reject(new Error("Failed to acquire server renderer. Seek help!"));
|
|
6699
|
+
}, 1e4);
|
|
6700
|
+
entryServerResolvers.push(() => {
|
|
6701
|
+
clearTimeout(timeout);
|
|
6702
|
+
resolve(KIRU_SERVER_ENTRY.current);
|
|
6703
|
+
});
|
|
6704
|
+
});
|
|
6705
|
+
}
|
|
6675
6706
|
|
|
6676
6707
|
// src/server.ts
|
|
6677
6708
|
async function getClientAssets(clientOutDirAbs, manifestPath) {
|
|
@@ -6748,8 +6779,56 @@ function collectCssForModules(manifest, moduleIds, projectRoot) {
|
|
|
6748
6779
|
}
|
|
6749
6780
|
return "";
|
|
6750
6781
|
}
|
|
6782
|
+
async function resolveServerRenderer() {
|
|
6783
|
+
if (process.env.NODE_ENV !== "production") {
|
|
6784
|
+
return awaitServerRendererInitialized_Dev();
|
|
6785
|
+
}
|
|
6786
|
+
return loadServerRenderer_Production();
|
|
6787
|
+
}
|
|
6788
|
+
async function loadServerRenderer_Production() {
|
|
6789
|
+
const projectRoot = process.cwd().replace(/\\/g, "/");
|
|
6790
|
+
const serverOutDirAbs = path2.resolve(projectRoot, "dist/server");
|
|
6791
|
+
const manifestPath = path2.resolve(serverOutDirAbs, "vite-manifest.json");
|
|
6792
|
+
if (!fs.existsSync(manifestPath)) {
|
|
6793
|
+
throw new Error(
|
|
6794
|
+
`Server manifest not found at ${manifestPath}. Make sure the SSR build has been completed.`
|
|
6795
|
+
);
|
|
6796
|
+
}
|
|
6797
|
+
const manifest = JSON.parse(
|
|
6798
|
+
fs.readFileSync(manifestPath, "utf-8")
|
|
6799
|
+
);
|
|
6800
|
+
const virtualEntryServerModule = Object.values(manifest).find(
|
|
6801
|
+
(value) => value.src === VIRTUAL_ENTRY_SERVER_ID
|
|
6802
|
+
);
|
|
6803
|
+
if (!virtualEntryServerModule) {
|
|
6804
|
+
throw new Error(
|
|
6805
|
+
"Virtual entry server module not found in manifest. Make sure the SSR build has been completed."
|
|
6806
|
+
);
|
|
6807
|
+
}
|
|
6808
|
+
const entryServerFile = virtualEntryServerModule.file;
|
|
6809
|
+
const entryServerPath = path2.resolve(serverOutDirAbs, entryServerFile);
|
|
6810
|
+
if (!fs.existsSync(entryServerPath)) {
|
|
6811
|
+
throw new Error(
|
|
6812
|
+
`Virtual entry server module file not found at ${entryServerPath}`
|
|
6813
|
+
);
|
|
6814
|
+
}
|
|
6815
|
+
const fileUrl = `file://${entryServerPath.replace(/\\/g, "/")}`;
|
|
6816
|
+
const module = await import(
|
|
6817
|
+
/* @vite-ignore */
|
|
6818
|
+
fileUrl
|
|
6819
|
+
);
|
|
6820
|
+
if (!module.render || !module.documentModuleId) {
|
|
6821
|
+
throw new Error(
|
|
6822
|
+
"Virtual entry server module does not export render and documentModuleId"
|
|
6823
|
+
);
|
|
6824
|
+
}
|
|
6825
|
+
return {
|
|
6826
|
+
render: module.render,
|
|
6827
|
+
documentModuleId: module.documentModuleId
|
|
6828
|
+
};
|
|
6829
|
+
}
|
|
6751
6830
|
async function renderPage(options) {
|
|
6752
|
-
const { render, documentModuleId } = await
|
|
6831
|
+
const { render, documentModuleId } = await resolveServerRenderer();
|
|
6753
6832
|
const moduleIds = [documentModuleId];
|
|
6754
6833
|
const projectRoot = process.cwd().replace(/\\/g, "/");
|
|
6755
6834
|
const { httpResponse } = await render(options.url, {
|