vike 0.4.267 → 0.4.268-commit-ca58695
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/RenderErrorPage.js +2 -2
- package/abort.js +2 -2
- package/dist/client/__internal/index.d.ts +3 -0
- package/dist/client/__internal/index.js +4 -0
- package/dist/client/runtime-client-routing/createPageContextClient.d.ts +5 -0
- package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +5 -0
- package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +28 -2
- package/dist/client/runtime-client-routing/getPageContextFromHooks.js +5 -5
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +490 -10
- package/dist/client/runtime-client-routing/renderPageClient.js +149 -43
- package/dist/client/runtime-client-routing/streamedValues.d.ts +5 -0
- package/dist/client/runtime-client-routing/streamedValues.js +23 -0
- package/dist/client/runtime-server-routing/createPageContextClient.d.ts +5 -0
- package/dist/client/runtime-server-routing/entry.js +1 -1
- package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +5 -0
- package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +5 -0
- package/dist/client/shared/getGlobalContextClientInternalShared.js +2 -0
- package/dist/client/shared/getJsonSerializedInHtml.d.ts +2 -2
- package/dist/client/shared/getJsonSerializedInHtml.js +9 -6
- package/dist/client/shared/loadPageConfigsLazyClientSide.js +0 -4
- package/dist/client/shared/removeFoucBuster.js +14 -3
- package/dist/client/shared/streamedValues/asyncIterable.d.ts +4 -0
- package/dist/client/shared/streamedValues/asyncIterable.js +26 -0
- package/dist/client/shared/streamedValues/lines.d.ts +11 -0
- package/dist/client/shared/streamedValues/lines.js +19 -0
- package/dist/client/shared/streamedValues/promise.d.ts +4 -0
- package/dist/client/shared/streamedValues/promise.js +19 -0
- package/dist/client/shared/streamedValues/readableStream.d.ts +4 -0
- package/dist/client/shared/streamedValues/readableStream.js +44 -0
- package/dist/client/shared/streamedValues/registry.d.ts +21 -0
- package/dist/client/shared/streamedValues/registry.js +40 -0
- package/dist/client/shared/streamedValues.d.ts +7 -0
- package/dist/client/shared/streamedValues.js +82 -0
- package/dist/node/api/dev.js +15 -1
- package/dist/node/api/resolveViteConfigUser.js +2 -2
- package/dist/node/api/serverEntryDev.d.ts +10 -0
- package/dist/node/api/serverEntryDev.js +125 -0
- package/dist/node/createDevMiddleware.js +12 -0
- package/dist/node/prerender/resolvePrerenderConfig.d.ts +1 -1
- package/dist/node/prerender/resolvePrerenderConfig.js +4 -1
- package/dist/node/prerender/runPrerender.d.ts +18 -18
- package/dist/node/prerender/runPrerender.js +61 -16
- package/dist/node/vite/assertEnvVite.js +1 -1
- package/dist/node/vite/index.js +2 -0
- package/dist/node/vite/plugins/build/handleAssetsManifest.js +6 -2
- package/dist/node/vite/plugins/build/pluginBuildApp.js +25 -26
- package/dist/node/vite/plugins/build/pluginBuildConfig.d.ts +2 -2
- package/dist/node/vite/plugins/build/pluginBuildConfig.js +25 -17
- package/dist/node/vite/plugins/build/pluginDistFileNames.js +70 -50
- package/dist/node/vite/plugins/build/pluginEnvironmentEntries.d.ts +6 -0
- package/dist/node/vite/plugins/build/pluginEnvironmentEntries.js +71 -0
- package/dist/node/vite/plugins/build/pluginSuppressRollupWarning.js +19 -17
- package/dist/node/vite/plugins/pluginCommon.js +10 -7
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.d.ts +2 -2
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +6 -2
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +6 -4
- package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.d.ts +3 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.js +28 -2
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.d.ts +1 -1
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.js +22 -11
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginWrapServerFile.d.ts +4 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginWrapServerFile.js +29 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy.js +29 -5
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -1
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +29 -12
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -2
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +7 -7
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +10 -6
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +5 -11
- package/dist/node/vite/plugins/pluginVirtualFiles.js +20 -0
- package/dist/node/vite/shared/addSsrMiddleware.js +11 -27
- package/dist/node/vite/shared/findPageFiles.d.ts +1 -1
- package/dist/node/vite/shared/findPageFiles.js +1 -11
- package/dist/node/vite/shared/getAssetsDir.d.ts +3 -2
- package/dist/node/vite/shared/getAssetsDir.js +3 -3
- package/dist/node/vite/shared/isViteCli.d.ts +3 -3
- package/dist/node/vite/shared/isViteCli.js +80 -84
- package/dist/node/vite/shared/isViteServerSide.js +2 -7
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.d.ts +6 -4
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +17 -6
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +9 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +5 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +86 -13
- package/dist/server/__internal/fetch-deprecated.d.ts +2 -0
- package/dist/server/__internal/fetch-deprecated.js +6 -0
- package/dist/server/__internal/fetch.d.ts +9 -0
- package/dist/server/__internal/fetch.js +5 -0
- package/dist/server/__internal/index.d.ts +4 -0
- package/dist/server/__internal/index.js +8 -0
- package/dist/server/createPageRenderer.d.ts +2 -2
- package/dist/server/createPageRenderer.js +2 -2
- package/dist/server/runtime/createDevMiddleware.js +3 -1
- package/dist/server/runtime/globalContext.d.ts +69 -10
- package/dist/server/runtime/globalContext.js +35 -2
- package/dist/server/runtime/index.d.ts +1 -1
- package/dist/server/runtime/index.js +1 -1
- package/dist/server/runtime/renderPageServer/analyzePage.js +3 -3
- package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +20 -9
- package/dist/server/runtime/renderPageServer/createHttpResponse.js +34 -21
- package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +13 -23
- package/dist/server/runtime/renderPageServer/csp.d.ts +2 -1
- package/dist/server/runtime/renderPageServer/csp.js +2 -1
- package/dist/server/runtime/renderPageServer/execHookOnError.js +1 -1
- package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.d.ts +9 -0
- package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.js +21 -9
- package/dist/server/runtime/renderPageServer/getHttpResponseBody.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/getHttpResponseBody.js +19 -12
- package/dist/server/runtime/renderPageServer/getPageContextJson.d.ts +8 -0
- package/dist/server/runtime/renderPageServer/getPageContextJson.js +47 -0
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.d.ts +2 -0
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.js +1 -1
- package/dist/server/runtime/renderPageServer/handlePageContextRequestUrl.js +2 -2
- package/dist/server/runtime/renderPageServer/headersResponse.d.ts +11 -2
- package/dist/server/runtime/renderPageServer/headersResponse.js +22 -2
- package/dist/server/runtime/renderPageServer/html/injectAssets/getHtmlTags.js +5 -4
- package/dist/server/runtime/renderPageServer/html/injectAssets.d.ts +3 -2
- package/dist/server/runtime/renderPageServer/html/injectAssets.js +7 -1
- package/dist/server/runtime/renderPageServer/html/renderHtml.js +4 -2
- package/dist/server/runtime/renderPageServer/html/serializeContext.d.ts +5 -1
- package/dist/server/runtime/renderPageServer/html/serializeContext.js +12 -9
- package/dist/server/runtime/renderPageServer/html/stream.d.ts +13 -6
- package/dist/server/runtime/renderPageServer/html/stream.js +135 -32
- package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.d.ts +30 -0
- package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.js +92 -0
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +10 -14
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.js +5 -1
- package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.d.ts +15 -0
- package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.js +61 -0
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +320 -55
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.js +21 -12
- package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.js +12 -0
- package/dist/server/runtime/renderPageServer/streamedValues/lines.d.ts +10 -0
- package/dist/server/runtime/renderPageServer/streamedValues/lines.js +49 -0
- package/dist/server/runtime/renderPageServer/streamedValues/promise.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/promise.js +14 -0
- package/dist/server/runtime/renderPageServer/streamedValues/pump.d.ts +10 -0
- package/dist/server/runtime/renderPageServer/streamedValues/pump.js +67 -0
- package/dist/server/runtime/renderPageServer/streamedValues/readableStream.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/readableStream.js +12 -0
- package/dist/server/runtime/renderPageServer/streamedValues/registry.d.ts +28 -0
- package/dist/server/runtime/renderPageServer/streamedValues/registry.js +33 -0
- package/dist/server/runtime/renderPageServer.d.ts +65 -18
- package/dist/server/runtime/renderPageServer.js +33 -62
- package/dist/server/runtime/universal-middleware/core.d.ts +25 -0
- package/dist/server/runtime/universal-middleware/core.js +167 -0
- package/dist/server/runtime/universal-middleware/deprecated-export.d.ts +3 -0
- package/dist/server/runtime/universal-middleware/deprecated-export.js +10 -0
- package/dist/server/runtime/universal-middleware/getMiddlewaresPipe.d.ts +15 -0
- package/dist/server/runtime/universal-middleware/getMiddlewaresPipe.js +51 -0
- package/dist/server/runtime/universal-middleware/vikeUniversalMiddleware.d.ts +9 -0
- package/dist/server/runtime/universal-middleware/vikeUniversalMiddleware.js +22 -0
- package/dist/shared-server-client/createGlobalContextShared.d.ts +8 -0
- package/dist/shared-server-client/createGlobalContextShared.js +2 -1
- package/dist/shared-server-client/getPageContextPublicShared.js +1 -3
- package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.d.ts +8 -0
- package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.js +17 -7
- package/dist/shared-server-client/hooks/execHook.d.ts +1 -1
- package/dist/shared-server-client/hooks/execHook.js +2 -2
- package/dist/shared-server-client/page-configs/serialize/serializeConfigValues.js +2 -0
- package/dist/shared-server-client/route/abort.d.ts +1 -1
- package/dist/shared-server-client/route/abort.js +4 -2
- package/dist/shared-server-client/streamedValues.d.ts +22 -0
- package/dist/shared-server-client/streamedValues.js +24 -0
- package/dist/shared-server-node/vike-environments.d.ts +4 -0
- package/dist/shared-server-node/vike-environments.js +10 -0
- package/dist/shared-server-node/virtualFileId.d.ts +7 -5
- package/dist/shared-server-node/virtualFileId.js +42 -42
- package/dist/types/Config.d.ts +11 -3
- package/dist/types/GlobalContext.d.ts +3 -3
- package/dist/types/PageConfig.d.ts +13 -5
- package/dist/types/PageContext.d.ts +18 -10
- package/dist/types/PageContext.js +1 -0
- package/dist/types/Server.d.ts +1 -1
- package/dist/types/VikeNamespace.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assertViteVersion.d.ts +1 -3
- package/dist/utils/assertViteVersion.js +6 -9
- package/dist/utils/catchInfiniteLoop.js +33 -11
- package/dist/utils/deepEqual.d.ts +2 -1
- package/dist/utils/deepEqual.js +21 -6
- package/dist/utils/getContentTypeFromUrl.d.ts +2 -0
- package/dist/utils/getContentTypeFromUrl.js +39 -0
- package/dist/utils/injectRollupInputs.d.ts +2 -2
- package/dist/utils/injectRollupInputs.js +2 -2
- package/dist/utils/installUncaughtErrorHandlers.js +9 -0
- package/dist/utils/isDev.js +2 -7
- package/dist/utils/parseUrl-extras.js +4 -0
- package/fetch.js +2 -2
- package/modifyUrl.js +2 -2
- package/package.json +42 -26
- package/routing.js +2 -2
- package/universal-middleware.js +2 -2
- package/vike-server.d.ts +14 -0
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.d.ts +0 -4
- package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.js +0 -22
- package/dist/server/runtime/fetch.d.ts +0 -10
- package/dist/server/runtime/fetch.js +0 -5
- package/dist/server/runtime/universal-middleware.d.ts +0 -10
- package/dist/server/runtime/universal-middleware.js +0 -27
- package/dist/shared-server-client/addIs404ToPageProps.d.ts +0 -2
- package/dist/shared-server-client/addIs404ToPageProps.js +0 -17
|
@@ -12,6 +12,8 @@ import { getAssetsDir } from '../../shared/getAssetsDir.js';
|
|
|
12
12
|
import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js';
|
|
13
13
|
import '../../assertEnvVite.js';
|
|
14
14
|
import { isVite8OrAbove } from '../../shared/isVite8OrAbove.js';
|
|
15
|
+
import { isViteServerSide_configEnvironment } from '../../shared/isViteServerSide.js';
|
|
16
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
15
17
|
function pluginDistFileNames() {
|
|
16
18
|
return [
|
|
17
19
|
{
|
|
@@ -19,42 +21,65 @@ function pluginDistFileNames() {
|
|
|
19
21
|
apply: 'build',
|
|
20
22
|
enforce: 'post',
|
|
21
23
|
configResolved: {
|
|
22
|
-
handler(config) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
|
|
34
|
-
rollupOutput.assetFileNames.isTheOneSetByVike = true;
|
|
35
|
-
assert(rollupOutput.assetFileNames.isTheOneSetByVike);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
// If a user needs this:
|
|
39
|
-
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
40
|
-
// - It's needed for getHash() of handleAssetsManifest()
|
|
41
|
-
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
42
|
-
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
43
|
-
assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
|
|
44
|
-
}
|
|
24
|
+
async handler(config) {
|
|
25
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
26
|
+
Object.entries(config.environments).forEach(([envName, envConfig]) => {
|
|
27
|
+
// Vike doesn't own the builds of additional environments (e.g. `rsc`): it only emits `entry-environment.mjs` there
|
|
28
|
+
if (additionalEnvironmentNames.includes(envName))
|
|
29
|
+
return;
|
|
30
|
+
const { build } = envConfig;
|
|
31
|
+
copyRollupOutputs(build);
|
|
32
|
+
const isServerSide = isViteServerSide_configEnvironment(envName, envConfig);
|
|
33
|
+
setFileNames(config, build, isServerSide, envName);
|
|
34
|
+
disableCSSBundling(config, build);
|
|
45
35
|
});
|
|
46
|
-
disableCSSBundling(config);
|
|
47
36
|
},
|
|
48
37
|
},
|
|
49
38
|
},
|
|
50
39
|
];
|
|
51
40
|
}
|
|
41
|
+
function setFileNames(config, build, isServerSide, envName) {
|
|
42
|
+
const rollupOutputs = getRollupOutputs(build);
|
|
43
|
+
// We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
|
|
44
|
+
rollupOutputs.forEach((rollupOutput) => {
|
|
45
|
+
// Server environments other than `ssr` keep their own entry file names, e.g. @vitejs/plugin-rsc imports its `rsc` entry as `index.js`
|
|
46
|
+
if (!('entryFileNames' in rollupOutput) && (!isServerSide || envName === 'ssr')) {
|
|
47
|
+
rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, build, isServerSide);
|
|
48
|
+
}
|
|
49
|
+
if (!('chunkFileNames' in rollupOutput)) {
|
|
50
|
+
rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, build, isServerSide);
|
|
51
|
+
}
|
|
52
|
+
if (!('assetFileNames' in rollupOutput)) {
|
|
53
|
+
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config, build);
|
|
54
|
+
rollupOutput.assetFileNames.isTheOneSetByVike = true;
|
|
55
|
+
assert(rollupOutput.assetFileNames.isTheOneSetByVike);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// If a user needs this:
|
|
59
|
+
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
60
|
+
// - It's needed for getHash() of handleAssetsManifest()
|
|
61
|
+
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
62
|
+
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
63
|
+
assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Vike sets entryFileNames/chunkFileNames/assetFileNames on an output object only if the user didn't set them. But the user's output object can be:
|
|
68
|
+
// - The same object for several environments.
|
|
69
|
+
// - Reused across Vite's config resolutions, e.g. an inline config such as VITE_CONFIG.
|
|
70
|
+
// Without a copy, the file names Vike sets for one environment look user-set to the next environment, which then keeps the wrong environment's file names.
|
|
71
|
+
function copyRollupOutputs(build) {
|
|
72
|
+
const { output } = build.rollupOptions;
|
|
73
|
+
if (!output)
|
|
74
|
+
return;
|
|
75
|
+
build.rollupOptions.output = isArray(output) ? output.map((o) => ({ ...o })) : { ...output };
|
|
76
|
+
}
|
|
52
77
|
function getIdHash(id) {
|
|
53
78
|
return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
54
79
|
}
|
|
55
|
-
function getAssetFileName(assetInfo, config) {
|
|
80
|
+
function getAssetFileName(assetInfo, config, build) {
|
|
56
81
|
const userRootDir = config.root;
|
|
57
|
-
const assetsDir = getAssetsDir(
|
|
82
|
+
const assetsDir = getAssetsDir(build);
|
|
58
83
|
const dir = assetsDir + '/static';
|
|
59
84
|
let { name } = assetInfo;
|
|
60
85
|
if (!name) {
|
|
@@ -78,19 +103,19 @@ function getAssetFileName(assetInfo, config) {
|
|
|
78
103
|
name = clean(name, userRootDir);
|
|
79
104
|
return `${dir}/${name}.[hash][extname]`;
|
|
80
105
|
}
|
|
81
|
-
function getChunkFileName(_chunkInfo,
|
|
82
|
-
const isForClientSide = !
|
|
106
|
+
function getChunkFileName(_chunkInfo, build, isServerSide) {
|
|
107
|
+
const isForClientSide = !isServerSide;
|
|
83
108
|
let name = 'chunks/chunk-[hash].js';
|
|
84
109
|
if (isForClientSide) {
|
|
85
|
-
const assetsDir = getAssetsDir(
|
|
110
|
+
const assetsDir = getAssetsDir(build);
|
|
86
111
|
name = `${assetsDir}/${name}`;
|
|
87
112
|
}
|
|
88
113
|
return name;
|
|
89
114
|
}
|
|
90
|
-
function getEntryFileName(chunkInfo, config,
|
|
115
|
+
function getEntryFileName(chunkInfo, config, build, isServerSide) {
|
|
91
116
|
const userRootDir = config.root;
|
|
92
|
-
const assetsDir = getAssetsDir(
|
|
93
|
-
const isForClientSide = !
|
|
117
|
+
const assetsDir = getAssetsDir(build);
|
|
118
|
+
const isForClientSide = !isServerSide;
|
|
94
119
|
let { name } = chunkInfo;
|
|
95
120
|
assertPosixPath(name);
|
|
96
121
|
name = clean(name, userRootDir, true,
|
|
@@ -100,7 +125,7 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
100
125
|
return `${assetsDir}/${name}.[hash].js`;
|
|
101
126
|
}
|
|
102
127
|
else {
|
|
103
|
-
return `${name}
|
|
128
|
+
return `${name}.mjs`;
|
|
104
129
|
}
|
|
105
130
|
}
|
|
106
131
|
function removePathSeparators(name) {
|
|
@@ -188,9 +213,9 @@ function workaroundGlob(name) {
|
|
|
188
213
|
return name;
|
|
189
214
|
}
|
|
190
215
|
// Workaround for Vite CSS duplication bug: https://github.com/vikejs/vike/issues/1815
|
|
191
|
-
function disableCSSBundling(config) {
|
|
216
|
+
function disableCSSBundling(config, build) {
|
|
192
217
|
if (isVite8OrAbove(config)) {
|
|
193
|
-
for (const output of getRolldownOutputs(
|
|
218
|
+
for (const output of getRolldownOutputs(build)) {
|
|
194
219
|
assert(output);
|
|
195
220
|
const { codeSplitting } = output;
|
|
196
221
|
// `codeSplitting: false` => single-bundle mode; respect the user's choice.
|
|
@@ -219,7 +244,7 @@ function disableCSSBundling(config) {
|
|
|
219
244
|
}
|
|
220
245
|
}
|
|
221
246
|
else {
|
|
222
|
-
for (const output of getRollupOutputs(
|
|
247
|
+
for (const output of getRollupOutputs(build)) {
|
|
223
248
|
assert(output);
|
|
224
249
|
wrapManualChunks(output, config, 'rollupOptions');
|
|
225
250
|
}
|
|
@@ -291,28 +316,23 @@ function getCssChunkName(id, config) {
|
|
|
291
316
|
return `${name}-${hash}`;
|
|
292
317
|
}
|
|
293
318
|
}
|
|
294
|
-
function getRollupOutputs(
|
|
295
|
-
var _a
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
299
|
-
(_b = config.build.rollupOptions).output ?? (_b.output = {});
|
|
300
|
-
const { output } = config.build.rollupOptions;
|
|
319
|
+
function getRollupOutputs(build) {
|
|
320
|
+
var _a;
|
|
321
|
+
(_a = build.rollupOptions).output ?? (_a.output = {});
|
|
322
|
+
const { output } = build.rollupOptions;
|
|
301
323
|
if (!isArray(output)) {
|
|
302
324
|
return [output];
|
|
303
325
|
}
|
|
304
326
|
return output;
|
|
305
327
|
}
|
|
306
|
-
function getRolldownOutputs(
|
|
307
|
-
var _a
|
|
308
|
-
// @ts-expect-error is read-only
|
|
309
|
-
config.build ?? (config.build = {});
|
|
328
|
+
function getRolldownOutputs(build) {
|
|
329
|
+
var _a;
|
|
310
330
|
// @ts-ignore
|
|
311
|
-
|
|
331
|
+
build.rolldownOptions ?? (build.rolldownOptions = {});
|
|
312
332
|
// @ts-ignore
|
|
313
|
-
(
|
|
333
|
+
(_a = build.rolldownOptions).output ?? (_a.output = {});
|
|
314
334
|
// @ts-ignore
|
|
315
|
-
const { output } =
|
|
335
|
+
const { output } = build.rolldownOptions;
|
|
316
336
|
if (!isArray(output)) {
|
|
317
337
|
return [output];
|
|
318
338
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { pluginEnvironmentEntries };
|
|
2
|
+
export { getEnvironmentEntryPlaceholder };
|
|
3
|
+
import type { Plugin } from 'vite';
|
|
4
|
+
import '../../assertEnvVite.js';
|
|
5
|
+
declare function pluginEnvironmentEntries(): Plugin[];
|
|
6
|
+
declare function getEnvironmentEntryPlaceholder(environmentName: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { pluginEnvironmentEntries };
|
|
2
|
+
export { getEnvironmentEntryPlaceholder };
|
|
3
|
+
// Vike's server environment imports the global entry of every additional environment (e.g. `rsc`), see loadPageContextEnvironments.ts
|
|
4
|
+
// - An additional environment is a separate build, so the server imports its entry by a path relative to the importing chunk, which is known only after chunking (the same marker + renderChunk() as @vitejs/plugin-rsc's import.meta.viteRsc.loadModule())
|
|
5
|
+
import { assertUsage } from '../../../../utils/assert.js';
|
|
6
|
+
import { generateVirtualFileIdAdditionalEnvironment } from '../../../../shared-server-node/virtualFileId.js';
|
|
7
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
8
|
+
import { getMagicString } from '../../shared/getMagicString.js';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import '../../assertEnvVite.js';
|
|
11
|
+
const environmentEntryFileName = 'entry-environment.mjs';
|
|
12
|
+
const environmentEntryPlaceholder = '__VIKE_ENVIRONMENT_ENTRY__';
|
|
13
|
+
const environmentEntryPlaceholderRegex = new RegExp(`(["'\`])${environmentEntryPlaceholder}:(.+?)\\1`, 'g');
|
|
14
|
+
function pluginEnvironmentEntries() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: 'vike:build:emitEnvironmentEntry',
|
|
18
|
+
apply: 'build',
|
|
19
|
+
buildStart: {
|
|
20
|
+
async handler() {
|
|
21
|
+
const { name, config } = this.environment;
|
|
22
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
23
|
+
if (!additionalEnvironmentNames.includes(name))
|
|
24
|
+
return;
|
|
25
|
+
assertUsage(config.consumer === 'server', `The Vike environment ${name} should be a server-side Vite environment`);
|
|
26
|
+
this.emitFile({
|
|
27
|
+
type: 'chunk',
|
|
28
|
+
id: generateVirtualFileIdAdditionalEnvironment(name),
|
|
29
|
+
fileName: environmentEntryFileName,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'vike:build:linkEnvironmentEntries',
|
|
36
|
+
apply: 'build',
|
|
37
|
+
resolveId: {
|
|
38
|
+
filter: { id: new RegExp(`^${environmentEntryPlaceholder}:`) },
|
|
39
|
+
handler(id) {
|
|
40
|
+
return { id, external: true };
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
renderChunk: {
|
|
44
|
+
handler(code, chunk) {
|
|
45
|
+
return replaceEnvironmentEntryPlaceholders(code, chunk.fileName, this.environment);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
// The import specifier of the environment's entry, replaced by its relative path once the importer's location is known
|
|
52
|
+
function getEnvironmentEntryPlaceholder(environmentName) {
|
|
53
|
+
return `${environmentEntryPlaceholder}:${environmentName}`;
|
|
54
|
+
}
|
|
55
|
+
// Replace each placeholder with the path of the environment's entry, relative to the chunk
|
|
56
|
+
function replaceEnvironmentEntryPlaceholders(code, chunkFileName, environment) {
|
|
57
|
+
if (!code.includes(environmentEntryPlaceholder))
|
|
58
|
+
return;
|
|
59
|
+
const { config } = environment;
|
|
60
|
+
const chunkDir = path.dirname(path.resolve(config.root, config.build.outDir, chunkFileName));
|
|
61
|
+
const { magicString, getMagicStringResult } = getMagicString(code, chunkFileName);
|
|
62
|
+
for (const match of code.matchAll(environmentEntryPlaceholderRegex)) {
|
|
63
|
+
const outDir = config.environments[match[2]].build.outDir;
|
|
64
|
+
const environmentEntry = path.resolve(config.root, outDir, environmentEntryFileName);
|
|
65
|
+
let importPath = path.relative(chunkDir, environmentEntry).split(path.sep).join('/');
|
|
66
|
+
if (!importPath.startsWith('.'))
|
|
67
|
+
importPath = `./${importPath}`;
|
|
68
|
+
magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(importPath));
|
|
69
|
+
}
|
|
70
|
+
return getMagicStringResult();
|
|
71
|
+
}
|
|
@@ -9,23 +9,25 @@ function pluginSuppressRollupWarning() {
|
|
|
9
9
|
enforce: 'post',
|
|
10
10
|
configResolved: {
|
|
11
11
|
async handler(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
onWarnOriginal
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
Object.values(config.environments).forEach(({ build }) => {
|
|
13
|
+
const onWarnOriginal = build.rollupOptions.onwarn;
|
|
14
|
+
build.rollupOptions.onwarn = function (warning, warn) {
|
|
15
|
+
// Suppress
|
|
16
|
+
if (suppressUnusedImport(warning))
|
|
17
|
+
return;
|
|
18
|
+
if (suppressEmptyBundle(warning))
|
|
19
|
+
return;
|
|
20
|
+
if (suppressUseClientDirective(warning))
|
|
21
|
+
return;
|
|
22
|
+
// Pass through
|
|
23
|
+
if (onWarnOriginal) {
|
|
24
|
+
onWarnOriginal.apply(this, arguments);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
warn(warning);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
29
31
|
},
|
|
30
32
|
},
|
|
31
33
|
},
|
|
@@ -8,11 +8,11 @@ import { isObject } from '../../../utils/isObject.js';
|
|
|
8
8
|
import { assertRollupInput } from './build/pluginBuildConfig.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
|
|
11
|
-
import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
|
|
11
|
+
import { getVikeConfigInternal, setVikeConfigContext, setViteEnvironmentNames, } from '../shared/resolveVikeConfigInternal.js';
|
|
12
12
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigUser.js';
|
|
13
13
|
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
14
14
|
import { resolvePrerenderConfigGlobal, isDistServerRemoved } from '../../prerender/resolvePrerenderConfig.js';
|
|
15
|
-
import {
|
|
15
|
+
import { assertViteVersion } from '../../../utils/assertViteVersion.js';
|
|
16
16
|
import '../assertEnvVite.js';
|
|
17
17
|
const pluginName = 'vike:pluginCommon';
|
|
18
18
|
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
@@ -24,7 +24,9 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
24
24
|
config: {
|
|
25
25
|
order: 'pre',
|
|
26
26
|
async handler(configFromUser, env) {
|
|
27
|
-
|
|
27
|
+
// `this` is `undefined` on Vite 6 or older
|
|
28
|
+
const viteVersion = this?.meta.viteVersion;
|
|
29
|
+
assertViteVersion(viteVersion);
|
|
28
30
|
const isDev = isDevCheck(env);
|
|
29
31
|
const isBuild = env.command === 'build';
|
|
30
32
|
const isPreview = env.isPreview;
|
|
@@ -38,7 +40,7 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
38
40
|
const vikeConfig = await getVikeConfigInternal();
|
|
39
41
|
return {
|
|
40
42
|
_isDev: isDev,
|
|
41
|
-
_viteVersionResolved:
|
|
43
|
+
_viteVersionResolved: viteVersion,
|
|
42
44
|
_rootResolvedEarly: rootResolvedEarly,
|
|
43
45
|
// TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
|
|
44
46
|
configVikePromise: Promise.resolve({
|
|
@@ -52,9 +54,10 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
52
54
|
{
|
|
53
55
|
name: pluginName,
|
|
54
56
|
configResolved: {
|
|
55
|
-
handler(config) {
|
|
57
|
+
async handler(config) {
|
|
56
58
|
assertViteRoot(config._rootResolvedEarly, config);
|
|
57
59
|
assertSingleInstance(config);
|
|
60
|
+
await setViteEnvironmentNames(Object.keys(config.environments));
|
|
58
61
|
},
|
|
59
62
|
},
|
|
60
63
|
},
|
|
@@ -72,7 +75,7 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
72
75
|
overrideViteDefaultSsrExternal(config)
|
|
73
76
|
//*/
|
|
74
77
|
workaroundCI(config);
|
|
75
|
-
assertRollupInput(config);
|
|
78
|
+
assertRollupInput(config.build.rollupOptions.input);
|
|
76
79
|
assertResolveAlias(config);
|
|
77
80
|
temp_supportOldInterface(config);
|
|
78
81
|
await emitServerEntryOnlyIfNeeded(config);
|
|
@@ -181,7 +184,7 @@ async function disableAutoImportIfPrerendering(isBuild) {
|
|
|
181
184
|
return;
|
|
182
185
|
const vikeConfig = await getVikeConfigInternal();
|
|
183
186
|
const prerenderConfigGlobal = await resolvePrerenderConfigGlobal(vikeConfig);
|
|
184
|
-
if (isDistServerRemoved(prerenderConfigGlobal)) {
|
|
187
|
+
if (isDistServerRemoved(prerenderConfigGlobal, vikeConfig)) {
|
|
185
188
|
return { vitePluginServerEntry: { disableAutoImport: true } };
|
|
186
189
|
}
|
|
187
190
|
}
|
|
@@ -4,12 +4,12 @@ import type { ResolvedConfig } from 'vite';
|
|
|
4
4
|
import '../../assertEnvVite.js';
|
|
5
5
|
declare const optimizeDeps: {
|
|
6
6
|
readonly optimizeDeps: {
|
|
7
|
-
readonly exclude: ["vike/client", "vike/client/router"];
|
|
7
|
+
readonly exclude: ["vike/client", "vike/client/router", "vike/__internal/client"];
|
|
8
8
|
readonly include: ["vike > @brillout/json-serializer/parse", "vike > @brillout/json-serializer/stringify", "vike > @brillout/picocolors"];
|
|
9
9
|
};
|
|
10
10
|
readonly ssr: {
|
|
11
11
|
readonly optimizeDeps: {
|
|
12
|
-
readonly exclude: ["@brillout/import", "@brillout/json-serializer", "@brillout/vite-plugin-server-entry", "vike"];
|
|
12
|
+
readonly exclude: ["@brillout/import", "@brillout/json-serializer", "@brillout/vite-plugin-server-entry", "vike", "@universal-middleware/core"];
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
};
|
|
@@ -43,6 +43,8 @@ const optimizeDeps = {
|
|
|
43
43
|
// We must exclude Vike's client runtime so it can import virtual modules
|
|
44
44
|
'vike/client',
|
|
45
45
|
'vike/client/router',
|
|
46
|
+
// Also all entries of Vike's client runtime, otherwise pre-bundling an entry would load a second copy of Vike's client code (also problematic as it duplicates module-level variables that don't use `getGlobalObject()`)
|
|
47
|
+
'vike/__internal/client',
|
|
46
48
|
],
|
|
47
49
|
include: [
|
|
48
50
|
// Avoid:
|
|
@@ -65,6 +67,8 @@ const optimizeDeps = {
|
|
|
65
67
|
*/
|
|
66
68
|
'@brillout/vite-plugin-server-entry',
|
|
67
69
|
'vike',
|
|
70
|
+
// Needed so that Vike doesn't get the user's @universal-middleware/core version (that might differ from Vike's @universal-middleware/core version). (Vite pre-bundles one copy per package name for every importer: https://github.com/vitejs/vite/issues/9948)
|
|
71
|
+
'@universal-middleware/core',
|
|
68
72
|
],
|
|
69
73
|
},
|
|
70
74
|
},
|
|
@@ -191,7 +195,7 @@ async function getPageDeps(config, pageConfigs, pageConfigGlobal) {
|
|
|
191
195
|
[...pageConfigs, pageConfigGlobal].forEach((pageConfig) => {
|
|
192
196
|
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
193
197
|
const runtimeEnv = {
|
|
194
|
-
isForClientSide,
|
|
198
|
+
environmentName: isForClientSide ? 'client' : 'server',
|
|
195
199
|
isDev: true,
|
|
196
200
|
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
197
201
|
isClientRouting: true,
|
|
@@ -211,7 +215,7 @@ async function getPageDeps(config, pageConfigs, pageConfigGlobal) {
|
|
|
211
215
|
}
|
|
212
216
|
// V0.4 design
|
|
213
217
|
{
|
|
214
|
-
const pageFiles = await findPageFiles(config, ['.page', '.page.client']
|
|
218
|
+
const pageFiles = await findPageFiles(config, ['.page', '.page.client']);
|
|
215
219
|
const userRootDir = config.root;
|
|
216
220
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
217
221
|
const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
@@ -16,7 +16,10 @@ const filterRolldown = {
|
|
|
16
16
|
include: new RegExp(escapeRegex(VIRTUAL_FILE_ID_constantsGlobalThis)),
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
|
-
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis ||
|
|
19
|
+
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis ||
|
|
20
|
+
// Vite re-resolves the resolved ID and its URL when a plugin adds the module as a watch file (@vitejs/plugin-rsc)
|
|
21
|
+
id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis) ||
|
|
22
|
+
id === `/@id/__x00__${VIRTUAL_FILE_ID_constantsGlobalThis}`;
|
|
20
23
|
// ===
|
|
21
24
|
function pluginReplaceConstantsGlobalThis() {
|
|
22
25
|
let config;
|
|
@@ -63,9 +66,8 @@ function pluginReplaceConstantsGlobalThis() {
|
|
|
63
66
|
resolveId: {
|
|
64
67
|
filter: filterRolldown,
|
|
65
68
|
handler(id) {
|
|
66
|
-
assert(filterFunction(id));
|
|
67
|
-
|
|
68
|
-
return addVirtualFileIdPrefix(id);
|
|
69
|
+
assert(filterFunction(id), { id });
|
|
70
|
+
return addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
|
|
69
71
|
},
|
|
70
72
|
},
|
|
71
73
|
load: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getServerConfig };
|
|
2
2
|
export { isUniversalDeployVitePreview };
|
|
3
|
+
export { getServerEntryFilePath_ifDev };
|
|
3
4
|
import type { ResolvedConfig } from 'vite';
|
|
4
5
|
import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
6
|
import '../../assertEnvVite.js';
|
|
@@ -7,5 +8,7 @@ declare function getServerConfig(vikeConfig: VikeConfigInternal): {
|
|
|
7
8
|
serverEntryId: string;
|
|
8
9
|
serverEntryVike: string;
|
|
9
10
|
serverFilePath: string | null;
|
|
11
|
+
serverEntryFilePath: string | null;
|
|
10
12
|
} | undefined;
|
|
13
|
+
declare function getServerEntryFilePath_ifDev(vikeConfig: VikeConfigInternal): string | null;
|
|
11
14
|
declare function isUniversalDeployVitePreview(vikeConfig: VikeConfigInternal, viteConfigResolved: ResolvedConfig): boolean | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getServerConfig };
|
|
2
2
|
export { isUniversalDeployVitePreview };
|
|
3
|
+
export { getServerEntryFilePath_ifDev };
|
|
3
4
|
import { catchAllEntry } from '@universal-deploy/store';
|
|
4
5
|
import { assert } from '../../../../utils/assert.js';
|
|
5
6
|
import '../../assertEnvVite.js';
|
|
@@ -7,12 +8,15 @@ function getServerConfig(vikeConfig) {
|
|
|
7
8
|
let serverEntryId;
|
|
8
9
|
let serverFilePath = null;
|
|
9
10
|
let serverEntryVike;
|
|
11
|
+
const serverEntryFilePath = getServerEntryFilePath(vikeConfig);
|
|
10
12
|
// universal-deploy support must be manually enabled
|
|
11
13
|
const serverConfig =
|
|
12
14
|
// +config.js > `export default { server: true }`
|
|
13
15
|
vikeConfig.config.server ||
|
|
14
16
|
// +server.js exists
|
|
15
17
|
!!vikeConfig._pageConfigGlobal.configValueSources.server ||
|
|
18
|
+
// +serverEntry.js exists
|
|
19
|
+
!!serverEntryFilePath ||
|
|
16
20
|
false;
|
|
17
21
|
if (serverConfig === false)
|
|
18
22
|
return;
|
|
@@ -26,22 +30,44 @@ function getServerConfig(vikeConfig) {
|
|
|
26
30
|
}
|
|
27
31
|
else {
|
|
28
32
|
serverEntryId = catchAllEntry;
|
|
29
|
-
serverEntryVike = 'vike/fetch';
|
|
33
|
+
serverEntryVike = 'vike/__internal/fetch';
|
|
30
34
|
}
|
|
31
35
|
return {
|
|
32
36
|
// Used to filter which module ID to transform.
|
|
33
37
|
// It points to a fully resolved server entry or the virtual universal-deploy catchAll entry.
|
|
34
38
|
serverEntryId,
|
|
35
39
|
// This entry will be pushed to universal-deploy via `addEntry`.
|
|
36
|
-
// It either points to the default fetchable endpoint (vike/fetch), or one defined by the user through +server.
|
|
40
|
+
// It either points to the default fetchable endpoint (vike/__internal/fetch), or one defined by the user through +server.
|
|
37
41
|
serverEntryVike,
|
|
38
42
|
serverFilePath,
|
|
43
|
+
// +serverEntry.js => it's the production server entry dist/server/index.mjs (instead of @universal-deploy/node's)
|
|
44
|
+
serverEntryFilePath,
|
|
39
45
|
};
|
|
40
46
|
}
|
|
47
|
+
// https://vike.dev/serverEntry
|
|
48
|
+
function getServerEntryFilePath(vikeConfig) {
|
|
49
|
+
const source = vikeConfig._pageConfigGlobal.configValueSources.serverEntry?.[0];
|
|
50
|
+
if (!source)
|
|
51
|
+
return null;
|
|
52
|
+
assert(source.valueIsLoaded && source.valueIsFilePath && typeof source.value === 'string');
|
|
53
|
+
assert('filePathAbsoluteFilesystem' in source.definedAt);
|
|
54
|
+
// `source.value` is the import path, e.g. `some-npm-package/serverEntry` if the file cannot be resolved
|
|
55
|
+
return source.definedAt.filePathAbsoluteFilesystem ?? source.value;
|
|
56
|
+
}
|
|
57
|
+
// The +serverEntry.js that `$ vike dev` runs: only if there isn't +server.js (otherwise +serverEntry.js is production-only)
|
|
58
|
+
// https://vike.dev/serverEntry
|
|
59
|
+
function getServerEntryFilePath_ifDev(vikeConfig) {
|
|
60
|
+
if (vikeConfig._pageConfigGlobal.configValueSources.server)
|
|
61
|
+
return null;
|
|
62
|
+
return getServerEntryFilePath(vikeConfig);
|
|
63
|
+
}
|
|
41
64
|
function isUniversalDeployVitePreview(vikeConfig, viteConfigResolved) {
|
|
42
65
|
const isServerConfig = getServerConfig(vikeConfig);
|
|
43
66
|
if (!isServerConfig)
|
|
44
67
|
return null; // not UD
|
|
68
|
+
// +serverEntry.js => dist/server/index.mjs is the user's server entry => real preview
|
|
69
|
+
if (isServerConfig.serverEntryFilePath)
|
|
70
|
+
return false;
|
|
45
71
|
// @universal-deploy/node -> real preview
|
|
46
72
|
// else -> vite preview
|
|
47
73
|
const udNodePlugin = viteConfigResolved.plugins.find((p) => p.name.match(/^ud:node:(?!.*:disabled$)/));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { pluginServerEntryAlias };
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
3
|
import '../../assertEnvVite.js';
|
|
4
|
-
/**
|
|
4
|
+
/** `vike:server` => alias for virtual:ud:catch-all, also re-exporting the non-default exports of +server.js (if any) */
|
|
5
5
|
declare function pluginServerEntryAlias(serverFilePath?: string | null): Plugin;
|
|
@@ -1,35 +1,46 @@
|
|
|
1
1
|
export { pluginServerEntryAlias };
|
|
2
2
|
import { catchAllEntry } from '@universal-deploy/store';
|
|
3
|
+
import pc from '@brillout/picocolors';
|
|
3
4
|
import { pluginCommon } from './common.js';
|
|
4
5
|
import { escapeRegex } from '../../../../utils/escapeRegex.js';
|
|
5
|
-
import { assert } from '../../../../utils/assert.js';
|
|
6
|
+
import { assert, assertWarning } from '../../../../utils/assert.js';
|
|
6
7
|
import '../../assertEnvVite.js';
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const serverAlias = 'vike:server';
|
|
9
|
+
// TO-DO/next-major-release: remove
|
|
10
|
+
const serverAliasDeprecated = 'vike:server-entry';
|
|
11
|
+
const virtualFileId = '\0' + serverAlias;
|
|
9
12
|
// === Rolldown filter
|
|
10
|
-
const
|
|
13
|
+
const filterRolldownResolveId = {
|
|
11
14
|
id: {
|
|
12
|
-
include: [
|
|
15
|
+
include: [serverAlias, serverAliasDeprecated, virtualFileId].map((id) => new RegExp(`^${escapeRegex(id)}$`)),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filterRolldownLoad = {
|
|
19
|
+
id: {
|
|
20
|
+
include: [new RegExp(`^${escapeRegex(virtualFileId)}$`)],
|
|
13
21
|
},
|
|
14
22
|
};
|
|
15
23
|
// ===
|
|
16
|
-
/**
|
|
24
|
+
/** `vike:server` => alias for virtual:ud:catch-all, also re-exporting the non-default exports of +server.js (if any) */
|
|
17
25
|
function pluginServerEntryAlias(serverFilePath) {
|
|
18
26
|
return {
|
|
19
27
|
name: 'vike:pluginUniversalDeploy:alias',
|
|
20
28
|
resolveId: {
|
|
21
|
-
filter:
|
|
22
|
-
handler() {
|
|
29
|
+
filter: filterRolldownResolveId,
|
|
30
|
+
handler(id) {
|
|
31
|
+
assert(id === serverAlias || id === serverAliasDeprecated || id === virtualFileId);
|
|
32
|
+
assertWarning(id !== serverAliasDeprecated, `${pc.cyan(serverAliasDeprecated)} is deprecated in favor of ${pc.cyan(serverAlias)}, e.g. replace ${pc.cyan(`"main": "${serverAliasDeprecated}"`)} with ${pc.cyan(`"main": "${serverAlias}"`)} in your wrangler.jsonc`, { onlyOnce: true });
|
|
23
33
|
if (!serverFilePath)
|
|
24
34
|
return catchAllEntry;
|
|
25
35
|
return virtualFileId;
|
|
26
36
|
},
|
|
27
37
|
},
|
|
28
38
|
load: {
|
|
29
|
-
filter:
|
|
30
|
-
handler() {
|
|
39
|
+
filter: filterRolldownLoad,
|
|
40
|
+
handler(id) {
|
|
41
|
+
assert(id === virtualFileId);
|
|
31
42
|
assert(serverFilePath);
|
|
32
|
-
// Also re-export non-default exports, to support Durable Objects
|
|
43
|
+
// Also re-export non-default exports, e.g. to support Durable Objects
|
|
33
44
|
return `import mod from ${JSON.stringify(catchAllEntry)};
|
|
34
45
|
|
|
35
46
|
export * from ${JSON.stringify(serverFilePath)};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { pluginWrapServerFile };
|
|
2
|
+
import { wrapper } from 'vite-plugin-wrapper';
|
|
3
|
+
import { escapeRegex } from '../../../../utils/escapeRegex.js';
|
|
4
|
+
import '../../assertEnvVite.js';
|
|
5
|
+
function pluginWrapServerFile(serverFilePath) {
|
|
6
|
+
return wrapper({
|
|
7
|
+
resolveId: {
|
|
8
|
+
filter: {
|
|
9
|
+
id: new RegExp(`${escapeRegex(serverFilePath)}$`),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
load(id) {
|
|
13
|
+
return [
|
|
14
|
+
// === Side exports
|
|
15
|
+
`export * from ${JSON.stringify(id)};`,
|
|
16
|
+
'',
|
|
17
|
+
// === Default export
|
|
18
|
+
// `vikeFetch` acts as fallback if the user's +server.js doesn't export `fetch`
|
|
19
|
+
// - Example: https://vike.dev/cloudflare#durable-objects
|
|
20
|
+
// - Bloat (when `vikeFetch` isn't used) is negligible
|
|
21
|
+
"import vikeFetch from 'vike/__internal/fetch';",
|
|
22
|
+
`import * as mod from ${JSON.stringify(id)};`,
|
|
23
|
+
// Destructured because mod.default makes Rolldown warn when +server.js has no default export
|
|
24
|
+
'const { default: server } = mod;',
|
|
25
|
+
'export default { ...server, ...server?.prod, fetch: server?.fetch ?? vikeFetch.fetch };',
|
|
26
|
+
].join('\n');
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|