vike 0.4.227 → 0.4.228-commit-1553dee
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/node/api/dev.js +2 -0
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +9 -4
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -5
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +13 -8
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +13 -21
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +8 -9
- package/dist/cjs/node/plugin/plugins/envVars.js +22 -13
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -2
- package/dist/cjs/node/plugin/plugins/fileEnv.js +1 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +25 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -4
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +3 -4
- package/dist/cjs/node/plugin/shared/getViteConfigRuntime.js +21 -0
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +11 -12
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +157 -196
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +57 -34
- package/dist/cjs/node/runtime/html/stream.js +2 -4
- package/dist/cjs/node/runtime/index-common.js +2 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +0 -23
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/shared/route/index.js +13 -11
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +2 -5
- package/dist/cjs/utils/findPackageJson.js +2 -2
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/cjs/utils/isNpmPackage.js +1 -1
- package/dist/cjs/utils/isScriptFile.js +4 -4
- package/dist/cjs/utils/parseUrl.js +4 -4
- package/dist/cjs/utils/preservePropertyGetters.js +30 -0
- package/dist/cjs/utils/requireResolve.js +60 -16
- package/dist/cjs/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -2
- package/dist/esm/node/api/dev.js +2 -0
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +9 -4
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +2 -4
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +12 -7
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +11 -22
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +7 -8
- package/dist/esm/node/plugin/plugins/envVars.js +19 -13
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -3
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -3
- package/dist/esm/node/plugin/plugins/fileEnv.js +2 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +2 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +26 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -4
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +4 -5
- package/dist/esm/node/plugin/shared/getViteConfigRuntime.d.ts +14 -0
- package/dist/esm/node/plugin/shared/getViteConfigRuntime.js +19 -0
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +10 -11
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +1 -1
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +1 -0
- package/dist/esm/node/prerender/runPrerender.js +160 -199
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +26 -17
- package/dist/esm/node/runtime/globalContext.js +57 -34
- package/dist/esm/node/runtime/html/stream.js +2 -4
- package/dist/esm/node/runtime/index-common.d.ts +1 -1
- package/dist/esm/node/runtime/index-common.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +9 -197
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +0 -23
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +1 -1
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/shared/route/index.d.ts +1 -1
- package/dist/esm/shared/route/index.js +13 -11
- package/dist/esm/shared/types.d.ts +1 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +2 -5
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/isNpmPackage.js +1 -1
- package/dist/esm/utils/isScriptFile.js +4 -4
- package/dist/esm/utils/parseUrl.js +4 -4
- package/dist/esm/utils/preservePropertyGetters.d.ts +2 -0
- package/dist/esm/utils/preservePropertyGetters.js +28 -0
- package/dist/esm/utils/requireResolve.d.ts +7 -1
- package/dist/esm/utils/requireResolve.js +54 -13
- package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.d.ts +4 -4
- package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
- package/package.json +3 -2
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getGlobalContext = getGlobalContext;
|
|
6
7
|
exports.getGlobalContextSync = getGlobalContextSync;
|
|
7
8
|
exports.getGlobalContextAsync = getGlobalContextAsync;
|
|
8
9
|
exports.getGlobalContextInternal = getGlobalContextInternal;
|
|
@@ -18,7 +19,6 @@ exports.setGlobalContext_isProduction = setGlobalContext_isProduction;
|
|
|
18
19
|
exports.setGlobalContext_buildEntry = setGlobalContext_buildEntry;
|
|
19
20
|
exports.clearGlobalContext = clearGlobalContext;
|
|
20
21
|
exports.assertBuildInfo = assertBuildInfo;
|
|
21
|
-
exports.getViteConfigRuntime = getViteConfigRuntime;
|
|
22
22
|
exports.updateUserFiles = updateUserFiles;
|
|
23
23
|
// The core logic revolves around:
|
|
24
24
|
// - globalObject.userFiles which is the main requirement for resolveGlobalContext()
|
|
@@ -59,13 +59,24 @@ function assertGlobalContextIsDefined() {
|
|
|
59
59
|
assertIsDefined(globalObject.globalContext);
|
|
60
60
|
(0, utils_js_1.assert)(globalObject.globalContext_public);
|
|
61
61
|
}
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Get runtime information about your app.
|
|
64
|
+
*
|
|
65
|
+
* https://vike.dev/getGlobalContext
|
|
66
|
+
*/
|
|
67
|
+
async function getGlobalContext() {
|
|
68
|
+
debug('getGlobalContext()');
|
|
69
|
+
const { isProduction } = globalObject;
|
|
70
|
+
// This assertion cannot fail for vike-server users (because when using vike-server it's guaranteed that globalObject.isProduction is set before executing any user-land code and any Vike extension code).
|
|
71
|
+
(0, utils_js_1.assertUsage)(isProduction !== undefined, "The global context isn't set yet, use getGlobalContextAsync() instead.");
|
|
72
|
+
(0, utils_js_1.assert)(typeof globalObject.isProduction === 'boolean');
|
|
73
|
+
return await getGlobalContextAsync(isProduction);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get runtime information about your app.
|
|
77
|
+
*
|
|
78
|
+
* https://vike.dev/getGlobalContext
|
|
79
|
+
*/
|
|
69
80
|
async function getGlobalContextAsync(isProduction) {
|
|
70
81
|
debug('getGlobalContextAsync()');
|
|
71
82
|
(0, utils_js_1.assertUsage)(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${picocolors_1.default.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${picocolors_1.default.cyan('true')} or ${picocolors_1.default.cyan('false')}`}`);
|
|
@@ -79,11 +90,29 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
79
90
|
(0, utils_js_1.assert)(globalContext_public);
|
|
80
91
|
return globalContext_public;
|
|
81
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Get runtime information about your app.
|
|
95
|
+
*
|
|
96
|
+
* https://vike.dev/getGlobalContext
|
|
97
|
+
*
|
|
98
|
+
* @deprecated
|
|
99
|
+
*/
|
|
100
|
+
function getGlobalContextSync() {
|
|
101
|
+
debug('getGlobalContextSync()');
|
|
102
|
+
const { globalContext_public } = globalObject;
|
|
103
|
+
(0, utils_js_1.assertUsage)(globalContext_public, "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.");
|
|
104
|
+
(0, utils_js_1.assertWarning)(false,
|
|
105
|
+
// We discourage users from using it because using `pageContext.globalContext` is better: it doesn't have the race condition issue that `getGlobalContextSync()` would have when called inside React/Vue components.
|
|
106
|
+
// We're lying about "is going to be deprecated in the next major release": let's keep it and see if users need it (so far I can't see a use case for it).
|
|
107
|
+
'getGlobalContextSync() is going to be deprecated in the next major release, see https://vike.dev/getGlobalContext', { onlyOnce: true });
|
|
108
|
+
return globalContext_public;
|
|
109
|
+
}
|
|
82
110
|
function makePublic(globalContext) {
|
|
83
111
|
const globalContextPublic = (0, utils_js_1.makePublicCopy)(globalContext, 'globalContext', [
|
|
84
112
|
'assetsManifest',
|
|
85
113
|
'config',
|
|
86
114
|
'viteConfig',
|
|
115
|
+
'viteConfigRuntime',
|
|
87
116
|
'pages',
|
|
88
117
|
'baseServer',
|
|
89
118
|
'baseAssets'
|
|
@@ -103,12 +132,12 @@ async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
|
103
132
|
assertGlobalContextIsDefined();
|
|
104
133
|
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
105
134
|
}
|
|
106
|
-
function setGlobalContext_viteConfig(viteConfig,
|
|
135
|
+
function setGlobalContext_viteConfig(viteConfig, viteConfigRuntime) {
|
|
107
136
|
if (globalObject.viteConfig)
|
|
108
137
|
return;
|
|
109
138
|
assertIsNotInitilizedYet();
|
|
110
139
|
globalObject.viteConfig = viteConfig;
|
|
111
|
-
globalObject.
|
|
140
|
+
globalObject.viteConfigRuntime = viteConfigRuntime;
|
|
112
141
|
}
|
|
113
142
|
function assertIsNotInitilizedYet() {
|
|
114
143
|
// In development, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
@@ -118,8 +147,13 @@ function setGlobalContext_isPrerendering() {
|
|
|
118
147
|
globalObject.isPrerendering = true;
|
|
119
148
|
setIsProduction(true);
|
|
120
149
|
}
|
|
121
|
-
function setGlobalContext_isProduction(isProduction) {
|
|
122
|
-
|
|
150
|
+
function setGlobalContext_isProduction(isProduction, tolerateContraditction) {
|
|
151
|
+
if (globalObject.isProduction === undefined) {
|
|
152
|
+
setIsProduction(isProduction);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
(0, utils_js_1.assert)(globalObject.isProduction === isProduction || tolerateContraditction);
|
|
156
|
+
}
|
|
123
157
|
}
|
|
124
158
|
function getViteDevServer() {
|
|
125
159
|
return globalObject.viteDevServer ?? null;
|
|
@@ -143,7 +177,6 @@ async function initGlobalContext_runPrerender() {
|
|
|
143
177
|
globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
|
|
144
178
|
(0, utils_js_1.assert)(globalObject.isPrerendering);
|
|
145
179
|
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
146
|
-
(0, utils_js_1.assert)(globalObject.outDirRoot);
|
|
147
180
|
// We assume initGlobalContext_runPrerender() to be called before:
|
|
148
181
|
// - initGlobalContext_renderPage()
|
|
149
182
|
// - initGlobalContext_getGlobalContextAsync()
|
|
@@ -179,7 +212,7 @@ async function initGlobalContext() {
|
|
|
179
212
|
await waitForViteDevServer();
|
|
180
213
|
}
|
|
181
214
|
else {
|
|
182
|
-
await loadBuildEntry(globalObject.
|
|
215
|
+
await loadBuildEntry(globalObject.viteConfigRuntime?.build.outDir);
|
|
183
216
|
}
|
|
184
217
|
assertGlobalContextIsDefined();
|
|
185
218
|
globalObject.isInitialized = true;
|
|
@@ -202,7 +235,7 @@ function defineGlobalContext() {
|
|
|
202
235
|
(0, utils_js_1.onSetupRuntime)();
|
|
203
236
|
}
|
|
204
237
|
function resolveGlobalContext() {
|
|
205
|
-
const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
|
|
238
|
+
const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction, userFiles } = globalObject;
|
|
206
239
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
207
240
|
let globalContext;
|
|
208
241
|
if (!isProduction) {
|
|
@@ -211,8 +244,8 @@ function resolveGlobalContext() {
|
|
|
211
244
|
return null;
|
|
212
245
|
(0, utils_js_1.assert)(userFiles); // main common requiement
|
|
213
246
|
(0, utils_js_1.assert)(viteConfig);
|
|
247
|
+
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
214
248
|
(0, utils_js_1.assert)(!isPrerendering);
|
|
215
|
-
const viteConfigRuntime = getViteConfigRuntime(viteConfig);
|
|
216
249
|
globalContext = {
|
|
217
250
|
isProduction: false,
|
|
218
251
|
isPrerendering: false,
|
|
@@ -312,14 +345,12 @@ async function loadBuildEntry(outDir) {
|
|
|
312
345
|
globalObject.buildEntry = globalObject.buildEntryPrevious;
|
|
313
346
|
}
|
|
314
347
|
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
348
|
+
// If using `inject` then dist/server/index.js imports dist/server/entry.js and loadBuildEntry() isn't needed.
|
|
349
|
+
// If dist/server/entry.js isn't imported then this means the user is running the original server entry `$ ts-node server/index.ts`.
|
|
315
350
|
(0, utils_js_1.assertWarning)(
|
|
316
|
-
// vike-server => `
|
|
317
|
-
// vike-node => `
|
|
318
|
-
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
|
|
319
|
-
/* TO-DO/eventually:
|
|
320
|
-
!!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
|
|
321
|
-
*/
|
|
322
|
-
`Run the built server entry (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
351
|
+
// vike-server => `inject === true`
|
|
352
|
+
// vike-node => `inject === [ 'index' ]` => we don't show the warning to vike-node users (I don't remember why).
|
|
353
|
+
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true || globalObject.isPrerendering, `Run the built server entry (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
323
354
|
}
|
|
324
355
|
const { buildEntry } = globalObject;
|
|
325
356
|
assertBuildEntry(buildEntry);
|
|
@@ -355,25 +386,17 @@ function assertBuildInfo(buildInfo) {
|
|
|
355
386
|
assertVersionAtBuildTime(buildInfo.versionAtBuildTime);
|
|
356
387
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo, 'viteConfigRuntime', 'object'));
|
|
357
388
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, '_baseViteOriginal', 'string'));
|
|
389
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, 'root', 'string'));
|
|
390
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, 'build', 'object'));
|
|
391
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime.build, 'outDir', 'string'));
|
|
358
392
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, 'vitePluginServerEntry', 'object'));
|
|
359
393
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo, 'usesClientRouter', 'boolean'));
|
|
360
|
-
(0, utils_js_1.checkType)({ ...buildInfo, viteConfigRuntime: buildInfo.viteConfigRuntime });
|
|
361
394
|
}
|
|
362
395
|
function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
363
396
|
const versionAtRuntime = utils_js_1.PROJECT_VERSION;
|
|
364
397
|
const pretty = (version) => picocolors_1.default.bold(`vike@${version}`);
|
|
365
398
|
(0, utils_js_1.assertUsage)(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
366
399
|
}
|
|
367
|
-
function getViteConfigRuntime(viteConfig) {
|
|
368
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(viteConfig, '_baseViteOriginal', 'string'));
|
|
369
|
-
const viteConfigRuntime = {
|
|
370
|
-
_baseViteOriginal: viteConfig._baseViteOriginal,
|
|
371
|
-
vitePluginServerEntry: {
|
|
372
|
-
inject: viteConfig.vitePluginServerEntry?.inject
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
return viteConfigRuntime;
|
|
376
|
-
}
|
|
377
400
|
async function updateUserFiles() {
|
|
378
401
|
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
379
402
|
(0, utils_js_1.assert)(!globalObject.isProduction);
|
|
@@ -522,7 +522,6 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
522
522
|
if (isStreamReadableWeb(streamOriginal)) {
|
|
523
523
|
debug('onRenderHtml() hook returned Web Readable');
|
|
524
524
|
const readableOriginal = streamOriginal;
|
|
525
|
-
let controllerProxyIsClosed = false;
|
|
526
525
|
let isClosed = false;
|
|
527
526
|
let isCancel = false;
|
|
528
527
|
const closeStream = async () => {
|
|
@@ -531,7 +530,6 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
531
530
|
isClosed = true;
|
|
532
531
|
await onEnd(isCancel);
|
|
533
532
|
controllerProxy.close();
|
|
534
|
-
controllerProxyIsClosed = true;
|
|
535
533
|
};
|
|
536
534
|
let controllerProxy;
|
|
537
535
|
assertReadableStreamConstructor();
|
|
@@ -559,8 +557,8 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
559
557
|
});
|
|
560
558
|
const writeChunk = (chunk) => {
|
|
561
559
|
if (
|
|
562
|
-
// If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether
|
|
563
|
-
!
|
|
560
|
+
// If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether the steam is closed.
|
|
561
|
+
!isClosed) {
|
|
564
562
|
controllerProxy.enqueue(encodeForWebStream(chunk));
|
|
565
563
|
debugWithChunk('data written (Web Readable)', chunk);
|
|
566
564
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPageRenderer = exports._injectAssets = exports.createDevMiddleware = exports.getGlobalContextAsync = exports.getGlobalContextSync = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
3
|
+
exports.createPageRenderer = exports._injectAssets = exports.createDevMiddleware = exports.getGlobalContextAsync = exports.getGlobalContextSync = exports.getGlobalContext = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
4
4
|
var renderPage_js_1 = require("./renderPage.js");
|
|
5
5
|
Object.defineProperty(exports, "renderPage", { enumerable: true, get: function () { return renderPage_js_1.renderPage; } });
|
|
6
6
|
var renderHtml_js_1 = require("./html/renderHtml.js");
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "stampPipe", { enumerable: true, get: function ()
|
|
|
14
14
|
var utils_js_1 = require("./utils.js");
|
|
15
15
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
16
16
|
var globalContext_js_1 = require("./globalContext.js");
|
|
17
|
+
Object.defineProperty(exports, "getGlobalContext", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContext; } });
|
|
17
18
|
Object.defineProperty(exports, "getGlobalContextSync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextSync; } });
|
|
18
19
|
Object.defineProperty(exports, "getGlobalContextAsync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextAsync; } });
|
|
19
20
|
var index_js_1 = require("../runtime-dev/index.js");
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.renderPageAlreadyRouted = renderPageAlreadyRouted;
|
|
7
7
|
exports.prerenderPage = prerenderPage;
|
|
8
|
-
exports.prerender404Page = prerender404Page;
|
|
9
8
|
exports.getPageContextInitEnhanced = getPageContextInitEnhanced;
|
|
10
9
|
exports.createPageContext = createPageContext;
|
|
11
10
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
@@ -85,28 +84,6 @@ async function prerenderPage(pageContext) {
|
|
|
85
84
|
return { documentHtml, pageContextSerialized, pageContext };
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
async function prerender404Page(pageContextInit_, globalContext) {
|
|
89
|
-
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext.pageFilesAll, globalContext.pageConfigs);
|
|
90
|
-
if (!errorPageId) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
// A URL is required for `viteDevServer.transformIndexHtml(url,html)`
|
|
94
|
-
const pageContextInit = { urlOriginal: '/fake-404-url' };
|
|
95
|
-
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
96
|
-
const pageContext = await getPageContextInitEnhanced(pageContextInit, globalContext, true);
|
|
97
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
98
|
-
pageId: errorPageId,
|
|
99
|
-
_httpRequestId: null,
|
|
100
|
-
_urlRewrite: null,
|
|
101
|
-
is404: true,
|
|
102
|
-
routeParams: {},
|
|
103
|
-
// `prerender404Page()` is about generating `dist/client/404.html` for static hosts; there is no Client Routing.
|
|
104
|
-
_usesClientRouter: false,
|
|
105
|
-
_debugRouteMatches: []
|
|
106
|
-
});
|
|
107
|
-
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
108
|
-
return prerenderPage(pageContext);
|
|
109
|
-
}
|
|
110
87
|
async function getPageContextInitEnhanced(pageContextInit, globalContext, isPrerendering, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } = {
|
|
111
88
|
urlRewrite: null,
|
|
112
89
|
urlHandler: null,
|
|
@@ -10,7 +10,7 @@ const globalContext_js_1 = require("../runtime/globalContext.js");
|
|
|
10
10
|
* https://vike.dev/createDevMiddleware
|
|
11
11
|
*/
|
|
12
12
|
async function createDevMiddleware(options = {}) {
|
|
13
|
-
(0, globalContext_js_1.setGlobalContext_isProduction)(false);
|
|
13
|
+
(0, globalContext_js_1.setGlobalContext_isProduction)(false, true);
|
|
14
14
|
const optionsMod = {
|
|
15
15
|
...options,
|
|
16
16
|
viteConfig: {
|
|
@@ -72,7 +72,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
72
72
|
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlLogical')) {
|
|
73
73
|
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(
|
|
74
74
|
// We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
|
|
75
|
-
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')}
|
|
75
|
+
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} and ${picocolors_1.default.cyan('urlLogical')}`);
|
|
76
76
|
}
|
|
77
77
|
(0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(hookReturn.pageContext, {
|
|
78
78
|
hookFilePath: onBeforeRouteHook.hookFilePath,
|
|
@@ -18,23 +18,25 @@ const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
|
18
18
|
const executeOnBeforeRouteHook_js_1 = require("./executeOnBeforeRouteHook.js");
|
|
19
19
|
const debug_js_1 = require("./debug.js");
|
|
20
20
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
|
-
async function route(pageContext) {
|
|
21
|
+
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
22
22
|
(0, debug_js_1.debug)('Pages routes:', pageContext._pageRoutes);
|
|
23
23
|
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
24
24
|
const pageContextFromRoute = {};
|
|
25
25
|
// onBeforeRoute()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (pageContextFromOnBeforeRouteHook
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
if (!skipOnBeforeRouteHook) {
|
|
27
|
+
const pageContextFromOnBeforeRouteHook = await (0, executeOnBeforeRouteHook_js_1.executeOnBeforeRouteHook)(pageContext);
|
|
28
|
+
if (pageContextFromOnBeforeRouteHook) {
|
|
29
|
+
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
30
|
+
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.pageId);
|
|
31
|
+
return pageContextFromOnBeforeRouteHook;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
(0, utils_js_1.objectAssign)(pageContextFromRoute, pageContextFromOnBeforeRouteHook);
|
|
35
|
+
}
|
|
34
36
|
}
|
|
37
|
+
// We take into account pageContext.urlLogical set by onBeforeRoute()
|
|
38
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextFromOnBeforeRouteHook);
|
|
35
39
|
}
|
|
36
|
-
// We take into account pageContext.urlLogical set by onBeforeRoute()
|
|
37
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextFromOnBeforeRouteHook);
|
|
38
40
|
// Vike's routing
|
|
39
41
|
const allPageIds = pageContext._allPageIds;
|
|
40
42
|
(0, utils_js_1.assertUsage)(allPageIds.length > 0, 'No page found. You must create at least one page.');
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -98,12 +98,9 @@ function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
|
|
|
98
98
|
if (onlyOnce) {
|
|
99
99
|
const { alreadyLogged } = globalObject;
|
|
100
100
|
const key = onlyOnce === true ? msg : onlyOnce;
|
|
101
|
-
if (alreadyLogged.has(key))
|
|
101
|
+
if (alreadyLogged.has(key))
|
|
102
102
|
return;
|
|
103
|
-
|
|
104
|
-
else {
|
|
105
|
-
alreadyLogged.add(key);
|
|
106
|
-
}
|
|
103
|
+
alreadyLogged.add(key);
|
|
107
104
|
}
|
|
108
105
|
globalObject.onBeforeLog?.();
|
|
109
106
|
if (showStackTrace) {
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findPackageJson = findPackageJson;
|
|
4
4
|
const findFile_js_1 = require("./findFile.js");
|
|
5
5
|
const module_1 = require("module");
|
|
6
|
-
// @ts-ignore `file
|
|
7
|
-
const importMetaUrl = `file
|
|
6
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
7
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
8
8
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
9
9
|
function findPackageJson(cwd) {
|
|
10
10
|
const packageJsonPath = (0, findFile_js_1.findFile)('package.json', cwd);
|
|
@@ -24,8 +24,8 @@ function assertFilePathAbsoluteFilesystem(filePath) {
|
|
|
24
24
|
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
25
25
|
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
26
26
|
// - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
|
|
27
|
-
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
28
27
|
(0, path_js_1.assertPosixPath)(filePath);
|
|
28
|
+
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Whether `filePath` is an absolute file path starting from the filesystem root.
|
|
@@ -10,10 +10,10 @@ const assert_js_1 = require("./assert.js");
|
|
|
10
10
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
12
|
function isNpmPackageImport(str, { cannotBePathAlias }) {
|
|
13
|
-
// We cannot distinguish path alises that look like npm package imports
|
|
14
13
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
15
14
|
return isNpmPackageImport_unreliable(str);
|
|
16
15
|
}
|
|
16
|
+
// We cannot distinguish path aliases that look like npm package imports
|
|
17
17
|
function isNpmPackageImport_unreliable(str) {
|
|
18
18
|
const res = parse(str);
|
|
19
19
|
return res !== null;
|
|
@@ -8,12 +8,12 @@ const assert_js_1 = require("./assert.js");
|
|
|
8
8
|
// We can't use a RegExp:
|
|
9
9
|
// - Needs to work with Micromatch: https://github.com/micromatch/micromatch because:
|
|
10
10
|
// - Vite's `import.meta.glob()` uses Micromatch
|
|
11
|
-
// - We need this to be a
|
|
11
|
+
// - We need this to be a allowlist because:
|
|
12
12
|
// - A pattern `*([a-zA-Z0-9]` doesn't work.
|
|
13
13
|
// - Because of ReScript: `.res` are ReScript source files which need to be ignored. (The ReScript compiler generates `.js` files alongside `.res` files.)
|
|
14
|
-
// -
|
|
15
|
-
// - We cannot implement a
|
|
16
|
-
// - A post `import.meta.glob()`
|
|
14
|
+
// - Block listing doesn't work.
|
|
15
|
+
// - We cannot implement a blocklist with a glob pattern.
|
|
16
|
+
// - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
|
|
17
17
|
// prettier-ignore
|
|
18
18
|
// biome-ignore format:
|
|
19
19
|
const extJavaScript = [
|
|
@@ -186,14 +186,14 @@ function parseProtocol(uri) {
|
|
|
186
186
|
return { protocol, uriWithoutProtocol };
|
|
187
187
|
}
|
|
188
188
|
function isUrlProtocol(protocol) {
|
|
189
|
-
// Is there an
|
|
190
|
-
// - If the
|
|
191
|
-
const
|
|
189
|
+
// Is there an alternative to having a blocklist?
|
|
190
|
+
// - If the blocklist becomes too big, maybe use a allowlist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
|
|
191
|
+
const blocklist = [
|
|
192
192
|
// https://docs.ipfs.tech/how-to/address-ipfs-on-web
|
|
193
193
|
'ipfs://',
|
|
194
194
|
'ipns://'
|
|
195
195
|
];
|
|
196
|
-
if (
|
|
196
|
+
if (blocklist.includes(protocol))
|
|
197
197
|
return false;
|
|
198
198
|
return protocol.endsWith('://');
|
|
199
199
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preservePropertyGetters = preservePropertyGetters;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
function preservePropertyGetters(objOriginal) {
|
|
6
|
+
// Store original getter descriptors
|
|
7
|
+
const getters = Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(objOriginal)).filter(([_, desc]) => 'get' in desc));
|
|
8
|
+
// Make getters non-enumerable
|
|
9
|
+
for (const [key, desc] of Object.entries(getters)) {
|
|
10
|
+
Object.defineProperty(objOriginal, key, { ...desc, enumerable: false });
|
|
11
|
+
}
|
|
12
|
+
const restorePropertyGetters = function () {
|
|
13
|
+
const objCopy = this;
|
|
14
|
+
delete objOriginal._restorePropertyGetters;
|
|
15
|
+
delete objCopy._restorePropertyGetters;
|
|
16
|
+
for (const [key, desc] of Object.entries(getters)) {
|
|
17
|
+
if (objCopy !== objOriginal) {
|
|
18
|
+
(0, assert_js_1.assert)(!(key in objCopy));
|
|
19
|
+
Object.defineProperty(objCopy, key, desc); // Add property getters to copy
|
|
20
|
+
}
|
|
21
|
+
(0, assert_js_1.assert)(key in objOriginal);
|
|
22
|
+
Object.defineProperty(objOriginal, key, desc); // Restore original `enumerable` value
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(objOriginal, '_restorePropertyGetters', {
|
|
26
|
+
value: restorePropertyGetters,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,37 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.requireResolve = requireResolve;
|
|
7
|
+
exports.requireResolveOptional = requireResolveOptional;
|
|
8
|
+
exports.requireResolveNonUserFile = requireResolveNonUserFile;
|
|
9
|
+
exports.requireResolveOptionalNonUserFile = requireResolveOptionalNonUserFile;
|
|
4
10
|
const assert_js_1 = require("./assert.js");
|
|
5
11
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
6
12
|
const assertSetup_js_1 = require("./assertSetup.js");
|
|
7
13
|
const path_js_1 = require("./path.js");
|
|
8
14
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
15
|
+
const node_module_1 = require("node:module");
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
18
|
+
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
19
|
+
const require_ = (0, node_module_1.createRequire)(importMetaUrl);
|
|
13
20
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
14
21
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
15
|
-
|
|
16
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
17
|
-
function requireResolve(importPath, cwd) {
|
|
22
|
+
function requireResolve_(importPath, cwd, options) {
|
|
18
23
|
(0, path_js_1.assertPosixPath)(cwd);
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
(0, path_js_1.assertPosixPath)(importPath);
|
|
25
|
+
cwd = resolveCwd(cwd);
|
|
26
|
+
let clean = () => { };
|
|
27
|
+
if (!options?.doNotHandleFileExtension) {
|
|
28
|
+
clean = addFileExtensionsToRequireResolve();
|
|
29
|
+
importPath = removeFileExtention(importPath);
|
|
30
|
+
}
|
|
21
31
|
let importedFile;
|
|
22
32
|
try {
|
|
33
|
+
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
34
|
+
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
23
35
|
importedFile = require_.resolve(importPath, { paths: [cwd] });
|
|
24
36
|
}
|
|
25
|
-
catch {
|
|
26
|
-
importedFile = null;
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
37
|
+
catch (err) {
|
|
29
38
|
clean();
|
|
39
|
+
return { importedFile: undefined, err, hasFailed: true };
|
|
30
40
|
}
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
clean();
|
|
42
|
+
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
43
|
+
return { importedFile, err: undefined, hasFailed: false };
|
|
44
|
+
}
|
|
45
|
+
function requireResolveOptional(importPath, cwd) {
|
|
46
|
+
const res = requireResolve_(importPath, cwd);
|
|
47
|
+
if (res.hasFailed)
|
|
48
|
+
return null;
|
|
49
|
+
return res.importedFile;
|
|
50
|
+
}
|
|
51
|
+
function requireResolveOptionalNonUserFile(importPath, cwd) {
|
|
52
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
53
|
+
if (res.hasFailed)
|
|
54
|
+
return null;
|
|
55
|
+
return res.importedFile;
|
|
56
|
+
}
|
|
57
|
+
function requireResolveNonUserFile(importPath, cwd) {
|
|
58
|
+
const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
|
|
59
|
+
if (res.hasFailed)
|
|
60
|
+
throw res.err;
|
|
61
|
+
return res.importedFile;
|
|
62
|
+
}
|
|
63
|
+
function requireResolve(importPath, cwd) {
|
|
64
|
+
const res = requireResolve_(importPath, cwd);
|
|
65
|
+
if (res.hasFailed)
|
|
66
|
+
throw res.err;
|
|
67
|
+
return res.importedFile;
|
|
68
|
+
}
|
|
69
|
+
function resolveCwd(cwd) {
|
|
70
|
+
let prefix = 'file://';
|
|
71
|
+
if (process.platform === 'win32')
|
|
72
|
+
prefix += '/';
|
|
73
|
+
if (cwd.startsWith(prefix)) {
|
|
74
|
+
cwd = cwd.slice(prefix.length);
|
|
75
|
+
cwd = node_path_1.default.posix.dirname(cwd);
|
|
33
76
|
}
|
|
34
|
-
|
|
77
|
+
(0, assert_js_1.assert)(!cwd.startsWith('file:'));
|
|
78
|
+
return cwd;
|
|
35
79
|
}
|
|
36
80
|
function removeFileExtention(importPath) {
|
|
37
81
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.rollupSourceMapRemove = rollupSourceMapRemove;
|
|
4
|
+
exports.rollupSourceMapPassthrough = rollupSourceMapPassthrough;
|
|
5
5
|
// https://rollupjs.org/guide/en/#source-code-transformations
|
|
6
6
|
/** Remove entire source mapping, to save KBs. */
|
|
7
|
-
function
|
|
7
|
+
function rollupSourceMapRemove(code) {
|
|
8
8
|
return {
|
|
9
9
|
code,
|
|
10
10
|
map: { mappings: '' }
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/** Don't provide any source map, pass through current source map instead. */
|
|
14
|
-
function
|
|
14
|
+
function rollupSourceMapPassthrough(code) {
|
|
15
15
|
return {
|
|
16
16
|
code,
|
|
17
17
|
map: null
|
|
@@ -3,9 +3,9 @@ import { isSameAsCurrentUrl, skipLink } from './skipLink.js';
|
|
|
3
3
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
4
4
|
import { scrollToHashOrTop } from './setScrollPosition.js';
|
|
5
5
|
function initOnLinkClick() {
|
|
6
|
-
document.addEventListener('click',
|
|
6
|
+
document.addEventListener('click', onLinkClick);
|
|
7
7
|
}
|
|
8
|
-
async function
|
|
8
|
+
async function onLinkClick(ev) {
|
|
9
9
|
if (!isNormalLeftClick(ev))
|
|
10
10
|
return;
|
|
11
11
|
const linkTag = findLinkTag(ev.target);
|
package/dist/esm/node/api/dev.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { dev };
|
|
2
2
|
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { createServer } from 'vite';
|
|
4
|
+
import { setGlobalContext_isProduction } from '../runtime/globalContext.js';
|
|
4
5
|
/**
|
|
5
6
|
* Programmatically trigger `$ vike dev`
|
|
6
7
|
*
|
|
7
8
|
* https://vike.dev/api#dev
|
|
8
9
|
*/
|
|
9
10
|
async function dev(options = {}) {
|
|
11
|
+
setGlobalContext_isProduction(false);
|
|
10
12
|
const { viteConfigFromUserEnhanced } = await prepareViteApiCall(options, 'dev');
|
|
11
13
|
const server = await createServer(viteConfigFromUserEnhanced);
|
|
12
14
|
return {
|
|
@@ -296,16 +296,21 @@ function handleAssetsManifest_getBuildConfig(config) {
|
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
298
|
async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
299
|
-
|
|
299
|
+
const isSsREnv = isViteServerBuild_onlySsrEnv(config, viteEnv);
|
|
300
|
+
if (isSsREnv) {
|
|
300
301
|
assert(!assetsJsonFilePath);
|
|
301
302
|
const outDirs = getOutDirs(config, viteEnv);
|
|
302
303
|
assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
303
304
|
await writeAssetsManifestFile(outDirs, assetsJsonFilePath, config);
|
|
304
305
|
}
|
|
305
306
|
if (isViteServerBuild(config, viteEnv)) {
|
|
306
|
-
|
|
307
|
-
//
|
|
308
|
-
|
|
307
|
+
// Replace __VITE_ASSETS_MANIFEST__ in server builds
|
|
308
|
+
// - Always replace it in dist/server/
|
|
309
|
+
// - Also in some other server builds such as dist/vercel/ from vike-vercel
|
|
310
|
+
// - Don't replace it in dist/rsc/ from vike-react-rsc since __VITE_ASSETS_MANIFEST__ doesn't exist there
|
|
311
|
+
const noop = await set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath);
|
|
312
|
+
if (isSsREnv)
|
|
313
|
+
assert(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
|
|
309
314
|
}
|
|
310
315
|
}
|
|
311
316
|
async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
|