@modern-js/runtime 2.53.0 → 2.54.0
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/{runtimeContext.js → cli/constants.js} +6 -10
- package/dist/cjs/cli/entry.js +42 -0
- package/dist/cjs/cli/index.js +10 -0
- package/dist/cjs/core/compatible.js +13 -29
- package/dist/cjs/core/{appConfig.js → config.js} +6 -4
- package/dist/cjs/core/context/index.js +28 -0
- package/dist/cjs/core/context/runtime.js +42 -0
- package/dist/cjs/core/index.js +8 -12
- package/dist/cjs/core/loader/useLoader.js +2 -2
- package/dist/cjs/core/{plugin.js → plugin/base.js} +5 -25
- package/dist/cjs/core/plugin/index.js +39 -0
- package/dist/cjs/core/plugin/runner.js +42 -0
- package/dist/cjs/index.js +2 -4
- package/dist/cjs/router/cli/code/getClientRoutes/getRoutes.js +197 -0
- package/dist/cjs/router/cli/code/getClientRoutes/getRoutesLegacy.js +195 -0
- package/dist/cjs/router/cli/code/getClientRoutes/index.js +31 -0
- package/dist/cjs/router/cli/code/getClientRoutes/utils.js +59 -0
- package/dist/cjs/router/cli/code/index.js +134 -0
- package/dist/cjs/router/cli/code/makeLegalIdentifier.js +37 -0
- package/dist/cjs/router/cli/code/nestedRoutes.js +294 -0
- package/dist/cjs/router/cli/code/templates.js +371 -0
- package/dist/cjs/router/cli/code/utils.js +143 -0
- package/dist/cjs/router/cli/constants.js +83 -0
- package/dist/cjs/router/cli/entry.js +87 -0
- package/dist/cjs/router/cli/handler.js +71 -0
- package/dist/cjs/router/cli/index.js +25 -0
- package/dist/cjs/router/runtime/plugin.js +7 -4
- package/dist/cjs/router/runtime/plugin.node.js +12 -5
- package/dist/cjs/ssr/index.node.js +1 -0
- package/dist/cjs/state/runtime/plugin.js +3 -2
- package/dist/esm/cli/constants.js +4 -0
- package/dist/esm/cli/entry.js +14 -0
- package/dist/esm/cli/index.js +10 -0
- package/dist/esm/core/compatible.js +11 -30
- package/dist/esm/core/{appConfig.js → config.js} +4 -1
- package/dist/esm/core/context/index.js +4 -0
- package/dist/esm/core/context/runtime.js +18 -0
- package/dist/esm/core/index.js +4 -6
- package/dist/esm/core/loader/useLoader.js +1 -1
- package/dist/esm/core/plugin/base.js +21 -0
- package/dist/esm/core/plugin/index.js +15 -0
- package/dist/esm/core/plugin/runner.js +17 -0
- package/dist/esm/index.js +2 -3
- package/dist/esm/router/cli/code/getClientRoutes/getRoutes.js +185 -0
- package/dist/esm/router/cli/code/getClientRoutes/getRoutesLegacy.js +183 -0
- package/dist/esm/router/cli/code/getClientRoutes/index.js +6 -0
- package/dist/esm/router/cli/code/getClientRoutes/utils.js +28 -0
- package/dist/esm/router/cli/code/index.js +214 -0
- package/dist/esm/router/cli/code/makeLegalIdentifier.js +15 -0
- package/dist/esm/router/cli/code/nestedRoutes.js +397 -0
- package/dist/esm/router/cli/code/templates.js +417 -0
- package/dist/esm/router/cli/code/utils.js +212 -0
- package/dist/esm/router/cli/constants.js +47 -0
- package/dist/esm/router/cli/entry.js +57 -0
- package/dist/esm/router/cli/handler.js +103 -0
- package/dist/esm/router/cli/index.js +57 -0
- package/dist/esm/router/runtime/plugin.js +7 -4
- package/dist/esm/router/runtime/plugin.node.js +13 -6
- package/dist/esm/ssr/index.node.js +1 -0
- package/dist/esm/state/runtime/plugin.js +3 -2
- package/dist/esm-node/cli/constants.js +4 -0
- package/dist/esm-node/cli/entry.js +8 -0
- package/dist/esm-node/cli/index.js +9 -0
- package/dist/esm-node/core/compatible.js +12 -28
- package/dist/esm-node/core/{appConfig.js → config.js} +2 -1
- package/dist/esm-node/core/context/index.js +4 -0
- package/dist/esm-node/core/context/runtime.js +16 -0
- package/dist/esm-node/core/index.js +4 -6
- package/dist/esm-node/core/loader/useLoader.js +1 -1
- package/dist/esm-node/core/plugin/base.js +19 -0
- package/dist/esm-node/core/plugin/index.js +13 -0
- package/dist/esm-node/core/plugin/runner.js +17 -0
- package/dist/esm-node/index.js +2 -3
- package/dist/esm-node/router/cli/code/getClientRoutes/getRoutes.js +163 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/getRoutesLegacy.js +161 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/index.js +6 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/utils.js +22 -0
- package/dist/esm-node/router/cli/code/index.js +100 -0
- package/dist/esm-node/router/cli/code/makeLegalIdentifier.js +13 -0
- package/dist/esm-node/router/cli/code/nestedRoutes.js +258 -0
- package/dist/esm-node/router/cli/code/templates.js +335 -0
- package/dist/esm-node/router/cli/code/utils.js +101 -0
- package/dist/esm-node/router/cli/constants.js +47 -0
- package/dist/esm-node/router/cli/entry.js +50 -0
- package/dist/esm-node/router/cli/handler.js +36 -0
- package/dist/esm-node/router/cli/index.js +22 -0
- package/dist/esm-node/router/runtime/plugin.js +7 -4
- package/dist/esm-node/router/runtime/plugin.node.js +12 -5
- package/dist/esm-node/ssr/index.node.js +1 -0
- package/dist/esm-node/state/runtime/plugin.js +3 -2
- package/dist/types/cli/constants.d.ts +1 -0
- package/dist/types/cli/entry.d.ts +1 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/core/compatible.d.ts +7 -3
- package/dist/types/core/config.d.ts +14 -0
- package/dist/types/core/context/index.d.ts +1 -0
- package/dist/types/{runtimeContext.d.ts → core/context/runtime.d.ts} +5 -4
- package/dist/types/core/index.d.ts +4 -4
- package/dist/types/core/plugin/base.d.ts +80 -0
- package/dist/types/core/plugin/index.d.ts +29 -0
- package/dist/types/core/plugin/runner.d.ts +26 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
- package/dist/types/router/cli/code/getClientRoutes/getRoutesLegacy.d.ts +9 -0
- package/dist/types/router/cli/code/getClientRoutes/index.d.ts +2 -0
- package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +5 -0
- package/dist/types/router/cli/code/index.d.ts +6 -0
- package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
- package/dist/types/router/cli/code/nestedRoutes.d.ts +7 -0
- package/dist/types/router/cli/code/templates.d.ts +14 -0
- package/dist/types/router/cli/code/utils.d.ts +12 -0
- package/dist/types/router/cli/constants.d.ts +32 -0
- package/dist/types/router/cli/entry.d.ts +5 -0
- package/dist/types/router/cli/handler.d.ts +5 -0
- package/dist/types/router/cli/index.d.ts +3 -1
- package/dist/types/ssr/serverRender/types.d.ts +3 -0
- package/package.json +37 -11
- package/dist/esm/core/plugin.js +0 -59
- package/dist/esm/runtimeContext.js +0 -7
- package/dist/esm-node/core/plugin.js +0 -37
- package/dist/esm-node/runtimeContext.js +0 -7
- package/dist/types/core/appConfig.d.ts +0 -4
- package/dist/types/core/plugin.d.ts +0 -204
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var getRoutes_exports = {};
|
|
30
|
+
__export(getRoutes_exports, {
|
|
31
|
+
getClientRoutes: () => getClientRoutes
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(getRoutes_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_makeLegalIdentifier = require("../makeLegalIdentifier");
|
|
37
|
+
var import_constants = require("../../constants");
|
|
38
|
+
var import_utils2 = require("../utils");
|
|
39
|
+
var import_utils3 = require("./utils");
|
|
40
|
+
const compName = (srcDirectory, filePath) => {
|
|
41
|
+
const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(import_path.default.relative(srcDirectory, filePath));
|
|
42
|
+
return `Comp_${legalCompName}`;
|
|
43
|
+
};
|
|
44
|
+
const layoutNameAbbr = (filePath) => {
|
|
45
|
+
const prefix = "L_";
|
|
46
|
+
const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
|
|
47
|
+
return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
48
|
+
};
|
|
49
|
+
const parents = [];
|
|
50
|
+
const recursiveReadDir = ({ dir, routes, basePath = "/", srcDirectory, srcAlias }) => {
|
|
51
|
+
let hasDynamicRoute = false;
|
|
52
|
+
let resetParent = false;
|
|
53
|
+
let parent = parents[parents.length - 1];
|
|
54
|
+
const layout = (0, import_utils3.findLayout)(dir);
|
|
55
|
+
if (layout) {
|
|
56
|
+
if (basePath === "/") {
|
|
57
|
+
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
58
|
+
} else {
|
|
59
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
|
|
60
|
+
const componentName = compName(srcDirectory, layout);
|
|
61
|
+
const route = {
|
|
62
|
+
path: `${basePath.substring(0, basePath.length - 1)}`,
|
|
63
|
+
children: [],
|
|
64
|
+
_component: alias,
|
|
65
|
+
component: componentName,
|
|
66
|
+
parent,
|
|
67
|
+
type: "page"
|
|
68
|
+
};
|
|
69
|
+
parent = route;
|
|
70
|
+
resetParent = true;
|
|
71
|
+
routes.push(route);
|
|
72
|
+
parents.push(route);
|
|
73
|
+
routes = route.children;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const relative of import_utils.fs.readdirSync(dir)) {
|
|
77
|
+
const filePath = import_path.default.join(dir, relative);
|
|
78
|
+
if (!(0, import_utils3.shouldSkip)(filePath)) {
|
|
79
|
+
const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
|
|
80
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
|
|
81
|
+
const componentName = compName(srcDirectory, filePath);
|
|
82
|
+
const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
83
|
+
if (dynamicRouteMatched) {
|
|
84
|
+
if (hasDynamicRoute) {
|
|
85
|
+
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
86
|
+
} else {
|
|
87
|
+
hasDynamicRoute = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const route = {
|
|
91
|
+
path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
|
|
92
|
+
_component: alias,
|
|
93
|
+
component: componentName,
|
|
94
|
+
parent,
|
|
95
|
+
type: "page"
|
|
96
|
+
};
|
|
97
|
+
if (import_utils.fs.statSync(filePath).isDirectory()) {
|
|
98
|
+
recursiveReadDir({
|
|
99
|
+
dir: filePath,
|
|
100
|
+
routes,
|
|
101
|
+
basePath: `${route.path}/`,
|
|
102
|
+
srcDirectory,
|
|
103
|
+
srcAlias
|
|
104
|
+
});
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
111
|
+
route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
|
|
112
|
+
}
|
|
113
|
+
if (filename === "404" && basePath === "/") {
|
|
114
|
+
route.path = "*";
|
|
115
|
+
}
|
|
116
|
+
routes.push(route);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (resetParent) {
|
|
120
|
+
parents.pop();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
124
|
+
const flat = (routes) => routes.reduce((memo, route) => memo.concat(Array.isArray(route.children) ? flat(route.children) : [
|
|
125
|
+
route
|
|
126
|
+
]), []);
|
|
127
|
+
const generate = (route) => {
|
|
128
|
+
const codes = [];
|
|
129
|
+
let lastComponent = route.component;
|
|
130
|
+
const imports = [
|
|
131
|
+
`import React from 'react';`,
|
|
132
|
+
`import ${lastComponent} from '${route._component}'`
|
|
133
|
+
];
|
|
134
|
+
while (route = route.parent) {
|
|
135
|
+
const layoutComponent = route.component;
|
|
136
|
+
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
137
|
+
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
138
|
+
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
139
|
+
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
140
|
+
lastComponent = currentComponent;
|
|
141
|
+
}
|
|
142
|
+
const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
143
|
+
import_utils.fs.outputFileSync(file, `${imports.join("\n")}
|
|
144
|
+
${codes.join("\n")}
|
|
145
|
+
export default ${lastComponent}`);
|
|
146
|
+
return {
|
|
147
|
+
component: lastComponent,
|
|
148
|
+
_component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const normalized = flat(nested).map((route) => route.parent ? {
|
|
152
|
+
...route,
|
|
153
|
+
...generate(route),
|
|
154
|
+
parent: void 0
|
|
155
|
+
} : {
|
|
156
|
+
...route,
|
|
157
|
+
parent: void 0
|
|
158
|
+
});
|
|
159
|
+
return normalized;
|
|
160
|
+
};
|
|
161
|
+
const getClientRoutes = ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias }) => {
|
|
162
|
+
const { entryName, pageRoutesEntry } = entrypoint;
|
|
163
|
+
if (!pageRoutesEntry) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
if (!import_utils.fs.existsSync(pageRoutesEntry)) {
|
|
167
|
+
throw new Error(`generate file system routes error, ${pageRoutesEntry} directory not found.`);
|
|
168
|
+
}
|
|
169
|
+
if (!(import_utils.fs.existsSync(pageRoutesEntry) && import_utils.fs.statSync(pageRoutesEntry).isDirectory())) {
|
|
170
|
+
throw new Error(`generate file system routes error, ${pageRoutesEntry} should be directory.`);
|
|
171
|
+
}
|
|
172
|
+
let routes = [];
|
|
173
|
+
recursiveReadDir({
|
|
174
|
+
dir: pageRoutesEntry,
|
|
175
|
+
routes,
|
|
176
|
+
basePath: "/",
|
|
177
|
+
srcDirectory,
|
|
178
|
+
srcAlias
|
|
179
|
+
});
|
|
180
|
+
const internalComponentsDir = import_path.default.resolve(internalDirectory, `${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
181
|
+
import_utils.fs.emptyDirSync(internalComponentsDir);
|
|
182
|
+
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
183
|
+
parents.length = 0;
|
|
184
|
+
routes.sort((a, b) => {
|
|
185
|
+
const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
|
|
186
|
+
if (delta === 0) {
|
|
187
|
+
return a.path.length - b.path.length;
|
|
188
|
+
}
|
|
189
|
+
return delta;
|
|
190
|
+
});
|
|
191
|
+
(0, import_utils3.debug)(`fileSystem routes: %o`, routes);
|
|
192
|
+
return routes;
|
|
193
|
+
};
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
getClientRoutes
|
|
197
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var getRoutesLegacy_exports = {};
|
|
30
|
+
__export(getRoutesLegacy_exports, {
|
|
31
|
+
getClientRoutes: () => getClientRoutes
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(getRoutesLegacy_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_constants = require("../../constants");
|
|
37
|
+
var import_utils2 = require("../utils");
|
|
38
|
+
var import_makeLegalIdentifier = require("../makeLegalIdentifier");
|
|
39
|
+
var import_utils3 = require("./utils");
|
|
40
|
+
const compName = (srcDirectory, filePath) => {
|
|
41
|
+
const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(import_path.default.relative(srcDirectory, filePath));
|
|
42
|
+
return `Comp_${legalCompName}`;
|
|
43
|
+
};
|
|
44
|
+
const layoutNameAbbr = (filePath) => {
|
|
45
|
+
const prefix = "L_";
|
|
46
|
+
const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
|
|
47
|
+
return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
|
|
48
|
+
};
|
|
49
|
+
const parents = [];
|
|
50
|
+
const recursiveReadDirLegacy = ({ dir, routes, basePath = "/", srcDirectory, srcAlias }) => {
|
|
51
|
+
let hasDynamicRoute = false;
|
|
52
|
+
let resetParent = false;
|
|
53
|
+
let parent = parents[parents.length - 1];
|
|
54
|
+
const layout = (0, import_utils3.findLayout)(dir);
|
|
55
|
+
if (layout) {
|
|
56
|
+
if (basePath === "/") {
|
|
57
|
+
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
58
|
+
} else {
|
|
59
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
|
|
60
|
+
const componentName = compName(srcDirectory, layout);
|
|
61
|
+
const route = {
|
|
62
|
+
path: `${basePath.substring(0, basePath.length - 1)}`,
|
|
63
|
+
exact: false,
|
|
64
|
+
routes: [],
|
|
65
|
+
_component: alias,
|
|
66
|
+
component: componentName,
|
|
67
|
+
parent
|
|
68
|
+
};
|
|
69
|
+
parent = route;
|
|
70
|
+
resetParent = true;
|
|
71
|
+
routes.push(route);
|
|
72
|
+
parents.push(route);
|
|
73
|
+
routes = route.routes;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const relative of import_utils.fs.readdirSync(dir)) {
|
|
77
|
+
const filePath = import_path.default.join(dir, relative);
|
|
78
|
+
if (!(0, import_utils3.shouldSkip)(filePath)) {
|
|
79
|
+
const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
|
|
80
|
+
const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
|
|
81
|
+
const componentName = compName(srcDirectory, filePath);
|
|
82
|
+
const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
83
|
+
if (dynamicRouteMatched) {
|
|
84
|
+
if (hasDynamicRoute) {
|
|
85
|
+
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
86
|
+
} else {
|
|
87
|
+
hasDynamicRoute = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const route = {
|
|
91
|
+
path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
|
|
92
|
+
_component: alias,
|
|
93
|
+
component: componentName,
|
|
94
|
+
exact: true,
|
|
95
|
+
parent
|
|
96
|
+
};
|
|
97
|
+
if (import_utils.fs.statSync(filePath).isDirectory()) {
|
|
98
|
+
recursiveReadDirLegacy({
|
|
99
|
+
dir: filePath,
|
|
100
|
+
routes,
|
|
101
|
+
basePath: `${route.path}/`,
|
|
102
|
+
srcDirectory,
|
|
103
|
+
srcAlias
|
|
104
|
+
});
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
|
|
111
|
+
route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
|
|
112
|
+
}
|
|
113
|
+
if (filename === "404" && basePath === "/") {
|
|
114
|
+
route.path = "*";
|
|
115
|
+
route.exact = false;
|
|
116
|
+
}
|
|
117
|
+
routes.push(route);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (resetParent) {
|
|
121
|
+
parents.pop();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
125
|
+
const flat = (routes) => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [
|
|
126
|
+
route
|
|
127
|
+
]), []);
|
|
128
|
+
const generate = (route) => {
|
|
129
|
+
const codes = [];
|
|
130
|
+
let lastComponent = route.component;
|
|
131
|
+
const imports = [
|
|
132
|
+
`import React from 'react';`,
|
|
133
|
+
`import ${lastComponent} from '${route._component}'`
|
|
134
|
+
];
|
|
135
|
+
while (route = route.parent) {
|
|
136
|
+
const layoutComponent = route.component;
|
|
137
|
+
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
138
|
+
imports.push(`import ${layoutComponent} from '${route._component}';`);
|
|
139
|
+
const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
|
|
140
|
+
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
141
|
+
lastComponent = currentComponent;
|
|
142
|
+
}
|
|
143
|
+
const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
144
|
+
import_utils.fs.outputFileSync(file, `${imports.join("\n")}
|
|
145
|
+
${codes.join("\n")}
|
|
146
|
+
export default ${lastComponent}`);
|
|
147
|
+
return {
|
|
148
|
+
component: lastComponent,
|
|
149
|
+
_component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const normalized = flat(nested).map((route) => route.parent ? {
|
|
153
|
+
...route,
|
|
154
|
+
...generate(route),
|
|
155
|
+
parent: void 0
|
|
156
|
+
} : {
|
|
157
|
+
...route,
|
|
158
|
+
parent: void 0
|
|
159
|
+
});
|
|
160
|
+
return normalized;
|
|
161
|
+
};
|
|
162
|
+
const getClientRoutes = ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias }) => {
|
|
163
|
+
const { entry, entryName } = entrypoint;
|
|
164
|
+
if (!import_utils.fs.existsSync(entry)) {
|
|
165
|
+
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
166
|
+
}
|
|
167
|
+
if (!(import_utils.fs.existsSync(entry) && import_utils.fs.statSync(entry).isDirectory())) {
|
|
168
|
+
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
169
|
+
}
|
|
170
|
+
let routes = [];
|
|
171
|
+
recursiveReadDirLegacy({
|
|
172
|
+
dir: entry,
|
|
173
|
+
routes,
|
|
174
|
+
basePath: "/",
|
|
175
|
+
srcDirectory,
|
|
176
|
+
srcAlias
|
|
177
|
+
});
|
|
178
|
+
const internalComponentsDir = import_path.default.resolve(internalDirectory, `${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
179
|
+
import_utils.fs.emptyDirSync(internalComponentsDir);
|
|
180
|
+
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
181
|
+
parents.length = 0;
|
|
182
|
+
routes.sort((a, b) => {
|
|
183
|
+
const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
|
|
184
|
+
if (delta === 0) {
|
|
185
|
+
return a.path.length - b.path.length;
|
|
186
|
+
}
|
|
187
|
+
return delta;
|
|
188
|
+
});
|
|
189
|
+
(0, import_utils3.debug)(`fileSystem routes: %o`, routes);
|
|
190
|
+
return routes;
|
|
191
|
+
};
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
getClientRoutes
|
|
195
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getClientRoutes_exports = {};
|
|
20
|
+
__export(getClientRoutes_exports, {
|
|
21
|
+
getClientRoutes: () => import_getRoutes.getClientRoutes,
|
|
22
|
+
getClientRoutesLegacy: () => import_getRoutesLegacy.getClientRoutes
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(getClientRoutes_exports);
|
|
25
|
+
var import_getRoutes = require("./getRoutes");
|
|
26
|
+
var import_getRoutesLegacy = require("./getRoutesLegacy");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
getClientRoutes,
|
|
30
|
+
getClientRoutesLegacy
|
|
31
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
debug: () => debug,
|
|
32
|
+
findLayout: () => findLayout,
|
|
33
|
+
getRouteWeight: () => getRouteWeight,
|
|
34
|
+
shouldSkip: () => shouldSkip
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(utils_exports);
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_constants = require("../../constants");
|
|
40
|
+
const debug = (0, import_utils.createDebugger)("get-client-routes");
|
|
41
|
+
const findLayout = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.FILE_SYSTEM_ROUTES_LAYOUT}${ext}`)));
|
|
42
|
+
const getRouteWeight = (route) => route === "*" ? 999 : route.split(":").length - 1;
|
|
43
|
+
const shouldSkip = (file) => {
|
|
44
|
+
if (import_utils.fs.statSync(file).isDirectory()) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const ext = import_path.default.extname(file);
|
|
48
|
+
if (import_constants.FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !import_utils.JS_EXTENSIONS.includes(ext) || import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === import_path.default.basename(file, ext)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
debug,
|
|
56
|
+
findLayout,
|
|
57
|
+
getRouteWeight,
|
|
58
|
+
shouldSkip
|
|
59
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var code_exports = {};
|
|
30
|
+
__export(code_exports, {
|
|
31
|
+
generateCode: () => generateCode
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(code_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_constants = require("../constants");
|
|
37
|
+
var templates = __toESM(require("./templates"));
|
|
38
|
+
var import_getClientRoutes = require("./getClientRoutes");
|
|
39
|
+
var import_utils2 = require("./utils");
|
|
40
|
+
var import_nestedRoutes = require("./nestedRoutes");
|
|
41
|
+
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
42
|
+
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
43
|
+
const hookRunners = api.useHookRunners();
|
|
44
|
+
const isV5 = (0, import_utils.isRouterV5)(config);
|
|
45
|
+
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
46
|
+
const importsStatemets = /* @__PURE__ */ new Map();
|
|
47
|
+
const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
|
48
|
+
await Promise.all(entrypoints.map(generateEntryCode));
|
|
49
|
+
return {
|
|
50
|
+
importsStatemets
|
|
51
|
+
};
|
|
52
|
+
async function generateEntryCode(entrypoint) {
|
|
53
|
+
const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
|
|
54
|
+
if (isAutoMount) {
|
|
55
|
+
if (fileSystemRoutes) {
|
|
56
|
+
var _config_output;
|
|
57
|
+
let initialRoutes = [];
|
|
58
|
+
let nestedRoutes = null;
|
|
59
|
+
if (entrypoint.entry) {
|
|
60
|
+
initialRoutes = getRoutes({
|
|
61
|
+
entrypoint,
|
|
62
|
+
srcDirectory,
|
|
63
|
+
srcAlias: internalSrcAlias,
|
|
64
|
+
internalDirectory,
|
|
65
|
+
internalDirAlias
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
|
69
|
+
nestedRoutes = await (0, import_nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
70
|
+
name: internalSrcAlias,
|
|
71
|
+
basename: srcDirectory
|
|
72
|
+
}, entrypoint.entryName, entrypoint.isMainEntry, oldVersion);
|
|
73
|
+
if (nestedRoutes) {
|
|
74
|
+
if (!Array.isArray(nestedRoutes)) {
|
|
75
|
+
nestedRoutes = [
|
|
76
|
+
nestedRoutes
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
for (const route of nestedRoutes) {
|
|
80
|
+
initialRoutes.unshift(route);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
85
|
+
entrypoint,
|
|
86
|
+
routes: initialRoutes
|
|
87
|
+
});
|
|
88
|
+
const config2 = api.useResolvedConfigContext();
|
|
89
|
+
const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
90
|
+
const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
|
|
91
|
+
let mode;
|
|
92
|
+
if (ssr) {
|
|
93
|
+
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
94
|
+
}
|
|
95
|
+
if (mode === "stream") {
|
|
96
|
+
const hasPageRoute = routes.some((route) => "type" in route && route.type === "page");
|
|
97
|
+
if (hasPageRoute) {
|
|
98
|
+
import_utils.logger.error("Streaming ssr is not supported when pages dir exists");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const { code } = await hookRunners.beforeGenerateRoutes({
|
|
103
|
+
entrypoint,
|
|
104
|
+
code: await templates.fileSystemRoutes({
|
|
105
|
+
routes,
|
|
106
|
+
ssrMode: useSSG ? "string" : mode,
|
|
107
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
108
|
+
entryName: entrypoint.entryName,
|
|
109
|
+
internalDirectory,
|
|
110
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
111
|
+
})
|
|
112
|
+
});
|
|
113
|
+
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
114
|
+
const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
|
|
115
|
+
const code2 = templates.routesForServer({
|
|
116
|
+
routes
|
|
117
|
+
});
|
|
118
|
+
await import_utils.fs.ensureFile(routesServerFile);
|
|
119
|
+
await import_utils.fs.writeFile(routesServerFile, code2);
|
|
120
|
+
}
|
|
121
|
+
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
122
|
+
if (serverLoaderCombined) {
|
|
123
|
+
const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(internalDirectory, entryName);
|
|
124
|
+
await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
125
|
+
}
|
|
126
|
+
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, "utf8");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
generateCode
|
|
134
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var makeLegalIdentifier_exports = {};
|
|
20
|
+
__export(makeLegalIdentifier_exports, {
|
|
21
|
+
makeLegalIdentifier: () => makeLegalIdentifier
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(makeLegalIdentifier_exports);
|
|
24
|
+
const reservedWords = "break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public";
|
|
25
|
+
const builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
|
|
26
|
+
const forbidList = new Set(`${reservedWords} ${builtins}`.split(" "));
|
|
27
|
+
function makeLegalIdentifier(str) {
|
|
28
|
+
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, "_");
|
|
29
|
+
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
30
|
+
return `_${identifier}`;
|
|
31
|
+
}
|
|
32
|
+
return identifier || "_";
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
makeLegalIdentifier
|
|
37
|
+
});
|