vike 0.4.174 → 0.4.175-commit-fef43b1
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/filesystemRouting.js +31 -5
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +23 -20
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +1 -0
- package/dist/cjs/utils/isPlainObject.js +2 -0
- package/dist/cjs/utils/normalizeHeaders.js +6 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -6
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +23 -20
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +1 -0
- package/dist/esm/utils/isPlainObject.d.ts +1 -3
- package/dist/esm/utils/isPlainObject.js +3 -2
- package/dist/esm/utils/normalizeHeaders.d.ts +2 -1
- package/dist/esm/utils/normalizeHeaders.js +8 -2
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getLogicalPath = exports.applyFilesystemRoutingRootEffect = exports.isGlobalLocation = exports.sortAfterInheritanceOrder = exports.getLocationId = exports.isInherited = exports.getFilesystemRouteDefinedBy = exports.getFilesystemRouteString = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
4
8
|
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
5
10
|
/**
|
|
6
11
|
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
7
12
|
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
@@ -20,7 +25,7 @@ filePathAbsoluteUserRootDir) {
|
|
|
20
25
|
exports.getLocationId = getLocationId;
|
|
21
26
|
/** Filesystem Routing: get the URL */
|
|
22
27
|
function getFilesystemRouteString(locationId) {
|
|
23
|
-
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
28
|
+
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index'], true);
|
|
24
29
|
}
|
|
25
30
|
exports.getFilesystemRouteString = getFilesystemRouteString;
|
|
26
31
|
/** Filesystem Inheritance: get the apply root */
|
|
@@ -30,8 +35,8 @@ function getInheritanceRoot(locationId) {
|
|
|
30
35
|
/**
|
|
31
36
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
32
37
|
*/
|
|
33
|
-
function getLogicalPath(locationId,
|
|
34
|
-
let logicalPath =
|
|
38
|
+
function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
39
|
+
let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs, removeParenthesesDirs);
|
|
35
40
|
assertIsPath(logicalPath);
|
|
36
41
|
return logicalPath;
|
|
37
42
|
}
|
|
@@ -86,11 +91,32 @@ function isInherited(locationId1, locationId2) {
|
|
|
86
91
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
87
92
|
}
|
|
88
93
|
exports.isInherited = isInherited;
|
|
89
|
-
function
|
|
94
|
+
function removeIgnoredDirectories(somePath, ignoredDirs, removeParenthesesDirs) {
|
|
90
95
|
(0, utils_js_1.assertPosixPath)(somePath);
|
|
91
96
|
somePath = somePath
|
|
92
97
|
.split('/')
|
|
93
|
-
.filter((
|
|
98
|
+
.filter((dir) => {
|
|
99
|
+
if (ignoredDirs.includes(dir)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (removeParenthesesDirs && 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
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
})
|
|
94
120
|
.join('/');
|
|
95
121
|
if (somePath === '')
|
|
96
122
|
somePath = '/';
|
|
@@ -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
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPlainObject = void 0;
|
|
4
4
|
function isPlainObject(value) {
|
|
5
|
+
// Is object?
|
|
5
6
|
if (typeof value !== 'object' || value === null) {
|
|
6
7
|
return false;
|
|
7
8
|
}
|
|
@@ -9,6 +10,7 @@ function isPlainObject(value) {
|
|
|
9
10
|
if (Object.getPrototypeOf(value) === null) {
|
|
10
11
|
return true;
|
|
11
12
|
}
|
|
13
|
+
// Is plain object?
|
|
12
14
|
return (
|
|
13
15
|
/* Doesn't work in Cloudflare Pages workers
|
|
14
16
|
value.constructor === Object
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeHeaders = void 0;
|
|
4
|
+
const isObject_js_1 = require("./isObject.js");
|
|
4
5
|
function normalizeHeaders(
|
|
5
6
|
/* This type is precise, too precise which can be annoying: e.g. cannot pass a string[][] argument because it doesn't match the more precise [string,string][] type.
|
|
6
7
|
headersOriginal ConstructorParameters<typeof Headers>[0]
|
|
7
8
|
*/
|
|
8
9
|
headersOriginal) {
|
|
9
|
-
|
|
10
|
+
let headersCleaned = headersOriginal;
|
|
11
|
+
// Copied from https://github.com/hattipjs/hattip/blob/69237d181300b200a14114df2c3c115c44e0f3eb/packages/adapter/adapter-node/src/request.ts#L78-L83
|
|
12
|
+
if ((0, isObject_js_1.isObject)(headersCleaned) && headersCleaned[':method'])
|
|
13
|
+
headersCleaned = Object.fromEntries(Object.entries(headersCleaned).filter(([key]) => !key.startsWith(':')));
|
|
14
|
+
const headersStandard = new Headers(headersCleaned);
|
|
10
15
|
const headers = Object.fromEntries(headersStandard.entries());
|
|
11
16
|
return headers;
|
|
12
17
|
}
|
|
@@ -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.
|
|
4
|
+
const PROJECT_VERSION = '0.4.175-commit-fef43b1';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -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,
|
|
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;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -7,7 +7,9 @@ export { isGlobalLocation };
|
|
|
7
7
|
export { applyFilesystemRoutingRootEffect };
|
|
8
8
|
// For ./filesystemRouting.spec.ts
|
|
9
9
|
export { getLogicalPath };
|
|
10
|
-
import
|
|
10
|
+
import pc from '@brillout/picocolors';
|
|
11
|
+
import { assert, assertIsNotProductionRuntime, assertPosixPath, assertWarning, higherFirst } from '../../../../utils.js';
|
|
12
|
+
assertIsNotProductionRuntime();
|
|
11
13
|
/**
|
|
12
14
|
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
13
15
|
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
@@ -25,7 +27,7 @@ filePathAbsoluteUserRootDir) {
|
|
|
25
27
|
}
|
|
26
28
|
/** Filesystem Routing: get the URL */
|
|
27
29
|
function getFilesystemRouteString(locationId) {
|
|
28
|
-
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
30
|
+
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index'], true);
|
|
29
31
|
}
|
|
30
32
|
/** Filesystem Inheritance: get the apply root */
|
|
31
33
|
function getInheritanceRoot(locationId) {
|
|
@@ -34,8 +36,8 @@ function getInheritanceRoot(locationId) {
|
|
|
34
36
|
/**
|
|
35
37
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
36
38
|
*/
|
|
37
|
-
function getLogicalPath(locationId,
|
|
38
|
-
let logicalPath =
|
|
39
|
+
function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
40
|
+
let logicalPath = removeIgnoredDirectories(locationId, ignoredDirs, removeParenthesesDirs);
|
|
39
41
|
assertIsPath(logicalPath);
|
|
40
42
|
return logicalPath;
|
|
41
43
|
}
|
|
@@ -86,11 +88,32 @@ function isInherited(locationId1, locationId2) {
|
|
|
86
88
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
87
89
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
88
90
|
}
|
|
89
|
-
function
|
|
91
|
+
function removeIgnoredDirectories(somePath, ignoredDirs, removeParenthesesDirs) {
|
|
90
92
|
assertPosixPath(somePath);
|
|
91
93
|
somePath = somePath
|
|
92
94
|
.split('/')
|
|
93
|
-
.filter((
|
|
95
|
+
.filter((dir) => {
|
|
96
|
+
if (ignoredDirs.includes(dir)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (removeParenthesesDirs && 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
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
})
|
|
94
117
|
.join('/');
|
|
95
118
|
if (somePath === '')
|
|
96
119
|
somePath = '/';
|
|
@@ -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
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export function isPlainObject(value) {
|
|
2
|
+
// Is object?
|
|
3
3
|
if (typeof value !== 'object' || value === null) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
@@ -7,6 +7,7 @@ function isPlainObject(value) {
|
|
|
7
7
|
if (Object.getPrototypeOf(value) === null) {
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
+
// Is plain object?
|
|
10
11
|
return (
|
|
11
12
|
/* Doesn't work in Cloudflare Pages workers
|
|
12
13
|
value.constructor === Object
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { normalizeHeaders };
|
|
2
|
+
declare function normalizeHeaders(headersOriginal: unknown): Record<string, string>;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { normalizeHeaders };
|
|
2
|
+
import { isObject } from './isObject.js';
|
|
3
|
+
function normalizeHeaders(
|
|
2
4
|
/* This type is precise, too precise which can be annoying: e.g. cannot pass a string[][] argument because it doesn't match the more precise [string,string][] type.
|
|
3
5
|
headersOriginal ConstructorParameters<typeof Headers>[0]
|
|
4
6
|
*/
|
|
5
7
|
headersOriginal) {
|
|
6
|
-
|
|
8
|
+
let headersCleaned = headersOriginal;
|
|
9
|
+
// Copied from https://github.com/hattipjs/hattip/blob/69237d181300b200a14114df2c3c115c44e0f3eb/packages/adapter/adapter-node/src/request.ts#L78-L83
|
|
10
|
+
if (isObject(headersCleaned) && headersCleaned[':method'])
|
|
11
|
+
headersCleaned = Object.fromEntries(Object.entries(headersCleaned).filter(([key]) => !key.startsWith(':')));
|
|
12
|
+
const headersStandard = new Headers(headersCleaned);
|
|
7
13
|
const headers = Object.fromEntries(headersStandard.entries());
|
|
8
14
|
return headers;
|
|
9
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.175-commit-fef43b1";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.175-commit-fef43b1";
|
|
7
7
|
};
|