vike 0.4.175 → 0.4.176

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.
@@ -25,7 +25,7 @@ filePathAbsoluteUserRootDir) {
25
25
  exports.getLocationId = getLocationId;
26
26
  /** Filesystem Routing: get the URL */
27
27
  function getFilesystemRouteString(locationId) {
28
- return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
28
+ return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index'], true);
29
29
  }
30
30
  exports.getFilesystemRouteString = getFilesystemRouteString;
31
31
  /** Filesystem Inheritance: get the apply root */
@@ -35,8 +35,8 @@ function getInheritanceRoot(locationId) {
35
35
  /**
36
36
  * getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
37
37
  */
38
- function getLogicalPath(locationId, ignoredDirs) {
39
- let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs);
38
+ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
39
+ let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs, removeParenthesesDirs);
40
40
  assertIsPath(logicalPath);
41
41
  return logicalPath;
42
42
  }
@@ -91,7 +91,7 @@ function isInherited(locationId1, locationId2) {
91
91
  return startsWith(inheritanceRoot2, inheritanceRoot1);
92
92
  }
93
93
  exports.isInherited = isInherited;
94
- function removeIgnoredDirectories(somePath, ignoredDirs) {
94
+ function removeIgnoredDirectories(somePath, ignoredDirs, removeParenthesesDirs) {
95
95
  (0, utils_js_1.assertPosixPath)(somePath);
96
96
  somePath = somePath
97
97
  .split('/')
@@ -99,20 +99,8 @@ function removeIgnoredDirectories(somePath, ignoredDirs) {
99
99
  if (ignoredDirs.includes(dir)) {
100
100
  return false;
101
101
  }
102
- if (dir.startsWith('(') && dir.endsWith(')')) {
103
- const dirname = dir.slice(1, -1);
104
- if (ignoredDirs.includes(dirname)) {
105
- const dirnameActual = dir;
106
- const dirnameCorect = dirname;
107
- const dirpathActual = somePath.slice(0, somePath.indexOf(dirnameActual) + dirnameActual.length);
108
- const dirpathCorect = dirpathActual.replaceAll(dirnameActual, dirnameCorect);
109
- const logDir = (d) => picocolors_1.default.bold(d + '/');
110
- (0, utils_js_1.assertWarning)(false, [
111
- `The directories ${logDir(dirnameCorect)} are always ignored by Vike's Filesystem Routing`,
112
- '(https://vike.dev/filesystem-routing):',
113
- `rename directory ${logDir(dirpathActual)} to ${logDir(dirpathCorect)}`
114
- ].join(' '), { onlyOnce: true });
115
- }
102
+ if (removeParenthesesDirs && dir.startsWith('(') && dir.endsWith(')')) {
103
+ assertRedundantParentheses(dir, ignoredDirs, somePath);
116
104
  return false;
117
105
  }
118
106
  return true;
@@ -122,6 +110,22 @@ function removeIgnoredDirectories(somePath, ignoredDirs) {
122
110
  somePath = '/';
123
111
  return somePath;
124
112
  }
113
+ function assertRedundantParentheses(dir, ignoredDirs, somePath) {
114
+ const dirWithoutParentheses = dir.slice(1, -1);
115
+ if (!ignoredDirs.includes(dirWithoutParentheses)) {
116
+ return;
117
+ }
118
+ const dirnameActual = dir;
119
+ const dirnameCorect = dirWithoutParentheses;
120
+ const dirpathActual = somePath.slice(0, somePath.indexOf(dirnameActual) + dirnameActual.length);
121
+ const dirpathCorect = dirpathActual.replaceAll(dirnameActual, dirnameCorect);
122
+ const logDir = (d) => picocolors_1.default.bold(d + '/');
123
+ (0, utils_js_1.assertWarning)(false, [
124
+ `The directories ${logDir(dirnameCorect)} are always ignored by Vike's Filesystem Routing`,
125
+ '(https://vike.dev/filesystem-routing):',
126
+ `rename directory ${logDir(dirpathActual)} to ${logDir(dirpathCorect)}`
127
+ ].join(' '), { onlyOnce: true });
128
+ }
125
129
  function removeFilename(filePathAbsoluteUserRootDir) {
126
130
  const filePathParts = filePathAbsoluteUserRootDir.split('/');
127
131
  {
@@ -15,27 +15,30 @@ const EXPORTS_IGNORE = [
15
15
  // Tolerate `export { frontmatter }` in .mdx files
16
16
  const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
17
17
  function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
18
- const exportsAll = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
19
- const exportsInvalid = exportsAll.filter((e) => e !== 'default' && e !== configName);
20
- if (exportsInvalid.length === 0) {
21
- if (exportsAll.length === 1) {
22
- return;
23
- }
24
- const exportDefault = picocolors_1.default.cyan('export default');
25
- const exportNamed = picocolors_1.default.cyan(`export { ${configName} }`);
26
- if (exportsAll.length === 0) {
27
- (0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} doesn't export any value, but it should have a ${exportNamed} or ${exportDefault}`);
28
- }
29
- else {
30
- (0, utils_js_1.assert)(exportsAll.length === 2); // because `exportsInvalid.length === 0`
31
- (0, utils_js_1.assertWarning)(false, `The exports of ${filePathToShowToUser} are ambiguous: remove ${exportDefault} or ${exportNamed}`, { onlyOnce: true });
32
- }
18
+ const exportNames = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
19
+ const isValid = (exportName) => exportName === 'default' || exportName === configName;
20
+ const exportNamesValid = exportNames.filter(isValid);
21
+ const exportNamesInvalid = exportNames.filter((e) => !isValid(e));
22
+ if (exportNamesValid.length === 1 && exportNamesInvalid.length === 0) {
23
+ return;
33
24
  }
34
- else {
35
- if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
36
- return;
37
- exportsInvalid.forEach((exportInvalid) => {
38
- (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} should have only one export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to its own +${exportsInvalid}.js file`, { onlyOnce: true });
25
+ const exportDefault = picocolors_1.default.code('export default');
26
+ const exportNamed = picocolors_1.default.code(`export { ${configName} }`);
27
+ if (exportNamesValid.length === 0) {
28
+ (0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
29
+ }
30
+ if (exportNamesValid.length === 2) {
31
+ (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`, {
32
+ onlyOnce: true
33
+ });
34
+ }
35
+ (0, utils_js_1.assert)(exportNamesValid.length === 1);
36
+ (0, utils_js_1.assert)(exportNamesInvalid.length > 0);
37
+ if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
38
+ exportNamesInvalid.forEach((exportInvalid) => {
39
+ (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} unexpected ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)}`, {
40
+ onlyOnce: true
41
+ });
39
42
  });
40
43
  }
41
44
  }
@@ -132,6 +132,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
132
132
  });
133
133
  }
134
134
  });
135
+ // Already validated by assertPlusFileExport() call above.
135
136
  (0, utils_js_1.assert)(valueWasFound);
136
137
  return { value, sideExports };
137
138
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.175';
4
+ const PROJECT_VERSION = '0.4.176';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -45,7 +45,7 @@ declare function getFilesystemRouteString(locationId: LocationId): string;
45
45
  /**
46
46
  * getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
47
47
  */
48
- declare function getLogicalPath(locationId: LocationId, ignoredDirs: string[]): string;
48
+ declare function getLogicalPath(locationId: LocationId, ignoredDirs: string[], removeParenthesesDirs?: true): string;
49
49
  /** Whether configs defined in `locationId` apply in every `locationIds` */
50
50
  declare function isGlobalLocation(locationId: LocationId, locationIds: LocationId[]): boolean;
51
51
  declare function sortAfterInheritanceOrder(locationId1: LocationId, locationId2: LocationId, locationIdPage: LocationId): -1 | 1 | 0;
@@ -27,7 +27,7 @@ filePathAbsoluteUserRootDir) {
27
27
  }
28
28
  /** Filesystem Routing: get the URL */
29
29
  function getFilesystemRouteString(locationId) {
30
- return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
30
+ return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index'], true);
31
31
  }
32
32
  /** Filesystem Inheritance: get the apply root */
33
33
  function getInheritanceRoot(locationId) {
@@ -36,8 +36,8 @@ function getInheritanceRoot(locationId) {
36
36
  /**
37
37
  * getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
38
38
  */
39
- function getLogicalPath(locationId, ignoredDirs) {
40
- let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs);
39
+ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
40
+ let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs, removeParenthesesDirs);
41
41
  assertIsPath(logicalPath);
42
42
  return logicalPath;
43
43
  }
@@ -88,7 +88,7 @@ function isInherited(locationId1, locationId2) {
88
88
  const inheritanceRoot2 = getInheritanceRoot(locationId2);
89
89
  return startsWith(inheritanceRoot2, inheritanceRoot1);
90
90
  }
91
- function removeIgnoredDirectories(somePath, ignoredDirs) {
91
+ function removeIgnoredDirectories(somePath, ignoredDirs, removeParenthesesDirs) {
92
92
  assertPosixPath(somePath);
93
93
  somePath = somePath
94
94
  .split('/')
@@ -96,20 +96,8 @@ function removeIgnoredDirectories(somePath, ignoredDirs) {
96
96
  if (ignoredDirs.includes(dir)) {
97
97
  return false;
98
98
  }
99
- if (dir.startsWith('(') && dir.endsWith(')')) {
100
- const dirname = dir.slice(1, -1);
101
- if (ignoredDirs.includes(dirname)) {
102
- const dirnameActual = dir;
103
- const dirnameCorect = dirname;
104
- const dirpathActual = somePath.slice(0, somePath.indexOf(dirnameActual) + dirnameActual.length);
105
- const dirpathCorect = dirpathActual.replaceAll(dirnameActual, dirnameCorect);
106
- const logDir = (d) => pc.bold(d + '/');
107
- assertWarning(false, [
108
- `The directories ${logDir(dirnameCorect)} are always ignored by Vike's Filesystem Routing`,
109
- '(https://vike.dev/filesystem-routing):',
110
- `rename directory ${logDir(dirpathActual)} to ${logDir(dirpathCorect)}`
111
- ].join(' '), { onlyOnce: true });
112
- }
99
+ if (removeParenthesesDirs && dir.startsWith('(') && dir.endsWith(')')) {
100
+ assertRedundantParentheses(dir, ignoredDirs, somePath);
113
101
  return false;
114
102
  }
115
103
  return true;
@@ -119,6 +107,22 @@ function removeIgnoredDirectories(somePath, ignoredDirs) {
119
107
  somePath = '/';
120
108
  return somePath;
121
109
  }
110
+ function assertRedundantParentheses(dir, ignoredDirs, somePath) {
111
+ const dirWithoutParentheses = dir.slice(1, -1);
112
+ if (!ignoredDirs.includes(dirWithoutParentheses)) {
113
+ return;
114
+ }
115
+ const dirnameActual = dir;
116
+ const dirnameCorect = dirWithoutParentheses;
117
+ const dirpathActual = somePath.slice(0, somePath.indexOf(dirnameActual) + dirnameActual.length);
118
+ const dirpathCorect = dirpathActual.replaceAll(dirnameActual, dirnameCorect);
119
+ const logDir = (d) => pc.bold(d + '/');
120
+ assertWarning(false, [
121
+ `The directories ${logDir(dirnameCorect)} are always ignored by Vike's Filesystem Routing`,
122
+ '(https://vike.dev/filesystem-routing):',
123
+ `rename directory ${logDir(dirpathActual)} to ${logDir(dirpathCorect)}`
124
+ ].join(' '), { onlyOnce: true });
125
+ }
122
126
  function removeFilename(filePathAbsoluteUserRootDir) {
123
127
  const filePathParts = filePathAbsoluteUserRootDir.split('/');
124
128
  {
@@ -10,27 +10,30 @@ const EXPORTS_IGNORE = [
10
10
  // Tolerate `export { frontmatter }` in .mdx files
11
11
  const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
12
12
  function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
13
- const exportsAll = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
14
- const exportsInvalid = exportsAll.filter((e) => e !== 'default' && e !== configName);
15
- if (exportsInvalid.length === 0) {
16
- if (exportsAll.length === 1) {
17
- return;
18
- }
19
- const exportDefault = pc.cyan('export default');
20
- const exportNamed = pc.cyan(`export { ${configName} }`);
21
- if (exportsAll.length === 0) {
22
- assertUsage(false, `${filePathToShowToUser} doesn't export any value, but it should have a ${exportNamed} or ${exportDefault}`);
23
- }
24
- else {
25
- assert(exportsAll.length === 2); // because `exportsInvalid.length === 0`
26
- assertWarning(false, `The exports of ${filePathToShowToUser} are ambiguous: remove ${exportDefault} or ${exportNamed}`, { onlyOnce: true });
27
- }
13
+ const exportNames = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
14
+ const isValid = (exportName) => exportName === 'default' || exportName === configName;
15
+ const exportNamesValid = exportNames.filter(isValid);
16
+ const exportNamesInvalid = exportNames.filter((e) => !isValid(e));
17
+ if (exportNamesValid.length === 1 && exportNamesInvalid.length === 0) {
18
+ return;
28
19
  }
29
- else {
30
- if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
31
- return;
32
- exportsInvalid.forEach((exportInvalid) => {
33
- assertWarning(false, `${filePathToShowToUser} should have only one export: move ${pc.cyan(`export { ${exportInvalid} }`)} to its own +${exportsInvalid}.js file`, { onlyOnce: true });
20
+ const exportDefault = pc.code('export default');
21
+ const exportNamed = pc.code(`export { ${configName} }`);
22
+ if (exportNamesValid.length === 0) {
23
+ assertUsage(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
24
+ }
25
+ if (exportNamesValid.length === 2) {
26
+ assertWarning(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`, {
27
+ onlyOnce: true
28
+ });
29
+ }
30
+ assert(exportNamesValid.length === 1);
31
+ assert(exportNamesInvalid.length > 0);
32
+ if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
33
+ exportNamesInvalid.forEach((exportInvalid) => {
34
+ assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}`, {
35
+ onlyOnce: true
36
+ });
34
37
  });
35
38
  }
36
39
  }
@@ -129,6 +129,7 @@ function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
129
129
  });
130
130
  }
131
131
  });
132
+ // Already validated by assertPlusFileExport() call above.
132
133
  assert(valueWasFound);
133
134
  return { value, sideExports };
134
135
  }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.175";
3
+ declare const PROJECT_VERSION: "0.4.176";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.175";
6
+ projectVersion: "0.4.176";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.175';
3
+ const PROJECT_VERSION = '0.4.176';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.175",
3
+ "version": "0.4.176",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",