vike 0.4.225 → 0.4.226
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/shared/getPageContextProxyForUser.js +3 -66
- package/dist/cjs/node/api/build.js +7 -7
- package/dist/cjs/node/api/dev.js +2 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +55 -30
- package/dist/cjs/node/api/prerender.js +2 -3
- package/dist/cjs/node/api/preview.js +27 -6
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/cli/entry.js +4 -2
- package/dist/cjs/node/cli/parseCli.js +10 -4
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +51 -0
- package/dist/cjs/node/plugin/plugins/build.js +3 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +8 -6
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +99 -85
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
- package/dist/cjs/node/plugin/shared/getEnvVarObject.js +7 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -3
- package/dist/cjs/node/prerender/runPrerender.js +8 -12
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -8
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +67 -14
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
- package/dist/cjs/node/runtime/renderPage.js +13 -28
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +2 -2
- package/dist/cjs/node/shared/assertV1Design.js +1 -1
- package/dist/cjs/node/shared/utils.js +1 -1
- package/dist/cjs/node/shared/virtual-files.js +14 -10
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +5 -0
- package/dist/cjs/shared/modifyUrl.js +3 -5
- package/dist/cjs/shared/modifyUrlSameOrigin.js +42 -0
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +3 -2
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +5 -5
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -9
- package/dist/cjs/shared/utils.js +2 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +10 -3
- package/dist/cjs/utils/assertSetup.js +12 -8
- package/dist/cjs/utils/getRandomId.js +1 -1
- package/dist/cjs/utils/isNullish.js +16 -0
- package/dist/cjs/utils/normalizeHeaders.js +1 -1
- package/dist/cjs/utils/objectAssign.js +7 -2
- package/dist/cjs/utils/objectFilter.js +10 -0
- package/dist/cjs/utils/pick.js +12 -0
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +6 -5
- package/dist/esm/client/client-routing-runtime/navigate.js +6 -2
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +6 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.js +6 -3
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +1 -11
- package/dist/esm/client/shared/getPageContextProxyForUser.js +4 -67
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.js +7 -7
- package/dist/esm/node/api/dev.js +2 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -1
- package/dist/esm/node/api/prepareViteApiCall.js +57 -32
- package/dist/esm/node/api/prerender.js +2 -3
- package/dist/esm/node/api/preview.d.ts +1 -1
- package/dist/esm/node/api/preview.js +24 -6
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/cli/entry.js +4 -2
- package/dist/esm/node/cli/parseCli.js +10 -4
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +49 -0
- package/dist/esm/node/plugin/plugins/build.js +3 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +3 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +8 -6
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +11 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +101 -86
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
- package/dist/esm/node/plugin/shared/getEnvVarObject.js +7 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +3 -3
- package/dist/esm/node/prerender/runPrerender.js +8 -12
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -3
- package/dist/esm/node/runtime/globalContext.js +13 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +69 -15
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
- package/dist/esm/node/runtime/renderPage.js +14 -29
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
- package/dist/esm/node/shared/assertV1Design.js +1 -1
- package/dist/esm/node/shared/utils.d.ts +1 -1
- package/dist/esm/node/shared/utils.js +1 -1
- package/dist/esm/node/shared/virtual-files.d.ts +2 -0
- package/dist/esm/node/shared/virtual-files.js +14 -10
- package/dist/esm/shared/NOT_SERIALIZABLE.d.ts +1 -0
- package/dist/esm/shared/NOT_SERIALIZABLE.js +2 -0
- package/dist/esm/shared/modifyUrl.d.ts +2 -2
- package/dist/esm/shared/modifyUrl.js +3 -5
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +9 -0
- package/dist/esm/shared/modifyUrlSameOrigin.js +40 -0
- package/dist/esm/shared/page-configs/Config.d.ts +11 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +3 -1
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +3 -2
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +5 -5
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -9
- package/dist/esm/shared/route/abort.d.ts +2 -2
- package/dist/esm/shared/types.d.ts +39 -3
- package/dist/esm/shared/utils.d.ts +2 -1
- package/dist/esm/shared/utils.js +2 -1
- package/dist/esm/types/index.d.ts +0 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.d.ts +2 -1
- package/dist/esm/utils/assert.js +10 -3
- package/dist/esm/utils/assertSetup.d.ts +2 -2
- package/dist/esm/utils/assertSetup.js +12 -8
- package/dist/esm/utils/getRandomId.d.ts +1 -1
- package/dist/esm/utils/getRandomId.js +1 -1
- package/dist/esm/utils/isNullish.d.ts +3 -0
- package/dist/esm/utils/isNullish.js +11 -0
- package/dist/esm/utils/normalizeHeaders.js +1 -1
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +7 -2
- package/dist/esm/utils/objectFilter.d.ts +1 -0
- package/dist/esm/utils/objectFilter.js +7 -0
- package/dist/esm/utils/pick.d.ts +1 -0
- package/dist/esm/utils/pick.js +9 -0
- package/package.json +4 -2
- package/dist/cjs/shared/notSerializable.js +0 -5
- package/dist/cjs/utils/isNotNullish.js +0 -5
- package/dist/esm/shared/notSerializable.d.ts +0 -1
- package/dist/esm/shared/notSerializable.js +0 -2
- package/dist/esm/utils/isNotNullish.d.ts +0 -1
- package/dist/esm/utils/isNotNullish.js +0 -1
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getViteDevScript = getViteDevScript;
|
|
7
7
|
const utils_js_1 = require("../../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
9
10
|
async function getViteDevScript(pageContext) {
|
|
10
11
|
const globalContext = pageContext._globalContext;
|
|
11
12
|
if (globalContext.isProduction) {
|
|
@@ -17,11 +18,13 @@ async function getViteDevScript(pageContext) {
|
|
|
17
18
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
18
19
|
fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
|
|
19
20
|
(0, utils_js_1.assertUsage)(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${picocolors_1.default.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
20
|
-
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')),
|
|
21
|
-
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd),
|
|
21
|
+
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
22
|
+
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
22
23
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
23
24
|
(0, utils_js_1.assert)(viteInjection.includes('script'));
|
|
24
|
-
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('),
|
|
25
|
+
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('), `Unexpected Vite injected HMR code. ${reachOutCTA}`, {
|
|
26
|
+
onlyOnce: true
|
|
27
|
+
});
|
|
25
28
|
const viteDevScript = viteInjection;
|
|
26
29
|
return viteDevScript;
|
|
27
30
|
}
|
|
@@ -5,12 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializePageContextClientSide = serializePageContextClientSide;
|
|
7
7
|
exports.serializePageContextAbort = serializePageContextAbort;
|
|
8
|
+
exports.getPropKeys = getPropKeys;
|
|
8
9
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
9
10
|
const utils_js_1 = require("../utils.js");
|
|
10
11
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
11
12
|
const addIs404ToPageProps_js_1 = require("../../../shared/addIs404ToPageProps.js");
|
|
12
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const
|
|
14
|
+
const NOT_SERIALIZABLE_js_1 = require("../../../shared/NOT_SERIALIZABLE.js");
|
|
14
15
|
const pageContextInitIsPassedToClient_js_1 = require("../../../shared/misc/pageContextInitIsPassedToClient.js");
|
|
15
16
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
16
17
|
const PASS_TO_CLIENT = [
|
|
@@ -30,12 +31,8 @@ const PASS_TO_CLIENT = [
|
|
|
30
31
|
const PASS_TO_CLIENT_ERROR_PAGE = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
|
|
31
32
|
function serializePageContextClientSide(pageContext) {
|
|
32
33
|
const passToClient = getPassToClient(pageContext);
|
|
33
|
-
const pageContextClient =
|
|
34
|
-
passToClient.
|
|
35
|
-
// We set non-existing props to `undefined`, in order to pass the list of passToClient values to the client-side
|
|
36
|
-
pageContextClient[prop] = pageContext[prop];
|
|
37
|
-
});
|
|
38
|
-
if (Object.keys(pageContext._pageContextInit).some((p) => passToClient.includes(p))) {
|
|
34
|
+
const pageContextClient = applyPassToClient(passToClient, pageContext);
|
|
35
|
+
if (passToClient.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
|
|
39
36
|
pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
|
|
40
37
|
}
|
|
41
38
|
let pageContextSerialized;
|
|
@@ -47,14 +44,15 @@ function serializePageContextClientSide(pageContext) {
|
|
|
47
44
|
let hasWarned = false;
|
|
48
45
|
const propsNonSerializable = [];
|
|
49
46
|
passToClient.forEach((prop) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const res = getPropVal(pageContext, prop);
|
|
48
|
+
if (!res)
|
|
49
|
+
return;
|
|
50
|
+
const { value } = res;
|
|
51
|
+
const varName = `pageContext${getPropKeys(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
|
|
53
52
|
try {
|
|
54
|
-
serialize(
|
|
53
|
+
serialize(value, varName);
|
|
55
54
|
}
|
|
56
55
|
catch (err) {
|
|
57
|
-
hasWarned = true;
|
|
58
56
|
propsNonSerializable.push(prop);
|
|
59
57
|
// useConfig() wrong usage
|
|
60
58
|
if (prop === '_configFromHook') {
|
|
@@ -67,7 +65,7 @@ function serializePageContextClientSide(pageContext) {
|
|
|
67
65
|
// Non-serializable pageContext set by the user
|
|
68
66
|
let msg = [
|
|
69
67
|
`${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
|
|
70
|
-
`Make sure ${h(varName)} is serializable, or remove ${h(
|
|
68
|
+
`Make sure ${h(varName)} is serializable, or remove ${h(JSON.stringify(prop))} from ${h('passToClient')}.`
|
|
71
69
|
].join(' ');
|
|
72
70
|
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
73
71
|
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
@@ -80,11 +78,12 @@ function serializePageContextClientSide(pageContext) {
|
|
|
80
78
|
}
|
|
81
79
|
// We warn (instead of throwing an error) since Vike's client runtime throws an error (with `assertUsage()`) if the user's client code tries to access the property that cannot be serialized
|
|
82
80
|
(0, utils_js_1.assertWarning)(false, msg, { onlyOnce: false });
|
|
81
|
+
hasWarned = true;
|
|
83
82
|
}
|
|
84
83
|
});
|
|
85
84
|
(0, utils_js_1.assert)(hasWarned);
|
|
86
85
|
propsNonSerializable.forEach((prop) => {
|
|
87
|
-
pageContextClient[prop] =
|
|
86
|
+
pageContextClient[getPropKeys(prop)[0]] = NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE;
|
|
88
87
|
});
|
|
89
88
|
try {
|
|
90
89
|
pageContextSerialized = serialize(pageContextClient);
|
|
@@ -143,3 +142,57 @@ function serializePageContextAbort(pageContext) {
|
|
|
143
142
|
}
|
|
144
143
|
return serialize(pageContext);
|
|
145
144
|
}
|
|
145
|
+
function applyPassToClient(passToClient, pageContext) {
|
|
146
|
+
const pageContextClient = {};
|
|
147
|
+
passToClient.forEach((prop) => {
|
|
148
|
+
// Get value from pageContext
|
|
149
|
+
const res = getPropVal(pageContext, prop);
|
|
150
|
+
if (!res)
|
|
151
|
+
return;
|
|
152
|
+
const { value } = res;
|
|
153
|
+
// Set value to pageContextClient
|
|
154
|
+
setPropVal(pageContextClient, prop, value);
|
|
155
|
+
});
|
|
156
|
+
return pageContextClient;
|
|
157
|
+
}
|
|
158
|
+
// Get a nested property from an object using a dot-separated path such as 'user.id'
|
|
159
|
+
function getPropVal(obj, prop) {
|
|
160
|
+
const keys = getPropKeys(prop);
|
|
161
|
+
let value = obj;
|
|
162
|
+
for (const key of keys) {
|
|
163
|
+
if ((0, utils_js_1.isObject)(value) && key in value) {
|
|
164
|
+
value = value[key];
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return null; // Property or intermediate property doesn't exist
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { value };
|
|
171
|
+
}
|
|
172
|
+
// Set a nested property in an object using a dot-separated path such as 'user.id'
|
|
173
|
+
function setPropVal(obj, prop, val) {
|
|
174
|
+
const keys = getPropKeys(prop);
|
|
175
|
+
let currentObj = obj;
|
|
176
|
+
// Creating intermediate objects if necessary
|
|
177
|
+
for (let i = 0; i <= keys.length - 2; i++) {
|
|
178
|
+
const key = keys[i];
|
|
179
|
+
if (!(key in currentObj)) {
|
|
180
|
+
// Create intermediate object
|
|
181
|
+
currentObj[key] = {};
|
|
182
|
+
}
|
|
183
|
+
if (!(0, utils_js_1.isObject)(currentObj[key])) {
|
|
184
|
+
// Skip value upon data structure conflict
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
currentObj = currentObj[key];
|
|
188
|
+
}
|
|
189
|
+
// Set the final key to the value
|
|
190
|
+
const finalKey = keys[keys.length - 1];
|
|
191
|
+
currentObj[finalKey] = val;
|
|
192
|
+
}
|
|
193
|
+
function getPropKeys(prop) {
|
|
194
|
+
// Like `prop.split('.')` but with added support for `\` escaping, see serializePageContextClientSide.spec.ts
|
|
195
|
+
return prop
|
|
196
|
+
.split(/(?<!\\)\./) // Split on unescaped dots
|
|
197
|
+
.map((key) => key.replace(/\\\./g, '.')); // Replace escaped dots with literal dots
|
|
198
|
+
}
|
|
@@ -9,14 +9,15 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
|
-
// It's too strict, see https://github.com/vikejs/vike/issues/1270#issuecomment-1820608999
|
|
13
|
-
// - Let's create a new setting `+doNotCatchInfiniteRedirect` if someone complains.
|
|
14
12
|
function assertNoInfiniteHttpRedirect(
|
|
15
13
|
// The exact URL that the user will be redirected to.
|
|
16
14
|
// - It includes the Base URL as well as the locale (i18n) base.
|
|
17
15
|
urlRedirectTarget,
|
|
18
16
|
// Rationale for checking against `pageContextInit.urlOriginal`: https://github.com/vikejs/vike/pull/2264#issuecomment-2713890263
|
|
19
17
|
pageContextInit) {
|
|
18
|
+
// TO-DO/eventually: use cookie as described at https://github.com/vikejs/vike/pull/2273
|
|
19
|
+
if (true)
|
|
20
|
+
return 'DISABLED'; // Disabled until we make it reliable.
|
|
20
21
|
if (!urlRedirectTarget.startsWith('/')) {
|
|
21
22
|
// We assume that urlRedirectTarget points to an origin that is external (not the same origin), and we can therefore assume that the app doesn't define an infinite loop (at least not in itself).
|
|
22
23
|
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin; we hope/assume the user sets the URL without origin.
|
|
@@ -9,5 +9,8 @@ function preparePageContextForUserConsumptionServerSide(pageContext) {
|
|
|
9
9
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.routeParams));
|
|
10
10
|
(0, utils_js_1.assert)('Page' in pageContext);
|
|
11
11
|
(0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
12
|
+
(0, utils_js_1.assert)(pageContext._isPageContextObject);
|
|
13
|
+
(0, utils_js_1.assert)(pageContext.isClientSide === false);
|
|
14
|
+
(0, utils_js_1.assert)(typeof pageContext.isPrerendering === 'boolean');
|
|
12
15
|
(0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext);
|
|
13
16
|
}
|
|
@@ -7,6 +7,7 @@ exports.renderPageAlreadyRouted = renderPageAlreadyRouted;
|
|
|
7
7
|
exports.prerenderPage = prerenderPage;
|
|
8
8
|
exports.prerender404Page = prerender404Page;
|
|
9
9
|
exports.getPageContextInitEnhanced = getPageContextInitEnhanced;
|
|
10
|
+
exports.createPageContext = createPageContext;
|
|
10
11
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
11
12
|
const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
12
13
|
const utils_js_1 = require("../utils.js");
|
|
@@ -89,7 +90,11 @@ async function prerender404Page(pageContextInit_, globalContext) {
|
|
|
89
90
|
if (!errorPageId) {
|
|
90
91
|
return null;
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
// A URL is required for `viteDevServer.transformIndexHtml(url,html)`
|
|
94
|
+
const pageContextInit = { urlOriginal: '/fake-404-url' };
|
|
95
|
+
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
96
|
+
const pageContext = await getPageContextInitEnhanced(pageContextInit, globalContext, true);
|
|
97
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
93
98
|
pageId: errorPageId,
|
|
94
99
|
_httpRequestId: null,
|
|
95
100
|
_urlRewrite: null,
|
|
@@ -98,25 +103,17 @@ async function prerender404Page(pageContextInit_, globalContext) {
|
|
|
98
103
|
// `prerender404Page()` is about generating `dist/client/404.html` for static hosts; there is no Client Routing.
|
|
99
104
|
_usesClientRouter: false,
|
|
100
105
|
_debugRouteMatches: []
|
|
101
|
-
};
|
|
102
|
-
const pageContextInit = {
|
|
103
|
-
urlOriginal: '/fake-404-url' // A URL is needed for `applyViteHtmlTransform`
|
|
104
|
-
};
|
|
105
|
-
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
106
|
-
{
|
|
107
|
-
const pageContextInitEnhanced = await getPageContextInitEnhanced(pageContextInit, globalContext);
|
|
108
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
109
|
-
}
|
|
106
|
+
});
|
|
110
107
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
111
108
|
return prerenderPage(pageContext);
|
|
112
109
|
}
|
|
113
|
-
async function getPageContextInitEnhanced(pageContextInit, globalContext, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } = {
|
|
110
|
+
async function getPageContextInitEnhanced(pageContextInit, globalContext, isPrerendering, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } = {
|
|
114
111
|
urlRewrite: null,
|
|
115
112
|
urlHandler: null,
|
|
116
113
|
isClientSideNavigation: false
|
|
117
114
|
} } = {}) {
|
|
118
115
|
(0, utils_js_1.assert)(pageContextInit.urlOriginal);
|
|
119
|
-
const pageContextInitEnhanced =
|
|
116
|
+
const pageContextInitEnhanced = createPageContext(pageContextInit, isPrerendering);
|
|
120
117
|
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, pageContextInit);
|
|
121
118
|
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, {
|
|
122
119
|
_objectCreatedByVike: true,
|
|
@@ -163,3 +160,12 @@ async function getPageContextInitEnhanced(pageContextInit, globalContext, { ssr:
|
|
|
163
160
|
}
|
|
164
161
|
return pageContextInitEnhanced;
|
|
165
162
|
}
|
|
163
|
+
function createPageContext(pageContextInit, isPrerendering) {
|
|
164
|
+
const pageContext = {
|
|
165
|
+
_isPageContextObject: true,
|
|
166
|
+
isClientSide: false,
|
|
167
|
+
isPrerendering
|
|
168
|
+
};
|
|
169
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextInit);
|
|
170
|
+
return pageContext;
|
|
171
|
+
}
|
|
@@ -108,15 +108,9 @@ async function renderPageAlreadyPrepared(pageContextInit, globalContext, httpReq
|
|
|
108
108
|
// https://stackoverflow.com/questions/9683007/detect-infinite-http-redirect-loop-on-server-side
|
|
109
109
|
0);
|
|
110
110
|
let pageContextNominalPageSuccess;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
(0, utils_js_1.objectAssign)(pageContextNominalPageInit, pageContextFromAllRewrites);
|
|
115
|
-
}
|
|
116
|
-
{
|
|
117
|
-
const pageContextInitEnhanced = await getPageContextInitEnhancedSSR(pageContextInit, globalContext, pageContextNominalPageInit._urlRewrite, httpRequestId);
|
|
118
|
-
(0, utils_js_1.objectAssign)(pageContextNominalPageInit, pageContextInitEnhanced);
|
|
119
|
-
}
|
|
111
|
+
const pageContextFromAllRewrites = (0, abort_js_1.getPageContextFromAllRewrites)(pageContextsFromRewrite);
|
|
112
|
+
const pageContextNominalPageInit = await getPageContextInitEnhancedSSR(pageContextInit, globalContext, pageContextFromAllRewrites._urlRewrite, httpRequestId);
|
|
113
|
+
(0, utils_js_1.objectAssign)(pageContextNominalPageInit, pageContextFromAllRewrites);
|
|
120
114
|
let errNominalPage;
|
|
121
115
|
{
|
|
122
116
|
try {
|
|
@@ -247,7 +241,7 @@ function prettyUrl(url) {
|
|
|
247
241
|
return picocolors_1.default.bold(decodeURI(url));
|
|
248
242
|
}
|
|
249
243
|
function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
|
|
250
|
-
const pageContextWithError = createPageContext(pageContextInit);
|
|
244
|
+
const pageContextWithError = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
251
245
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseError)(pageContext);
|
|
252
246
|
(0, utils_js_1.objectAssign)(pageContextWithError, {
|
|
253
247
|
httpResponse,
|
|
@@ -255,13 +249,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
|
|
|
255
249
|
});
|
|
256
250
|
return pageContextWithError;
|
|
257
251
|
}
|
|
258
|
-
function createPageContext(pageContextInit) {
|
|
259
|
-
const pageContext = {
|
|
260
|
-
_isPageContextObject: true
|
|
261
|
-
};
|
|
262
|
-
Object.assign(pageContext, pageContextInit);
|
|
263
|
-
return pageContext;
|
|
264
|
-
}
|
|
265
252
|
async function renderPageNominal(pageContext) {
|
|
266
253
|
(0, utils_js_1.objectAssign)(pageContext, { errorWhileRendering: null });
|
|
267
254
|
// Route
|
|
@@ -286,10 +273,8 @@ async function renderPageNominal(pageContext) {
|
|
|
286
273
|
return pageContextAfterRender;
|
|
287
274
|
}
|
|
288
275
|
async function getPageContextErrorPageInit(pageContextInit, globalContext, errNominalPage, pageContextNominalPagePartial, httpRequestId) {
|
|
289
|
-
const
|
|
276
|
+
const pageContext = await getPageContextInitEnhancedSSR(pageContextInit, globalContext, null, httpRequestId);
|
|
290
277
|
(0, utils_js_1.assert)(errNominalPage);
|
|
291
|
-
const pageContext = {};
|
|
292
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
293
278
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
294
279
|
is404: false,
|
|
295
280
|
errorWhileRendering: errNominalPage,
|
|
@@ -303,7 +288,7 @@ async function getPageContextErrorPageInit(pageContextInit, globalContext, errNo
|
|
|
303
288
|
}
|
|
304
289
|
async function getPageContextInitEnhancedSSR(pageContextInit, globalContext, urlRewrite, httpRequestId) {
|
|
305
290
|
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
306
|
-
const pageContextInitEnhanced = await (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, globalContext, {
|
|
291
|
+
const pageContextInitEnhanced = await (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, globalContext, false, {
|
|
307
292
|
ssr: {
|
|
308
293
|
urlRewrite,
|
|
309
294
|
urlHandler: _urlHandler,
|
|
@@ -347,7 +332,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
347
332
|
return null;
|
|
348
333
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
349
334
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit);
|
|
350
|
-
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
335
|
+
const pageContextHttpResponse = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
351
336
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
352
337
|
return pageContextHttpResponse;
|
|
353
338
|
}
|
|
@@ -389,7 +374,7 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
389
374
|
}
|
|
390
375
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
391
376
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlTarget, statusCode: 301 }, pageContextInit);
|
|
392
|
-
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
377
|
+
const pageContextHttpResponse = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
393
378
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
394
379
|
return pageContextHttpResponse;
|
|
395
380
|
}
|
|
@@ -410,10 +395,10 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
410
395
|
const abortCall = pageContextAbort._abortCall;
|
|
411
396
|
(0, utils_js_1.assert)(abortCall);
|
|
412
397
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
413
|
-
const pageContext = createPageContext({});
|
|
398
|
+
const pageContext = (0, renderPageAlreadyRouted_js_1.createPageContext)({}, false);
|
|
414
399
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
415
400
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
416
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
401
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
417
402
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
418
403
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
419
404
|
pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext);
|
|
@@ -434,7 +419,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
434
419
|
return { pageContextReturn };
|
|
435
420
|
}
|
|
436
421
|
if (pageContextAbort._urlRedirect) {
|
|
437
|
-
const pageContextReturn = createPageContext(pageContextInit);
|
|
422
|
+
const pageContextReturn = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
438
423
|
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
439
424
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)(pageContextAbort._urlRedirect, pageContextInit);
|
|
440
425
|
(0, utils_js_1.objectAssign)(pageContextReturn, { httpResponse });
|
|
@@ -449,7 +434,7 @@ async function checkBaseUrl(pageContextInit, globalContext) {
|
|
|
449
434
|
const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlOriginal, baseServer);
|
|
450
435
|
if (!isBaseMissing)
|
|
451
436
|
return;
|
|
452
|
-
const pageContext = createPageContext(pageContextInit);
|
|
437
|
+
const pageContext = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
453
438
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseBaseIsMissing)(urlOriginal, baseServer);
|
|
454
439
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
455
440
|
httpResponse,
|
|
@@ -462,7 +447,7 @@ function renderInvalidRequest(pageContextInit) {
|
|
|
462
447
|
const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
|
|
463
448
|
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
464
449
|
if (urlPathnameWithBase.endsWith('/favicon.ico')) {
|
|
465
|
-
const pageContext = createPageContext(pageContextInit);
|
|
450
|
+
const pageContext = (0, renderPageAlreadyRouted_js_1.createPageContext)(pageContextInit, false);
|
|
466
451
|
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
|
|
467
452
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
468
453
|
(0, utils_js_1.checkType)(pageContext);
|
|
@@ -51,7 +51,7 @@ __exportStar(require("../../utils/urlToFile.js"), exports);
|
|
|
51
51
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
52
52
|
__exportStar(require("../../utils/freezePartial.js"), exports);
|
|
53
53
|
__exportStar(require("../../utils/isNpmPackage.js"), exports);
|
|
54
|
-
__exportStar(require("../../utils/
|
|
54
|
+
__exportStar(require("../../utils/isNullish.js"), exports);
|
|
55
55
|
__exportStar(require("../../utils/isScriptFile.js"), exports);
|
|
56
56
|
__exportStar(require("../../utils/removeFileExtention.js"), exports);
|
|
57
57
|
__exportStar(require("../../utils/objectKeys.js"), exports);
|
|
@@ -22,8 +22,8 @@ async function createDevMiddleware(options = {}) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
const {
|
|
26
|
-
const server = await (0, vite_1.createServer)(
|
|
25
|
+
const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(optionsMod, 'dev');
|
|
26
|
+
const server = await (0, vite_1.createServer)(viteConfigFromUserEnhanced);
|
|
27
27
|
const devMiddleware = server.middlewares;
|
|
28
28
|
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
29
29
|
}
|
|
@@ -12,7 +12,7 @@ function assertV1Design(pageConfigs, pageFilesAll) {
|
|
|
12
12
|
(0, utils_js_1.assert)(pageConfigs.length > 0);
|
|
13
13
|
const filesV1 = (0, utils_js_1.unique)(pageConfigs
|
|
14
14
|
.map((p) => Object.values(p.configValueSources).map((sources) => sources
|
|
15
|
-
.map((c) => c.
|
|
15
|
+
.map((c) => c.definedAt)
|
|
16
16
|
.map((definedAt) => (definedAt.definedBy ? null : definedAt.filePathAbsoluteUserRootDir))
|
|
17
17
|
.filter(utils_js_1.isNotNullish)
|
|
18
18
|
.map((filePathToShowToUser) => indent + filePathToShowToUser)))
|
|
@@ -28,6 +28,6 @@ __exportStar(require("../../utils/parseUrl.js"), exports);
|
|
|
28
28
|
__exportStar(require("../../utils/parseUrl-extras.js"), exports);
|
|
29
29
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
30
30
|
__exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
|
|
31
|
-
__exportStar(require("../../utils/
|
|
31
|
+
__exportStar(require("../../utils/isNullish.js"), exports);
|
|
32
32
|
__exportStar(require("../../utils/unique.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/debug.js"), exports);
|
|
@@ -6,32 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.isVirtualFileId = isVirtualFileId;
|
|
7
7
|
exports.getVirtualFileId = getVirtualFileId;
|
|
8
8
|
exports.resolveVirtualFileId = resolveVirtualFileId;
|
|
9
|
+
exports.removeVirtualIdTag = removeVirtualIdTag;
|
|
9
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
11
|
const utils_js_1 = require("./utils.js");
|
|
11
12
|
const idBase = 'virtual:vike:';
|
|
12
13
|
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
|
|
13
|
-
const
|
|
14
|
+
const virtualIdTag = '\0';
|
|
14
15
|
function isVirtualFileId(id) {
|
|
15
16
|
if (id.startsWith(idBase))
|
|
16
17
|
return true;
|
|
17
|
-
if (id.startsWith(
|
|
18
|
+
if (id.startsWith(virtualIdTag + idBase))
|
|
18
19
|
return true;
|
|
19
20
|
// https://github.com/vikejs/vike/issues/1985
|
|
20
21
|
(0, utils_js_1.assertUsage)(!id.includes(idBase), `Encountered a module ID ${picocolors_1.default.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
23
24
|
function getVirtualFileId(id) {
|
|
24
|
-
|
|
25
|
-
id = id.slice(tag.length);
|
|
26
|
-
}
|
|
27
|
-
(0, utils_js_1.assert)(!id.startsWith(tag));
|
|
28
|
-
return id;
|
|
25
|
+
return removeVirtualIdTag(id);
|
|
29
26
|
}
|
|
30
27
|
function resolveVirtualFileId(id) {
|
|
31
28
|
(0, utils_js_1.assert)(isVirtualFileId(id));
|
|
32
|
-
if (!id.startsWith(
|
|
33
|
-
id =
|
|
29
|
+
if (!id.startsWith(virtualIdTag)) {
|
|
30
|
+
id = virtualIdTag + id;
|
|
31
|
+
}
|
|
32
|
+
(0, utils_js_1.assert)(id.startsWith(virtualIdTag));
|
|
33
|
+
return id;
|
|
34
|
+
}
|
|
35
|
+
function removeVirtualIdTag(id) {
|
|
36
|
+
if (id.startsWith(virtualIdTag)) {
|
|
37
|
+
id = id.slice(virtualIdTag.length);
|
|
34
38
|
}
|
|
35
|
-
(0, utils_js_1.assert)(id.startsWith(
|
|
39
|
+
(0, utils_js_1.assert)(!id.startsWith(virtualIdTag));
|
|
36
40
|
return id;
|
|
37
41
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.modifyUrl = modifyUrl;
|
|
4
|
+
const modifyUrlSameOrigin_js_1 = require("./modifyUrlSameOrigin.js");
|
|
4
5
|
const utils_js_1 = require("./utils.js");
|
|
5
6
|
/**
|
|
6
7
|
* Modify a URL.
|
|
@@ -10,9 +11,8 @@ const utils_js_1 = require("./utils.js");
|
|
|
10
11
|
* https://vike.dev/modifyUrl
|
|
11
12
|
*/
|
|
12
13
|
function modifyUrl(url, modify) {
|
|
14
|
+
url = (0, modifyUrlSameOrigin_js_1.modifyUrlSameOrigin)(url, modify);
|
|
13
15
|
const urlParsed = (0, utils_js_1.parseUrl)(url, '/');
|
|
14
|
-
// Pathname
|
|
15
|
-
const pathname = modify.pathname ?? urlParsed.pathname;
|
|
16
16
|
// Origin
|
|
17
17
|
const originParts = [
|
|
18
18
|
modify.protocol ?? urlParsed.protocol ?? '',
|
|
@@ -23,8 +23,6 @@ function modifyUrl(url, modify) {
|
|
|
23
23
|
originParts.push(`:${port}`);
|
|
24
24
|
}
|
|
25
25
|
const origin = originParts.join('');
|
|
26
|
-
const urlModified = (0, utils_js_1.createUrlFromComponents)(origin, pathname,
|
|
27
|
-
// Should we also support modifying search and hash?
|
|
28
|
-
urlParsed.searchOriginal, urlParsed.hashOriginal);
|
|
26
|
+
const urlModified = (0, utils_js_1.createUrlFromComponents)(origin, urlParsed.pathname, urlParsed.searchOriginal, urlParsed.hashOriginal);
|
|
29
27
|
return urlModified;
|
|
30
28
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modifyUrlSameOrigin = modifyUrlSameOrigin;
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
function modifyUrlSameOrigin(url, modify) {
|
|
6
|
+
const urlParsed = (0, utils_js_1.parseUrl)(url, '/');
|
|
7
|
+
// Pathname
|
|
8
|
+
const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
|
|
9
|
+
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(pathname, 'modify.pathname');
|
|
10
|
+
// Search
|
|
11
|
+
let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
|
|
12
|
+
if (search === '?')
|
|
13
|
+
search = '';
|
|
14
|
+
// Hash
|
|
15
|
+
let hash;
|
|
16
|
+
if (modify.hash === null) {
|
|
17
|
+
hash = '';
|
|
18
|
+
}
|
|
19
|
+
else if (modify.hash === undefined) {
|
|
20
|
+
hash = urlParsed.hashOriginal ?? '';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
hash = modify.hash;
|
|
24
|
+
if (!hash.startsWith('#'))
|
|
25
|
+
hash = '#' + hash;
|
|
26
|
+
}
|
|
27
|
+
const urlModified = (0, utils_js_1.createUrlFromComponents)(urlParsed.origin, pathname, search, hash);
|
|
28
|
+
return urlModified;
|
|
29
|
+
}
|
|
30
|
+
function resolveSearch(urlParsed, search) {
|
|
31
|
+
let searchParams;
|
|
32
|
+
if (search instanceof URLSearchParams) {
|
|
33
|
+
// Overwrite
|
|
34
|
+
searchParams = search;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Merge
|
|
38
|
+
const searchMap = (0, utils_js_1.objectFilter)({ ...urlParsed.search, ...search }, (utils_js_1.isNotNullish_keyVal));
|
|
39
|
+
searchParams = new URLSearchParams(searchMap);
|
|
40
|
+
}
|
|
41
|
+
return '?' + searchParams.toString();
|
|
42
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getConfigDefinedAt = getConfigDefinedAt;
|
|
7
7
|
exports.getConfigDefinedAtOptional = getConfigDefinedAtOptional;
|
|
8
8
|
exports.getDefinedAtString = getDefinedAtString;
|
|
9
|
+
exports.getDefinedByString = getDefinedByString;
|
|
9
10
|
const utils_js_1 = require("../utils.js");
|
|
10
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
12
|
const getExportPath_js_1 = require("./getExportPath.js");
|
|
@@ -49,14 +50,14 @@ function getDefinedAtString(definedAtData, configName) {
|
|
|
49
50
|
}
|
|
50
51
|
function getDefinedByString(definedAt, configName) {
|
|
51
52
|
if (definedAt.definedBy === 'api') {
|
|
52
|
-
return `API call ${picocolors_1.default.cyan(`${definedAt.operation}({${configName}})`)}`;
|
|
53
|
+
return `API call ${picocolors_1.default.cyan(`${definedAt.operation}({ vikeConfig: { ${configName} } })`)}`;
|
|
53
54
|
}
|
|
54
55
|
const { definedBy } = definedAt;
|
|
55
56
|
if (definedBy === 'cli') {
|
|
56
57
|
return `CLI option ${picocolors_1.default.cyan(`--${configName}`)}`;
|
|
57
58
|
}
|
|
58
59
|
if (definedBy === 'env') {
|
|
59
|
-
return `environment variable ${picocolors_1.default.cyan(`
|
|
60
|
+
return `environment variable ${picocolors_1.default.cyan(`VIKE_CONFIG="{${configName}}"`)}`;
|
|
60
61
|
}
|
|
61
62
|
(0, utils_js_1.checkType)(definedBy);
|
|
62
63
|
(0, utils_js_1.assert)(false);
|
|
@@ -58,11 +58,11 @@ function mergeCumulative(configValueSources) {
|
|
|
58
58
|
return { value, definedAtData };
|
|
59
59
|
}
|
|
60
60
|
function getDefinedAt(configValueSource) {
|
|
61
|
-
const {
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
61
|
+
const { definedAt } = configValueSource;
|
|
62
|
+
if (definedAt.definedBy)
|
|
63
|
+
return definedAt;
|
|
64
64
|
return {
|
|
65
|
-
filePathToShowToUser:
|
|
66
|
-
fileExportPathToShowToUser:
|
|
65
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
66
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
67
67
|
};
|
|
68
68
|
}
|
|
@@ -52,7 +52,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
52
52
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
53
53
|
let valueData;
|
|
54
54
|
if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
|
|
55
|
-
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.
|
|
55
|
+
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAt, importStatements, filesEnv, configValueSource.configEnv);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
58
|
valueData = getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName);
|
|
@@ -103,9 +103,9 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
103
103
|
}
|
|
104
104
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
105
105
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
106
|
-
const { valueIsDefinedByPlusValueFile,
|
|
107
|
-
(0, utils_js_1.assert)(!
|
|
108
|
-
const { filePathAbsoluteVite, fileExportName } =
|
|
106
|
+
const { valueIsDefinedByPlusValueFile, definedAt, configEnv } = configValueSource;
|
|
107
|
+
(0, utils_js_1.assert)(!definedAt.definedBy);
|
|
108
|
+
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
109
109
|
if (valueIsDefinedByPlusValueFile)
|
|
110
110
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
111
111
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
@@ -232,12 +232,12 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
232
232
|
return [...fromComputed, ...fromSources].filter((r) => r !== 'SKIP');
|
|
233
233
|
}
|
|
234
234
|
function getDefinedAtFileSource(source) {
|
|
235
|
-
const {
|
|
236
|
-
if (
|
|
237
|
-
return
|
|
235
|
+
const { definedAt } = source;
|
|
236
|
+
if (definedAt.definedBy)
|
|
237
|
+
return definedAt;
|
|
238
238
|
const definedAtFile = {
|
|
239
|
-
filePathToShowToUser:
|
|
240
|
-
fileExportPathToShowToUser:
|
|
239
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
240
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
241
241
|
};
|
|
242
242
|
return definedAtFile;
|
|
243
243
|
}
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -30,7 +30,7 @@ __exportStar(require("../utils/isBrowser.js"), exports);
|
|
|
30
30
|
__exportStar(require("../utils/hasProp.js"), exports);
|
|
31
31
|
__exportStar(require("../utils/isPlainObject.js"), exports);
|
|
32
32
|
__exportStar(require("../utils/compareString.js"), exports);
|
|
33
|
-
__exportStar(require("../utils/
|
|
33
|
+
__exportStar(require("../utils/isNullish.js"), exports);
|
|
34
34
|
__exportStar(require("../utils/stringifyStringArray.js"), exports);
|
|
35
35
|
__exportStar(require("../utils/cast.js"), exports);
|
|
36
36
|
__exportStar(require("../utils/isPropertyGetter.js"), exports);
|
|
@@ -42,3 +42,4 @@ __exportStar(require("../utils/isArray.js"), exports);
|
|
|
42
42
|
__exportStar(require("../utils/changeEnumerable.js"), exports);
|
|
43
43
|
__exportStar(require("../utils/objectDefineProperty.js"), exports);
|
|
44
44
|
__exportStar(require("../utils/isScriptFile.js"), exports);
|
|
45
|
+
__exportStar(require("../utils/objectFilter.js"), exports);
|