vike 0.4.202 → 0.4.203-commit-1b14559

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.
@@ -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 wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
83
- let extendList;
84
- if (!('extends' in configFileExport)) {
85
- return [];
86
- }
87
- else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string')) {
88
- extendList = [configFileExport.extends];
89
- }
90
- else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string[]')) {
91
- extendList = configFileExport.extends;
92
- }
93
- else {
94
- (0, utils_js_1.assertUsage)(false, wrongUsage);
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
- const extendsPointerImportData = extendList.map((importString) => {
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
- // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
153
- // - This is temporary, see comment below.
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
- // - 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.
160
- // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
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.assertWarning)(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`, {
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 validated by assertPlusFileExport() call above.
135
+ // Already asserted by assertPlusFileExport() call above.
135
136
  (0, utils_js_1.assert)(valueWasFound);
136
137
  return { value, sideExports };
137
138
  }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.202';
5
+ exports.PROJECT_VERSION = '0.4.203-commit-1b14559';
@@ -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 { initHistoryState };
5
+ export { monkeyPatchHistoryAPI };
4
6
  export type { HistoryInfo };
5
7
  export type { ScrollPosition };
6
8
  type StateEnhanced = {
@@ -15,6 +17,7 @@ type ScrollPosition = {
15
17
  };
16
18
  declare function saveScrollPosition(): void;
17
19
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
20
+ declare function monkeyPatchHistoryAPI(): void;
18
21
  type HistoryInfo = {
19
22
  url: `/${string}`;
20
23
  state: StateEnhanced;
@@ -24,3 +27,4 @@ declare function onPopStateBegin(): {
24
27
  previous: HistoryInfo;
25
28
  current: HistoryInfo;
26
29
  };
30
+ declare function initHistoryState(): void;
@@ -1,8 +1,10 @@
1
1
  export { pushHistoryState };
2
2
  export { onPopStateBegin };
3
3
  export { saveScrollPosition };
4
+ export { initHistoryState };
5
+ export { monkeyPatchHistoryAPI };
4
6
  import { assert, assertUsage, getCurrentUrl, getGlobalObject, hasProp, isObject } from './utils.js';
5
- init();
7
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
6
8
  const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
7
9
  // `window.history.state === null` when:
8
10
  // - The very first render
@@ -129,10 +131,6 @@ function assertStateVikeEnhanced(state) {
129
131
  assert(hasProp(state.scrollPosition, 'x', 'number') && hasProp(state.scrollPosition, 'y', 'number'));
130
132
  }
131
133
  }
132
- function init() {
133
- enhanceHistoryState();
134
- monkeyPatchHistoryAPI();
135
- }
136
134
  function getHistoryInfo() {
137
135
  return {
138
136
  url: getCurrentUrl(),
@@ -148,3 +146,6 @@ function onPopStateBegin() {
148
146
  globalObject.previous = current;
149
147
  return { isNewState, previous, current };
150
148
  }
149
+ function initHistoryState() {
150
+ enhanceHistoryState();
151
+ }
@@ -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 { initHistoryState, 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
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
30
33
  setupNativeScrollRestoration();
31
34
  autoSaveScrollPosition();
32
35
  // Handle back-/forward navigation
@@ -2,7 +2,7 @@
2
2
  export { loadImportedFile };
3
3
  export { loadValueFile };
4
4
  export { loadConfigFile };
5
- import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../../../../utils.js';
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 wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
78
- let extendList;
79
- if (!('extends' in configFileExport)) {
80
- return [];
81
- }
82
- else if (hasProp(configFileExport, 'extends', 'string')) {
83
- extendList = [configFileExport.extends];
84
- }
85
- else if (hasProp(configFileExport, 'extends', 'string[]')) {
86
- extendList = configFileExport.extends;
87
- }
88
- else {
89
- assertUsage(false, wrongUsage);
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
- const extendsPointerImportData = extendList.map((importString) => {
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
- // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
148
- // - This is temporary, see comment below.
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
- // - 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.
155
- // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
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
- assertWarning(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`, {
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 validated by assertPlusFileExport() call above.
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.202";
1
+ export declare const PROJECT_VERSION: "0.4.203-commit-1b14559";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.202';
2
+ export const PROJECT_VERSION = '0.4.203-commit-1b14559';
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.202";
3
+ projectVersion: "0.4.203-commit-1b14559";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.202",
3
+ "version": "0.4.203-commit-1b14559",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {