vike 0.4.215 → 0.4.216
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 +7 -2
- 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} +2 -2
- 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 +2 -3
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +21 -3
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
- package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
- package/dist/cjs/node/prerender/runPrerender.js +3 -3
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +6 -6
- package/dist/cjs/node/runtime/index-common.js +3 -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/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 +7 -2
- 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/{prepareApiCall.d.ts → prepareViteApiCall.d.ts} +2 -2
- package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +2 -2
- 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.js +3 -4
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +21 -3
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
- package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
- package/dist/esm/node/prerender/runPrerender.js +4 -4
- 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 +2 -2
- package/dist/esm/node/runtime/globalContext.js +7 -7
- 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.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/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/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- 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,135 @@
|
|
|
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.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
|
|
7
|
+
exports.onSetupRuntime = onSetupRuntime;
|
|
8
|
+
exports.onSetupBuild = onSetupBuild;
|
|
9
|
+
exports.onSetupPrerender = onSetupPrerender;
|
|
10
|
+
exports.setNodeEnvProduction = setNodeEnvProduction;
|
|
11
|
+
exports.markSetup_viteDevServer = markSetup_viteDevServer;
|
|
12
|
+
exports.markSetup_vitePreviewServer = markSetup_vitePreviewServer;
|
|
13
|
+
exports.markSetup_vikeVitePlugin = markSetup_vikeVitePlugin;
|
|
14
|
+
exports.markSetup_isViteDev = markSetup_isViteDev;
|
|
15
|
+
exports.markSetup_isPrerendering = markSetup_isPrerendering;
|
|
16
|
+
const assert_js_1 = require("./assert.js");
|
|
17
|
+
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
18
|
+
const debug_js_1 = require("./debug.js");
|
|
19
|
+
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
20
|
+
const isVitest_js_1 = require("./isVitest.js");
|
|
21
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
22
|
+
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
23
|
+
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
24
|
+
const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
|
|
25
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
26
|
+
function assertIsNotProductionRuntime() {
|
|
27
|
+
if (debug.isActivated)
|
|
28
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
29
|
+
setup.shouldNotBeProduction = true;
|
|
30
|
+
}
|
|
31
|
+
function onSetupRuntime() {
|
|
32
|
+
if (debug.isActivated)
|
|
33
|
+
debug('assertSetup()', new Error().stack);
|
|
34
|
+
if (isTest())
|
|
35
|
+
return;
|
|
36
|
+
if (!isViteLoaded()) {
|
|
37
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
38
|
+
(0, assert_js_1.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 });
|
|
39
|
+
(0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
40
|
+
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
41
|
+
(0, assert_js_1.assert)(!setup.shouldNotBeProduction);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
45
|
+
(0, assert_js_1.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 });
|
|
46
|
+
// These two assert() calls aren't that interesting
|
|
47
|
+
(0, assert_js_1.assert)(setup.vikeVitePlugin);
|
|
48
|
+
(0, assert_js_1.assert)(setup.shouldNotBeProduction);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Ensure NODE_ENV is 'production' when building.
|
|
52
|
+
// - Used by both Vue and React for bundling minified version:
|
|
53
|
+
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
54
|
+
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
55
|
+
// - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
56
|
+
// - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
57
|
+
function onSetupBuild() {
|
|
58
|
+
assertUsageNodeEnvIsNotDev('building');
|
|
59
|
+
/* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
|
|
60
|
+
setNodeEnvProduction()
|
|
61
|
+
*/
|
|
62
|
+
}
|
|
63
|
+
function onSetupPrerender() {
|
|
64
|
+
markSetup_isPrerendering();
|
|
65
|
+
if (getNodeEnvValue())
|
|
66
|
+
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
67
|
+
setNodeEnvProduction();
|
|
68
|
+
}
|
|
69
|
+
function isViteLoaded() {
|
|
70
|
+
// Do we need setup.viteDevServer or setup.vitePreviewServer ?
|
|
71
|
+
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
72
|
+
}
|
|
73
|
+
function isTest() {
|
|
74
|
+
return (0, isVitest_js_1.isVitest)() || getNodeEnvValue() === 'test';
|
|
75
|
+
}
|
|
76
|
+
// Called by Vite hook configureServer()
|
|
77
|
+
function markSetup_viteDevServer() {
|
|
78
|
+
if (debug.isActivated)
|
|
79
|
+
debug('markSetup_viteDevServer()', new Error().stack);
|
|
80
|
+
setup.viteDevServer = true;
|
|
81
|
+
}
|
|
82
|
+
// Called by Vite hook configurePreviewServer()
|
|
83
|
+
function markSetup_vitePreviewServer() {
|
|
84
|
+
if (debug.isActivated)
|
|
85
|
+
debug('markSetup_vitePreviewServer()', new Error().stack);
|
|
86
|
+
setup.vitePreviewServer = true;
|
|
87
|
+
}
|
|
88
|
+
// Called by ../node/plugin/index.ts
|
|
89
|
+
function markSetup_vikeVitePlugin() {
|
|
90
|
+
if (debug.isActivated)
|
|
91
|
+
debug('markSetup_vikeVitePlugin()', new Error().stack);
|
|
92
|
+
setup.vikeVitePlugin = true;
|
|
93
|
+
}
|
|
94
|
+
// Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
|
|
95
|
+
function markSetup_isViteDev(isViteDev) {
|
|
96
|
+
if (debug.isActivated)
|
|
97
|
+
debug('markSetup_isViteDev()', new Error().stack);
|
|
98
|
+
setup.isViteDev = isViteDev;
|
|
99
|
+
}
|
|
100
|
+
// Called by ../node/prerender/runPrerender.ts
|
|
101
|
+
function markSetup_isPrerendering() {
|
|
102
|
+
if (debug.isActivated)
|
|
103
|
+
debug('markSetup_isPrerendering()', new Error().stack);
|
|
104
|
+
setup.isPrerendering = true;
|
|
105
|
+
}
|
|
106
|
+
function assertUsageNodeEnvIsNotDev(operation) {
|
|
107
|
+
if (!isNodeEnvDev())
|
|
108
|
+
return;
|
|
109
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
110
|
+
(0, assert_js_1.assertWarning)(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
111
|
+
}
|
|
112
|
+
function getEnvDescription() {
|
|
113
|
+
const nodeEnv = getNodeEnvValue();
|
|
114
|
+
const isDev = isNodeEnvDev();
|
|
115
|
+
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
116
|
+
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
117
|
+
return nodeEnvDesc;
|
|
118
|
+
}
|
|
119
|
+
function isNodeEnvDev() {
|
|
120
|
+
const nodeEnv = getNodeEnvValue();
|
|
121
|
+
// That's quite strict, let's see if some user complains
|
|
122
|
+
return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
|
|
123
|
+
}
|
|
124
|
+
function getNodeEnvValue() {
|
|
125
|
+
if (typeof process === 'undefined')
|
|
126
|
+
return null;
|
|
127
|
+
return process.env.NODE_ENV?.toLowerCase();
|
|
128
|
+
}
|
|
129
|
+
function setNodeEnvProduction() {
|
|
130
|
+
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
131
|
+
const proc = process;
|
|
132
|
+
const { env } = proc;
|
|
133
|
+
env.NODE_ENV = 'production';
|
|
134
|
+
(0, assert_js_1.assert)(getNodeEnvValue() === 'production');
|
|
135
|
+
}
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isDocker = isDocker;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const
|
|
9
|
-
(0,
|
|
8
|
+
const assertSetup_js_1 = require("./assertSetup.js");
|
|
9
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
10
10
|
function isDocker() {
|
|
11
11
|
return hasContainerEnv() || isDockerContainer();
|
|
12
12
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.requireResolve = requireResolve;
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
5
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
6
|
-
const
|
|
6
|
+
const assertSetup_js_1 = require("./assertSetup.js");
|
|
7
7
|
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
8
8
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
9
|
const module_1 = require("module");
|
|
@@ -11,7 +11,7 @@ const module_1 = require("module");
|
|
|
11
11
|
const importMetaUrl = `file://${__filename}`;
|
|
12
12
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
13
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
14
|
-
(0,
|
|
14
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
15
15
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
16
16
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
17
17
|
function requireResolve(importPath, cwd) {
|
|
@@ -5,7 +5,7 @@ export { getMiddlewares };
|
|
|
5
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
6
|
import { getPageFilesAll } from '../shared/getPageFiles.js';
|
|
7
7
|
import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
|
|
8
|
-
import {
|
|
8
|
+
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
9
9
|
import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
10
|
/**
|
|
11
11
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
@@ -14,7 +14,7 @@ import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRo
|
|
|
14
14
|
* @param config
|
|
15
15
|
*/
|
|
16
16
|
async function getPagesAndRoutes() {
|
|
17
|
-
|
|
17
|
+
setNodeEnvProduction();
|
|
18
18
|
const renderContext = await getRenderContext();
|
|
19
19
|
const {
|
|
20
20
|
//
|
|
@@ -2,6 +2,11 @@ export { build };
|
|
|
2
2
|
import { type Rollup } from 'vite';
|
|
3
3
|
import type { APIOptions } from './types.js';
|
|
4
4
|
type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
|
|
5
|
+
/**
|
|
6
|
+
* Programmatically trigger `$ vike build`
|
|
7
|
+
*
|
|
8
|
+
* https://vike.dev/api#build
|
|
9
|
+
*/
|
|
5
10
|
declare function build(options?: APIOptions): Promise<{
|
|
6
11
|
rollupOutputClient: RollupOutput;
|
|
7
12
|
rollupOutputServer: RollupOutput;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { build };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { build as buildVite } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike build`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#build
|
|
8
|
+
*/
|
|
4
9
|
async function build(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced, configVike } = await
|
|
10
|
+
const { viteConfigEnhanced, configVike } = await prepareViteApiCall(options.viteConfig, 'build');
|
|
6
11
|
// Build client-side
|
|
7
12
|
const outputClient = await buildVite(viteConfigEnhanced);
|
|
8
13
|
// Build server-side
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
export { isVikeCliOrApi };
|
|
2
2
|
// export { getOperation }
|
|
3
3
|
export { setOperation as setOperation };
|
|
4
|
-
import { assert } from './utils.js';
|
|
5
|
-
|
|
4
|
+
import { assert, getGlobalObject } from './utils.js';
|
|
5
|
+
const globalObject = getGlobalObject('context.ts', {
|
|
6
|
+
apiOperation: undefined
|
|
7
|
+
});
|
|
6
8
|
function getOperation() {
|
|
7
|
-
assert(apiOperation);
|
|
8
|
-
return apiOperation;
|
|
9
|
+
assert(globalObject.apiOperation);
|
|
10
|
+
return globalObject.apiOperation;
|
|
9
11
|
}
|
|
10
12
|
function isVikeCliOrApi() {
|
|
11
13
|
// The CLI uses the API
|
|
12
|
-
return !!apiOperation;
|
|
14
|
+
return !!globalObject.apiOperation;
|
|
13
15
|
}
|
|
14
16
|
function setOperation(operation) {
|
|
15
|
-
assert(!apiOperation);
|
|
16
|
-
apiOperation = operation;
|
|
17
|
+
assert(!globalObject.apiOperation);
|
|
18
|
+
globalObject.apiOperation = operation;
|
|
17
19
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { dev };
|
|
2
2
|
import { type ResolvedConfig, type ViteDevServer } from 'vite';
|
|
3
3
|
import type { APIOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike dev`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#dev
|
|
8
|
+
*/
|
|
4
9
|
declare function dev(options?: APIOptions): Promise<{
|
|
5
10
|
viteServer: ViteDevServer;
|
|
6
11
|
viteConfig: ResolvedConfig;
|
package/dist/esm/node/api/dev.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { dev };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { createServer } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike dev`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#dev
|
|
8
|
+
*/
|
|
4
9
|
async function dev(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'dev');
|
|
6
11
|
const server = await createServer(viteConfigEnhanced);
|
|
7
12
|
return {
|
|
8
13
|
viteServer: server,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { prepareViteApiCall };
|
|
2
2
|
import type { InlineConfig } from 'vite';
|
|
3
3
|
import type { Operation } from './types.js';
|
|
4
|
-
declare function
|
|
4
|
+
declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
|
|
5
5
|
viteConfigEnhanced: InlineConfig;
|
|
6
6
|
configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
|
|
7
7
|
}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { prepareViteApiCall };
|
|
2
2
|
import { resolveConfig } from 'vite';
|
|
3
3
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
4
4
|
import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
|
|
5
5
|
import { setOperation } from './context.js';
|
|
6
|
-
async function
|
|
6
|
+
async function prepareViteApiCall(viteConfig = {}, operation) {
|
|
7
7
|
setOperation(operation);
|
|
8
8
|
return enhanceViteConfig(viteConfig, operation);
|
|
9
9
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { prerender };
|
|
2
2
|
import { type PrerenderOptions } from '../prerender/runPrerender.js';
|
|
3
3
|
import type { ResolvedConfig } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike prerender`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#prerender
|
|
8
|
+
*/
|
|
4
9
|
declare function prerender(options?: PrerenderOptions): Promise<{
|
|
5
10
|
viteConfig: ResolvedConfig;
|
|
6
11
|
}>;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { prerender };
|
|
2
2
|
import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
|
|
3
|
-
import {
|
|
3
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike prerender`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#prerender
|
|
8
|
+
*/
|
|
4
9
|
async function prerender(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
|
|
6
11
|
options.viteConfig = viteConfigEnhanced;
|
|
7
12
|
const { viteConfig } = await runPrerenderFromAPI(options);
|
|
8
13
|
return {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { preview };
|
|
2
2
|
import { type ResolvedConfig, type PreviewServer } from 'vite';
|
|
3
3
|
import type { APIOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike preview`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#preview
|
|
8
|
+
*/
|
|
4
9
|
declare function preview(options?: APIOptions): Promise<{
|
|
5
10
|
viteServer: PreviewServer;
|
|
6
11
|
viteConfig: ResolvedConfig;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { preview };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { preview as previewVite } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike preview`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#preview
|
|
8
|
+
*/
|
|
4
9
|
async function preview(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
|
|
6
11
|
const server = await previewVite(viteConfigEnhanced);
|
|
7
12
|
return {
|
|
8
13
|
viteServer: server,
|
|
@@ -4,7 +4,7 @@ export { plugin };
|
|
|
4
4
|
export { plugin as ssr };
|
|
5
5
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
6
|
import { version } from 'vite';
|
|
7
|
-
import {
|
|
7
|
+
import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
|
|
8
8
|
import { buildConfig } from './plugins/buildConfig.js';
|
|
9
9
|
import { previewConfig } from './plugins/previewConfig.js';
|
|
10
10
|
import { autoFullBuild } from './plugins/autoFullBuild.js';
|
|
@@ -28,8 +28,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
|
|
|
28
28
|
import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
|
|
29
29
|
import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
|
|
30
30
|
import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
|
|
31
|
-
|
|
32
|
-
markEnvAsVikePluginLoaded();
|
|
31
|
+
markSetup_vikeVitePlugin();
|
|
33
32
|
assertViteVersion();
|
|
34
33
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
35
34
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
@@ -48,7 +47,7 @@ function plugin(vikeConfig) {
|
|
|
48
47
|
...extractAssetsPlugin(),
|
|
49
48
|
extractExportNamesPlugin(),
|
|
50
49
|
suppressRollupWarning(),
|
|
51
|
-
setGlobalContext(),
|
|
50
|
+
...setGlobalContext(),
|
|
52
51
|
...importBuild(),
|
|
53
52
|
baseUrls(vikeConfig),
|
|
54
53
|
envVarsPlugin(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { onLoad };
|
|
2
2
|
import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
|
|
3
|
-
import { assertIsNotProductionRuntime } from '../../utils/
|
|
3
|
+
import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
|
|
4
4
|
import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
|
|
5
5
|
function onLoad() {
|
|
6
6
|
assertIsNotBrowser();
|
|
@@ -2,7 +2,7 @@ export { buildConfig };
|
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
|
-
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs,
|
|
5
|
+
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, onSetupBuild, assertIsNpmPackageImport } from '../utils.js';
|
|
6
6
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
8
8
|
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
@@ -27,14 +27,14 @@ function buildConfig() {
|
|
|
27
27
|
let config;
|
|
28
28
|
return [
|
|
29
29
|
{
|
|
30
|
-
name: 'vike:buildConfig:
|
|
30
|
+
name: 'vike:buildConfig:post',
|
|
31
31
|
apply: 'build',
|
|
32
32
|
enforce: 'post',
|
|
33
33
|
configResolved: {
|
|
34
34
|
order: 'post',
|
|
35
35
|
async handler(config_) {
|
|
36
36
|
config = config_;
|
|
37
|
-
|
|
37
|
+
onSetupBuild();
|
|
38
38
|
assertRollupInput(config);
|
|
39
39
|
const entries = await getEntries(config);
|
|
40
40
|
assert(Object.keys(entries).length > 0);
|
|
@@ -57,7 +57,7 @@ function buildConfig() {
|
|
|
57
57
|
config: {
|
|
58
58
|
order: 'post',
|
|
59
59
|
handler(config) {
|
|
60
|
-
|
|
60
|
+
onSetupBuild();
|
|
61
61
|
isSsrBuild = viteIsSSR(config);
|
|
62
62
|
return {
|
|
63
63
|
build: {
|
|
@@ -69,14 +69,15 @@ function buildConfig() {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
buildStart() {
|
|
72
|
-
|
|
72
|
+
onSetupBuild();
|
|
73
73
|
},
|
|
74
74
|
async closeBundle() {
|
|
75
|
+
onSetupBuild();
|
|
75
76
|
await fixServerAssets_assertCssTarget(config);
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
79
|
{
|
|
79
|
-
name: 'vike:buildConfig:
|
|
80
|
+
name: 'vike:buildConfig:pre',
|
|
80
81
|
apply: 'build',
|
|
81
82
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
82
83
|
// - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
@@ -9,9 +9,7 @@ import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
|
9
9
|
import { pluginName } from './commonConfig/pluginName.js';
|
|
10
10
|
import { getEnvVarObject } from '../shared/getEnvVarObject.js';
|
|
11
11
|
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
12
|
-
|
|
13
|
-
onlyOnce: true
|
|
14
|
-
});
|
|
12
|
+
import { isVikeCliOrApi } from '../../api/context.js';
|
|
15
13
|
function commonConfig() {
|
|
16
14
|
return [
|
|
17
15
|
{
|
|
@@ -34,6 +32,7 @@ function commonConfig() {
|
|
|
34
32
|
assertRollupInput(config);
|
|
35
33
|
assertResolveAlias(config);
|
|
36
34
|
assertEsm(config.root);
|
|
35
|
+
assertVikeCliOrApi(config);
|
|
37
36
|
}
|
|
38
37
|
},
|
|
39
38
|
config: {
|
|
@@ -97,3 +96,22 @@ function assertSingleInstance(config) {
|
|
|
97
96
|
const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
|
|
98
97
|
assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
|
|
99
98
|
}
|
|
99
|
+
function assertVikeCliOrApi(config) {
|
|
100
|
+
if (isVikeCliOrApi())
|
|
101
|
+
return;
|
|
102
|
+
if (isViteCliCall()) {
|
|
103
|
+
assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
104
|
+
onlyOnce: true
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (config.server.middlewareMode) {
|
|
109
|
+
assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
110
|
+
onlyOnce: true
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
assertWarning(false, `Vite's JavaScript API is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
115
|
+
onlyOnce: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -3,7 +3,7 @@ export { logDockerHint };
|
|
|
3
3
|
import { determineOptimizeDeps } from './determineOptimizeDeps.js';
|
|
4
4
|
import { determineFsAllowList } from './determineFsAllowList.js';
|
|
5
5
|
import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
|
|
6
|
-
import { applyDev, assertWarning, isDocker
|
|
6
|
+
import { applyDev, assertWarning, isDocker } from '../../utils.js';
|
|
7
7
|
import { improveViteLogs } from '../../shared/loggerVite.js';
|
|
8
8
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
9
9
|
import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
|
|
@@ -65,9 +65,6 @@ function devConfig() {
|
|
|
65
65
|
improveViteLogs(config);
|
|
66
66
|
}
|
|
67
67
|
logDockerHint(config.server.host);
|
|
68
|
-
},
|
|
69
|
-
configureServer() {
|
|
70
|
-
markEnvAsViteDev();
|
|
71
68
|
}
|
|
72
69
|
},
|
|
73
70
|
{
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -13,12 +13,16 @@ assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
|
13
13
|
let gitIsNotUsable = false;
|
|
14
14
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
|
|
15
15
|
assertPosixPath(userRootDir);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
//*/
|
|
17
|
+
const outDirRelativeFromUserRootDir = null;
|
|
18
|
+
/*/
|
|
19
|
+
assertPosixPath(outDirAbsoluteFilesystem)
|
|
20
|
+
let outDirRelativeFromUserRootDir: string | null = path.posix.relative(userRootDir, outDirAbsoluteFilesystem)
|
|
18
21
|
if (outDirRelativeFromUserRootDir.startsWith('../')) {
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
23
|
+
outDirRelativeFromUserRootDir = null
|
|
21
24
|
}
|
|
25
|
+
//*/
|
|
22
26
|
assert(outDirRelativeFromUserRootDir === null ||
|
|
23
27
|
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
24
28
|
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { previewConfig };
|
|
2
|
-
import { assertUsage, getOutDirs, resolveOutDir,
|
|
2
|
+
import { assertUsage, getOutDirs, resolveOutDir, applyPreview } from '../utils.js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
|
|
@@ -29,7 +29,6 @@ function previewConfig() {
|
|
|
29
29
|
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
30
30
|
config.appType = 'mpa'
|
|
31
31
|
*/
|
|
32
|
-
markEnvAsVitePreview();
|
|
33
32
|
return () => {
|
|
34
33
|
assertDist();
|
|
35
34
|
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
|
-
import {
|
|
3
|
-
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck } from '../utils.js';
|
|
2
|
+
import { setGlobalContext_isViteDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
|
|
3
|
+
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck, markSetup_isViteDev, markSetup_viteDevServer, markSetup_vitePreviewServer } from '../utils.js';
|
|
4
4
|
function setGlobalContext() {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
name: 'vike:setGlobalContext:pre',
|
|
8
|
+
enforce: 'pre',
|
|
9
|
+
configureServer: {
|
|
10
|
+
order: 'pre',
|
|
11
|
+
handler(viteDevServer) {
|
|
12
|
+
setGlobalContext_viteDevServer(viteDevServer);
|
|
13
|
+
markSetup_viteDevServer();
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
configurePreviewServer() {
|
|
17
|
+
markSetup_vitePreviewServer();
|
|
18
|
+
},
|
|
19
|
+
config: {
|
|
20
|
+
order: 'pre',
|
|
21
|
+
handler(_, env) {
|
|
22
|
+
const isViteDev = isDevCheck(env);
|
|
23
|
+
setGlobalContext_isViteDev(isViteDev);
|
|
24
|
+
markSetup_isViteDev(isViteDev);
|
|
25
|
+
}
|
|
12
26
|
}
|
|
13
27
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
{
|
|
29
|
+
name: 'vike:setGlobalContext:post',
|
|
30
|
+
enforce: 'post',
|
|
31
|
+
configResolved: {
|
|
32
|
+
order: 'post',
|
|
33
|
+
handler(config) {
|
|
34
|
+
const { outDirRoot } = getOutDirs(config);
|
|
35
|
+
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
36
|
+
setGlobalContext_viteConfig(config, outDirRoot);
|
|
37
|
+
}
|
|
18
38
|
}
|
|
19
|
-
},
|
|
20
|
-
configResolved(config) {
|
|
21
|
-
const { outDirRoot } = getOutDirs(config);
|
|
22
|
-
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
23
|
-
setGlobalContext_viteConfig(config, outDirRoot);
|
|
24
39
|
}
|
|
25
|
-
|
|
40
|
+
];
|
|
26
41
|
}
|