vike 0.4.224-commit-00ed9fe → 0.4.225
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 +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +9 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +75 -21
- 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/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 +18 -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 +6 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +2 -2
- package/dist/cjs/utils/assertSingleInstance.js +11 -17
- 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 +2 -0
- 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 +9 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +75 -21
- 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/index-deprecated.d.ts +1 -3
- 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 +3 -3
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +19 -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 +6 -2
- package/dist/esm/shared/route/loadPageRoutes.js +2 -2
- 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 -2
- package/dist/esm/utils/assertSingleInstance.js +11 -17
- package/package.json +3 -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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { parseCli };
|
|
2
2
|
import pc from '@brillout/picocolors';
|
|
3
|
-
import {
|
|
3
|
+
import { assert, includes, PROJECT_VERSION } from './utils.js';
|
|
4
|
+
import { parseJson5 } from '../plugin/shared/getEnvVarObject.js';
|
|
4
5
|
const commands = [
|
|
5
6
|
{ name: 'dev', desc: 'Start development server' },
|
|
6
7
|
{ name: 'build', desc: 'Build for production' },
|
|
@@ -8,32 +9,59 @@ const commands = [
|
|
|
8
9
|
{ name: 'prerender', desc: 'Pre-render pages (only needed when partial.disableAutoRun is true)' }
|
|
9
10
|
];
|
|
10
11
|
function parseCli() {
|
|
11
|
-
const command = (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const command = getCommand();
|
|
13
|
+
const cliOptions = getCliOptions();
|
|
14
|
+
return { command, cliOptions };
|
|
15
|
+
}
|
|
16
|
+
function getCommand() {
|
|
17
|
+
const firstArg = process.argv[2];
|
|
18
|
+
if (includes(commands.map((c) => c.name), firstArg)) {
|
|
19
|
+
return firstArg;
|
|
20
|
+
}
|
|
21
|
+
if (!firstArg)
|
|
22
|
+
showHelp();
|
|
23
|
+
showHelpOrVersion(firstArg);
|
|
24
|
+
wrongUsage(`Unknown command ${pc.bold(firstArg)}`);
|
|
25
|
+
}
|
|
26
|
+
function getCliOptions() {
|
|
27
|
+
let cliOptions = {};
|
|
28
|
+
let configNameCurrent;
|
|
29
|
+
const commitIfDefinedWithoutValue = () => {
|
|
30
|
+
if (configNameCurrent)
|
|
31
|
+
commit(true);
|
|
32
|
+
};
|
|
33
|
+
const commit = (val) => {
|
|
34
|
+
assert(configNameCurrent);
|
|
35
|
+
cliOptions[configNameCurrent] = val;
|
|
36
|
+
configNameCurrent = undefined;
|
|
37
|
+
};
|
|
21
38
|
for (const arg of process.argv.slice(3)) {
|
|
22
39
|
showHelpOrVersion(arg);
|
|
23
|
-
|
|
40
|
+
if (arg.startsWith('--')) {
|
|
41
|
+
commitIfDefinedWithoutValue();
|
|
42
|
+
configNameCurrent = arg.slice('--'.length);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (!configNameCurrent)
|
|
46
|
+
wrongUsage(`Unknown option ${pc.bold(arg)}`);
|
|
47
|
+
commit(parseJson5(arg, `CLI option --${configNameCurrent}`));
|
|
48
|
+
}
|
|
24
49
|
}
|
|
25
|
-
|
|
50
|
+
commitIfDefinedWithoutValue();
|
|
51
|
+
return cliOptions;
|
|
26
52
|
}
|
|
27
53
|
function showHelp() {
|
|
28
54
|
const TAB = ' '.repeat(3);
|
|
29
55
|
const nameMaxLength = Math.max(...commands.map((c) => c.name.length));
|
|
30
56
|
console.log([
|
|
31
|
-
`vike@${
|
|
57
|
+
`vike@${PROJECT_VERSION}`,
|
|
32
58
|
'',
|
|
33
59
|
'Usage:',
|
|
34
60
|
...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${pc.dim('$')} ${pc.bold(`vike ${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${pc.dim(`# ${c.desc}`)}`),
|
|
35
61
|
'',
|
|
36
|
-
`
|
|
62
|
+
`Vike settings can be passed over the ${pc.cyan('VIKE_CONFIG')} environment variable or as ${pc.cyan('CLI options')} such as --host.`,
|
|
63
|
+
`Vite settings can be passed over the ${pc.cyan('VITE_CONFIG')} environment variable.`,
|
|
64
|
+
`See ${pc.underline('https://vike.dev/cli')} for more information.`
|
|
37
65
|
].join('\n'));
|
|
38
66
|
process.exit(1);
|
|
39
67
|
}
|
|
@@ -46,7 +74,7 @@ function showHelpOrVersion(arg) {
|
|
|
46
74
|
}
|
|
47
75
|
}
|
|
48
76
|
function showVersion() {
|
|
49
|
-
console.log(
|
|
77
|
+
console.log(PROJECT_VERSION);
|
|
50
78
|
process.exit(1);
|
|
51
79
|
}
|
|
52
80
|
function wrongUsage(msg) {
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
import { onLoad } from './onLoad.js';
|
|
4
4
|
onLoad();
|
|
5
5
|
export * from '../../utils/assert.js';
|
|
6
|
-
export * from '../../utils/
|
|
6
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
|
7
7
|
export * from '../../utils/includes.js';
|
|
8
8
|
export * from '../../utils/getGlobalObject.js';
|
|
@@ -2,7 +2,7 @@ export { pluginBuildEntry };
|
|
|
2
2
|
export { set_macro_ASSETS_MANIFEST };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
5
|
-
import { assert,
|
|
5
|
+
import { assert, PROJECT_VERSION, toPosixPath } from '../../utils.js';
|
|
6
6
|
import fs from 'fs/promises';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { createRequire } from 'module';
|
|
@@ -35,7 +35,7 @@ function pluginBuildEntry() {
|
|
|
35
35
|
function getServerProductionEntryCode(config) {
|
|
36
36
|
const importPath = getImportPath(config);
|
|
37
37
|
const buildInfo = {
|
|
38
|
-
versionAtBuildTime:
|
|
38
|
+
versionAtBuildTime: PROJECT_VERSION,
|
|
39
39
|
usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
|
|
40
40
|
viteConfigRuntime: getViteConfigRuntime(config)
|
|
41
41
|
};
|
|
@@ -73,11 +73,22 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
73
73
|
config: {
|
|
74
74
|
order: 'post',
|
|
75
75
|
handler(configFromUser) {
|
|
76
|
-
// Change default port
|
|
77
76
|
let configFromVike = { server: {}, preview: {} };
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
const vike = getVikeConfigPublic(configFromUser);
|
|
78
|
+
if (vike.config.port !== undefined) {
|
|
79
|
+
// https://vike.dev/port
|
|
80
|
+
setDefault('port', vike.config.port, configFromUser, configFromVike);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Change Vite's default port
|
|
84
|
+
setDefault('port', 3000, configFromUser, configFromVike);
|
|
85
|
+
}
|
|
86
|
+
if (vike.config.host) {
|
|
87
|
+
// https://vike.dev/host
|
|
88
|
+
setDefault('host', vike.config.host, configFromUser, configFromVike);
|
|
89
|
+
}
|
|
90
|
+
else if (isDocker()) {
|
|
91
|
+
// Set `--host` for Docker/Podman
|
|
81
92
|
setDefault('host', true, configFromUser, configFromVike);
|
|
82
93
|
}
|
|
83
94
|
// VITE_CONFIG
|
|
@@ -53,6 +53,8 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
53
53
|
const { definedAtFilePath, configEnv } = configValueSource;
|
|
54
54
|
if (!configEnv.client)
|
|
55
55
|
return;
|
|
56
|
+
if (definedAtFilePath.definedBy)
|
|
57
|
+
return;
|
|
56
58
|
if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
|
|
57
59
|
// Vite expects entries to be filesystem absolute paths (surprisingly so).
|
|
58
60
|
addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
|
|
@@ -44,7 +44,9 @@ type ConfigDefinition = {
|
|
|
44
44
|
*
|
|
45
45
|
* https://vike.dev/extends#inheritance
|
|
46
46
|
*/
|
|
47
|
-
global?: boolean | ((value: unknown
|
|
47
|
+
global?: boolean | ((value: unknown, moreInfo: {
|
|
48
|
+
isGlobalLocation: boolean;
|
|
49
|
+
}) => boolean);
|
|
48
50
|
type?: string | string[];
|
|
49
51
|
};
|
|
50
52
|
/**
|
|
@@ -123,6 +123,14 @@ const configDefinitionsBuiltIn = {
|
|
|
123
123
|
cacheControl: {
|
|
124
124
|
env: { server: true }
|
|
125
125
|
},
|
|
126
|
+
host: {
|
|
127
|
+
env: { config: true },
|
|
128
|
+
global: true
|
|
129
|
+
},
|
|
130
|
+
port: {
|
|
131
|
+
env: { config: true },
|
|
132
|
+
global: true
|
|
133
|
+
},
|
|
126
134
|
injectScriptsAt: {
|
|
127
135
|
env: { server: true }
|
|
128
136
|
},
|
|
@@ -148,7 +156,7 @@ const configDefinitionsBuiltIn = {
|
|
|
148
156
|
},
|
|
149
157
|
prerender: {
|
|
150
158
|
env: { config: true },
|
|
151
|
-
global: (value) => typeof value === 'object',
|
|
159
|
+
global: (value, { isGlobalLocation }) => typeof value === 'object' || isGlobalLocation,
|
|
152
160
|
type: ['boolean', 'object'],
|
|
153
161
|
cumulative: true
|
|
154
162
|
},
|
|
@@ -23,6 +23,9 @@ import { assertExtensionsRequire } from './getVikeConfig/assertExtensions.js';
|
|
|
23
23
|
import { getPageConfigGlobalUserFriendly, getPageConfigUserFriendly } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
24
24
|
import { getConfigValuesBase, isJsonValue } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
25
25
|
import { getPlusFilesAll } from './getVikeConfig/getPlusFilesAll.js';
|
|
26
|
+
import { getEnvVarObject } from '../../../shared/getEnvVarObject.js';
|
|
27
|
+
import { getApiOperation } from '../../../../api/context.js';
|
|
28
|
+
import { getCliOptions } from '../../../../cli/context.js';
|
|
26
29
|
assertIsNotProductionRuntime();
|
|
27
30
|
let restartVite = false;
|
|
28
31
|
let wasConfigInvalid = null;
|
|
@@ -145,6 +148,8 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
145
148
|
const { pageConfigGlobal, pageConfigs } = getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRootDir);
|
|
146
149
|
// Backwards compatibility for vike(options) in vite.config.js
|
|
147
150
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
151
|
+
// TODO/now: add validation
|
|
152
|
+
setCliAndApiOptions(pageConfigGlobal);
|
|
148
153
|
// global
|
|
149
154
|
const pageConfigGlobalValues = getConfigValues(pageConfigGlobal);
|
|
150
155
|
const global = getPageConfigGlobalUserFriendly({ pageConfigGlobalValues });
|
|
@@ -203,13 +208,13 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
203
208
|
objectEntries(configDefinitionsResolved.configDefinitionsGlobal).forEach(([configName, configDef]) => {
|
|
204
209
|
const sources = resolveConfigValueSources(configName, configDef,
|
|
205
210
|
// We use `plusFilesAll` in order to allow local Vike extensions to create global configs, and to set the value of global configs such as `+vite` (enabling Vike extensions to add Vite plugins).
|
|
206
|
-
Object.values(plusFilesAll).flat(), userRootDir, true);
|
|
211
|
+
Object.values(plusFilesAll).flat(), userRootDir, true, plusFilesAll);
|
|
207
212
|
if (sources.length === 0)
|
|
208
213
|
return;
|
|
209
214
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
210
215
|
});
|
|
211
216
|
applyEffectsMetaEnv(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
212
|
-
applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
217
|
+
applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal, plusFilesAll);
|
|
213
218
|
sortConfigValueSources(pageConfigGlobal.configValueSources, null);
|
|
214
219
|
assertPageConfigGlobal(pageConfigGlobal, plusFilesAll);
|
|
215
220
|
const pageConfigs = objectEntries(configDefinitionsResolved.configDefinitionsLocal)
|
|
@@ -220,14 +225,14 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
220
225
|
objectEntries(configDefinitionsLocal)
|
|
221
226
|
.filter(([_configName, configDef]) => configDef.global !== true)
|
|
222
227
|
.forEach(([configName, configDef]) => {
|
|
223
|
-
const sources = resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, false);
|
|
228
|
+
const sources = resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, false, plusFilesAll);
|
|
224
229
|
if (sources.length === 0)
|
|
225
230
|
return;
|
|
226
231
|
configValueSources[configName] = sources;
|
|
227
232
|
});
|
|
228
233
|
const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
|
|
229
234
|
applyEffectsMetaEnv(configValueSources, configDefinitionsLocal);
|
|
230
|
-
applyEffectsConfVal(configValueSources, configDefinitionsLocal);
|
|
235
|
+
applyEffectsConfVal(configValueSources, configDefinitionsLocal, plusFilesAll);
|
|
231
236
|
sortConfigValueSources(configValueSources, locationId);
|
|
232
237
|
const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
|
|
233
238
|
const pageConfig = {
|
|
@@ -352,6 +357,7 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
|
|
|
352
357
|
assert(includes(objectKeys(configDefinitionsBuiltIn), configName));
|
|
353
358
|
const configDef = configDefinitionsBuiltIn[configName];
|
|
354
359
|
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
360
|
+
// TODO/now: use getSourceNonConfigFile()
|
|
355
361
|
sources.push({
|
|
356
362
|
valueIsLoaded: true,
|
|
357
363
|
value,
|
|
@@ -370,6 +376,49 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
|
|
|
370
376
|
});
|
|
371
377
|
});
|
|
372
378
|
}
|
|
379
|
+
function setCliAndApiOptions(pageConfigGlobal) {
|
|
380
|
+
// VIKE_CONFIG
|
|
381
|
+
const configFromEnv = getEnvVarObject('VIKE_CONFIG');
|
|
382
|
+
if (configFromEnv) {
|
|
383
|
+
add(configFromEnv, { definedBy: 'env' });
|
|
384
|
+
}
|
|
385
|
+
// Vike API — passed options
|
|
386
|
+
const apiOperation = getApiOperation();
|
|
387
|
+
if (apiOperation?.options.vikeConfig) {
|
|
388
|
+
add(apiOperation.options.vikeConfig, {
|
|
389
|
+
definedBy: 'api',
|
|
390
|
+
operation: apiOperation.operation
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
// Vike CLI options
|
|
394
|
+
const cliOptions = getCliOptions();
|
|
395
|
+
if (cliOptions) {
|
|
396
|
+
add(cliOptions, { definedBy: 'cli' });
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
function add(configValues, definedBy) {
|
|
400
|
+
Object.entries(configValues).forEach(([configName, value]) => {
|
|
401
|
+
var _a;
|
|
402
|
+
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
403
|
+
sources.unshift(getSourceNonConfigFile(configName, value, definedBy));
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function getSourceNonConfigFile(configName, value, definedAt) {
|
|
408
|
+
assert(includes(objectKeys(configDefinitionsBuiltIn), configName));
|
|
409
|
+
const configDef = configDefinitionsBuiltIn[configName];
|
|
410
|
+
const source = {
|
|
411
|
+
valueIsLoaded: true,
|
|
412
|
+
value,
|
|
413
|
+
configEnv: configDef.env,
|
|
414
|
+
definedAtFilePath: definedAt,
|
|
415
|
+
locationId: '/',
|
|
416
|
+
plusFile: null,
|
|
417
|
+
valueIsLoadedWithImport: false,
|
|
418
|
+
valueIsDefinedByPlusValueFile: false
|
|
419
|
+
};
|
|
420
|
+
return source;
|
|
421
|
+
}
|
|
373
422
|
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
374
423
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
375
424
|
sources
|
|
@@ -456,7 +505,7 @@ function sortPlusFilesSameLocationId(plusFile1, plusFile2, configName) {
|
|
|
456
505
|
// No need to make it deterministic: the overall order is arleady deterministic, see sortMakeDeterministic() at getPlusFilesAll()
|
|
457
506
|
return 0;
|
|
458
507
|
}
|
|
459
|
-
function resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, isGlobal) {
|
|
508
|
+
function resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, isGlobal, plusFilesAll) {
|
|
460
509
|
let sources = plusFilesRelevant
|
|
461
510
|
.filter((plusFile) => isDefiningConfig(plusFile, configName))
|
|
462
511
|
.map((plusFile) => getConfigValueSource(configName, plusFile, configDef, userRootDir));
|
|
@@ -471,7 +520,7 @@ function resolveConfigValueSources(configName, configDef, plusFilesRelevant, use
|
|
|
471
520
|
sources = sources.filter((source) => {
|
|
472
521
|
assert(source.configEnv.config);
|
|
473
522
|
assert(source.valueIsLoaded);
|
|
474
|
-
const valueIsGlobal = resolveIsGlobalValue(configDef.global, source
|
|
523
|
+
const valueIsGlobal = resolveIsGlobalValue(configDef.global, source, plusFilesAll);
|
|
475
524
|
return isGlobal ? valueIsGlobal : !valueIsGlobal;
|
|
476
525
|
});
|
|
477
526
|
}
|
|
@@ -595,10 +644,13 @@ function isDefiningPage(plusFiles) {
|
|
|
595
644
|
function isDefiningPageConfig(configName) {
|
|
596
645
|
return ['Page', 'route'].includes(configName);
|
|
597
646
|
}
|
|
598
|
-
function resolveIsGlobalValue(configDefGlobal,
|
|
647
|
+
function resolveIsGlobalValue(configDefGlobal, source, plusFilesAll) {
|
|
648
|
+
assert(source.valueIsLoaded);
|
|
599
649
|
let isGlobal;
|
|
600
650
|
if (isCallable(configDefGlobal))
|
|
601
|
-
isGlobal = configDefGlobal(
|
|
651
|
+
isGlobal = configDefGlobal(source.value, {
|
|
652
|
+
isGlobalLocation: isGlobalLocation(source.locationId, plusFilesAll)
|
|
653
|
+
});
|
|
602
654
|
else
|
|
603
655
|
isGlobal = configDefGlobal ?? false;
|
|
604
656
|
assert(typeof isGlobal === 'boolean');
|
|
@@ -688,7 +740,7 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
|
|
|
688
740
|
});
|
|
689
741
|
}
|
|
690
742
|
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/vite.config.ts#L39
|
|
691
|
-
function applyEffectsConfVal(configValueSources, configDefinitions) {
|
|
743
|
+
function applyEffectsConfVal(configValueSources, configDefinitions, plusFilesAll) {
|
|
692
744
|
objectEntries(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
693
745
|
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
694
746
|
if (!sourceEffect)
|
|
@@ -696,8 +748,8 @@ function applyEffectsConfVal(configValueSources, configDefinitions) {
|
|
|
696
748
|
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
697
749
|
if (!effect)
|
|
698
750
|
return;
|
|
699
|
-
const
|
|
700
|
-
applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions,
|
|
751
|
+
const configModFromEffect = effect;
|
|
752
|
+
applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, plusFilesAll);
|
|
701
753
|
});
|
|
702
754
|
}
|
|
703
755
|
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/pages/config-meta/effect/e2e-test.ts#L16
|
|
@@ -709,7 +761,7 @@ function applyEffectsMetaEnv(configValueSources, configDefinitions) {
|
|
|
709
761
|
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
710
762
|
if (!effect)
|
|
711
763
|
return;
|
|
712
|
-
const
|
|
764
|
+
const configModFromEffect = effect;
|
|
713
765
|
applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect);
|
|
714
766
|
});
|
|
715
767
|
}
|
|
@@ -721,17 +773,16 @@ function runEffect(configName, configDef, source) {
|
|
|
721
773
|
`Cannot add meta.effect to ${pc.cyan(configName)} because its meta.env is ${pc.cyan(JSON.stringify(configDef.env))} but an effect can only be added to a config that has a meta.env with ${pc.cyan('{ config: true }')}.`
|
|
722
774
|
].join(' '));
|
|
723
775
|
assert(source.valueIsLoaded);
|
|
724
|
-
const configValueEffectSource = source.value;
|
|
725
776
|
// Call effect
|
|
726
777
|
const configModFromEffect = configDef.effect({
|
|
727
|
-
configValue:
|
|
778
|
+
configValue: source.value,
|
|
728
779
|
configDefinedAt: getConfigDefinedAt('Config', configName, source.definedAtFilePath)
|
|
729
780
|
});
|
|
730
781
|
if (!configModFromEffect)
|
|
731
782
|
return null;
|
|
732
|
-
return
|
|
783
|
+
return configModFromEffect;
|
|
733
784
|
}
|
|
734
|
-
function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions,
|
|
785
|
+
function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, plusFilesAll) {
|
|
735
786
|
objectEntries(configModFromEffect).forEach(([configNameTarget, configValue]) => {
|
|
736
787
|
if (configNameTarget === 'meta')
|
|
737
788
|
return;
|
|
@@ -748,11 +799,12 @@ function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSource
|
|
|
748
799
|
valueIsLoaded: true,
|
|
749
800
|
value: configValue
|
|
750
801
|
};
|
|
751
|
-
|
|
752
|
-
const
|
|
802
|
+
assert(sourceEffect.valueIsLoaded);
|
|
803
|
+
const isValueGlobalSource = resolveIsGlobalValue(configDefEffect.global, sourceEffect, plusFilesAll);
|
|
804
|
+
const isValueGlobalTarget = resolveIsGlobalValue(configDef.global, configValueSource, plusFilesAll);
|
|
753
805
|
const isGlobalHumanReadable = (isGlobal) => `${isGlobal ? 'non-' : ''}global`;
|
|
754
806
|
// The error message make it sound like it's an inherent limitation, it actually isn't (both ways can make senses).
|
|
755
|
-
assertUsage(isValueGlobalSource === isValueGlobalTarget, `The configuration ${pc.cyan(configNameEffect)} is set to ${pc.cyan(JSON.stringify(
|
|
807
|
+
assertUsage(isValueGlobalSource === isValueGlobalTarget, `The configuration ${pc.cyan(configNameEffect)} is set to ${pc.cyan(JSON.stringify(sourceEffect.value))} which is considered ${isGlobalHumanReadable(isValueGlobalSource)}. However, it has a meta.effect that sets the configuration ${pc.cyan(configNameTarget)} to ${pc.cyan(JSON.stringify(configValue))} which is considered ${isGlobalHumanReadable(isValueGlobalTarget)}. This is contradictory: make sure the values are either both non-global or both global.`);
|
|
756
808
|
configValueSources[configNameTarget] ?? (configValueSources[configNameTarget] = []);
|
|
757
809
|
configValueSources[configNameTarget].push(configValueSource);
|
|
758
810
|
});
|
|
@@ -889,7 +941,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
889
941
|
assert(filesystemRouteString.startsWith('/'));
|
|
890
942
|
const routeFilesystem = {
|
|
891
943
|
routeString: filesystemRouteString,
|
|
892
|
-
|
|
944
|
+
definedAtLocation: filesystemRouteDefinedBy
|
|
893
945
|
};
|
|
894
946
|
return { routeFilesystem, isErrorPage: undefined };
|
|
895
947
|
}
|
|
@@ -901,7 +953,9 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
901
953
|
const configDefinedAt = getConfigDefinedAt('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
902
954
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
903
955
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
904
|
-
const {
|
|
956
|
+
const { definedAtFilePath } = configFilesystemRoutingRoot;
|
|
957
|
+
assert(!definedAtFilePath.definedBy);
|
|
958
|
+
const { filePathAbsoluteUserRootDir } = definedAtFilePath;
|
|
905
959
|
assert(filePathAbsoluteUserRootDir);
|
|
906
960
|
const before = getFilesystemRouteString(getLocationId(filePathAbsoluteUserRootDir));
|
|
907
961
|
const after = value;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { getEnvVarObject };
|
|
2
|
-
|
|
2
|
+
export { parseJson5 };
|
|
3
|
+
declare function getEnvVarObject(envVarName: 'VITE_CONFIG' | 'VIKE_CRAWL' | 'VIKE_CONFIG'): null | Record<string, unknown>;
|
|
4
|
+
declare function parseJson5(valueStr: string, what: string): unknown;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
export { getEnvVarObject };
|
|
2
|
+
export { parseJson5 };
|
|
2
3
|
import pc from '@brillout/picocolors';
|
|
3
4
|
import { assertUsage, isObject } from '../utils.js';
|
|
4
5
|
import JSON5 from 'json5';
|
|
5
|
-
function getEnvVarObject(envVarName
|
|
6
|
-
/* Let's eventually implement this for Vike's config as well
|
|
7
|
-
| 'VIKE_CONFIG'
|
|
8
|
-
*/
|
|
9
|
-
) {
|
|
6
|
+
function getEnvVarObject(envVarName) {
|
|
10
7
|
const valueStr = process.env[envVarName];
|
|
11
8
|
if (!valueStr)
|
|
12
9
|
return null;
|
|
10
|
+
const value = parseJson5(valueStr, envVarName);
|
|
11
|
+
assertUsage(value, `${envVarName} should define an object but it's ${pc.bold(String(value))} instead.`);
|
|
12
|
+
assertUsage(isObject(value), `${envVarName} should define an object but it's set to the following which isn't an object: ${pc.bold(valueStr)}`);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function parseJson5(valueStr, what) {
|
|
13
16
|
let value;
|
|
14
17
|
try {
|
|
15
18
|
value = JSON5.parse(valueStr);
|
|
16
19
|
}
|
|
17
20
|
catch (err) {
|
|
18
21
|
console.error(err);
|
|
19
|
-
assertUsage(false, `Cannot parse ${
|
|
22
|
+
assertUsage(false, `Cannot parse ${pc.cyan(what)} (see error above) because it's set to the following which isn't a valid JSON5 string: ${pc.bold(valueStr)}`);
|
|
20
23
|
}
|
|
21
|
-
assertUsage(value, `${envVarName} should define an object but it's ${pc.bold(String(value))} instead.`);
|
|
22
|
-
assertUsage(isObject(value), `${envVarName} should define an object but it's set to the following which isn't an object: ${pc.bold(valueStr)}`);
|
|
23
24
|
return value;
|
|
24
25
|
}
|
|
@@ -2,7 +2,7 @@ export { logWithViteTag };
|
|
|
2
2
|
export { logWithVikeTag };
|
|
3
3
|
export { logDirectly };
|
|
4
4
|
export { applyViteSourceMapToStackTrace };
|
|
5
|
-
import { assert,
|
|
5
|
+
import { assert, stripAnsi, hasProp, assertIsNotProductionRuntime, PROJECT_VERSION } from '../../utils.js';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
8
8
|
import { getViteDevServer } from '../../../runtime/globalContext.js';
|
|
@@ -15,7 +15,7 @@ function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
|
15
15
|
function getProjectTag(showVikeVersion) {
|
|
16
16
|
let projectTag;
|
|
17
17
|
if (showVikeVersion) {
|
|
18
|
-
projectTag = `[vike@${
|
|
18
|
+
projectTag = `[vike@${PROJECT_VERSION}]`;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
projectTag = `[vike]`;
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
export { resolvePrerenderConfigGlobal };
|
|
2
2
|
export { resolvePrerenderConfigLocal };
|
|
3
|
-
import { assert, isArray, objectAssign } from './utils.js';
|
|
3
|
+
import { assert, isArray, isObject, objectAssign } from './utils.js';
|
|
4
4
|
import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
|
|
5
|
+
// When setting +prerender to an object => it also enables pre-rendering
|
|
6
|
+
const defaultValueForObject = true;
|
|
5
7
|
function resolvePrerenderConfigGlobal(vikeConfig) {
|
|
6
|
-
const prerenderConfigs = vikeConfig.global.config.prerender;
|
|
7
|
-
|
|
8
|
-
// Needed because of backwards compatibility of `vike({prerender:true})` in `vite.config.js`; after we remove it we can remove this line.
|
|
9
|
-
prerenderConfigList = prerenderConfigList.filter(isObject2);
|
|
10
|
-
assert(prerenderConfigList.every(isObject2)); // Help TS
|
|
8
|
+
const prerenderConfigs = vikeConfig.global.config.prerender || [];
|
|
9
|
+
const prerenderSettings = prerenderConfigs.filter(isObject2);
|
|
11
10
|
const prerenderConfigGlobal = {
|
|
12
|
-
partial: pickFirst(
|
|
13
|
-
noExtraDir: pickFirst(
|
|
14
|
-
parallel: pickFirst(
|
|
15
|
-
disableAutoRun: pickFirst(
|
|
11
|
+
partial: pickFirst(prerenderSettings.map((c) => c.partial)) ?? false,
|
|
12
|
+
noExtraDir: pickFirst(prerenderSettings.map((c) => c.noExtraDir)) ?? false,
|
|
13
|
+
parallel: pickFirst(prerenderSettings.map((c) => c.parallel)) ?? true,
|
|
14
|
+
disableAutoRun: pickFirst(prerenderSettings.map((c) => c.disableAutoRun)) ?? false
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
let defaultLocalValue = false;
|
|
17
|
+
{
|
|
18
|
+
const valueFirst = prerenderConfigs.filter((p) => !isObject(p) || p.value !== null)[0];
|
|
19
|
+
if (valueFirst === true || (isObject(valueFirst) && (valueFirst.value ?? defaultValueForObject))) {
|
|
20
|
+
defaultLocalValue = true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// TODO/next-major: remove
|
|
24
|
+
// Backwards compatibility for `vike({prerender:true})` in vite.config.js
|
|
25
|
+
{
|
|
26
|
+
const valuesWithDefinedAt = vikeConfig.global._from.configsCumulative.prerender?.values ?? [];
|
|
27
|
+
if (valuesWithDefinedAt.some((v) => v.definedAt.includes('vite.config.js') && v.value)) {
|
|
28
|
+
defaultLocalValue = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
23
31
|
objectAssign(prerenderConfigGlobal, {
|
|
24
32
|
defaultLocalValue,
|
|
25
33
|
isPrerenderingEnabledForAllPages: vikeConfig.pageConfigs.length > 0 &&
|
|
@@ -45,8 +53,8 @@ function resolvePrerenderConfigLocal(pageConfig) {
|
|
|
45
53
|
const prerenderConfigLocal = { value };
|
|
46
54
|
return prerenderConfigLocal;
|
|
47
55
|
}
|
|
48
|
-
function isObject2(
|
|
49
|
-
return typeof
|
|
56
|
+
function isObject2(value) {
|
|
57
|
+
return typeof value === 'object' && value !== null;
|
|
50
58
|
}
|
|
51
59
|
function pickFirst(arr) {
|
|
52
60
|
return arr.filter((v) => v !== undefined)[0];
|
|
@@ -4,7 +4,7 @@ export { runPrerenderFromAutoRun };
|
|
|
4
4
|
export { runPrerender_forceExit };
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { route } from '../../shared/route/index.js';
|
|
7
|
-
import { assert, assertUsage, assertWarning, hasProp,
|
|
7
|
+
import { assert, assertUsage, assertWarning, hasProp, objectAssign, isObjectWithKeys, isCallable, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender, isObject, makePublicCopy, PROJECT_VERSION } from './utils.js';
|
|
8
8
|
import { prerenderPage, prerender404Page, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { cpus } from 'os';
|
|
@@ -38,7 +38,7 @@ async function runPrerenderFromAPI(options = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
async function runPrerenderFromCLIPrerenderCommand() {
|
|
40
40
|
try {
|
|
41
|
-
const { viteConfigEnhanced } = await prepareViteApiCall(
|
|
41
|
+
const { viteConfigEnhanced } = await prepareViteApiCall({}, 'prerender');
|
|
42
42
|
await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
|
|
43
43
|
}
|
|
44
44
|
catch (err) {
|
|
@@ -75,7 +75,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
75
75
|
getHook_setIsPrerenderering();
|
|
76
76
|
const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
|
|
77
77
|
if (logLevel === 'info') {
|
|
78
|
-
console.log(`${pc.cyan(`vike v${
|
|
78
|
+
console.log(`${pc.cyan(`vike v${PROJECT_VERSION}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
79
79
|
}
|
|
80
80
|
await disableReactStreaming();
|
|
81
81
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'build', 'production');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '../../utils/assert.js';
|
|
2
2
|
export * from '../../utils/hasProp.js';
|
|
3
|
-
export * from '../../utils/
|
|
3
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
|
4
4
|
export * from '../../utils/objectAssign.js';
|
|
5
5
|
export * from '../../utils/isObjectWithKeys.js';
|
|
6
6
|
export * from '../../utils/isCallable.js';
|
|
@@ -2,7 +2,7 @@ import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
|
|
|
2
2
|
assertIsNotBrowser();
|
|
3
3
|
export * from '../../utils/assert.js';
|
|
4
4
|
export * from '../../utils/hasProp.js';
|
|
5
|
-
export * from '../../utils/
|
|
5
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
|
6
6
|
export * from '../../utils/objectAssign.js';
|
|
7
7
|
export * from '../../utils/isObjectWithKeys.js';
|
|
8
8
|
export * from '../../utils/isCallable.js';
|