vike 0.4.238 → 0.4.239-commit-33e55d4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +10 -0
- package/dist/cjs/node/runtime/index.js +3 -3
- package/dist/cjs/node/runtime/page-files/setup.js +3 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -9
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/csp.js +47 -0
- package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/headersResponse.js +48 -0
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +8 -6
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +5 -3
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
- package/dist/cjs/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
- package/dist/cjs/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +17 -38
- package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +17 -9
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
- package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +62 -57
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +107 -93
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +27 -13
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +107 -84
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +40 -21
- package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +59 -33
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +54 -36
- package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +20 -22
- package/dist/cjs/shared/createGlobalContextShared.js +4 -22
- package/dist/cjs/shared/createPageContextShared.js +2 -2
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +62 -43
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +16 -1
- package/dist/cjs/utils/assertNodeVersion.js +3 -1
- package/dist/cjs/utils/assertVersion.js +26 -5
- package/dist/cjs/utils/joinEnglish.js +2 -1
- package/dist/cjs/utils/virtualFileId.js +15 -11
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +40 -17
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +99 -85
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +39 -11
- package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +44 -29
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +40 -17
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +39 -11
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +39 -11
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -3
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +4 -3
- package/dist/esm/node/prerender/runPrerender.d.ts +61 -16
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +167 -42
- package/dist/esm/node/runtime/globalContext.js +11 -1
- package/dist/esm/node/runtime/index.d.ts +3 -3
- package/dist/esm/node/runtime/index.js +3 -3
- package/dist/esm/node/runtime/page-files/setup.js +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -9
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +56 -12
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/csp.d.ts +12 -0
- package/dist/esm/node/runtime/renderPage/csp.js +45 -0
- package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -1
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/headersResponse.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/headersResponse.js +46 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
- package/dist/esm/node/runtime/renderPage/html/injectAssets/inferHtmlTags.d.ts +10 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +7 -5
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/html/injectAssets/mergeScriptTags.d.ts +3 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +6 -4
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
- package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.d.ts +6 -5
- package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
- package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +66 -17
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -39
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +122 -32
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
- package/dist/esm/node/runtime/renderPage.d.ts +56 -12
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +18 -10
- package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
- package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +62 -57
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +107 -91
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +27 -13
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +107 -84
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +41 -22
- package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +58 -33
- package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +56 -38
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -8
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +22 -24
- package/dist/esm/shared/createGlobalContextShared.d.ts +75 -19
- package/dist/esm/shared/createGlobalContextShared.js +5 -23
- package/dist/esm/shared/createPageContextShared.d.ts +2 -7
- package/dist/esm/shared/createPageContextShared.js +2 -2
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +91 -31
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +62 -43
- package/dist/esm/types/Config/ConfigResolved.d.ts +8 -0
- package/dist/esm/types/Config.d.ts +14 -6
- package/dist/esm/types/PageContext.d.ts +8 -25
- package/dist/esm/types/VikeNamespace.d.ts +0 -27
- package/dist/esm/types/index.d.ts +2 -2
- 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 +16 -1
- package/dist/esm/utils/assertNodeVersion.js +3 -1
- package/dist/esm/utils/assertVersion.d.ts +4 -3
- package/dist/esm/utils/assertVersion.js +23 -5
- package/dist/esm/utils/joinEnglish.js +2 -1
- package/dist/esm/utils/virtualFileId.d.ts +4 -0
- package/dist/esm/utils/virtualFileId.js +14 -11
- package/package.json +5 -5
- package/dist/cjs/types/Config/helpers.js +0 -2
- package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +0 -9
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +0 -2
- package/dist/esm/types/Config/PageContextConfig.d.ts +0 -15
- package/dist/esm/types/Config/helpers.d.ts +0 -10
- package/dist/esm/types/Config/helpers.js +0 -1
- /package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
- /package/dist/cjs/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/stream.d.ts +0 -0
- /package/dist/esm/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
|
@@ -22,54 +22,58 @@ function pluginDev() {
|
|
|
22
22
|
{
|
|
23
23
|
name: 'vike:pluginDev',
|
|
24
24
|
apply: utils_js_1.applyDev,
|
|
25
|
-
config
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
25
|
+
config: {
|
|
26
|
+
handler() {
|
|
27
|
+
return {
|
|
28
|
+
appType: 'custom',
|
|
29
|
+
// TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
|
|
30
|
+
optimizeDeps: {
|
|
31
|
+
exclude: [
|
|
32
|
+
// We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
|
|
33
|
+
'vike/client',
|
|
34
|
+
'vike/client/router',
|
|
35
|
+
// It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
|
|
36
|
+
// ```
|
|
37
|
+
// Client runtime loaded twice https://vike.dev/client-runtime-duplicated
|
|
38
|
+
// ```
|
|
39
|
+
'vike/routing',
|
|
40
|
+
'vike/getPageContext',
|
|
41
|
+
// We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
|
|
42
|
+
// ```
|
|
43
|
+
// 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
|
|
44
|
+
// 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
|
|
45
|
+
// ```
|
|
46
|
+
'@brillout/json-serializer/parse',
|
|
47
|
+
'@brillout/json-serializer/stringify',
|
|
48
|
+
'@brillout/picocolors',
|
|
49
|
+
// We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
|
|
50
|
+
// ```
|
|
51
|
+
// Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
|
|
52
|
+
// 343| // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
|
|
53
|
+
// 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
|
|
54
|
+
// ```
|
|
55
|
+
// The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
|
|
56
|
+
// ```js
|
|
57
|
+
// // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
|
|
58
|
+
// import { parse as parse2 } from "@brillout/json-serializer/parse";
|
|
59
|
+
// ```
|
|
60
|
+
'react-streaming',
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
63
65
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
configResolved: {
|
|
67
|
+
async handler(config_) {
|
|
68
|
+
config = config_;
|
|
69
|
+
await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config);
|
|
70
|
+
await (0, determineFsAllowList_js_1.determineFsAllowList)(config);
|
|
71
|
+
if (!(0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
72
|
+
await (0, getHttpRequestAsyncStore_js_1.installHttpRequestAsyncStore)();
|
|
73
|
+
(0, loggerVite_js_1.improveViteLogs)(config);
|
|
74
|
+
}
|
|
75
|
+
logDockerHint(config.server.host);
|
|
76
|
+
},
|
|
73
77
|
},
|
|
74
78
|
},
|
|
75
79
|
{
|
|
@@ -7,6 +7,7 @@ const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
|
7
7
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
8
8
|
const isViteServerSide_js_1 = require("../shared/isViteServerSide.js");
|
|
9
9
|
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
10
|
+
const pluginReplaceConstants_js_1 = require("./pluginReplaceConstants.js");
|
|
10
11
|
// TO-DO/eventually:
|
|
11
12
|
// - Make ({}) work inside +config.js
|
|
12
13
|
// - 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
|
|
@@ -22,66 +23,70 @@ function pluginEnvVars() {
|
|
|
22
23
|
return {
|
|
23
24
|
name: 'vike:pluginEnvVars',
|
|
24
25
|
enforce: 'post',
|
|
25
|
-
configResolved
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
configResolved: {
|
|
27
|
+
handler(config_) {
|
|
28
|
+
config = config_;
|
|
29
|
+
envsAll = (0, vite_1.loadEnv)(config.mode, config.envDir || config.root, '');
|
|
30
|
+
config.plugins.sort((0, utils_js_1.lowerFirst)((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
31
|
+
},
|
|
29
32
|
},
|
|
30
|
-
transform
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
transform: {
|
|
34
|
+
filter: pluginReplaceConstants_js_1.filterRolldown,
|
|
35
|
+
handler(code, id, options) {
|
|
36
|
+
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
37
|
+
(0, utils_js_1.assertPosixPath)(id);
|
|
38
|
+
(0, utils_js_1.assertPosixPath)(config.root);
|
|
39
|
+
if (!id.startsWith(config.root))
|
|
40
|
+
return; // skip linked dependencies
|
|
41
|
+
(0, utils_js_1.assert)((0, pluginReplaceConstants_js_1.filterFunction)(id, code));
|
|
42
|
+
const isBuild = config.command === 'build';
|
|
43
|
+
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
44
|
+
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
45
|
+
// Find & check
|
|
46
|
+
const replacements = Object.entries(envsAll)
|
|
47
|
+
.filter(([key]) => {
|
|
48
|
+
// Already handled by Vite
|
|
49
|
+
const envPrefix = !config.envPrefix ? [] : (0, utils_js_1.isArray)(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
50
|
+
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
51
|
+
})
|
|
52
|
+
.map(([envName, envVal]) => {
|
|
53
|
+
const envStatement = `({}).${envName}`;
|
|
54
|
+
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
55
|
+
// Security check
|
|
56
|
+
{
|
|
57
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
58
|
+
if (isPrivate && isClientSide) {
|
|
59
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
60
|
+
return;
|
|
61
|
+
const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
62
|
+
const errMsgAddendum = isBuild
|
|
63
|
+
? ''
|
|
64
|
+
: ' (Vike will prevent your app from building for production)';
|
|
65
|
+
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
66
|
+
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`;
|
|
67
|
+
if (isBuild) {
|
|
68
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
72
|
+
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
73
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
74
|
+
}
|
|
70
75
|
}
|
|
76
|
+
// Double check
|
|
77
|
+
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return null;
|
|
84
|
-
return getMagicStringResult();
|
|
79
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
80
|
+
})
|
|
81
|
+
.filter(utils_js_1.isNotNullish);
|
|
82
|
+
// Apply
|
|
83
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
84
|
+
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
85
|
+
});
|
|
86
|
+
if (!magicString.hasChanged())
|
|
87
|
+
return null;
|
|
88
|
+
return getMagicStringResult();
|
|
89
|
+
},
|
|
85
90
|
},
|
|
86
91
|
};
|
|
87
92
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
2
|
+
// TO-DO/next-major-release: remove
|
|
4
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
5
|
};
|
|
@@ -24,6 +23,12 @@ const rawRE = /(\?|&)raw(?:&|$)/;
|
|
|
24
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
25
24
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
26
25
|
const debug = (0, utils_js_1.createDebugger)('vike:pluginExtractAssets');
|
|
26
|
+
const filterRolldown = {
|
|
27
|
+
id: {
|
|
28
|
+
include: extractAssetsRE,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const filterFunction = (id) => extractAssetsRE.test(id);
|
|
27
32
|
function pluginExtractAssets() {
|
|
28
33
|
let config;
|
|
29
34
|
let vikeConfig;
|
|
@@ -35,24 +40,25 @@ function pluginExtractAssets() {
|
|
|
35
40
|
// In dev, things just work. (Because Vite's module graph erroneously conflates the Vite server-side importees with the client-side importees.)
|
|
36
41
|
apply: 'build',
|
|
37
42
|
enforce: 'post',
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
transform: {
|
|
44
|
+
filter: filterRolldown,
|
|
45
|
+
async handler(src, id, options) {
|
|
46
|
+
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
47
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
48
|
+
if (isFixEnabled) {
|
|
49
|
+
// I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
50
|
+
(0, assertV1Design_js_1.assertV1Design)(vikeConfig._pageConfigs, true);
|
|
51
|
+
(0, utils_js_1.assert)(false);
|
|
52
|
+
}
|
|
53
|
+
const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
|
|
54
|
+
(0, utils_js_1.assert)(includeAssetsImportedByServer);
|
|
55
|
+
(0, utils_js_1.assert)(!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options));
|
|
56
|
+
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
57
|
+
const moduleNames = getImportedModules(importStatements);
|
|
58
|
+
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
59
|
+
debugTransformResult(id, code, importStatements);
|
|
60
|
+
return (0, utils_js_1.rollupSourceMapRemove)(code);
|
|
61
|
+
},
|
|
56
62
|
},
|
|
57
63
|
},
|
|
58
64
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -63,89 +69,97 @@ function pluginExtractAssets() {
|
|
|
63
69
|
// - rollup's `alias` plugin; https://github.com/rollup/plugins/blob/5363f55aa1933b6c650832b08d6a54cb9ea64539/packages/alias/src/index.ts
|
|
64
70
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
65
71
|
enforce: 'pre',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
72
|
+
resolveId: {
|
|
73
|
+
async handler(source, importer, options) {
|
|
74
|
+
if ((0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options)) {
|
|
75
|
+
// When building for the server, there should never be a `?extractAssets` query
|
|
76
|
+
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
77
|
+
(0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// If there is no `importer` then `module` is an entry.
|
|
81
|
+
// We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
|
|
82
|
+
if (!importer) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// We only append `?extractAssets` if the parent module has `?extractAssets`
|
|
86
|
+
if (!extractAssetsRE.test(importer)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
|
|
90
|
+
(0, utils_js_1.assert)(includeAssetsImportedByServer);
|
|
91
|
+
let resolution = null;
|
|
92
|
+
try {
|
|
93
|
+
resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
|
|
94
|
+
}
|
|
95
|
+
catch { }
|
|
96
|
+
// Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
|
|
97
|
+
if (!resolution)
|
|
98
|
+
return emptyModule(source, importer);
|
|
99
|
+
const { id: file, external } = resolution;
|
|
100
|
+
// Nothing is externalized when building for the client-side
|
|
101
|
+
(0, utils_js_1.assert)(external === false);
|
|
102
|
+
// We include:
|
|
103
|
+
// - CSS(/LESS/SCSS/...) files
|
|
104
|
+
// - Asset files (`.svg`, `.pdf`, ...)
|
|
105
|
+
// - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
|
|
106
|
+
if (utils_js_1.styleFileRE.test(file) || (0, isAsset_js_1.isAsset)(file) || urlRE.test(file)) {
|
|
107
|
+
debugOperation('INCLUDED', file, importer);
|
|
108
|
+
return resolution;
|
|
109
|
+
}
|
|
110
|
+
// We erase `source` if its file doesn't contain JavaScript
|
|
111
|
+
if (!(0, utils_js_1.isScriptFile)(file)) {
|
|
112
|
+
return emptyModule(file, importer);
|
|
113
|
+
}
|
|
114
|
+
// If the import path resolves to a file in `node_modules/`, we ignore that file:
|
|
115
|
+
// - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
|
|
116
|
+
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
|
|
117
|
+
(0, utils_js_1.assertPosixPath)(file);
|
|
118
|
+
if (file.includes('/node_modules/')) {
|
|
119
|
+
return emptyModule(file, importer);
|
|
120
|
+
}
|
|
121
|
+
// When a library is symlinked, it lives outside `root`.
|
|
122
|
+
(0, utils_js_1.assertPosixPath)(config.root);
|
|
123
|
+
if (!file.startsWith(config.root)) {
|
|
124
|
+
return emptyModule(file, importer);
|
|
125
|
+
}
|
|
126
|
+
return appendExtractAssetsQuery(file, importer);
|
|
127
|
+
},
|
|
120
128
|
},
|
|
121
129
|
},
|
|
122
130
|
{
|
|
123
131
|
name: 'vike:pluginExtractAssets-3',
|
|
124
132
|
apply: 'build',
|
|
125
|
-
load
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
load: {
|
|
134
|
+
handler(id) {
|
|
135
|
+
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
136
|
+
return undefined;
|
|
137
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
138
|
+
if (id === EMPTY_MODULE_ID) {
|
|
139
|
+
return '// Erased by vike:pluginExtractAssets';
|
|
140
|
+
}
|
|
141
|
+
},
|
|
132
142
|
},
|
|
133
|
-
config
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
config: {
|
|
144
|
+
handler() {
|
|
145
|
+
if (debug.isActivated) {
|
|
146
|
+
return { logLevel: 'silent' };
|
|
147
|
+
}
|
|
148
|
+
},
|
|
137
149
|
},
|
|
138
150
|
},
|
|
139
151
|
{
|
|
140
152
|
name: 'vike:pluginExtractAssets-4',
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
153
|
+
configResolved: {
|
|
154
|
+
async handler(config_) {
|
|
155
|
+
config = config_;
|
|
156
|
+
vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
157
|
+
isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)();
|
|
158
|
+
if (!isFixEnabled) {
|
|
159
|
+
// https://github.com/vikejs/vike/issues/1060
|
|
160
|
+
(0, utils_js_1.assertUsage)(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
|
|
161
|
+
}
|
|
162
|
+
},
|
|
149
163
|
},
|
|
150
164
|
},
|
|
151
165
|
];
|
|
@@ -11,31 +11,45 @@ const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
|
11
11
|
exports.extractExportNamesRE = extractExportNamesRE;
|
|
12
12
|
const debug = (0, utils_js_1.createDebugger)('vike:pluginExtractExportNames');
|
|
13
13
|
const globalObject = (0, utils_js_1.getGlobalObject)('plugins/pluginExtractExportNames.ts', {});
|
|
14
|
+
const filterRolldown = {
|
|
15
|
+
id: {
|
|
16
|
+
include: extractExportNamesRE,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const filterFunction = (id) => extractExportNamesRE.test(id);
|
|
14
20
|
function pluginExtractExportNames() {
|
|
15
21
|
let isDev = false;
|
|
16
22
|
let config;
|
|
17
23
|
return {
|
|
18
24
|
name: 'vike:pluginExtractExportNames',
|
|
19
25
|
enforce: 'post',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
transform: {
|
|
27
|
+
filter: filterRolldown,
|
|
28
|
+
async handler(src, id, options) {
|
|
29
|
+
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
30
|
+
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
31
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
24
32
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
25
33
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
26
34
|
return code;
|
|
27
|
-
}
|
|
35
|
+
},
|
|
28
36
|
},
|
|
29
|
-
configureServer
|
|
30
|
-
|
|
37
|
+
configureServer: {
|
|
38
|
+
handler() {
|
|
39
|
+
isDev = true;
|
|
40
|
+
},
|
|
31
41
|
},
|
|
32
|
-
configResolved
|
|
33
|
-
|
|
42
|
+
configResolved: {
|
|
43
|
+
handler(config_) {
|
|
44
|
+
config = config_;
|
|
45
|
+
},
|
|
34
46
|
},
|
|
35
|
-
config
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
config: {
|
|
48
|
+
handler() {
|
|
49
|
+
if (debug.isActivated) {
|
|
50
|
+
return { logLevel: 'silent' };
|
|
51
|
+
}
|
|
52
|
+
},
|
|
39
53
|
},
|
|
40
54
|
};
|
|
41
55
|
}
|