vike 0.4.215 → 0.4.217-commit-99ea561
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/__internal/index.js +2 -2
- package/dist/cjs/node/api/build.js +10 -3
- package/dist/cjs/node/api/context.js +8 -6
- package/dist/cjs/node/api/dev.js +7 -2
- package/dist/cjs/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
- package/dist/cjs/node/api/prerender.js +7 -2
- package/dist/cjs/node/api/preview.js +7 -2
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +7 -10
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +10 -10
- package/dist/cjs/node/plugin/plugins/commonConfig.js +35 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -4
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -106
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +42 -28
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -4
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +35 -17
- package/dist/cjs/node/prerender/runPrerender.js +5 -7
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +21 -13
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +4 -2
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
- package/dist/cjs/node/runtime-dev/index.js +32 -0
- package/dist/cjs/node/shared/resolveBase.js +41 -0
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +135 -0
- package/dist/cjs/utils/isDocker.js +2 -2
- package/dist/cjs/utils/requireResolve.js +2 -2
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/api/build.d.ts +5 -0
- package/dist/esm/node/api/build.js +10 -3
- package/dist/esm/node/api/context.js +9 -7
- package/dist/esm/node/api/dev.d.ts +5 -0
- package/dist/esm/node/api/dev.js +7 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
- package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
- package/dist/esm/node/api/prerender.d.ts +5 -0
- package/dist/esm/node/api/prerender.js +7 -2
- package/dist/esm/node/api/preview.d.ts +5 -0
- package/dist/esm/node/api/preview.js +7 -2
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.d.ts +3 -3
- package/dist/esm/node/plugin/index.js +6 -9
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +11 -11
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +36 -5
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -5
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -106
- package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +43 -29
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +5 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +37 -19
- package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +6 -8
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +8 -4
- package/dist/esm/node/runtime/globalContext.js +22 -14
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +5 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
- package/dist/esm/node/runtime-dev/index.d.ts +3 -0
- package/dist/esm/node/runtime-dev/index.js +6 -0
- package/dist/esm/node/shared/resolveBase.d.ts +11 -0
- package/dist/esm/node/shared/resolveBase.js +36 -0
- package/dist/esm/shared/page-configs/Config.d.ts +2 -2
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.d.ts +20 -0
- package/dist/esm/utils/assertSetup.js +130 -0
- package/dist/esm/utils/isDocker.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
- package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
- package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
- package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
- package/dist/cjs/node/shared/getConfigVike.js +0 -10
- package/dist/cjs/shared/ConfigVike.js +0 -2
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- package/dist/esm/node/api/prepareApiCall.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
- package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +0 -76
- package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
- package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
- package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
- package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
- package/dist/esm/node/shared/getConfigVike.js +0 -8
- package/dist/esm/shared/ConfigVike.js +0 -1
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
- package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
- package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
- package/dist/esm/utils/assertNodeEnv.js +0 -103
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export { assertIsNotProductionRuntime };
|
|
2
|
+
export { onSetupRuntime };
|
|
3
|
+
export { onSetupBuild };
|
|
4
|
+
export { onSetupPrerender };
|
|
5
|
+
export { setNodeEnvProduction };
|
|
6
|
+
export { markSetup_viteDevServer };
|
|
7
|
+
export { markSetup_vitePreviewServer };
|
|
8
|
+
export { markSetup_vikeVitePlugin };
|
|
9
|
+
export { markSetup_isViteDev };
|
|
10
|
+
export { markSetup_isPrerendering };
|
|
11
|
+
import { assert, assertUsage, assertWarning } from './assert.js';
|
|
12
|
+
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
13
|
+
import { createDebugger } from './debug.js';
|
|
14
|
+
import { getGlobalObject } from './getGlobalObject.js';
|
|
15
|
+
import { isVitest } from './isVitest.js';
|
|
16
|
+
import pc from '@brillout/picocolors';
|
|
17
|
+
assertIsNotBrowser();
|
|
18
|
+
const debug = createDebugger('vike:setup');
|
|
19
|
+
const setup = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
|
|
20
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
|
+
function assertIsNotProductionRuntime() {
|
|
22
|
+
if (debug.isActivated)
|
|
23
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
24
|
+
setup.shouldNotBeProduction = true;
|
|
25
|
+
}
|
|
26
|
+
function onSetupRuntime() {
|
|
27
|
+
if (debug.isActivated)
|
|
28
|
+
debug('assertSetup()', new Error().stack);
|
|
29
|
+
if (isTest())
|
|
30
|
+
return;
|
|
31
|
+
if (!isViteLoaded()) {
|
|
32
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
33
|
+
assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which seems contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
34
|
+
assertUsage(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
35
|
+
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
36
|
+
assert(!setup.shouldNotBeProduction);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
40
|
+
assertWarning(isNodeEnvDev() || setup.vitePreviewServer || setup.isPrerendering, `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
41
|
+
// These two assert() calls aren't that interesting
|
|
42
|
+
assert(setup.vikeVitePlugin);
|
|
43
|
+
assert(setup.shouldNotBeProduction);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Ensure NODE_ENV is 'production' when building.
|
|
47
|
+
// - Used by both Vue and React for bundling minified version:
|
|
48
|
+
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
49
|
+
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
50
|
+
// - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
51
|
+
// - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
52
|
+
function onSetupBuild() {
|
|
53
|
+
assertUsageNodeEnvIsNotDev('building');
|
|
54
|
+
/* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
|
|
55
|
+
setNodeEnvProduction()
|
|
56
|
+
*/
|
|
57
|
+
}
|
|
58
|
+
function onSetupPrerender() {
|
|
59
|
+
markSetup_isPrerendering();
|
|
60
|
+
if (getNodeEnvValue())
|
|
61
|
+
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
62
|
+
setNodeEnvProduction();
|
|
63
|
+
}
|
|
64
|
+
function isViteLoaded() {
|
|
65
|
+
// Do we need setup.viteDevServer or setup.vitePreviewServer ?
|
|
66
|
+
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
67
|
+
}
|
|
68
|
+
function isTest() {
|
|
69
|
+
return isVitest() || getNodeEnvValue() === 'test';
|
|
70
|
+
}
|
|
71
|
+
// Called by Vite hook configureServer()
|
|
72
|
+
function markSetup_viteDevServer() {
|
|
73
|
+
if (debug.isActivated)
|
|
74
|
+
debug('markSetup_viteDevServer()', new Error().stack);
|
|
75
|
+
setup.viteDevServer = true;
|
|
76
|
+
}
|
|
77
|
+
// Called by Vite hook configurePreviewServer()
|
|
78
|
+
function markSetup_vitePreviewServer() {
|
|
79
|
+
if (debug.isActivated)
|
|
80
|
+
debug('markSetup_vitePreviewServer()', new Error().stack);
|
|
81
|
+
setup.vitePreviewServer = true;
|
|
82
|
+
}
|
|
83
|
+
// Called by ../node/plugin/index.ts
|
|
84
|
+
function markSetup_vikeVitePlugin() {
|
|
85
|
+
if (debug.isActivated)
|
|
86
|
+
debug('markSetup_vikeVitePlugin()', new Error().stack);
|
|
87
|
+
setup.vikeVitePlugin = true;
|
|
88
|
+
}
|
|
89
|
+
// Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
|
|
90
|
+
function markSetup_isViteDev(isViteDev) {
|
|
91
|
+
if (debug.isActivated)
|
|
92
|
+
debug('markSetup_isViteDev()', new Error().stack);
|
|
93
|
+
setup.isViteDev = isViteDev;
|
|
94
|
+
}
|
|
95
|
+
// Called by ../node/prerender/runPrerender.ts
|
|
96
|
+
function markSetup_isPrerendering() {
|
|
97
|
+
if (debug.isActivated)
|
|
98
|
+
debug('markSetup_isPrerendering()', new Error().stack);
|
|
99
|
+
setup.isPrerendering = true;
|
|
100
|
+
}
|
|
101
|
+
function assertUsageNodeEnvIsNotDev(operation) {
|
|
102
|
+
if (!isNodeEnvDev())
|
|
103
|
+
return;
|
|
104
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
105
|
+
assertWarning(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
106
|
+
}
|
|
107
|
+
function getEnvDescription() {
|
|
108
|
+
const nodeEnv = getNodeEnvValue();
|
|
109
|
+
const isDev = isNodeEnvDev();
|
|
110
|
+
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
111
|
+
const nodeEnvDesc = `environment is set to be a ${pc.bold(envType)} by ${pc.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
112
|
+
return nodeEnvDesc;
|
|
113
|
+
}
|
|
114
|
+
function isNodeEnvDev() {
|
|
115
|
+
const nodeEnv = getNodeEnvValue();
|
|
116
|
+
// That's quite strict, let's see if some user complains
|
|
117
|
+
return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
|
|
118
|
+
}
|
|
119
|
+
function getNodeEnvValue() {
|
|
120
|
+
if (typeof process === 'undefined')
|
|
121
|
+
return null;
|
|
122
|
+
return process.env.NODE_ENV?.toLowerCase();
|
|
123
|
+
}
|
|
124
|
+
function setNodeEnvProduction() {
|
|
125
|
+
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
126
|
+
const proc = process;
|
|
127
|
+
const { env } = proc;
|
|
128
|
+
env.NODE_ENV = 'production';
|
|
129
|
+
assert(getNodeEnvValue() === 'production');
|
|
130
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { isDocker };
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { assertIsNotProductionRuntime } from './
|
|
3
|
+
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
4
4
|
assertIsNotProductionRuntime();
|
|
5
5
|
function isDocker() {
|
|
6
6
|
return hasContainerEnv() || isDockerContainer();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { requireResolve };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
|
-
import { assertIsNotProductionRuntime } from './
|
|
4
|
+
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
5
5
|
import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
|
|
6
6
|
import { scriptFileExtensionList } from './isScriptFile.js';
|
|
7
7
|
import { createRequire } from 'module';
|
package/package.json
CHANGED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertVikeConfig = assertVikeConfig;
|
|
4
|
-
const utils_js_1 = require("../../utils.js");
|
|
5
|
-
function assertVikeConfig(vikeConfig, wrongUsageMsg) {
|
|
6
|
-
const wrongUsageError = checkConfigVike(vikeConfig);
|
|
7
|
-
if (wrongUsageError) {
|
|
8
|
-
(0, utils_js_1.assertUsage)(false, wrongUsageMsg(wrongUsageError));
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function checkConfigVike(configVike) {
|
|
12
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(configVike));
|
|
13
|
-
{
|
|
14
|
-
const prop = 'disableUrlNormalization';
|
|
15
|
-
if (!(0, utils_js_1.hasProp)(configVike, prop, 'boolean') && !(0, utils_js_1.hasProp)(configVike, prop, 'undefined'))
|
|
16
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
17
|
-
}
|
|
18
|
-
{
|
|
19
|
-
const prop = 'trailingSlash';
|
|
20
|
-
if (!(0, utils_js_1.hasProp)(configVike, prop, 'boolean') && !(0, utils_js_1.hasProp)(configVike, prop, 'undefined'))
|
|
21
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
22
|
-
}
|
|
23
|
-
{
|
|
24
|
-
const prop = 'redirects';
|
|
25
|
-
const { redirects } = configVike;
|
|
26
|
-
if (!(redirects === undefined ||
|
|
27
|
-
((0, utils_js_1.isObject)(redirects) && Object.values(redirects).every((v) => typeof v === 'string'))))
|
|
28
|
-
return { prop, errMsg: 'should be an object of strings' };
|
|
29
|
-
}
|
|
30
|
-
{
|
|
31
|
-
const prop = 'disableAutoFullBuild';
|
|
32
|
-
if (!(0, utils_js_1.hasProp)(configVike, prop, 'boolean') &&
|
|
33
|
-
!(0, utils_js_1.hasProp)(configVike, prop, 'undefined') &&
|
|
34
|
-
!(configVike[prop] === 'prerender'))
|
|
35
|
-
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
36
|
-
}
|
|
37
|
-
{
|
|
38
|
-
const prop = 'includeAssetsImportedByServer';
|
|
39
|
-
if (!(0, utils_js_1.hasProp)(configVike, prop, 'boolean') && !(0, utils_js_1.hasProp)(configVike, prop, 'undefined'))
|
|
40
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
41
|
-
}
|
|
42
|
-
{
|
|
43
|
-
const prop = 'prerender';
|
|
44
|
-
if (!(0, utils_js_1.hasProp)(configVike, prop, 'object') &&
|
|
45
|
-
!(0, utils_js_1.hasProp)(configVike, prop, 'boolean') &&
|
|
46
|
-
!(0, utils_js_1.hasProp)(configVike, prop, 'undefined'))
|
|
47
|
-
return { prop, errMsg: 'should be an object or a boolean' };
|
|
48
|
-
}
|
|
49
|
-
const configVikePrerender = configVike.prerender;
|
|
50
|
-
if (typeof configVikePrerender === 'object') {
|
|
51
|
-
{
|
|
52
|
-
const p = 'partial';
|
|
53
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
54
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
55
|
-
}
|
|
56
|
-
{
|
|
57
|
-
const p = 'noExtraDir';
|
|
58
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
59
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
60
|
-
}
|
|
61
|
-
{
|
|
62
|
-
const p = 'disableAutoRun';
|
|
63
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
64
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
65
|
-
}
|
|
66
|
-
{
|
|
67
|
-
const p = 'parallel';
|
|
68
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') &&
|
|
69
|
-
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'number') &&
|
|
70
|
-
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
71
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean or a number' };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveVikeConfig = resolveVikeConfig;
|
|
7
|
-
const assertVikeConfig_js_1 = require("./assertVikeConfig.js");
|
|
8
|
-
const utils_js_1 = require("../../utils.js");
|
|
9
|
-
const pickFirst_js_1 = require("./pickFirst.js");
|
|
10
|
-
const resolveBase_js_1 = require("./resolveBase.js");
|
|
11
|
-
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
12
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
function resolveVikeConfig(vikeConfig) {
|
|
14
|
-
let isDev;
|
|
15
|
-
return {
|
|
16
|
-
name: 'vike:resolveVikeConfig',
|
|
17
|
-
enforce: 'pre',
|
|
18
|
-
apply(_config, env) {
|
|
19
|
-
isDev = (0, utils_js_1.isDevCheck)(env);
|
|
20
|
-
return true;
|
|
21
|
-
},
|
|
22
|
-
async configResolved(config) {
|
|
23
|
-
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
24
|
-
const promise = getConfigVikPromise(vikeConfig, config, isDev);
|
|
25
|
-
config.configVikePromise = promise;
|
|
26
|
-
await promise;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
async function getConfigVikPromise(vikeConfig, config, isDev) {
|
|
31
|
-
const fromPluginOptions = (vikeConfig ?? {});
|
|
32
|
-
const fromViteConfig = (config.vike ?? {});
|
|
33
|
-
const configs = [fromPluginOptions, fromViteConfig];
|
|
34
|
-
(0, assertVikeConfig_js_1.assertVikeConfig)(fromViteConfig, ({ prop, errMsg }) => `vite.config.js#vike.${prop} ${errMsg}`);
|
|
35
|
-
// TODO/v1-release: deprecate this
|
|
36
|
-
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
|
|
37
|
-
const crawlWithGit = fromPluginOptions.crawl?.git ?? null;
|
|
38
|
-
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, { crawlWithGit });
|
|
39
|
-
configs.push(fromPlusConfigFile);
|
|
40
|
-
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
41
|
-
// TODO: add config file path ?
|
|
42
|
-
return `config ${picocolors_1.default.cyan(prop)} ${errMsg}`;
|
|
43
|
-
});
|
|
44
|
-
const { baseServer, baseAssets } = (0, resolveBase_js_1.resolveBase)(configs, config);
|
|
45
|
-
const configVike = {
|
|
46
|
-
disableAutoFullBuild: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.disableAutoFullBuild)) ?? null,
|
|
47
|
-
prerender: resolvePrerenderOptions(configs),
|
|
48
|
-
includeAssetsImportedByServer: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
|
|
49
|
-
baseServer,
|
|
50
|
-
baseAssets,
|
|
51
|
-
redirects: merge(configs.map((c) => c.redirects)) ?? {},
|
|
52
|
-
disableUrlNormalization: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.disableUrlNormalization)) ?? false,
|
|
53
|
-
trailingSlash: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.trailingSlash)) ?? false,
|
|
54
|
-
crawl: {
|
|
55
|
-
git: crawlWithGit
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
return configVike;
|
|
59
|
-
}
|
|
60
|
-
function resolvePrerenderOptions(configs) {
|
|
61
|
-
if (!configs.some((c) => c.prerender)) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const configsPrerender = configs.map((c) => c.prerender).filter(isObject);
|
|
65
|
-
return {
|
|
66
|
-
partial: (0, pickFirst_js_1.pickFirst)(configsPrerender.map((c) => c.partial)) ?? false,
|
|
67
|
-
noExtraDir: (0, pickFirst_js_1.pickFirst)(configsPrerender.map((c) => c.noExtraDir)) ?? false,
|
|
68
|
-
parallel: (0, pickFirst_js_1.pickFirst)(configsPrerender.map((c) => c.parallel)) ?? true,
|
|
69
|
-
disableAutoRun: (0, pickFirst_js_1.pickFirst)(configsPrerender.map((c) => c.disableAutoRun)) ?? false
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function isObject(p) {
|
|
73
|
-
return typeof p === 'object';
|
|
74
|
-
}
|
|
75
|
-
function merge(objs) {
|
|
76
|
-
const obj = {};
|
|
77
|
-
objs.forEach((e) => {
|
|
78
|
-
Object.assign(obj, e);
|
|
79
|
-
});
|
|
80
|
-
return obj;
|
|
81
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveBase = resolveBase;
|
|
7
|
-
exports.resolveBaseFromUserConfig = resolveBaseFromUserConfig;
|
|
8
|
-
const utils_js_1 = require("../../utils.js");
|
|
9
|
-
const pickFirst_js_1 = require("./pickFirst.js");
|
|
10
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
function resolveBase(configs, config) {
|
|
12
|
-
const baseServer = (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.baseServer)) ?? null;
|
|
13
|
-
const baseAssets = (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.baseAssets)) ?? null;
|
|
14
|
-
let baseOriginal = config._baseOriginal;
|
|
15
|
-
if (baseOriginal === '/__UNSET__')
|
|
16
|
-
baseOriginal = null;
|
|
17
|
-
(0, utils_js_1.assert)(baseOriginal === null || typeof baseOriginal == 'string');
|
|
18
|
-
return resolve(baseOriginal, baseServer, baseAssets);
|
|
19
|
-
}
|
|
20
|
-
function resolveBaseFromUserConfig(config, configVike) {
|
|
21
|
-
return resolve(config.base ?? null, configVike?.baseServer ?? null, configVike?.baseAssets ?? null);
|
|
22
|
-
}
|
|
23
|
-
function resolve(base, baseServer_, baseAssets_) {
|
|
24
|
-
{
|
|
25
|
-
const wrongBase = (val) => `should start with ${picocolors_1.default.cyan('/')}, ${picocolors_1.default.cyan('http://')}, or ${picocolors_1.default.cyan('https://')} (it's ${picocolors_1.default.cyan(val)} instead)`;
|
|
26
|
-
(0, utils_js_1.assertUsage)(base === null || (0, utils_js_1.isBaseAssets)(base), `vite.config.js#base ${wrongBase(base)}`);
|
|
27
|
-
(0, utils_js_1.assertUsage)(baseAssets_ === null || (0, utils_js_1.isBaseAssets)(baseAssets_), `Config ${picocolors_1.default.cyan('baseAssets')} ${wrongBase(baseAssets_)}`);
|
|
28
|
-
(0, utils_js_1.assertUsage)(baseServer_ === null || baseServer_.startsWith('/'), `Config ${picocolors_1.default.cyan('baseServer')} should start with a leading slash ${picocolors_1.default.cyan('/')} (it's ${picocolors_1.default.cyan(String(baseServer_))} instead)`);
|
|
29
|
-
}
|
|
30
|
-
if (base) {
|
|
31
|
-
if (base.startsWith('http')) {
|
|
32
|
-
baseAssets_ = baseAssets_ ?? base;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
baseAssets_ = baseAssets_ ?? base;
|
|
36
|
-
baseServer_ = baseServer_ ?? base;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const baseServer = baseServer_ ?? '/';
|
|
40
|
-
const baseAssets = baseAssets_ ?? '/';
|
|
41
|
-
(0, utils_js_1.assert)((0, utils_js_1.isBaseAssets)(baseAssets));
|
|
42
|
-
(0, utils_js_1.assert)((0, utils_js_1.isBaseServer)(baseServer));
|
|
43
|
-
return {
|
|
44
|
-
baseServer,
|
|
45
|
-
baseAssets
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfigVike = getConfigVike;
|
|
4
|
-
const utils_js_1 = require("./utils.js");
|
|
5
|
-
async function getConfigVike(config) {
|
|
6
|
-
const { configVikePromise } = config;
|
|
7
|
-
(0, utils_js_1.assert)(configVikePromise);
|
|
8
|
-
const configVike = await configVikePromise;
|
|
9
|
-
return configVike;
|
|
10
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Mechanism to ensure code isn't loaded by production runtime
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.vikeVitePluginLoadedInProductionError = void 0;
|
|
5
|
-
exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
|
|
6
|
-
exports.markEnvAsViteDev = markEnvAsViteDev;
|
|
7
|
-
exports.markEnvAsVitePreview = markEnvAsVitePreview;
|
|
8
|
-
exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
|
|
9
|
-
exports.assertEnv = assertEnv;
|
|
10
|
-
const assert_js_1 = require("./assert.js");
|
|
11
|
-
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
-
const debug_js_1 = require("./debug.js");
|
|
13
|
-
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
14
|
-
const isVitest_js_1 = require("./isVitest.js");
|
|
15
|
-
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
16
|
-
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
17
|
-
const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
|
|
18
|
-
exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProductionError;
|
|
19
|
-
const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
|
|
20
|
-
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
|
-
function assertIsNotProductionRuntime() {
|
|
22
|
-
if (debug.isActivated)
|
|
23
|
-
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
24
|
-
env.shouldNotBeProduction = true;
|
|
25
|
-
}
|
|
26
|
-
// Called by Vite hook configureServer()
|
|
27
|
-
function markEnvAsViteDev() {
|
|
28
|
-
if (debug.isActivated)
|
|
29
|
-
debug('markEnvAsViteDev()', new Error().stack);
|
|
30
|
-
env.isViteDev = true;
|
|
31
|
-
}
|
|
32
|
-
// Called by Vite hook configurePreviewServer()
|
|
33
|
-
function markEnvAsVitePreview() {
|
|
34
|
-
if (debug.isActivated)
|
|
35
|
-
debug('markEnvAsVitePreview()', new Error().stack);
|
|
36
|
-
env.isVitePreview = true;
|
|
37
|
-
}
|
|
38
|
-
// Called by ../node/plugin/index.ts
|
|
39
|
-
function markEnvAsVikePluginLoaded() {
|
|
40
|
-
if (debug.isActivated)
|
|
41
|
-
debug('markEnvAsVikePluginLoaded()', new Error().stack);
|
|
42
|
-
env.isVikePluginLoaded = true;
|
|
43
|
-
}
|
|
44
|
-
// Called by ../node/runtime/index.ts
|
|
45
|
-
function assertEnv() {
|
|
46
|
-
if (debug.isActivated)
|
|
47
|
-
debug('assertEnv()', new Error().stack);
|
|
48
|
-
if ((0, isVitest_js_1.isVitest)())
|
|
49
|
-
return;
|
|
50
|
-
const isProduction = !env.isViteDev && !env.isVitePreview;
|
|
51
|
-
if (isProduction) {
|
|
52
|
-
// Seems to be the only reliable way to assert that the user doesn't load Vike's Vite plugin in production. (The other assert() that uses process.env.NODE_ENV doesn't work if the user sets the process.env.NODE_ENV value later.)
|
|
53
|
-
(0, assert_js_1.assertUsage)(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
|
|
54
|
-
// This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
55
|
-
(0, assert_js_1.assert)(!env.shouldNotBeProduction);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// This assert() is obious and boring
|
|
59
|
-
(0, assert_js_1.assert)(env.shouldNotBeProduction);
|
|
60
|
-
(0, assert_js_1.assert)(env.isVikePluginLoaded);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file serves the following three purposes:
|
|
3
|
-
// 1. Upon building the app, we ensure the right NODE_ENV value is set.
|
|
4
|
-
// - Both Vue and React use NODE_ENV for enabling production-specific features:
|
|
5
|
-
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
6
|
-
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
7
|
-
// - Setting NODE_ENV to 'production' doesn't seem to make any sense in development.
|
|
8
|
-
// - With React upon building the app, setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
9
|
-
// - With Vue upon building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
10
|
-
// 2. Ensure Vite isn't loaded in production.
|
|
11
|
-
// - We currently only check whether Vite's development middleware is instantiated (i.e. whether Vite's `createServer()` was called). Is there a way to detect whether Vite's code is loaded?
|
|
12
|
-
// 3. Ensure NODE_ENV isn't mistakenly set to a wrong value.
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.assertNodeEnv_build = assertNodeEnv_build;
|
|
18
|
-
exports.assertNodeEnv_runtime = assertNodeEnv_runtime;
|
|
19
|
-
exports.assertNodeEnv_onVikePluginLoad = assertNodeEnv_onVikePluginLoad;
|
|
20
|
-
exports.handleNodeEnv_prerender = handleNodeEnv_prerender;
|
|
21
|
-
exports.handleNodeEnv_vitePluginVercel = handleNodeEnv_vitePluginVercel;
|
|
22
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
23
|
-
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
24
|
-
const assert_js_1 = require("./assert.js");
|
|
25
|
-
const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
|
|
26
|
-
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
27
|
-
function assertNodeEnv_build() {
|
|
28
|
-
assertNodeEnvIsNotDev('building');
|
|
29
|
-
}
|
|
30
|
-
function assertNodeEnv_runtime(isViteDev) {
|
|
31
|
-
const nodeEnv = getNodeEnv();
|
|
32
|
-
if (nodeEnv === null || nodeEnv === 'test')
|
|
33
|
-
return;
|
|
34
|
-
const isNodeDev = isNodeEnvDev();
|
|
35
|
-
// Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
36
|
-
if (isViteDev === isNodeDev)
|
|
37
|
-
return;
|
|
38
|
-
const nodeEnvDesc = getNodeEnvDesc();
|
|
39
|
-
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
40
|
-
const errMsg = `Running ${isViteDev ? picocolors_1.default.cyan('$ vike dev') : 'app in production'} while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`;
|
|
41
|
-
(0, assert_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
42
|
-
}
|
|
43
|
-
function assertNodeEnv_onVikePluginLoad() {
|
|
44
|
-
const nodeEnv = getNodeEnv();
|
|
45
|
-
if (nodeEnv === 'test')
|
|
46
|
-
return;
|
|
47
|
-
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
48
|
-
(0, assert_js_1.assertWarning)(
|
|
49
|
-
/* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
|
|
50
|
-
isNodeEnvDev() || isVikeCliBuild(),
|
|
51
|
-
/*/
|
|
52
|
-
isNodeEnvDev() || true,
|
|
53
|
-
///*/
|
|
54
|
-
[
|
|
55
|
-
picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
|
|
56
|
-
'(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
|
|
57
|
-
'while the vike/plugin module is loaded.',
|
|
58
|
-
assertIsNotProductionRuntime_js_1.vikeVitePluginLoadedInProductionError
|
|
59
|
-
].join(' '), { onlyOnce: true });
|
|
60
|
-
}
|
|
61
|
-
function handleNodeEnv_prerender() {
|
|
62
|
-
const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
|
|
63
|
-
if (getNodeEnv())
|
|
64
|
-
assertNodeEnv();
|
|
65
|
-
setNodeEnvToProduction();
|
|
66
|
-
assertNodeEnv();
|
|
67
|
-
}
|
|
68
|
-
function handleNodeEnv_vitePluginVercel() {
|
|
69
|
-
setNodeEnvToProduction();
|
|
70
|
-
}
|
|
71
|
-
function getNodeEnv() {
|
|
72
|
-
if (typeof process === 'undefined')
|
|
73
|
-
return null;
|
|
74
|
-
return process.env.NODE_ENV;
|
|
75
|
-
}
|
|
76
|
-
function setNodeEnvToProduction() {
|
|
77
|
-
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
78
|
-
const proc = process;
|
|
79
|
-
const { env } = proc;
|
|
80
|
-
env.NODE_ENV = 'production';
|
|
81
|
-
}
|
|
82
|
-
function isNodeEnvDev() {
|
|
83
|
-
const nodeEnv = getNodeEnv();
|
|
84
|
-
if (!nodeEnv)
|
|
85
|
-
return true;
|
|
86
|
-
if (['development', 'dev'].includes(nodeEnv))
|
|
87
|
-
return true;
|
|
88
|
-
// That's quite aggressive, let's see if some user complains
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
function getNodeEnvDesc() {
|
|
92
|
-
const nodeEnv = getNodeEnv();
|
|
93
|
-
const isDev = isNodeEnvDev();
|
|
94
|
-
const nodeEnvDesc = `environment is set to be a ${(isDev ? 'development' : 'production')} environment by ${picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)}`;
|
|
95
|
-
return nodeEnvDesc;
|
|
96
|
-
}
|
|
97
|
-
function assertNodeEnvIsNotDev(operation) {
|
|
98
|
-
const isDev = isNodeEnvDev();
|
|
99
|
-
if (!isDev)
|
|
100
|
-
return;
|
|
101
|
-
const nodeEnvDesc = getNodeEnvDesc();
|
|
102
|
-
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
103
|
-
(0, assert_js_1.assertWarning)(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, {
|
|
104
|
-
onlyOnce: true
|
|
105
|
-
});
|
|
106
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { prepareApiCall };
|
|
2
|
-
import type { InlineConfig } from 'vite';
|
|
3
|
-
import type { Operation } from './types.js';
|
|
4
|
-
declare function prepareApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
|
|
5
|
-
viteConfigEnhanced: InlineConfig;
|
|
6
|
-
configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
|
|
7
|
-
}>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { assertVikeConfig };
|
|
2
|
-
import type { ConfigVikeUserProvided } from '../../../../shared/ConfigVike.js';
|
|
3
|
-
type WrongUsage = {
|
|
4
|
-
prop: string;
|
|
5
|
-
errMsg: `should be a${string}`;
|
|
6
|
-
};
|
|
7
|
-
declare function assertVikeConfig(vikeConfig: unknown, wrongUsageMsg: (wrongUsage: WrongUsage) => string): asserts vikeConfig is ConfigVikeUserProvided;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export { assertVikeConfig };
|
|
2
|
-
import { assert, assertUsage, hasProp, isObject } from '../../utils.js';
|
|
3
|
-
function assertVikeConfig(vikeConfig, wrongUsageMsg) {
|
|
4
|
-
const wrongUsageError = checkConfigVike(vikeConfig);
|
|
5
|
-
if (wrongUsageError) {
|
|
6
|
-
assertUsage(false, wrongUsageMsg(wrongUsageError));
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
function checkConfigVike(configVike) {
|
|
10
|
-
assert(isObject(configVike));
|
|
11
|
-
{
|
|
12
|
-
const prop = 'disableUrlNormalization';
|
|
13
|
-
if (!hasProp(configVike, prop, 'boolean') && !hasProp(configVike, prop, 'undefined'))
|
|
14
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
15
|
-
}
|
|
16
|
-
{
|
|
17
|
-
const prop = 'trailingSlash';
|
|
18
|
-
if (!hasProp(configVike, prop, 'boolean') && !hasProp(configVike, prop, 'undefined'))
|
|
19
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
20
|
-
}
|
|
21
|
-
{
|
|
22
|
-
const prop = 'redirects';
|
|
23
|
-
const { redirects } = configVike;
|
|
24
|
-
if (!(redirects === undefined ||
|
|
25
|
-
(isObject(redirects) && Object.values(redirects).every((v) => typeof v === 'string'))))
|
|
26
|
-
return { prop, errMsg: 'should be an object of strings' };
|
|
27
|
-
}
|
|
28
|
-
{
|
|
29
|
-
const prop = 'disableAutoFullBuild';
|
|
30
|
-
if (!hasProp(configVike, prop, 'boolean') &&
|
|
31
|
-
!hasProp(configVike, prop, 'undefined') &&
|
|
32
|
-
!(configVike[prop] === 'prerender'))
|
|
33
|
-
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
34
|
-
}
|
|
35
|
-
{
|
|
36
|
-
const prop = 'includeAssetsImportedByServer';
|
|
37
|
-
if (!hasProp(configVike, prop, 'boolean') && !hasProp(configVike, prop, 'undefined'))
|
|
38
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
39
|
-
}
|
|
40
|
-
{
|
|
41
|
-
const prop = 'prerender';
|
|
42
|
-
if (!hasProp(configVike, prop, 'object') &&
|
|
43
|
-
!hasProp(configVike, prop, 'boolean') &&
|
|
44
|
-
!hasProp(configVike, prop, 'undefined'))
|
|
45
|
-
return { prop, errMsg: 'should be an object or a boolean' };
|
|
46
|
-
}
|
|
47
|
-
const configVikePrerender = configVike.prerender;
|
|
48
|
-
if (typeof configVikePrerender === 'object') {
|
|
49
|
-
{
|
|
50
|
-
const p = 'partial';
|
|
51
|
-
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
52
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
53
|
-
}
|
|
54
|
-
{
|
|
55
|
-
const p = 'noExtraDir';
|
|
56
|
-
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
57
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
58
|
-
}
|
|
59
|
-
{
|
|
60
|
-
const p = 'disableAutoRun';
|
|
61
|
-
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
62
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
63
|
-
}
|
|
64
|
-
{
|
|
65
|
-
const p = 'parallel';
|
|
66
|
-
if (!hasProp(configVikePrerender, p, 'boolean') &&
|
|
67
|
-
!hasProp(configVikePrerender, p, 'number') &&
|
|
68
|
-
!hasProp(configVikePrerender, p, 'undefined'))
|
|
69
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean or a number' };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|