@modern-js/prod-server 2.9.0 → 2.9.1-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/server/index.js +8 -6
- package/dist/esm/server/index.js +71 -18
- package/dist/esm-node/server/index.js +9 -6
- package/dist/js/modern/constants.js +35 -0
- package/dist/js/modern/index.js +18 -0
- package/dist/js/modern/libs/context/context.js +160 -0
- package/dist/js/modern/libs/context/index.js +6 -0
- package/dist/js/modern/libs/hook-api/index.js +134 -0
- package/dist/js/modern/libs/hook-api/route.js +20 -0
- package/dist/js/modern/libs/hook-api/template.js +73 -0
- package/dist/js/modern/libs/loadConfig.js +62 -0
- package/dist/js/modern/libs/logger.js +111 -0
- package/dist/js/modern/libs/metrics.js +11 -0
- package/dist/js/modern/libs/proxy.js +92 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +114 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +254 -0
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +47 -0
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +37 -0
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +91 -0
- package/dist/js/modern/libs/render/cache/index.js +115 -0
- package/dist/js/modern/libs/render/cache/page-caches/index.js +32 -0
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +29 -0
- package/dist/js/modern/libs/render/cache/spr.js +248 -0
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +102 -0
- package/dist/js/modern/libs/render/index.js +86 -0
- package/dist/js/modern/libs/render/measure.js +68 -0
- package/dist/js/modern/libs/render/reader.js +107 -0
- package/dist/js/modern/libs/render/ssr.js +100 -0
- package/dist/js/modern/libs/render/static.js +60 -0
- package/dist/js/modern/libs/render/type.js +9 -0
- package/dist/js/modern/libs/route/index.js +54 -0
- package/dist/js/modern/libs/route/matcher.js +87 -0
- package/dist/js/modern/libs/route/route.js +16 -0
- package/dist/js/modern/libs/serve-file.js +67 -0
- package/dist/js/modern/server/index.js +208 -0
- package/dist/js/modern/server/modern-server-split.js +74 -0
- package/dist/js/modern/server/modern-server.js +554 -0
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +136 -0
- package/dist/js/modern/worker-server.js +89 -0
- package/dist/js/node/constants.js +62 -0
- package/dist/js/node/index.js +44 -0
- package/dist/js/node/libs/context/context.js +189 -0
- package/dist/js/node/libs/context/index.js +30 -0
- package/dist/js/node/libs/hook-api/index.js +164 -0
- package/dist/js/node/libs/hook-api/route.js +43 -0
- package/dist/js/node/libs/hook-api/template.js +97 -0
- package/dist/js/node/libs/loadConfig.js +91 -0
- package/dist/js/node/libs/logger.js +133 -0
- package/dist/js/node/libs/metrics.js +34 -0
- package/dist/js/node/libs/proxy.js +114 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +115 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +245 -0
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +70 -0
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +60 -0
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +114 -0
- package/dist/js/node/libs/render/cache/index.js +134 -0
- package/dist/js/node/libs/render/cache/page-caches/index.js +55 -0
- package/dist/js/node/libs/render/cache/page-caches/lru.js +58 -0
- package/dist/js/node/libs/render/cache/spr.js +270 -0
- package/dist/js/node/libs/render/cache/type.js +15 -0
- package/dist/js/node/libs/render/cache/util.js +138 -0
- package/dist/js/node/libs/render/index.js +115 -0
- package/dist/js/node/libs/render/measure.js +90 -0
- package/dist/js/node/libs/render/reader.js +140 -0
- package/dist/js/node/libs/render/ssr.js +123 -0
- package/dist/js/node/libs/render/static.js +89 -0
- package/dist/js/node/libs/render/type.js +32 -0
- package/dist/js/node/libs/route/index.js +78 -0
- package/dist/js/node/libs/route/matcher.js +106 -0
- package/dist/js/node/libs/route/route.js +39 -0
- package/dist/js/node/libs/serve-file.js +97 -0
- package/dist/js/node/server/index.js +219 -0
- package/dist/js/node/server/modern-server-split.js +97 -0
- package/dist/js/node/server/modern-server.js +559 -0
- package/dist/js/node/type.js +15 -0
- package/dist/js/node/utils.js +166 -0
- package/dist/js/node/worker-server.js +113 -0
- package/dist/js/treeshaking/constants.js +29 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +274 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +281 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +68 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +127 -0
- package/dist/js/treeshaking/libs/loadConfig.js +82 -0
- package/dist/js/treeshaking/libs/logger.js +205 -0
- package/dist/js/treeshaking/libs/metrics.js +6 -0
- package/dist/js/treeshaking/libs/proxy.js +244 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +291 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +781 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +67 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +147 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +346 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +154 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +84 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +492 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +280 -0
- package/dist/js/treeshaking/libs/render/index.js +234 -0
- package/dist/js/treeshaking/libs/render/measure.js +146 -0
- package/dist/js/treeshaking/libs/render/reader.js +339 -0
- package/dist/js/treeshaking/libs/render/ssr.js +223 -0
- package/dist/js/treeshaking/libs/render/static.js +216 -0
- package/dist/js/treeshaking/libs/render/type.js +7 -0
- package/dist/js/treeshaking/libs/route/index.js +130 -0
- package/dist/js/treeshaking/libs/route/matcher.js +143 -0
- package/dist/js/treeshaking/libs/route/route.js +40 -0
- package/dist/js/treeshaking/libs/serve-file.js +184 -0
- package/dist/js/treeshaking/server/index.js +505 -0
- package/dist/js/treeshaking/server/modern-server-split.js +360 -0
- package/dist/js/treeshaking/server/modern-server.js +1089 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +147 -0
- package/dist/js/treeshaking/worker-server.js +233 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var reader_exports = {};
|
|
45
|
+
__export(reader_exports, {
|
|
46
|
+
LruReader: () => LruReader,
|
|
47
|
+
close: () => close,
|
|
48
|
+
init: () => init,
|
|
49
|
+
readFile: () => readFile,
|
|
50
|
+
updateFile: () => updateFile
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(reader_exports);
|
|
53
|
+
var import_utils = require("@modern-js/utils");
|
|
54
|
+
var import_lru_cache = __toESM(require("lru-cache"));
|
|
55
|
+
const Byte = 1;
|
|
56
|
+
const KB = 1024 * Byte;
|
|
57
|
+
const MB = 1024 * KB;
|
|
58
|
+
const getContentLength = (cache) => cache.content.length;
|
|
59
|
+
const createCacheItem = (filepath, mtime) => __async(void 0, null, function* () {
|
|
60
|
+
const content = yield import_utils.fs.readFile(filepath);
|
|
61
|
+
return {
|
|
62
|
+
content,
|
|
63
|
+
mtime
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
class LruReader {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.cache = new import_lru_cache.default({
|
|
69
|
+
max: 256 * MB,
|
|
70
|
+
length: getContentLength,
|
|
71
|
+
maxAge: 5 * 60 * 5e3
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
init() {
|
|
75
|
+
}
|
|
76
|
+
close() {
|
|
77
|
+
}
|
|
78
|
+
read(filepath) {
|
|
79
|
+
return __async(this, null, function* () {
|
|
80
|
+
if (this.cache.has(filepath)) {
|
|
81
|
+
const { content } = this.cache.get(filepath);
|
|
82
|
+
return { content };
|
|
83
|
+
}
|
|
84
|
+
if (!import_utils.fs.existsSync(filepath)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const stat = import_utils.fs.statSync(filepath);
|
|
88
|
+
if (stat.isDirectory()) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if (stat.size > 20 * MB) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const item = yield createCacheItem(filepath, stat.mtime);
|
|
95
|
+
this.cache.set(filepath, item);
|
|
96
|
+
return item;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
update() {
|
|
100
|
+
const { cache } = this;
|
|
101
|
+
const files = cache.keys();
|
|
102
|
+
for (const filepath of files) {
|
|
103
|
+
if (!import_utils.fs.existsSync(filepath)) {
|
|
104
|
+
cache.del(filepath);
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const item = cache.get(filepath);
|
|
108
|
+
const stat = import_utils.fs.statSync(filepath);
|
|
109
|
+
const { mtime } = stat;
|
|
110
|
+
if (item.mtime < mtime) {
|
|
111
|
+
cache.del(filepath);
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
cache.del(filepath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const reader = new LruReader();
|
|
120
|
+
const readFile = (filepath) => __async(void 0, null, function* () {
|
|
121
|
+
const file = yield reader.read(filepath);
|
|
122
|
+
return file == null ? void 0 : file.content;
|
|
123
|
+
});
|
|
124
|
+
const updateFile = () => {
|
|
125
|
+
reader.update();
|
|
126
|
+
};
|
|
127
|
+
const init = () => {
|
|
128
|
+
reader.init();
|
|
129
|
+
};
|
|
130
|
+
const close = () => {
|
|
131
|
+
reader.close();
|
|
132
|
+
};
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
LruReader,
|
|
136
|
+
close,
|
|
137
|
+
init,
|
|
138
|
+
readFile,
|
|
139
|
+
updateFile
|
|
140
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var ssr_exports = {};
|
|
45
|
+
__export(ssr_exports, {
|
|
46
|
+
render: () => render
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(ssr_exports);
|
|
49
|
+
var import_path = __toESM(require("path"));
|
|
50
|
+
var import_utils = require("@modern-js/utils");
|
|
51
|
+
var import_cookie = __toESM(require("cookie"));
|
|
52
|
+
var import_cache = __toESM(require("./cache"));
|
|
53
|
+
var import_measure = require("./measure");
|
|
54
|
+
const render = (ctx, renderOptions, runner) => __async(void 0, null, function* () {
|
|
55
|
+
var _a;
|
|
56
|
+
const { urlPath, bundle, distDir, template, entryName, staticGenerate } = renderOptions;
|
|
57
|
+
const bundleJS = import_path.default.join(distDir, bundle);
|
|
58
|
+
const loadableUri = import_path.default.join(distDir, import_utils.LOADABLE_STATS_FILE);
|
|
59
|
+
const loadableStats = import_utils.fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
60
|
+
const routesManifestUri = import_path.default.join(distDir, import_utils.ROUTE_MINIFEST_FILE);
|
|
61
|
+
const routeManifest = import_utils.fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
62
|
+
const context = {
|
|
63
|
+
request: {
|
|
64
|
+
baseUrl: urlPath,
|
|
65
|
+
params: ctx.params,
|
|
66
|
+
pathname: ctx.path,
|
|
67
|
+
host: ctx.host,
|
|
68
|
+
query: ctx.query,
|
|
69
|
+
url: ctx.href,
|
|
70
|
+
cookieMap: import_cookie.default.parse(ctx.headers.cookie || ""),
|
|
71
|
+
headers: ctx.headers
|
|
72
|
+
},
|
|
73
|
+
response: {
|
|
74
|
+
setHeader: (key, value) => {
|
|
75
|
+
return ctx.res.setHeader(key, value);
|
|
76
|
+
},
|
|
77
|
+
status: (code) => {
|
|
78
|
+
ctx.res.statusCode = code;
|
|
79
|
+
},
|
|
80
|
+
locals: ((_a = ctx.res) == null ? void 0 : _a.locals) || {}
|
|
81
|
+
},
|
|
82
|
+
redirection: {},
|
|
83
|
+
template,
|
|
84
|
+
loadableStats,
|
|
85
|
+
routeManifest,
|
|
86
|
+
entryName,
|
|
87
|
+
staticGenerate,
|
|
88
|
+
logger: void 0,
|
|
89
|
+
metrics: void 0,
|
|
90
|
+
req: ctx.req,
|
|
91
|
+
res: ctx.res
|
|
92
|
+
};
|
|
93
|
+
context.logger = (0, import_measure.createLogger)(context, ctx.logger);
|
|
94
|
+
context.metrics = (0, import_measure.createMetrics)(context, ctx.metrics);
|
|
95
|
+
runner.extendSSRContext(context);
|
|
96
|
+
const serverRender = require(bundleJS)[import_utils.SERVER_RENDER_FUNCTION_NAME];
|
|
97
|
+
const content = yield (0, import_cache.default)(serverRender, ctx)(context);
|
|
98
|
+
const { url, status = 302 } = context.redirection;
|
|
99
|
+
if (url) {
|
|
100
|
+
return {
|
|
101
|
+
content: url,
|
|
102
|
+
contentType: "",
|
|
103
|
+
statusCode: status,
|
|
104
|
+
redirect: true
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (typeof content === "string") {
|
|
108
|
+
return {
|
|
109
|
+
content,
|
|
110
|
+
contentType: import_utils.mime.contentType("html")
|
|
111
|
+
};
|
|
112
|
+
} else {
|
|
113
|
+
return {
|
|
114
|
+
content: "",
|
|
115
|
+
contentStream: content,
|
|
116
|
+
contentType: import_utils.mime.contentType("html")
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
render
|
|
123
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var static_exports = {};
|
|
45
|
+
__export(static_exports, {
|
|
46
|
+
handleDirectory: () => handleDirectory
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(static_exports);
|
|
49
|
+
var import_path = __toESM(require("path"));
|
|
50
|
+
var import_utils = require("@modern-js/utils");
|
|
51
|
+
var import_reader = require("./reader");
|
|
52
|
+
function handleDirectory(ctx, entryPath, urlPath) {
|
|
53
|
+
return __async(this, null, function* () {
|
|
54
|
+
const { path: pathname } = ctx;
|
|
55
|
+
const filepath = import_path.default.join(entryPath, trimLeft(pathname, urlPath));
|
|
56
|
+
let content = yield (0, import_reader.readFile)(filepath);
|
|
57
|
+
let contentType = import_utils.mime.contentType(import_path.default.extname(filepath) || "");
|
|
58
|
+
if (!content) {
|
|
59
|
+
if (pathname.endsWith("/")) {
|
|
60
|
+
content = yield (0, import_reader.readFile)(`${filepath}index.html`);
|
|
61
|
+
} else if (!pathname.includes(".")) {
|
|
62
|
+
content = yield (0, import_reader.readFile)(`${filepath}.html`);
|
|
63
|
+
if (!content) {
|
|
64
|
+
content = yield (0, import_reader.readFile)(`${filepath}/index.html`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (content) {
|
|
68
|
+
contentType = import_utils.mime.contentType("html");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!content) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
content,
|
|
76
|
+
contentType: contentType || ""
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const trimLeft = (str, prefix) => {
|
|
81
|
+
if (str.startsWith(prefix)) {
|
|
82
|
+
return str.substring(prefix.length);
|
|
83
|
+
}
|
|
84
|
+
return str;
|
|
85
|
+
};
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
handleDirectory
|
|
89
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var type_exports = {};
|
|
19
|
+
__export(type_exports, {
|
|
20
|
+
RenderLevel: () => RenderLevel
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(type_exports);
|
|
23
|
+
var RenderLevel = /* @__PURE__ */ ((RenderLevel2) => {
|
|
24
|
+
RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
25
|
+
RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
26
|
+
RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
27
|
+
return RenderLevel2;
|
|
28
|
+
})(RenderLevel || {});
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
RenderLevel
|
|
32
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var route_exports = {};
|
|
19
|
+
__export(route_exports, {
|
|
20
|
+
RouteMatchManager: () => RouteMatchManager,
|
|
21
|
+
RouteMatcher: () => import_matcher.RouteMatcher
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(route_exports);
|
|
24
|
+
var import_matcher = require("./matcher");
|
|
25
|
+
class RouteMatchManager {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.specs = [];
|
|
28
|
+
this.matchers = [];
|
|
29
|
+
}
|
|
30
|
+
filter(pathname) {
|
|
31
|
+
return this.matchers.reduce((matches, matcher) => {
|
|
32
|
+
if (matcher.matchUrlPath(pathname)) {
|
|
33
|
+
matches.push(matcher);
|
|
34
|
+
}
|
|
35
|
+
return matches;
|
|
36
|
+
}, []);
|
|
37
|
+
}
|
|
38
|
+
best(pathname, matches) {
|
|
39
|
+
let best;
|
|
40
|
+
let matchedLen = 0;
|
|
41
|
+
for (const match of matches) {
|
|
42
|
+
const len = match.matchLength(pathname);
|
|
43
|
+
if (len === null) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (len > matchedLen) {
|
|
47
|
+
best = match;
|
|
48
|
+
matchedLen = len;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
reset(specs) {
|
|
54
|
+
this.specs = specs;
|
|
55
|
+
const matchers = specs.reduce((ms, spec) => {
|
|
56
|
+
ms.push(new import_matcher.RouteMatcher(spec));
|
|
57
|
+
return ms;
|
|
58
|
+
}, []);
|
|
59
|
+
this.matchers = matchers;
|
|
60
|
+
}
|
|
61
|
+
match(pathname) {
|
|
62
|
+
const matches = this.filter(pathname);
|
|
63
|
+
const best = this.best(pathname, matches);
|
|
64
|
+
return best;
|
|
65
|
+
}
|
|
66
|
+
matchEntry(entryname) {
|
|
67
|
+
return this.matchers.find((matcher) => matcher.matchEntry(entryname));
|
|
68
|
+
}
|
|
69
|
+
getBundles() {
|
|
70
|
+
const bundles = this.specs.filter((route) => route.isSSR).map((route) => route.bundle);
|
|
71
|
+
return bundles;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
RouteMatchManager,
|
|
77
|
+
RouteMatcher
|
|
78
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var matcher_exports = {};
|
|
19
|
+
__export(matcher_exports, {
|
|
20
|
+
RouteMatcher: () => RouteMatcher
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(matcher_exports);
|
|
23
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
24
|
+
var import_route = require("./route");
|
|
25
|
+
const removeTailSlash = (s) => s.replace(/\/+$/, "");
|
|
26
|
+
const removeHtmlSuffix = (url) => {
|
|
27
|
+
if (url.endsWith(".html")) {
|
|
28
|
+
return url.slice(0, -5);
|
|
29
|
+
}
|
|
30
|
+
return url;
|
|
31
|
+
};
|
|
32
|
+
const toPath = (reg, params) => {
|
|
33
|
+
const fn = (0, import_path_to_regexp.compile)(reg, { encode: encodeURIComponent });
|
|
34
|
+
return fn(params);
|
|
35
|
+
};
|
|
36
|
+
const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
37
|
+
class RouteMatcher {
|
|
38
|
+
constructor(spec) {
|
|
39
|
+
this.urlPath = "";
|
|
40
|
+
this.spec = spec;
|
|
41
|
+
this.setupUrlPath();
|
|
42
|
+
}
|
|
43
|
+
generate(url) {
|
|
44
|
+
const route = new import_route.ModernRoute(this.spec);
|
|
45
|
+
if (this.urlPath) {
|
|
46
|
+
const params = this.parseURLParams(url);
|
|
47
|
+
route.urlPath = toPath(route.urlPath, params);
|
|
48
|
+
route.params = params;
|
|
49
|
+
}
|
|
50
|
+
return route;
|
|
51
|
+
}
|
|
52
|
+
parseURLParams(pathname) {
|
|
53
|
+
if (!this.urlMatcher) {
|
|
54
|
+
return {};
|
|
55
|
+
} else {
|
|
56
|
+
const matchResult = this.urlMatcher(pathname);
|
|
57
|
+
return matchResult.params;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
matchLength(pathname) {
|
|
61
|
+
var _a;
|
|
62
|
+
if (!this.urlReg) {
|
|
63
|
+
return this.urlPath.length;
|
|
64
|
+
} else {
|
|
65
|
+
const result = this.urlReg.exec(pathname);
|
|
66
|
+
return ((_a = result == null ? void 0 : result[0]) == null ? void 0 : _a.length) || null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
matchUrlPath(requestUrl) {
|
|
70
|
+
let urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
|
|
71
|
+
urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
|
|
72
|
+
if (this.urlMatcher) {
|
|
73
|
+
return Boolean(this.urlMatcher(urlWithoutSlash));
|
|
74
|
+
} else {
|
|
75
|
+
const urlPath = removeHtmlSuffix(this.urlPath);
|
|
76
|
+
if (urlWithoutSlash.startsWith(urlPath)) {
|
|
77
|
+
if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith(`${urlPath}/`)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
matchEntry(entryName) {
|
|
86
|
+
return this.spec.entryName === entryName;
|
|
87
|
+
}
|
|
88
|
+
setupUrlPath() {
|
|
89
|
+
const { urlPath } = this.spec;
|
|
90
|
+
this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
|
|
91
|
+
const useReg = regCharsDetector.test(urlPath);
|
|
92
|
+
if (useReg) {
|
|
93
|
+
this.urlMatcher = (0, import_path_to_regexp.match)(urlPath, {
|
|
94
|
+
end: false,
|
|
95
|
+
decode: decodeURIComponent
|
|
96
|
+
});
|
|
97
|
+
this.urlReg = (0, import_path_to_regexp.pathToRegexp)(urlPath, [], {
|
|
98
|
+
end: false
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
RouteMatcher
|
|
106
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var route_exports = {};
|
|
19
|
+
__export(route_exports, {
|
|
20
|
+
ModernRoute: () => ModernRoute
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(route_exports);
|
|
23
|
+
class ModernRoute {
|
|
24
|
+
constructor(routeSpec) {
|
|
25
|
+
this.params = {};
|
|
26
|
+
this.entryName = routeSpec.entryName || "";
|
|
27
|
+
this.urlPath = routeSpec.urlPath;
|
|
28
|
+
this.entryPath = routeSpec.entryPath || "";
|
|
29
|
+
this.isSSR = routeSpec.isSSR || false;
|
|
30
|
+
this.isSPA = routeSpec.isSPA || false;
|
|
31
|
+
this.isApi = routeSpec.isApi || false;
|
|
32
|
+
this.bundle = routeSpec.bundle || "";
|
|
33
|
+
this.responseHeaders = routeSpec.responseHeaders;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
ModernRoute
|
|
39
|
+
});
|