@modern-js/plugin-server 2.58.1 → 2.58.3
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/cli.js +7 -6
- package/dist/cjs/runtime/assets/assets.js +1 -1
- package/dist/cjs/runtime/assets/node.js +2 -2
- package/dist/cjs/server.js +7 -7
- package/dist/cjs/utils.js +4 -4
- package/dist/esm/cli.js +30 -14
- package/dist/esm/runtime/assets/assets.js +1 -1
- package/dist/esm/runtime/assets/node.js +2 -2
- package/dist/esm/server.js +77 -22
- package/dist/esm/utils.js +65 -23
- package/dist/esm-node/cli.js +7 -6
- package/dist/esm-node/runtime/assets/assets.js +1 -1
- package/dist/esm-node/runtime/assets/node.js +2 -2
- package/dist/esm-node/server.js +7 -7
- package/dist/esm-node/utils.js +4 -4
- package/dist/types/cli.d.ts +1 -1
- package/dist/types/server.d.ts +1 -1
- package/dist/types/utils.d.ts +4 -4
- package/package.json +10 -10
package/dist/cjs/cli.js
CHANGED
|
@@ -33,9 +33,9 @@ __export(cli_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(cli_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
|
|
37
|
-
var import_utils = require("@modern-js/utils");
|
|
38
36
|
var import_server_utils = require("@modern-js/server-utils");
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
|
|
39
39
|
function checkHasCache(appDir) {
|
|
40
40
|
const tsFilepath = import_path.default.resolve(appDir, "server", "cache.ts");
|
|
41
41
|
const jsfilepath = import_path.default.resolve(appDir, "server", "cache.js");
|
|
@@ -54,7 +54,7 @@ const serverPlugin = () => ({
|
|
|
54
54
|
};
|
|
55
55
|
},
|
|
56
56
|
async afterBuild() {
|
|
57
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
|
57
|
+
const { appDirectory, distDirectory, moduleType } = api.useAppContext();
|
|
58
58
|
if (checkHasCache(appDirectory)) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
@@ -64,9 +64,9 @@ const serverPlugin = () => ({
|
|
|
64
64
|
const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
|
65
65
|
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
66
66
|
const sourceDirs = [];
|
|
67
|
-
if (import_fs_extra.default.
|
|
67
|
+
if (await import_fs_extra.default.pathExists(serverDir)) {
|
|
68
68
|
sourceDirs.push(serverDir);
|
|
69
|
-
if (import_fs_extra.default.
|
|
69
|
+
if (await import_fs_extra.default.pathExists(sharedDir)) {
|
|
70
70
|
sourceDirs.push(sharedDir);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -81,7 +81,8 @@ const serverPlugin = () => ({
|
|
|
81
81
|
}, {
|
|
82
82
|
sourceDirs,
|
|
83
83
|
distDir,
|
|
84
|
-
tsconfigPath
|
|
84
|
+
tsconfigPath,
|
|
85
|
+
moduleType
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -23,8 +23,8 @@ __export(assets_exports, {
|
|
|
23
23
|
injectAssetsTags: () => injectAssetsTags
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(assets_exports);
|
|
26
|
-
var import_remix_router = require("@modern-js/runtime-utils/remix-router");
|
|
27
26
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
27
|
+
var import_remix_router = require("@modern-js/runtime-utils/remix-router");
|
|
28
28
|
const createScript = (href, nonce) => `<script defer src="${href}"${nonce ? ` nonce="${nonce}"` : ""}></script>`;
|
|
29
29
|
const createCss = (href) => `<link rel="stylesheet" type="text/css" href="${href}">`;
|
|
30
30
|
const getAssets = (html, nestedRoutes, routesJson, routesManifest, pathname) => {
|
|
@@ -33,10 +33,10 @@ __export(node_exports, {
|
|
|
33
33
|
injectAssets: () => injectAssets
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(node_exports);
|
|
36
|
-
var import_node_path = __toESM(require("node:path"));
|
|
37
36
|
var import_fs = __toESM(require("fs"));
|
|
38
|
-
var
|
|
37
|
+
var import_node_path = __toESM(require("node:path"));
|
|
39
38
|
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_constants = require("@modern-js/utils/universal/constants");
|
|
40
40
|
var import_assets = require("./assets");
|
|
41
41
|
var import_assets2 = require("./assets");
|
|
42
42
|
const injectAssets = async ({ html, pathname, distDir, nonce }) => {
|
package/dist/cjs/server.js
CHANGED
|
@@ -80,9 +80,9 @@ var server_default = () => ({
|
|
|
80
80
|
const storage = new Storage();
|
|
81
81
|
const transformAPI = createTransformAPI(storage);
|
|
82
82
|
const pwd = (0, import_utils.isProd)() ? distDirectory : appDirectory;
|
|
83
|
-
const loadMod = () => {
|
|
84
|
-
const { middleware: unstableMiddleware } = (0, import_utils2.loadMiddleware)(pwd);
|
|
85
|
-
const { defaultExports, hooks, middleware, unstableMiddleware: unstableMiddlewares } = (0, import_utils2.loadServerMod)(pwd);
|
|
83
|
+
const loadMod = async () => {
|
|
84
|
+
const { middleware: unstableMiddleware } = await (0, import_utils2.loadMiddleware)(pwd);
|
|
85
|
+
const { defaultExports, hooks, middleware, unstableMiddleware: unstableMiddlewares } = await (0, import_utils2.loadServerMod)(pwd);
|
|
86
86
|
if (defaultExports) {
|
|
87
87
|
defaultExports(transformAPI);
|
|
88
88
|
}
|
|
@@ -102,12 +102,12 @@ var server_default = () => ({
|
|
|
102
102
|
};
|
|
103
103
|
let factory;
|
|
104
104
|
return {
|
|
105
|
-
prepare() {
|
|
106
|
-
loadMod();
|
|
105
|
+
async prepare() {
|
|
106
|
+
await loadMod();
|
|
107
107
|
},
|
|
108
|
-
reset() {
|
|
108
|
+
async reset() {
|
|
109
109
|
storage.reset();
|
|
110
|
-
loadMod();
|
|
110
|
+
await loadMod();
|
|
111
111
|
factory = getFactory(storage);
|
|
112
112
|
},
|
|
113
113
|
afterMatch(context, next) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -35,9 +35,9 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
37
|
const WEB_APP_NAME = "index";
|
|
38
|
-
const loadMiddleware = (pwd = process.cwd()) => {
|
|
38
|
+
const loadMiddleware = async (pwd = process.cwd()) => {
|
|
39
39
|
const middlewarePath = import_path.default.resolve(pwd, import_utils.SERVER_DIR, "_middleware");
|
|
40
|
-
const middlewareMode = (0, import_utils.requireExistModule)(middlewarePath, {
|
|
40
|
+
const middlewareMode = await (0, import_utils.requireExistModule)(middlewarePath, {
|
|
41
41
|
interop: false
|
|
42
42
|
});
|
|
43
43
|
const { middleware = [] } = middlewareMode || {};
|
|
@@ -45,9 +45,9 @@ const loadMiddleware = (pwd = process.cwd()) => {
|
|
|
45
45
|
middleware
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
|
-
const loadServerMod = (pwd = process.cwd()) => {
|
|
48
|
+
const loadServerMod = async (pwd = process.cwd()) => {
|
|
49
49
|
const webAppPath = import_path.default.resolve(pwd, import_utils.SERVER_DIR, WEB_APP_NAME);
|
|
50
|
-
const mod = (0, import_utils.requireExistModule)(webAppPath, {
|
|
50
|
+
const mod = await (0, import_utils.requireExistModule)(webAppPath, {
|
|
51
51
|
interop: false
|
|
52
52
|
});
|
|
53
53
|
const { default: defaultExports, middleware, unstableMiddleware, ...hooks } = mod || {};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import fs from "@modern-js/utils/fs-extra";
|
|
5
|
-
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
|
6
4
|
import { compile } from "@modern-js/server-utils";
|
|
5
|
+
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
|
6
|
+
import fs from "@modern-js/utils/fs-extra";
|
|
7
7
|
function checkHasCache(appDir) {
|
|
8
8
|
var tsFilepath = path.resolve(appDir, "server", "cache.ts");
|
|
9
9
|
var jsfilepath = path.resolve(appDir, "server", "cache.js");
|
|
@@ -26,11 +26,11 @@ var serverPlugin = function() {
|
|
|
26
26
|
},
|
|
27
27
|
afterBuild: function afterBuild() {
|
|
28
28
|
return _async_to_generator(function() {
|
|
29
|
-
var _api_useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
|
29
|
+
var _api_useAppContext, appDirectory, distDirectory, moduleType, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
|
30
30
|
return _ts_generator(this, function(_state) {
|
|
31
31
|
switch (_state.label) {
|
|
32
32
|
case 0:
|
|
33
|
-
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
|
|
33
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory, moduleType = _api_useAppContext.moduleType;
|
|
34
34
|
if (checkHasCache(appDirectory)) {
|
|
35
35
|
return [
|
|
36
36
|
2
|
|
@@ -42,19 +42,34 @@ var serverPlugin = function() {
|
|
|
42
42
|
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
43
43
|
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
44
44
|
sourceDirs = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
return [
|
|
46
|
+
4,
|
|
47
|
+
fs.pathExists(serverDir)
|
|
48
|
+
];
|
|
49
|
+
case 1:
|
|
50
|
+
if (!_state.sent())
|
|
51
|
+
return [
|
|
52
|
+
3,
|
|
53
|
+
3
|
|
54
|
+
];
|
|
55
|
+
sourceDirs.push(serverDir);
|
|
56
|
+
return [
|
|
57
|
+
4,
|
|
58
|
+
fs.pathExists(sharedDir)
|
|
59
|
+
];
|
|
60
|
+
case 2:
|
|
61
|
+
if (_state.sent()) {
|
|
62
|
+
sourceDirs.push(sharedDir);
|
|
50
63
|
}
|
|
64
|
+
_state.label = 3;
|
|
65
|
+
case 3:
|
|
51
66
|
server = modernConfig.server;
|
|
52
67
|
alias = modernConfig.source.alias;
|
|
53
68
|
babel = modernConfig.tools.babel;
|
|
54
69
|
if (!(sourceDirs.length > 0))
|
|
55
70
|
return [
|
|
56
71
|
3,
|
|
57
|
-
|
|
72
|
+
5
|
|
58
73
|
];
|
|
59
74
|
return [
|
|
60
75
|
4,
|
|
@@ -65,13 +80,14 @@ var serverPlugin = function() {
|
|
|
65
80
|
}, {
|
|
66
81
|
sourceDirs,
|
|
67
82
|
distDir,
|
|
68
|
-
tsconfigPath
|
|
83
|
+
tsconfigPath,
|
|
84
|
+
moduleType
|
|
69
85
|
})
|
|
70
86
|
];
|
|
71
|
-
case
|
|
87
|
+
case 4:
|
|
72
88
|
_state.sent();
|
|
73
|
-
_state.label =
|
|
74
|
-
case
|
|
89
|
+
_state.label = 5;
|
|
90
|
+
case 5:
|
|
75
91
|
return [
|
|
76
92
|
2
|
|
77
93
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
3
2
|
import { matchEntry } from "@modern-js/runtime-utils/node";
|
|
3
|
+
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
4
4
|
var createScript = function(href, nonce) {
|
|
5
5
|
return '<script defer src="'.concat(href, '"').concat(nonce ? ' nonce="'.concat(nonce, '"') : "", "></script>");
|
|
6
6
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import path from "node:path";
|
|
4
3
|
import fs from "fs";
|
|
5
|
-
import
|
|
4
|
+
import path from "node:path";
|
|
6
5
|
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
|
|
6
|
+
import { NESTED_ROUTE_SPEC_FILE, ROUTE_SPEC_FILE } from "@modern-js/utils/universal/constants";
|
|
7
7
|
import { getAssetsTags, injectAssetsTags } from "./assets";
|
|
8
8
|
import { getAssetsTags as getAssetsTags2, getAssets } from "./assets";
|
|
9
9
|
var injectAssets = function() {
|
package/dist/esm/server.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
1
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
5
|
import { isProd, logger } from "@modern-js/utils";
|
|
4
6
|
import { loadMiddleware, loadServerMod } from "./utils";
|
|
5
7
|
var HOOKS;
|
|
@@ -66,35 +68,88 @@ function server_default() {
|
|
|
66
68
|
var transformAPI = createTransformAPI(storage);
|
|
67
69
|
var pwd = isProd() ? distDirectory : appDirectory;
|
|
68
70
|
var loadMod = function() {
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
var _ref = _async_to_generator(function() {
|
|
72
|
+
var _storage_unstableMiddlewares, _ref2, unstableMiddleware, _ref1, defaultExports, hooks, middleware, unstableMiddlewares;
|
|
73
|
+
return _ts_generator(this, function(_state) {
|
|
74
|
+
switch (_state.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
return [
|
|
77
|
+
4,
|
|
78
|
+
loadMiddleware(pwd)
|
|
79
|
+
];
|
|
80
|
+
case 1:
|
|
81
|
+
_ref2 = _state.sent(), unstableMiddleware = _ref2.middleware;
|
|
82
|
+
return [
|
|
83
|
+
4,
|
|
84
|
+
loadServerMod(pwd)
|
|
85
|
+
];
|
|
86
|
+
case 2:
|
|
87
|
+
_ref1 = _state.sent(), defaultExports = _ref1.defaultExports, hooks = _ref1.hooks, middleware = _ref1.middleware, unstableMiddlewares = _ref1.unstableMiddleware;
|
|
88
|
+
if (defaultExports) {
|
|
89
|
+
defaultExports(transformAPI);
|
|
90
|
+
}
|
|
91
|
+
if (hooks) {
|
|
92
|
+
Object.values(HOOKS).forEach(function(key) {
|
|
93
|
+
var fn = hooks[key];
|
|
94
|
+
if (fn) {
|
|
95
|
+
storage.hooks[key] = fn;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (middleware) {
|
|
100
|
+
storage.middlewares = [].concat(middleware);
|
|
101
|
+
}
|
|
102
|
+
storage.middlewares = storage.middlewares.concat(unstableMiddleware);
|
|
103
|
+
(_storage_unstableMiddlewares = storage.unstableMiddlewares).push.apply(_storage_unstableMiddlewares, _to_consumable_array(unstableMiddlewares || []));
|
|
104
|
+
return [
|
|
105
|
+
2
|
|
106
|
+
];
|
|
80
107
|
}
|
|
81
108
|
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
(_storage_unstableMiddlewares = storage.unstableMiddlewares).push.apply(_storage_unstableMiddlewares, _to_consumable_array(unstableMiddlewares || []));
|
|
88
|
-
};
|
|
109
|
+
});
|
|
110
|
+
return function loadMod2() {
|
|
111
|
+
return _ref.apply(this, arguments);
|
|
112
|
+
};
|
|
113
|
+
}();
|
|
89
114
|
var factory;
|
|
90
115
|
return {
|
|
91
116
|
prepare: function prepare() {
|
|
92
|
-
|
|
117
|
+
return _async_to_generator(function() {
|
|
118
|
+
return _ts_generator(this, function(_state) {
|
|
119
|
+
switch (_state.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
return [
|
|
122
|
+
4,
|
|
123
|
+
loadMod()
|
|
124
|
+
];
|
|
125
|
+
case 1:
|
|
126
|
+
_state.sent();
|
|
127
|
+
return [
|
|
128
|
+
2
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
})();
|
|
93
133
|
},
|
|
94
134
|
reset: function reset() {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
135
|
+
return _async_to_generator(function() {
|
|
136
|
+
return _ts_generator(this, function(_state) {
|
|
137
|
+
switch (_state.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
storage.reset();
|
|
140
|
+
return [
|
|
141
|
+
4,
|
|
142
|
+
loadMod()
|
|
143
|
+
];
|
|
144
|
+
case 1:
|
|
145
|
+
_state.sent();
|
|
146
|
+
factory = getFactory(storage);
|
|
147
|
+
return [
|
|
148
|
+
2
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
})();
|
|
98
153
|
},
|
|
99
154
|
afterMatch: function afterMatch(context, next) {
|
|
100
155
|
if (!storage.hooks.afterMatch) {
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,36 +1,78 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
1
2
|
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
2
4
|
import path from "path";
|
|
3
5
|
import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
|
|
4
6
|
var WEB_APP_NAME = "index";
|
|
5
7
|
var loadMiddleware = function() {
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var _ref = _async_to_generator(function() {
|
|
9
|
+
var pwd, middlewarePath, middlewareMode, _ref2, _ref_middleware, middleware;
|
|
10
|
+
var _arguments = arguments;
|
|
11
|
+
return _ts_generator(this, function(_state) {
|
|
12
|
+
switch (_state.label) {
|
|
13
|
+
case 0:
|
|
14
|
+
pwd = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : process.cwd();
|
|
15
|
+
middlewarePath = path.resolve(pwd, SERVER_DIR, "_middleware");
|
|
16
|
+
return [
|
|
17
|
+
4,
|
|
18
|
+
requireExistModule(middlewarePath, {
|
|
19
|
+
interop: false
|
|
20
|
+
})
|
|
21
|
+
];
|
|
22
|
+
case 1:
|
|
23
|
+
middlewareMode = _state.sent();
|
|
24
|
+
_ref2 = middlewareMode || {}, _ref_middleware = _ref2.middleware, middleware = _ref_middleware === void 0 ? [] : _ref_middleware;
|
|
25
|
+
return [
|
|
26
|
+
2,
|
|
27
|
+
{
|
|
28
|
+
middleware
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
10
33
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
middleware
|
|
34
|
+
return function loadMiddleware2() {
|
|
35
|
+
return _ref.apply(this, arguments);
|
|
14
36
|
};
|
|
15
|
-
};
|
|
37
|
+
}();
|
|
16
38
|
var loadServerMod = function() {
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
var _ref = _async_to_generator(function() {
|
|
40
|
+
var pwd, webAppPath, mod, _ref2, defaultExports, middleware, unstableMiddleware, hooks;
|
|
41
|
+
var _arguments = arguments;
|
|
42
|
+
return _ts_generator(this, function(_state) {
|
|
43
|
+
switch (_state.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
pwd = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : process.cwd();
|
|
46
|
+
webAppPath = path.resolve(pwd, SERVER_DIR, WEB_APP_NAME);
|
|
47
|
+
return [
|
|
48
|
+
4,
|
|
49
|
+
requireExistModule(webAppPath, {
|
|
50
|
+
interop: false
|
|
51
|
+
})
|
|
52
|
+
];
|
|
53
|
+
case 1:
|
|
54
|
+
mod = _state.sent();
|
|
55
|
+
_ref2 = mod || {}, defaultExports = _ref2.default, middleware = _ref2.middleware, unstableMiddleware = _ref2.unstableMiddleware, hooks = _object_without_properties(_ref2, [
|
|
56
|
+
"default",
|
|
57
|
+
"middleware",
|
|
58
|
+
"unstableMiddleware"
|
|
59
|
+
]);
|
|
60
|
+
return [
|
|
61
|
+
2,
|
|
62
|
+
{
|
|
63
|
+
defaultExports,
|
|
64
|
+
unstableMiddleware,
|
|
65
|
+
hooks,
|
|
66
|
+
middleware
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
21
71
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"middleware",
|
|
25
|
-
"unstableMiddleware"
|
|
26
|
-
]);
|
|
27
|
-
return {
|
|
28
|
-
defaultExports,
|
|
29
|
-
unstableMiddleware,
|
|
30
|
-
hooks,
|
|
31
|
-
middleware
|
|
72
|
+
return function loadServerMod2() {
|
|
73
|
+
return _ref.apply(this, arguments);
|
|
32
74
|
};
|
|
33
|
-
};
|
|
75
|
+
}();
|
|
34
76
|
export {
|
|
35
77
|
loadMiddleware,
|
|
36
78
|
loadServerMod
|
package/dist/esm-node/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import fs from "@modern-js/utils/fs-extra";
|
|
3
|
-
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
|
4
2
|
import { compile } from "@modern-js/server-utils";
|
|
3
|
+
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
|
4
|
+
import fs from "@modern-js/utils/fs-extra";
|
|
5
5
|
function checkHasCache(appDir) {
|
|
6
6
|
const tsFilepath = path.resolve(appDir, "server", "cache.ts");
|
|
7
7
|
const jsfilepath = path.resolve(appDir, "server", "cache.js");
|
|
@@ -20,7 +20,7 @@ const serverPlugin = () => ({
|
|
|
20
20
|
};
|
|
21
21
|
},
|
|
22
22
|
async afterBuild() {
|
|
23
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
|
23
|
+
const { appDirectory, distDirectory, moduleType } = api.useAppContext();
|
|
24
24
|
if (checkHasCache(appDirectory)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -30,9 +30,9 @@ const serverPlugin = () => ({
|
|
|
30
30
|
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
31
31
|
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
32
32
|
const sourceDirs = [];
|
|
33
|
-
if (fs.
|
|
33
|
+
if (await fs.pathExists(serverDir)) {
|
|
34
34
|
sourceDirs.push(serverDir);
|
|
35
|
-
if (fs.
|
|
35
|
+
if (await fs.pathExists(sharedDir)) {
|
|
36
36
|
sourceDirs.push(sharedDir);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -47,7 +47,8 @@ const serverPlugin = () => ({
|
|
|
47
47
|
}, {
|
|
48
48
|
sourceDirs,
|
|
49
49
|
distDir,
|
|
50
|
-
tsconfigPath
|
|
50
|
+
tsconfigPath,
|
|
51
|
+
moduleType
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
2
1
|
import { matchEntry } from "@modern-js/runtime-utils/node";
|
|
2
|
+
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
3
3
|
const createScript = (href, nonce) => `<script defer src="${href}"${nonce ? ` nonce="${nonce}"` : ""}></script>`;
|
|
4
4
|
const createCss = (href) => `<link rel="stylesheet" type="text/css" href="${href}">`;
|
|
5
5
|
const getAssets = (html, nestedRoutes, routesJson, routesManifest, pathname) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import fs from "fs";
|
|
3
|
-
import
|
|
2
|
+
import path from "node:path";
|
|
4
3
|
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
|
|
4
|
+
import { NESTED_ROUTE_SPEC_FILE, ROUTE_SPEC_FILE } from "@modern-js/utils/universal/constants";
|
|
5
5
|
import { getAssetsTags, injectAssetsTags } from "./assets";
|
|
6
6
|
import { getAssetsTags as getAssetsTags2, getAssets } from "./assets";
|
|
7
7
|
const injectAssets = async ({ html, pathname, distDir, nonce }) => {
|
package/dist/esm-node/server.js
CHANGED
|
@@ -54,9 +54,9 @@ var server_default = () => ({
|
|
|
54
54
|
const storage = new Storage();
|
|
55
55
|
const transformAPI = createTransformAPI(storage);
|
|
56
56
|
const pwd = isProd() ? distDirectory : appDirectory;
|
|
57
|
-
const loadMod = () => {
|
|
58
|
-
const { middleware: unstableMiddleware } = loadMiddleware(pwd);
|
|
59
|
-
const { defaultExports, hooks, middleware, unstableMiddleware: unstableMiddlewares } = loadServerMod(pwd);
|
|
57
|
+
const loadMod = async () => {
|
|
58
|
+
const { middleware: unstableMiddleware } = await loadMiddleware(pwd);
|
|
59
|
+
const { defaultExports, hooks, middleware, unstableMiddleware: unstableMiddlewares } = await loadServerMod(pwd);
|
|
60
60
|
if (defaultExports) {
|
|
61
61
|
defaultExports(transformAPI);
|
|
62
62
|
}
|
|
@@ -76,12 +76,12 @@ var server_default = () => ({
|
|
|
76
76
|
};
|
|
77
77
|
let factory;
|
|
78
78
|
return {
|
|
79
|
-
prepare() {
|
|
80
|
-
loadMod();
|
|
79
|
+
async prepare() {
|
|
80
|
+
await loadMod();
|
|
81
81
|
},
|
|
82
|
-
reset() {
|
|
82
|
+
async reset() {
|
|
83
83
|
storage.reset();
|
|
84
|
-
loadMod();
|
|
84
|
+
await loadMod();
|
|
85
85
|
factory = getFactory(storage);
|
|
86
86
|
},
|
|
87
87
|
afterMatch(context, next) {
|
package/dist/esm-node/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
|
|
3
3
|
const WEB_APP_NAME = "index";
|
|
4
|
-
const loadMiddleware = (pwd = process.cwd()) => {
|
|
4
|
+
const loadMiddleware = async (pwd = process.cwd()) => {
|
|
5
5
|
const middlewarePath = path.resolve(pwd, SERVER_DIR, "_middleware");
|
|
6
|
-
const middlewareMode = requireExistModule(middlewarePath, {
|
|
6
|
+
const middlewareMode = await requireExistModule(middlewarePath, {
|
|
7
7
|
interop: false
|
|
8
8
|
});
|
|
9
9
|
const { middleware = [] } = middlewareMode || {};
|
|
@@ -11,9 +11,9 @@ const loadMiddleware = (pwd = process.cwd()) => {
|
|
|
11
11
|
middleware
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
const loadServerMod = (pwd = process.cwd()) => {
|
|
14
|
+
const loadServerMod = async (pwd = process.cwd()) => {
|
|
15
15
|
const webAppPath = path.resolve(pwd, SERVER_DIR, WEB_APP_NAME);
|
|
16
|
-
const mod = requireExistModule(webAppPath, {
|
|
16
|
+
const mod = await requireExistModule(webAppPath, {
|
|
17
17
|
interop: false
|
|
18
18
|
});
|
|
19
19
|
const { default: defaultExports, middleware, unstableMiddleware, ...hooks } = mod || {};
|
package/dist/types/cli.d.ts
CHANGED
package/dist/types/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServerPlugin } from '@modern-js/server-core';
|
|
2
2
|
import type { MiddlewareContext, NextFunction } from '@modern-js/types';
|
|
3
|
-
import { Hook, Middleware, loadMiddleware, loadServerMod } from './utils';
|
|
3
|
+
import { type Hook, type Middleware, loadMiddleware, loadServerMod } from './utils';
|
|
4
4
|
export { loadMiddleware, loadServerMod };
|
|
5
5
|
export type { Hook, Middleware };
|
|
6
6
|
export declare const compose: (middlewares: Middleware[]) => (ctx: MiddlewareContext, resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void) => NextFunction;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ export type ServerMod = {
|
|
|
8
8
|
afterMatch: Hook;
|
|
9
9
|
afterRender: Hook;
|
|
10
10
|
};
|
|
11
|
-
export declare const loadMiddleware: (pwd?: string) => {
|
|
11
|
+
export declare const loadMiddleware: (pwd?: string) => Promise<{
|
|
12
12
|
middleware: any;
|
|
13
|
-
}
|
|
14
|
-
export declare const loadServerMod: (pwd?: string) => {
|
|
13
|
+
}>;
|
|
14
|
+
export declare const loadServerMod: (pwd?: string) => Promise<{
|
|
15
15
|
defaultExports: (args: any) => void;
|
|
16
16
|
unstableMiddleware: any[];
|
|
17
17
|
hooks: {
|
|
@@ -19,4 +19,4 @@ export declare const loadServerMod: (pwd?: string) => {
|
|
|
19
19
|
afterRender: Hook;
|
|
20
20
|
};
|
|
21
21
|
middleware: Middleware[];
|
|
22
|
-
}
|
|
22
|
+
}>;
|
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.3",
|
|
19
19
|
"types": "./dist/types/cli.d.ts",
|
|
20
20
|
"jsnext:source": "./src/cli",
|
|
21
21
|
"main": "./dist/cjs/cli.js",
|
|
@@ -65,21 +65,21 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@swc/helpers": "0.5.3",
|
|
68
|
-
"@modern-js/runtime-utils": "2.58.
|
|
69
|
-
"@modern-js/utils": "2.58.
|
|
70
|
-
"@modern-js/
|
|
68
|
+
"@modern-js/runtime-utils": "2.58.3",
|
|
69
|
+
"@modern-js/server-utils": "2.58.3",
|
|
70
|
+
"@modern-js/utils": "2.58.3"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/jest": "^29",
|
|
74
74
|
"@types/node": "^14",
|
|
75
75
|
"jest": "^29",
|
|
76
76
|
"typescript": "^5",
|
|
77
|
-
"@modern-js/app-tools": "2.58.
|
|
78
|
-
"@modern-js/server-core": "2.58.
|
|
79
|
-
"@modern-js/core": "2.58.
|
|
80
|
-
"@modern-js/types": "2.58.
|
|
81
|
-
"@scripts/build": "2.58.
|
|
82
|
-
"@scripts/jest-config": "2.58.
|
|
77
|
+
"@modern-js/app-tools": "2.58.3",
|
|
78
|
+
"@modern-js/server-core": "2.58.3",
|
|
79
|
+
"@modern-js/core": "2.58.3",
|
|
80
|
+
"@modern-js/types": "2.58.3",
|
|
81
|
+
"@scripts/build": "2.58.3",
|
|
82
|
+
"@scripts/jest-config": "2.58.3"
|
|
83
83
|
},
|
|
84
84
|
"sideEffects": [
|
|
85
85
|
"*.css",
|