vike 0.4.219 → 0.4.220
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/api/prepareViteApiCall.js +3 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +15 -1
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +13 -3
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +8 -0
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/skipLink.js +1 -0
- package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
- package/dist/esm/node/api/prepareViteApiCall.js +3 -3
- package/dist/esm/node/plugin/plugins/commonConfig.js +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/assertSetup.js +15 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -63,19 +63,19 @@ async function enhanceViteConfig(viteConfig, operation) {
|
|
|
63
63
|
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
64
64
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
65
65
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
66
|
-
const viteConfigEnhanced =
|
|
66
|
+
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
67
67
|
return {
|
|
68
68
|
viteConfigEnhanced,
|
|
69
69
|
vikeConfigGlobal: vikeConfig.vikeConfigGlobal
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
73
73
|
const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
|
|
74
74
|
if (!viteConfigs)
|
|
75
75
|
return viteConfigEnhanced;
|
|
76
76
|
viteConfigs.values.forEach((v) => {
|
|
77
77
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(v.value), `${v.definedAt} should be an object`);
|
|
78
|
-
viteConfigEnhanced = (0, vite_1.mergeConfig)(
|
|
78
|
+
viteConfigEnhanced = (0, vite_1.mergeConfig)(viteConfigEnhanced ?? {}, v.value);
|
|
79
79
|
});
|
|
80
80
|
return viteConfigEnhanced;
|
|
81
81
|
}
|
|
@@ -80,7 +80,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
80
80
|
// VITE_CONFIG
|
|
81
81
|
const configFromEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VITE_CONFIG');
|
|
82
82
|
if (configFromEnvVar)
|
|
83
|
-
configFromVike = (0, vite_1.mergeConfig)(
|
|
83
|
+
configFromVike = (0, vite_1.mergeConfig)(configFromVike, configFromEnvVar);
|
|
84
84
|
return configFromVike;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -121,7 +121,7 @@ function getEnvDescription() {
|
|
|
121
121
|
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
122
122
|
function assertNodeEnvIsNotUndefinedString() {
|
|
123
123
|
const nodeEnv = getNodeEnv();
|
|
124
|
-
(0, assert_js_1.assertWarning)(nodeEnv !== 'undefined', `${picocolors_1.default.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${picocolors_1.default.cyan('process.env.NODE_ENV')}
|
|
124
|
+
(0, assert_js_1.assertWarning)(nodeEnv !== 'undefined', `${picocolors_1.default.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${picocolors_1.default.cyan('process.env.NODE_ENV')} is allowed to be the *value* ${picocolors_1.default.cyan('undefined')} (i.e. ${picocolors_1.default.cyan('process.env.NODE_ENV===undefined')}) but it shouldn't be the *string* ${picocolors_1.default.cyan('"undefined"')} ${picocolors_1.default.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
125
125
|
}
|
|
126
126
|
function isNodeEnvDev() {
|
|
127
127
|
const nodeEnv = getNodeEnv();
|
|
@@ -141,6 +141,20 @@ function getNodeEnv() {
|
|
|
141
141
|
catch {
|
|
142
142
|
return undefined;
|
|
143
143
|
}
|
|
144
|
+
/*
|
|
145
|
+
// Should we show the following warning? So far I don't think so because of the following. Maybe we can show it once we enable users to disable warnings.
|
|
146
|
+
// - The warning isn't always actionable, e.g. if it's a tool that dynamically sets `process.env.NODE_ENV`.
|
|
147
|
+
// - We assume that tools use `process.env.NODE_ENV` and not someting like `const { env } = process; env.NODE_ENV`. Thus, in practice, `val` overrides `val2` so having `val!==val2` isn't an issue.
|
|
148
|
+
{
|
|
149
|
+
const val2 = process.env['NODE' + '_ENV']
|
|
150
|
+
if (val2)
|
|
151
|
+
assertWarning(
|
|
152
|
+
val === val2,
|
|
153
|
+
`Dynamically setting process.env.NODE_ENV to ${val2} hasn't any effect because process.env.NODE_ENV is being statically replaced to ${val}.`,
|
|
154
|
+
{ onlyOnce: true }
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
//*/
|
|
144
158
|
return val;
|
|
145
159
|
}
|
|
146
160
|
function setNodeEnvProduction() {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Code adapted from https://github.com/HenrikJoreteg/internal-nav-helper/blob/5199ec5448d0b0db7ec63cf76d88fa6cad878b7d/src/index.js#L11-L29
|
|
2
2
|
export { initOnLinkClick };
|
|
3
|
-
|
|
3
|
+
export { getCurrentLinkClick };
|
|
4
|
+
import { getGlobalObject } from './utils.js';
|
|
4
5
|
import { isSameAsCurrentUrl, skipLink } from './skipLink.js';
|
|
5
6
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
6
7
|
import { scrollToHashOrTop } from './setScrollPosition.js';
|
|
8
|
+
const globalObject = getGlobalObject('initOnLinkClick.ts', {});
|
|
7
9
|
function initOnLinkClick() {
|
|
8
10
|
document.addEventListener('click', onClick);
|
|
9
11
|
}
|
|
@@ -14,10 +16,16 @@ async function onClick(ev) {
|
|
|
14
16
|
if (!linkTag)
|
|
15
17
|
return;
|
|
16
18
|
const href = linkTag.getAttribute('href');
|
|
19
|
+
if (href === null)
|
|
20
|
+
return;
|
|
21
|
+
globalObject.currentLinkClick = { href };
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
delete globalObject.currentLinkClick;
|
|
24
|
+
}, 0);
|
|
17
25
|
// Workaround for Firefox bug: clicking on a hash link that doesn't change the current URL causes Firefox to erroneously set `window.history.state = null` without firing any signal that we can detect.
|
|
18
26
|
// - https://github.com/vikejs/vike/issues/1962
|
|
19
27
|
// - https://github.com/sveltejs/kit/issues/8725
|
|
20
|
-
if (href
|
|
28
|
+
if (href.includes('#') && isSameAsCurrentUrl(href)) {
|
|
21
29
|
// Prevent Firefox from setting `window.history.state` to `null`
|
|
22
30
|
ev.preventDefault();
|
|
23
31
|
// Replicate the browser's native behavior
|
|
@@ -26,7 +34,6 @@ async function onClick(ev) {
|
|
|
26
34
|
}
|
|
27
35
|
if (skipLink(linkTag))
|
|
28
36
|
return;
|
|
29
|
-
assert(href);
|
|
30
37
|
ev.preventDefault();
|
|
31
38
|
let scrollTarget;
|
|
32
39
|
{
|
|
@@ -53,3 +60,6 @@ function findLinkTag(target) {
|
|
|
53
60
|
}
|
|
54
61
|
return target;
|
|
55
62
|
}
|
|
63
|
+
function getCurrentLinkClick() {
|
|
64
|
+
return globalObject.currentLinkClick;
|
|
65
|
+
}
|
|
@@ -4,6 +4,8 @@ import { assertWarning, getGlobalObject } from './utils.js';
|
|
|
4
4
|
import { onPopStateBegin } from './history.js';
|
|
5
5
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
6
6
|
import { setScrollPosition } from './setScrollPosition.js';
|
|
7
|
+
import { getCurrentLinkClick } from './initOnLinkClick.js';
|
|
8
|
+
import { isSamePageHashLink } from './skipLink.js';
|
|
7
9
|
const globalObject = getGlobalObject('initOnPopState.ts', { listeners: [] });
|
|
8
10
|
function initOnPopState() {
|
|
9
11
|
// - The popstate event is trigged upon:
|
|
@@ -16,7 +18,13 @@ function initOnPopState() {
|
|
|
16
18
|
// - `location.hash = 'some-hash'`
|
|
17
19
|
// - The `event` argument of `window.addEventListener('popstate', (event) => /*...*/)` is useless: the History API doesn't provide the previous state (the popped state), see https://stackoverflow.com/questions/48055323/is-history-state-always-the-same-as-popstate-event-state
|
|
18
20
|
window.addEventListener('popstate', async () => {
|
|
21
|
+
const currentLinkClick = getCurrentLinkClick();
|
|
19
22
|
const { isNewState, previous, current } = onPopStateBegin();
|
|
23
|
+
// We use currentLinkClick.href instead of current.url because current.url missing text links such as #:~:text=With%20frontmatter-,Global%20metadata,-What%20is%20global (e.g. Chrome strips the `#:~:text=` part from the URL before the popstate event).
|
|
24
|
+
if (currentLinkClick && isSamePageHashLink(currentLinkClick.href)) {
|
|
25
|
+
// Let the browser handle hash links
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
20
28
|
const scrollTarget = current.state.scrollPosition || undefined;
|
|
21
29
|
const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
|
|
22
30
|
const isHashNavigation = removeHash(current.url) === removeHash(previous.url) && current.url !== previous.url;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { skipLink };
|
|
2
2
|
export { isSameAsCurrentUrl };
|
|
3
|
+
export { isSamePageHashLink };
|
|
3
4
|
declare function skipLink(linkTag: HTMLElement): boolean;
|
|
5
|
+
declare function isSamePageHashLink(href: string): boolean;
|
|
4
6
|
declare function isSameAsCurrentUrl(href: string): boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { skipLink };
|
|
2
2
|
export { isSameAsCurrentUrl };
|
|
3
|
+
export { isSamePageHashLink };
|
|
3
4
|
import { normalizeClientSideUrl } from '../shared/normalizeClientSideUrl.js';
|
|
4
5
|
import { getBaseServer } from './getBaseServer.js';
|
|
5
6
|
import { assert, parseUrl, isBaseServer, isUrl, isUrlExternal } from './utils.js';
|
|
@@ -2,9 +2,8 @@ export { normalizeClientSideUrl };
|
|
|
2
2
|
import { assert, parseUrl } from './utils.js';
|
|
3
3
|
/** Resolves relative URLs */
|
|
4
4
|
function normalizeClientSideUrl(url, options) {
|
|
5
|
-
// This function doesn't work for `url === '#some-hash'` because `searchOriginal`
|
|
6
|
-
// -
|
|
7
|
-
// - It makes sense that `parseUrl()` returns `searchOriginal === null` since there isn't any search string in `url`.
|
|
5
|
+
// This function doesn't work for `url === '#some-hash'` because `searchOriginal` will be missing: if window.location.href has a search string then it's going to be missing in the returned `urlCurrent` value because `parseUrl(url)` returns `searchOriginal: null` since there isn't any search string in `url`.
|
|
6
|
+
// - Maybe `const { searchOriginal } = parseUrl(window.location.href)` can be a fix. (Let's check how `normalizeClientSideUrl()` is being used.)
|
|
8
7
|
assert(!url.startsWith('#'));
|
|
9
8
|
const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
|
|
10
9
|
let urlCurrent = `${pathname}${searchOriginal || ''}`;
|
|
@@ -25,19 +25,19 @@ async function enhanceViteConfig(viteConfig, operation) {
|
|
|
25
25
|
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
26
26
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
27
27
|
const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
28
|
-
const viteConfigEnhanced =
|
|
28
|
+
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
29
29
|
return {
|
|
30
30
|
viteConfigEnhanced,
|
|
31
31
|
vikeConfigGlobal: vikeConfig.vikeConfigGlobal
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
35
35
|
const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
|
|
36
36
|
if (!viteConfigs)
|
|
37
37
|
return viteConfigEnhanced;
|
|
38
38
|
viteConfigs.values.forEach((v) => {
|
|
39
39
|
assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
|
|
40
|
-
viteConfigEnhanced = mergeConfig(
|
|
40
|
+
viteConfigEnhanced = mergeConfig(viteConfigEnhanced ?? {}, v.value);
|
|
41
41
|
});
|
|
42
42
|
return viteConfigEnhanced;
|
|
43
43
|
}
|
|
@@ -75,7 +75,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
75
75
|
// VITE_CONFIG
|
|
76
76
|
const configFromEnvVar = getEnvVarObject('VITE_CONFIG');
|
|
77
77
|
if (configFromEnvVar)
|
|
78
|
-
configFromVike = mergeConfig(
|
|
78
|
+
configFromVike = mergeConfig(configFromVike, configFromEnvVar);
|
|
79
79
|
return configFromVike;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.220";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.220';
|
|
@@ -116,7 +116,7 @@ function getEnvDescription() {
|
|
|
116
116
|
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
117
117
|
function assertNodeEnvIsNotUndefinedString() {
|
|
118
118
|
const nodeEnv = getNodeEnv();
|
|
119
|
-
assertWarning(nodeEnv !== 'undefined', `${pc.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${pc.cyan('process.env.NODE_ENV')}
|
|
119
|
+
assertWarning(nodeEnv !== 'undefined', `${pc.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${pc.cyan('process.env.NODE_ENV')} is allowed to be the *value* ${pc.cyan('undefined')} (i.e. ${pc.cyan('process.env.NODE_ENV===undefined')}) but it shouldn't be the *string* ${pc.cyan('"undefined"')} ${pc.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
120
120
|
}
|
|
121
121
|
function isNodeEnvDev() {
|
|
122
122
|
const nodeEnv = getNodeEnv();
|
|
@@ -136,6 +136,20 @@ function getNodeEnv() {
|
|
|
136
136
|
catch {
|
|
137
137
|
return undefined;
|
|
138
138
|
}
|
|
139
|
+
/*
|
|
140
|
+
// Should we show the following warning? So far I don't think so because of the following. Maybe we can show it once we enable users to disable warnings.
|
|
141
|
+
// - The warning isn't always actionable, e.g. if it's a tool that dynamically sets `process.env.NODE_ENV`.
|
|
142
|
+
// - We assume that tools use `process.env.NODE_ENV` and not someting like `const { env } = process; env.NODE_ENV`. Thus, in practice, `val` overrides `val2` so having `val!==val2` isn't an issue.
|
|
143
|
+
{
|
|
144
|
+
const val2 = process.env['NODE' + '_ENV']
|
|
145
|
+
if (val2)
|
|
146
|
+
assertWarning(
|
|
147
|
+
val === val2,
|
|
148
|
+
`Dynamically setting process.env.NODE_ENV to ${val2} hasn't any effect because process.env.NODE_ENV is being statically replaced to ${val}.`,
|
|
149
|
+
{ onlyOnce: true }
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
//*/
|
|
139
153
|
return val;
|
|
140
154
|
}
|
|
141
155
|
function setNodeEnvProduction() {
|