vike 0.4.224-commit-00ed9fe → 0.4.225-commit-37a36a5
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/build.js +1 -1
- package/dist/cjs/node/api/context.js +4 -4
- package/dist/cjs/node/api/dev.js +1 -1
- package/dist/cjs/node/api/prepareViteApiCall.js +3 -2
- package/dist/cjs/node/api/prerender.js +1 -1
- package/dist/cjs/node/api/preview.js +1 -1
- package/dist/cjs/node/cli/context.js +5 -4
- package/dist/cjs/node/cli/entry.js +3 -3
- package/dist/cjs/node/cli/parseCli.js +43 -15
- package/dist/cjs/node/cli/utils.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +15 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +138 -83
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
- package/dist/cjs/node/plugin/shared/getEnvVarObject.js +9 -8
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -17
- package/dist/cjs/node/prerender/runPrerender.js +2 -2
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +9 -5
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/cjs/node/runtime/utils.js +0 -1
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +10 -8
- package/dist/cjs/node/shared/assertV1Design.js +2 -1
- package/dist/cjs/node/shared/utils.js +0 -1
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +19 -2
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +8 -5
- package/dist/cjs/shared/page-configs/helpers.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -5
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -5
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +11 -4
- package/dist/cjs/utils/assertSingleInstance.js +11 -17
- package/dist/cjs/utils/getRandomId.js +1 -1
- package/dist/cjs/utils/normalizeHeaders.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -2
- package/dist/esm/node/api/build.js +1 -1
- package/dist/esm/node/api/context.d.ts +8 -2
- package/dist/esm/node/api/context.js +4 -4
- package/dist/esm/node/api/dev.js +1 -1
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.js +3 -2
- package/dist/esm/node/api/prerender.js +1 -1
- package/dist/esm/node/api/preview.js +1 -1
- package/dist/esm/node/api/types.d.ts +7 -0
- package/dist/esm/node/cli/context.d.ts +4 -2
- package/dist/esm/node/cli/context.js +5 -4
- package/dist/esm/node/cli/entry.js +4 -4
- package/dist/esm/node/cli/parseCli.d.ts +3 -0
- package/dist/esm/node/cli/parseCli.js +44 -16
- package/dist/esm/node/cli/utils.d.ts +1 -1
- package/dist/esm/node/cli/utils.js +1 -1
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -84
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
- package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +3 -1
- package/dist/esm/node/plugin/shared/getEnvVarObject.js +9 -8
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +2 -2
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +26 -18
- package/dist/esm/node/prerender/runPrerender.js +3 -3
- 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.js +10 -6
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -3
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/esm/node/runtime/utils.d.ts +0 -1
- package/dist/esm/node/runtime/utils.js +0 -1
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +10 -8
- package/dist/esm/node/shared/assertV1Design.js +2 -1
- package/dist/esm/node/shared/utils.d.ts +0 -1
- package/dist/esm/node/shared/utils.js +0 -1
- package/dist/esm/shared/page-configs/Config.d.ts +19 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +16 -5
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +5 -3
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +20 -3
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +8 -5
- package/dist/esm/shared/page-configs/helpers.js +1 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -5
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -3
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -5
- package/dist/esm/shared/route/loadPageRoutes.js +2 -2
- package/dist/esm/shared/types.d.ts +5 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.d.ts +2 -1
- package/dist/esm/utils/assert.js +11 -4
- package/dist/esm/utils/assertSingleInstance.js +11 -17
- package/dist/esm/utils/getRandomId.d.ts +1 -1
- package/dist/esm/utils/getRandomId.js +1 -1
- package/dist/esm/utils/normalizeHeaders.js +1 -1
- package/package.json +5 -3
- package/dist/cjs/utils/projectInfo.js +0 -8
- package/dist/esm/utils/projectInfo.d.ts +0 -4
- package/dist/esm/utils/projectInfo.js +0 -5
|
@@ -76,7 +76,7 @@ async function runPrerenderFromAPI(options = {}) {
|
|
|
76
76
|
}
|
|
77
77
|
async function runPrerenderFromCLIPrerenderCommand() {
|
|
78
78
|
try {
|
|
79
|
-
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(
|
|
79
|
+
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)({}, 'prerender');
|
|
80
80
|
await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
@@ -113,7 +113,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
113
113
|
(0, getHook_js_1.getHook_setIsPrerenderering)();
|
|
114
114
|
const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
|
|
115
115
|
if (logLevel === 'info') {
|
|
116
|
-
console.log(`${picocolors_1.default.cyan(`vike v${utils_js_1.
|
|
116
|
+
console.log(`${picocolors_1.default.cyan(`vike v${utils_js_1.PROJECT_VERSION}`)} ${picocolors_1.default.green('pre-rendering HTML...')}`);
|
|
117
117
|
}
|
|
118
118
|
await disableReactStreaming();
|
|
119
119
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'build', 'production');
|
|
@@ -18,7 +18,7 @@ const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
|
|
|
18
18
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
19
19
|
__exportStar(require("../../utils/assert.js"), exports);
|
|
20
20
|
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
21
|
-
__exportStar(require("../../utils/
|
|
21
|
+
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
22
22
|
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
23
23
|
__exportStar(require("../../utils/isObjectWithKeys.js"), exports);
|
|
24
24
|
__exportStar(require("../../utils/isCallable.js"), exports);
|
|
@@ -92,9 +92,10 @@ function makePublic(globalContext) {
|
|
|
92
92
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
93
93
|
debug('setGlobalContext_viteDevServer()');
|
|
94
94
|
setIsProduction(false);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
// We cannot cache globalObject.viteDevServer because it's fully replaced when the user modifies vite.config.js => Vite's dev server is fully reloaded and a new viteDevServer replaces the previous one.
|
|
96
|
+
if (!globalObject.viteDevServer) {
|
|
97
|
+
assertIsNotInitilizedYet();
|
|
98
|
+
}
|
|
98
99
|
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
99
100
|
globalObject.viteDevServer = viteDevServer;
|
|
100
101
|
await updateUserFiles();
|
|
@@ -354,7 +355,7 @@ function assertBuildInfo(buildInfo) {
|
|
|
354
355
|
(0, utils_js_1.checkType)({ ...buildInfo, viteConfigRuntime: buildInfo.viteConfigRuntime });
|
|
355
356
|
}
|
|
356
357
|
function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
357
|
-
const versionAtRuntime = utils_js_1.
|
|
358
|
+
const versionAtRuntime = utils_js_1.PROJECT_VERSION;
|
|
358
359
|
const pretty = (version) => picocolors_1.default.bold(`vike@${version}`);
|
|
359
360
|
(0, utils_js_1.assertUsage)(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
360
361
|
}
|
|
@@ -372,7 +373,7 @@ async function updateUserFiles() {
|
|
|
372
373
|
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
373
374
|
(0, utils_js_1.assert)(!globalObject.isProduction);
|
|
374
375
|
globalObject.waitForUserFilesUpdate = promise;
|
|
375
|
-
const viteDevServer =
|
|
376
|
+
const { viteDevServer } = globalObject;
|
|
376
377
|
(0, utils_js_1.assert)(viteDevServer);
|
|
377
378
|
let virtualFileExports;
|
|
378
379
|
try {
|
|
@@ -384,6 +385,9 @@ async function updateUserFiles() {
|
|
|
384
385
|
}
|
|
385
386
|
virtualFileExports = virtualFileExports.default || virtualFileExports;
|
|
386
387
|
(0, utils_js_1.debugGlob)('Glob result: ', virtualFileExports);
|
|
388
|
+
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
389
|
+
if (viteDevServer !== globalObject.viteDevServer)
|
|
390
|
+
return;
|
|
387
391
|
await setUserFiles(virtualFileExports);
|
|
388
392
|
resolve();
|
|
389
393
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getViteDevScript = getViteDevScript;
|
|
7
7
|
const utils_js_1 = require("../../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
9
10
|
async function getViteDevScript(pageContext) {
|
|
10
11
|
const globalContext = pageContext._globalContext;
|
|
11
12
|
if (globalContext.isProduction) {
|
|
@@ -17,11 +18,13 @@ async function getViteDevScript(pageContext) {
|
|
|
17
18
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
18
19
|
fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
|
|
19
20
|
(0, utils_js_1.assertUsage)(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${picocolors_1.default.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
20
|
-
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')),
|
|
21
|
-
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd),
|
|
21
|
+
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
22
|
+
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
22
23
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
23
24
|
(0, utils_js_1.assert)(viteInjection.includes('script'));
|
|
24
|
-
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('),
|
|
25
|
+
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('), `Unexpected Vite injected HMR code. ${reachOutCTA}`, {
|
|
26
|
+
onlyOnce: true
|
|
27
|
+
});
|
|
25
28
|
const viteDevScript = viteInjection;
|
|
26
29
|
return viteDevScript;
|
|
27
30
|
}
|
|
@@ -9,14 +9,15 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
|
-
// It's too strict, see https://github.com/vikejs/vike/issues/1270#issuecomment-1820608999
|
|
13
|
-
// - Let's create a new setting `+doNotCatchInfiniteRedirect` if someone complains.
|
|
14
12
|
function assertNoInfiniteHttpRedirect(
|
|
15
13
|
// The exact URL that the user will be redirected to.
|
|
16
14
|
// - It includes the Base URL as well as the locale (i18n) base.
|
|
17
15
|
urlRedirectTarget,
|
|
18
16
|
// Rationale for checking against `pageContextInit.urlOriginal`: https://github.com/vikejs/vike/pull/2264#issuecomment-2713890263
|
|
19
17
|
pageContextInit) {
|
|
18
|
+
// TO-DO/eventually: use cookie as described at https://github.com/vikejs/vike/pull/2273
|
|
19
|
+
if (true)
|
|
20
|
+
return 'DISABLED'; // Disabled until we make it reliable.
|
|
20
21
|
if (!urlRedirectTarget.startsWith('/')) {
|
|
21
22
|
// We assume that urlRedirectTarget points to an origin that is external (not the same origin), and we can therefore assume that the app doesn't define an infinite loop (at least not in itself).
|
|
22
23
|
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin; we hope/assume the user sets the URL without origin.
|
|
@@ -31,7 +31,6 @@ __exportStar(require("../../utils/parseUrl.js"), exports);
|
|
|
31
31
|
__exportStar(require("../../utils/parseUrl-extras.js"), exports);
|
|
32
32
|
__exportStar(require("../../utils/slice.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/sorter.js"), exports);
|
|
34
|
-
__exportStar(require("../../utils/projectInfo.js"), exports);
|
|
35
34
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
36
35
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
37
36
|
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
@@ -11,16 +11,18 @@ const globalContext_js_1 = require("../runtime/globalContext.js");
|
|
|
11
11
|
*/
|
|
12
12
|
async function createDevMiddleware(options = {}) {
|
|
13
13
|
(0, globalContext_js_1.setGlobalContext_isProduction)(false);
|
|
14
|
-
const
|
|
15
|
-
...options
|
|
16
|
-
|
|
17
|
-
...options.viteConfig
|
|
18
|
-
|
|
14
|
+
const optionsMod = {
|
|
15
|
+
...options,
|
|
16
|
+
viteConfig: {
|
|
17
|
+
...options.viteConfig,
|
|
18
|
+
root: options.root ?? options.viteConfig?.root,
|
|
19
|
+
server: {
|
|
20
|
+
...options.viteConfig?.server,
|
|
21
|
+
middlewareMode: options.viteConfig?.server?.middlewareMode ?? true
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
|
-
|
|
22
|
-
viteConfigFromOptions.root = options.root;
|
|
23
|
-
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(viteConfigFromOptions, 'dev');
|
|
25
|
+
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(optionsMod, 'dev');
|
|
24
26
|
const server = await (0, vite_1.createServer)(viteConfigEnhanced);
|
|
25
27
|
const devMiddleware = server.middlewares;
|
|
26
28
|
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
@@ -12,7 +12,8 @@ function assertV1Design(pageConfigs, pageFilesAll) {
|
|
|
12
12
|
(0, utils_js_1.assert)(pageConfigs.length > 0);
|
|
13
13
|
const filesV1 = (0, utils_js_1.unique)(pageConfigs
|
|
14
14
|
.map((p) => Object.values(p.configValueSources).map((sources) => sources
|
|
15
|
-
.map((c) => c.
|
|
15
|
+
.map((c) => c.definedAt)
|
|
16
|
+
.map((definedAt) => (definedAt.definedBy ? null : definedAt.filePathAbsoluteUserRootDir))
|
|
16
17
|
.filter(utils_js_1.isNotNullish)
|
|
17
18
|
.map((filePathToShowToUser) => indent + filePathToShowToUser)))
|
|
18
19
|
.flat(2));
|
|
@@ -19,7 +19,6 @@ const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
|
|
|
19
19
|
__exportStar(require("../../utils/assert.js"), exports);
|
|
20
20
|
__exportStar(require("../../utils/getFileExtension.js"), exports);
|
|
21
21
|
__exportStar(require("../../utils/isPlainObject.js"), exports);
|
|
22
|
-
__exportStar(require("../../utils/projectInfo.js"), exports);
|
|
23
22
|
__exportStar(require("../../utils/checkType.js"), exports);
|
|
24
23
|
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
25
24
|
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getConfigDefinedAt = getConfigDefinedAt;
|
|
7
7
|
exports.getConfigDefinedAtOptional = getConfigDefinedAtOptional;
|
|
8
8
|
exports.getDefinedAtString = getDefinedAtString;
|
|
9
|
+
exports.getDefinedByString = getDefinedByString;
|
|
9
10
|
const utils_js_1 = require("../utils.js");
|
|
10
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
12
|
const getExportPath_js_1 = require("./getExportPath.js");
|
|
@@ -33,8 +34,10 @@ function getDefinedAtString(definedAtData, configName) {
|
|
|
33
34
|
}
|
|
34
35
|
(0, utils_js_1.assert)(files.length >= 1);
|
|
35
36
|
const definedAtString = files
|
|
36
|
-
.map((
|
|
37
|
-
|
|
37
|
+
.map((definedAt) => {
|
|
38
|
+
if (definedAt.definedBy)
|
|
39
|
+
return getDefinedByString(definedAt, configName);
|
|
40
|
+
const { filePathToShowToUser, fileExportPathToShowToUser } = definedAt;
|
|
38
41
|
let s = filePathToShowToUser;
|
|
39
42
|
const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPathToShowToUser, configName);
|
|
40
43
|
if (exportPath) {
|
|
@@ -45,3 +48,17 @@ function getDefinedAtString(definedAtData, configName) {
|
|
|
45
48
|
.join(' / ');
|
|
46
49
|
return definedAtString;
|
|
47
50
|
}
|
|
51
|
+
function getDefinedByString(definedAt, configName) {
|
|
52
|
+
if (definedAt.definedBy === 'api') {
|
|
53
|
+
return `API call ${picocolors_1.default.cyan(`${definedAt.operation}({ vikeConfig: { ${configName} } })`)}`;
|
|
54
|
+
}
|
|
55
|
+
const { definedBy } = definedAt;
|
|
56
|
+
if (definedBy === 'cli') {
|
|
57
|
+
return `CLI option ${picocolors_1.default.cyan(`--${configName}`)}`;
|
|
58
|
+
}
|
|
59
|
+
if (definedBy === 'env') {
|
|
60
|
+
return `environment variable ${picocolors_1.default.cyan(`VIKE_CONFIG="{${configName}}"`)}`;
|
|
61
|
+
}
|
|
62
|
+
(0, utils_js_1.checkType)(definedBy);
|
|
63
|
+
(0, utils_js_1.assert)(false);
|
|
64
|
+
}
|
|
@@ -33,7 +33,7 @@ function getConfigValue(pageConfig, configName) {
|
|
|
33
33
|
return {
|
|
34
34
|
type: 'standard',
|
|
35
35
|
value: configValueSource.value,
|
|
36
|
-
definedAtData:
|
|
36
|
+
definedAtData: getDefinedAt(configValueSource)
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
@@ -53,13 +53,16 @@ function mergeCumulative(configValueSources) {
|
|
|
53
53
|
(0, utils_js_1.assert)(configValueSource.configEnv.config === true);
|
|
54
54
|
(0, utils_js_1.assert)(configValueSource.valueIsLoaded);
|
|
55
55
|
value.push(configValueSource.value);
|
|
56
|
-
definedAtData.push(
|
|
56
|
+
definedAtData.push(getDefinedAt(configValueSource));
|
|
57
57
|
});
|
|
58
58
|
return { value, definedAtData };
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function getDefinedAt(configValueSource) {
|
|
61
|
+
const { definedAt } = configValueSource;
|
|
62
|
+
if (definedAt.definedBy)
|
|
63
|
+
return definedAt;
|
|
61
64
|
return {
|
|
62
|
-
filePathToShowToUser:
|
|
63
|
-
fileExportPathToShowToUser:
|
|
65
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
66
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
64
67
|
};
|
|
65
68
|
}
|
|
@@ -14,7 +14,7 @@ function getConfigValueFilePathToShowToUser(definedAtData) {
|
|
|
14
14
|
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
15
15
|
// - cumulative config values have multiple file paths
|
|
16
16
|
// - computed values don't have any file path
|
|
17
|
-
if (!definedAtData || (0, utils_js_1.isArray)(definedAtData))
|
|
17
|
+
if (!definedAtData || (0, utils_js_1.isArray)(definedAtData) || definedAtData.definedBy)
|
|
18
18
|
return null;
|
|
19
19
|
const { filePathToShowToUser } = definedAtData;
|
|
20
20
|
(0, utils_js_1.assert)(filePathToShowToUser);
|
|
@@ -6,10 +6,6 @@ const utils_js_1 = require("../../utils.js");
|
|
|
6
6
|
const getConfigDefinedAt_js_1 = require("../getConfigDefinedAt.js");
|
|
7
7
|
const parse_1 = require("@brillout/json-serializer/parse");
|
|
8
8
|
const assertPlusFileExport_js_1 = require("../assertPlusFileExport.js");
|
|
9
|
-
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
10
|
-
const configValues = parseConfigValuesSerialized_tmp(configValuesSerialized);
|
|
11
|
-
return configValues;
|
|
12
|
-
}
|
|
13
9
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
14
10
|
// pageConfigs
|
|
15
11
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
@@ -45,7 +41,7 @@ function assertRouteConfigValue(configValues) {
|
|
|
45
41
|
}
|
|
46
42
|
*/
|
|
47
43
|
}
|
|
48
|
-
function
|
|
44
|
+
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
49
45
|
const configValues = {};
|
|
50
46
|
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
51
47
|
let configValue;
|
|
@@ -102,6 +98,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
|
102
98
|
if (valueSerialized.type === 'plus-file') {
|
|
103
99
|
const definedAtFile = getDefinedAtFile();
|
|
104
100
|
const { exportValues } = valueSerialized;
|
|
101
|
+
(0, utils_js_1.assert)(!definedAtFile.definedBy);
|
|
105
102
|
(0, assertPlusFileExport_js_1.assertPlusFileExport)(exportValues, definedAtFile.filePathToShowToUser, configName);
|
|
106
103
|
let value;
|
|
107
104
|
let valueWasFound = false;
|
|
@@ -52,7 +52,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
52
52
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
53
53
|
let valueData;
|
|
54
54
|
if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
|
|
55
|
-
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.
|
|
55
|
+
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAt, importStatements, filesEnv, configValueSource.configEnv);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
58
|
valueData = getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName);
|
|
@@ -103,8 +103,9 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
103
103
|
}
|
|
104
104
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
105
105
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
106
|
-
const { valueIsDefinedByPlusValueFile,
|
|
107
|
-
|
|
106
|
+
const { valueIsDefinedByPlusValueFile, definedAt, configEnv } = configValueSource;
|
|
107
|
+
(0, utils_js_1.assert)(!definedAt.definedBy);
|
|
108
|
+
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
108
109
|
if (valueIsDefinedByPlusValueFile)
|
|
109
110
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
110
111
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
@@ -231,9 +232,12 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
231
232
|
return [...fromComputed, ...fromSources].filter((r) => r !== 'SKIP');
|
|
232
233
|
}
|
|
233
234
|
function getDefinedAtFileSource(source) {
|
|
235
|
+
const { definedAt } = source;
|
|
236
|
+
if (definedAt.definedBy)
|
|
237
|
+
return definedAt;
|
|
234
238
|
const definedAtFile = {
|
|
235
|
-
filePathToShowToUser:
|
|
236
|
-
fileExportPathToShowToUser:
|
|
239
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
240
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
237
241
|
};
|
|
238
242
|
return definedAtFile;
|
|
239
243
|
}
|
|
@@ -62,11 +62,11 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
62
62
|
if (!pageRoute) {
|
|
63
63
|
const { routeFilesystem } = pageConfig;
|
|
64
64
|
(0, utils_js_1.assert)(routeFilesystem);
|
|
65
|
-
const { routeString,
|
|
65
|
+
const { routeString, definedAtLocation } = routeFilesystem;
|
|
66
66
|
(0, utils_js_1.assert)(routeFilesystem.routeString.startsWith('/'));
|
|
67
67
|
pageRoute = {
|
|
68
68
|
pageId,
|
|
69
|
-
routeFilesystemDefinedBy:
|
|
69
|
+
routeFilesystemDefinedBy: definedAtLocation,
|
|
70
70
|
comesFromV1PageConfig,
|
|
71
71
|
routeString,
|
|
72
72
|
routeDefinedAtString: null,
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -17,7 +17,7 @@ const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
|
17
17
|
const createErrorWithCleanStackTrace_js_1 = require("./createErrorWithCleanStackTrace.js");
|
|
18
18
|
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
19
19
|
const isObject_js_1 = require("./isObject.js");
|
|
20
|
-
const
|
|
20
|
+
const PROJECT_VERSION_js_1 = require("./PROJECT_VERSION.js");
|
|
21
21
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
22
22
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts', {
|
|
23
23
|
alreadyLogged: new Set(),
|
|
@@ -34,7 +34,7 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
|
|
|
34
34
|
});
|
|
35
35
|
(0, assertSingleInstance_js_1.assertSingleInstance_onAssertModuleLoad)();
|
|
36
36
|
const projectTag = `[vike]`;
|
|
37
|
-
const projectTagWithVersion = `[vike@${
|
|
37
|
+
const projectTagWithVersion = `[vike@${PROJECT_VERSION_js_1.PROJECT_VERSION}]`;
|
|
38
38
|
const bugTag = 'Bug';
|
|
39
39
|
const numberOfStackTraceLinesToRemove = 2;
|
|
40
40
|
function assert(condition, debugInfo) {
|
|
@@ -61,7 +61,7 @@ function assert(condition, debugInfo) {
|
|
|
61
61
|
globalObject.onBeforeLog?.();
|
|
62
62
|
throw internalError;
|
|
63
63
|
}
|
|
64
|
-
function assertUsage(condition, errMsg, { showStackTrace } = {}) {
|
|
64
|
+
function assertUsage(condition, errMsg, { showStackTrace, exitOnError } = {}) {
|
|
65
65
|
if (condition)
|
|
66
66
|
return;
|
|
67
67
|
showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
|
|
@@ -73,7 +73,13 @@ function assertUsage(condition, errMsg, { showStackTrace } = {}) {
|
|
|
73
73
|
globalObject.showStackTraceList.add(usageError);
|
|
74
74
|
}
|
|
75
75
|
globalObject.onBeforeLog?.();
|
|
76
|
-
|
|
76
|
+
if (!exitOnError) {
|
|
77
|
+
throw usageError;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.error(showStackTrace ? usageError : errMsg);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
77
83
|
}
|
|
78
84
|
function getProjectError(errMsg) {
|
|
79
85
|
errMsg = addWhitespace(errMsg);
|
|
@@ -187,6 +193,7 @@ function overwriteAssertProductionLogger(logger) {
|
|
|
187
193
|
function isBug(err) {
|
|
188
194
|
return String(err).includes(`[${bugTag}]`);
|
|
189
195
|
}
|
|
196
|
+
// Called upon `DEBUG=vike:error`
|
|
190
197
|
function setAlwaysShowStackTrace() {
|
|
191
198
|
globalObject.alwaysShowStackTrace = true;
|
|
192
199
|
}
|
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.assertSingleInstance_onClientEntryServerRouting = assertSingleInstance_onClientEntryServerRouting;
|
|
7
7
|
exports.assertSingleInstance_onClientEntryClientRouting = assertSingleInstance_onClientEntryClientRouting;
|
|
8
8
|
exports.assertSingleInstance_onAssertModuleLoad = assertSingleInstance_onAssertModuleLoad;
|
|
9
|
-
// -
|
|
9
|
+
// - Show warning if there are two different Vike versions loaded
|
|
10
10
|
// - Show warning if entry of Client Routing and entry of Server Routing are both loaded
|
|
11
|
-
// - Show warning if
|
|
11
|
+
// - Show warning if Vike is loaded twice
|
|
12
12
|
const unique_js_1 = require("./unique.js");
|
|
13
13
|
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
14
|
-
const projectInfo_js_1 = require("./projectInfo.js");
|
|
15
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const PROJECT_VERSION_js_1 = require("./PROJECT_VERSION.js");
|
|
16
|
+
/* Use original assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
17
|
+
import { assertWarning } from './assert.js'
|
|
18
18
|
*/
|
|
19
19
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
|
|
20
20
|
instances: [],
|
|
@@ -25,9 +25,10 @@ const clientNotSingleInstance = 'Client runtime loaded twice https://vike.dev/cl
|
|
|
25
25
|
function assertSingleInstance() {
|
|
26
26
|
{
|
|
27
27
|
const versions = (0, unique_js_1.unique)(globalObject.instances);
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
28
|
+
assertWarning(versions.length <= 1,
|
|
29
|
+
// Do *NOT* patch Vike to remove this warning: you *will* eventually encounter the issues listed at https://vike.dev/warning/version-mismatch
|
|
30
|
+
// - This happened before: https://github.com/vikejs/vike/issues/1108#issuecomment-1719061509
|
|
31
|
+
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded which is highly discouraged, see ${picocolors_1.default.underline('https://vike.dev/warning/version-mismatch')}`, { onlyOnce: true, showStackTrace: false });
|
|
31
32
|
}
|
|
32
33
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
33
34
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|
|
@@ -67,21 +68,14 @@ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
|
67
68
|
}
|
|
68
69
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
69
70
|
function assertSingleInstance_onAssertModuleLoad() {
|
|
70
|
-
globalObject.instances.push(
|
|
71
|
+
globalObject.instances.push(PROJECT_VERSION_js_1.PROJECT_VERSION);
|
|
71
72
|
assertSingleInstance();
|
|
72
73
|
}
|
|
73
|
-
function assertUsage(condition, errorMessage) {
|
|
74
|
-
if (condition) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const errMsg = `[vike][Wrong Usage] ${errorMessage}`;
|
|
78
|
-
throw new Error(errMsg);
|
|
79
|
-
}
|
|
80
74
|
function assertWarning(condition, errorMessage, { onlyOnce, showStackTrace }) {
|
|
81
75
|
if (condition) {
|
|
82
76
|
return;
|
|
83
77
|
}
|
|
84
|
-
const msg = `[
|
|
78
|
+
const msg = `[Vike][Warning] ${errorMessage}`;
|
|
85
79
|
if (onlyOnce) {
|
|
86
80
|
const { alreadyLogged } = globalObject;
|
|
87
81
|
const key = onlyOnce === true ? msg : onlyOnce;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getRandomId = getRandomId;
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
5
|
// https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
|
|
6
|
-
function getRandomId(length) {
|
|
6
|
+
function getRandomId(length = 12) {
|
|
7
7
|
let randomId = '';
|
|
8
8
|
while (randomId.length < length) {
|
|
9
9
|
randomId += Math.random().toString(36).slice(2);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.normalizeHeaders = normalizeHeaders;
|
|
4
4
|
const isObject_js_1 = require("./isObject.js");
|
|
5
5
|
function normalizeHeaders(
|
|
6
|
-
/* This type is
|
|
6
|
+
/* This type is too strict which is annoying: cannot pass `string[][]` because it doesn't match the more precise type `[string,string][]`.
|
|
7
7
|
headersOriginal ConstructorParameters<typeof Headers>[0]
|
|
8
8
|
*/
|
|
9
9
|
headersOriginal) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createPageContext };
|
|
2
2
|
declare function createPageContext(urlOriginal: string): Promise<{
|
|
3
|
+
_isPageContextObject: boolean;
|
|
3
4
|
urlOriginal: string;
|
|
4
5
|
_objectCreatedByVike: boolean;
|
|
5
6
|
_urlHandler: null;
|
|
@@ -11,7 +12,6 @@ declare function createPageContext(urlOriginal: string): Promise<{
|
|
|
11
12
|
_allPageIds: string[];
|
|
12
13
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
13
14
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
14
|
-
_isPageContextObject: boolean;
|
|
15
15
|
} & {
|
|
16
16
|
urlParsed: import("./utils.js").UrlPublic;
|
|
17
17
|
urlPathname: string;
|
|
@@ -13,6 +13,7 @@ async function createPageContext(urlOriginal) {
|
|
|
13
13
|
const baseServer = getBaseServer();
|
|
14
14
|
assert(isBaseServer(baseServer));
|
|
15
15
|
const pageContext = {
|
|
16
|
+
_isPageContextObject: true,
|
|
16
17
|
urlOriginal,
|
|
17
18
|
_objectCreatedByVike: true,
|
|
18
19
|
_urlHandler: null,
|
|
@@ -23,8 +24,7 @@ async function createPageContext(urlOriginal) {
|
|
|
23
24
|
_pageConfigGlobal: pageConfigGlobal,
|
|
24
25
|
_allPageIds: allPageIds,
|
|
25
26
|
_pageRoutes: pageRoutes,
|
|
26
|
-
_onBeforeRouteHook: onBeforeRouteHook
|
|
27
|
-
_isPageContextObject: true
|
|
27
|
+
_onBeforeRouteHook: onBeforeRouteHook
|
|
28
28
|
};
|
|
29
29
|
const pageContextUrlComputed = getPageContextUrlComputed(pageContext);
|
|
30
30
|
objectAssign(pageContext, pageContextUrlComputed);
|
|
@@ -11,7 +11,7 @@ import { assertVersion } from './utils.js';
|
|
|
11
11
|
* https://vike.dev/api#build
|
|
12
12
|
*/
|
|
13
13
|
async function build(options = {}) {
|
|
14
|
-
const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options
|
|
14
|
+
const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options, 'build');
|
|
15
15
|
// Pass it to pluginAutoFullBuild()
|
|
16
16
|
if (viteConfigEnhanced)
|
|
17
17
|
viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export { isVikeCliOrApi };
|
|
2
2
|
export { setContextApiOperation };
|
|
3
3
|
export { clearContextApiOperation };
|
|
4
|
-
|
|
4
|
+
export { getApiOperation };
|
|
5
|
+
import type { APIOptions, Operation } from './types.js';
|
|
6
|
+
type ApiOperation = {
|
|
7
|
+
operation: Operation;
|
|
8
|
+
options: APIOptions;
|
|
9
|
+
};
|
|
10
|
+
declare function getApiOperation(): ApiOperation | null;
|
|
5
11
|
declare function isVikeCliOrApi(): boolean;
|
|
6
|
-
declare function setContextApiOperation(operation: Operation): void;
|
|
12
|
+
declare function setContextApiOperation(operation: Operation, options: APIOptions): void;
|
|
7
13
|
declare function clearContextApiOperation(): void;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export { isVikeCliOrApi };
|
|
2
2
|
export { setContextApiOperation };
|
|
3
3
|
export { clearContextApiOperation };
|
|
4
|
+
export { getApiOperation };
|
|
4
5
|
import { assert, getGlobalObject } from './utils.js';
|
|
5
6
|
const globalObject = getGlobalObject('api/context.ts', {});
|
|
6
7
|
function getApiOperation() {
|
|
7
|
-
|
|
8
|
-
return globalObject.apiOperation;
|
|
8
|
+
return globalObject.apiOperation ?? null;
|
|
9
9
|
}
|
|
10
10
|
function isVikeCliOrApi() {
|
|
11
11
|
// The CLI uses the API
|
|
12
12
|
return !!globalObject.apiOperation;
|
|
13
13
|
}
|
|
14
|
-
function setContextApiOperation(operation) {
|
|
14
|
+
function setContextApiOperation(operation, options) {
|
|
15
15
|
assert(!globalObject.apiOperation);
|
|
16
|
-
globalObject.apiOperation = operation;
|
|
16
|
+
globalObject.apiOperation = { operation, options };
|
|
17
17
|
}
|
|
18
18
|
function clearContextApiOperation() {
|
|
19
19
|
globalObject.apiOperation = undefined;
|
package/dist/esm/node/api/dev.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createServer } from 'vite';
|
|
|
7
7
|
* https://vike.dev/api#dev
|
|
8
8
|
*/
|
|
9
9
|
async function dev(options = {}) {
|
|
10
|
-
const { viteConfigEnhanced } = await prepareViteApiCall(options
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options, 'dev');
|
|
11
11
|
const server = await createServer(viteConfigEnhanced);
|
|
12
12
|
return {
|
|
13
13
|
viteServer: server,
|
|
@@ -3,9 +3,9 @@ export { getViteRoot };
|
|
|
3
3
|
export { assertViteRoot };
|
|
4
4
|
export { normalizeViteRoot };
|
|
5
5
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
6
|
-
import type { Operation } from './types.js';
|
|
6
|
+
import type { APIOptions, Operation } from './types.js';
|
|
7
7
|
import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
8
|
-
declare function prepareViteApiCall(
|
|
8
|
+
declare function prepareViteApiCall(options: APIOptions, operation: Operation): Promise<{
|
|
9
9
|
vikeConfig: VikeConfigObject;
|
|
10
10
|
viteConfigEnhanced: InlineConfig | undefined;
|
|
11
11
|
}>;
|
|
@@ -10,9 +10,10 @@ import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './u
|
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { clearGlobalContext } from '../runtime/globalContext.js';
|
|
12
12
|
const globalObject = getGlobalObject('api/prepareViteApiCall.ts', {});
|
|
13
|
-
async function prepareViteApiCall(
|
|
13
|
+
async function prepareViteApiCall(options, operation) {
|
|
14
14
|
clear();
|
|
15
|
-
setContextApiOperation(operation);
|
|
15
|
+
setContextApiOperation(operation, options);
|
|
16
|
+
const viteConfigFromOptions = options.viteConfig;
|
|
16
17
|
return enhanceViteConfig(viteConfigFromOptions, operation);
|
|
17
18
|
}
|
|
18
19
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
@@ -8,7 +8,7 @@ import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
|
8
8
|
* https://vike.dev/api#prerender
|
|
9
9
|
*/
|
|
10
10
|
async function prerender(options = {}) {
|
|
11
|
-
const { viteConfigEnhanced } = await prepareViteApiCall(options
|
|
11
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options, 'prerender');
|
|
12
12
|
options.viteConfig = viteConfigEnhanced;
|
|
13
13
|
const { viteConfig } = await runPrerenderFromAPI(options);
|
|
14
14
|
return {
|
|
@@ -7,7 +7,7 @@ import { preview as previewVite } from 'vite';
|
|
|
7
7
|
* https://vike.dev/api#preview
|
|
8
8
|
*/
|
|
9
9
|
async function preview(options = {}) {
|
|
10
|
-
const { viteConfigEnhanced } = await prepareViteApiCall(options
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options, 'preview');
|
|
11
11
|
const server = await previewVite(viteConfigEnhanced);
|
|
12
12
|
return {
|
|
13
13
|
viteServer: server,
|