@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,143 @@
|
|
|
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
|
+
getPathWithoutExt: () => getPathWithoutExt,
|
|
32
|
+
getServerCombinedModueFile: () => getServerCombinedModueFile,
|
|
33
|
+
getServerLoadersFile: () => getServerLoadersFile,
|
|
34
|
+
hasAction: () => hasAction,
|
|
35
|
+
hasLoader: () => hasLoader,
|
|
36
|
+
isPageComponentFile: () => isPageComponentFile,
|
|
37
|
+
parseModule: () => parseModule,
|
|
38
|
+
replaceWithAlias: () => replaceWithAlias,
|
|
39
|
+
walkDirectory: () => walkDirectory
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(utils_exports);
|
|
42
|
+
var import_fs = __toESM(require("fs"));
|
|
43
|
+
var import_path = __toESM(require("path"));
|
|
44
|
+
var import_utils = require("@modern-js/utils");
|
|
45
|
+
var import_esbuild = require("esbuild");
|
|
46
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
47
|
+
var import_constants = require("../constants");
|
|
48
|
+
const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previous, filename) => {
|
|
49
|
+
const filePath = import_path.default.join(dir, filename);
|
|
50
|
+
if (import_fs.default.statSync(filePath).isDirectory()) {
|
|
51
|
+
return [
|
|
52
|
+
...previous,
|
|
53
|
+
...walkDirectory(filePath)
|
|
54
|
+
];
|
|
55
|
+
} else {
|
|
56
|
+
return [
|
|
57
|
+
...previous,
|
|
58
|
+
filePath
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
const isPageComponentFile = (filePath) => {
|
|
63
|
+
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if ([
|
|
67
|
+
".js",
|
|
68
|
+
".jsx",
|
|
69
|
+
".ts",
|
|
70
|
+
".tsx"
|
|
71
|
+
].includes(import_path.default.extname(filePath))) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
const replaceWithAlias = (base, filePath, alias) => {
|
|
77
|
+
if (filePath.includes(base)) {
|
|
78
|
+
return (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
|
79
|
+
} else {
|
|
80
|
+
return filePath;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const parseModule = async ({ source, filename }) => {
|
|
84
|
+
let content = source;
|
|
85
|
+
if (import_utils.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
|
|
86
|
+
const result = await (0, import_esbuild.transform)(content, {
|
|
87
|
+
loader: import_path.default.extname(filename).slice(1),
|
|
88
|
+
format: "esm"
|
|
89
|
+
});
|
|
90
|
+
content = result.code;
|
|
91
|
+
}
|
|
92
|
+
return (0, import_es_module_lexer.parse)(content);
|
|
93
|
+
};
|
|
94
|
+
const hasLoader = async (filename, source) => {
|
|
95
|
+
let content = source;
|
|
96
|
+
if (!source) {
|
|
97
|
+
content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
|
|
98
|
+
}
|
|
99
|
+
if (content) {
|
|
100
|
+
const [, moduleExports] = await parseModule({
|
|
101
|
+
source: content.toString(),
|
|
102
|
+
filename
|
|
103
|
+
});
|
|
104
|
+
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
const hasAction = async (filename, source) => {
|
|
109
|
+
let content = source;
|
|
110
|
+
if (!source) {
|
|
111
|
+
content = (await import_utils.fs.readFile(filename, "utf-8")).toString();
|
|
112
|
+
}
|
|
113
|
+
if (content) {
|
|
114
|
+
const [, moduleExports] = await parseModule({
|
|
115
|
+
source: content.toString(),
|
|
116
|
+
filename
|
|
117
|
+
});
|
|
118
|
+
return moduleExports.some((e) => e.n === import_constants.ACTION_EXPORT_NAME);
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
123
|
+
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
124
|
+
};
|
|
125
|
+
const getServerCombinedModueFile = (internalDirectory, entryName) => {
|
|
126
|
+
return import_path.default.join(internalDirectory, entryName, "server-loader-combined.js");
|
|
127
|
+
};
|
|
128
|
+
const getPathWithoutExt = (filename) => {
|
|
129
|
+
const extname = import_path.default.extname(filename);
|
|
130
|
+
return filename.slice(0, -extname.length);
|
|
131
|
+
};
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
getPathWithoutExt,
|
|
135
|
+
getServerCombinedModueFile,
|
|
136
|
+
getServerLoadersFile,
|
|
137
|
+
hasAction,
|
|
138
|
+
hasLoader,
|
|
139
|
+
isPageComponentFile,
|
|
140
|
+
parseModule,
|
|
141
|
+
replaceWithAlias,
|
|
142
|
+
walkDirectory
|
|
143
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
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 constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
ACTION_EXPORT_NAME: () => ACTION_EXPORT_NAME,
|
|
22
|
+
FILE_SYSTEM_ROUTES_COMPONENTS_DIR: () => FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
|
|
23
|
+
FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: () => FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
|
|
24
|
+
FILE_SYSTEM_ROUTES_FILE_NAME: () => FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
25
|
+
FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT: () => FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
|
|
26
|
+
FILE_SYSTEM_ROUTES_IGNORED_REGEX: () => FILE_SYSTEM_ROUTES_IGNORED_REGEX,
|
|
27
|
+
FILE_SYSTEM_ROUTES_INDEX: () => FILE_SYSTEM_ROUTES_INDEX,
|
|
28
|
+
FILE_SYSTEM_ROUTES_LAYOUT: () => FILE_SYSTEM_ROUTES_LAYOUT,
|
|
29
|
+
LOADER_EXPORT_NAME: () => LOADER_EXPORT_NAME,
|
|
30
|
+
NESTED_ROUTE: () => NESTED_ROUTE,
|
|
31
|
+
NESTED_ROUTES_DIR: () => NESTED_ROUTES_DIR,
|
|
32
|
+
PAGES_DIR_NAME: () => PAGES_DIR_NAME,
|
|
33
|
+
TEMP_LOADERS_DIR: () => TEMP_LOADERS_DIR
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(constants_exports);
|
|
36
|
+
const PAGES_DIR_NAME = "pages";
|
|
37
|
+
const NESTED_ROUTES_DIR = "routes";
|
|
38
|
+
const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
39
|
+
const LOADER_EXPORT_NAME = "loader";
|
|
40
|
+
const ACTION_EXPORT_NAME = "action";
|
|
41
|
+
const TEMP_LOADERS_DIR = "__loaders__";
|
|
42
|
+
const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
|
|
43
|
+
const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
|
|
44
|
+
const FILE_SYSTEM_ROUTES_INDEX = "index";
|
|
45
|
+
const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
|
46
|
+
const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
47
|
+
const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
48
|
+
const NESTED_ROUTE = {
|
|
49
|
+
LAYOUT_FILE: "layout",
|
|
50
|
+
LAYOUT_CONFIG_FILE: "layout.config",
|
|
51
|
+
LAYOUT_LOADER_FILE: "layout.loader",
|
|
52
|
+
LAYOUT_DATA_FILE: "layout.data",
|
|
53
|
+
LAYOUT_CLIENT_LOADER: "layout.data.client",
|
|
54
|
+
PAGE_FILE: "page",
|
|
55
|
+
PAGE_CONFIG_FILE: "page.config",
|
|
56
|
+
PAGE_LOADER_FILE: "page.loader",
|
|
57
|
+
PAGE_DATA_FILE: "page.data",
|
|
58
|
+
PAGE_CLIENT_LOADER: "page.data.client",
|
|
59
|
+
SPLATE_FILE: "$",
|
|
60
|
+
SPLATE_CONFIG_FILE: "$.config",
|
|
61
|
+
SPLATE_LOADER_FILE: "$.loader",
|
|
62
|
+
SPLATE_DATA_FILE: "$.data",
|
|
63
|
+
SPLATE_CLIENT_DATA: "$.data.client",
|
|
64
|
+
LOADING_FILE: "loading",
|
|
65
|
+
ERROR_FILE: "error",
|
|
66
|
+
LOADER_FILE: "loader"
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
ACTION_EXPORT_NAME,
|
|
71
|
+
FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
|
|
72
|
+
FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
|
|
73
|
+
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
74
|
+
FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
|
|
75
|
+
FILE_SYSTEM_ROUTES_IGNORED_REGEX,
|
|
76
|
+
FILE_SYSTEM_ROUTES_INDEX,
|
|
77
|
+
FILE_SYSTEM_ROUTES_LAYOUT,
|
|
78
|
+
LOADER_EXPORT_NAME,
|
|
79
|
+
NESTED_ROUTE,
|
|
80
|
+
NESTED_ROUTES_DIR,
|
|
81
|
+
PAGES_DIR_NAME,
|
|
82
|
+
TEMP_LOADERS_DIR
|
|
83
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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 entry_exports = {};
|
|
30
|
+
__export(entry_exports, {
|
|
31
|
+
hasNestedRoutes: () => hasNestedRoutes,
|
|
32
|
+
hasPages: () => hasPages,
|
|
33
|
+
isRouteEntry: () => isRouteEntry,
|
|
34
|
+
modifyEntrypoints: () => modifyEntrypoints
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(entry_exports);
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_constants = require("./constants");
|
|
40
|
+
const hasPages = (dir) => import_utils.fs.existsSync(import_path.default.join(dir, import_constants.PAGES_DIR_NAME));
|
|
41
|
+
const hasNestedRoutes = (dir) => import_utils.fs.existsSync(import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR));
|
|
42
|
+
const isRouteEntry = (dir) => {
|
|
43
|
+
if (hasNestedRoutes(dir)) {
|
|
44
|
+
return import_path.default.join(dir, import_constants.NESTED_ROUTES_DIR);
|
|
45
|
+
}
|
|
46
|
+
if (hasPages(dir)) {
|
|
47
|
+
return import_path.default.join(dir, import_constants.PAGES_DIR_NAME);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
const modifyEntrypoints = (entrypoints, config = {}) => {
|
|
52
|
+
return entrypoints.map((entrypoint) => {
|
|
53
|
+
if (!entrypoint.isAutoMount) {
|
|
54
|
+
return entrypoint;
|
|
55
|
+
}
|
|
56
|
+
const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
|
|
57
|
+
const isHasPages = hasPages(entrypoint.absoluteEntryDir);
|
|
58
|
+
if (!isHasNestedRoutes && !isHasPages) {
|
|
59
|
+
return entrypoint;
|
|
60
|
+
}
|
|
61
|
+
if (entrypoint.fileSystemRoutes && !(0, import_utils.isRouterV5)(config)) {
|
|
62
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
63
|
+
} else if (!entrypoint.fileSystemRoutes) {
|
|
64
|
+
entrypoint.fileSystemRoutes = {
|
|
65
|
+
globalApp: (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(entrypoint.absoluteEntryDir, `./${import_constants.PAGES_DIR_NAME}/${import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
|
66
|
+
};
|
|
67
|
+
if (isHasPages) {
|
|
68
|
+
entrypoint.entry = import_path.default.join(entrypoint.absoluteEntryDir, import_constants.PAGES_DIR_NAME);
|
|
69
|
+
entrypoint.pageRoutesEntry = entrypoint.entry;
|
|
70
|
+
}
|
|
71
|
+
if (isHasNestedRoutes) {
|
|
72
|
+
entrypoint.entry = import_path.default.join(entrypoint.absoluteEntryDir, import_constants.NESTED_ROUTES_DIR);
|
|
73
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
77
|
+
}
|
|
78
|
+
return entrypoint;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
hasNestedRoutes,
|
|
84
|
+
hasPages,
|
|
85
|
+
isRouteEntry,
|
|
86
|
+
modifyEntrypoints
|
|
87
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
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 handler_exports = {};
|
|
30
|
+
__export(handler_exports, {
|
|
31
|
+
handleFileChange: () => handleFileChange,
|
|
32
|
+
handleModifyEntrypoints: () => handleModifyEntrypoints
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(handler_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_lodash = require("@modern-js/utils/lodash");
|
|
37
|
+
var import_entry = require("./entry");
|
|
38
|
+
var import_utils = require("./code/utils");
|
|
39
|
+
let originEntrypoints = [];
|
|
40
|
+
async function handleModifyEntrypoints(api, entrypoints) {
|
|
41
|
+
const config = api.useResolvedConfigContext();
|
|
42
|
+
const newEntryPoints = (0, import_entry.modifyEntrypoints)(entrypoints, config);
|
|
43
|
+
const appContext = api.useAppContext();
|
|
44
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
45
|
+
appContext.entrypoints = newEntryPoints;
|
|
46
|
+
originEntrypoints = (0, import_lodash.cloneDeep)(newEntryPoints);
|
|
47
|
+
const { generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
48
|
+
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
49
|
+
return newEntryPoints;
|
|
50
|
+
}
|
|
51
|
+
async function handleFileChange(api, e) {
|
|
52
|
+
const appContext = api.useAppContext();
|
|
53
|
+
const { appDirectory, entrypoints } = appContext;
|
|
54
|
+
const { filename, eventType } = e;
|
|
55
|
+
const nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
56
|
+
const pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !import_path.default.extname(entry)).concat(nestedRouteEntries);
|
|
57
|
+
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
58
|
+
const absoluteFilePath = import_path.default.resolve(appDirectory, filename);
|
|
59
|
+
const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils.isPageComponentFile)(absoluteFilePath);
|
|
60
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
61
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
62
|
+
const { generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
63
|
+
const entrypoints2 = (0, import_lodash.cloneDeep)(originEntrypoints);
|
|
64
|
+
await generateCode(appContext, resolvedConfig, entrypoints2, api);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
handleFileChange,
|
|
70
|
+
handleModifyEntrypoints
|
|
71
|
+
});
|
|
@@ -19,10 +19,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var cli_exports = {};
|
|
20
20
|
__export(cli_exports, {
|
|
21
21
|
default: () => cli_default,
|
|
22
|
+
handleFileChange: () => import_handler2.handleFileChange,
|
|
23
|
+
handleModifyEntrypoints: () => import_handler2.handleModifyEntrypoints,
|
|
24
|
+
isRouteEntry: () => import_entry2.isRouteEntry,
|
|
22
25
|
routerPlugin: () => routerPlugin
|
|
23
26
|
});
|
|
24
27
|
module.exports = __toCommonJS(cli_exports);
|
|
25
28
|
var import_utils = require("@modern-js/utils");
|
|
29
|
+
var import_entry = require("./entry");
|
|
30
|
+
var import_handler = require("./handler");
|
|
31
|
+
var import_entry2 = require("./entry");
|
|
32
|
+
var import_handler2 = require("./handler");
|
|
26
33
|
const PLUGIN_IDENTIFIER = "router";
|
|
27
34
|
const ROUTES_IDENTIFIER = "routes";
|
|
28
35
|
const routerPlugin = () => ({
|
|
@@ -34,6 +41,12 @@ const routerPlugin = () => ({
|
|
|
34
41
|
const runtimeConfigMap = /* @__PURE__ */ new Map();
|
|
35
42
|
let pluginsExportsUtils;
|
|
36
43
|
return {
|
|
44
|
+
checkEntryPoint({ path, entry }) {
|
|
45
|
+
return {
|
|
46
|
+
path,
|
|
47
|
+
entry: entry || (0, import_entry.isRouteEntry)(path)
|
|
48
|
+
};
|
|
49
|
+
},
|
|
37
50
|
config() {
|
|
38
51
|
const appContext = api.useAppContext();
|
|
39
52
|
pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
|
|
@@ -53,6 +66,12 @@ const routerPlugin = () => ({
|
|
|
53
66
|
}
|
|
54
67
|
};
|
|
55
68
|
},
|
|
69
|
+
async modifyEntrypoints({ entrypoints }) {
|
|
70
|
+
const newEntryPoints = await (0, import_handler.handleModifyEntrypoints)(api, entrypoints);
|
|
71
|
+
return {
|
|
72
|
+
entrypoints: newEntryPoints
|
|
73
|
+
};
|
|
74
|
+
},
|
|
56
75
|
modifyEntryImports({ entrypoint, imports }) {
|
|
57
76
|
const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
|
|
58
77
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -104,6 +123,9 @@ const routerPlugin = () => ({
|
|
|
104
123
|
if (!(0, import_utils.isRouterV5)(userConfig)) {
|
|
105
124
|
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/router'`);
|
|
106
125
|
}
|
|
126
|
+
},
|
|
127
|
+
async fileChange(e) {
|
|
128
|
+
await (0, import_handler.handleFileChange)(api, e);
|
|
107
129
|
}
|
|
108
130
|
};
|
|
109
131
|
}
|
|
@@ -111,5 +133,8 @@ const routerPlugin = () => ({
|
|
|
111
133
|
var cli_default = routerPlugin;
|
|
112
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
113
135
|
0 && (module.exports = {
|
|
136
|
+
handleFileChange,
|
|
137
|
+
handleModifyEntrypoints,
|
|
138
|
+
isRouteEntry,
|
|
114
139
|
routerPlugin
|
|
115
140
|
});
|
|
@@ -91,10 +91,11 @@ const routerPlugin = ({
|
|
|
91
91
|
context
|
|
92
92
|
});
|
|
93
93
|
},
|
|
94
|
-
hoc: ({ App }, next) => {
|
|
94
|
+
hoc: ({ App, config }, next) => {
|
|
95
95
|
if (!finalRouteConfig && !createRoutes) {
|
|
96
96
|
return next({
|
|
97
|
-
App
|
|
97
|
+
App,
|
|
98
|
+
config
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
101
|
const getRouteApp = () => {
|
|
@@ -168,11 +169,13 @@ const routerPlugin = ({
|
|
|
168
169
|
}
|
|
169
170
|
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
|
170
171
|
return next({
|
|
171
|
-
App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp)
|
|
172
|
+
App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp),
|
|
173
|
+
config
|
|
172
174
|
});
|
|
173
175
|
}
|
|
174
176
|
return next({
|
|
175
|
-
App: RouteApp
|
|
177
|
+
App: RouteApp,
|
|
178
|
+
config
|
|
176
179
|
});
|
|
177
180
|
},
|
|
178
181
|
pickContext: ({ context, pickedContext }, next) => {
|
|
@@ -88,7 +88,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
88
88
|
context
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
const { request, mode: ssrMode, nonce } = context.ssrContext;
|
|
91
|
+
const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
|
|
92
92
|
const baseUrl = originalBaseUrl || request.baseUrl;
|
|
93
93
|
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
94
94
|
const { reporter, serverTiming } = context.ssrContext;
|
|
@@ -118,6 +118,10 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
118
118
|
if (routerContext instanceof Response) {
|
|
119
119
|
return routerContext;
|
|
120
120
|
}
|
|
121
|
+
if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && loaderFailureMode === "clientRender") {
|
|
122
|
+
routerContext.statusCode = 200;
|
|
123
|
+
throw routerContext.errors[0];
|
|
124
|
+
}
|
|
121
125
|
const router = (0, import_router.createStaticRouter)(routes, routerContext);
|
|
122
126
|
context.remixRouter = router;
|
|
123
127
|
context.routerContext = routerContext;
|
|
@@ -127,10 +131,11 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
127
131
|
context
|
|
128
132
|
});
|
|
129
133
|
},
|
|
130
|
-
hoc: ({ App }, next) => {
|
|
134
|
+
hoc: ({ App, config }, next) => {
|
|
131
135
|
if (!routesConfig) {
|
|
132
136
|
return next({
|
|
133
|
-
App
|
|
137
|
+
App,
|
|
138
|
+
config
|
|
134
139
|
});
|
|
135
140
|
}
|
|
136
141
|
const getRouteApp = () => {
|
|
@@ -157,11 +162,13 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
157
162
|
const RouteApp = getRouteApp();
|
|
158
163
|
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
|
159
164
|
return next({
|
|
160
|
-
App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp)
|
|
165
|
+
App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp),
|
|
166
|
+
config
|
|
161
167
|
});
|
|
162
168
|
}
|
|
163
169
|
return next({
|
|
164
|
-
App: RouteApp
|
|
170
|
+
App: RouteApp,
|
|
171
|
+
config
|
|
165
172
|
});
|
|
166
173
|
},
|
|
167
174
|
pickContext: ({ context, pickedContext }, next) => {
|
|
@@ -54,6 +54,7 @@ const ssr = (config = {}) => ({
|
|
|
54
54
|
context.ssrContext.request = (0, import_utils.formatServer)(request);
|
|
55
55
|
context.ssrContext.mode = config.mode;
|
|
56
56
|
context.ssrContext.tracker = (0, import_tracker.createSSRTracker)(context.ssrContext);
|
|
57
|
+
context.ssrContext.loaderFailureMode = config.loaderFailureMode;
|
|
57
58
|
if (!context.ssrContext.htmlModifiers) {
|
|
58
59
|
context.ssrContext.htmlModifiers = [];
|
|
59
60
|
}
|
|
@@ -70,7 +70,7 @@ const state = (config) => ({
|
|
|
70
70
|
setup: () => {
|
|
71
71
|
const storeConfig = getStoreConfig(config);
|
|
72
72
|
return {
|
|
73
|
-
hoc({ App }, next) {
|
|
73
|
+
hoc({ App, config: config2 }, next) {
|
|
74
74
|
const getStateApp = (props) => {
|
|
75
75
|
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
76
76
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Provider, {
|
|
@@ -82,7 +82,8 @@ const state = (config) => ({
|
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
return next({
|
|
85
|
-
App: (0, import_hoist_non_react_statics.default)(getStateApp, App)
|
|
85
|
+
App: (0, import_hoist_non_react_statics.default)(getStateApp, App),
|
|
86
|
+
config: config2
|
|
86
87
|
});
|
|
87
88
|
},
|
|
88
89
|
init({ context }, next) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { JS_EXTENSIONS, findExists } from "@modern-js/utils";
|
|
3
|
+
import { APP_FILE_NAME } from "./constants";
|
|
4
|
+
var hasApp = function(dir) {
|
|
5
|
+
return findExists(JS_EXTENSIONS.map(function(ext) {
|
|
6
|
+
return path.resolve(dir, "".concat(APP_FILE_NAME).concat(ext));
|
|
7
|
+
}));
|
|
8
|
+
};
|
|
9
|
+
var isRuntimeEntry = function(dir) {
|
|
10
|
+
return hasApp(dir);
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
isRuntimeEntry
|
|
14
|
+
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { statePlugin } from "../state/cli";
|
|
|
5
5
|
import { ssrPlugin } from "../ssr/cli";
|
|
6
6
|
import { routerPlugin } from "../router/cli";
|
|
7
7
|
import { documentPlugin } from "../document/cli";
|
|
8
|
+
import { isRuntimeEntry } from "./entry";
|
|
9
|
+
import { isRuntimeEntry as isRuntimeEntry2 } from "./entry";
|
|
8
10
|
var runtimePlugin = function() {
|
|
9
11
|
return {
|
|
10
12
|
name: "@modern-js/runtime",
|
|
@@ -24,6 +26,13 @@ var runtimePlugin = function() {
|
|
|
24
26
|
],
|
|
25
27
|
setup: function(api) {
|
|
26
28
|
return {
|
|
29
|
+
checkEntryPoint: function checkEntryPoint(param) {
|
|
30
|
+
var path = param.path, entry = param.entry;
|
|
31
|
+
return {
|
|
32
|
+
path,
|
|
33
|
+
entry: entry || isRuntimeEntry(path)
|
|
34
|
+
};
|
|
35
|
+
},
|
|
27
36
|
config: function config() {
|
|
28
37
|
var appDir = api.useAppContext().appDirectory;
|
|
29
38
|
process.env.IS_REACT18 = isReact18(appDir).toString();
|
|
@@ -74,5 +83,6 @@ var runtimePlugin = function() {
|
|
|
74
83
|
var cli_default = runtimePlugin;
|
|
75
84
|
export {
|
|
76
85
|
cli_default as default,
|
|
86
|
+
isRuntimeEntry2 as isRuntimeEntry,
|
|
77
87
|
runtimePlugin
|
|
78
88
|
};
|