@shuvi/platform-shared 1.0.0-rc.1 → 1.0.0-rc.12
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/esm/shared/application.d.ts +13 -66
- package/esm/shared/application.js +41 -12
- package/esm/shared/applicationTypes.d.ts +15 -18
- package/esm/shared/helper/getAppData.d.ts +1 -4
- package/esm/shared/helper/getAppData.js +0 -1
- package/esm/shared/helper/getPublicPath.js +1 -2
- package/esm/shared/index.d.ts +3 -1
- package/esm/shared/index.js +2 -3
- package/esm/shared/loader/index.d.ts +0 -1
- package/esm/shared/loader/index.js +0 -1
- package/esm/shared/loader/loader.d.ts +1 -1
- package/esm/shared/loader/loader.js +2 -2
- package/esm/shared/loader/types.d.ts +4 -8
- package/esm/shared/models/error.d.ts +4 -4
- package/esm/shared/models/error.js +2 -2
- package/esm/shared/models/loader.d.ts +13 -0
- package/esm/shared/models/loader.js +24 -0
- package/esm/shared/routerTypes.d.ts +28 -15
- package/esm/shared/{lifecycle.d.ts → runtimPlugin.d.ts} +2 -4
- package/esm/shared/{lifecycle.js → runtimPlugin.js} +2 -1
- package/esm/shared/runtimeConfigTypes.d.ts +1 -0
- package/esm/shared/runtimeConfigTypes.js +1 -0
- package/esm/shared/shuvi-singleton-runtimeConfig.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-app.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +1 -1
- package/esm/shuvi-app/shuvi-runtime-index.js +1 -1
- package/lib/node/platform/index.d.ts +1 -13
- package/lib/node/platform/plugins/main/hooks.d.ts +1 -1
- package/lib/node/platform/plugins/main/index.d.ts +1 -13
- package/lib/node/platform/plugins/main/index.js +1 -2
- package/lib/node/platform/runtimeFiles.d.ts +1 -1
- package/lib/node/platform/runtimeFiles.js +2 -1
- package/lib/node/project/file-presets/files/app/core/entry.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/error.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/platform.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/polyfill.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/runtimeConfig.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/setPublicRuntimeConfig.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/core/setRuntimeConfig.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/app.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/error.js.d.ts +1 -1
- package/lib/node/project/file-presets/files/app/user/server.js.d.ts +3 -0
- package/lib/node/project/file-presets/files/app/user/server.js.js +15 -0
- package/lib/node/project/file-presets/index.d.ts +3 -3
- package/lib/node/project/projectContext.d.ts +2 -1
- package/lib/node/project/projectContext.js +2 -1
- package/lib/node/route/helpers.d.ts +5 -6
- package/lib/node/route/helpers.js +32 -47
- package/lib/node/route/index.d.ts +1 -1
- package/lib/node/route/index.js +2 -1
- package/lib/node/route/matchSpec.d.ts +8 -0
- package/lib/node/route/matchSpec.js +138 -0
- package/lib/node/route/route.d.ts +9 -12
- package/lib/node/route/route.js +88 -78
- package/lib/shared/application.d.ts +13 -66
- package/lib/shared/application.js +43 -14
- package/lib/shared/applicationTypes.d.ts +15 -18
- package/lib/shared/helper/getAppData.d.ts +1 -4
- package/lib/shared/helper/getAppData.js +0 -1
- package/lib/shared/helper/getPublicPath.js +1 -2
- package/lib/shared/index.d.ts +3 -1
- package/lib/shared/index.js +7 -4
- package/lib/shared/loader/index.d.ts +0 -1
- package/lib/shared/loader/index.js +0 -1
- package/lib/shared/loader/loader.d.ts +1 -1
- package/lib/shared/loader/loader.js +2 -2
- package/lib/shared/loader/types.d.ts +4 -8
- package/lib/shared/models/error.d.ts +4 -4
- package/lib/shared/models/error.js +2 -2
- package/lib/shared/models/loader.d.ts +13 -0
- package/lib/shared/models/loader.js +27 -0
- package/lib/shared/routerTypes.d.ts +28 -15
- package/lib/shared/{lifecycle.d.ts → runtimPlugin.d.ts} +2 -4
- package/lib/shared/{lifecycle.js → runtimPlugin.js} +4 -2
- package/lib/shared/runtimeConfigTypes.d.ts +1 -0
- package/lib/{node/platform/plugins/main/shuvi-app.js → shared/runtimeConfigTypes.js} +0 -0
- package/lib/shared/shuvi-singleton-runtimeConfig.d.ts +1 -1
- package/package.json +31 -20
- package/shuvi-type-extensions-node.js +1 -0
- package/{shuvi-app-extensions.d.ts → shuvi-type-extensions-runtime.d.ts} +2 -6
- package/esm/shared/loader/loaderManager.d.ts +0 -16
- package/esm/shared/loader/loaderManager.js +0 -49
- package/lib/node/platform/plugins/main/shuvi-app.d.ts +0 -8
- package/lib/shared/loader/loaderManager.d.ts +0 -16
- package/lib/shared/loader/loaderManager.js +0 -53
|
@@ -45,7 +45,8 @@ const getPresetRuntimeFilesCreator = (platformModule, polyfills) => (pluginConte
|
|
|
45
45
|
const context = (0, projectContext_1.createProjectContext)();
|
|
46
46
|
context.userModule = {
|
|
47
47
|
error: getCandidates('error', 'nullish'),
|
|
48
|
-
app: getCandidates('app', 'noop')
|
|
48
|
+
app: getCandidates('app', 'noop'),
|
|
49
|
+
server: getCandidates('server', 'noop')
|
|
49
50
|
};
|
|
50
51
|
context.platformModule = platformModule;
|
|
51
52
|
context.runtimeConfig = Object.assign(Object.assign({}, serverRuntimeConfig), publicRuntimeConfig);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").
|
|
1
|
+
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").FileOptionWithoutId<string, any>, "name">;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project/index").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project/index").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project/index").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project/index").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").
|
|
1
|
+
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").FileOptionWithoutId<string, any>, "name">;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").
|
|
1
|
+
declare const _default: () => Omit<import("@shuvi/service/lib/project/index").FileOptionWithoutId<string, any>, "name">;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectContext } from '../../../../projectContext';
|
|
2
|
-
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").
|
|
2
|
+
declare const _default: (context: ProjectContext) => Omit<import("@shuvi/service/lib/project").FileOptionWithoutId<string, any>, "name">;
|
|
3
3
|
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const project_1 = require("@shuvi/service/lib/project");
|
|
4
|
+
const __1 = require("../../..");
|
|
5
|
+
const { getAllFiles, getFirstModuleExport } = project_1.fileUtils;
|
|
6
|
+
exports.default = (context) => {
|
|
7
|
+
const { server } = context.userModule;
|
|
8
|
+
const candidates = Array.isArray(server) ? server : [server];
|
|
9
|
+
return (0, __1.defineFile)({
|
|
10
|
+
dependencies: candidates,
|
|
11
|
+
content: () => {
|
|
12
|
+
return getFirstModuleExport(getAllFiles(candidates), candidates);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileOption, FileOptionWithoutId } from '@shuvi/service/lib/project';
|
|
2
2
|
import { ProjectContext } from '../projectContext';
|
|
3
|
-
export declare function getFilePresets(context: ProjectContext):
|
|
4
|
-
export declare const defineFile: (options: Omit<
|
|
3
|
+
export declare function getFilePresets(context: ProjectContext): FileOption<any>[];
|
|
4
|
+
export declare const defineFile: (options: Omit<FileOptionWithoutId, 'name'>) => Omit<FileOptionWithoutId<string, any>, "name">;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IRuntimeConfig } from '
|
|
1
|
+
import { IRuntimeConfig } from '../../shared';
|
|
2
2
|
export interface UserModule {
|
|
3
3
|
app: string | string[];
|
|
4
4
|
error: string | string[];
|
|
5
|
+
server: string | string[];
|
|
5
6
|
}
|
|
6
7
|
export interface ProjectContext {
|
|
7
8
|
entryCodes: string[];
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { IApiRouteConfig, IMiddlewareRouteConfig, IPageRouteConfig } from './route';
|
|
2
1
|
declare const supportFileTypes: readonly ["page", "layout", "middleware", "api"];
|
|
3
2
|
declare type GetArrayElementType<T extends readonly any[]> = T extends readonly any[] ? T[number] : never;
|
|
4
3
|
export declare type SupportFileType = GetArrayElementType<typeof supportFileTypes>;
|
|
5
4
|
declare type CapName = Capitalize<SupportFileType>;
|
|
6
5
|
declare type FileTypeChecker = Record<`is${CapName}`, (filename: string) => boolean>;
|
|
7
|
-
export declare function normalizeFilePath(filepath: string): string;
|
|
8
6
|
export declare function parseDynamicPath(normalizedRoute: string): string;
|
|
9
7
|
export declare function normalizeRoutePath(rawPath: string): string;
|
|
10
|
-
export declare
|
|
8
|
+
export declare function combineComponents(fisrt: string, sec: string): string;
|
|
11
9
|
export declare const isRouteFile: (file: string) => boolean;
|
|
12
10
|
export declare const getAllowFilesAndDirs: (dirname: string) => Promise<string[]>;
|
|
13
11
|
export declare const hasAllowFiles: (files: string[]) => boolean;
|
|
14
12
|
export declare const readDir: (fullPath: string) => Promise<string[]>;
|
|
15
13
|
export declare const hasRouteChildren: (files: string[], parentPath: string) => Promise<boolean>;
|
|
16
14
|
declare const fileTypeChecker: FileTypeChecker;
|
|
17
|
-
declare function sortRoutes
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
declare function sortRoutes<T extends {
|
|
16
|
+
path: string;
|
|
17
|
+
children?: T[];
|
|
18
|
+
}>(routes: T[]): T[];
|
|
20
19
|
export { fileTypeChecker, sortRoutes };
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.sortRoutes = exports.fileTypeChecker = exports.hasRouteChildren = exports.readDir = exports.hasAllowFiles = exports.getAllowFilesAndDirs = exports.isRouteFile = exports.
|
|
15
|
+
exports.sortRoutes = exports.fileTypeChecker = exports.hasRouteChildren = exports.readDir = exports.hasAllowFiles = exports.getAllowFilesAndDirs = exports.isRouteFile = exports.combineComponents = exports.normalizeRoutePath = exports.parseDynamicPath = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const file_1 = require("@shuvi/utils/lib/file");
|
|
@@ -20,53 +20,26 @@ const invariant_1 = __importDefault(require("@shuvi/utils/lib/invariant"));
|
|
|
20
20
|
const router_1 = require("../../shared/router");
|
|
21
21
|
const supportFileTypes = ['page', 'layout', 'middleware', 'api'];
|
|
22
22
|
const allowReadFilExtList = ['ts', 'js', 'tsx', 'jsx'];
|
|
23
|
-
const dynamicMatchAllRegex =
|
|
24
|
-
const dynamicMatchPartRegex =
|
|
25
|
-
function normalizeFilePath(filepath) {
|
|
26
|
-
const res = filepath
|
|
27
|
-
// Remove the file extension from the end
|
|
28
|
-
.replace(/\.\w+$/, '')
|
|
29
|
-
// Convert to unix path
|
|
30
|
-
.replace(/\\/g, '/');
|
|
31
|
-
return res.charAt(0) !== '/' ? '/' + res : res;
|
|
32
|
-
}
|
|
33
|
-
exports.normalizeFilePath = normalizeFilePath;
|
|
23
|
+
const dynamicMatchAllRegex = /\$$/;
|
|
24
|
+
const dynamicMatchPartRegex = /\$/g;
|
|
34
25
|
function parseDynamicPath(normalizedRoute) {
|
|
35
|
-
(0, invariant_1.default)(normalizedRoute
|
|
36
|
-
(0, invariant_1.default)(!checkSpecialRegexChars(normalizedRoute), 'filePath should not be special regex chars: |\\{}()^$+*?');
|
|
26
|
+
(0, invariant_1.default)(!checkSpecialRegexChars(normalizedRoute), 'filePath should not be special regex chars: |\\{}()^:+*?');
|
|
37
27
|
return normalizedRoute
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
.map(segment => {
|
|
41
|
-
let result = '';
|
|
42
|
-
result = segment.replace(dynamicMatchAllRegex, function (matchString, ...matchArr) {
|
|
43
|
-
return parseMatchRepeat(matchArr[0], true);
|
|
44
|
-
});
|
|
45
|
-
result = result.replace(dynamicMatchPartRegex, function (matchString, ...matchArr) {
|
|
46
|
-
return parseMatchRepeat(matchArr[0], false);
|
|
47
|
-
});
|
|
48
|
-
return `/${result}`;
|
|
49
|
-
})
|
|
50
|
-
.join('');
|
|
28
|
+
.replace(dynamicMatchAllRegex, '*')
|
|
29
|
+
.replace(dynamicMatchPartRegex, ':');
|
|
51
30
|
}
|
|
52
31
|
exports.parseDynamicPath = parseDynamicPath;
|
|
53
|
-
function parseMatchRepeat(param, optional) {
|
|
54
|
-
const repeat = param.startsWith('...');
|
|
55
|
-
if (repeat) {
|
|
56
|
-
param = param.slice(3);
|
|
57
|
-
}
|
|
58
|
-
return repeat
|
|
59
|
-
? optional
|
|
60
|
-
? `:${param}*`
|
|
61
|
-
: `:${param}+`
|
|
62
|
-
: `:${param}${optional ? '?' : ''}`;
|
|
63
|
-
}
|
|
64
32
|
function checkSpecialRegexChars(string) {
|
|
65
|
-
return /[|\\{}()
|
|
33
|
+
return /[|\\{}()^:+*?]/g.test(string);
|
|
66
34
|
}
|
|
67
35
|
function normalizeRoutePath(rawPath) {
|
|
36
|
+
let routePath = rawPath
|
|
37
|
+
// Remove the file extension from the end
|
|
38
|
+
.replace(/\.\w+$/, '')
|
|
39
|
+
// Convert to unix path
|
|
40
|
+
.replace(/\\/g, '/');
|
|
68
41
|
// /xxxx/index -> /xxxx/
|
|
69
|
-
|
|
42
|
+
routePath = rawPath.replace(/\/index$/, '/');
|
|
70
43
|
// remove the last slash
|
|
71
44
|
// e.g. /abc/ -> /abc
|
|
72
45
|
if (routePath !== '/' && routePath.slice(-1) === '/') {
|
|
@@ -76,14 +49,26 @@ function normalizeRoutePath(rawPath) {
|
|
|
76
49
|
return routePath;
|
|
77
50
|
}
|
|
78
51
|
exports.normalizeRoutePath = normalizeRoutePath;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return result;
|
|
52
|
+
function combineComponents(fisrt, sec) {
|
|
53
|
+
if (fisrt === '' || sec === '') {
|
|
54
|
+
return `${fisrt}${sec}`;
|
|
83
55
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
if (fisrt.endsWith('/')) {
|
|
57
|
+
if (sec.startsWith('/')) {
|
|
58
|
+
return `${fisrt}${sec.slice(1)}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return `${fisrt}${sec}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (sec.startsWith('/')) {
|
|
65
|
+
return `${fisrt}${sec}`;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return `${fisrt}/${sec}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.combineComponents = combineComponents;
|
|
87
72
|
const isRouteFile = (file) => {
|
|
88
73
|
return Object.keys(fileTypeChecker).some(key => {
|
|
89
74
|
return fileTypeChecker[key](file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { IPageRouteConfig, IApiRouteConfig, IMiddlewareRouteConfig, getPageRoutes, getApiRoutes, getMiddlewareRoutes } from './route';
|
|
1
|
+
export { RawRoutes, PageRoutes, ApiRoutes, MiddlewareRoutes, IPageRouteConfig, IApiRouteConfig, IMiddlewareRouteConfig, getRawRoutesFromDir, getPageRoutes, getApiRoutes, getMiddlewareRoutes } from './route';
|
package/lib/node/route/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMiddlewareRoutes = exports.getApiRoutes = exports.getPageRoutes = void 0;
|
|
3
|
+
exports.getMiddlewareRoutes = exports.getApiRoutes = exports.getPageRoutes = exports.getRawRoutesFromDir = void 0;
|
|
4
4
|
var route_1 = require("./route");
|
|
5
|
+
Object.defineProperty(exports, "getRawRoutesFromDir", { enumerable: true, get: function () { return route_1.getRawRoutesFromDir; } });
|
|
5
6
|
Object.defineProperty(exports, "getPageRoutes", { enumerable: true, get: function () { return route_1.getPageRoutes; } });
|
|
6
7
|
Object.defineProperty(exports, "getApiRoutes", { enumerable: true, get: function () { return route_1.getApiRoutes; } });
|
|
7
8
|
Object.defineProperty(exports, "getMiddlewareRoutes", { enumerable: true, get: function () { return route_1.getMiddlewareRoutes; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface FileMatcherPatterns {
|
|
2
|
+
excludePattern: string | undefined;
|
|
3
|
+
}
|
|
4
|
+
export declare function getRegularExpressionsForWildcards(specs: readonly string[] | undefined, basePath: string): readonly string[] | undefined;
|
|
5
|
+
export declare function getRegularExpressionForWildcard(specs: readonly string[] | undefined, basePath: string, usage: 'exclude'): string | undefined;
|
|
6
|
+
export declare function getRegexFromPattern(pattern: string, caseSensitive: boolean): RegExp;
|
|
7
|
+
export declare function getFileMatcherPatterns(basePath: string, excludes: readonly string[] | undefined): FileMatcherPatterns;
|
|
8
|
+
export declare function matchFile(file: string, patterns: FileMatcherPatterns, caseSensitive: boolean): boolean;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.matchFile = exports.getFileMatcherPatterns = exports.getRegexFromPattern = exports.getRegularExpressionForWildcard = exports.getRegularExpressionsForWildcards = void 0;
|
|
27
|
+
// port from typescript
|
|
28
|
+
const nodePath = __importStar(require("path"));
|
|
29
|
+
const directorySeparator = '/';
|
|
30
|
+
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
|
|
31
|
+
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
|
|
32
|
+
// proof.
|
|
33
|
+
const reservedCharacterPattern = /[^\w\s\/]/g;
|
|
34
|
+
const commonPackageFolders = ['node_modules'];
|
|
35
|
+
// does not match centeain directories or directories that start with a . character
|
|
36
|
+
const implicitExcludePathRegexPattern = `/((${commonPackageFolders.join('|')})|([/.][^/]*))`;
|
|
37
|
+
function replaceWildcardCharacter(match, singleAsteriskRegexFragment) {
|
|
38
|
+
return match === '*'
|
|
39
|
+
? singleAsteriskRegexFragment
|
|
40
|
+
: match === '?'
|
|
41
|
+
? '[^/]'
|
|
42
|
+
: '\\' + match;
|
|
43
|
+
}
|
|
44
|
+
const wildcardMatcher = {
|
|
45
|
+
singleAsteriskRegexFragment: '[^/]*',
|
|
46
|
+
doubleAsteriskRegexFragment: '(/.+?)?',
|
|
47
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, wildcardMatcher.singleAsteriskRegexFragment)
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* An "includes" path "foo" is implicitly a glob "foo/** /*" (without the space) if its last component has no extension,
|
|
51
|
+
* and does not contain any glob characters itself.
|
|
52
|
+
*/
|
|
53
|
+
function isImplicitGlob(lastPathComponent) {
|
|
54
|
+
return !/[.*?]/.test(lastPathComponent);
|
|
55
|
+
}
|
|
56
|
+
function normalizePath(path, currentDirectory) {
|
|
57
|
+
return currentDirectory
|
|
58
|
+
? nodePath.posix.resolve(currentDirectory, path)
|
|
59
|
+
: nodePath.posix.normalize(path);
|
|
60
|
+
}
|
|
61
|
+
function getNormalizedPathComponents(path, currentDirectory) {
|
|
62
|
+
const normalizedPath = normalizePath(path, currentDirectory);
|
|
63
|
+
const comps = normalizedPath.split('/');
|
|
64
|
+
if (comps.length && !comps[comps.length - 1])
|
|
65
|
+
comps.pop();
|
|
66
|
+
return comps;
|
|
67
|
+
}
|
|
68
|
+
function getSubPatternFromSpec(spec, basePath, { doubleAsteriskRegexFragment, replaceWildcardCharacter }) {
|
|
69
|
+
let subpattern = '';
|
|
70
|
+
let hasWrittenComponent = false;
|
|
71
|
+
const components = getNormalizedPathComponents(spec, basePath);
|
|
72
|
+
const lastComponent = components[components.length - 1];
|
|
73
|
+
// remove trailing slash
|
|
74
|
+
components[0] = components[0].replace(/[/]$/, '');
|
|
75
|
+
if (isImplicitGlob(lastComponent)) {
|
|
76
|
+
components.push('**', '*');
|
|
77
|
+
}
|
|
78
|
+
for (let component of components) {
|
|
79
|
+
if (component === '**') {
|
|
80
|
+
subpattern += doubleAsteriskRegexFragment;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (hasWrittenComponent) {
|
|
84
|
+
subpattern += directorySeparator;
|
|
85
|
+
}
|
|
86
|
+
subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
|
|
87
|
+
}
|
|
88
|
+
hasWrittenComponent = true;
|
|
89
|
+
}
|
|
90
|
+
return subpattern;
|
|
91
|
+
}
|
|
92
|
+
function getRegularExpressionsForWildcards(specs, basePath) {
|
|
93
|
+
if (specs === undefined || specs.length === 0) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const result = [];
|
|
97
|
+
for (const spec of specs) {
|
|
98
|
+
if (spec) {
|
|
99
|
+
let r = getSubPatternFromSpec(spec, basePath, wildcardMatcher);
|
|
100
|
+
if (r) {
|
|
101
|
+
result.push(r);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
exports.getRegularExpressionsForWildcards = getRegularExpressionsForWildcards;
|
|
108
|
+
function getRegularExpressionForWildcard(specs, basePath, usage) {
|
|
109
|
+
const patterns = getRegularExpressionsForWildcards(specs, basePath);
|
|
110
|
+
if (!patterns || !patterns.length) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const pattern = patterns.map(pattern => `(${pattern})`).join('|');
|
|
114
|
+
// If excluding, match "foo/bar/baz...", but if including, only allow "foo".
|
|
115
|
+
const terminator = usage === 'exclude' ? '($|/)' : '$';
|
|
116
|
+
return `^(${pattern})${terminator}`;
|
|
117
|
+
}
|
|
118
|
+
exports.getRegularExpressionForWildcard = getRegularExpressionForWildcard;
|
|
119
|
+
function getRegexFromPattern(pattern, caseSensitive) {
|
|
120
|
+
return new RegExp(pattern, caseSensitive ? '' : 'i');
|
|
121
|
+
}
|
|
122
|
+
exports.getRegexFromPattern = getRegexFromPattern;
|
|
123
|
+
function getFileMatcherPatterns(basePath, excludes) {
|
|
124
|
+
const absolutePath = normalizePath(basePath);
|
|
125
|
+
return {
|
|
126
|
+
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, 'exclude')
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
exports.getFileMatcherPatterns = getFileMatcherPatterns;
|
|
130
|
+
function matchFile(file, patterns, caseSensitive) {
|
|
131
|
+
file = normalizePath(file);
|
|
132
|
+
const excludeRegex = patterns.excludePattern &&
|
|
133
|
+
getRegexFromPattern(patterns.excludePattern, caseSensitive);
|
|
134
|
+
const implicitExcludeRegex = getRegexFromPattern(implicitExcludePathRegexPattern, caseSensitive);
|
|
135
|
+
return (!implicitExcludeRegex.test(file) &&
|
|
136
|
+
(!excludeRegex || !excludeRegex.test(file)));
|
|
137
|
+
}
|
|
138
|
+
exports.matchFile = matchFile;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPageRouteConfig, IApiRouteConfig, IMiddlewareRouteConfig } from '../../shared';
|
|
2
2
|
import { SupportFileType } from './helpers';
|
|
3
|
-
export
|
|
4
|
-
export type { IApiRouteConfig, IMiddlewareRouteConfig };
|
|
3
|
+
export type { IPageRouteConfig, IApiRouteConfig, IMiddlewareRouteConfig };
|
|
5
4
|
interface RawFileRoute {
|
|
6
5
|
kind: 'file';
|
|
7
6
|
type: SupportFileType;
|
|
8
|
-
name: string;
|
|
9
|
-
segment: string;
|
|
10
7
|
filepath: string;
|
|
8
|
+
segment: string;
|
|
11
9
|
}
|
|
12
|
-
interface RawDirRoute {
|
|
10
|
+
export interface RawDirRoute {
|
|
13
11
|
kind: 'dir';
|
|
14
12
|
filepath: string;
|
|
15
13
|
segment: string;
|
|
16
|
-
parentSegment: string;
|
|
17
14
|
children: (RawFileRoute | RawDirRoute)[];
|
|
18
15
|
}
|
|
19
|
-
declare type RawRoute = RawFileRoute | RawDirRoute;
|
|
16
|
+
export declare type RawRoute = RawFileRoute | RawDirRoute;
|
|
20
17
|
export interface RouteException {
|
|
21
18
|
type: SupportFileType | 'dir';
|
|
22
19
|
msg: string;
|
|
@@ -31,7 +28,7 @@ export declare type PageRoutes = RouteResult<IPageRouteConfig>;
|
|
|
31
28
|
export declare type ApiRoutes = RouteResult<IApiRouteConfig>;
|
|
32
29
|
export declare type MiddlewareRoutes = RouteResult<IMiddlewareRouteConfig>;
|
|
33
30
|
export declare type RouteConfigType = IPageRouteConfig | IApiRouteConfig | IMiddlewareRouteConfig;
|
|
34
|
-
export declare const getRawRoutesFromDir: (dirname: string) => Promise<RawRoutes>;
|
|
35
|
-
export declare const getPageRoutes: (
|
|
36
|
-
export declare const getApiRoutes: (dir: string) => Promise<ApiRoutes>;
|
|
37
|
-
export declare const getMiddlewareRoutes: (
|
|
31
|
+
export declare const getRawRoutesFromDir: (dirname: string, excludes?: string[]) => Promise<RawRoutes>;
|
|
32
|
+
export declare const getPageRoutes: (dir: string | RawRoutes, excludes?: string[]) => Promise<PageRoutes>;
|
|
33
|
+
export declare const getApiRoutes: (dir: string | RawRoutes, excludes?: string[]) => Promise<ApiRoutes>;
|
|
34
|
+
export declare const getMiddlewareRoutes: (dir: string | RawRoutes, excludes?: string[]) => Promise<MiddlewareRoutes>;
|