vike 0.4.259 → 0.4.260
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/AGENTS.md +3 -0
- package/README.md +2 -0
- package/dist/client/runtime-client-routing/renderPageClient.js +1 -1
- package/dist/client/shared/getJsonSerializedInHtml.js +1 -10
- package/dist/node/api/build.js +6 -6
- package/dist/node/api/dev.d.ts +2 -10
- package/dist/node/api/dev.js +5 -52
- package/dist/node/api/prepareViteApiCall.d.ts +1 -1
- package/dist/node/api/prepareViteApiCall.js +2 -2
- package/dist/node/api/prerender.js +2 -2
- package/dist/node/api/preview.d.ts +2 -2
- package/dist/node/api/preview.js +15 -16
- package/dist/node/api/{resolveViteConfigFromUser.d.ts → resolveViteConfigUser.d.ts} +5 -5
- package/dist/node/api/{resolveViteConfigFromUser.js → resolveViteConfigUser.js} +99 -68
- package/dist/node/api/startupLog.d.ts +4 -0
- package/dist/node/api/{getStartupLogFirstLine.js → startupLog.js} +15 -1
- package/dist/node/api/types.d.ts +9 -0
- package/dist/node/cli/entry.js +1 -5
- package/dist/node/cli/parseCli.js +25 -11
- package/dist/node/createDevMiddleware.js +2 -2
- package/dist/node/prerender/runPrerender.d.ts +8 -2
- package/dist/node/prerender/runPrerender.js +3 -1
- package/dist/node/prerender/runPrerenderEntry.js +2 -2
- package/dist/node/vite/index.js +2 -2
- package/dist/node/vite/plugins/build/handleAssetsManifest.d.ts +2 -6
- package/dist/node/vite/plugins/build/handleAssetsManifest.js +16 -9
- package/dist/node/vite/plugins/build/pluginBuildApp.js +10 -5
- package/dist/node/vite/plugins/build/pluginBuildConfig.d.ts +6 -1
- package/dist/node/vite/plugins/build/pluginBuildConfig.js +13 -11
- package/dist/node/vite/plugins/build/pluginDistFileNames.js +1 -6
- package/dist/node/vite/plugins/build/pluginModuleBanner.js +2 -4
- package/dist/node/vite/plugins/pluginCommon.d.ts +1 -1
- package/dist/node/vite/plugins/pluginCommon.js +15 -7
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +67 -31
- package/dist/node/vite/plugins/pluginStripPointerImportAttribute.js +31 -10
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +5 -7
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +2 -2
- package/dist/node/vite/shared/addSsrMiddleware.js +1 -1
- package/dist/node/vite/shared/isVite8OrAbove.d.ts +4 -0
- package/dist/node/vite/shared/isVite8OrAbove.js +9 -0
- package/dist/node/vite/shared/isViteCli.d.ts +9 -4
- package/dist/node/vite/shared/isViteCli.js +24 -4
- package/dist/node/vite/shared/loggerDev.js +6 -5
- package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.d.ts +2 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.js +6 -5
- package/dist/node/vite/shared/resolveVikeConfigInternal/crawlPlusFilePaths.js +1 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.d.ts +3 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.js +15 -13
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.d.ts +15 -15
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +15 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +18 -3
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +213 -72
- package/dist/server/runtime/globalContext.js +4 -1
- package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +12 -3
- package/dist/server/runtime/renderPageServer/html/injectAssets/getHtmlTags.js +2 -3
- package/dist/server/runtime/renderPageServer/html/serializeContext.js +5 -10
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +8 -2
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +32 -8
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.js +1 -1
- package/dist/server/runtime/renderPageServer.d.ts +8 -2
- package/dist/server/runtime/renderPageServer.js +6 -4
- package/dist/shared-server-client/page-configs/serialize/serializeConfigValues.d.ts +3 -3
- package/dist/shared-server-client/page-configs/serialize/serializeConfigValues.js +8 -1
- package/dist/types/Config.d.ts +34 -6
- package/dist/types/PageConfig.d.ts +11 -9
- package/dist/types/PageContext.d.ts +8 -3
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.js +8 -8
- package/dist/utils/debug.d.ts +1 -1
- package/dist/utils/debug.js +1 -0
- package/dist/utils/getViteRPC.js +1 -1
- package/dist/utils/objectMap.d.ts +2 -0
- package/dist/utils/objectMap.js +4 -0
- package/dist/utils/parseNpmPackage.js +4 -1
- package/dist/utils/pick.d.ts +1 -1
- package/package.json +13 -15
- package/dist/node/api/getStartupLogFirstLine.d.ts +0 -7
- package/dist/server/__internal/vite.d.ts +0 -2
- package/dist/server/__internal/vite.js +0 -2
- package/dist/server/runtime/renderPageServer/html/injectAssets/sanitizeJson.d.ts +0 -4
- package/dist/server/runtime/renderPageServer/html/injectAssets/sanitizeJson.js +0 -7
|
@@ -3,6 +3,7 @@ export { resolveOptimizeDeps };
|
|
|
3
3
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
4
4
|
import { assert } from '../../../../utils/assert.js';
|
|
5
5
|
import { createDebug } from '../../../../utils/debug.js';
|
|
6
|
+
import { deepEqual } from '../../../../utils/deepEqual.js';
|
|
6
7
|
import { isArray } from '../../../../utils/isArray.js';
|
|
7
8
|
import { isFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
8
9
|
import { assertImportIsNpmPackage, getNpmPackageName } from '../../../../utils/parseNpmPackage.js';
|
|
@@ -24,8 +25,12 @@ const LATE_DISCOVERED = [
|
|
|
24
25
|
// Workaround for https://github.com/vikejs/vike/issues/2823#issuecomment-3514325487
|
|
25
26
|
'@compiled/react/runtime',
|
|
26
27
|
];
|
|
27
|
-
// TO-DO/eventually: remove this
|
|
28
|
-
//
|
|
28
|
+
// TO-DO/eventually: remove this workaround using following plan:
|
|
29
|
+
// 1. Remove `include: ["vike > @brillout/require-shim"]` from vike-photon
|
|
30
|
+
// https://github.com/vikejs/vike-photon/blob/e11edb617ae44da6c1748222c387b10bf3fa5495/packages/vike-photon/src/plugin/plugins/configPlugin.ts#L16-L17
|
|
31
|
+
// 2. Release new vike-photon version
|
|
32
|
+
// 2. Remove this workaround
|
|
33
|
+
// Even though Vike doesn't use @brillout/require-shim anymore, it's still needed because vike-photon adds @brillout/require-shim to optimizeDeps.include which leads to this error:
|
|
29
34
|
// ```
|
|
30
35
|
// [11:32:49.768][/test/photon-vercel/.test-dev.test.ts][pnpm run dev][stderr] Failed to resolve dependency: vike > @brillout/require-shim, present in ssr 'optimizeDeps.include'
|
|
31
36
|
// ```
|
|
@@ -70,9 +75,9 @@ const optimizeDeps = {
|
|
|
70
75
|
// - Make server environments inherit from ssr.optimizeDeps (it isn't the case by default)
|
|
71
76
|
async function resolveOptimizeDeps(config) {
|
|
72
77
|
const vikeConfig = await getVikeConfigInternal();
|
|
73
|
-
const { _pageConfigs: pageConfigs } = vikeConfig;
|
|
78
|
+
const { _pageConfigs: pageConfigs, _pageConfigGlobal: pageConfigGlobal } = vikeConfig;
|
|
74
79
|
// Retrieve user's + files (i.e. Vike entries)
|
|
75
|
-
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
|
|
80
|
+
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs, pageConfigGlobal);
|
|
76
81
|
// Add late discovered dependencies, if they exist
|
|
77
82
|
LATE_DISCOVERED.forEach((dep) => {
|
|
78
83
|
const userRootDir = config.root;
|
|
@@ -114,18 +119,19 @@ async function resolveOptimizeDeps(config) {
|
|
|
114
119
|
env.optimizeDeps.entries = remove(env.optimizeDeps.entries ?? []);
|
|
115
120
|
}
|
|
116
121
|
// Debug
|
|
117
|
-
if (debug.isActivated)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
if (debug.isActivated) {
|
|
123
|
+
const envs = {};
|
|
124
|
+
for (const envName in config.environments) {
|
|
125
|
+
const env = config.environments[envName];
|
|
126
|
+
envs[`config.environments.${envName}.optimizeDeps.entries`] = env.optimizeDeps.entries;
|
|
127
|
+
envs[`config.environments.${envName}.optimizeDeps.include`] = env.optimizeDeps.include;
|
|
128
|
+
envs[`config.environments.${envName}.optimizeDeps.exclude`] = env.optimizeDeps.exclude;
|
|
129
|
+
}
|
|
130
|
+
debug('optimizeDeps', envs);
|
|
131
|
+
assertEnvsInSyncWithLegacy(config);
|
|
132
|
+
}
|
|
127
133
|
}
|
|
128
|
-
async function getPageDeps(config, pageConfigs) {
|
|
134
|
+
async function getPageDeps(config, pageConfigs, pageConfigGlobal) {
|
|
129
135
|
let entriesClient = [];
|
|
130
136
|
let entriesServer = [];
|
|
131
137
|
let includeClient = [];
|
|
@@ -158,6 +164,14 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
158
164
|
includeServer.push(e);
|
|
159
165
|
}
|
|
160
166
|
};
|
|
167
|
+
const addEntryOrInclude = (filePath, isForClientSide, definedAt) => {
|
|
168
|
+
if (filePath.filePathAbsoluteUserRootDir !== null) {
|
|
169
|
+
addEntry(filePath.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
addInclude(filePath.importPathAbsolute, isForClientSide, definedAt);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
161
175
|
const isExcluded = (e, isForClientSide, definedAt) => {
|
|
162
176
|
const exclude = isForClientSide ? config.optimizeDeps.exclude : config.ssr.optimizeDeps.exclude;
|
|
163
177
|
if (!exclude)
|
|
@@ -173,7 +187,8 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
173
187
|
{
|
|
174
188
|
;
|
|
175
189
|
[true, false].forEach((isForClientSide) => {
|
|
176
|
-
|
|
190
|
+
;
|
|
191
|
+
[...pageConfigs, pageConfigGlobal].forEach((pageConfig) => {
|
|
177
192
|
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
178
193
|
const runtimeEnv = {
|
|
179
194
|
isForClientSide,
|
|
@@ -188,16 +203,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
188
203
|
const { definedAt } = configValueSource;
|
|
189
204
|
if (definedAt.definedBy)
|
|
190
205
|
return;
|
|
191
|
-
|
|
192
|
-
addEntry(
|
|
193
|
-
// optimizeDeps.entries expects filesystem absolute paths
|
|
194
|
-
definedAt.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
addInclude(
|
|
198
|
-
// optimizeDeps.include expects npm packages
|
|
199
|
-
definedAt.importPathAbsolute, isForClientSide, definedAt);
|
|
200
|
-
}
|
|
206
|
+
addEntryOrInclude(definedAt, isForClientSide, definedAt);
|
|
201
207
|
});
|
|
202
208
|
});
|
|
203
209
|
});
|
|
@@ -214,13 +220,26 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
214
220
|
});
|
|
215
221
|
}
|
|
216
222
|
// Add virtual files.
|
|
217
|
-
// -
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
223
|
+
// - Vite 8+ (Rolldown-based dep scanner) crawls virtual IDs natively — its scanner routes
|
|
224
|
+
// through `environment.pluginContainer.resolveId()`, so Vike's resolveId/load handlers
|
|
225
|
+
// run during the scan and the virtual file's transitive deps are seen.
|
|
226
|
+
// - Vite ≤7 (esbuild-based dep scanner) cannot crawl virtual IDs — those virtuals' deps
|
|
227
|
+
// surface lazily and trigger "✨ new dependencies optimized" reload cycles. As a
|
|
228
|
+
// workaround we could materialize each virtual to a real file under
|
|
229
|
+
// `node_modules/.vike/optimizeDeps-virtuals/`; an implementation lives in the reverted
|
|
230
|
+
// commit https://github.com/vikejs/vike/commit/b068009c3 (re-apply if Vite ≤7 support
|
|
231
|
+
// matters).
|
|
221
232
|
{
|
|
222
233
|
const { hasClientRouting, hasServerRouting, clientEntries } = analyzeClientEntries(pageConfigs, config);
|
|
223
|
-
Object.values(clientEntries).forEach((
|
|
234
|
+
Object.values(clientEntries).forEach(({ entryTarget, entryFilePath }) => {
|
|
235
|
+
if (entryFilePath) {
|
|
236
|
+
addEntryOrInclude(entryFilePath, true);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Page-entry virtual IDs have no file path.
|
|
240
|
+
addEntry(entryTarget, true);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
224
243
|
if (hasClientRouting)
|
|
225
244
|
addEntry(virtualFileIdGlobalEntryClientCR, true);
|
|
226
245
|
if (hasServerRouting)
|
|
@@ -258,3 +277,20 @@ function remove(input) {
|
|
|
258
277
|
list = list.filter((e) => !ALWAYS_REMOVE.includes(e));
|
|
259
278
|
return list;
|
|
260
279
|
}
|
|
280
|
+
// Sanity-check that the legacy `config.optimizeDeps` and `config.ssr.optimizeDeps` slots
|
|
281
|
+
// stay in sync with the corresponding environment values — so logging only the env values
|
|
282
|
+
// (above) isn't hiding anything.
|
|
283
|
+
function assertEnvsInSyncWithLegacy(config) {
|
|
284
|
+
const client = config.environments.client?.optimizeDeps;
|
|
285
|
+
assert(client);
|
|
286
|
+
assert(deepEqual(config.optimizeDeps.entries, client.entries));
|
|
287
|
+
assert(deepEqual(config.optimizeDeps.include, client.include));
|
|
288
|
+
assert(deepEqual(config.optimizeDeps.exclude, client.exclude));
|
|
289
|
+
const ssr = config.environments.ssr?.optimizeDeps;
|
|
290
|
+
assert(ssr);
|
|
291
|
+
/* Vite doesn't seem to support config.ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
292
|
+
assert(deepEqual(config.ssr.optimizeDeps.entries, ssr.entries))
|
|
293
|
+
*/
|
|
294
|
+
assert(deepEqual(config.ssr.optimizeDeps.include, ssr.include));
|
|
295
|
+
assert(deepEqual(config.ssr.optimizeDeps.exclude, ssr.exclude));
|
|
296
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { pluginStripPointerImportAttribute };
|
|
2
|
+
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
2
3
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
3
4
|
import '../assertEnvVite.js';
|
|
4
5
|
// Match `with { type: 'vike:pointer' }` (with optional whitespace variations)
|
|
@@ -14,18 +15,38 @@ function pluginStripPointerImportAttribute() {
|
|
|
14
15
|
},
|
|
15
16
|
},
|
|
16
17
|
handler(code, id) {
|
|
17
|
-
|
|
18
|
-
if (!runtimeAttrRE.test(code))
|
|
19
|
-
return;
|
|
20
|
-
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
21
|
-
runtimeAttrRE.lastIndex = 0;
|
|
22
|
-
let match;
|
|
23
|
-
while ((match = runtimeAttrRE.exec(code)) !== null) {
|
|
24
|
-
magicString.remove(match.index, match.index + match[0].length);
|
|
25
|
-
}
|
|
26
|
-
return getMagicStringResult();
|
|
18
|
+
return stripPointerImportAttributes(code, id);
|
|
27
19
|
},
|
|
28
20
|
},
|
|
29
21
|
},
|
|
30
22
|
];
|
|
31
23
|
}
|
|
24
|
+
async function stripPointerImportAttributes(code, id) {
|
|
25
|
+
// Fast path: skip parsing when there is nothing to strip
|
|
26
|
+
runtimeAttrRE.lastIndex = 0;
|
|
27
|
+
if (!runtimeAttrRE.test(code))
|
|
28
|
+
return;
|
|
29
|
+
// Restrict stripping to genuine `import` statements, so that we don't touch occurrences
|
|
30
|
+
// inside string literals/comments (e.g. documentation code examples).
|
|
31
|
+
// https://github.com/brillout/docpress/issues/167
|
|
32
|
+
let importStatements;
|
|
33
|
+
try {
|
|
34
|
+
importStatements = await getImportStatements(code);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Not parsable as an ES module (e.g. a raw Markdown file) => leave it untouched
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
41
|
+
for (const { ss, se } of importStatements)
|
|
42
|
+
stripAttribute(magicString, code, ss, se);
|
|
43
|
+
return getMagicStringResult();
|
|
44
|
+
}
|
|
45
|
+
function stripAttribute(magicString, code, start, end) {
|
|
46
|
+
const region = code.slice(start, end);
|
|
47
|
+
runtimeAttrRE.lastIndex = 0;
|
|
48
|
+
let match;
|
|
49
|
+
while ((match = runtimeAttrRE.exec(region)) !== null) {
|
|
50
|
+
magicString.remove(start + match.index, start + match.index + match[0].length);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { generateVirtualFilePageEntry };
|
|
2
|
-
import { assert, getProjectError } from '../../../../utils/assert.js';
|
|
2
|
+
import { assert, getDebugInfoStr, getProjectError } from '../../../../utils/assert.js';
|
|
3
3
|
import { parseVirtualFileId, generateVirtualFileId } from '../../../../shared-server-node/virtualFileId.js';
|
|
4
4
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../../shared-server-node/extractAssetsQuery.js';
|
|
@@ -26,12 +26,10 @@ async function generateVirtualFilePageEntry(id, isDev) {
|
|
|
26
26
|
assert(pageConfig);
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw getProjectError('Outdated request');
|
|
34
|
-
//*/
|
|
29
|
+
if (!pageConfig) {
|
|
30
|
+
// Happens very seldom and can't reproduce reliably. Some kind of HMR race condition? It still happens as of June 2026 with Cloudflare Workers in development — but it isn't blocking, reloading the page fixes the issue.
|
|
31
|
+
throw getProjectError(`Outdated request. Try again. ${getDebugInfoStr({ id, pageId })}`);
|
|
32
|
+
}
|
|
35
33
|
}
|
|
36
34
|
const code = getCode(pageConfig, isForClientSide, pageId, resolveIncludeAssetsImportedByServer(vikeConfig.config), isDev);
|
|
37
35
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
@@ -3,7 +3,7 @@ export { getConfigValueSourceRelevantAnyEnv };
|
|
|
3
3
|
export { isRuntimeEnvMatch };
|
|
4
4
|
export { isConfigSourceValueNull };
|
|
5
5
|
export type { RuntimeEnv };
|
|
6
|
-
import type {
|
|
6
|
+
import type { ConfigEnv, ConfigValueSource, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../../../../types/PageConfig.js';
|
|
7
7
|
import '../../assertEnvVite.js';
|
|
8
8
|
type RuntimeEnv = {
|
|
9
9
|
isForClientSide: boolean;
|
|
@@ -15,5 +15,5 @@ type RuntimeEnv = {
|
|
|
15
15
|
type PageConfigPartial = Pick<PageConfigBuildTime | PageConfigGlobalBuildTime, 'configValueSources' | 'configDefinitions'>;
|
|
16
16
|
declare function getConfigValueSourcesRelevant(configName: string, runtimeEnv: RuntimeEnv, pageConfig: PageConfigPartial): ConfigValueSource[];
|
|
17
17
|
declare function getConfigValueSourceRelevantAnyEnv(configName: string, pageConfig: PageConfigPartial): null | ConfigValueSource;
|
|
18
|
-
declare function isRuntimeEnvMatch(configEnv:
|
|
18
|
+
declare function isRuntimeEnvMatch(configEnv: ConfigEnv, runtimeEnv: RuntimeEnv): boolean;
|
|
19
19
|
declare function isConfigSourceValueNull(source: ConfigValueSource): boolean | null;
|
|
@@ -14,7 +14,7 @@ function addSsrMiddleware(middlewares, config, isPreview, isPrerenderingEnabled)
|
|
|
14
14
|
const pageContextInit = {
|
|
15
15
|
urlOriginal: url,
|
|
16
16
|
headersOriginal: headers,
|
|
17
|
-
|
|
17
|
+
_nodeDev: { req, res },
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(pageContextInit, 'userAgent', {
|
|
20
20
|
get() {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { isVite8OrAbove };
|
|
2
|
+
import { assert } from '../../../utils/assert.js';
|
|
3
|
+
import { isVersionMatch } from '../../../utils/assertVersion.js';
|
|
4
|
+
import '../assertEnvVite.js';
|
|
5
|
+
function isVite8OrAbove(config) {
|
|
6
|
+
const viteVersion = config._viteVersionResolved;
|
|
7
|
+
assert(viteVersion);
|
|
8
|
+
return isVersionMatch(viteVersion, ['8.0.0']);
|
|
9
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { isViteCli };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { getViteCliArgs };
|
|
3
|
+
export { getViteBuildCliArgs };
|
|
4
|
+
export { getViteCliCommand };
|
|
4
5
|
import '../assertEnvVite.js';
|
|
5
6
|
declare function isViteCli(): boolean;
|
|
6
7
|
type ConfigFromCli = {
|
|
@@ -10,5 +11,9 @@ type ConfigFromCli = {
|
|
|
10
11
|
build: Record<string, unknown>;
|
|
11
12
|
};
|
|
12
13
|
type ViteCommand = 'dev' | 'build' | 'optimize' | 'preview';
|
|
13
|
-
declare function
|
|
14
|
-
declare function
|
|
14
|
+
declare function getViteCliCommand(): ViteCommand | null;
|
|
15
|
+
declare function getViteBuildCliArgs(): null | ConfigFromCli;
|
|
16
|
+
declare function getViteCliArgs(): null | {
|
|
17
|
+
root: string | undefined;
|
|
18
|
+
configFile: string | undefined;
|
|
19
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { isViteCli };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { getViteCliArgs };
|
|
3
|
+
export { getViteBuildCliArgs };
|
|
4
|
+
export { getViteCliCommand };
|
|
4
5
|
import { assert } from '../../../utils/assert.js';
|
|
5
6
|
import { isObject } from '../../../utils/isObject.js';
|
|
6
7
|
import { isToolCli } from '../../../utils/isToolCli.js';
|
|
@@ -10,7 +11,7 @@ const desc = 'vike:vite-cli-simulation';
|
|
|
10
11
|
function isViteCli() {
|
|
11
12
|
return isToolCli('vite');
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function getViteCliCommand() {
|
|
14
15
|
if (!isViteCli())
|
|
15
16
|
return null;
|
|
16
17
|
let command;
|
|
@@ -45,7 +46,7 @@ function getViteCommandFromCli() {
|
|
|
45
46
|
assert(command);
|
|
46
47
|
return command;
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
+
function getViteBuildCliArgs() {
|
|
49
50
|
if (!isViteCli())
|
|
50
51
|
return null;
|
|
51
52
|
// Copied & adapted from Vite
|
|
@@ -135,3 +136,22 @@ function getViteConfigForBuildFromCli() {
|
|
|
135
136
|
return ret;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
139
|
+
function getViteCliArgs() {
|
|
140
|
+
if (!isViteCli())
|
|
141
|
+
return null;
|
|
142
|
+
const cli = cac(desc);
|
|
143
|
+
cli.option('-c, --config <file>', desc);
|
|
144
|
+
let result = null;
|
|
145
|
+
const setResult = (root, options) => {
|
|
146
|
+
assert(root === undefined || typeof root === 'string');
|
|
147
|
+
assert(isObject(options));
|
|
148
|
+
assert(options.config === undefined || typeof options.config === 'string');
|
|
149
|
+
result = { root, configFile: options.config };
|
|
150
|
+
};
|
|
151
|
+
cli.command('[root]', desc).alias('serve').alias('dev').action(setResult);
|
|
152
|
+
cli.command('build [root]', desc).action(setResult);
|
|
153
|
+
cli.command('optimize [root]', desc).action(setResult);
|
|
154
|
+
cli.command('preview [root]', desc).action(setResult);
|
|
155
|
+
cli.parse();
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
@@ -29,7 +29,6 @@ import { getBetterError } from '../../../utils/getBetterError.js';
|
|
|
29
29
|
import { getRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
30
30
|
import { getRequestTag } from '../../../server/runtime/renderPageServer.js';
|
|
31
31
|
import '../assertEnvVite.js';
|
|
32
|
-
import { isDeno } from '../../../utils/isDeno.js';
|
|
33
32
|
assertIsNotProductionRuntime();
|
|
34
33
|
setLogRuntimeDev(logErrorServerDev, logRuntimeInfoDev);
|
|
35
34
|
setAssertOnBeforeErr((err) => {
|
|
@@ -139,14 +138,16 @@ function logDev(msg, logType, tagSource, tagTool, doNotAddTags) {
|
|
|
139
138
|
}
|
|
140
139
|
function getTagSource(requestId = null) {
|
|
141
140
|
const requestIdFromStore = getRequestId_withAsyncHook();
|
|
142
|
-
if (requestIdFromStore !== null
|
|
143
|
-
// Workaround for Deno bug: https://github.com/vikejs/vike/issues/3240
|
|
144
|
-
!isDeno()) {
|
|
141
|
+
if (requestIdFromStore !== null) {
|
|
145
142
|
if (requestId === null) {
|
|
146
143
|
requestId = requestIdFromStore;
|
|
147
144
|
}
|
|
148
145
|
else {
|
|
149
|
-
assert
|
|
146
|
+
/* Surprisingly, this assert can fail:
|
|
147
|
+
* - https://github.com/vikejs/vike/issues/3240
|
|
148
|
+
* - https://github.com/vikejs/vike/issues/3289
|
|
149
|
+
assert(requestId === requestIdFromStore)
|
|
150
|
+
*/
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
if (requestId === null)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
2
|
export { assertExtensionsRequire };
|
|
3
|
+
export { getExtensionName };
|
|
3
4
|
import type { PlusFile } from './getPlusFilesByLocationId.js';
|
|
4
5
|
import '../../assertEnvVite.js';
|
|
5
6
|
declare function assertExtensionsConventions(plusFile: PlusFile): void;
|
|
6
7
|
declare function assertExtensionsRequire(plusFiles: PlusFile[]): void;
|
|
8
|
+
declare function getExtensionName(plusFile: PlusFile): null | string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
2
|
export { assertExtensionsRequire };
|
|
3
|
+
export { getExtensionName };
|
|
3
4
|
import pc from '@brillout/picocolors';
|
|
4
5
|
import { PROJECT_VERSION } from '../../../../utils/PROJECT_VERSION.js';
|
|
5
6
|
import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
|
|
@@ -21,14 +22,14 @@ function assertConfigExportPath(plusFile) {
|
|
|
21
22
|
assert(!p.includes('node_modules'));
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
const name =
|
|
25
|
+
const name = getExtensionName(plusFile);
|
|
25
26
|
assert(name); // already asserted in assertExtensionName()
|
|
26
27
|
const importPathAbsoluteExpected = `${name}/config`;
|
|
27
28
|
assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${pc.bold(name)} is exported at ${pc.bold(importPathAbsolute)}, but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
|
|
28
29
|
}
|
|
29
30
|
function assertExtensionName(plusFile) {
|
|
30
31
|
const filePathToShowToUser = getFilePathToShowToUser(plusFile);
|
|
31
|
-
const name =
|
|
32
|
+
const name = getExtensionName(plusFile);
|
|
32
33
|
assertUsage(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${pc.cyan('name')}`);
|
|
33
34
|
}
|
|
34
35
|
function assertExtensionsRequire(plusFiles) {
|
|
@@ -36,7 +37,7 @@ function assertExtensionsRequire(plusFiles) {
|
|
|
36
37
|
// Collect extensions
|
|
37
38
|
const extensions = {};
|
|
38
39
|
plusFilesRelevantList.forEach((plusFile) => {
|
|
39
|
-
const name =
|
|
40
|
+
const name = getExtensionName(plusFile);
|
|
40
41
|
if (name) {
|
|
41
42
|
const version = getExtensionVersion(name, plusFile);
|
|
42
43
|
extensions[name] = version;
|
|
@@ -47,7 +48,7 @@ function assertExtensionsRequire(plusFiles) {
|
|
|
47
48
|
const require = resolveRequireSetting(plusFile);
|
|
48
49
|
if (!require)
|
|
49
50
|
return;
|
|
50
|
-
const name =
|
|
51
|
+
const name = getExtensionName(plusFile);
|
|
51
52
|
const filePathToShowToUser = getFilePathToShowToUser(plusFile);
|
|
52
53
|
assertUsage(name, `Setting ${pc.bold('name')} is required for being able to use setting ${pc.bold('require')} in ${filePathToShowToUser}.`);
|
|
53
54
|
Object.entries(require).forEach(([reqName, req]) => {
|
|
@@ -96,7 +97,7 @@ function resolveRequireSetting(plusFile) {
|
|
|
96
97
|
});
|
|
97
98
|
return requireSetting;
|
|
98
99
|
}
|
|
99
|
-
function
|
|
100
|
+
function getExtensionName(plusFile) {
|
|
100
101
|
const confVal = getConfVal(plusFile, 'name');
|
|
101
102
|
if (!confVal)
|
|
102
103
|
return null;
|
|
@@ -28,6 +28,7 @@ assertIsNotProductionRuntime();
|
|
|
28
28
|
const globalObject = getGlobalObject('getVikeConfig/crawlPlusFilePaths.ts', {
|
|
29
29
|
gitIsNotUsable: false,
|
|
30
30
|
});
|
|
31
|
+
// TODO/after-PR-merge rename crawlPlusFilePaths crawlPlusFiles
|
|
31
32
|
async function crawlPlusFilePaths(userRootDir) {
|
|
32
33
|
assertPosixPath(userRootDir);
|
|
33
34
|
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { getPlusFilesByLocationId };
|
|
2
|
+
export { getPlusFileFromConfigFile };
|
|
2
3
|
export type { PlusFileValue };
|
|
3
4
|
export type { PlusFile };
|
|
4
5
|
export type { PlusFilesByLocationId };
|
|
5
6
|
import { type LocationId } from './filesystemRouting.js';
|
|
6
7
|
import { type EsbuildCache } from './transpileAndExecuteFile.js';
|
|
7
|
-
import { PointerImportLoaded } from './loadFileAtConfigTime.js';
|
|
8
|
+
import { type ConfigFile, PointerImportLoaded } from './loadFileAtConfigTime.js';
|
|
8
9
|
import type { FilePathResolved } from '../../../../types/FilePath.js';
|
|
9
10
|
import '../../assertEnvVite.js';
|
|
10
11
|
type PlusFile = PlusFileConfig | PlusFileValue;
|
|
@@ -40,3 +41,4 @@ type PlusFileValue = PlusFileCommon & {
|
|
|
40
41
|
};
|
|
41
42
|
type PlusFilesByLocationId = Record<LocationId, PlusFile[]>;
|
|
42
43
|
declare function getPlusFilesByLocationId(userRootDir: string, esbuildCache: EsbuildCache): Promise<PlusFilesByLocationId>;
|
|
44
|
+
declare function getPlusFileFromConfigFile(configFile: ConfigFile, isExtensionConfig: boolean, locationId: LocationId, userRootDir: string): PlusFileConfig;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getPlusFilesByLocationId };
|
|
2
|
+
export { getPlusFileFromConfigFile };
|
|
2
3
|
import { assert } from '../../../../utils/assert.js';
|
|
3
4
|
import { metaBuiltIn } from './metaBuiltIn.js';
|
|
4
5
|
import { getLocationId } from './filesystemRouting.js';
|
|
@@ -9,6 +10,7 @@ import { resolvePointerImport } from './resolvePointerImport.js';
|
|
|
9
10
|
import { getFilePathResolved } from '../getFilePath.js';
|
|
10
11
|
import { assertExtensionsConventions, assertExtensionsRequire } from './assertExtensions.js';
|
|
11
12
|
import '../../assertEnvVite.js';
|
|
13
|
+
// TODO/after-PR-merge rename getPlusFilesByLocationId getPlusFiles
|
|
12
14
|
async function getPlusFilesByLocationId(userRootDir, esbuildCache) {
|
|
13
15
|
const plusFilePaths = (await crawlPlusFilePaths(userRootDir)).map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
|
|
14
16
|
const plusFilesByLocationId = {};
|
|
@@ -25,21 +27,21 @@ async function getPlusFilesByLocationId(userRootDir, esbuildCache) {
|
|
|
25
27
|
plusFilesByLocationId[locationId].push(plusFile);
|
|
26
28
|
extendsConfigs.forEach((extendsConfig) => {
|
|
27
29
|
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
```js
|
|
31
|
+
// /pages/admin/+config.js
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
import vikeVue from 'vike-vue/config'
|
|
34
|
+
// Should only apply to /pages/admin/**
|
|
35
|
+
export default { extends: [vikeVue] }
|
|
36
|
+
```
|
|
37
|
+
```js
|
|
38
|
+
// /pages/marketing/+config.js
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
import vikeReact from 'vike-react/config'
|
|
41
|
+
// Should only apply to /pages/marketing/**
|
|
42
|
+
export default { extends: [vikeReact] }
|
|
43
|
+
```
|
|
44
|
+
*/
|
|
43
45
|
const plusFile = getPlusFileFromConfigFile(extendsConfig, true, locationId, userRootDir);
|
|
44
46
|
assertExtensionsConventions(plusFile);
|
|
45
47
|
plusFilesByLocationId[locationId].push(plusFile);
|
|
@@ -4,8 +4,8 @@ export type { ConfigDefinitions };
|
|
|
4
4
|
export type { ConfigDefinitionsInternal };
|
|
5
5
|
export type { ConfigDefinitionInternal };
|
|
6
6
|
export type { ConfigEffect };
|
|
7
|
-
import type {
|
|
8
|
-
import type { Config, ConfigNameBuiltIn,
|
|
7
|
+
import type { ConfigEnv, DefinedAtFilePath } from '../../../../types/PageConfig.js';
|
|
8
|
+
import type { Config, ConfigNameBuiltIn, ConfigNameBuiltInGlobal } from '../../../../types/Config.js';
|
|
9
9
|
import { type ConfigDefinedAt } from '../../../../shared-server-client/page-configs/getConfigDefinedAt.js';
|
|
10
10
|
import type { PageConfigBuildTimeBeforeComputed } from '../resolveVikeConfigInternal.js';
|
|
11
11
|
import '../../assertEnvVite.js';
|
|
@@ -13,8 +13,7 @@ import '../../assertEnvVite.js';
|
|
|
13
13
|
*
|
|
14
14
|
* https://vike.dev/meta
|
|
15
15
|
*/
|
|
16
|
-
type ConfigDefinition =
|
|
17
|
-
type ConfigDefinition_ = {
|
|
16
|
+
type ConfigDefinition = {
|
|
18
17
|
/** In what environment(s) the config value is loaded.
|
|
19
18
|
*
|
|
20
19
|
* https://vike.dev/meta
|
|
@@ -57,7 +56,14 @@ type ConfigDefinition_ = {
|
|
|
57
56
|
}) => boolean);
|
|
58
57
|
/** Whether changes to the configuration should trigger a Vite restart. */
|
|
59
58
|
vite?: boolean;
|
|
60
|
-
|
|
59
|
+
/** @experimental */
|
|
60
|
+
_computed?: (pageConfig: PageConfigBuildTimeBeforeComputed) => unknown;
|
|
61
|
+
/** @experimental */
|
|
62
|
+
_valueIsFilePath?: true;
|
|
63
|
+
/** @experimental */
|
|
64
|
+
_userEffectDefinedAtFilePath?: DefinedAtFilePath;
|
|
65
|
+
isDefinedByPeerDependency?: undefined;
|
|
66
|
+
} | ConfigDefinitionDefinedByPeerDependency;
|
|
61
67
|
type ConfigDefinitionDefinedByPeerDependency = {
|
|
62
68
|
/**
|
|
63
69
|
* Omit the "unknown config" error without defining the config — useful for optional peer dependencies: for example, vike-server sets +stream.require which is defined by vike-{react,vue,solid} but some users don't use vike-{react,vue,solid}
|
|
@@ -70,27 +76,21 @@ type ConfigDefinitionDefinedByPeerDependency = {
|
|
|
70
76
|
* https://vike.dev/meta
|
|
71
77
|
*/
|
|
72
78
|
type ConfigEffect = (config: {
|
|
73
|
-
/** The config value.
|
|
79
|
+
/** The config's value.
|
|
74
80
|
*
|
|
75
81
|
* https://vike.dev/meta
|
|
76
82
|
*/
|
|
77
83
|
configValue: unknown;
|
|
78
|
-
/** Where the config value is defined.
|
|
84
|
+
/** Where the config's value is defined.
|
|
79
85
|
*
|
|
80
86
|
* https://vike.dev/meta
|
|
81
87
|
*/
|
|
82
88
|
configDefinedAt: ConfigDefinedAt;
|
|
83
89
|
}) => Config | undefined;
|
|
84
|
-
|
|
85
|
-
type ConfigDefinitionInternal = Omit<ConfigDefinition_, 'env'> & {
|
|
86
|
-
_computed?: (pageConfig: PageConfigBuildTimeBeforeComputed) => unknown;
|
|
87
|
-
_valueIsFilePath?: true;
|
|
88
|
-
_userEffectDefinedAtFilePath?: DefinedAtFilePath;
|
|
89
|
-
env: ConfigEnvInternal;
|
|
90
|
-
};
|
|
90
|
+
type ConfigDefinitionInternal = Exclude<ConfigDefinition, ConfigDefinitionDefinedByPeerDependency>;
|
|
91
91
|
type ConfigDefinitions = Record<string, // configName
|
|
92
92
|
ConfigDefinition>;
|
|
93
93
|
type ConfigDefinitionsInternal = Record<string, // configName
|
|
94
94
|
ConfigDefinitionInternal>;
|
|
95
|
-
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn |
|
|
95
|
+
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn | ConfigNameBuiltInGlobal, ConfigDefinitionInternal>;
|
|
96
96
|
declare const metaBuiltIn: ConfigDefinitionsBuiltIn;
|
|
@@ -4,6 +4,7 @@ import { getConfigDefinedAt, } from '../../../../shared-server-client/page-confi
|
|
|
4
4
|
import { getConfigValueSourceRelevantAnyEnv, getConfigValueSourcesRelevant, isConfigSourceValueNull, } from '../../plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
|
|
5
5
|
import { getFileSuffixes } from '../../../../shared-server-node/getFileSuffixes.js';
|
|
6
6
|
import '../../assertEnvVite.js';
|
|
7
|
+
// @AI (CRITICAL FOR AI AGENTS): the values below (e.g. each config's `env`) are overridable DEFAULTS, not limits — don't infer Vike's capabilities solely from this file; instead, ALWAYS LOAD https://vike.dev/llms.txt (Vike documentation index) in your context when using Vike.
|
|
7
8
|
const metaBuiltIn = {
|
|
8
9
|
onRenderHtml: {
|
|
9
10
|
env: { server: true },
|
|
@@ -102,6 +103,11 @@ const metaBuiltIn = {
|
|
|
102
103
|
extends: {
|
|
103
104
|
env: { config: true },
|
|
104
105
|
},
|
|
106
|
+
pages: {
|
|
107
|
+
env: { config: true },
|
|
108
|
+
global: true,
|
|
109
|
+
cumulative: true,
|
|
110
|
+
},
|
|
105
111
|
meta: {
|
|
106
112
|
env: { config: true },
|
|
107
113
|
},
|
|
@@ -197,13 +203,22 @@ const metaBuiltIn = {
|
|
|
197
203
|
mode: {
|
|
198
204
|
env: { config: true },
|
|
199
205
|
global: true,
|
|
206
|
+
/* +mode can't be set in +config.js => a +config.js change never affects it — no Vite restart needed
|
|
200
207
|
vite: true,
|
|
208
|
+
*/
|
|
201
209
|
},
|
|
202
210
|
force: {
|
|
203
211
|
env: { config: true },
|
|
204
212
|
global: true,
|
|
205
213
|
vite: true,
|
|
206
214
|
},
|
|
215
|
+
root: {
|
|
216
|
+
env: { config: true },
|
|
217
|
+
global: true,
|
|
218
|
+
/* +root can't be set in +config.js => a +config.js change never affects it — no Vite restart needed
|
|
219
|
+
vite: true,
|
|
220
|
+
*/
|
|
221
|
+
},
|
|
207
222
|
csp: {
|
|
208
223
|
env: { server: true },
|
|
209
224
|
},
|