vike 0.4.196-commit-df033dd → 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/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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Utils needed by Server Routing.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
// We assume all runtime entries will load this utils.ts file
|
|
19
|
+
const onLoad_js_1 = require("./onLoad.js");
|
|
20
|
+
(0, onLoad_js_1.onLoad)();
|
|
21
|
+
__exportStar(require("../../utils/assert.js"), exports);
|
|
22
|
+
__exportStar(require("../../utils/assertSingleInstance.js"), exports);
|
|
23
|
+
__exportStar(require("../../shared/hooks/executeHook.js"), exports);
|
|
24
|
+
__exportStar(require("../../utils/checkType.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
25
|
+
__exportStar(require("../../utils/getCurrentUrl.js"), exports);
|
|
26
|
+
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
27
|
+
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
28
|
+
__exportStar(require("../../utils/isCallable.js"), exports);
|
|
29
|
+
__exportStar(require("../../utils/isObject.js"), exports);
|
|
30
|
+
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
31
|
+
__exportStar(require("../../utils/parseUrl.js"), exports);
|
|
32
|
+
__exportStar(require("../../utils/slice.js"), exports);
|
|
33
|
+
__exportStar(require("../../utils/unique.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
34
|
+
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPageContextProxyForUser = getPageContextProxyForUser;
|
|
4
|
+
const utils_js_1 = require("../server-routing-runtime/utils.js");
|
|
5
|
+
const notSerializable_js_1 = require("../../shared/notSerializable.js");
|
|
6
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('getPageContextProxyForUser.ts', {});
|
|
7
|
+
/**
|
|
8
|
+
* Throw error when pageContext value isn't:
|
|
9
|
+
* - serializable, or
|
|
10
|
+
* - defined.
|
|
11
|
+
*/
|
|
12
|
+
function getPageContextProxyForUser(pageContext) {
|
|
13
|
+
(0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromServer));
|
|
14
|
+
(0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromClient));
|
|
15
|
+
return new Proxy(pageContext, {
|
|
16
|
+
get(_, prop) {
|
|
17
|
+
const val = pageContext[prop];
|
|
18
|
+
const propName = (0, utils_js_1.getPropAccessNotation)(prop);
|
|
19
|
+
(0, utils_js_1.assertUsage)(val !== notSerializable_js_1.notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
|
|
20
|
+
passToClientHint(pageContext, prop, propName);
|
|
21
|
+
return val;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function passToClientHint(pageContext, prop, propName) {
|
|
26
|
+
if (handleVueReactivity(prop))
|
|
27
|
+
return;
|
|
28
|
+
// `prop in pageContext` is the trick we use to know the passToClient value on the client-side, as we set a value to all passToClient props, even `undefined` ones:
|
|
29
|
+
// ```html
|
|
30
|
+
// <script id="vike_pageContext" type="application/json">{"pageProps":"!undefined"}</script>
|
|
31
|
+
// ```
|
|
32
|
+
if (prop in pageContext)
|
|
33
|
+
return;
|
|
34
|
+
if (isWhitelisted(prop))
|
|
35
|
+
return;
|
|
36
|
+
// The trick described above (`prop in pageContext`) doesn't work if Vike doesn't fetch any pageContext from the server.
|
|
37
|
+
// - There would still be some value to show a warning, but it isn't worth it because of the confusion that the first recommendation (adding `prop` to `passToClient`) wouldn't actually remove the warning, and only the second recommendation (using `prop in pageContext` instead of `pageContext[prop]`) would work.
|
|
38
|
+
if (!pageContext._hasPageContextFromServer)
|
|
39
|
+
return;
|
|
40
|
+
const errMsg = `pageContext${propName} isn't defined on the client-side, see https://vike.dev/passToClient#error`;
|
|
41
|
+
if (
|
|
42
|
+
// TODO/next-major-release always make it an error.
|
|
43
|
+
// - Remove pageContext._hasPageContextFromClient logic (IIRC this is its only use case).
|
|
44
|
+
pageContext._hasPageContextFromClient) {
|
|
45
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: false, showStackTrace: true });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const WHITELIST = [
|
|
52
|
+
'then',
|
|
53
|
+
// Vue calls toJSON()
|
|
54
|
+
'toJSON'
|
|
55
|
+
];
|
|
56
|
+
function isWhitelisted(prop) {
|
|
57
|
+
if (WHITELIST.includes(prop))
|
|
58
|
+
return true;
|
|
59
|
+
if (typeof prop === 'symbol')
|
|
60
|
+
return true; // Vue tries to access some symbols
|
|
61
|
+
if (typeof prop !== 'string')
|
|
62
|
+
return true;
|
|
63
|
+
if (prop.startsWith('__v_'))
|
|
64
|
+
return true; // Vue internals upon `reactive(pageContext)`
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Handle Vue's reactivity.
|
|
68
|
+
// When changing a reactive object:
|
|
69
|
+
// - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextReactive.routeParams = pageContextNew.routeParams` and `pageContextReactive` has no `routeParams`.
|
|
70
|
+
// - Vue seems to read __v_raw before reading the property.
|
|
71
|
+
function handleVueReactivity(prop) {
|
|
72
|
+
if (globalObject.prev === prop || globalObject.prev === '__v_raw')
|
|
73
|
+
return true;
|
|
74
|
+
globalObject.prev = prop;
|
|
75
|
+
window.setTimeout(() => {
|
|
76
|
+
globalObject.prev = undefined;
|
|
77
|
+
}, 0);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePageContextForUserConsumptionClientSide = preparePageContextForUserConsumptionClientSide;
|
|
4
|
+
const utils_js_1 = require("../server-routing-runtime/utils.js");
|
|
5
|
+
const getPageContextProxyForUser_js_1 = require("./getPageContextProxyForUser.js");
|
|
6
|
+
const preparePageContextForUserConsumption_js_1 = require("../../shared/preparePageContextForUserConsumption.js");
|
|
7
|
+
function preparePageContextForUserConsumptionClientSide(pageContext, isClientRouting) {
|
|
8
|
+
if (isClientRouting) {
|
|
9
|
+
const pageContextTyped = pageContext;
|
|
10
|
+
(0, utils_js_1.assert)([true, false].includes(pageContextTyped.isHydration));
|
|
11
|
+
(0, utils_js_1.assert)([true, false, null].includes(pageContextTyped.isBackwardNavigation));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const pageContextTyped = pageContext;
|
|
15
|
+
(0, utils_js_1.assert)(pageContextTyped.isHydration === true);
|
|
16
|
+
(0, utils_js_1.assert)(pageContextTyped.isBackwardNavigation === null);
|
|
17
|
+
}
|
|
18
|
+
const Page = pageContext.config.Page ||
|
|
19
|
+
// TODO/next-major-release: remove
|
|
20
|
+
pageContext.exports.Page;
|
|
21
|
+
(0, utils_js_1.objectAssign)(pageContext, { Page });
|
|
22
|
+
// TODO/next-major-release: remove
|
|
23
|
+
// - Requires https://github.com/vikejs/vike-vue/issues/198
|
|
24
|
+
// - 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.
|
|
25
|
+
supportVueReactiviy(pageContext);
|
|
26
|
+
(0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext);
|
|
27
|
+
const pageContextProxy = (0, getPageContextProxyForUser_js_1.getPageContextProxyForUser)(pageContext);
|
|
28
|
+
return pageContextProxy;
|
|
29
|
+
}
|
|
30
|
+
// With Vue + Cient Routing, the `pageContext` is made reactive:
|
|
31
|
+
// ```js
|
|
32
|
+
// import { reactive } from 'vue'
|
|
33
|
+
// // See /examples/vue-full/renderer/createVueApp.ts
|
|
34
|
+
// const pageContextReactive = reactive(pageContext)
|
|
35
|
+
// ```
|
|
36
|
+
function supportVueReactiviy(pageContext) {
|
|
37
|
+
resolveGetters(pageContext);
|
|
38
|
+
}
|
|
39
|
+
// Remove propery descriptor getters because they break Vue's reactivity.
|
|
40
|
+
// E.g. resolve the `pageContext.urlPathname` getter.
|
|
41
|
+
function resolveGetters(pageContext) {
|
|
42
|
+
Object.entries(pageContext).forEach(([key, val]) => {
|
|
43
|
+
delete pageContext[key];
|
|
44
|
+
pageContext[key] = val;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -68,6 +68,11 @@ const configDefinitionsBuiltIn = {
|
|
|
68
68
|
hydrationCanBeAborted: {
|
|
69
69
|
env: { client: true }
|
|
70
70
|
},
|
|
71
|
+
prefetch: {
|
|
72
|
+
env: { client: true },
|
|
73
|
+
eager: true
|
|
74
|
+
},
|
|
75
|
+
// TODO/v1-release: remove
|
|
71
76
|
prefetchStaticAssets: {
|
|
72
77
|
env: { client: true }
|
|
73
78
|
},
|
|
@@ -101,10 +106,12 @@ const configDefinitionsBuiltIn = {
|
|
|
101
106
|
},
|
|
102
107
|
onBeforeRenderEnv: {
|
|
103
108
|
env: { client: true },
|
|
109
|
+
eager: true,
|
|
104
110
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
105
111
|
},
|
|
106
112
|
dataEnv: {
|
|
107
113
|
env: { client: true },
|
|
114
|
+
eager: true,
|
|
108
115
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
109
116
|
},
|
|
110
117
|
hooksTimeout: {
|
|
@@ -121,6 +128,9 @@ const configDefinitionsBuiltIn = {
|
|
|
121
128
|
},
|
|
122
129
|
require: {
|
|
123
130
|
env: { config: true }
|
|
131
|
+
},
|
|
132
|
+
keepScrollPosition: {
|
|
133
|
+
env: { client: true }
|
|
124
134
|
}
|
|
125
135
|
};
|
|
126
136
|
exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
|
|
@@ -149,7 +159,13 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
149
159
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
150
160
|
if (!configValueSource)
|
|
151
161
|
return null;
|
|
152
|
-
|
|
162
|
+
const { configEnv } = configValueSource;
|
|
163
|
+
const env = {};
|
|
164
|
+
if (configEnv.client)
|
|
165
|
+
env.client = true;
|
|
166
|
+
if (configEnv.server)
|
|
167
|
+
env.server = true;
|
|
168
|
+
return env;
|
|
153
169
|
}
|
|
154
170
|
function isConfigSet(configValueSources, configName) {
|
|
155
171
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
11
11
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
12
12
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
|
-
const
|
|
14
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
15
15
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
16
16
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
17
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -94,7 +94,7 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
94
94
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
95
95
|
}
|
|
96
96
|
const extendsPointerImportData = extendList.map((importString) => {
|
|
97
|
-
const pointerImportData = (0,
|
|
97
|
+
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(importString);
|
|
98
98
|
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
99
99
|
return pointerImportData;
|
|
100
100
|
});
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -8,20 +8,20 @@ exports.resolvePointerImport = resolvePointerImport;
|
|
|
8
8
|
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
9
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
10
|
const utils_js_1 = require("../../../../utils.js");
|
|
11
|
-
const
|
|
11
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
13
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
14
14
|
const filesEnvMap = new Map();
|
|
15
15
|
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
16
16
|
if (typeof configValue !== 'string')
|
|
17
17
|
return null;
|
|
18
|
-
const pointerImportData = (0,
|
|
18
|
+
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(configValue);
|
|
19
19
|
if (!pointerImportData)
|
|
20
20
|
return null;
|
|
21
21
|
const { importPath, exportName } = pointerImportData;
|
|
22
22
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
23
23
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
24
|
-
|
|
24
|
+
assertUsageFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
25
25
|
return {
|
|
26
26
|
...filePath,
|
|
27
27
|
fileExportName: exportName,
|
|
@@ -29,33 +29,36 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
32
|
+
// `importPath` should be one of the following:
|
|
33
|
+
// - A relative import path
|
|
34
|
+
// - A filesystem absolute path
|
|
35
|
+
// - An npm package import
|
|
32
36
|
const { importPath } = pointerImportData;
|
|
33
37
|
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
34
38
|
let filePath;
|
|
35
|
-
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
36
|
-
// - A relative import path
|
|
37
|
-
// - A filesystem absolute path
|
|
38
|
-
// - An npm package import
|
|
39
|
-
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
40
39
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
41
40
|
if (importPath.startsWith('.') || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
42
41
|
if (importPath.startsWith('.')) {
|
|
43
|
-
(0, utils_js_1.
|
|
42
|
+
(0, utils_js_1.assertUsage)(importPath.startsWith('./') || importPath.startsWith('../'), `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
45
|
+
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
46
|
+
// 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
|
|
47
|
+
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.`;
|
|
46
48
|
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({ filePathAbsoluteFilesystem, userRootDir });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (importPath.startsWith('.')) {
|
|
50
|
+
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The relative import ${picocolors_1.default.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
(0, utils_js_1.assert)((0, utils_js_1.isFilePathAbsolute)(importPath));
|
|
54
|
+
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} is ${errSuffix}`);
|
|
55
|
+
}
|
|
56
|
+
// Forbid node_modules/ because it's brittle: if node_modules/ lives outside of userRootDir then it crashes.
|
|
57
|
+
(0, utils_js_1.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.`);
|
|
53
58
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
54
59
|
}
|
|
55
60
|
else {
|
|
56
61
|
const importPathAbsolute = importPath;
|
|
57
|
-
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
58
|
-
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
59
62
|
if (filePathAbsoluteFilesystem) {
|
|
60
63
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({
|
|
61
64
|
userRootDir,
|
|
@@ -81,14 +84,14 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
81
84
|
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(pointerImportData.importPath, cwd);
|
|
82
85
|
return filePathAbsoluteFilesystem;
|
|
83
86
|
}
|
|
84
|
-
function
|
|
87
|
+
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
85
88
|
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
86
89
|
const { filePathToShowToUser } = importerFilePath;
|
|
87
90
|
if (!filePathAbsoluteFilesystem) {
|
|
88
|
-
const importPathString = picocolors_1.default.
|
|
91
|
+
const importPathString = picocolors_1.default.code(`${importPath}`);
|
|
89
92
|
const errIntro = importStringWasGenerated
|
|
90
93
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
91
|
-
: `The import ${picocolors_1.default.
|
|
94
|
+
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
92
95
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
93
96
|
if (importPath.startsWith('.')) {
|
|
94
97
|
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
@@ -99,7 +102,7 @@ function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importe
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
|
-
function
|
|
105
|
+
function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
103
106
|
let key;
|
|
104
107
|
if (filePathAbsoluteFilesystem) {
|
|
105
108
|
key = filePathAbsoluteFilesystem;
|
|
@@ -118,7 +121,7 @@ function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, config
|
|
|
118
121
|
if (configDifferentEnv) {
|
|
119
122
|
(0, utils_js_1.assertUsage)(false, [
|
|
120
123
|
`${key} defines the value of configs living in different environments:`,
|
|
121
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.
|
|
124
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.code(c.configName)} which value lives in environment ${picocolors_1.default.code(JSON.stringify(c.configEnv))}`),
|
|
122
125
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
123
126
|
].join('\n'));
|
|
124
127
|
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.transformPointerImports = transformPointerImports;
|
|
7
7
|
exports.parsePointerImportData = parsePointerImportData;
|
|
8
8
|
exports.isPointerImportData = isPointerImportData;
|
|
9
9
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -24,9 +24,8 @@ exports.isPointerImportData = isPointerImportData;
|
|
|
24
24
|
const acorn_1 = require("acorn");
|
|
25
25
|
const utils_js_1 = require("../../../../utils.js");
|
|
26
26
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// For ./transformFileImports.spec.ts
|
|
27
|
+
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
28
|
+
// For ./transformPointerImports.spec.ts
|
|
30
29
|
skipWarnings) {
|
|
31
30
|
const spliceOperations = [];
|
|
32
31
|
// Performance trick
|
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const import_1 = require("@brillout/import");
|
|
15
15
|
const utils_js_1 = require("../../../../utils.js");
|
|
16
|
-
const
|
|
16
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
17
17
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
18
18
|
require("source-map-support/register.js");
|
|
19
19
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
@@ -22,7 +22,7 @@ const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
|
22
22
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
23
23
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
24
24
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
25
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.
|
|
25
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
26
26
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
27
27
|
if (isHeader) {
|
|
28
28
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -50,17 +50,17 @@ async function transpileFile(filePath, transformImports, userRootDir) {
|
|
|
50
50
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
51
51
|
let isImportTransformed = false;
|
|
52
52
|
if (transformImports) {
|
|
53
|
-
const codeMod = (0,
|
|
53
|
+
const codeMod = (0, transformPointerImports_js_1.transformPointerImports)(code, filePathToShowToUserResolved, pointerImports);
|
|
54
54
|
if (codeMod) {
|
|
55
55
|
code = codeMod;
|
|
56
56
|
isImportTransformed = true;
|
|
57
57
|
if (debug.isActivated)
|
|
58
|
-
debug(`code, post
|
|
58
|
+
debug(`code, post pointer imports transform (${filePathToShowToUserResolved})`, code);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
if (!isImportTransformed) {
|
|
62
62
|
if (debug.isActivated)
|
|
63
|
-
debug(`code, no
|
|
63
|
+
debug(`code, no pointer imports (${filePathToShowToUserResolved})`);
|
|
64
64
|
}
|
|
65
65
|
return code;
|
|
66
66
|
}
|
|
@@ -108,12 +108,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
108
108
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
109
109
|
const resolved = await build.resolve(path, opts);
|
|
110
110
|
if (resolved.errors.length > 0) {
|
|
111
|
-
/* 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
|
|
111
|
+
/* 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.
|
|
112
112
|
pointerImports[args.path] = false
|
|
113
113
|
return { external: true }
|
|
114
114
|
*/
|
|
115
|
-
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
116
115
|
cleanEsbuildErrors(resolved.errors);
|
|
116
|
+
// Let esbuild throw the error
|
|
117
117
|
return resolved;
|
|
118
118
|
}
|
|
119
119
|
(0, utils_js_1.assert)(resolved.path);
|
|
@@ -121,73 +121,70 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
121
121
|
const importPathOriginal = args.path;
|
|
122
122
|
// Esbuild resolves path aliases.
|
|
123
123
|
// - Enabling us to use:
|
|
124
|
-
//
|
|
125
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
126
|
-
// assertIsNpmPackageImport()
|
|
127
|
-
// ```
|
|
124
|
+
// - assertIsNpmPackageImport()
|
|
125
|
+
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
128
126
|
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
129
127
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
130
128
|
// - This is temporary, see comment below.
|
|
131
|
-
const
|
|
129
|
+
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
132
130
|
const isPointerImport = transformImports === 'all' ||
|
|
133
|
-
// .jsx, .vue, .svg, ... => obviously not config code
|
|
134
|
-
!(0, utils_js_1.
|
|
135
|
-
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a
|
|
136
|
-
// -
|
|
131
|
+
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
132
|
+
!(0, utils_js_1.isPlainJavaScriptFile)(importPathResolved) ||
|
|
133
|
+
// 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).
|
|
134
|
+
// - 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.
|
|
137
135
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
138
|
-
|
|
139
|
-
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
140
|
-
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
141
|
-
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
142
|
-
resolved.errors.length > 0;
|
|
136
|
+
isVikeExtensionImport;
|
|
143
137
|
(0, utils_js_1.assertPosixPath)(importPathResolved);
|
|
144
138
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
145
139
|
const isExternal = isPointerImport ||
|
|
146
|
-
// Performance: npm package imports
|
|
140
|
+
// 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.)
|
|
147
141
|
isNodeModules;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
if (!isExternal) {
|
|
143
|
+
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
144
|
+
(0, utils_js_1.assert)(!isPointerImport && !isNodeModules);
|
|
145
|
+
if (debug.isActivated)
|
|
146
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
152
149
|
let importPathTranspiled;
|
|
153
150
|
(0, utils_js_1.assertPosixPath)(importPathOriginal);
|
|
154
151
|
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
155
|
-
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
156
|
-
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
157
|
-
// - ~~~js
|
|
158
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
159
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
160
|
-
// ~~~
|
|
161
|
-
// - ~~~js
|
|
162
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
163
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
164
|
-
// ~~~
|
|
165
|
-
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `Import ${picocolors_1.default.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.`);
|
|
166
152
|
importPathTranspiled = importPathResolved;
|
|
167
153
|
}
|
|
168
154
|
else {
|
|
169
|
-
// importPathOriginal is either:
|
|
155
|
+
// `importPathOriginal` is either:
|
|
170
156
|
// - Npm package import
|
|
171
157
|
// - Path alias
|
|
158
|
+
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({
|
|
159
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
160
|
+
userRootDir
|
|
161
|
+
});
|
|
162
|
+
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
172
163
|
if (filePathAbsoluteUserRootDir && !isNodeModules) {
|
|
173
|
-
// importPathOriginal is
|
|
164
|
+
// `importPathOriginal` is a path alias.
|
|
165
|
+
// - We have to use esbuild's path alias resolution, because:
|
|
166
|
+
// - Vike doesn't resolve path aliases at all.
|
|
167
|
+
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
168
|
+
// - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
174
169
|
importPathTranspiled = importPathResolved;
|
|
175
170
|
}
|
|
176
171
|
else {
|
|
177
|
-
// importPathOriginal is an npm package import.
|
|
172
|
+
// `importPathOriginal` is an npm package import.
|
|
178
173
|
(0, utils_js_1.assertIsNpmPackageImport)(importPathOriginal);
|
|
174
|
+
// For less confusing error messages, let the resolution be handled by Vike or Node.js.
|
|
179
175
|
importPathTranspiled = importPathOriginal;
|
|
180
176
|
}
|
|
181
177
|
}
|
|
182
178
|
if (debug.isActivated)
|
|
183
179
|
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
180
|
+
(0, utils_js_1.assert)(isExternal);
|
|
181
|
+
(0, utils_js_1.assert)(
|
|
182
|
+
// Import of runtime code => handled by Vike
|
|
183
|
+
isPointerImport ||
|
|
184
|
+
// Import of config code => loaded by Node.js at build-time
|
|
185
|
+
isNodeModules);
|
|
186
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
187
|
+
return { external: true, path: importPathTranspiled };
|
|
191
188
|
});
|
|
192
189
|
}
|
|
193
190
|
},
|
|
@@ -243,7 +243,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
243
243
|
const importedFilesLoaded = {};
|
|
244
244
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
245
245
|
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
246
|
-
.filter(([
|
|
246
|
+
.filter(([pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
247
247
|
.map(async ([locationId]) => {
|
|
248
248
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
249
249
|
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
@@ -306,7 +306,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
306
306
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
307
307
|
_providedByHook: null,
|
|
308
308
|
routeParams,
|
|
309
|
-
|
|
309
|
+
pageId: pageId,
|
|
310
310
|
_debugRouteMatches: [
|
|
311
311
|
{
|
|
312
312
|
pageId,
|
|
@@ -469,8 +469,8 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
469
469
|
const { urlOriginal } = pageContext;
|
|
470
470
|
(0, utils_js_1.assert)(urlOriginal);
|
|
471
471
|
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
472
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromRoute, '
|
|
473
|
-
if (pageContextFromRoute.
|
|
472
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromRoute, 'pageId', 'null') || (0, utils_js_1.hasProp)(pageContextFromRoute, 'pageId', 'string'));
|
|
473
|
+
if (pageContextFromRoute.pageId === null) {
|
|
474
474
|
let hookName;
|
|
475
475
|
let hookFilePath;
|
|
476
476
|
if (pageContext._providedByHook) {
|
|
@@ -492,9 +492,9 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
492
492
|
return;
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
(0, utils_js_1.assert)(pageContextFromRoute.
|
|
495
|
+
(0, utils_js_1.assert)(pageContextFromRoute.pageId);
|
|
496
496
|
(0, utils_js_1.objectAssign)(pageContext, pageContextFromRoute);
|
|
497
|
-
const {
|
|
497
|
+
const { pageId: pageId } = pageContext;
|
|
498
498
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
499
499
|
let usesClientRouter;
|
|
500
500
|
{
|
|
@@ -19,7 +19,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
19
19
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
20
20
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
21
21
|
const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
|
|
22
|
-
const injectScriptsAt = getInjectScriptsAt(pageContext.
|
|
22
|
+
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
23
23
|
const injectFilterEntries = pageAssets
|
|
24
24
|
.filter((asset) => {
|
|
25
25
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
@@ -16,7 +16,7 @@ async function injectAssets__public(htmlString, pageContext) {
|
|
|
16
16
|
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, 'urlPathname', 'string'), errMsg('`pageContext.urlPathname` should be a string'), {
|
|
17
17
|
showStackTrace: true
|
|
18
18
|
});
|
|
19
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, '
|
|
19
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'string'), errMsg('`pageContext.pageId` should be a string'), {
|
|
20
20
|
showStackTrace: true
|
|
21
21
|
});
|
|
22
22
|
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, '__getPageAssets'), errMsg('`pageContext.__getPageAssets` is missing'), {
|
|
@@ -23,7 +23,7 @@ const PASS_TO_CLIENT = [
|
|
|
23
23
|
'_abortCaller',
|
|
24
24
|
*/
|
|
25
25
|
pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient,
|
|
26
|
-
'
|
|
26
|
+
'pageId',
|
|
27
27
|
'routeParams',
|
|
28
28
|
'data' // for data() hook
|
|
29
29
|
];
|
|
@@ -100,7 +100,7 @@ function serialize(value, varName) {
|
|
|
100
100
|
}
|
|
101
101
|
function getPassToClient(pageContext) {
|
|
102
102
|
let passToClient = [...pageContext._passToClient, ...PASS_TO_CLIENT];
|
|
103
|
-
if ((0, error_page_js_1.isErrorPage)(pageContext.
|
|
103
|
+
if ((0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs)) {
|
|
104
104
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'is404', 'boolean'));
|
|
105
105
|
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
106
106
|
passToClient.push(...PASS_TO_CLIENT_ERROR_PAGE);
|