vike 0.4.240 → 0.4.241
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/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/runtime-client-routing/logErrorClient.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/logErrorClient.js +11 -0
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +95 -84
- package/dist/esm/client/runtime-client-routing/utils.d.ts +0 -1
- package/dist/esm/client/runtime-client-routing/utils.js +0 -1
- package/dist/esm/node/cli/parseCli.js +10 -6
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +92 -0
- package/dist/esm/node/runtime/globalContext.js +12 -3
- package/dist/esm/node/runtime/logErrorServer.d.ts +2 -0
- package/dist/esm/node/runtime/logErrorServer.js +11 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.js +26 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -5
- package/dist/esm/node/runtime/renderPage.js +8 -7
- package/dist/esm/node/vite/index.js +6 -6
- package/dist/esm/node/vite/onLoad.js +3 -8
- package/dist/esm/node/vite/plugins/build/handleAssetsManifest.js +0 -1
- package/dist/esm/node/vite/plugins/build/pluginDistFileNames.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.js +13 -2
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +9 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.js +129 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +10 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +77 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.d.ts +3 -0
- package/dist/esm/node/vite/plugins/{pluginReplaceIsClientSide.js → pluginReplaceConstantsPageContext.js} +5 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +7 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +2 -2
- package/dist/esm/node/vite/shared/getFilePath.d.ts +4 -6
- package/dist/esm/node/vite/shared/getFilePath.js +6 -11
- package/dist/esm/node/vite/shared/isViteServerSide.d.ts +6 -3
- package/dist/esm/node/vite/shared/isViteServerSide.js +13 -4
- package/dist/esm/node/vite/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/vite/shared/loggerNotProd/log.js +8 -2
- package/dist/esm/node/vite/shared/loggerNotProd.d.ts +1 -1
- package/dist/esm/node/vite/shared/loggerNotProd.js +11 -11
- package/dist/esm/node/vite/shared/loggerVite.js +4 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +12 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -6
- package/dist/esm/shared/createGlobalContextShared.d.ts +2 -1
- package/dist/esm/shared/createGlobalContextShared.js +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +5 -4
- package/dist/esm/shared/route/abort.d.ts +1 -0
- package/dist/esm/shared/route/abort.js +12 -4
- package/dist/esm/shared/route/index.js +13 -4
- package/dist/esm/shared/route/utils.d.ts +1 -0
- package/dist/esm/shared/route/utils.js +1 -0
- package/dist/esm/types/Config.d.ts +14 -3
- 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 +1 -0
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/assertViteVersion.d.ts +2 -0
- package/dist/esm/utils/assertViteVersion.js +11 -0
- package/dist/esm/utils/debug.d.ts +5 -3
- package/dist/esm/utils/debug.js +20 -16
- package/dist/esm/utils/getGlobalObject.d.ts +5 -1
- package/dist/esm/utils/getGlobalObject.js +5 -1
- package/dist/esm/utils/isVikeReactApp.js +2 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +3 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +0 -110
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.d.ts +0 -9
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.js +0 -45
- package/dist/esm/node/vite/plugins/pluginReplaceIsClientSide.d.ts +0 -3
- package/dist/esm/shared/route/debug.d.ts +0 -6
- package/dist/esm/shared/route/debug.js +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.241",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
},
|
|
115
115
|
"dependencies": {
|
|
116
116
|
"@brillout/import": "^0.2.6",
|
|
117
|
-
"@brillout/json-serializer": "^0.5.
|
|
117
|
+
"@brillout/json-serializer": "^0.5.21",
|
|
118
118
|
"@brillout/picocolors": "^1.0.26",
|
|
119
119
|
"@brillout/require-shim": "^0.1.2",
|
|
120
120
|
"@brillout/vite-plugin-server-entry": "^0.7.15",
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
"@types/source-map-support": "^0.5.10",
|
|
248
248
|
"react-streaming": "^0.4.3",
|
|
249
249
|
"rimraf": "^5.0.5",
|
|
250
|
-
"typescript": "^5.
|
|
250
|
+
"typescript": "^5.9.2",
|
|
251
251
|
"vite": "^7.1.5"
|
|
252
252
|
},
|
|
253
253
|
"scripts": {
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
export { pluginEnvVars };
|
|
2
|
-
import { loadEnv } from 'vite';
|
|
3
|
-
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, isNotNullish, lowerFirst, } from '../utils.js';
|
|
4
|
-
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
5
|
-
import { normalizeId } from '../shared/normalizeId.js';
|
|
6
|
-
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
7
|
-
import { getMagicString } from '../shared/getMagicString.js';
|
|
8
|
-
// TO-DO/eventually:
|
|
9
|
-
// - Make import.meta.env work inside +config.js
|
|
10
|
-
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
11
|
-
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
12
|
-
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
13
|
-
const PUBLIC_ENV_ALLOWLIST = [
|
|
14
|
-
// https://github.com/vikejs/vike/issues/1724
|
|
15
|
-
'STORYBOOK',
|
|
16
|
-
];
|
|
17
|
-
const skipNodeModules = '/node_modules/';
|
|
18
|
-
const skipIrrelevant = 'import.meta.env.';
|
|
19
|
-
const filterRolldown = {
|
|
20
|
-
id: {
|
|
21
|
-
exclude: `**${skipNodeModules}**`,
|
|
22
|
-
},
|
|
23
|
-
code: {
|
|
24
|
-
include: skipIrrelevant,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
const filterFunction = (id, code) => {
|
|
28
|
-
if (id.includes(skipNodeModules))
|
|
29
|
-
return false;
|
|
30
|
-
if (!code.includes(skipIrrelevant))
|
|
31
|
-
return false;
|
|
32
|
-
return true;
|
|
33
|
-
};
|
|
34
|
-
function pluginEnvVars() {
|
|
35
|
-
let envsAll;
|
|
36
|
-
let config;
|
|
37
|
-
return [
|
|
38
|
-
{
|
|
39
|
-
name: 'vike:pluginEnvVars',
|
|
40
|
-
enforce: 'post',
|
|
41
|
-
configResolved: {
|
|
42
|
-
handler(config_) {
|
|
43
|
-
config = config_;
|
|
44
|
-
envsAll = loadEnv(config.mode, config.envDir || config.root, '');
|
|
45
|
-
config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
transform: {
|
|
49
|
-
filter: filterRolldown,
|
|
50
|
-
handler(code, id, options) {
|
|
51
|
-
id = normalizeId(id);
|
|
52
|
-
assertPosixPath(id);
|
|
53
|
-
assertPosixPath(config.root);
|
|
54
|
-
if (!id.startsWith(config.root))
|
|
55
|
-
return; // skip linked dependencies
|
|
56
|
-
assert(filterFunction(id, code));
|
|
57
|
-
const isBuild = config.command === 'build';
|
|
58
|
-
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
59
|
-
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
60
|
-
// Find & check
|
|
61
|
-
const replacements = Object.entries(envsAll)
|
|
62
|
-
.filter(([key]) => {
|
|
63
|
-
// Already handled by Vite
|
|
64
|
-
const envPrefix = !config.envPrefix
|
|
65
|
-
? []
|
|
66
|
-
: isArray(config.envPrefix)
|
|
67
|
-
? config.envPrefix
|
|
68
|
-
: [config.envPrefix];
|
|
69
|
-
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
70
|
-
})
|
|
71
|
-
.map(([envName, envVal]) => {
|
|
72
|
-
const envStatement = `import.meta.env.${envName}`;
|
|
73
|
-
const envStatementRegExpStr = escapeRegex(envStatement) + '\\b';
|
|
74
|
-
// Security check
|
|
75
|
-
{
|
|
76
|
-
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
77
|
-
if (isPrivate && isClientSide) {
|
|
78
|
-
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
79
|
-
return;
|
|
80
|
-
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
81
|
-
const errMsgAddendum = isBuild
|
|
82
|
-
? ''
|
|
83
|
-
: ' (Vike will prevent your app from building for production)';
|
|
84
|
-
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
85
|
-
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
86
|
-
if (isBuild) {
|
|
87
|
-
assertUsage(false, errMsg);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
91
|
-
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
92
|
-
assertWarning(false, errMsg, { onlyOnce: true });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Double check
|
|
96
|
-
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
97
|
-
}
|
|
98
|
-
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
99
|
-
})
|
|
100
|
-
.filter(isNotNullish);
|
|
101
|
-
// Apply
|
|
102
|
-
replacements.forEach(({ regExpStr, replacement }) => {
|
|
103
|
-
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
104
|
-
});
|
|
105
|
-
return getMagicStringResult();
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { pluginReplaceGlobalThisConstants };
|
|
2
|
-
import type { Plugin } from 'vite';
|
|
3
|
-
declare global {
|
|
4
|
-
/** Like `import.meta.env.DEV` but works inside `node_modules/` (even if package is `ssr.external`). The value `undefined` is to be interpreted as `false`. */
|
|
5
|
-
var __VIKE__IS_DEV: boolean | undefined;
|
|
6
|
-
/** Like `import.meta.env.SSR` but works inside `node_modules/` (even if package is `ssr.external`). The value `undefined` is to be interpreted as `false`. */
|
|
7
|
-
var __VIKE__IS_CLIENT: boolean | undefined;
|
|
8
|
-
}
|
|
9
|
-
declare function pluginReplaceGlobalThisConstants(): Plugin[];
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export { pluginReplaceGlobalThisConstants };
|
|
2
|
-
import { assert } from '../utils.js';
|
|
3
|
-
// === Explanation: globalThis.__VIKE__IS_DEV
|
|
4
|
-
// If client-side => always noExternal => globalThis.__VIKE__IS_DEV is set by the `define` config below.
|
|
5
|
-
// If server-side:
|
|
6
|
-
// If ssr.noExternal => globalThis.__VIKE__IS_DEV is set by the `define` config below.
|
|
7
|
-
// If `ssr.external`:
|
|
8
|
-
// If not RunnableDevEnvironment (e.g. `@cloudflare/vite-plugin`) => always ssr.noExternal => globalThis.__VIKE__IS_DEV is set by the `define` config below.
|
|
9
|
-
// If RunnableDevEnvironment (the default setup):
|
|
10
|
-
// If dev/preview/pre-rendering => Vite is loaded, and server and Vite run inside the same process (because RunnableDevEnvironment) => globalThis.__VIKE__IS_DEV is set by the assignment below.
|
|
11
|
-
// If production => Vite isn't loaded => globalThis.__VIKE__IS_DEV is `undefined` (it's never set) => value `undefined` is to be interpreted as `false`.
|
|
12
|
-
// === Explanation: globalThis.__VIKE__IS_CLIENT
|
|
13
|
-
// If client-side => always noExternal => globalThis.__VIKE__IS_CLIENT is set to `true` by the `define` config below.
|
|
14
|
-
// If server-side => globalThis.__VIKE__IS_CLIENT is either `false` or `undefined` (the value `undefined` is to be interpreted as `false`).
|
|
15
|
-
globalThis.__VIKE__IS_CLIENT = false;
|
|
16
|
-
function pluginReplaceGlobalThisConstants() {
|
|
17
|
-
return [
|
|
18
|
-
{
|
|
19
|
-
name: 'vike:pluginReplaceGlobalThisConstants',
|
|
20
|
-
config: {
|
|
21
|
-
handler(config) {
|
|
22
|
-
const isDev = config._isDev;
|
|
23
|
-
assert(typeof isDev === 'boolean');
|
|
24
|
-
globalThis.__VIKE__IS_DEV = isDev;
|
|
25
|
-
return {
|
|
26
|
-
define: {
|
|
27
|
-
'globalThis.__VIKE__IS_DEV': JSON.stringify(isDev),
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
configEnvironment: {
|
|
33
|
-
handler(name, config) {
|
|
34
|
-
const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');
|
|
35
|
-
const isClientSide = consumer === 'client';
|
|
36
|
-
return {
|
|
37
|
-
define: {
|
|
38
|
-
'globalThis.__VIKE__IS_CLIENT': JSON.stringify(isClientSide),
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { debug };
|
|
2
|
-
export { setCreateDebugger };
|
|
3
|
-
import type { createDebugger, Debug } from '../../utils/debug.js';
|
|
4
|
-
type CreateDebugger = typeof createDebugger;
|
|
5
|
-
declare function debug(...args: Parameters<Debug>): void;
|
|
6
|
-
declare function setCreateDebugger(createDebugger: CreateDebugger): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { debug };
|
|
2
|
-
export { setCreateDebugger };
|
|
3
|
-
// Using createDebugger() for isomorphic code without bloating the client-side.
|
|
4
|
-
// On the server-side, this is just a transparent proxy.
|
|
5
|
-
// On the client-side, this is an empty shell.
|
|
6
|
-
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
7
|
-
const globalObject = getGlobalObject('route/debug.ts', {});
|
|
8
|
-
function debug(...args) {
|
|
9
|
-
// Client-side => does nothing
|
|
10
|
-
if (!globalObject.createDebugger)
|
|
11
|
-
return;
|
|
12
|
-
// Server-side => just a proxy
|
|
13
|
-
if (!globalObject.debug) {
|
|
14
|
-
globalObject.debug = globalObject.createDebugger('vike:routing');
|
|
15
|
-
}
|
|
16
|
-
globalObject.debug(...args);
|
|
17
|
-
}
|
|
18
|
-
// Called only on the server-side
|
|
19
|
-
function setCreateDebugger(createDebugger) {
|
|
20
|
-
globalObject.createDebugger = createDebugger;
|
|
21
|
-
}
|