@modern-js/prod-server 2.0.0-beta.2 → 2.0.0-beta.4
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/CHANGELOG.md +132 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +42 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +144 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +377 -419
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +45 -30
- package/dist/js/node/index.js +31 -57
- package/dist/js/node/libs/context/context.js +79 -94
- package/dist/js/node/libs/context/index.js +23 -13
- package/dist/js/node/libs/hook-api/index.js +69 -48
- package/dist/js/node/libs/hook-api/route.js +22 -11
- package/dist/js/node/libs/hook-api/template.js +36 -39
- package/dist/js/node/libs/loadConfig.js +69 -35
- package/dist/js/node/libs/metrics.js +21 -9
- package/dist/js/node/libs/proxy.js +86 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +50 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
- package/dist/js/node/libs/render/cache/spr.js +156 -129
- package/dist/js/node/libs/render/cache/type.js +0 -5
- package/dist/js/node/libs/render/cache/util.js +88 -45
- package/dist/js/node/libs/render/index.js +102 -67
- package/dist/js/node/libs/render/measure.js +55 -31
- package/dist/js/node/libs/render/reader.js +87 -70
- package/dist/js/node/libs/render/ssr.js +76 -47
- package/dist/js/node/libs/render/static.js +75 -40
- package/dist/js/node/libs/render/type.js +27 -12
- package/dist/js/node/libs/route/index.js +26 -26
- package/dist/js/node/libs/route/matcher.js +36 -41
- package/dist/js/node/libs/route/route.js +25 -22
- package/dist/js/node/libs/serve-file.js +61 -32
- package/dist/js/node/server/index.js +160 -160
- package/dist/js/node/server/modern-server-split.js +68 -22
- package/dist/js/node/server/modern-server.js +395 -443
- package/dist/js/node/type.js +0 -3
- package/dist/js/node/utils.js +74 -52
- package/dist/js/node/worker-server.js +53 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +265 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +468 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1046 -911
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,69 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
createProxyHandler: () => createProxyHandler,
|
|
21
|
+
formatProxyOptions: () => formatProxyOptions
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
24
|
+
var import_http_proxy_middleware = require("http-proxy-middleware");
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
var __defProp2 = Object.defineProperty;
|
|
27
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
28
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
29
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
30
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
31
|
+
var __spreadValues = (a, b) => {
|
|
32
|
+
for (var prop in b || (b = {}))
|
|
33
|
+
if (__hasOwnProp2.call(b, prop))
|
|
34
|
+
__defNormalProp(a, prop, b[prop]);
|
|
35
|
+
if (__getOwnPropSymbols)
|
|
36
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
37
|
+
if (__propIsEnum.call(b, prop))
|
|
38
|
+
__defNormalProp(a, prop, b[prop]);
|
|
39
|
+
}
|
|
40
|
+
return a;
|
|
41
|
+
};
|
|
42
|
+
var __async = (__this, __arguments, generator) => {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
var fulfilled = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.next(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var rejected = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.throw(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
+
});
|
|
61
|
+
};
|
|
13
62
|
function formatProxyOptions(proxyOptions) {
|
|
14
63
|
const formattedProxy = [];
|
|
15
64
|
if (!Array.isArray(proxyOptions)) {
|
|
16
|
-
if (
|
|
65
|
+
if ("target" in proxyOptions) {
|
|
17
66
|
formattedProxy.push(proxyOptions);
|
|
18
67
|
} else {
|
|
19
|
-
Array.prototype.push.apply(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
68
|
+
Array.prototype.push.apply(
|
|
69
|
+
formattedProxy,
|
|
70
|
+
Object.keys(proxyOptions).reduce(
|
|
71
|
+
(total, source) => {
|
|
72
|
+
const option = proxyOptions[source];
|
|
73
|
+
total.push(__spreadValues({
|
|
74
|
+
context: source,
|
|
75
|
+
changeOrigin: true,
|
|
76
|
+
logLevel: "warn"
|
|
77
|
+
}, typeof option === "string" ? { target: option } : option));
|
|
78
|
+
return total;
|
|
79
|
+
},
|
|
80
|
+
[]
|
|
81
|
+
)
|
|
82
|
+
);
|
|
30
83
|
}
|
|
31
84
|
} else {
|
|
32
85
|
formattedProxy.push(...proxyOptions);
|
|
33
86
|
}
|
|
34
87
|
return formattedProxy;
|
|
35
88
|
}
|
|
36
|
-
const createProxyHandler = proxyOptions => {
|
|
37
|
-
(0,
|
|
89
|
+
const createProxyHandler = (proxyOptions) => {
|
|
90
|
+
(0, import_utils.debug)("createProxyHandler", proxyOptions);
|
|
38
91
|
if (!proxyOptions) {
|
|
39
92
|
return null;
|
|
40
93
|
}
|
|
41
|
-
|
|
42
|
-
// If it is not an array, it may be an object that uses the context attribute
|
|
43
|
-
// or an object in the form of { source: ProxyDetail }
|
|
44
94
|
const formattedProxy = formatProxyOptions(proxyOptions);
|
|
45
|
-
const middlewares = formattedProxy.map(option => {
|
|
46
|
-
const middleware = (0,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
req,
|
|
52
|
-
res
|
|
53
|
-
} = ctx;
|
|
54
|
-
const bypassUrl = typeof option.bypass === 'function' ? option.bypass(req, res, option) : null;
|
|
55
|
-
|
|
56
|
-
// only false, no true
|
|
57
|
-
if (typeof bypassUrl === 'boolean') {
|
|
95
|
+
const middlewares = formattedProxy.map((option) => {
|
|
96
|
+
const middleware = (0, import_http_proxy_middleware.createProxyMiddleware)(option.context, option);
|
|
97
|
+
return (ctx, next) => __async(void 0, null, function* () {
|
|
98
|
+
const { req, res } = ctx;
|
|
99
|
+
const bypassUrl = typeof option.bypass === "function" ? option.bypass(req, res, option) : null;
|
|
100
|
+
if (typeof bypassUrl === "boolean") {
|
|
58
101
|
ctx.status = 404;
|
|
59
102
|
return next();
|
|
60
|
-
} else if (typeof bypassUrl ===
|
|
103
|
+
} else if (typeof bypassUrl === "string") {
|
|
61
104
|
ctx.url = bypassUrl;
|
|
62
105
|
return next();
|
|
63
106
|
}
|
|
64
107
|
middleware(req, res, next);
|
|
65
|
-
};
|
|
108
|
+
});
|
|
66
109
|
});
|
|
67
110
|
return middlewares;
|
|
68
111
|
};
|
|
69
|
-
exports.createProxyHandler = createProxyHandler;
|
|
@@ -1,72 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => stdin_default
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_url = __toESM(require("url"));
|
|
30
|
+
var import_spr = require("../spr");
|
|
31
|
+
var import_util = require("../util");
|
|
32
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
33
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
34
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
35
|
+
};
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
29
44
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const htmlWithHead = (0, _util.cacheAddition)(contentWithHead, hash);
|
|
40
|
-
expect(htmlWithHead).toBe(`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`);
|
|
41
|
-
});
|
|
42
|
-
it('should only invoke func one time', async () => {
|
|
43
|
-
let index = 0;
|
|
44
|
-
const fn = (0, _util.withCoalescedInvoke)(async () => new Promise(resolve => {
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
index += 1;
|
|
47
|
-
resolve(index);
|
|
48
|
-
}, 500);
|
|
49
|
-
}));
|
|
50
|
-
const key = 'test';
|
|
51
|
-
const [res1, res2] = await Promise.all([fn(key, []), fn(key, [])]);
|
|
52
|
-
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
53
|
-
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
54
|
-
expect(res1.value).toBe(1);
|
|
55
|
-
expect(res2.value).toBe(1);
|
|
56
|
-
});
|
|
57
|
-
it('should invoke sync or async', async () => {
|
|
58
|
-
const foo = '';
|
|
59
|
-
const async = await (0, _util.maybeSync)(() => new Promise(resolve => {
|
|
60
|
-
setTimeout(() => {
|
|
61
|
-
resolve(foo);
|
|
62
|
-
}, 100);
|
|
63
|
-
}))(false);
|
|
64
|
-
expect(async).toBeUndefined();
|
|
65
|
-
const sync = await (0, _util.maybeSync)(() => new Promise(resolve => {
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
resolve(foo);
|
|
68
|
-
}, 100);
|
|
69
|
-
}))(true);
|
|
70
|
-
expect(sync).toBe(foo);
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
71
54
|
});
|
|
72
|
-
}
|
|
55
|
+
};
|
|
56
|
+
var require_cache_fun_test = __commonJS({
|
|
57
|
+
"src/libs/render/cache/__tests__/cache.fun.test.ts"(exports) {
|
|
58
|
+
describe("test spr util functions", () => {
|
|
59
|
+
it("should return value correctly", () => {
|
|
60
|
+
expect((0, import_util.connectFactor)("bar", "foo")).toBe("bar-foo");
|
|
61
|
+
expect((0, import_util.fname)(1)).toBe("f1");
|
|
62
|
+
expect((0, import_util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
|
|
63
|
+
});
|
|
64
|
+
it("should create or destroy instance correctly", () => {
|
|
65
|
+
const ins1 = (0, import_spr.createCache)();
|
|
66
|
+
const ins2 = (0, import_spr.createCache)();
|
|
67
|
+
expect(ins1 === ins2).toBe(true);
|
|
68
|
+
(0, import_spr.destroyCache)();
|
|
69
|
+
const ins3 = (0, import_spr.createCache)();
|
|
70
|
+
expect(ins1 === ins3).toBe(false);
|
|
71
|
+
expect(ins2 === ins3).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
it("should return function correctly", () => {
|
|
74
|
+
const urlParams = (() => new import_url.default.URLSearchParams())();
|
|
75
|
+
urlParams.set("name", "modern");
|
|
76
|
+
const getParam = (0, import_util.valueFactory)(urlParams);
|
|
77
|
+
expect(getParam("name")).toBe("modern");
|
|
78
|
+
const headers = { age: "12345" };
|
|
79
|
+
const getHeader = (0, import_util.valueFactory)(headers);
|
|
80
|
+
expect(getHeader("age")).toBe("12345");
|
|
81
|
+
});
|
|
82
|
+
it("should add target html content", () => {
|
|
83
|
+
const contentNoHead = "<div>123</div>";
|
|
84
|
+
const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
|
|
85
|
+
expect(html).toBe(contentNoHead);
|
|
86
|
+
const contentWithHead = "<head></head><div>123</div>";
|
|
87
|
+
const hash = Math.random().toString();
|
|
88
|
+
const htmlWithHead = (0, import_util.cacheAddition)(contentWithHead, hash);
|
|
89
|
+
expect(htmlWithHead).toBe(
|
|
90
|
+
`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
it("should only invoke func one time", () => __async(exports, null, function* () {
|
|
94
|
+
let index = 0;
|
|
95
|
+
const fn = (0, import_util.withCoalescedInvoke)(
|
|
96
|
+
() => __async(exports, null, function* () {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
index += 1;
|
|
100
|
+
resolve(index);
|
|
101
|
+
}, 500);
|
|
102
|
+
});
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
const key = "test";
|
|
106
|
+
const [res1, res2] = yield Promise.all([fn(key, []), fn(key, [])]);
|
|
107
|
+
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
108
|
+
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
109
|
+
expect(res1.value).toBe(1);
|
|
110
|
+
expect(res2.value).toBe(1);
|
|
111
|
+
}));
|
|
112
|
+
it("should invoke sync or async", () => __async(exports, null, function* () {
|
|
113
|
+
const foo = "";
|
|
114
|
+
const async = yield (0, import_util.maybeSync)(
|
|
115
|
+
() => new Promise((resolve) => {
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
resolve(foo);
|
|
118
|
+
}, 100);
|
|
119
|
+
})
|
|
120
|
+
)(false);
|
|
121
|
+
expect(async).toBeUndefined();
|
|
122
|
+
const sync = yield (0, import_util.maybeSync)(
|
|
123
|
+
() => new Promise((resolve) => {
|
|
124
|
+
setTimeout(() => {
|
|
125
|
+
resolve(foo);
|
|
126
|
+
}, 100);
|
|
127
|
+
})
|
|
128
|
+
)(true);
|
|
129
|
+
expect(sync).toBe(foo);
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
var stdin_default = require_cache_fun_test();
|