vike 0.4.239-commit-95ab407 → 0.4.240-commit-bac5dee
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.js +1 -1
- package/dist/esm/node/runtime/globalContext.js +10 -8
- package/dist/esm/node/vite/index.js +21 -16
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.d.ts +7 -0
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js +47 -0
- package/dist/esm/node/vite/plugins/{pluginNonRunnableDev.d.ts → non-runnable-dev/pluginViteRPC.d.ts} +3 -7
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginViteRPC.js +30 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -7
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +1 -1
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.js +127 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +17 -0
- package/dist/esm/node/vite/plugins/{pluginReplaceGlobalThisConstants.js → pluginReplaceConstantsGlobalThis.js} +11 -4
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.d.ts +3 -0
- package/dist/esm/node/vite/plugins/{pluginReplaceIsClientSide.js → pluginReplaceConstantsPageContext.js} +5 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +1 -1
- package/dist/esm/node/vite/shared/getMagicString.d.ts +1 -1
- package/dist/esm/node/vite/shared/getMagicString.js +2 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +2 -2
- 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 +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/assert.js +1 -0
- package/dist/esm/utils/debug.d.ts +5 -3
- package/dist/esm/utils/debug.js +28 -11
- package/dist/esm/utils/getGlobalObject.d.ts +5 -1
- package/dist/esm/utils/getGlobalObject.js +5 -1
- package/dist/esm/utils/isDev.js +3 -1
- package/dist/esm/utils/isNonRunnableDev.js +2 -2
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +2 -2
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +0 -112
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +0 -86
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.d.ts +0 -9
- 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/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistFileNames.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistFileNames.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistPackageJsonFile.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistPackageJsonFile.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginModuleBanner.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginModuleBanner.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.js +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.js +0 -0
|
@@ -168,7 +168,7 @@ function hasServerOnlyHook(pageContext) {
|
|
|
168
168
|
if (isOldDesign(pageContext))
|
|
169
169
|
return false;
|
|
170
170
|
const pageConfig = getPageConfig(pageContext.pageId, pageContext._globalContext._pageConfigs);
|
|
171
|
-
const val = getConfigValueRuntime(pageConfig, `
|
|
171
|
+
const val = getConfigValueRuntime(pageConfig, `hasServerOnlyHook`)?.value;
|
|
172
172
|
assert(val === true || val === false);
|
|
173
173
|
return val;
|
|
174
174
|
}
|
|
@@ -261,6 +261,7 @@ async function loadProdBuildEntry(outDir) {
|
|
|
261
261
|
// https://github.com/vikejs/vike/blob/8c350e8105a626469e87594d983090919e82099b/packages/vike/node/vite/plugins/pluginBuild/pluginProdBuildEntry.ts#L47
|
|
262
262
|
async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
|
|
263
263
|
debug('setGlobalContext_prodBuildEntry()');
|
|
264
|
+
assert(!isNonRunnableDev());
|
|
264
265
|
assertProdBuildEntry(prodBuildEntry);
|
|
265
266
|
globalObject.prodBuildEntry = prodBuildEntry;
|
|
266
267
|
globalObject.prodBuildEntryPrevious = prodBuildEntry;
|
|
@@ -359,13 +360,14 @@ async function updateUserFiles() {
|
|
|
359
360
|
}
|
|
360
361
|
else {
|
|
361
362
|
try {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
// We don't directly use import() because:
|
|
364
|
+
// - Avoid Cloudflare Workers (without @cloudflare/vite-plugin) to try to bundle `import('virtual:id')`.
|
|
365
|
+
// - Using import() seems to lead to a Vite HMR bug:
|
|
366
|
+
// ```js
|
|
367
|
+
// assert(false)
|
|
368
|
+
// // This line breaks the HMR of regular (runnable) apps, even though (as per the assert() above) it's never run. It seems to be a Vite bug: handleHotUpdate() receives an empty `modules` list.
|
|
369
|
+
// import('virtual:vike:global-entry:server')
|
|
370
|
+
// ```
|
|
369
371
|
virtualFileExportsGlobalEntry = await __VIKE__DYNAMIC_IMPORT('virtual:vike:global-entry:server');
|
|
370
372
|
}
|
|
371
373
|
catch (err_) {
|
|
@@ -563,7 +565,7 @@ function isProdOptional() {
|
|
|
563
565
|
// getGlobalContextAsync(isProduction)
|
|
564
566
|
const no4 = globalObject.isProductionAccordingToUser === false;
|
|
565
567
|
// @cloudflare/vite-plugin
|
|
566
|
-
const no5 = isNonRunnableDev()
|
|
568
|
+
const no5 = isNonRunnableDev();
|
|
567
569
|
const no = no1 || no2 || no3 || no4 || no5;
|
|
568
570
|
const debug = { yes1, yes2, yes3, yes4, yes5, yes6, no1, no2, no3, no4, no5 };
|
|
569
571
|
assert(typeof yes === 'boolean', debug);
|
|
@@ -6,7 +6,7 @@ export { getVikeConfig } from './shared/resolveVikeConfigInternal.js';
|
|
|
6
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
7
|
import { getClientEntrySrcDev } from './shared/getClientEntrySrcDev.js';
|
|
8
8
|
import { setGetClientEntrySrcDev } from '../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
9
|
-
import { assertUsage } from './utils.js';
|
|
9
|
+
import { assertIsNotProductionRuntime, assertUsage } from './utils.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { pluginPreview } from './plugins/pluginPreview.js';
|
|
12
12
|
import { pluginDev } from './plugins/pluginDev.js';
|
|
@@ -16,22 +16,24 @@ import { pluginExtractExportNames } from './plugins/pluginExtractExportNames.js'
|
|
|
16
16
|
import { pluginSetGlobalContext } from './plugins/pluginSetGlobalContext.js';
|
|
17
17
|
import { pluginCommon } from './plugins/pluginCommon.js';
|
|
18
18
|
import { pluginBaseUrls } from './plugins/pluginBaseUrls.js';
|
|
19
|
-
import {
|
|
19
|
+
import { pluginReplaceConstantsEnvVars } from './plugins/pluginReplaceConstantsEnvVars.js';
|
|
20
20
|
import { pluginFileEnv } from './plugins/pluginFileEnv.js';
|
|
21
21
|
import { pluginWorkaroundCssModuleHmr } from './plugins/pluginWorkaroundCssModuleHmr.js';
|
|
22
22
|
import { pluginWorkaroundVite6HmrRegression } from './plugins/pluginWorkaroundVite6HmrRegression.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { pluginBuildApp } from './plugins/
|
|
27
|
-
import { pluginDistPackageJsonFile } from './plugins/
|
|
28
|
-
import { pluginSuppressRollupWarning } from './plugins/
|
|
29
|
-
import { pluginDistFileNames } from './plugins/
|
|
30
|
-
import { pluginProdBuildEntry } from './plugins/
|
|
31
|
-
import { pluginBuildConfig } from './plugins/
|
|
32
|
-
import { pluginModuleBanner } from './plugins/
|
|
23
|
+
import { pluginReplaceConstantsPageContext } from './plugins/pluginReplaceConstantsPageContext.js';
|
|
24
|
+
import { pluginReplaceConstantsGlobalThis } from './plugins/pluginReplaceConstantsGlobalThis.js';
|
|
25
|
+
import { pluginViteRPC } from './plugins/non-runnable-dev/pluginViteRPC.js';
|
|
26
|
+
import { pluginBuildApp } from './plugins/build/pluginBuildApp.js';
|
|
27
|
+
import { pluginDistPackageJsonFile } from './plugins/build/pluginDistPackageJsonFile.js';
|
|
28
|
+
import { pluginSuppressRollupWarning } from './plugins/build/pluginSuppressRollupWarning.js';
|
|
29
|
+
import { pluginDistFileNames } from './plugins/build/pluginDistFileNames.js';
|
|
30
|
+
import { pluginProdBuildEntry } from './plugins/build/pluginProdBuildEntry.js';
|
|
31
|
+
import { pluginBuildConfig } from './plugins/build/pluginBuildConfig.js';
|
|
32
|
+
import { pluginModuleBanner } from './plugins/build/pluginModuleBanner.js';
|
|
33
|
+
import { pluginReplaceConstantsNonRunnableDev } from './plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js';
|
|
33
34
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
34
35
|
setGetClientEntrySrcDev(getClientEntrySrcDev);
|
|
36
|
+
assertIsNotProductionRuntime();
|
|
35
37
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
36
38
|
function plugin(vikeVitePluginOptions = {}) {
|
|
37
39
|
const plugins = [
|
|
@@ -44,13 +46,13 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
44
46
|
...pluginExtractExportNames(),
|
|
45
47
|
...pluginSetGlobalContext(),
|
|
46
48
|
...pluginBaseUrls(),
|
|
47
|
-
...
|
|
49
|
+
...pluginReplaceConstantsEnvVars(),
|
|
48
50
|
...pluginFileEnv(),
|
|
49
51
|
...pluginWorkaroundCssModuleHmr(),
|
|
50
52
|
...pluginWorkaroundVite6HmrRegression(),
|
|
51
|
-
...
|
|
52
|
-
...
|
|
53
|
-
...
|
|
53
|
+
...pluginReplaceConstantsPageContext(),
|
|
54
|
+
...pluginReplaceConstantsGlobalThis(),
|
|
55
|
+
...pluginNonRunnabeDev(),
|
|
54
56
|
];
|
|
55
57
|
Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
|
|
56
58
|
return plugins;
|
|
@@ -66,6 +68,9 @@ function pluginBuild() {
|
|
|
66
68
|
...pluginModuleBanner(),
|
|
67
69
|
];
|
|
68
70
|
}
|
|
71
|
+
function pluginNonRunnabeDev() {
|
|
72
|
+
return [...pluginViteRPC(), ...pluginReplaceConstantsNonRunnableDev()];
|
|
73
|
+
}
|
|
69
74
|
// Error upon wrong usage
|
|
70
75
|
Object.defineProperty(plugin, 'apply', {
|
|
71
76
|
enumerable: true,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { pluginReplaceConstantsNonRunnableDev };
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
|
+
declare global {
|
|
4
|
+
var __VIKE__IS_NON_RUNNABLE_DEV: undefined | true;
|
|
5
|
+
var __VIKE__DYNAMIC_IMPORT: (module: `virtual:${string}`) => Promise<Record<string, unknown>>;
|
|
6
|
+
}
|
|
7
|
+
declare function pluginReplaceConstantsNonRunnableDev(): Plugin[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export { pluginReplaceConstantsNonRunnableDev };
|
|
2
|
+
import { isRunnableDevEnvironment, isDevCheck } from '../../utils.js';
|
|
3
|
+
import { getMagicString } from '../../shared/getMagicString.js';
|
|
4
|
+
// - We cannot use [`define`](https://vite.dev/config/shared-options.html#define) because we don't have access to `this.environment` and therefore we cannot call `isRunnableDevEnvironment(this.environment)` inside a configEnvironment() hook.
|
|
5
|
+
// - We cannot use [`filter.id`](https://rolldown.rs/plugins/hook-filters) because Vite's optimizeDeps bundles packages (e.g. `vike` or `telefunc`) into node_modules/.vite/deps_ssr/chunk-WBC5FHD7.js
|
|
6
|
+
const IS_NON_RUNNABLE_DEV = 'globalThis.__VIKE__IS_NON_RUNNABLE_DEV';
|
|
7
|
+
const DYNAMIC_IMPORT = '__VIKE__DYNAMIC_IMPORT';
|
|
8
|
+
function pluginReplaceConstantsNonRunnableDev() {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
name: 'vike:pluginReplaceConstantsNonRunnableDev:IS_NON_RUNNABLE_DEV',
|
|
12
|
+
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
13
|
+
transform: {
|
|
14
|
+
filter: {
|
|
15
|
+
code: {
|
|
16
|
+
include: IS_NON_RUNNABLE_DEV,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
handler(code, id) {
|
|
20
|
+
if (isRunnableDevEnvironment(this.environment))
|
|
21
|
+
return;
|
|
22
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
23
|
+
magicString.replaceAll(IS_NON_RUNNABLE_DEV, JSON.stringify(true));
|
|
24
|
+
return getMagicStringResult();
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'vike:pluginReplaceConstantsNonRunnableDev:DYNAMIC_IMPORT',
|
|
30
|
+
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
31
|
+
transform: {
|
|
32
|
+
filter: {
|
|
33
|
+
code: {
|
|
34
|
+
include: DYNAMIC_IMPORT,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
handler(code, id) {
|
|
38
|
+
if (isRunnableDevEnvironment(this.environment))
|
|
39
|
+
return;
|
|
40
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
41
|
+
magicString.replaceAll(DYNAMIC_IMPORT, 'import');
|
|
42
|
+
return getMagicStringResult();
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
package/dist/esm/node/vite/plugins/{pluginNonRunnableDev.d.ts → non-runnable-dev/pluginViteRPC.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginViteRPC };
|
|
2
2
|
import type { Plugin, ViteDevServer } from 'vite';
|
|
3
|
-
import type { ClientDependency } from '
|
|
3
|
+
import type { ClientDependency } from '../../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
4
4
|
export type ViteRPC = ReturnType<typeof getViteRpcFunctions>;
|
|
5
5
|
declare function getViteRpcFunctions(viteDevServer: ViteDevServer): {
|
|
6
6
|
transformIndexHtmlRPC(html: string): Promise<string>;
|
|
@@ -19,8 +19,4 @@ declare function getViteRpcFunctions(viteDevServer: ViteDevServer): {
|
|
|
19
19
|
};
|
|
20
20
|
}>;
|
|
21
21
|
};
|
|
22
|
-
declare
|
|
23
|
-
var __VIKE__DYNAMIC_IMPORT: (module: string) => Promise<Record<string, unknown>>;
|
|
24
|
-
var __VIKE__IS_NON_RUNNABLE_DEV: undefined | boolean;
|
|
25
|
-
}
|
|
26
|
-
declare function pluginNonRunnableDev(): Plugin[];
|
|
22
|
+
declare function pluginViteRPC(): Plugin[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { pluginViteRPC };
|
|
2
|
+
import { createViteRPC, isDevCheck } from '../../utils.js';
|
|
3
|
+
import { retrievePageAssetsDev } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
4
|
+
import { getViteConfigRuntime } from '../../shared/getViteConfigRuntime.js';
|
|
5
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
6
|
+
return {
|
|
7
|
+
async transformIndexHtmlRPC(html) {
|
|
8
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
9
|
+
},
|
|
10
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
11
|
+
return await retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries);
|
|
12
|
+
},
|
|
13
|
+
async getViteConfigRuntimeRPC() {
|
|
14
|
+
return getViteConfigRuntime(viteDevServer.config);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function pluginViteRPC() {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
name: 'vike:pluginViteRPC:1',
|
|
22
|
+
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
23
|
+
configureServer: {
|
|
24
|
+
handler(viteDevServer) {
|
|
25
|
+
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { pluginCommon };
|
|
2
2
|
import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isObject, isVitest } from '../utils.js';
|
|
3
|
-
import { assertRollupInput } from './
|
|
3
|
+
import { assertRollupInput } from './build/pluginBuildConfig.js';
|
|
4
4
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
|
|
@@ -129,9 +129,6 @@ function assertVikeCliOrApi(config) {
|
|
|
129
129
|
return;
|
|
130
130
|
if (isViteCliCall()) {
|
|
131
131
|
assert(!isVitest());
|
|
132
|
-
assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
133
|
-
onlyOnce: true,
|
|
134
|
-
});
|
|
135
132
|
return;
|
|
136
133
|
}
|
|
137
134
|
if (isVitest()) {
|
|
@@ -144,9 +141,6 @@ function assertVikeCliOrApi(config) {
|
|
|
144
141
|
});
|
|
145
142
|
return;
|
|
146
143
|
}
|
|
147
|
-
assertWarning(false, `Vite's JavaScript API is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
148
|
-
onlyOnce: true,
|
|
149
|
-
});
|
|
150
144
|
}
|
|
151
145
|
// TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
|
|
152
146
|
function temp_supportOldInterface(config) {
|
|
@@ -2,7 +2,7 @@ export { determineOptimizeDeps };
|
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
3
|
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, } from '../../utils.js';
|
|
4
4
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
|
-
import { analyzeClientEntries } from '../
|
|
5
|
+
import { analyzeClientEntries } from '../build/pluginBuildConfig.js';
|
|
6
6
|
import { virtualFileIdGlobalEntryClientCR, virtualFileIdGlobalEntryClientSR } from '../../../shared/virtualFileId.js';
|
|
7
7
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
8
8
|
import { getConfigValueSourcesRelevant } from '../pluginVirtualFiles/getConfigValueSourcesRelevant.js';
|
|
@@ -12,7 +12,7 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
|
12
12
|
import { isAsset } from '../shared/isAsset.js';
|
|
13
13
|
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
14
14
|
import pc from '@brillout/picocolors';
|
|
15
|
-
import { handleAssetsManifest_isFixEnabled } from './
|
|
15
|
+
import { handleAssetsManifest_isFixEnabled } from './build/handleAssetsManifest.js';
|
|
16
16
|
import { getVikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
|
|
17
17
|
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
18
18
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
export { pluginReplaceConstantsEnvVars };
|
|
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
|
+
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
9
|
+
const PUBLIC_ENV_ALLOWLIST = [
|
|
10
|
+
// https://github.com/vikejs/vike/issues/1724
|
|
11
|
+
'STORYBOOK',
|
|
12
|
+
];
|
|
13
|
+
// TO-DO/eventually:
|
|
14
|
+
// - Make import.meta.env work inside +config.js
|
|
15
|
+
// - 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
|
|
16
|
+
// - 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`.)
|
|
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 pluginReplaceConstantsEnvVars() {
|
|
35
|
+
let envVarsAll;
|
|
36
|
+
let envPrefix;
|
|
37
|
+
let config;
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
name: 'vike:pluginReplaceConstantsEnvVars',
|
|
41
|
+
enforce: 'post',
|
|
42
|
+
configResolved: {
|
|
43
|
+
handler(config_) {
|
|
44
|
+
config = config_;
|
|
45
|
+
envVarsAll = loadEnv(config.mode, config.envDir || config.root, '');
|
|
46
|
+
envPrefix = getEnvPrefix(config);
|
|
47
|
+
config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
transform: {
|
|
51
|
+
filter: filterRolldown,
|
|
52
|
+
handler(code, id, options) {
|
|
53
|
+
id = normalizeId(id);
|
|
54
|
+
assertPosixPath(id);
|
|
55
|
+
assertPosixPath(config.root);
|
|
56
|
+
if (!id.startsWith(config.root))
|
|
57
|
+
return; // skip linked dependencies
|
|
58
|
+
assert(filterFunction(id, code));
|
|
59
|
+
const isBuild = config.command === 'build';
|
|
60
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
61
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
62
|
+
// Get regex operations
|
|
63
|
+
const replacements = Object.entries(envVarsAll)
|
|
64
|
+
// Skip env vars that start with [`config.envPrefix`](https://vite.dev/config/shared-options.html#envprefix) => they are already handled by Vite
|
|
65
|
+
.filter(([envName]) => !envPrefix.some((prefix) => envName.startsWith(prefix)))
|
|
66
|
+
.map(([envName, envVal]) => {
|
|
67
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
68
|
+
const envStatementRegExpStr = escapeRegex(envStatement) + '\\b';
|
|
69
|
+
// Show error (warning in dev) if client code contains a private environment variable (one that doesn't start with PUBLIC_ENV__ and that isn't included in `PUBLIC_ENV_ALLOWLIST`).
|
|
70
|
+
if (isClientSide) {
|
|
71
|
+
const skip = assertNoClientSideLeak({
|
|
72
|
+
envName,
|
|
73
|
+
envStatement,
|
|
74
|
+
envStatementRegExpStr,
|
|
75
|
+
code,
|
|
76
|
+
id,
|
|
77
|
+
config,
|
|
78
|
+
isBuild,
|
|
79
|
+
});
|
|
80
|
+
if (skip)
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
84
|
+
})
|
|
85
|
+
.filter(isNotNullish);
|
|
86
|
+
// Apply regex operations
|
|
87
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
88
|
+
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
89
|
+
});
|
|
90
|
+
return getMagicStringResult();
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
function getEnvPrefix(config) {
|
|
97
|
+
const { envPrefix } = config;
|
|
98
|
+
if (!envPrefix)
|
|
99
|
+
return [];
|
|
100
|
+
if (!isArray(envPrefix))
|
|
101
|
+
return [envPrefix];
|
|
102
|
+
return envPrefix;
|
|
103
|
+
}
|
|
104
|
+
function assertNoClientSideLeak({ envName, envStatement, envStatementRegExpStr, code, id, config, isBuild, }) {
|
|
105
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
106
|
+
// ✅ All good
|
|
107
|
+
if (!isPrivate)
|
|
108
|
+
return;
|
|
109
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
110
|
+
return true;
|
|
111
|
+
// ❌ Security leak!
|
|
112
|
+
// - Warning in dev
|
|
113
|
+
// - assertUsage() and abort when building for production
|
|
114
|
+
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
115
|
+
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
116
|
+
const envNameFixed = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
117
|
+
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 ${envNameFixed}, see https://vike.dev/env`;
|
|
118
|
+
if (isBuild) {
|
|
119
|
+
assertUsage(false, errMsg);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
123
|
+
// - Although only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
124
|
+
assertWarning(false, errMsg, { onlyOnce: true });
|
|
125
|
+
}
|
|
126
|
+
assert(!isBuild); // we should abort if building for production
|
|
127
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { pluginReplaceConstantsGlobalThis };
|
|
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
|
+
* Whether a debug flag is enabled (either the global flag `DEBUG=vike` or a specific flag `DEBUG=vike:some-flag`).
|
|
10
|
+
*
|
|
11
|
+
* WARNING: must be used ONLY on the client-side. (The value is always `undefined` on the server-side.)
|
|
12
|
+
*
|
|
13
|
+
* In isomorhpic code, use `globalThis.__VIKE__IS_CLIENT` to make sure it's only used on the client-side.
|
|
14
|
+
*/
|
|
15
|
+
var __VIKE__IS_DEBUG: boolean | undefined;
|
|
16
|
+
}
|
|
17
|
+
declare function pluginReplaceConstantsGlobalThis(): Plugin[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import { assert } from '../utils.js';
|
|
1
|
+
export { pluginReplaceConstantsGlobalThis };
|
|
2
|
+
import { assert, isDebug } from '../utils.js';
|
|
3
3
|
// === Explanation: globalThis.__VIKE__IS_DEV
|
|
4
4
|
// If client-side => always noExternal => globalThis.__VIKE__IS_DEV is set by the `define` config below.
|
|
5
5
|
// If server-side:
|
|
@@ -13,10 +13,10 @@ import { assert } from '../utils.js';
|
|
|
13
13
|
// If client-side => always noExternal => globalThis.__VIKE__IS_CLIENT is set to `true` by the `define` config below.
|
|
14
14
|
// If server-side => globalThis.__VIKE__IS_CLIENT is either `false` or `undefined` (the value `undefined` is to be interpreted as `false`).
|
|
15
15
|
globalThis.__VIKE__IS_CLIENT = false;
|
|
16
|
-
function
|
|
16
|
+
function pluginReplaceConstantsGlobalThis() {
|
|
17
17
|
return [
|
|
18
18
|
{
|
|
19
|
-
name: 'vike:
|
|
19
|
+
name: 'vike:pluginReplaceConstantsGlobalThis',
|
|
20
20
|
config: {
|
|
21
21
|
handler(config) {
|
|
22
22
|
const isDev = config._isDev;
|
|
@@ -33,9 +33,16 @@ function pluginReplaceGlobalThisConstants() {
|
|
|
33
33
|
handler(name, config) {
|
|
34
34
|
const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');
|
|
35
35
|
const isClientSide = consumer === 'client';
|
|
36
|
+
const defineIsDebug = !isClientSide
|
|
37
|
+
? {}
|
|
38
|
+
: {
|
|
39
|
+
// We purposely only define it on the client-side, because we cannot know the value in server-side ssr.external production.
|
|
40
|
+
'globalThis.__VIKE__IS_DEBUG': JSON.stringify(isDebug()),
|
|
41
|
+
};
|
|
36
42
|
return {
|
|
37
43
|
define: {
|
|
38
44
|
'globalThis.__VIKE__IS_CLIENT': JSON.stringify(isClientSide),
|
|
45
|
+
...defineIsDebug,
|
|
39
46
|
},
|
|
40
47
|
};
|
|
41
48
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginReplaceConstantsPageContext };
|
|
2
2
|
import { assert, assertPosixPath } from '../utils.js';
|
|
3
3
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
4
4
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
@@ -9,6 +9,8 @@ const constantsIsClientSide = [
|
|
|
9
9
|
'globalContext.isClientSide',
|
|
10
10
|
'pageContext.globalContext.isClientSide',
|
|
11
11
|
];
|
|
12
|
+
// - See https://vike.dev/pageContext#narrowing-down
|
|
13
|
+
// - We cannot use [`define`](https://vite.dev/config/shared-options.html#define) because of https://github.com/rolldown/rolldown/issues/4300
|
|
12
14
|
const skipNodeModules = '/node_modules/';
|
|
13
15
|
const skipIrrelevant = 'Context.isClientSide';
|
|
14
16
|
assert(constantsIsClientSide.every((constant) => constant.endsWith(skipIrrelevant)));
|
|
@@ -27,11 +29,11 @@ const filterFunction = (id, code) => {
|
|
|
27
29
|
return false;
|
|
28
30
|
return true;
|
|
29
31
|
};
|
|
30
|
-
function
|
|
32
|
+
function pluginReplaceConstantsPageContext() {
|
|
31
33
|
let config;
|
|
32
34
|
return [
|
|
33
35
|
{
|
|
34
|
-
name: 'vike:
|
|
36
|
+
name: 'vike:pluginReplaceConstantsPageContext',
|
|
35
37
|
enforce: 'post',
|
|
36
38
|
apply: 'build',
|
|
37
39
|
configResolved: {
|
|
@@ -61,8 +63,6 @@ function pluginReplaceIsClientSide() {
|
|
|
61
63
|
const regExp = getConstantRegExp(constantsIsClientSide);
|
|
62
64
|
magicString.replaceAll(regExp, JSON.stringify(replacement));
|
|
63
65
|
}
|
|
64
|
-
if (!magicString.hasChanged())
|
|
65
|
-
return null;
|
|
66
66
|
return getMagicStringResult();
|
|
67
67
|
},
|
|
68
68
|
},
|
|
@@ -5,7 +5,7 @@ import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js
|
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
6
6
|
import { debug } from './debug.js';
|
|
7
7
|
import { serializeConfigValues } from '../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
8
|
-
import { handleAssetsManifest_isFixEnabled } from '../
|
|
8
|
+
import { handleAssetsManifest_isFixEnabled } from '../build/handleAssetsManifest.js';
|
|
9
9
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
10
10
|
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
11
11
|
async function generateVirtualFilePageEntry(id, isDev) {
|
|
@@ -4,9 +4,8 @@ import MagicString from 'magic-string';
|
|
|
4
4
|
function getMagicString(code, id) {
|
|
5
5
|
const magicString = new MagicString(code);
|
|
6
6
|
const getMagicStringResult = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
7
|
+
if (!magicString.hasChanged())
|
|
8
|
+
return undefined;
|
|
10
9
|
return {
|
|
11
10
|
code: magicString.toString(),
|
|
12
11
|
map: magicString.generateMap({ hires: true, source: id }),
|
|
@@ -96,11 +96,11 @@ const configDefinitionsBuiltIn = {
|
|
|
96
96
|
meta: {
|
|
97
97
|
env: { config: true },
|
|
98
98
|
},
|
|
99
|
-
|
|
99
|
+
hasServerOnlyHook: {
|
|
100
100
|
env: { client: true },
|
|
101
101
|
eager: true,
|
|
102
102
|
_computed: (pageConfig) => {
|
|
103
|
-
const sources = ['data', 'onBeforeRender', 'onCreatePageContext']
|
|
103
|
+
const sources = ['data', 'onBeforeRender', 'onCreatePageContext', 'guard']
|
|
104
104
|
.map((hookName) => getConfigValueSourcesRelevant(hookName, {
|
|
105
105
|
isForClientSide: false,
|
|
106
106
|
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
@@ -26,7 +26,11 @@ function redirect(url, statusCode) {
|
|
|
26
26
|
statusCode = 302;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
if (
|
|
29
|
+
if (
|
|
30
|
+
// Tree-shaking to save client-side KBs
|
|
31
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
32
|
+
globalThis.__VIKE__IS_DEV ||
|
|
33
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
30
34
|
assertStatusCode(statusCode, [301, 302], 'redirect');
|
|
31
35
|
}
|
|
32
36
|
args.push(String(statusCode));
|
|
@@ -69,7 +73,11 @@ function render_(urlOrStatusCode, abortReason, abortCall, abortCaller, pageConte
|
|
|
69
73
|
return AbortRender(pageContextAbort);
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
72
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
// Tree-shaking to save client-side KBs
|
|
78
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
79
|
+
globalThis.__VIKE__IS_DEV ||
|
|
80
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
73
81
|
assertStatusCode(urlOrStatusCode, [401, 403, 404, 410, 429, 500, 503], 'render');
|
|
74
82
|
}
|
|
75
83
|
const abortStatusCode = urlOrStatusCode;
|
|
@@ -136,8 +144,8 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
136
144
|
});
|
|
137
145
|
}
|
|
138
146
|
function assertStatusCode(statusCode, expected, caller) {
|
|
139
|
-
assert(!globalThis.__VIKE__IS_CLIENT || globalThis.__VIKE__IS_DEV); //
|
|
140
|
-
// double check vike:
|
|
147
|
+
assert(!globalThis.__VIKE__IS_CLIENT || globalThis.__VIKE__IS_DEV || globalThis.__VIKE__IS_DEBUG); // assert tree-shaking
|
|
148
|
+
// double check vike:pluginReplaceConstantsGlobalThis
|
|
141
149
|
if (globalThis.__VIKE__IS_CLIENT) {
|
|
142
150
|
assert(isBrowser());
|
|
143
151
|
assert(typeof globalThis.__VIKE__IS_DEV === 'boolean');
|
|
@@ -5,17 +5,21 @@ import { isBrowser } from '../../utils/isBrowser.js';
|
|
|
5
5
|
if (isBrowser()) {
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
|
-
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
8
|
+
import { assert, assertUsage, isPlainObject, objectAssign, debug } from './utils.js';
|
|
9
9
|
import { resolvePrecedence } from './resolvePrecedence.js';
|
|
10
10
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
11
11
|
import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
12
12
|
import { execHookOnBeforeRoute } from './execHookOnBeforeRoute.js';
|
|
13
|
-
import { debug } from './debug.js';
|
|
14
13
|
import pc from '@brillout/picocolors';
|
|
15
14
|
// TO-DO/next-major-release: make it sync
|
|
16
15
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
17
|
-
debug('Pages routes:', pageContext._globalContext._pageRoutes);
|
|
18
16
|
const pageContextFromRoute = {};
|
|
17
|
+
if (
|
|
18
|
+
// Tree-shaking to save client-side KBs
|
|
19
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
20
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
21
|
+
debug('vike:routing', 'Pages routes:', pageContext._globalContext._pageRoutes);
|
|
22
|
+
}
|
|
19
23
|
// onBeforeRoute()
|
|
20
24
|
if (!skipOnBeforeRouteHook) {
|
|
21
25
|
const pageContextFromOnBeforeRouteHook = await execHookOnBeforeRoute(pageContext);
|
|
@@ -80,7 +84,12 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
80
84
|
}));
|
|
81
85
|
resolvePrecedence(routeMatches);
|
|
82
86
|
const winner = routeMatches[0] ?? null;
|
|
83
|
-
|
|
87
|
+
if (
|
|
88
|
+
// Tree-shaking to save client-side KBs
|
|
89
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
90
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
91
|
+
debug('vike:routing', `Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches);
|
|
92
|
+
}
|
|
84
93
|
// For vite-plugin-vercel https://github.com/magne4000/vite-plugin-vercel/blob/main/packages/vike-integration/vike.ts#L173
|
|
85
94
|
objectAssign(pageContextFromRoute, { _routeMatch: winner });
|
|
86
95
|
if (!winner) {
|
|
@@ -50,7 +50,7 @@ type HookName = HookNamePage | HookNameGlobal;
|
|
|
50
50
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
|
|
51
51
|
type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext';
|
|
52
52
|
type HookNameOldDesign = 'render' | 'prerender' | 'onBeforePrerender';
|
|
53
|
-
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | '
|
|
53
|
+
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'hasServerOnlyHook' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
54
54
|
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
|
|
55
55
|
type Config = ConfigBuiltIn & Vike.Config;
|
|
56
56
|
/** @deprecated This type is deprecated, see https://vike.dev/data */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.240-commit-bac5dee";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.240-commit-bac5dee';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
export { debug };
|
|
1
2
|
export { createDebugger };
|
|
3
|
+
export { isDebug };
|
|
2
4
|
export { isDebugActivated };
|
|
3
|
-
|
|
4
|
-
declare const flags: readonly ["vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
5
|
+
declare const flags: ["vike", "vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
5
6
|
type Flag = (typeof flags)[number];
|
|
6
|
-
type Debug = ReturnType<typeof createDebugger>;
|
|
7
7
|
type Options = {
|
|
8
8
|
serialization?: {
|
|
9
9
|
emptyArray?: string;
|
|
@@ -13,4 +13,6 @@ declare function createDebugger(flag: Flag, optionsGlobal?: Options): ((...msgs:
|
|
|
13
13
|
options: (optionsLocal: Options) => (...msgs: unknown[]) => void;
|
|
14
14
|
isActivated: boolean;
|
|
15
15
|
};
|
|
16
|
+
declare function debug(flag: Flag, ...msgs: unknown[]): void;
|
|
16
17
|
declare function isDebugActivated(flag: Flag): boolean;
|
|
18
|
+
declare function isDebug(): boolean;
|
package/dist/esm/utils/debug.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
export { debug };
|
|
1
2
|
export { createDebugger };
|
|
3
|
+
export { isDebug };
|
|
2
4
|
export { isDebugActivated };
|
|
3
5
|
import { isCallable } from './isCallable.js';
|
|
4
6
|
import { objectAssign } from './objectAssign.js';
|
|
5
7
|
import { assert, assertUsage } from './assert.js';
|
|
6
|
-
import { checkType } from './checkType.js';
|
|
7
8
|
import { getTerminalWidth } from './getTerminalWidth.js';
|
|
8
9
|
import pc from '@brillout/picocolors';
|
|
9
10
|
import { isArray } from './isArray.js';
|
|
10
11
|
import { isObject } from './isObject.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Assert tree-shaking (ensure this module is loaded on the client-side only if debug is enabled).
|
|
13
|
+
assert(!globalThis.__VIKE__IS_CLIENT ||
|
|
14
|
+
globalThis.__VIKE__IS_DEBUG ||
|
|
15
|
+
// Vite doesn't do tree-shaking in dev (maybe it will with Rolldown?)
|
|
16
|
+
import.meta.env.DEV);
|
|
15
17
|
const flags = [
|
|
18
|
+
'vike',
|
|
16
19
|
'vike:crawl',
|
|
17
20
|
'vike:error',
|
|
18
21
|
'vike:esbuild-resolve',
|
|
@@ -25,7 +28,7 @@ const flags = [
|
|
|
25
28
|
'vike:outDir',
|
|
26
29
|
'vike:pageFiles',
|
|
27
30
|
'vike:pointer-imports',
|
|
28
|
-
'vike:
|
|
31
|
+
'vike:requireResolve',
|
|
29
32
|
'vike:routing',
|
|
30
33
|
'vike:setup',
|
|
31
34
|
'vike:stream',
|
|
@@ -40,7 +43,6 @@ if (isDebug())
|
|
|
40
43
|
Error.stackTraceLimit = Infinity;
|
|
41
44
|
assertFlagsActivated();
|
|
42
45
|
function createDebugger(flag, optionsGlobal) {
|
|
43
|
-
checkType(flag);
|
|
44
46
|
assert(flags.includes(flag));
|
|
45
47
|
const debugWithOptions = (optionsLocal) => {
|
|
46
48
|
return (...msgs) => {
|
|
@@ -52,6 +54,9 @@ function createDebugger(flag, optionsGlobal) {
|
|
|
52
54
|
objectAssign(debug, { options: debugWithOptions, isActivated: isDebugActivated(flag) });
|
|
53
55
|
return debug;
|
|
54
56
|
}
|
|
57
|
+
function debug(flag, ...msgs) {
|
|
58
|
+
return debug_(flag, {}, ...msgs);
|
|
59
|
+
}
|
|
55
60
|
function debug_(flag, options, ...msgs) {
|
|
56
61
|
if (!isDebugActivated(flag))
|
|
57
62
|
return;
|
|
@@ -80,7 +85,6 @@ function debug_(flag, options, ...msgs) {
|
|
|
80
85
|
});
|
|
81
86
|
}
|
|
82
87
|
function isDebugActivated(flag) {
|
|
83
|
-
checkType(flag);
|
|
84
88
|
assert(flags.includes(flag));
|
|
85
89
|
const { flagsActivated, all } = getFlagsActivated();
|
|
86
90
|
const isActivated = flagsActivated.includes(flag) || (all && !flagsSkipWildcard.includes(flag));
|
|
@@ -152,17 +156,30 @@ function assertFlagsActivated() {
|
|
|
152
156
|
assertUsage(flags.includes(flag), `Unknown DEBUG flag ${pc.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${pc.cyan(f)}`).join('\n')}`);
|
|
153
157
|
});
|
|
154
158
|
}
|
|
159
|
+
// TODO/now: refactor isAll
|
|
160
|
+
// TODO/now: refactor inline flagRegex
|
|
155
161
|
function getFlagsActivated() {
|
|
156
162
|
const flagsActivated = DEBUG.match(flagRegex) ?? [];
|
|
157
163
|
const all = DEBUG.includes('vike:*');
|
|
158
|
-
|
|
164
|
+
const isGlobal = /\bvike\b[^:]/.test(DEBUG);
|
|
165
|
+
return { flagsActivated, all, isGlobal };
|
|
159
166
|
}
|
|
160
167
|
function isDebug() {
|
|
161
|
-
const { flagsActivated, all } = getFlagsActivated();
|
|
162
|
-
return all || flagsActivated.length > 0;
|
|
168
|
+
const { flagsActivated, all, isGlobal } = getFlagsActivated();
|
|
169
|
+
return all || flagsActivated.length > 0 || isGlobal;
|
|
163
170
|
}
|
|
164
171
|
function getDEBUG() {
|
|
165
172
|
let DEBUG;
|
|
173
|
+
// ssr.noExternal
|
|
174
|
+
/* // Full implementation:
|
|
175
|
+
// - https://github.com/vikejs/vike/commit/7637564a98f43e23834bcae2f7ada8d941958a34
|
|
176
|
+
// - https://github.com/vikejs/vike/pull/2718
|
|
177
|
+
// - We don't implement this yet because it crashes @cloudflare/vite-plugin
|
|
178
|
+
if (import.meta.env) {
|
|
179
|
+
return import.meta.env.DEBUG
|
|
180
|
+
}
|
|
181
|
+
//*/
|
|
182
|
+
// ssr.external
|
|
166
183
|
// - `process` can be undefined in edge workers
|
|
167
184
|
// - We want bundlers to be able to statically replace `process.env.*`
|
|
168
185
|
try {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
2
|
import type { VikeGlobalInternal } from '../types/VikeGlobalInternal.js';
|
|
3
3
|
type ModuleId = `${string}.ts`;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Share information across module instances.
|
|
6
|
+
*
|
|
7
|
+
* @__NO_SIDE_EFFECTS__
|
|
8
|
+
*/
|
|
5
9
|
declare function getGlobalObject<T extends Record<string, unknown> = never>(moduleId: ModuleId, defaultValue: T): T;
|
|
6
10
|
declare global {
|
|
7
11
|
var _vike: VikeGlobalInternal;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Share information across module instances.
|
|
4
|
+
*
|
|
5
|
+
* @__NO_SIDE_EFFECTS__
|
|
6
|
+
*/
|
|
3
7
|
function getGlobalObject(moduleId, defaultValue) {
|
|
4
8
|
const globals = getGlobals();
|
|
5
9
|
const globalObject = (globals[moduleId] ?? (globals[moduleId] = defaultValue));
|
package/dist/esm/utils/isDev.js
CHANGED
|
@@ -5,8 +5,10 @@ import { assertUsage } from './assert.js';
|
|
|
5
5
|
function isDevCheck(configEnv) {
|
|
6
6
|
const { isPreview, command } = configEnv;
|
|
7
7
|
// Note that:
|
|
8
|
-
// - `assertVersion('Vite', version, '5.1.0')`
|
|
8
|
+
// - `assertVersion('Vite', version, '5.1.0')` isn't enough: https://github.com/vitejs/vite/pull/19355
|
|
9
9
|
// - We'll eventually be able to make this an assert() instead of assertUsage() once Vike requires a Vite version that supports this.meta.viteVersion
|
|
10
|
+
// - https://github.com/vitejs/vite/pull/20088
|
|
11
|
+
// - Released at 7.0.0: https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
|
|
10
12
|
assertUsage(typeof isPreview === 'boolean', 'You are using an old Vite version; make sure to use Vite 5.1.0 or above.');
|
|
11
13
|
return command === 'serve' && !isPreview;
|
|
12
14
|
}
|
|
@@ -3,8 +3,8 @@ import { assert } from './assert.js';
|
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
4
|
assertIsNotBrowser();
|
|
5
5
|
function isNonRunnableDev() {
|
|
6
|
-
if (
|
|
6
|
+
if (globalThis.__VIKE__IS_NON_RUNNABLE_DEV === undefined)
|
|
7
7
|
return false;
|
|
8
|
-
assert(__VIKE__IS_NON_RUNNABLE_DEV === true);
|
|
8
|
+
assert(globalThis.__VIKE__IS_NON_RUNNABLE_DEV === true);
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
@@ -17,7 +17,7 @@ const importMetaUrl = import.meta.url;
|
|
|
17
17
|
assertPosixPath(importMetaUrl);
|
|
18
18
|
assertIsNotBrowser();
|
|
19
19
|
assertIsNotProductionRuntime();
|
|
20
|
-
const debug = createDebugger('vike:
|
|
20
|
+
const debug = createDebugger('vike:requireResolve');
|
|
21
21
|
// - We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
22
22
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
23
23
|
// - Passing context to createRequire(context) isn't equivalent to passing it to the `paths` argument of require.resolve()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.240-commit-bac5dee",
|
|
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",
|
|
@@ -1,112 +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
|
-
if (!magicString.hasChanged())
|
|
106
|
-
return null;
|
|
107
|
-
return getMagicStringResult();
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
];
|
|
112
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export { pluginNonRunnableDev };
|
|
2
|
-
import { createViteRPC, assertIsNotProductionRuntime, isRunnableDevEnvironment, assert, isDevCheck } from '../utils.js';
|
|
3
|
-
import { retrievePageAssetsDev } from '../../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
4
|
-
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
5
|
-
import { getMagicString } from '../shared/getMagicString.js';
|
|
6
|
-
// TODO/now: move to vite/index.ts
|
|
7
|
-
assertIsNotProductionRuntime();
|
|
8
|
-
/* We cannot use [`filter.id`](https://rolldown.rs/plugins/hook-filters) because Vite's optimizeDeps bundles the package `vike` into node_modules/.vite/deps_ssr/chunk-WBC5FHD7.js
|
|
9
|
-
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js')
|
|
10
|
-
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js')
|
|
11
|
-
const filterRolldown = {
|
|
12
|
-
id: {
|
|
13
|
-
include: [distFileIsNonRunnableDev, distFileGlobalContext].map(
|
|
14
|
-
(filePath) => new RegExp(`^${escapeRegex(filePath)}($|${escapeRegex('?')}.*)`),
|
|
15
|
-
),
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
*/
|
|
19
|
-
const __VIKE__DYNAMIC_IMPORT = '__VIKE__DYNAMIC_IMPORT';
|
|
20
|
-
const __VIKE__IS_NON_RUNNABLE_DEV = '__VIKE__IS_NON_RUNNABLE_DEV';
|
|
21
|
-
function getViteRpcFunctions(viteDevServer) {
|
|
22
|
-
return {
|
|
23
|
-
async transformIndexHtmlRPC(html) {
|
|
24
|
-
return await viteDevServer.transformIndexHtml('/', html);
|
|
25
|
-
},
|
|
26
|
-
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
27
|
-
return await retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries);
|
|
28
|
-
},
|
|
29
|
-
async getViteConfigRuntimeRPC() {
|
|
30
|
-
return getViteConfigRuntime(viteDevServer.config);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function pluginNonRunnableDev() {
|
|
35
|
-
let config;
|
|
36
|
-
return [
|
|
37
|
-
{
|
|
38
|
-
name: 'vike:pluginNonRunnableDev:1',
|
|
39
|
-
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
40
|
-
configureServer: {
|
|
41
|
-
handler(viteDevServer) {
|
|
42
|
-
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
configResolved: {
|
|
46
|
-
handler(config_) {
|
|
47
|
-
config = config_;
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
transform: {
|
|
51
|
-
filter: {
|
|
52
|
-
code: {
|
|
53
|
-
include: __VIKE__IS_NON_RUNNABLE_DEV,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
handler(code, id) {
|
|
57
|
-
assert(config._isDev);
|
|
58
|
-
if (isRunnableDevEnvironment(this.environment))
|
|
59
|
-
return;
|
|
60
|
-
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
61
|
-
magicString.replaceAll(__VIKE__IS_NON_RUNNABLE_DEV, JSON.stringify(true));
|
|
62
|
-
return getMagicStringResult();
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'vike:pluginNonRunnableDev:2',
|
|
68
|
-
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
69
|
-
transform: {
|
|
70
|
-
filter: {
|
|
71
|
-
code: {
|
|
72
|
-
include: __VIKE__DYNAMIC_IMPORT,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
handler(code, id) {
|
|
76
|
-
assert(config._isDev);
|
|
77
|
-
if (isRunnableDevEnvironment(this.environment))
|
|
78
|
-
return;
|
|
79
|
-
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
80
|
-
magicString.replaceAll(__VIKE__DYNAMIC_IMPORT, 'import');
|
|
81
|
-
return getMagicStringResult();
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
];
|
|
86
|
-
}
|
|
@@ -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,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
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|