vike 0.4.249 → 0.4.250-commit-193dea3
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/bin.js +3 -0
- package/dist/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/client/runtime-client-routing/getPageContext.js +0 -2
- package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +136 -4
- package/dist/client/runtime-client-routing/history.d.ts +1 -1
- package/dist/client/runtime-client-routing/history.js +4 -11
- package/dist/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +601 -6
- package/dist/client/runtime-client-routing/utils.d.ts +0 -1
- package/dist/client/runtime-client-routing/utils.js +0 -1
- package/dist/client/runtime-server-routing/createPageContextClientSide.d.ts +2 -6
- package/dist/client/runtime-server-routing/createPageContextClientSide.js +1 -21
- package/dist/client/runtime-server-routing/entry.js +15 -1
- package/dist/client/shared/execHookOnRenderClient.d.ts +4 -1
- package/dist/node/vite/index.js +5 -2
- package/dist/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js +38 -13
- package/dist/node/vite/plugins/pluginAssertFileEnv.js +22 -13
- package/dist/node/vite/plugins/pluginExtractAssets.js +2 -0
- package/dist/node/vite/plugins/pluginExtractExportNames.js +2 -0
- package/dist/node/vite/plugins/pluginReplaceConstantsEnvVars.js +2 -0
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +3 -1
- package/dist/node/vite/plugins/pluginReplaceConstantsPageContext.js +2 -0
- package/dist/node/vite/plugins/pluginStaticReplace/applyStaticReplace.d.ts +126 -0
- package/dist/node/vite/plugins/pluginStaticReplace/applyStaticReplace.js +421 -0
- package/dist/node/vite/plugins/pluginStaticReplace.d.ts +4 -0
- package/dist/node/vite/plugins/pluginStaticReplace.js +88 -0
- package/dist/node/vite/plugins/pluginVirtualFiles.js +73 -113
- package/dist/node/vite/plugins/pluginViteConfigVikeExtensions.d.ts +2 -1
- package/dist/node/vite/plugins/pluginViteConfigVikeExtensions.js +1 -3
- package/dist/node/vite/shared/importString.d.ts +50 -0
- package/dist/node/vite/shared/importString.js +63 -0
- package/dist/node/vite/shared/loggerDev.d.ts +3 -3
- package/dist/node/vite/shared/loggerDev.js +3 -3
- package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +10 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles.d.ts → crawlPlusFilePaths.d.ts} +2 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles.js → crawlPlusFilePaths.js} +4 -4
- package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesAll.d.ts → getPlusFilesByLocationId.d.ts} +8 -6
- package/dist/node/vite/shared/resolveVikeConfigInternal/{getPlusFilesAll.js → getPlusFilesByLocationId.js} +47 -59
- package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +11 -18
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +66 -64
- package/dist/server/onLoad.js +2 -2
- package/dist/server/runtime/logErrorServer.d.ts +2 -2
- package/dist/server/runtime/logErrorServer.js +0 -2
- package/dist/server/runtime/loggerRuntime.d.ts +3 -2
- package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +4 -2
- package/dist/server/runtime/renderPageServer/createHttpResponse.js +16 -8
- package/dist/server/runtime/renderPageServer/createPageContextServerSide.d.ts +5 -2
- package/dist/server/runtime/renderPageServer/createPageContextServerSide.js +1 -0
- package/dist/server/runtime/renderPageServer/csp.js +2 -0
- package/dist/server/runtime/renderPageServer/execHookOnError.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.d.ts +4 -4
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.js +3 -4
- package/dist/server/runtime/renderPageServer/html/serializeContext.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/html/stream.js +12 -13
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/log404/index.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +3 -3
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.js +2 -2
- package/dist/server/runtime/renderPageServer.js +19 -19
- package/dist/shared-server-client/hooks/execHook.d.ts +5 -1
- package/dist/types/Config/ConfigResolved.d.ts +3 -2
- package/dist/types/Config.d.ts +38 -31
- package/dist/types/PageConfig.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.d.ts +5 -5
- package/dist/utils/assert.js +8 -8
- package/dist/utils/debug.d.ts +1 -1
- package/dist/utils/debug.js +1 -0
- package/package.json +9 -7
- package/node/cli/bin.js +0 -3
- /package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles → crawlPlusFilePaths}/ignorePatternsBuiltIn.d.ts +0 -0
- /package/dist/node/vite/shared/resolveVikeConfigInternal/{crawlPlusFiles → crawlPlusFilePaths}/ignorePatternsBuiltIn.js +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
|
+
export type PageContextCreatedClient_ServerRouting = Awaited<ReturnType<typeof createPageContextClientSide>>;
|
|
2
3
|
declare function createPageContextClientSide(): Promise<{
|
|
3
4
|
_isOriginalObject: true;
|
|
4
5
|
isPageContext: true;
|
|
@@ -59,9 +60,4 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
59
60
|
isBackwardNavigation: null;
|
|
60
61
|
isHistoryNavigation: null;
|
|
61
62
|
_hasPageContextFromServer: true;
|
|
62
|
-
} &
|
|
63
|
-
pageId: string;
|
|
64
|
-
routeParams: Record<string, string>;
|
|
65
|
-
} & import("../../shared-server-client/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & import("../../shared-server-client/getPageFiles.js").PageContextConfig & {
|
|
66
|
-
_pageFilesLoaded: import("../../shared-server-client/getPageFiles.js").PageFile[];
|
|
67
|
-
}>;
|
|
63
|
+
} & import("../../shared-server-client/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic>;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
|
-
import {
|
|
3
|
-
import { getPageContextSerializedInHtml } from '../shared/getJsonSerializedInHtml.js';
|
|
4
|
-
import { loadPageConfigsLazyClientSide, } from '../shared/loadPageConfigsLazyClientSide.js';
|
|
5
|
-
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
2
|
+
import { updateType, objectAssign } from './utils.js';
|
|
6
3
|
import { createPageContextObject, createPageContextShared } from '../../shared-server-client/createPageContextShared.js';
|
|
7
4
|
import { getGlobalContextClientInternal } from './getGlobalContextClientInternal.js';
|
|
8
|
-
import { preparePageContextForPublicUsageClient, } from './preparePageContextForPublicUsageClient.js';
|
|
9
|
-
import { execHook } from '../../shared-server-client/hooks/execHook.js';
|
|
10
|
-
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
11
5
|
async function createPageContextClientSide() {
|
|
12
6
|
const globalContext = await getGlobalContextClientInternal();
|
|
13
7
|
const pageContextCreated = createPageContextObject();
|
|
@@ -21,21 +15,7 @@ async function createPageContextClientSide() {
|
|
|
21
15
|
isHistoryNavigation: null,
|
|
22
16
|
_hasPageContextFromServer: true,
|
|
23
17
|
});
|
|
24
|
-
objectAssign(pageContextCreated, getPageContextSerializedInHtml());
|
|
25
18
|
// Sets pageContext.config to global configs
|
|
26
19
|
updateType(pageContextCreated, createPageContextShared(pageContextCreated, globalContext._globalConfigPublic));
|
|
27
|
-
// Sets pageContext.config to local configs (overrides the pageContext.config set above)
|
|
28
|
-
updateType(pageContextCreated, await loadPageConfigsLazyClientSideAndExecHook(pageContextCreated));
|
|
29
|
-
assertPristineUrl();
|
|
30
20
|
return pageContextCreated;
|
|
31
21
|
}
|
|
32
|
-
function assertPristineUrl() {
|
|
33
|
-
const urlCurrent = getCurrentUrl({ withoutHash: true });
|
|
34
|
-
assertUsage(urlFirst === urlCurrent, `The URL was manipulated before the hydration finished ('${urlFirst}' to '${urlCurrent}'). Ensure the hydration has finished before manipulating the URL. Consider using the onHydrationEnd() hook.`);
|
|
35
|
-
}
|
|
36
|
-
async function loadPageConfigsLazyClientSideAndExecHook(pageContext) {
|
|
37
|
-
const pageContextAddendum = await loadPageConfigsLazyClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._globalContext._pageConfigs, pageContext._globalContext._pageConfigGlobal);
|
|
38
|
-
objectAssign(pageContext, pageContextAddendum);
|
|
39
|
-
await execHook('onCreatePageContext', pageContext, preparePageContextForPublicUsageClient);
|
|
40
|
-
return pageContext;
|
|
41
|
-
}
|
|
@@ -2,13 +2,17 @@ import { assertServerRouting } from '../../utils/assertRoutingType.js';
|
|
|
2
2
|
assertServerRouting();
|
|
3
3
|
import { createPageContextClientSide } from './createPageContextClientSide.js';
|
|
4
4
|
import { execHookOnRenderClient } from '../shared/execHookOnRenderClient.js';
|
|
5
|
-
import { assertSingleInstance_onClientEntryServerRouting } from './utils.js';
|
|
5
|
+
import { assertSingleInstance_onClientEntryServerRouting, assertUsage, objectAssign } from './utils.js';
|
|
6
6
|
import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
7
7
|
import { execHook } from '../../shared-server-client/hooks/execHook.js';
|
|
8
8
|
import { preparePageContextForPublicUsageClient } from './preparePageContextForPublicUsageClient.js';
|
|
9
9
|
import { setVirtualFileExportsGlobalEntry } from '../shared/getGlobalContextClientInternalShared.js';
|
|
10
10
|
// @ts-expect-error
|
|
11
11
|
import * as virtualFileExportsGlobalEntry from 'virtual:vike:global-entry:client:server-routing';
|
|
12
|
+
import { loadPageConfigsLazyClientSide } from '../shared/loadPageConfigsLazyClientSide.js';
|
|
13
|
+
import { getPageContextSerializedInHtml } from '../shared/getJsonSerializedInHtml.js';
|
|
14
|
+
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
15
|
+
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
12
16
|
assertSingleInstance_onClientEntryServerRouting(import.meta.env.PROD);
|
|
13
17
|
setVirtualFileExportsGlobalEntry(virtualFileExportsGlobalEntry);
|
|
14
18
|
if (import.meta.env.DEV)
|
|
@@ -16,6 +20,16 @@ if (import.meta.env.DEV)
|
|
|
16
20
|
hydrate();
|
|
17
21
|
async function hydrate() {
|
|
18
22
|
const pageContext = await createPageContextClientSide();
|
|
23
|
+
objectAssign(pageContext, getPageContextSerializedInHtml());
|
|
24
|
+
// Sets pageContext.config using local configs — overrides the pageContext.config set using global configs at createPageContextClientSide()
|
|
25
|
+
const pageContextAddendum = await loadPageConfigsLazyClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._globalContext._pageConfigs, pageContext._globalContext._pageConfigGlobal);
|
|
26
|
+
objectAssign(pageContext, pageContextAddendum);
|
|
27
|
+
await execHook('onCreatePageContext', pageContext, preparePageContextForPublicUsageClient);
|
|
28
|
+
assertPristineUrl();
|
|
19
29
|
await execHookOnRenderClient(pageContext, preparePageContextForPublicUsageClient);
|
|
20
30
|
await execHook('onHydrationEnd', pageContext, preparePageContextForPublicUsageClient);
|
|
21
31
|
}
|
|
32
|
+
function assertPristineUrl() {
|
|
33
|
+
const urlCurrent = getCurrentUrl({ withoutHash: true });
|
|
34
|
+
assertUsage(urlFirst === urlCurrent, `The URL was manipulated before the hydration finished ('${urlFirst}' to '${urlCurrent}'). Ensure the hydration has finished before manipulating the URL. Consider using the onHydrationEnd() hook.`);
|
|
35
|
+
}
|
|
@@ -3,11 +3,14 @@ export type { PageContextBeforeRenderClient };
|
|
|
3
3
|
import type { PageFile, PageContextConfig } from '../../shared-server-client/getPageFiles.js';
|
|
4
4
|
import type { PageContextForPublicUsageClientShared } from './preparePageContextForPublicUsageClientShared.js';
|
|
5
5
|
import type { GlobalContextClientInternalShared } from './getGlobalContextClientInternalShared.js';
|
|
6
|
+
import type { PageContextCreatedClient } from '../runtime-client-routing/createPageContextClientSide.js';
|
|
7
|
+
import type { PageContextCreatedClient_ServerRouting } from '../runtime-server-routing/createPageContextClientSide.js';
|
|
8
|
+
type PageContextCreatedClientShared = PageContextCreatedClient | PageContextCreatedClient_ServerRouting;
|
|
6
9
|
type PageContextBeforeRenderClient = {
|
|
7
10
|
_pageFilesLoaded: PageFile[];
|
|
8
11
|
urlOriginal?: string;
|
|
9
12
|
urlPathname?: string;
|
|
10
13
|
pageId: string;
|
|
11
14
|
_globalContext: GlobalContextClientInternalShared;
|
|
12
|
-
} & PageContextConfig & PageContextForPublicUsageClientShared;
|
|
15
|
+
} & PageContextCreatedClientShared & PageContextConfig & PageContextForPublicUsageClientShared;
|
|
13
16
|
declare function execHookOnRenderClient<PageContext extends PageContextBeforeRenderClient>(pageContext: PageContext, prepareForPublicUsage: (pageConfig: PageContext) => PageContext): Promise<void>;
|
package/dist/node/vite/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { pluginWorkaroundCssModuleHmr } from './plugins/pluginWorkaroundCssModul
|
|
|
22
22
|
import { pluginWorkaroundVite6HmrRegression } from './plugins/pluginWorkaroundVite6HmrRegression.js';
|
|
23
23
|
import { pluginReplaceConstantsPageContext } from './plugins/pluginReplaceConstantsPageContext.js';
|
|
24
24
|
import { pluginReplaceConstantsGlobalThis } from './plugins/pluginReplaceConstantsGlobalThis.js';
|
|
25
|
+
import { pluginStaticReplace } from './plugins/pluginStaticReplace.js';
|
|
25
26
|
import { pluginViteRPC } from './plugins/non-runnable-dev/pluginViteRPC.js';
|
|
26
27
|
import { pluginBuildApp } from './plugins/build/pluginBuildApp.js';
|
|
27
28
|
import { pluginDistPackageJsonFile } from './plugins/build/pluginDistPackageJsonFile.js';
|
|
@@ -33,7 +34,7 @@ import { pluginModuleBanner } from './plugins/build/pluginModuleBanner.js';
|
|
|
33
34
|
import { pluginReplaceConstantsNonRunnableDev } from './plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js';
|
|
34
35
|
import { isVikeCliOrApi } from '../../shared-server-node/api-context.js';
|
|
35
36
|
import { pluginViteConfigVikeExtensions } from './plugins/pluginViteConfigVikeExtensions.js';
|
|
36
|
-
import { isOnlyResolvingUserConfig } from '../api/resolveViteConfigFromUser.js';
|
|
37
|
+
import { getVikeConfigInternalEarly, isOnlyResolvingUserConfig } from '../api/resolveViteConfigFromUser.js';
|
|
37
38
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
38
39
|
setGetClientEntrySrcDev(getClientEntrySrcDev);
|
|
39
40
|
assertIsNotProductionRuntime();
|
|
@@ -42,6 +43,7 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
42
43
|
const promise = (async () => {
|
|
43
44
|
if (skip())
|
|
44
45
|
return [];
|
|
46
|
+
const vikeConfig = await getVikeConfigInternalEarly();
|
|
45
47
|
const plugins = [
|
|
46
48
|
...pluginCommon(vikeVitePluginOptions),
|
|
47
49
|
...pluginVirtualFiles(),
|
|
@@ -58,8 +60,9 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
58
60
|
...pluginWorkaroundVite6HmrRegression(),
|
|
59
61
|
...pluginReplaceConstantsPageContext(),
|
|
60
62
|
...pluginReplaceConstantsGlobalThis(),
|
|
63
|
+
...pluginStaticReplace(vikeConfig),
|
|
61
64
|
...pluginNonRunnabeDev(),
|
|
62
|
-
...(await pluginViteConfigVikeExtensions()),
|
|
65
|
+
...(await pluginViteConfigVikeExtensions(vikeConfig)),
|
|
63
66
|
];
|
|
64
67
|
return plugins;
|
|
65
68
|
})();
|
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
export { pluginReplaceConstantsNonRunnableDev };
|
|
2
|
-
|
|
2
|
+
// 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.
|
|
3
|
+
import { isRunnableDevEnvironment, isDevCheck, assert } from '../../utils.js';
|
|
3
4
|
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
5
|
const IS_NON_RUNNABLE_DEV = 'globalThis.__VIKE__IS_NON_RUNNABLE_DEV';
|
|
7
6
|
const DYNAMIC_IMPORT = '__VIKE__DYNAMIC_IMPORT';
|
|
7
|
+
// === Rolldown filter
|
|
8
|
+
const filterRolldown1 = {
|
|
9
|
+
code: {
|
|
10
|
+
include: IS_NON_RUNNABLE_DEV,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const filterFunction1 = (code) => {
|
|
14
|
+
return code.includes(IS_NON_RUNNABLE_DEV);
|
|
15
|
+
};
|
|
16
|
+
const filterRolldown2 = {
|
|
17
|
+
code: {
|
|
18
|
+
include: DYNAMIC_IMPORT,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const filterFunction2 = (code) => {
|
|
22
|
+
return code.includes(DYNAMIC_IMPORT);
|
|
23
|
+
};
|
|
24
|
+
// 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
|
|
25
|
+
//
|
|
26
|
+
// Therefore, we cannot do this:
|
|
27
|
+
// ```js
|
|
28
|
+
// const distFileIsNonRunnableDev = requireResolveDistFile('dist/utils/isNonRunnableDevProcess.js')
|
|
29
|
+
// const distFileGlobalContext = requireResolveDistFile('dist/server/runtime/globalContext.js')
|
|
30
|
+
// const filterRolldown = {
|
|
31
|
+
// id: {
|
|
32
|
+
// include: [distFileIsNonRunnableDev, distFileGlobalContext].map(
|
|
33
|
+
// (filePath) => new RegExp(`^${escapeRegex(filePath)}($|${escapeRegex('?')}.*)`),
|
|
34
|
+
// ),
|
|
35
|
+
// },
|
|
36
|
+
// }
|
|
37
|
+
// ```
|
|
38
|
+
// ===
|
|
8
39
|
function pluginReplaceConstantsNonRunnableDev() {
|
|
9
40
|
return [
|
|
10
41
|
{
|
|
11
42
|
name: 'vike:pluginReplaceConstantsNonRunnableDev:IS_NON_RUNNABLE_DEV',
|
|
12
43
|
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
13
44
|
transform: {
|
|
14
|
-
filter:
|
|
15
|
-
code: {
|
|
16
|
-
include: IS_NON_RUNNABLE_DEV,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
45
|
+
filter: filterRolldown1,
|
|
19
46
|
handler(code, id) {
|
|
47
|
+
assert(filterFunction1(code));
|
|
20
48
|
if (isRunnableDevEnvironment(this.environment))
|
|
21
49
|
return;
|
|
22
50
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
@@ -29,12 +57,9 @@ function pluginReplaceConstantsNonRunnableDev() {
|
|
|
29
57
|
name: 'vike:pluginReplaceConstantsNonRunnableDev:DYNAMIC_IMPORT',
|
|
30
58
|
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
31
59
|
transform: {
|
|
32
|
-
filter:
|
|
33
|
-
code: {
|
|
34
|
-
include: DYNAMIC_IMPORT,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
60
|
+
filter: filterRolldown2,
|
|
37
61
|
handler(code, id) {
|
|
62
|
+
assert(filterFunction2(code));
|
|
38
63
|
if (isRunnableDevEnvironment(this.environment))
|
|
39
64
|
return;
|
|
40
65
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { pluginAssertFileEnv };
|
|
2
|
-
import { assert, assertUsage, assertWarning, capitalizeFirstLetter, isFilePathAbsolute, joinEnglish, rollupSourceMapRemove, } from '../utils.js';
|
|
2
|
+
import { applyDev, assert, assertUsage, assertWarning, capitalizeFirstLetter, isFilePathAbsolute, joinEnglish, rollupSourceMapRemove, } from '../utils.js';
|
|
3
3
|
import { extractAssetsRE } from './pluginExtractAssets.js';
|
|
4
4
|
import { extractExportNamesRE } from './pluginExtractExportNames.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
@@ -10,6 +10,7 @@ import { isV1Design } from '../shared/resolveVikeConfigInternal.js';
|
|
|
10
10
|
import { isViteServerSide, isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
11
11
|
import { suffixesAssertFileEnv } from '../../../shared-server-node/getFileSuffixes.js';
|
|
12
12
|
const envS = suffixesAssertFileEnv;
|
|
13
|
+
// === Rolldown filter
|
|
13
14
|
const skipNodeModules = '/node_modules/'; // Only assert `.server.js`, `.client.js` and `.ssr.js` for user files
|
|
14
15
|
const filterRolldown = {
|
|
15
16
|
id: {
|
|
@@ -22,18 +23,19 @@ const filterFunction = (id) => {
|
|
|
22
23
|
return false;
|
|
23
24
|
return envS.some((suffix) => id.includes(getSuffix(suffix)));
|
|
24
25
|
};
|
|
26
|
+
// ===
|
|
25
27
|
function pluginAssertFileEnv() {
|
|
26
28
|
let config;
|
|
27
29
|
let viteDevServer;
|
|
28
30
|
return [
|
|
29
31
|
{
|
|
30
|
-
name: 'vike:pluginAssertFileEnv',
|
|
32
|
+
name: 'vike:pluginAssertFileEnv:dev',
|
|
33
|
+
// In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
|
|
34
|
+
apply: applyDev,
|
|
31
35
|
load: {
|
|
32
36
|
filter: filterRolldown,
|
|
33
37
|
handler(id, options) {
|
|
34
|
-
|
|
35
|
-
if (!viteDevServer)
|
|
36
|
-
return;
|
|
38
|
+
assert(viteDevServer);
|
|
37
39
|
if (!isV1Design())
|
|
38
40
|
return;
|
|
39
41
|
if (skip(id, config.root))
|
|
@@ -53,14 +55,26 @@ function pluginAssertFileEnv() {
|
|
|
53
55
|
true);
|
|
54
56
|
},
|
|
55
57
|
},
|
|
58
|
+
configureServer: {
|
|
59
|
+
handler(viteDevServer_) {
|
|
60
|
+
viteDevServer = viteDevServer_;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
configResolved: {
|
|
64
|
+
handler(config_) {
|
|
65
|
+
config = config_;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'vike:pluginAssertFileEnv:build',
|
|
71
|
+
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
72
|
+
apply: 'build',
|
|
56
73
|
// In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
|
|
57
74
|
transform: {
|
|
58
75
|
filter: filterRolldown,
|
|
59
76
|
async handler(code, id, options) {
|
|
60
77
|
id = normalizeId(id);
|
|
61
|
-
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
62
|
-
if (viteDevServer)
|
|
63
|
-
return;
|
|
64
78
|
if (skip(id, config.root))
|
|
65
79
|
return;
|
|
66
80
|
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
@@ -101,11 +115,6 @@ function pluginAssertFileEnv() {
|
|
|
101
115
|
config = config_;
|
|
102
116
|
},
|
|
103
117
|
},
|
|
104
|
-
configureServer: {
|
|
105
|
-
handler(viteDevServer_) {
|
|
106
|
-
viteDevServer = viteDevServer_;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
118
|
},
|
|
110
119
|
];
|
|
111
120
|
function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
|
|
@@ -23,12 +23,14 @@ const rawRE = /(\?|&)raw(?:&|$)/;
|
|
|
23
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
24
24
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
25
25
|
const debug = createDebug('vike:pluginExtractAssets');
|
|
26
|
+
// === Rolldown filter
|
|
26
27
|
const filterRolldown = {
|
|
27
28
|
id: {
|
|
28
29
|
include: extractAssetsRE,
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
32
|
const filterFunction = (id) => extractAssetsRE.test(id);
|
|
33
|
+
// ===
|
|
32
34
|
function pluginExtractAssets() {
|
|
33
35
|
let config;
|
|
34
36
|
let vikeConfig;
|
|
@@ -8,12 +8,14 @@ import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
|
8
8
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
9
9
|
const debug = createDebug('vike:pluginExtractExportNames');
|
|
10
10
|
const globalObject = getGlobalObject('plugins/pluginExtractExportNames.ts', {});
|
|
11
|
+
// === Rolldown filter
|
|
11
12
|
const filterRolldown = {
|
|
12
13
|
id: {
|
|
13
14
|
include: extractExportNamesRE,
|
|
14
15
|
},
|
|
15
16
|
};
|
|
16
17
|
const filterFunction = (id) => extractExportNamesRE.test(id);
|
|
18
|
+
// ===
|
|
17
19
|
function pluginExtractExportNames() {
|
|
18
20
|
let isDev = false;
|
|
19
21
|
let config;
|
|
@@ -14,6 +14,7 @@ const PUBLIC_ENV_ALLOWLIST = [
|
|
|
14
14
|
// - Make import.meta.env work inside +config.js
|
|
15
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
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
|
+
// === Rolldown filter
|
|
17
18
|
const skipNodeModules = '/node_modules/';
|
|
18
19
|
const skipIrrelevant = 'import.meta.env.';
|
|
19
20
|
const filterRolldown = {
|
|
@@ -31,6 +32,7 @@ const filterFunction = (id, code) => {
|
|
|
31
32
|
return false;
|
|
32
33
|
return true;
|
|
33
34
|
};
|
|
35
|
+
// ===
|
|
34
36
|
function pluginReplaceConstantsEnvVars() {
|
|
35
37
|
let envVarsAll;
|
|
36
38
|
let envPrefix;
|
|
@@ -2,16 +2,18 @@ export { pluginReplaceConstantsGlobalThis };
|
|
|
2
2
|
export { VIRTUAL_FILE_ID_constantsGlobalThis };
|
|
3
3
|
import { assert, isDebug, addVirtualFileIdPrefix, escapeRegex } from '../utils.js';
|
|
4
4
|
import { isViteServerSide_applyToEnvironment, isViteServerSide_configEnvironment, isViteServerSide_extraSafe, } from '../shared/isViteServerSide.js';
|
|
5
|
+
const VIRTUAL_FILE_ID_constantsGlobalThis = 'virtual:vike:server:constantsGlobalThis';
|
|
5
6
|
const isDebugVal = isDebug();
|
|
6
7
|
globalThis.__VIKE__IS_CLIENT = false;
|
|
7
8
|
globalThis.__VIKE__IS_DEBUG = isDebugVal;
|
|
8
|
-
|
|
9
|
+
// === Rolldown filter
|
|
9
10
|
const filterRolldown = {
|
|
10
11
|
id: {
|
|
11
12
|
include: new RegExp(escapeRegex(VIRTUAL_FILE_ID_constantsGlobalThis)),
|
|
12
13
|
},
|
|
13
14
|
};
|
|
14
15
|
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis || id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
|
|
16
|
+
// ===
|
|
15
17
|
function pluginReplaceConstantsGlobalThis() {
|
|
16
18
|
let config;
|
|
17
19
|
let isDev;
|
|
@@ -11,6 +11,7 @@ const constantsIsClientSide = [
|
|
|
11
11
|
];
|
|
12
12
|
// - See https://vike.dev/pageContext#narrowing-down
|
|
13
13
|
// - We cannot use [`define`](https://vite.dev/config/shared-options.html#define) because of https://github.com/rolldown/rolldown/issues/4300
|
|
14
|
+
// === Rolldown filter
|
|
14
15
|
const skipNodeModules = '/node_modules/';
|
|
15
16
|
const skipIrrelevant = 'Context.isClientSide';
|
|
16
17
|
assert(constantsIsClientSide.every((constant) => constant.endsWith(skipIrrelevant)));
|
|
@@ -29,6 +30,7 @@ const filterFunction = (id, code) => {
|
|
|
29
30
|
return false;
|
|
30
31
|
return true;
|
|
31
32
|
};
|
|
33
|
+
// ===
|
|
32
34
|
function pluginReplaceConstantsPageContext() {
|
|
33
35
|
let config;
|
|
34
36
|
return [
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export { applyStaticReplace };
|
|
2
|
+
export type { StaticReplace };
|
|
3
|
+
/**
|
|
4
|
+
* Condition to match an argument value.
|
|
5
|
+
* - string starting with 'import:' matches an imported identifier
|
|
6
|
+
* - { prop, equals } matches a property value inside an object argument
|
|
7
|
+
* - { call, args } matches a call expression with specific arguments
|
|
8
|
+
* - { member, object, property } matches a member expression like $setup["ClientOnly"]
|
|
9
|
+
*/
|
|
10
|
+
type ArgCondition = string | {
|
|
11
|
+
prop: string;
|
|
12
|
+
equals: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
call: string;
|
|
15
|
+
args?: Record<number, ArgCondition>;
|
|
16
|
+
} | {
|
|
17
|
+
member: true;
|
|
18
|
+
object: string;
|
|
19
|
+
property: string | ArgCondition;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Target for replace operation.
|
|
23
|
+
*/
|
|
24
|
+
type ReplaceTarget = {
|
|
25
|
+
with: unknown;
|
|
26
|
+
} | {
|
|
27
|
+
arg: number;
|
|
28
|
+
prop: string;
|
|
29
|
+
with: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
arg: number;
|
|
32
|
+
with: unknown;
|
|
33
|
+
} | {
|
|
34
|
+
argsFrom: number;
|
|
35
|
+
with: unknown;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Target for remove operation.
|
|
39
|
+
*/
|
|
40
|
+
type RemoveTarget = {
|
|
41
|
+
arg: number;
|
|
42
|
+
prop: string;
|
|
43
|
+
} | {
|
|
44
|
+
arg: number;
|
|
45
|
+
} | {
|
|
46
|
+
argsFrom: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Rule for static replacement/removal.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // jsx/jsxs/jsxDEV: replace children prop with null
|
|
53
|
+
* {
|
|
54
|
+
* env: 'server',
|
|
55
|
+
* type: 'call',
|
|
56
|
+
* match: {
|
|
57
|
+
* function: ['jsx', 'jsxs', 'jsxDEV'],
|
|
58
|
+
* args: { 0: 'import:vike-react/ClientOnly:ClientOnly' }
|
|
59
|
+
* },
|
|
60
|
+
* replace: { arg: 1, prop: 'children', with: null }
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // createElement: remove all children (args from index 2)
|
|
65
|
+
* {
|
|
66
|
+
* env: 'server',
|
|
67
|
+
* type: 'call',
|
|
68
|
+
* match: {
|
|
69
|
+
* function: 'createElement',
|
|
70
|
+
* args: { 0: 'import:vike-react/ClientOnly:ClientOnly' }
|
|
71
|
+
* },
|
|
72
|
+
* remove: { argsFrom: 2 }
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // ssrRenderComponent: match nested call expression and remove default slot
|
|
77
|
+
* {
|
|
78
|
+
* env: 'server',
|
|
79
|
+
* type: 'call',
|
|
80
|
+
* match: {
|
|
81
|
+
* function: 'import:vue/server-renderer:ssrRenderComponent',
|
|
82
|
+
* args: {
|
|
83
|
+
* 0: {
|
|
84
|
+
* call: 'import:vue:unref',
|
|
85
|
+
* args: { 0: 'import:vike-vue/ClientOnly:ClientOnly' }
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* },
|
|
89
|
+
* remove: { arg: 2, prop: 'default' }
|
|
90
|
+
* }
|
|
91
|
+
*/
|
|
92
|
+
type StaticReplace = {
|
|
93
|
+
/** Environment filter: 'client' = client only, 'server' = everything except client */
|
|
94
|
+
env: 'server' | 'client';
|
|
95
|
+
/** Rolldown filter — MUST be narrowing as much as possible, otherwise you'll get significant performance degradation */
|
|
96
|
+
filter: string;
|
|
97
|
+
/** Type of transformation - currently only 'call' is supported, but can be extended in the future */
|
|
98
|
+
type: 'call';
|
|
99
|
+
/** Match criteria */
|
|
100
|
+
match: {
|
|
101
|
+
/**
|
|
102
|
+
* Function name(s) to match.
|
|
103
|
+
* - Plain string: matches function name directly (e.g., 'jsx')
|
|
104
|
+
* - Import string: 'import:importPath:exportName' (e.g., 'import:react/jsx-runtime:jsx')
|
|
105
|
+
*/
|
|
106
|
+
function: string | string[];
|
|
107
|
+
/** Conditions on arguments: index -> condition */
|
|
108
|
+
args?: Record<number, ArgCondition>;
|
|
109
|
+
};
|
|
110
|
+
/** Replace target (optional) */
|
|
111
|
+
replace?: ReplaceTarget;
|
|
112
|
+
/** Remove target (optional) */
|
|
113
|
+
remove?: RemoveTarget;
|
|
114
|
+
};
|
|
115
|
+
declare function applyStaticReplace(code: string, staticReplaceList: StaticReplace[], id: string, env: 'server' | 'client'): Promise<{
|
|
116
|
+
code: string;
|
|
117
|
+
map: {
|
|
118
|
+
version: number;
|
|
119
|
+
sources: string[];
|
|
120
|
+
names: string[];
|
|
121
|
+
sourceRoot?: string | undefined;
|
|
122
|
+
sourcesContent?: string[] | undefined;
|
|
123
|
+
mappings: string;
|
|
124
|
+
file: string;
|
|
125
|
+
} | null | undefined;
|
|
126
|
+
} | null | undefined>;
|