vike 0.4.236-commit-85d361d → 0.4.236-commit-64431e7
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/cjs/client/shared/createGetGlobalContextClient.js +2 -2
- package/dist/cjs/node/runtime/globalContext.js +83 -21
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +2 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginViteRPC.js +42 -0
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +14 -6
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +3 -0
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +32 -52
- package/dist/esm/node/runtime/globalContext.js +84 -22
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -33
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +20 -66
- package/dist/esm/node/runtime/renderPage.d.ts +10 -33
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +2 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +25 -0
- package/dist/esm/node/vite/plugins/pluginViteRPC.js +40 -0
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +14 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/package.json +10 -1
|
@@ -13,6 +13,8 @@ function pluginDistFileNames() {
|
|
|
13
13
|
apply: 'build',
|
|
14
14
|
enforce: 'post',
|
|
15
15
|
configResolved(config) {
|
|
16
|
+
// TODO/now remove
|
|
17
|
+
// if (true as boolean) return
|
|
16
18
|
const rollupOutputs = getRollupOutputs(config);
|
|
17
19
|
// We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
|
|
18
20
|
rollupOutputs.forEach((rollupOutput) => {
|
|
@@ -101,6 +103,7 @@ function getIdHash(id) {
|
|
|
101
103
|
return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
102
104
|
}
|
|
103
105
|
function getAssetFileName(assetInfo, config) {
|
|
106
|
+
const userRootDir = config.root;
|
|
104
107
|
const assetsDir = getAssetsDir(config);
|
|
105
108
|
const dir = assetsDir + '/static';
|
|
106
109
|
let { name } = assetInfo;
|
|
@@ -118,11 +121,11 @@ function getAssetFileName(assetInfo, config) {
|
|
|
118
121
|
// Vite 3
|
|
119
122
|
name?.endsWith('?extractAssets&lang.css')) {
|
|
120
123
|
name = name.split('.').slice(0, -2).join('.');
|
|
121
|
-
name = clean(name);
|
|
124
|
+
name = clean(name, userRootDir);
|
|
122
125
|
return `${dir}/${name}.[hash][extname]`;
|
|
123
126
|
}
|
|
124
127
|
name = name.split('.').slice(0, -1).join('.');
|
|
125
|
-
name = clean(name);
|
|
128
|
+
name = clean(name, userRootDir);
|
|
126
129
|
return `${dir}/${name}.[hash][extname]`;
|
|
127
130
|
}
|
|
128
131
|
function getChunkFileName(_chunkInfo, config) {
|
|
@@ -135,11 +138,12 @@ function getChunkFileName(_chunkInfo, config) {
|
|
|
135
138
|
return name;
|
|
136
139
|
}
|
|
137
140
|
function getEntryFileName(chunkInfo, config, isEntry) {
|
|
141
|
+
const userRootDir = config.root;
|
|
138
142
|
const assetsDir = getAssetsDir(config);
|
|
139
143
|
const isForClientSide = !config.build.ssr;
|
|
140
144
|
let { name } = chunkInfo;
|
|
141
145
|
assertPosixPath(name);
|
|
142
|
-
name = clean(name, true,
|
|
146
|
+
name = clean(name, userRootDir, true,
|
|
143
147
|
// Not needed for client-side because dist/ filenames contain `.[hash].js`
|
|
144
148
|
!isForClientSide);
|
|
145
149
|
if (isForClientSide) {
|
|
@@ -149,9 +153,14 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
149
153
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
|
-
function removePathSeparators(name) {
|
|
156
|
+
function removePathSeparators(name, userRootDir) {
|
|
153
157
|
assertPosixPath(name);
|
|
154
|
-
|
|
158
|
+
if (name.startsWith(userRootDir)) {
|
|
159
|
+
name = name.slice(userRootDir.length);
|
|
160
|
+
if (name.startsWith('/'))
|
|
161
|
+
name = name.slice(1);
|
|
162
|
+
}
|
|
163
|
+
assert(!name.startsWith('/'), { name });
|
|
155
164
|
const entryDir = 'entries/';
|
|
156
165
|
const hasEntryDir = name.startsWith(entryDir);
|
|
157
166
|
if (hasEntryDir) {
|
|
@@ -164,14 +173,14 @@ function removePathSeparators(name) {
|
|
|
164
173
|
}
|
|
165
174
|
return name;
|
|
166
175
|
}
|
|
167
|
-
function clean(name, removePathSep, fixGlob) {
|
|
176
|
+
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
168
177
|
name = fixExtractAssetsQuery(name);
|
|
169
178
|
if (fixGlob) {
|
|
170
179
|
name = workaroundGlob(name);
|
|
171
180
|
}
|
|
172
181
|
name = replaceNonLatinCharacters(name);
|
|
173
182
|
if (removePathSep) {
|
|
174
|
-
name = removePathSeparators(name);
|
|
183
|
+
name = removePathSeparators(name, userRootDir);
|
|
175
184
|
}
|
|
176
185
|
name = removeLeadingUnderscoreInFilename(name);
|
|
177
186
|
name = removeUnderscoreDoublets(name);
|
|
@@ -11,6 +11,7 @@ import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVi
|
|
|
11
11
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
12
12
|
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
13
13
|
const pluginName = 'vike:pluginCommon';
|
|
14
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
14
15
|
function pluginCommon(vikeVitePluginOptions) {
|
|
15
16
|
return [
|
|
16
17
|
{
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { pluginViteRPC };
|
|
2
|
+
import type { Plugin, ViteDevServer } from 'vite';
|
|
3
|
+
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
4
|
+
export type ViteRPC = ReturnType<typeof getViteRpcFunctions>;
|
|
5
|
+
declare function getViteRpcFunctions(viteDevServer: ViteDevServer): {
|
|
6
|
+
transformIndexHtmlRPC(html: string): Promise<string>;
|
|
7
|
+
retrievePageAssetsDevRPC(clientDependencies: ClientDependency[], clientEntries: string[]): Promise<{
|
|
8
|
+
clientEntriesSrc: string[];
|
|
9
|
+
assetUrls: string[];
|
|
10
|
+
}>;
|
|
11
|
+
getViteConfigRuntimeRPC(): Promise<{
|
|
12
|
+
root: string;
|
|
13
|
+
build: {
|
|
14
|
+
outDir: string;
|
|
15
|
+
};
|
|
16
|
+
_baseViteOriginal: string;
|
|
17
|
+
vitePluginServerEntry: {
|
|
18
|
+
inject: boolean | undefined;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
declare global {
|
|
23
|
+
var __VIKE__DYNAMIC_IMPORT: (module: string) => Promise<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
declare function pluginViteRPC(): Plugin;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { pluginViteRPC };
|
|
2
|
+
import { createViteRPC, assertIsNotProductionRuntime, requireResolveVikeDistFile } from '../utils.js';
|
|
3
|
+
import { resolveClientEntriesDev } from '../shared/resolveClientEntriesDev.js';
|
|
4
|
+
import { retrieveAssetsDev } from '../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js';
|
|
5
|
+
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
6
|
+
assertIsNotProductionRuntime();
|
|
7
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
8
|
+
return {
|
|
9
|
+
async transformIndexHtmlRPC(html) {
|
|
10
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
11
|
+
},
|
|
12
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
13
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
14
|
+
const assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
15
|
+
return { clientEntriesSrc, assetUrls };
|
|
16
|
+
},
|
|
17
|
+
async getViteConfigRuntimeRPC() {
|
|
18
|
+
const viteConfigRuntime = getViteConfigRuntime(viteDevServer.config);
|
|
19
|
+
return viteConfigRuntime;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function pluginViteRPC() {
|
|
24
|
+
const runtimeFileWithDynamicImport = requireResolveVikeDistFile('dist/esm/node/runtime/globalContext.js');
|
|
25
|
+
return {
|
|
26
|
+
name: 'vike:pluginViteRPC',
|
|
27
|
+
configureServer(viteDevServer) {
|
|
28
|
+
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
29
|
+
},
|
|
30
|
+
transform(code, id) {
|
|
31
|
+
if (id !== runtimeFileWithDynamicImport)
|
|
32
|
+
return;
|
|
33
|
+
const envName = this.environment?.name;
|
|
34
|
+
if (!envName || ['client', 'ssr'].includes(envName))
|
|
35
|
+
return;
|
|
36
|
+
// TODO/now use magic-string
|
|
37
|
+
return code.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -9,10 +9,10 @@ import type { GlobalContextServerInternal } from '../node/runtime/globalContext.
|
|
|
9
9
|
import type { GlobalContextClientInternal } from '../client/runtime-client-routing/globalContext.js';
|
|
10
10
|
import { type Hook } from './hooks/getHook.js';
|
|
11
11
|
declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
12
|
-
declare function createGlobalContextShared<
|
|
12
|
+
declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>, GlobalContextAddedAsync extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
|
|
13
13
|
globalContext?: Record<string, unknown>;
|
|
14
14
|
onCreateGlobalContextHooks?: Hook[];
|
|
15
|
-
},
|
|
15
|
+
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>, addGlobalContextAsync?: (globalContext: GlobalContextBase) => Promise<GlobalContextAddedAsync>): Promise<{
|
|
16
16
|
/**
|
|
17
17
|
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
18
18
|
*
|
|
@@ -35,7 +35,7 @@ declare function createGlobalContextShared<GlobalContextAddendum extends Record<
|
|
|
35
35
|
pages: {
|
|
36
36
|
[k: string]: import("./page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
|
|
37
37
|
};
|
|
38
|
-
} &
|
|
38
|
+
} & GlobalContextAdded & GlobalContextAddedAsync>;
|
|
39
39
|
type GlobalContextBasePublic = Pick<GlobalContextBase, 'config' | 'pages' | 'isGlobalContext'>;
|
|
40
40
|
type GlobalContextBase = ReturnType<typeof createGlobalContextBase>;
|
|
41
41
|
declare function createGlobalContextBase(virtualFileExports: unknown): {
|
|
@@ -7,25 +7,33 @@ import { execHookGlobal } from './hooks/execHook.js';
|
|
|
7
7
|
import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
|
|
8
8
|
import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
|
|
9
9
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
10
|
-
async function createGlobalContextShared(virtualFileExports, globalObject,
|
|
10
|
+
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
|
|
11
|
+
// TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
|
|
12
|
+
addGlobalContextTmp, addGlobalContextAsync) {
|
|
11
13
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
12
14
|
let isNewGlobalContext;
|
|
13
15
|
if (!globalObject.globalContext) {
|
|
16
|
+
// We set globalObject.globalContext early and before any async operations, so that getGlobalContextSync() can be used early.
|
|
17
|
+
// - Required by vike-vercel
|
|
14
18
|
globalObject.globalContext = globalContext;
|
|
15
19
|
isNewGlobalContext = false;
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
22
|
isNewGlobalContext = true;
|
|
19
23
|
}
|
|
20
|
-
if (
|
|
24
|
+
if (addGlobalContext &&
|
|
21
25
|
// TODO/next-major-release: remove
|
|
22
26
|
globalContext._pageConfigs.length > 0) {
|
|
23
|
-
const
|
|
24
|
-
objectAssign(globalContext,
|
|
27
|
+
const globalContextAdded = addGlobalContext?.(globalContext);
|
|
28
|
+
objectAssign(globalContext, globalContextAdded);
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
|
-
const
|
|
28
|
-
objectAssign(globalContext,
|
|
31
|
+
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
32
|
+
objectAssign(globalContext, globalContextAdded);
|
|
33
|
+
}
|
|
34
|
+
{
|
|
35
|
+
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
36
|
+
objectAssign(globalContext, globalContextAddedAsync);
|
|
29
37
|
}
|
|
30
38
|
const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
31
39
|
let hooksCalled = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.236-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.236-commit-64431e7";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.236-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.236-commit-64431e7';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createDebugger };
|
|
2
2
|
export { isDebugActivated };
|
|
3
3
|
export type { Debug };
|
|
4
|
-
declare const flags: readonly ["vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles"];
|
|
4
|
+
declare const flags: readonly ["vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
5
5
|
type Flag = (typeof flags)[number];
|
|
6
6
|
type Debug = ReturnType<typeof createDebugger>;
|
|
7
7
|
type Options = {
|
package/dist/esm/utils/debug.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { getViteRPC };
|
|
2
|
+
export { createViteRPC };
|
|
3
|
+
import type { ViteDevServer } from 'vite';
|
|
4
|
+
declare function getViteRPC<RpcFunctions>(): RpcFunctions;
|
|
5
|
+
type AsyncFunction = (...args: any[]) => Promise<unknown>;
|
|
6
|
+
declare function createViteRPC(viteDevServer: ViteDevServer, getRpcFunctions: (viteDevServer: ViteDevServer) => Record<string, AsyncFunction>): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export { getViteRPC }; // consumer (aka RPC client)
|
|
2
|
+
export { createViteRPC }; // provider (aka RPC server)
|
|
3
|
+
import { assert } from './assert.js';
|
|
4
|
+
import { genPromise } from './genPromise.js';
|
|
5
|
+
import { getRandomId } from './getRandomId.js';
|
|
6
|
+
import { getGlobalObject } from './getGlobalObject.js';
|
|
7
|
+
import { createDebugger } from './debug.js';
|
|
8
|
+
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
9
|
+
assertIsNotBrowser();
|
|
10
|
+
const globalObject = getGlobalObject('utils/getViteRPC.ts', {
|
|
11
|
+
rpc: null,
|
|
12
|
+
});
|
|
13
|
+
const debug = createDebugger('vike:vite-rpc');
|
|
14
|
+
function getViteRPC() {
|
|
15
|
+
globalObject.rpc ?? (globalObject.rpc = createRpcClient());
|
|
16
|
+
return globalObject.rpc;
|
|
17
|
+
}
|
|
18
|
+
function createRpcClient() {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const hot = import.meta.hot;
|
|
21
|
+
assert(hot);
|
|
22
|
+
const callbacks = [];
|
|
23
|
+
hot.on(`vike:rpc:response`, (dataResponse) => {
|
|
24
|
+
if (debug.isActivated)
|
|
25
|
+
debug('Response received', dataResponse);
|
|
26
|
+
const { callId, functionReturn } = dataResponse;
|
|
27
|
+
callbacks.forEach((c) => {
|
|
28
|
+
if (callId !== c.callId)
|
|
29
|
+
return;
|
|
30
|
+
c.cb(functionReturn);
|
|
31
|
+
callbacks.splice(callbacks.indexOf(c), 1);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
const rpc = new Proxy({}, {
|
|
35
|
+
get(_, functionName) {
|
|
36
|
+
return async (...functionArgs) => {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const hot = import.meta.hot;
|
|
39
|
+
assert(hot);
|
|
40
|
+
const callId = getRandomId();
|
|
41
|
+
const { promise, resolve } = genPromise({ timeout: 3 * 1000 });
|
|
42
|
+
callbacks.push({
|
|
43
|
+
callId,
|
|
44
|
+
cb: (functionReturn) => {
|
|
45
|
+
resolve(functionReturn);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const dataRequest = { callId, functionName, functionArgs };
|
|
49
|
+
if (debug.isActivated)
|
|
50
|
+
debug('Request sent', dataRequest);
|
|
51
|
+
// Vite's type is wrong; it import.meta.hot.send() does seem to return a promise
|
|
52
|
+
await hot.send('vike:rpc:request', dataRequest);
|
|
53
|
+
const functionReturn = await promise;
|
|
54
|
+
return functionReturn;
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return rpc;
|
|
59
|
+
}
|
|
60
|
+
function createViteRPC(viteDevServer, getRpcFunctions) {
|
|
61
|
+
const rpcFunctions = getRpcFunctions(viteDevServer);
|
|
62
|
+
const { environments } = viteDevServer;
|
|
63
|
+
for (const envName in environments) {
|
|
64
|
+
debug('Listening to environment', envName);
|
|
65
|
+
const env = environments[envName];
|
|
66
|
+
env.hot.on('vike:rpc:request', async (dataRequest) => {
|
|
67
|
+
if (debug.isActivated)
|
|
68
|
+
debug('Request received', dataRequest);
|
|
69
|
+
const { callId, functionName, functionArgs } = dataRequest;
|
|
70
|
+
const functionReturn = await rpcFunctions[functionName](...functionArgs);
|
|
71
|
+
const dataResponse = { callId, functionReturn };
|
|
72
|
+
if (debug.isActivated)
|
|
73
|
+
debug('Response sent', dataResponse);
|
|
74
|
+
env.hot.send('vike:rpc:response', dataResponse);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.236-commit-
|
|
3
|
+
"version": "0.4.236-commit-64431e7",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
7
7
|
"worker": "./dist/esm/node/runtime/index.js",
|
|
8
|
+
"workerd": "./dist/esm/node/runtime/index.js",
|
|
8
9
|
"require": "./dist/cjs/node/runtime/index.js",
|
|
9
10
|
"node": "./dist/esm/node/runtime/index.js",
|
|
10
11
|
"browser": "./dist/esm/client/node.js",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"./client/router": {
|
|
21
22
|
"worker": "./dist/esm/node/client/router.js",
|
|
23
|
+
"workerd": "./dist/esm/node/client/router.js",
|
|
22
24
|
"require": "./dist/cjs/node/client/router.js",
|
|
23
25
|
"node": "./dist/esm/node/client/router.js",
|
|
24
26
|
"browser": "./dist/esm/client/runtime-client-routing/index.js",
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
},
|
|
28
30
|
"./routing": {
|
|
29
31
|
"worker": "./dist/esm/shared/route/routing.js",
|
|
32
|
+
"workerd": "./dist/esm/shared/route/routing.js",
|
|
30
33
|
"require": "./dist/cjs/shared/route/routing.js",
|
|
31
34
|
"node": "./dist/esm/shared/route/routing.js",
|
|
32
35
|
"browser": "./dist/esm/shared/route/routing.js",
|
|
@@ -59,6 +62,7 @@
|
|
|
59
62
|
},
|
|
60
63
|
"./RenderErrorPage": {
|
|
61
64
|
"worker": "./dist/esm/shared/RenderErrorPage.js",
|
|
65
|
+
"workerd": "./dist/esm/shared/RenderErrorPage.js",
|
|
62
66
|
"require": "./dist/cjs/shared/RenderErrorPage.js",
|
|
63
67
|
"node": "./dist/esm/shared/RenderErrorPage.js",
|
|
64
68
|
"browser": "./dist/esm/shared/RenderErrorPage.js",
|
|
@@ -67,6 +71,7 @@
|
|
|
67
71
|
},
|
|
68
72
|
"./abort": {
|
|
69
73
|
"worker": "./dist/esm/shared/abort.js",
|
|
74
|
+
"workerd": "./dist/esm/shared/abort.js",
|
|
70
75
|
"require": "./dist/cjs/shared/abort.js",
|
|
71
76
|
"node": "./dist/esm/shared/abort.js",
|
|
72
77
|
"browser": "./dist/esm/shared/abort.js",
|
|
@@ -75,6 +80,7 @@
|
|
|
75
80
|
},
|
|
76
81
|
"./getPageContext": {
|
|
77
82
|
"worker": "./dist/esm/shared/getPageContext.js",
|
|
83
|
+
"workerd": "./dist/esm/shared/getPageContext.js",
|
|
78
84
|
"require": "./dist/cjs/shared/getPageContext.js",
|
|
79
85
|
"node": "./dist/esm/shared/getPageContext.js",
|
|
80
86
|
"browser": "./dist/esm/shared/getPageContext.js",
|
|
@@ -83,6 +89,7 @@
|
|
|
83
89
|
},
|
|
84
90
|
"./modifyUrl": {
|
|
85
91
|
"worker": "./dist/esm/shared/modifyUrl.js",
|
|
92
|
+
"workerd": "./dist/esm/shared/modifyUrl.js",
|
|
86
93
|
"require": "./dist/cjs/shared/modifyUrl.js",
|
|
87
94
|
"node": "./dist/esm/shared/modifyUrl.js",
|
|
88
95
|
"browser": "./dist/esm/shared/modifyUrl.js",
|
|
@@ -91,6 +98,7 @@
|
|
|
91
98
|
},
|
|
92
99
|
"./universal-middleware": {
|
|
93
100
|
"worker": "./dist/esm/node/runtime/universal-middleware.js",
|
|
101
|
+
"workerd": "./dist/esm/node/runtime/universal-middleware.js",
|
|
94
102
|
"require": "./dist/cjs/node/runtime/universal-middleware.js",
|
|
95
103
|
"node": "./dist/esm/node/runtime/universal-middleware.js",
|
|
96
104
|
"browser": "./dist/esm/client/node.js",
|
|
@@ -111,6 +119,7 @@
|
|
|
111
119
|
},
|
|
112
120
|
".": {
|
|
113
121
|
"worker": "./dist/esm/node/runtime/index.js",
|
|
122
|
+
"workerd": "./dist/esm/node/runtime/index.js",
|
|
114
123
|
"require": "./dist/cjs/node/runtime/index.js",
|
|
115
124
|
"node": "./dist/esm/node/runtime/index.js",
|
|
116
125
|
"browser": "./dist/esm/client/index.js",
|