vike 0.4.196 → 0.4.197-commit-9db6c02
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/client/client-routing-runtime/prefetch/PrefetchSetting.js +2 -0
- package/dist/cjs/client/server-routing-runtime/onLoad.js +7 -0
- package/dist/cjs/client/server-routing-runtime/utils.js +34 -0
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +79 -0
- package/dist/cjs/client/shared/preparePageContextForUserConsumptionClientSide.js +46 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +17 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +26 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.js → transformPointerImports.js} +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +44 -47
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +5 -5
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +3 -3
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +1 -1
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -4
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -7
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/cjs/node/runtime/renderPage.js +8 -8
- package/dist/cjs/shared/addIs404ToPageProps.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/shared/preparePageContextForUserConsumption.js +34 -0
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/cjs/shared/route/index.js +3 -3
- package/dist/cjs/shared/route/resolveRouteString.js +10 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isNpmPackage.js +4 -0
- package/dist/cjs/utils/isScriptFile.js +3 -3
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +10 -0
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +25 -0
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +28 -18
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +39 -32
- package/dist/esm/client/client-routing-runtime/history.js +1 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/{installClientRouter.js → initClientRouter.js} +11 -8
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/{onLinkClick.js → initOnLinkClick.js} +2 -2
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +1 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
- package/dist/esm/client/client-routing-runtime/prefetch/PrefetchSetting.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/prefetch/PrefetchSetting.js +1 -0
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +8 -7
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.js +74 -67
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +16 -5
- package/dist/esm/client/client-routing-runtime/prefetch.js +167 -64
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +115 -28
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +1 -1
- package/dist/esm/client/shared/getPageContextSerializedInHtml.d.ts +1 -1
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +1 -1
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +20 -29
- package/dist/esm/client/shared/removeFoucBuster.js +17 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +17 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +25 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.d.ts → transformPointerImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.js → transformPointerImports.js} +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +45 -48
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +5 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +3 -3
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -4
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +6 -6
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/esm/node/runtime/renderPage.js +8 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -1
- package/dist/esm/shared/addIs404ToPageProps.js +1 -1
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +21 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +5 -0
- package/dist/esm/shared/preparePageContextForUserConsumption.js +32 -0
- package/dist/esm/shared/route/executeGuardHook.d.ts +1 -1
- package/dist/esm/shared/route/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/esm/shared/route/index.d.ts +1 -1
- package/dist/esm/shared/route/index.js +3 -3
- package/dist/esm/shared/route/resolveRouteString.d.ts +2 -15
- package/dist/esm/shared/route/resolveRouteString.js +10 -1
- package/dist/esm/shared/types.d.ts +6 -2
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isNpmPackage.d.ts +2 -0
- package/dist/esm/utils/isNpmPackage.js +4 -0
- package/dist/esm/utils/isScriptFile.d.ts +2 -2
- package/dist/esm/utils/isScriptFile.js +3 -3
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/shared/sortPageContext.js +0 -12
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/prefetch/alreadyPrefetched.d.ts +0 -4
- package/dist/esm/client/client-routing-runtime/prefetch/alreadyPrefetched.js +0 -16
- package/dist/esm/shared/sortPageContext.d.ts +0 -2
- package/dist/esm/shared/sortPageContext.js +0 -10
- /package/{readme.md → README.md} +0 -0
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
export { preparePageContextForUserConsumptionClientSide };
|
|
2
|
-
import { assert,
|
|
3
|
-
import { sortPageContext } from '../../shared/sortPageContext.js';
|
|
4
|
-
import { addIs404ToPageProps } from '../../shared/addIs404ToPageProps.js';
|
|
2
|
+
import { assert, objectAssign } from '../server-routing-runtime/utils.js';
|
|
5
3
|
import { getPageContextProxyForUser } from './getPageContextProxyForUser.js';
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
// This adds `assertPassToClient()`.
|
|
9
|
-
//
|
|
10
|
-
// With Vue support (when `pageContext` is made reactive with Vue).
|
|
11
|
-
//
|
|
12
|
-
// For Vue + Cient Routing, the `pageContext` needs to be made reactive:
|
|
13
|
-
// ```js
|
|
14
|
-
// import { reactive } from 'vue'
|
|
15
|
-
// // See entire example at `/examples/vue-full/`
|
|
16
|
-
// const pageContextReactive = reactive(pageContext)
|
|
17
|
-
// ```
|
|
4
|
+
import { preparePageContextForUserConsumption } from '../../shared/preparePageContextForUserConsumption.js';
|
|
18
5
|
function preparePageContextForUserConsumptionClientSide(pageContext, isClientRouting) {
|
|
19
6
|
if (isClientRouting) {
|
|
20
7
|
const pageContextTyped = pageContext;
|
|
@@ -26,22 +13,26 @@ function preparePageContextForUserConsumptionClientSide(pageContext, isClientRou
|
|
|
26
13
|
assert(pageContextTyped.isHydration === true);
|
|
27
14
|
assert(pageContextTyped.isBackwardNavigation === null);
|
|
28
15
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
assert('exports' in pageContext);
|
|
33
|
-
assert('exportsAll' in pageContext);
|
|
34
|
-
assert('pageExports' in pageContext);
|
|
35
|
-
assert(isObject(pageContext.pageExports));
|
|
36
|
-
const Page = pageContext.exports.Page;
|
|
16
|
+
const Page = pageContext.config.Page ||
|
|
17
|
+
// TODO/next-major-release: remove
|
|
18
|
+
pageContext.exports.Page;
|
|
37
19
|
objectAssign(pageContext, { Page });
|
|
38
|
-
//
|
|
20
|
+
// TODO/next-major-release: remove
|
|
21
|
+
// - Requires https://github.com/vikejs/vike-vue/issues/198
|
|
22
|
+
// - Last time I tried to remove it (https://github.com/vikejs/vike/commit/705fd23598d9d69bf46a52c8550216cd7117ce71) the tests were failing as expected: only the Vue integrations that used shallowReactive() failed.
|
|
23
|
+
supportVueReactiviy(pageContext);
|
|
24
|
+
preparePageContextForUserConsumption(pageContext);
|
|
25
|
+
const pageContextProxy = getPageContextProxyForUser(pageContext);
|
|
26
|
+
return pageContextProxy;
|
|
27
|
+
}
|
|
28
|
+
// With Vue + Cient Routing, the `pageContext` is made reactive:
|
|
29
|
+
// ```js
|
|
30
|
+
// import { reactive } from 'vue'
|
|
31
|
+
// // See /examples/vue-full/renderer/createVueApp.ts
|
|
32
|
+
// const pageContextReactive = reactive(pageContext)
|
|
33
|
+
// ```
|
|
34
|
+
function supportVueReactiviy(pageContext) {
|
|
39
35
|
resolveGetters(pageContext);
|
|
40
|
-
// For prettier `console.log(pageContext)`
|
|
41
|
-
sortPageContext(pageContext);
|
|
42
|
-
const pageContextForUserConsumption = getPageContextProxyForUser(pageContext);
|
|
43
|
-
addIs404ToPageProps(pageContext);
|
|
44
|
-
return pageContextForUserConsumption;
|
|
45
36
|
}
|
|
46
37
|
// Remove propery descriptor getters because they break Vue's reactivity.
|
|
47
38
|
// E.g. resolve the `pageContext.urlPathname` getter.
|
|
@@ -8,15 +8,16 @@ import { assert } from './utils.js';
|
|
|
8
8
|
function removeFoucBuster() {
|
|
9
9
|
assert(import.meta.env.DEV);
|
|
10
10
|
let sleep = 2;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
setTimeout(runClean, sleep);
|
|
12
|
+
return;
|
|
13
|
+
function runClean() {
|
|
14
|
+
const isCleaned = clean();
|
|
15
|
+
if (!isCleaned) {
|
|
14
16
|
if (sleep < 1000)
|
|
15
17
|
sleep = 2 * sleep;
|
|
16
18
|
setTimeout(runClean, sleep);
|
|
17
19
|
}
|
|
18
|
-
}
|
|
19
|
-
setTimeout(runClean, sleep);
|
|
20
|
+
}
|
|
20
21
|
}
|
|
21
22
|
function clean() {
|
|
22
23
|
const VITE_ID = 'data-vite-dev-id';
|
|
@@ -30,15 +31,20 @@ function clean() {
|
|
|
30
31
|
// - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/html/injectAssets/inferHtmlTags.ts#L35
|
|
31
32
|
// - https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/node/runtime/renderPage/getPageAssets.ts#L68
|
|
32
33
|
const injectedByVike = [...document.querySelectorAll(`link[rel="stylesheet"][type="text/css"][href$="${suffix}"]`)];
|
|
33
|
-
let
|
|
34
|
-
injectedByVike.forEach((
|
|
35
|
-
const
|
|
34
|
+
let isCleaned = true;
|
|
35
|
+
injectedByVike.forEach((linkVike) => {
|
|
36
|
+
const href = linkVike.getAttribute('href');
|
|
37
|
+
assert(href && href.endsWith(suffix));
|
|
38
|
+
let filePathAbsoluteUserRootDir = href.slice(0, -suffix.length);
|
|
39
|
+
const prefix = '/@fs/';
|
|
40
|
+
if (filePathAbsoluteUserRootDir.startsWith(prefix))
|
|
41
|
+
filePathAbsoluteUserRootDir = filePathAbsoluteUserRootDir.slice(prefix.length);
|
|
36
42
|
if (injectedByVite.some((filePathAbsoluteFilesystem) => filePathAbsoluteFilesystem.endsWith(filePathAbsoluteUserRootDir))) {
|
|
37
|
-
|
|
43
|
+
linkVike.remove();
|
|
38
44
|
}
|
|
39
45
|
else {
|
|
40
|
-
|
|
46
|
+
isCleaned = false;
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
|
-
return
|
|
49
|
+
return isCleaned;
|
|
44
50
|
}
|
|
@@ -67,6 +67,11 @@ const configDefinitionsBuiltIn = {
|
|
|
67
67
|
hydrationCanBeAborted: {
|
|
68
68
|
env: { client: true }
|
|
69
69
|
},
|
|
70
|
+
prefetch: {
|
|
71
|
+
env: { client: true },
|
|
72
|
+
eager: true
|
|
73
|
+
},
|
|
74
|
+
// TODO/v1-release: remove
|
|
70
75
|
prefetchStaticAssets: {
|
|
71
76
|
env: { client: true }
|
|
72
77
|
},
|
|
@@ -100,10 +105,12 @@ const configDefinitionsBuiltIn = {
|
|
|
100
105
|
},
|
|
101
106
|
onBeforeRenderEnv: {
|
|
102
107
|
env: { client: true },
|
|
108
|
+
eager: true,
|
|
103
109
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
104
110
|
},
|
|
105
111
|
dataEnv: {
|
|
106
112
|
env: { client: true },
|
|
113
|
+
eager: true,
|
|
107
114
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
108
115
|
},
|
|
109
116
|
hooksTimeout: {
|
|
@@ -120,6 +127,9 @@ const configDefinitionsBuiltIn = {
|
|
|
120
127
|
},
|
|
121
128
|
require: {
|
|
122
129
|
env: { config: true }
|
|
130
|
+
},
|
|
131
|
+
keepScrollPosition: {
|
|
132
|
+
env: { client: true }
|
|
123
133
|
}
|
|
124
134
|
};
|
|
125
135
|
const configDefinitionsBuiltInGlobal = {
|
|
@@ -146,7 +156,13 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
146
156
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
147
157
|
if (!configValueSource)
|
|
148
158
|
return null;
|
|
149
|
-
|
|
159
|
+
const { configEnv } = configValueSource;
|
|
160
|
+
const env = {};
|
|
161
|
+
if (configEnv.client)
|
|
162
|
+
env.client = true;
|
|
163
|
+
if (configEnv.server)
|
|
164
|
+
env.server = true;
|
|
165
|
+
return env;
|
|
150
166
|
}
|
|
151
167
|
function isConfigSet(configValueSources, configName) {
|
|
152
168
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -6,7 +6,7 @@ import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../.
|
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
import { parsePointerImportData } from './
|
|
9
|
+
import { parsePointerImportData } from './transformPointerImports.js';
|
|
10
10
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
11
|
import { resolvePointerImport } from './resolvePointerImport.js';
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
@@ -2,7 +2,7 @@ export { resolvePointerImportOfConfig };
|
|
|
2
2
|
export { resolvePointerImport };
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
4
|
import type { ConfigEnvInternal, DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
5
|
-
import { type PointerImportData } from './
|
|
5
|
+
import { type PointerImportData } from './transformPointerImports.js';
|
|
6
6
|
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
type PointerImportResolved = DefinedAtFilePath & {
|
|
8
8
|
fileExportName: string;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -3,7 +3,7 @@ export { resolvePointerImport };
|
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isFilePathAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
|
-
import { parsePointerImportData } from './
|
|
6
|
+
import { parsePointerImportData } from './transformPointerImports.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
9
9
|
const filesEnvMap = new Map();
|
|
@@ -16,7 +16,7 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
16
16
|
const { importPath, exportName } = pointerImportData;
|
|
17
17
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
18
18
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
19
|
-
|
|
19
|
+
assertUsageFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
20
20
|
return {
|
|
21
21
|
...filePath,
|
|
22
22
|
fileExportName: exportName,
|
|
@@ -24,33 +24,36 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
27
|
+
// `importPath` should be one of the following:
|
|
28
|
+
// - A relative import path
|
|
29
|
+
// - A filesystem absolute path
|
|
30
|
+
// - An npm package import
|
|
27
31
|
const { importPath } = pointerImportData;
|
|
28
32
|
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
29
33
|
let filePath;
|
|
30
|
-
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
31
|
-
// - A relative import path
|
|
32
|
-
// - A filesystem absolute path
|
|
33
|
-
// - An npm package import
|
|
34
|
-
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
35
34
|
assertPosixPath(importPath);
|
|
36
35
|
if (importPath.startsWith('.') || isFilePathAbsolute(importPath)) {
|
|
37
36
|
if (importPath.startsWith('.')) {
|
|
38
|
-
|
|
37
|
+
assertUsage(importPath.startsWith('./') || importPath.startsWith('../'), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
40
|
+
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
41
|
+
// Pointer imports are included in virtual files, and we need filePathAbsoluteUserRootDir because we didn't find a way to have filesystem absolute import paths in virtual files: https://gist.github.com/brillout/2315231c9a8164f950c64b4b4a7bbd39
|
|
42
|
+
const errSuffix = `outside of the ${userRootDir} directory which is forbidden: make sure your import paths resolve inside the ${userRootDir} directory, or import from an npm package.`;
|
|
41
43
|
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
if (importPath.startsWith('.')) {
|
|
45
|
+
assertUsage(filePathAbsoluteUserRootDir, `The relative import ${pc.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
assert(isFilePathAbsolute(importPath));
|
|
49
|
+
assertUsage(filePathAbsoluteUserRootDir, `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} is ${errSuffix}`);
|
|
50
|
+
}
|
|
51
|
+
// Forbid node_modules/ because it's brittle: if node_modules/ lives outside of userRootDir then it crashes.
|
|
52
|
+
assertUsage(!filePathAbsoluteUserRootDir.includes('/node_modules/'), `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} inside of node_modules/ which is forbbiden: use an npm package import instead.`);
|
|
48
53
|
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
49
54
|
}
|
|
50
55
|
else {
|
|
51
56
|
const importPathAbsolute = importPath;
|
|
52
|
-
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
53
|
-
assertIsNpmPackageImport(importPathAbsolute);
|
|
54
57
|
if (filePathAbsoluteFilesystem) {
|
|
55
58
|
filePath = getFilePathResolved({
|
|
56
59
|
userRootDir,
|
|
@@ -76,14 +79,14 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
76
79
|
const filePathAbsoluteFilesystem = requireResolve(pointerImportData.importPath, cwd);
|
|
77
80
|
return filePathAbsoluteFilesystem;
|
|
78
81
|
}
|
|
79
|
-
function
|
|
82
|
+
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
80
83
|
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
81
84
|
const { filePathToShowToUser } = importerFilePath;
|
|
82
85
|
if (!filePathAbsoluteFilesystem) {
|
|
83
|
-
const importPathString = pc.
|
|
86
|
+
const importPathString = pc.code(`${importPath}`);
|
|
84
87
|
const errIntro = importStringWasGenerated
|
|
85
88
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
86
|
-
: `The import ${pc.
|
|
89
|
+
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
87
90
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
88
91
|
if (importPath.startsWith('.')) {
|
|
89
92
|
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
@@ -94,7 +97,7 @@ function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importe
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
function
|
|
100
|
+
function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
98
101
|
let key;
|
|
99
102
|
if (filePathAbsoluteFilesystem) {
|
|
100
103
|
key = filePathAbsoluteFilesystem;
|
|
@@ -113,7 +116,7 @@ function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, config
|
|
|
113
116
|
if (configDifferentEnv) {
|
|
114
117
|
assertUsage(false, [
|
|
115
118
|
`${key} defines the value of configs living in different environments:`,
|
|
116
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.
|
|
119
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.code(c.configName)} which value lives in environment ${pc.code(JSON.stringify(c.configEnv))}`),
|
|
117
120
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
118
121
|
].join('\n'));
|
|
119
122
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
4
|
export type { PointerImportData };
|
|
5
|
-
declare function
|
|
5
|
+
declare function transformPointerImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
7
|
* Data Structure for [pointer imports](https://vike.dev/config#pointer-imports):
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -19,9 +19,8 @@ export { isPointerImportData };
|
|
|
19
19
|
import { parse } from 'acorn';
|
|
20
20
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
21
21
|
import pc from '@brillout/picocolors';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// For ./transformFileImports.spec.ts
|
|
22
|
+
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
23
|
+
// For ./transformPointerImports.spec.ts
|
|
25
24
|
skipWarnings) {
|
|
26
25
|
const spliceOperations = [];
|
|
27
26
|
// Performance trick
|
|
@@ -7,8 +7,8 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage,
|
|
11
|
-
import {
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport } from '../../../../utils.js';
|
|
11
|
+
import { transformPointerImports } from './transformPointerImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
14
|
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
@@ -17,7 +17,7 @@ const debug = createDebugger('vike:pointer-imports');
|
|
|
17
17
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
18
18
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
19
19
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
20
|
-
assertUsage(
|
|
20
|
+
assertUsage(isPlainJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
21
21
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
22
22
|
if (isHeader) {
|
|
23
23
|
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -45,17 +45,17 @@ async function transpileFile(filePath, transformImports, userRootDir) {
|
|
|
45
45
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
46
46
|
let isImportTransformed = false;
|
|
47
47
|
if (transformImports) {
|
|
48
|
-
const codeMod =
|
|
48
|
+
const codeMod = transformPointerImports(code, filePathToShowToUserResolved, pointerImports);
|
|
49
49
|
if (codeMod) {
|
|
50
50
|
code = codeMod;
|
|
51
51
|
isImportTransformed = true;
|
|
52
52
|
if (debug.isActivated)
|
|
53
|
-
debug(`code, post
|
|
53
|
+
debug(`code, post pointer imports transform (${filePathToShowToUserResolved})`, code);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
if (!isImportTransformed) {
|
|
57
57
|
if (debug.isActivated)
|
|
58
|
-
debug(`code, no
|
|
58
|
+
debug(`code, no pointer imports (${filePathToShowToUserResolved})`);
|
|
59
59
|
}
|
|
60
60
|
return code;
|
|
61
61
|
}
|
|
@@ -103,12 +103,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
103
103
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
104
104
|
const resolved = await build.resolve(path, opts);
|
|
105
105
|
if (resolved.errors.length > 0) {
|
|
106
|
-
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs
|
|
106
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs whereas esbuild refers to the source +config.ts file.
|
|
107
107
|
pointerImports[args.path] = false
|
|
108
108
|
return { external: true }
|
|
109
109
|
*/
|
|
110
|
-
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
111
110
|
cleanEsbuildErrors(resolved.errors);
|
|
111
|
+
// Let esbuild throw the error
|
|
112
112
|
return resolved;
|
|
113
113
|
}
|
|
114
114
|
assert(resolved.path);
|
|
@@ -116,73 +116,70 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
116
116
|
const importPathOriginal = args.path;
|
|
117
117
|
// Esbuild resolves path aliases.
|
|
118
118
|
// - Enabling us to use:
|
|
119
|
-
//
|
|
120
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
121
|
-
// assertIsNpmPackageImport()
|
|
122
|
-
// ```
|
|
119
|
+
// - assertIsNpmPackageImport()
|
|
120
|
+
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
123
121
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
124
122
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
125
123
|
// - This is temporary, see comment below.
|
|
126
|
-
const
|
|
124
|
+
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
127
125
|
const isPointerImport = transformImports === 'all' ||
|
|
128
|
-
// .jsx, .vue, .svg, ... => obviously not config code
|
|
129
|
-
!
|
|
130
|
-
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a
|
|
131
|
-
// -
|
|
126
|
+
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
127
|
+
!isPlainJavaScriptFile(importPathResolved) ||
|
|
128
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a config has been set by the user or by a Vike extension).
|
|
129
|
+
// - TODO/eventually: stop doing this and, instead, let Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
132
130
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
133
|
-
|
|
134
|
-
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
135
|
-
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
136
|
-
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
137
|
-
resolved.errors.length > 0;
|
|
131
|
+
isVikeExtensionImport;
|
|
138
132
|
assertPosixPath(importPathResolved);
|
|
139
133
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
140
134
|
const isExternal = isPointerImport ||
|
|
141
|
-
// Performance: npm package imports
|
|
135
|
+
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
142
136
|
isNodeModules;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
if (!isExternal) {
|
|
138
|
+
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
139
|
+
assert(!isPointerImport && !isNodeModules);
|
|
140
|
+
if (debug.isActivated)
|
|
141
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
142
|
+
return resolved;
|
|
143
|
+
}
|
|
147
144
|
let importPathTranspiled;
|
|
148
145
|
assertPosixPath(importPathOriginal);
|
|
149
146
|
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
150
|
-
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
151
|
-
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
152
|
-
// - ~~~js
|
|
153
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
154
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
155
|
-
// ~~~
|
|
156
|
-
// - ~~~js
|
|
157
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
158
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
159
|
-
// ~~~
|
|
160
|
-
assertUsage(filePathAbsoluteUserRootDir, `Import ${pc.cyan(importPathOriginal)} resolves to ${importPathResolved} outside of ${userRootDir} which is forbidden: make sure your relative import paths resolve inside ${userRootDir}, or import from an npm package.`);
|
|
161
147
|
importPathTranspiled = importPathResolved;
|
|
162
148
|
}
|
|
163
149
|
else {
|
|
164
|
-
// importPathOriginal is either:
|
|
150
|
+
// `importPathOriginal` is either:
|
|
165
151
|
// - Npm package import
|
|
166
152
|
// - Path alias
|
|
153
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({
|
|
154
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
155
|
+
userRootDir
|
|
156
|
+
});
|
|
157
|
+
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
167
158
|
if (filePathAbsoluteUserRootDir && !isNodeModules) {
|
|
168
|
-
// importPathOriginal is
|
|
159
|
+
// `importPathOriginal` is a path alias.
|
|
160
|
+
// - We have to use esbuild's path alias resolution, because:
|
|
161
|
+
// - Vike doesn't resolve path aliases at all.
|
|
162
|
+
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
163
|
+
// - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
169
164
|
importPathTranspiled = importPathResolved;
|
|
170
165
|
}
|
|
171
166
|
else {
|
|
172
|
-
// importPathOriginal is an npm package import.
|
|
167
|
+
// `importPathOriginal` is an npm package import.
|
|
173
168
|
assertIsNpmPackageImport(importPathOriginal);
|
|
169
|
+
// For less confusing error messages, let the resolution be handled by Vike or Node.js.
|
|
174
170
|
importPathTranspiled = importPathOriginal;
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
if (debug.isActivated)
|
|
178
174
|
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
175
|
+
assert(isExternal);
|
|
176
|
+
assert(
|
|
177
|
+
// Import of runtime code => handled by Vike
|
|
178
|
+
isPointerImport ||
|
|
179
|
+
// Import of config code => loaded by Node.js at build-time
|
|
180
|
+
isNodeModules);
|
|
181
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
182
|
+
return { external: true, path: importPathTranspiled };
|
|
186
183
|
});
|
|
187
184
|
}
|
|
188
185
|
},
|
|
@@ -237,7 +237,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
237
237
|
const importedFilesLoaded = {};
|
|
238
238
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
239
239
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
240
|
-
.filter(([
|
|
240
|
+
.filter(([pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
241
241
|
.map(async ([locationId]) => {
|
|
242
242
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
243
243
|
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
@@ -278,7 +278,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
278
278
|
objectAssign(pageContext, {
|
|
279
279
|
_providedByHook: null,
|
|
280
280
|
routeParams,
|
|
281
|
-
|
|
281
|
+
pageId: pageId,
|
|
282
282
|
_debugRouteMatches: [
|
|
283
283
|
{
|
|
284
284
|
pageId,
|
|
@@ -441,8 +441,8 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
441
441
|
const { urlOriginal } = pageContext;
|
|
442
442
|
assert(urlOriginal);
|
|
443
443
|
const pageContextFromRoute = await route(pageContext);
|
|
444
|
-
assert(hasProp(pageContextFromRoute, '
|
|
445
|
-
if (pageContextFromRoute.
|
|
444
|
+
assert(hasProp(pageContextFromRoute, 'pageId', 'null') || hasProp(pageContextFromRoute, 'pageId', 'string'));
|
|
445
|
+
if (pageContextFromRoute.pageId === null) {
|
|
446
446
|
let hookName;
|
|
447
447
|
let hookFilePath;
|
|
448
448
|
if (pageContext._providedByHook) {
|
|
@@ -464,9 +464,9 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
464
464
|
return;
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
assert(pageContextFromRoute.
|
|
467
|
+
assert(pageContextFromRoute.pageId);
|
|
468
468
|
objectAssign(pageContext, pageContextFromRoute);
|
|
469
|
-
const {
|
|
469
|
+
const { pageId: pageId } = pageContext;
|
|
470
470
|
objectAssign(pageContext, await loadUserFilesServerSide(pageContext));
|
|
471
471
|
let usesClientRouter;
|
|
472
472
|
{
|
|
@@ -14,7 +14,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
14
14
|
assert([true, false].includes(pageContext._isHtmlOnly));
|
|
15
15
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
16
16
|
const { isProduction } = getGlobalContext();
|
|
17
|
-
const injectScriptsAt = getInjectScriptsAt(pageContext.
|
|
17
|
+
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
18
18
|
const injectFilterEntries = pageAssets
|
|
19
19
|
.filter((asset) => {
|
|
20
20
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
@@ -14,7 +14,7 @@ async function injectAssets__public(htmlString, pageContext) {
|
|
|
14
14
|
assertUsage(hasProp(pageContext, 'urlPathname', 'string'), errMsg('`pageContext.urlPathname` should be a string'), {
|
|
15
15
|
showStackTrace: true
|
|
16
16
|
});
|
|
17
|
-
assertUsage(hasProp(pageContext, '
|
|
17
|
+
assertUsage(hasProp(pageContext, 'pageId', 'string'), errMsg('`pageContext.pageId` should be a string'), {
|
|
18
18
|
showStackTrace: true
|
|
19
19
|
});
|
|
20
20
|
assertUsage(hasProp(pageContext, '__getPageAssets'), errMsg('`pageContext.__getPageAssets` is missing'), {
|
|
@@ -11,7 +11,7 @@ import type { PageContextSerialization } from './serializePageContextClientSide.
|
|
|
11
11
|
type PageContextInjectAssets = {
|
|
12
12
|
urlPathname: string;
|
|
13
13
|
__getPageAssets: () => Promise<PageAsset[]>;
|
|
14
|
-
|
|
14
|
+
pageId: string;
|
|
15
15
|
_isHtmlOnly: boolean;
|
|
16
16
|
_pageContextPromise: PageContextPromise;
|
|
17
17
|
_renderHook: {
|
|
@@ -4,7 +4,7 @@ export type { PageContextSerialization };
|
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
6
6
|
type PageContextSerialization = {
|
|
7
|
-
|
|
7
|
+
pageId: string;
|
|
8
8
|
routeParams: Record<string, string>;
|
|
9
9
|
_passToClient: string[];
|
|
10
10
|
_pageConfigs: PageConfigRuntime[];
|
|
@@ -18,7 +18,7 @@ const PASS_TO_CLIENT = [
|
|
|
18
18
|
'_abortCaller',
|
|
19
19
|
*/
|
|
20
20
|
pageContextInitIsPassedToClient,
|
|
21
|
-
'
|
|
21
|
+
'pageId',
|
|
22
22
|
'routeParams',
|
|
23
23
|
'data' // for data() hook
|
|
24
24
|
];
|
|
@@ -95,7 +95,7 @@ function serialize(value, varName) {
|
|
|
95
95
|
}
|
|
96
96
|
function getPassToClient(pageContext) {
|
|
97
97
|
let passToClient = [...pageContext._passToClient, ...PASS_TO_CLIENT];
|
|
98
|
-
if (isErrorPage(pageContext.
|
|
98
|
+
if (isErrorPage(pageContext.pageId, pageContext._pageConfigs)) {
|
|
99
99
|
assert(hasProp(pageContext, 'is404', 'boolean'));
|
|
100
100
|
addIs404ToPageProps(pageContext);
|
|
101
101
|
passToClient.push(...PASS_TO_CLIENT_ERROR_PAGE);
|
|
@@ -20,7 +20,7 @@ type HttpResponse = {
|
|
|
20
20
|
contentType: 'application/json' | 'text/html;charset=utf-8';
|
|
21
21
|
} & HttpResponseBody;
|
|
22
22
|
declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null | RenderHook, pageContext: {
|
|
23
|
-
|
|
23
|
+
pageId: null | string;
|
|
24
24
|
is404: null | boolean;
|
|
25
25
|
errorWhileRendering: null | Error;
|
|
26
26
|
__getPageAssets: GetPageAssets;
|
|
@@ -12,7 +12,7 @@ import { assertNoInfiniteHttpRedirect } from './createHttpResponse/assertNoInfin
|
|
|
12
12
|
async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
13
13
|
let statusCode = pageContext.abortStatusCode;
|
|
14
14
|
if (!statusCode) {
|
|
15
|
-
const isError = !pageContext.
|
|
15
|
+
const isError = !pageContext.pageId || isErrorPage(pageContext.pageId, pageContext._pageConfigs);
|
|
16
16
|
if (pageContext.errorWhileRendering) {
|
|
17
17
|
assert(isError);
|
|
18
18
|
}
|
|
@@ -27,8 +27,8 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
|
27
27
|
}
|
|
28
28
|
const earlyHints = getEarlyHints(await pageContext.__getPageAssets());
|
|
29
29
|
const headers = [];
|
|
30
|
-
assert(pageContext.
|
|
31
|
-
const cacheControl = getCacheControl(pageContext.
|
|
30
|
+
assert(pageContext.pageId);
|
|
31
|
+
const cacheControl = getCacheControl(pageContext.pageId, pageContext._pageConfigs);
|
|
32
32
|
if (cacheControl) {
|
|
33
33
|
headers.push(['Cache-Control', cacheControl]);
|
|
34
34
|
}
|