vike 0.4.202 → 0.4.203-commit-d47722f
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/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +31 -21
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +6 -5
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -3
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/client-routing-runtime/entry.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/history.js +2 -5
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +32 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +6 -5
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -3
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -60,14 +60,13 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
60
60
|
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
61
61
|
}
|
|
62
62
|
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
63
|
-
const extendsPointerImportData = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
63
|
+
const { extendsPointerImportData, extendsConfigs } = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
64
64
|
const extendsConfigFiles = [];
|
|
65
65
|
extendsPointerImportData.map((pointerImportData) => {
|
|
66
66
|
const filePath = (0, resolvePointerImport_js_1.resolvePointerImport)(pointerImportData, configFilePath, userRootDir);
|
|
67
67
|
(0, utils_js_1.assert)(filePath.filePathAbsoluteFilesystem);
|
|
68
68
|
extendsConfigFiles.push(filePath);
|
|
69
69
|
});
|
|
70
|
-
const extendsConfigs = [];
|
|
71
70
|
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
72
71
|
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
73
72
|
extendsConfigs.push(result.configFile);
|
|
@@ -79,24 +78,35 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
79
78
|
function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
80
79
|
const { filePathToShowToUser } = configFilePath;
|
|
81
80
|
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
(0, utils_js_1.
|
|
81
|
+
const extendsConfigs = [];
|
|
82
|
+
const extendsPointerImportData = [];
|
|
83
|
+
if ('extends' in configFileExport) {
|
|
84
|
+
const extendsValue = configFileExport.extends;
|
|
85
|
+
const extendList = [];
|
|
86
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
87
|
+
if (typeof extendsValue === 'string') {
|
|
88
|
+
extendList.push(extendsValue);
|
|
89
|
+
}
|
|
90
|
+
else if ((0, utils_js_1.isArrayOfStrings)(extendsValue)) {
|
|
91
|
+
extendList.push(...extendsValue);
|
|
92
|
+
}
|
|
93
|
+
else if ((0, utils_js_1.isObject)(extendsValue)) {
|
|
94
|
+
/* If we want to implement this then we need to make filePath optional
|
|
95
|
+
extendsConfigs.push({
|
|
96
|
+
fileExports: extendsValue,
|
|
97
|
+
filePath: null,
|
|
98
|
+
})
|
|
99
|
+
*/
|
|
100
|
+
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
104
|
+
}
|
|
105
|
+
extendsPointerImportData.push(...extendList.map((importString) => {
|
|
106
|
+
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(importString);
|
|
107
|
+
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
108
|
+
return pointerImportData;
|
|
109
|
+
}));
|
|
95
110
|
}
|
|
96
|
-
|
|
97
|
-
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(importString);
|
|
98
|
-
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
99
|
-
return pointerImportData;
|
|
100
|
-
});
|
|
101
|
-
return extendsPointerImportData;
|
|
111
|
+
return { extendsPointerImportData, extendsConfigs };
|
|
102
112
|
}
|
|
@@ -149,15 +149,16 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
149
149
|
// - assertIsNpmPackageImport()
|
|
150
150
|
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
151
151
|
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
152
|
+
// Should be remove this? See comment below.
|
|
153
|
+
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
155
154
|
const isPointerImport = transformImports === 'all' ||
|
|
156
155
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
157
156
|
!(0, utils_js_1.isPlainJavaScriptFile)(importPathResolved) ||
|
|
158
157
|
// 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).
|
|
159
|
-
// -
|
|
160
|
-
// -
|
|
158
|
+
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
159
|
+
// - In principle, we can use the setting 'name' value of Vike extensions.
|
|
160
|
+
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
161
|
+
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
161
162
|
isVikeExtensionImport;
|
|
162
163
|
(0, utils_js_1.assertPosixPath)(importPathResolved);
|
|
163
164
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
@@ -29,9 +29,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
29
29
|
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} should have ${exportNamed} or ${exportDefault}`);
|
|
30
30
|
}
|
|
31
31
|
if (exportNamesValid.length === 2) {
|
|
32
|
-
(0, utils_js_1.
|
|
33
|
-
onlyOnce: true
|
|
34
|
-
});
|
|
32
|
+
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`);
|
|
35
33
|
}
|
|
36
34
|
if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
|
|
37
35
|
exportNamesInvalid.forEach((exportInvalid) => {
|
|
@@ -114,6 +114,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
|
114
114
|
const isSideExport = exportName !== 'default' && exportName !== configName;
|
|
115
115
|
if (!isSideExport) {
|
|
116
116
|
value = exportValue;
|
|
117
|
+
// Already asserted by assertPlusFileExport() call above.
|
|
117
118
|
(0, utils_js_1.assert)(!valueWasFound);
|
|
118
119
|
valueWasFound = true;
|
|
119
120
|
}
|
|
@@ -131,7 +132,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
134
|
});
|
|
134
|
-
// Already
|
|
135
|
+
// Already asserted by assertPlusFileExport() call above.
|
|
135
136
|
(0, utils_js_1.assert)(valueWasFound);
|
|
136
137
|
return { value, sideExports };
|
|
137
138
|
}
|
|
@@ -7,6 +7,6 @@ import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
|
7
7
|
// @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
|
|
8
8
|
const isProd = import.meta.env.PROD;
|
|
9
9
|
assertSingleInstance_onClientEntryClientRouting(isProd);
|
|
10
|
+
initClientRouter();
|
|
10
11
|
if (import.meta.env.DEV)
|
|
11
12
|
removeFoucBuster();
|
|
12
|
-
initClientRouter();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { pushHistoryState };
|
|
2
2
|
export { onPopStateBegin };
|
|
3
3
|
export { saveScrollPosition };
|
|
4
|
+
export { enhanceHistoryState };
|
|
5
|
+
export { monkeyPatchHistoryAPI };
|
|
4
6
|
export type { HistoryInfo };
|
|
5
7
|
export type { ScrollPosition };
|
|
6
8
|
type StateEnhanced = {
|
|
@@ -13,8 +15,10 @@ type ScrollPosition = {
|
|
|
13
15
|
x: number;
|
|
14
16
|
y: number;
|
|
15
17
|
};
|
|
18
|
+
declare function enhanceHistoryState(): void;
|
|
16
19
|
declare function saveScrollPosition(): void;
|
|
17
20
|
declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
|
|
21
|
+
declare function monkeyPatchHistoryAPI(): void;
|
|
18
22
|
type HistoryInfo = {
|
|
19
23
|
url: `/${string}`;
|
|
20
24
|
state: StateEnhanced;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { pushHistoryState };
|
|
2
2
|
export { onPopStateBegin };
|
|
3
3
|
export { saveScrollPosition };
|
|
4
|
+
export { enhanceHistoryState };
|
|
5
|
+
export { monkeyPatchHistoryAPI };
|
|
4
6
|
import { assert, assertUsage, getCurrentUrl, getGlobalObject, hasProp, isObject } from './utils.js';
|
|
5
|
-
init();
|
|
6
7
|
const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
|
|
7
8
|
// `window.history.state === null` when:
|
|
8
9
|
// - The very first render
|
|
@@ -129,10 +130,6 @@ function assertStateVikeEnhanced(state) {
|
|
|
129
130
|
assert(hasProp(state.scrollPosition, 'x', 'number') && hasProp(state.scrollPosition, 'y', 'number'));
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
|
-
function init() {
|
|
133
|
-
enhanceHistoryState();
|
|
134
|
-
monkeyPatchHistoryAPI();
|
|
135
|
-
}
|
|
136
133
|
function getHistoryInfo() {
|
|
137
134
|
return {
|
|
138
135
|
url: getCurrentUrl(),
|
|
@@ -6,6 +6,7 @@ import { initOnLinkClick } from './initOnLinkClick.js';
|
|
|
6
6
|
import { setupNativeScrollRestoration } from './scrollRestoration.js';
|
|
7
7
|
import { autoSaveScrollPosition } from './setScrollPosition.js';
|
|
8
8
|
import { initLinkPrefetchHandlers } from './prefetch.js';
|
|
9
|
+
import { enhanceHistoryState, monkeyPatchHistoryAPI } from './history.js';
|
|
9
10
|
async function initClientRouter() {
|
|
10
11
|
// Init navigation history and scroll restoration
|
|
11
12
|
initHistoryAndScroll();
|
|
@@ -27,6 +28,8 @@ async function renderFirstPage() {
|
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
function initHistoryAndScroll() {
|
|
31
|
+
monkeyPatchHistoryAPI();
|
|
32
|
+
enhanceHistoryState();
|
|
30
33
|
setupNativeScrollRestoration();
|
|
31
34
|
autoSaveScrollPosition();
|
|
32
35
|
// Handle back-/forward navigation
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
4
|
export { loadConfigFile };
|
|
5
|
-
import { assert, assertUsage,
|
|
5
|
+
import { assert, assertUsage, assertIsNotProductionRuntime, isArrayOfStrings, isObject } from '../../../../utils.js';
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -55,14 +55,13 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
55
55
|
assertUsage(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
56
56
|
}
|
|
57
57
|
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
58
|
-
const extendsPointerImportData = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
58
|
+
const { extendsPointerImportData, extendsConfigs } = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
59
59
|
const extendsConfigFiles = [];
|
|
60
60
|
extendsPointerImportData.map((pointerImportData) => {
|
|
61
61
|
const filePath = resolvePointerImport(pointerImportData, configFilePath, userRootDir);
|
|
62
62
|
assert(filePath.filePathAbsoluteFilesystem);
|
|
63
63
|
extendsConfigFiles.push(filePath);
|
|
64
64
|
});
|
|
65
|
-
const extendsConfigs = [];
|
|
66
65
|
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
67
66
|
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
68
67
|
extendsConfigs.push(result.configFile);
|
|
@@ -74,24 +73,35 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
74
73
|
function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
75
74
|
const { filePathToShowToUser } = configFilePath;
|
|
76
75
|
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
const extendsConfigs = [];
|
|
77
|
+
const extendsPointerImportData = [];
|
|
78
|
+
if ('extends' in configFileExport) {
|
|
79
|
+
const extendsValue = configFileExport.extends;
|
|
80
|
+
const extendList = [];
|
|
81
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
82
|
+
if (typeof extendsValue === 'string') {
|
|
83
|
+
extendList.push(extendsValue);
|
|
84
|
+
}
|
|
85
|
+
else if (isArrayOfStrings(extendsValue)) {
|
|
86
|
+
extendList.push(...extendsValue);
|
|
87
|
+
}
|
|
88
|
+
else if (isObject(extendsValue)) {
|
|
89
|
+
/* If we want to implement this then we need to make filePath optional
|
|
90
|
+
extendsConfigs.push({
|
|
91
|
+
fileExports: extendsValue,
|
|
92
|
+
filePath: null,
|
|
93
|
+
})
|
|
94
|
+
*/
|
|
95
|
+
assertUsage(false, wrongUsage);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
assertUsage(false, wrongUsage);
|
|
99
|
+
}
|
|
100
|
+
extendsPointerImportData.push(...extendList.map((importString) => {
|
|
101
|
+
const pointerImportData = parsePointerImportData(importString);
|
|
102
|
+
assertUsage(pointerImportData, wrongUsage);
|
|
103
|
+
return pointerImportData;
|
|
104
|
+
}));
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
const pointerImportData = parsePointerImportData(importString);
|
|
93
|
-
assertUsage(pointerImportData, wrongUsage);
|
|
94
|
-
return pointerImportData;
|
|
95
|
-
});
|
|
96
|
-
return extendsPointerImportData;
|
|
106
|
+
return { extendsPointerImportData, extendsConfigs };
|
|
97
107
|
}
|
|
@@ -144,15 +144,16 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
144
144
|
// - assertIsNpmPackageImport()
|
|
145
145
|
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
146
146
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
147
|
+
// Should be remove this? See comment below.
|
|
148
|
+
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
150
149
|
const isPointerImport = transformImports === 'all' ||
|
|
151
150
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
152
151
|
!isPlainJavaScriptFile(importPathResolved) ||
|
|
153
152
|
// 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).
|
|
154
|
-
// -
|
|
155
|
-
// -
|
|
153
|
+
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
154
|
+
// - In principle, we can use the setting 'name' value of Vike extensions.
|
|
155
|
+
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
156
|
+
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
156
157
|
isVikeExtensionImport;
|
|
157
158
|
assertPosixPath(importPathResolved);
|
|
158
159
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
@@ -24,9 +24,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
24
24
|
assertUsage(false, `${filePathToShowToUser} should have ${exportNamed} or ${exportDefault}`);
|
|
25
25
|
}
|
|
26
26
|
if (exportNamesValid.length === 2) {
|
|
27
|
-
|
|
28
|
-
onlyOnce: true
|
|
29
|
-
});
|
|
27
|
+
assertUsage(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`);
|
|
30
28
|
}
|
|
31
29
|
if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
|
|
32
30
|
exportNamesInvalid.forEach((exportInvalid) => {
|
|
@@ -112,6 +112,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
|
112
112
|
const isSideExport = exportName !== 'default' && exportName !== configName;
|
|
113
113
|
if (!isSideExport) {
|
|
114
114
|
value = exportValue;
|
|
115
|
+
// Already asserted by assertPlusFileExport() call above.
|
|
115
116
|
assert(!valueWasFound);
|
|
116
117
|
valueWasFound = true;
|
|
117
118
|
}
|
|
@@ -129,7 +130,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
});
|
|
132
|
-
// Already
|
|
133
|
+
// Already asserted by assertPlusFileExport() call above.
|
|
133
134
|
assert(valueWasFound);
|
|
134
135
|
return { value, sideExports };
|
|
135
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.203-commit-d47722f";
|
|
@@ -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.203-commit-d47722f';
|