@modern-js/server-core 2.58.1 → 2.58.2-alpha.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/adapters/node/helper/loadCache.js +2 -2
- package/dist/cjs/adapters/node/helper/loadConfig.js +10 -10
- package/dist/cjs/adapters/node/helper/loadPlugin.js +4 -4
- package/dist/cjs/adapters/node/node.js +2 -2
- package/dist/cjs/adapters/node/plugins/resource.js +9 -14
- package/dist/cjs/plugins/customServer/index.js +1 -11
- package/dist/cjs/plugins/render/render.js +1 -1
- package/dist/cjs/utils/warmup.js +1 -11
- package/dist/esm/adapters/node/helper/loadCache.js +35 -10
- package/dist/esm/adapters/node/helper/loadConfig.js +118 -22
- package/dist/esm/adapters/node/helper/loadPlugin.js +51 -9
- package/dist/esm/adapters/node/plugins/resource.js +30 -15
- package/dist/esm-node/adapters/node/helper/loadCache.js +2 -2
- package/dist/esm-node/adapters/node/helper/loadConfig.js +11 -11
- package/dist/esm-node/adapters/node/helper/loadPlugin.js +5 -5
- package/dist/esm-node/adapters/node/plugins/resource.js +9 -14
- package/dist/types/adapters/node/helper/loadCache.d.ts +1 -1
- package/dist/types/adapters/node/helper/loadConfig.d.ts +1 -1
- package/dist/types/adapters/node/helper/loadPlugin.d.ts +1 -1
- package/package.json +3 -3
|
@@ -34,9 +34,9 @@ module.exports = __toCommonJS(loadCache_exports);
|
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
36
|
const CACHE_FILENAME = "cache";
|
|
37
|
-
function loadCacheConfig(pwd) {
|
|
37
|
+
async function loadCacheConfig(pwd) {
|
|
38
38
|
const serverCacheFilepath = import_path.default.resolve(pwd, import_utils.SERVER_DIR, CACHE_FILENAME);
|
|
39
|
-
const mod = (0, import_utils.requireExistModule)(serverCacheFilepath, {
|
|
39
|
+
const mod = await (0, import_utils.requireExistModule)(serverCacheFilepath, {
|
|
40
40
|
interop: false
|
|
41
41
|
});
|
|
42
42
|
if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
|
|
@@ -35,30 +35,30 @@ module.exports = __toCommonJS(loadConfig_exports);
|
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_flatted = require("flatted");
|
|
38
|
-
const requireConfig = (serverConfigPath) => {
|
|
38
|
+
const requireConfig = async (serverConfigPath) => {
|
|
39
39
|
if (import_utils.fs.pathExistsSync(serverConfigPath)) {
|
|
40
|
-
return (0, import_utils.
|
|
40
|
+
return (0, import_utils.compatibleRequire)(serverConfigPath);
|
|
41
41
|
}
|
|
42
42
|
return void 0;
|
|
43
43
|
};
|
|
44
|
-
function loadServerConfigNew(serverConfigPath) {
|
|
45
|
-
const mod = (0, import_utils.requireExistModule)(serverConfigPath);
|
|
44
|
+
async function loadServerConfigNew(serverConfigPath) {
|
|
45
|
+
const mod = await (0, import_utils.requireExistModule)(serverConfigPath);
|
|
46
46
|
if (mod) {
|
|
47
47
|
return mod;
|
|
48
48
|
}
|
|
49
49
|
return void 0;
|
|
50
50
|
}
|
|
51
|
-
function loadServerConfigOld(pwd, configFile) {
|
|
52
|
-
const serverConfigPath = import_path.default.join(pwd, `${configFile}.
|
|
53
|
-
const serverConfig = requireConfig(serverConfigPath);
|
|
51
|
+
async function loadServerConfigOld(pwd, configFile) {
|
|
52
|
+
const serverConfigPath = import_path.default.join(pwd, `${configFile}.cjs`);
|
|
53
|
+
const serverConfig = await requireConfig(serverConfigPath);
|
|
54
54
|
return serverConfig;
|
|
55
55
|
}
|
|
56
|
-
function loadServerRuntimeConfig(pwd, oldServerFile = import_utils.DEFAULT_SERVER_CONFIG, newServerConfigPath) {
|
|
57
|
-
const newServerConfig = newServerConfigPath && loadServerConfigNew(newServerConfigPath);
|
|
56
|
+
async function loadServerRuntimeConfig(pwd, oldServerFile = import_utils.DEFAULT_SERVER_CONFIG, newServerConfigPath) {
|
|
57
|
+
const newServerConfig = newServerConfigPath && await loadServerConfigNew(newServerConfigPath);
|
|
58
58
|
if (newServerConfig) {
|
|
59
59
|
return newServerConfig;
|
|
60
60
|
}
|
|
61
|
-
const oldServerConfig = loadServerConfigOld(pwd, oldServerFile);
|
|
61
|
+
const oldServerConfig = await loadServerConfigOld(pwd, oldServerFile);
|
|
62
62
|
return oldServerConfig;
|
|
63
63
|
}
|
|
64
64
|
function loadServerCliConfig(pwd, defaultConfig = {}) {
|
|
@@ -22,15 +22,15 @@ __export(loadPlugin_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(loadPlugin_exports);
|
|
24
24
|
var import_utils = require("@modern-js/utils");
|
|
25
|
-
function resolveServerPlugin(plugin, appDirectory) {
|
|
25
|
+
async function resolveServerPlugin(plugin, appDirectory) {
|
|
26
26
|
const { name, options } = plugin;
|
|
27
27
|
const pluginPath = (0, import_utils.tryResolve)(name, appDirectory);
|
|
28
|
-
const module2 = (0, import_utils.
|
|
28
|
+
const module2 = await (0, import_utils.compatibleRequire)(pluginPath);
|
|
29
29
|
const pluginInstance = module2(options);
|
|
30
30
|
return pluginInstance;
|
|
31
31
|
}
|
|
32
|
-
function loadServerPlugins(serverPlugins, appDirectory) {
|
|
33
|
-
const instances = serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory));
|
|
32
|
+
async function loadServerPlugins(serverPlugins, appDirectory) {
|
|
33
|
+
const instances = await Promise.all(serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory)));
|
|
34
34
|
return instances;
|
|
35
35
|
}
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -128,10 +128,10 @@ const createNodeServer = async (requestHandler, httpsOptions) => {
|
|
|
128
128
|
const requestListener = getRequestListener(requestHandler);
|
|
129
129
|
let nodeServer;
|
|
130
130
|
if (httpsOptions) {
|
|
131
|
-
const { createServer } = await
|
|
131
|
+
const { createServer } = await import("node:https");
|
|
132
132
|
nodeServer = createServer(httpsOptions, requestListener);
|
|
133
133
|
} else {
|
|
134
|
-
const { createServer } = await
|
|
134
|
+
const { createServer } = await import("node:http");
|
|
135
135
|
nodeServer = createServer(requestListener);
|
|
136
136
|
}
|
|
137
137
|
nodeServer.getRequestListener = () => requestListener;
|
|
@@ -64,22 +64,17 @@ function injectTemplates(pwd, routes) {
|
|
|
64
64
|
await next();
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
const dynamicImport = (filePath) => {
|
|
68
|
-
try {
|
|
69
|
-
const module2 = require(filePath);
|
|
70
|
-
return Promise.resolve(module2);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return Promise.reject(e);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
67
|
const loadBundle = async (filepath, logger) => {
|
|
76
68
|
if (!await import_utils.fs.pathExists(filepath)) {
|
|
77
69
|
return void 0;
|
|
78
70
|
}
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
try {
|
|
72
|
+
const module2 = await (0, import_utils.compatibleRequire)(filepath, false);
|
|
73
|
+
return module2;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
|
|
81
76
|
return void 0;
|
|
82
|
-
}
|
|
77
|
+
}
|
|
83
78
|
};
|
|
84
79
|
async function getServerManifest(pwd, routes, logger) {
|
|
85
80
|
const loaderBundles = {};
|
|
@@ -94,11 +89,11 @@ async function getServerManifest(pwd, routes, logger) {
|
|
|
94
89
|
loaderBundle && (loaderBundles[entryName] = loaderBundle);
|
|
95
90
|
}));
|
|
96
91
|
const loadableUri = import_path.default.join(pwd, import_utils.LOADABLE_STATS_FILE);
|
|
97
|
-
const loadableStats = await
|
|
92
|
+
const loadableStats = await (0, import_utils.compatibleRequire)(loadableUri).catch((_) => ({}));
|
|
98
93
|
const routesManifestUri = import_path.default.join(pwd, import_utils.ROUTE_MANIFEST_FILE);
|
|
99
|
-
const routeManifest = await
|
|
94
|
+
const routeManifest = await (0, import_utils.compatibleRequire)(routesManifestUri).catch((_) => ({}));
|
|
100
95
|
const nestedRoutesJsonPath = import_path.default.join(pwd, import_utils.NESTED_ROUTE_SPEC_FILE);
|
|
101
|
-
const nestedRoutesJson = await
|
|
96
|
+
const nestedRoutesJson = await import(nestedRoutesJsonPath).catch((_) => ({}));
|
|
102
97
|
return {
|
|
103
98
|
loaderBundles,
|
|
104
99
|
renderBundles,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var customServer_exports = {};
|
|
30
20
|
__export(customServer_exports, {
|
|
@@ -176,7 +166,7 @@ async function createMiddlewareContextFromHono(c) {
|
|
|
176
166
|
"HEAD"
|
|
177
167
|
].includes(method) && !rawRequest.body && c.env.node.req) {
|
|
178
168
|
const streamPath = "../../adapters/node/polyfills/stream";
|
|
179
|
-
const { createReadableStreamFromReadable } = await
|
|
169
|
+
const { createReadableStreamFromReadable } = await import(streamPath);
|
|
180
170
|
const init = {
|
|
181
171
|
body: createReadableStreamFromReadable(c.env.node.req),
|
|
182
172
|
headers: rawRequest.headers,
|
|
@@ -164,7 +164,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
164
164
|
const { nestedRoutesJson } = serverManifest;
|
|
165
165
|
const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
|
|
166
166
|
if (routes) {
|
|
167
|
-
const { matchRoutes } = await
|
|
167
|
+
const { matchRoutes } = await import("@modern-js/runtime-utils/remix-router");
|
|
168
168
|
const url = new URL(request.url);
|
|
169
169
|
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
170
170
|
if (!matchedRoutes) {
|
package/dist/cjs/utils/warmup.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var warmup_exports = {};
|
|
30
20
|
__export(warmup_exports, {
|
|
@@ -33,7 +23,7 @@ __export(warmup_exports, {
|
|
|
33
23
|
module.exports = __toCommonJS(warmup_exports);
|
|
34
24
|
function warmup(bundles) {
|
|
35
25
|
bundles.forEach((bundle) => {
|
|
36
|
-
bundle &&
|
|
26
|
+
bundle && import(bundle).catch((_) => {
|
|
37
27
|
});
|
|
38
28
|
});
|
|
39
29
|
}
|
|
@@ -1,18 +1,43 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
1
3
|
import path from "path";
|
|
2
4
|
import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
|
|
3
5
|
var CACHE_FILENAME = "cache";
|
|
4
6
|
function loadCacheConfig(pwd) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
return _loadCacheConfig.apply(this, arguments);
|
|
8
|
+
}
|
|
9
|
+
function _loadCacheConfig() {
|
|
10
|
+
_loadCacheConfig = _async_to_generator(function(pwd) {
|
|
11
|
+
var serverCacheFilepath, mod;
|
|
12
|
+
return _ts_generator(this, function(_state) {
|
|
13
|
+
switch (_state.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
|
|
16
|
+
return [
|
|
17
|
+
4,
|
|
18
|
+
requireExistModule(serverCacheFilepath, {
|
|
19
|
+
interop: false
|
|
20
|
+
})
|
|
21
|
+
];
|
|
22
|
+
case 1:
|
|
23
|
+
mod = _state.sent();
|
|
24
|
+
if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
|
|
25
|
+
return [
|
|
26
|
+
2,
|
|
27
|
+
{
|
|
28
|
+
strategy: mod.cacheOption,
|
|
29
|
+
container: mod.customContainer
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
2,
|
|
35
|
+
void 0
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
8
39
|
});
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
strategy: mod.cacheOption,
|
|
12
|
-
container: mod.customContainer
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return void 0;
|
|
40
|
+
return _loadCacheConfig.apply(this, arguments);
|
|
16
41
|
}
|
|
17
42
|
export {
|
|
18
43
|
loadCacheConfig
|
|
@@ -1,32 +1,128 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
1
3
|
import path from "path";
|
|
2
|
-
import {
|
|
4
|
+
import { fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire } from "@modern-js/utils";
|
|
3
5
|
import { parse } from "flatted";
|
|
4
|
-
var requireConfig = function(
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var requireConfig = function() {
|
|
7
|
+
var _ref = _async_to_generator(function(serverConfigPath) {
|
|
8
|
+
return _ts_generator(this, function(_state) {
|
|
9
|
+
if (fs.pathExistsSync(serverConfigPath)) {
|
|
10
|
+
return [
|
|
11
|
+
2,
|
|
12
|
+
compatibleRequire(serverConfigPath)
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
return [
|
|
16
|
+
2,
|
|
17
|
+
void 0
|
|
18
|
+
];
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return function requireConfig2(serverConfigPath) {
|
|
22
|
+
return _ref.apply(this, arguments);
|
|
23
|
+
};
|
|
24
|
+
}();
|
|
10
25
|
function loadServerConfigNew(serverConfigPath) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
return _loadServerConfigNew.apply(this, arguments);
|
|
27
|
+
}
|
|
28
|
+
function _loadServerConfigNew() {
|
|
29
|
+
_loadServerConfigNew = _async_to_generator(function(serverConfigPath) {
|
|
30
|
+
var mod;
|
|
31
|
+
return _ts_generator(this, function(_state) {
|
|
32
|
+
switch (_state.label) {
|
|
33
|
+
case 0:
|
|
34
|
+
return [
|
|
35
|
+
4,
|
|
36
|
+
requireExistModule(serverConfigPath)
|
|
37
|
+
];
|
|
38
|
+
case 1:
|
|
39
|
+
mod = _state.sent();
|
|
40
|
+
if (mod) {
|
|
41
|
+
return [
|
|
42
|
+
2,
|
|
43
|
+
mod
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
return [
|
|
47
|
+
2,
|
|
48
|
+
void 0
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return _loadServerConfigNew.apply(this, arguments);
|
|
16
54
|
}
|
|
17
55
|
function loadServerConfigOld(pwd, configFile) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
56
|
+
return _loadServerConfigOld.apply(this, arguments);
|
|
57
|
+
}
|
|
58
|
+
function _loadServerConfigOld() {
|
|
59
|
+
_loadServerConfigOld = _async_to_generator(function(pwd, configFile) {
|
|
60
|
+
var serverConfigPath, serverConfig;
|
|
61
|
+
return _ts_generator(this, function(_state) {
|
|
62
|
+
switch (_state.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
serverConfigPath = path.join(pwd, "".concat(configFile, ".cjs"));
|
|
65
|
+
return [
|
|
66
|
+
4,
|
|
67
|
+
requireConfig(serverConfigPath)
|
|
68
|
+
];
|
|
69
|
+
case 1:
|
|
70
|
+
serverConfig = _state.sent();
|
|
71
|
+
return [
|
|
72
|
+
2,
|
|
73
|
+
serverConfig
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return _loadServerConfigOld.apply(this, arguments);
|
|
21
79
|
}
|
|
22
80
|
function loadServerRuntimeConfig(pwd) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
81
|
+
return _loadServerRuntimeConfig.apply(this, arguments);
|
|
82
|
+
}
|
|
83
|
+
function _loadServerRuntimeConfig() {
|
|
84
|
+
_loadServerRuntimeConfig = _async_to_generator(function(pwd) {
|
|
85
|
+
var oldServerFile, newServerConfigPath, newServerConfig, _tmp, oldServerConfig;
|
|
86
|
+
var _arguments = arguments;
|
|
87
|
+
return _ts_generator(this, function(_state) {
|
|
88
|
+
switch (_state.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
oldServerFile = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : DEFAULT_SERVER_CONFIG, newServerConfigPath = _arguments.length > 2 ? _arguments[2] : void 0;
|
|
91
|
+
_tmp = newServerConfigPath;
|
|
92
|
+
if (!_tmp)
|
|
93
|
+
return [
|
|
94
|
+
3,
|
|
95
|
+
2
|
|
96
|
+
];
|
|
97
|
+
return [
|
|
98
|
+
4,
|
|
99
|
+
loadServerConfigNew(newServerConfigPath)
|
|
100
|
+
];
|
|
101
|
+
case 1:
|
|
102
|
+
_tmp = _state.sent();
|
|
103
|
+
_state.label = 2;
|
|
104
|
+
case 2:
|
|
105
|
+
newServerConfig = _tmp;
|
|
106
|
+
if (newServerConfig) {
|
|
107
|
+
return [
|
|
108
|
+
2,
|
|
109
|
+
newServerConfig
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
return [
|
|
113
|
+
4,
|
|
114
|
+
loadServerConfigOld(pwd, oldServerFile)
|
|
115
|
+
];
|
|
116
|
+
case 3:
|
|
117
|
+
oldServerConfig = _state.sent();
|
|
118
|
+
return [
|
|
119
|
+
2,
|
|
120
|
+
oldServerConfig
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return _loadServerRuntimeConfig.apply(this, arguments);
|
|
30
126
|
}
|
|
31
127
|
function loadServerCliConfig(pwd) {
|
|
32
128
|
var defaultConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
@@ -1,16 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { compatibleRequire, tryResolve } from "@modern-js/utils";
|
|
2
4
|
function resolveServerPlugin(plugin, appDirectory) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
return _resolveServerPlugin.apply(this, arguments);
|
|
6
|
+
}
|
|
7
|
+
function _resolveServerPlugin() {
|
|
8
|
+
_resolveServerPlugin = _async_to_generator(function(plugin, appDirectory) {
|
|
9
|
+
var name, options, pluginPath, module, pluginInstance;
|
|
10
|
+
return _ts_generator(this, function(_state) {
|
|
11
|
+
switch (_state.label) {
|
|
12
|
+
case 0:
|
|
13
|
+
name = plugin.name, options = plugin.options;
|
|
14
|
+
pluginPath = tryResolve(name, appDirectory);
|
|
15
|
+
return [
|
|
16
|
+
4,
|
|
17
|
+
compatibleRequire(pluginPath)
|
|
18
|
+
];
|
|
19
|
+
case 1:
|
|
20
|
+
module = _state.sent();
|
|
21
|
+
pluginInstance = module(options);
|
|
22
|
+
return [
|
|
23
|
+
2,
|
|
24
|
+
pluginInstance
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return _resolveServerPlugin.apply(this, arguments);
|
|
8
30
|
}
|
|
9
31
|
function loadServerPlugins(serverPlugins, appDirectory) {
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
return _loadServerPlugins.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
function _loadServerPlugins() {
|
|
35
|
+
_loadServerPlugins = _async_to_generator(function(serverPlugins, appDirectory) {
|
|
36
|
+
var instances;
|
|
37
|
+
return _ts_generator(this, function(_state) {
|
|
38
|
+
switch (_state.label) {
|
|
39
|
+
case 0:
|
|
40
|
+
return [
|
|
41
|
+
4,
|
|
42
|
+
Promise.all(serverPlugins.map(function(plugin) {
|
|
43
|
+
return resolveServerPlugin(plugin, appDirectory);
|
|
44
|
+
}))
|
|
45
|
+
];
|
|
46
|
+
case 1:
|
|
47
|
+
instances = _state.sent();
|
|
48
|
+
return [
|
|
49
|
+
2,
|
|
50
|
+
instances
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
12
54
|
});
|
|
13
|
-
return
|
|
55
|
+
return _loadServerPlugins.apply(this, arguments);
|
|
14
56
|
}
|
|
15
57
|
export {
|
|
16
58
|
loadServerPlugins
|
|
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
6
|
-
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
|
|
6
|
+
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs, compatibleRequire } from "@modern-js/utils";
|
|
7
7
|
function getHtmlTemplates(pwd, routes) {
|
|
8
8
|
return _getHtmlTemplates.apply(this, arguments);
|
|
9
9
|
}
|
|
@@ -110,16 +110,9 @@ function injectTemplates(pwd, routes) {
|
|
|
110
110
|
};
|
|
111
111
|
}();
|
|
112
112
|
}
|
|
113
|
-
var dynamicImport = function(filePath) {
|
|
114
|
-
try {
|
|
115
|
-
var module = require(filePath);
|
|
116
|
-
return Promise.resolve(module);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
return Promise.reject(e);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
113
|
var loadBundle = function() {
|
|
122
114
|
var _ref = _async_to_generator(function(filepath, logger) {
|
|
115
|
+
var module, e;
|
|
123
116
|
return _ts_generator(this, function(_state) {
|
|
124
117
|
switch (_state.label) {
|
|
125
118
|
case 0:
|
|
@@ -134,12 +127,34 @@ var loadBundle = function() {
|
|
|
134
127
|
void 0
|
|
135
128
|
];
|
|
136
129
|
}
|
|
130
|
+
_state.label = 2;
|
|
131
|
+
case 2:
|
|
132
|
+
_state.trys.push([
|
|
133
|
+
2,
|
|
134
|
+
4,
|
|
135
|
+
,
|
|
136
|
+
5
|
|
137
|
+
]);
|
|
138
|
+
return [
|
|
139
|
+
4,
|
|
140
|
+
compatibleRequire(filepath, false)
|
|
141
|
+
];
|
|
142
|
+
case 3:
|
|
143
|
+
module = _state.sent();
|
|
137
144
|
return [
|
|
138
145
|
2,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
module
|
|
147
|
+
];
|
|
148
|
+
case 4:
|
|
149
|
+
e = _state.sent();
|
|
150
|
+
logger.error("Load ".concat(filepath, " bundle failed, error = %s"), _instanceof(e, Error) ? e.stack || e.message : e);
|
|
151
|
+
return [
|
|
152
|
+
2,
|
|
153
|
+
void 0
|
|
154
|
+
];
|
|
155
|
+
case 5:
|
|
156
|
+
return [
|
|
157
|
+
2
|
|
143
158
|
];
|
|
144
159
|
}
|
|
145
160
|
});
|
|
@@ -202,7 +217,7 @@ function _getServerManifest() {
|
|
|
202
217
|
loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
|
|
203
218
|
return [
|
|
204
219
|
4,
|
|
205
|
-
|
|
220
|
+
compatibleRequire(loadableUri).catch(function(_) {
|
|
206
221
|
return {};
|
|
207
222
|
})
|
|
208
223
|
];
|
|
@@ -211,7 +226,7 @@ function _getServerManifest() {
|
|
|
211
226
|
routesManifestUri = path.join(pwd, ROUTE_MANIFEST_FILE);
|
|
212
227
|
return [
|
|
213
228
|
4,
|
|
214
|
-
|
|
229
|
+
compatibleRequire(routesManifestUri).catch(function(_) {
|
|
215
230
|
return {};
|
|
216
231
|
})
|
|
217
232
|
];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
|
|
3
3
|
const CACHE_FILENAME = "cache";
|
|
4
|
-
function loadCacheConfig(pwd) {
|
|
4
|
+
async function loadCacheConfig(pwd) {
|
|
5
5
|
const serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
|
|
6
|
-
const mod = requireExistModule(serverCacheFilepath, {
|
|
6
|
+
const mod = await requireExistModule(serverCacheFilepath, {
|
|
7
7
|
interop: false
|
|
8
8
|
});
|
|
9
9
|
if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire } from "@modern-js/utils";
|
|
3
3
|
import { parse } from "flatted";
|
|
4
|
-
const requireConfig = (serverConfigPath) => {
|
|
4
|
+
const requireConfig = async (serverConfigPath) => {
|
|
5
5
|
if (fs.pathExistsSync(serverConfigPath)) {
|
|
6
|
-
return
|
|
6
|
+
return compatibleRequire(serverConfigPath);
|
|
7
7
|
}
|
|
8
8
|
return void 0;
|
|
9
9
|
};
|
|
10
|
-
function loadServerConfigNew(serverConfigPath) {
|
|
11
|
-
const mod = requireExistModule(serverConfigPath);
|
|
10
|
+
async function loadServerConfigNew(serverConfigPath) {
|
|
11
|
+
const mod = await requireExistModule(serverConfigPath);
|
|
12
12
|
if (mod) {
|
|
13
13
|
return mod;
|
|
14
14
|
}
|
|
15
15
|
return void 0;
|
|
16
16
|
}
|
|
17
|
-
function loadServerConfigOld(pwd, configFile) {
|
|
18
|
-
const serverConfigPath = path.join(pwd, `${configFile}.
|
|
19
|
-
const serverConfig = requireConfig(serverConfigPath);
|
|
17
|
+
async function loadServerConfigOld(pwd, configFile) {
|
|
18
|
+
const serverConfigPath = path.join(pwd, `${configFile}.cjs`);
|
|
19
|
+
const serverConfig = await requireConfig(serverConfigPath);
|
|
20
20
|
return serverConfig;
|
|
21
21
|
}
|
|
22
|
-
function loadServerRuntimeConfig(pwd, oldServerFile = DEFAULT_SERVER_CONFIG, newServerConfigPath) {
|
|
23
|
-
const newServerConfig = newServerConfigPath && loadServerConfigNew(newServerConfigPath);
|
|
22
|
+
async function loadServerRuntimeConfig(pwd, oldServerFile = DEFAULT_SERVER_CONFIG, newServerConfigPath) {
|
|
23
|
+
const newServerConfig = newServerConfigPath && await loadServerConfigNew(newServerConfigPath);
|
|
24
24
|
if (newServerConfig) {
|
|
25
25
|
return newServerConfig;
|
|
26
26
|
}
|
|
27
|
-
const oldServerConfig = loadServerConfigOld(pwd, oldServerFile);
|
|
27
|
+
const oldServerConfig = await loadServerConfigOld(pwd, oldServerFile);
|
|
28
28
|
return oldServerConfig;
|
|
29
29
|
}
|
|
30
30
|
function loadServerCliConfig(pwd, defaultConfig = {}) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function resolveServerPlugin(plugin, appDirectory) {
|
|
1
|
+
import { compatibleRequire, tryResolve } from "@modern-js/utils";
|
|
2
|
+
async function resolveServerPlugin(plugin, appDirectory) {
|
|
3
3
|
const { name, options } = plugin;
|
|
4
4
|
const pluginPath = tryResolve(name, appDirectory);
|
|
5
|
-
const module =
|
|
5
|
+
const module = await compatibleRequire(pluginPath);
|
|
6
6
|
const pluginInstance = module(options);
|
|
7
7
|
return pluginInstance;
|
|
8
8
|
}
|
|
9
|
-
function loadServerPlugins(serverPlugins, appDirectory) {
|
|
10
|
-
const instances = serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory));
|
|
9
|
+
async function loadServerPlugins(serverPlugins, appDirectory) {
|
|
10
|
+
const instances = await Promise.all(serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory)));
|
|
11
11
|
return instances;
|
|
12
12
|
}
|
|
13
13
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
3
|
-
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
|
|
3
|
+
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs, compatibleRequire } from "@modern-js/utils";
|
|
4
4
|
async function getHtmlTemplates(pwd, routes) {
|
|
5
5
|
const htmls = await Promise.all(routes.map(async (route) => {
|
|
6
6
|
let html;
|
|
@@ -27,22 +27,17 @@ function injectTemplates(pwd, routes) {
|
|
|
27
27
|
await next();
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
const dynamicImport = (filePath) => {
|
|
31
|
-
try {
|
|
32
|
-
const module = require(filePath);
|
|
33
|
-
return Promise.resolve(module);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return Promise.reject(e);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
30
|
const loadBundle = async (filepath, logger) => {
|
|
39
31
|
if (!await fs.pathExists(filepath)) {
|
|
40
32
|
return void 0;
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
try {
|
|
35
|
+
const module = await compatibleRequire(filepath, false);
|
|
36
|
+
return module;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
|
|
44
39
|
return void 0;
|
|
45
|
-
}
|
|
40
|
+
}
|
|
46
41
|
};
|
|
47
42
|
async function getServerManifest(pwd, routes, logger) {
|
|
48
43
|
const loaderBundles = {};
|
|
@@ -57,9 +52,9 @@ async function getServerManifest(pwd, routes, logger) {
|
|
|
57
52
|
loaderBundle && (loaderBundles[entryName] = loaderBundle);
|
|
58
53
|
}));
|
|
59
54
|
const loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
|
|
60
|
-
const loadableStats = await
|
|
55
|
+
const loadableStats = await compatibleRequire(loadableUri).catch((_) => ({}));
|
|
61
56
|
const routesManifestUri = path.join(pwd, ROUTE_MANIFEST_FILE);
|
|
62
|
-
const routeManifest = await
|
|
57
|
+
const routeManifest = await compatibleRequire(routesManifestUri).catch((_) => ({}));
|
|
63
58
|
const nestedRoutesJsonPath = path.join(pwd, NESTED_ROUTE_SPEC_FILE);
|
|
64
59
|
const nestedRoutesJson = await import(nestedRoutesJsonPath).catch((_) => ({}));
|
|
65
60
|
return {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CacheConfig } from '../../../types';
|
|
2
|
-
export declare function loadCacheConfig(pwd: string): CacheConfig | undefined
|
|
2
|
+
export declare function loadCacheConfig(pwd: string): Promise<CacheConfig | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { CliConfig, ServerConfig, UserConfig } from '../../../types';
|
|
2
|
-
export declare function loadServerRuntimeConfig(pwd: string, oldServerFile?: string, newServerConfigPath?: string): ServerConfig | undefined
|
|
2
|
+
export declare function loadServerRuntimeConfig(pwd: string, oldServerFile?: string, newServerConfigPath?: string): Promise<ServerConfig | undefined>;
|
|
3
3
|
export declare function loadServerCliConfig(pwd: string, defaultConfig?: UserConfig): CliConfig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ServerPlugin } from '@modern-js/types';
|
|
2
2
|
import { ServerPlugin as ServerPluginInstance } from '../../../types';
|
|
3
|
-
export declare function loadServerPlugins(serverPlugins: ServerPlugin[], appDirectory: string): ServerPluginInstance[]
|
|
3
|
+
export declare function loadServerPlugins(serverPlugins: ServerPlugin[], appDirectory: string): Promise<ServerPluginInstance[]>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.
|
|
18
|
+
"version": "2.58.2-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"hono": "^3.12.2",
|
|
55
55
|
"ts-deepmerge": "7.0.0",
|
|
56
56
|
"@modern-js/plugin": "2.58.1",
|
|
57
|
-
"@modern-js/
|
|
58
|
-
"@modern-js/utils": "2.58.1"
|
|
57
|
+
"@modern-js/utils": "2.58.1",
|
|
58
|
+
"@modern-js/runtime-utils": "2.58.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/jest": "^29",
|