@modern-js/plugin-polyfill 2.14.0 → 2.16.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/CHANGELOG.md +19 -0
- package/dist/cjs/cli.js +17 -30
- package/dist/cjs/const.js +16 -25
- package/dist/cjs/index.js +69 -51
- package/dist/cjs/libs/cache.js +40 -43
- package/dist/cjs/type.js +4 -15
- package/dist/esm/cli.js +29 -29
- package/dist/esm/const.js +9 -10
- package/dist/esm/index.js +194 -187
- package/dist/esm/libs/cache.js +67 -64
- package/dist/esm/type.js +1 -1
- package/dist/esm-node/cli.js +9 -9
- package/dist/esm-node/const.js +7 -7
- package/dist/esm-node/index.js +5 -9
- package/dist/esm-node/libs/cache.js +22 -11
- package/dist/esm-node/type.js +1 -0
- package/package.json +13 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/plugin-polyfill
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5954330]
|
|
12
|
+
- Updated dependencies [7596520]
|
|
13
|
+
- Updated dependencies [4e876ab]
|
|
14
|
+
- @modern-js/utils@2.16.0
|
|
15
|
+
|
|
16
|
+
## 2.15.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- @modern-js/utils@2.15.0
|
|
21
|
+
|
|
3
22
|
## 2.14.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 cli_exports = {};
|
|
19
|
-
__export(cli_exports, {
|
|
20
|
-
default: () => cli_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
8
|
+
});
|
|
9
|
+
const _const = require("./const");
|
|
10
|
+
const _default = () => ({
|
|
25
11
|
name: "@modern-js/plugin-polyfill",
|
|
26
12
|
setup: (api) => ({
|
|
27
13
|
htmlPartials({ entrypoint, partials }) {
|
|
28
14
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
29
15
|
if (resolvedConfig.output.polyfill === "ua") {
|
|
30
|
-
partials.top.push(
|
|
31
|
-
`<script src="${import_const.defaultPolyfill}" crossorigin></script>`
|
|
32
|
-
);
|
|
16
|
+
partials.top.push(`<script src="${_const.defaultPolyfill}" crossorigin></script>`);
|
|
33
17
|
}
|
|
34
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
partials,
|
|
20
|
+
entrypoint
|
|
21
|
+
};
|
|
35
22
|
},
|
|
36
23
|
collectServerPlugins({ plugins }) {
|
|
37
24
|
plugins.push({
|
|
38
25
|
"@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/server"
|
|
39
26
|
});
|
|
40
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
plugins
|
|
29
|
+
};
|
|
41
30
|
}
|
|
42
31
|
})
|
|
43
32
|
});
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {});
|
package/dist/cjs/const.js
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 const_exports = {};
|
|
19
|
-
__export(const_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
defaultPolyfill: () => defaultPolyfill,
|
|
21
14
|
getDefaultFeatures: () => getDefaultFeatures
|
|
22
15
|
});
|
|
23
|
-
module.exports = __toCommonJS(const_exports);
|
|
24
16
|
const defaultPolyfill = "/__polyfill__";
|
|
25
17
|
const getDefaultFeatures = () => ({
|
|
26
|
-
es6: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getDefaultFeatures
|
|
18
|
+
es6: {
|
|
19
|
+
flags: [
|
|
20
|
+
"gated"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
32
23
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,50 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var src_exports = {};
|
|
29
|
-
__export(src_exports, {
|
|
30
|
-
default: () => src_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
9
|
+
const _polyfilllib = require("@modern-js/polyfill-lib");
|
|
10
|
+
const _utils = require("@modern-js/utils");
|
|
11
|
+
const _uaparserjs = /* @__PURE__ */ _interop_require_default(require("ua-parser-js"));
|
|
12
|
+
const _const = require("./const");
|
|
13
|
+
const _cache = /* @__PURE__ */ _interop_require_wildcard(require("./libs/cache"));
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function")
|
|
21
|
+
return null;
|
|
22
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
23
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
25
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
26
|
+
})(nodeInterop);
|
|
27
|
+
}
|
|
28
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
29
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
33
|
+
return {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
38
|
+
if (cache && cache.has(obj)) {
|
|
39
|
+
return cache.get(obj);
|
|
40
|
+
}
|
|
41
|
+
var newObj = {};
|
|
42
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
|
+
for (var key in obj) {
|
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
46
|
+
if (desc && (desc.get || desc.set)) {
|
|
47
|
+
Object.defineProperty(newObj, key, desc);
|
|
48
|
+
} else {
|
|
49
|
+
newObj[key] = obj[key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
newObj.default = obj;
|
|
54
|
+
if (cache) {
|
|
55
|
+
cache.set(obj, newObj);
|
|
56
|
+
}
|
|
57
|
+
return newObj;
|
|
58
|
+
}
|
|
59
|
+
const _default = () => ({
|
|
39
60
|
name: "@modern-js/plugin-polyfill",
|
|
40
61
|
setup: () => ({
|
|
41
62
|
beforeProdServer() {
|
|
42
|
-
const cache = new
|
|
43
|
-
const route =
|
|
44
|
-
const features = (0,
|
|
63
|
+
const cache = new _cache.default();
|
|
64
|
+
const route = _const.defaultPolyfill;
|
|
65
|
+
const features = (0, _const.getDefaultFeatures)();
|
|
45
66
|
const minify = process.env.NODE_ENV === "production";
|
|
46
67
|
const featureDig = Object.keys(features).map((name) => {
|
|
47
|
-
const { flags = [
|
|
68
|
+
const { flags = [
|
|
69
|
+
"gated"
|
|
70
|
+
] } = features[name];
|
|
48
71
|
const flagStr = flags.join(",");
|
|
49
72
|
return `${name}-${flagStr}`;
|
|
50
73
|
}).join(",");
|
|
@@ -52,9 +75,9 @@ var src_default = () => ({
|
|
|
52
75
|
if (context.url !== route) {
|
|
53
76
|
return next();
|
|
54
77
|
}
|
|
55
|
-
const parsedUA = (0,
|
|
78
|
+
const parsedUA = (0, _uaparserjs.default)(context.headers["user-agent"]);
|
|
56
79
|
const { name = "", version = "" } = parsedUA.browser;
|
|
57
|
-
const cacheKey = (0,
|
|
80
|
+
const cacheKey = (0, _cache.generateCacheKey)({
|
|
58
81
|
name,
|
|
59
82
|
version,
|
|
60
83
|
features: featureDig,
|
|
@@ -62,23 +85,18 @@ var src_default = () => ({
|
|
|
62
85
|
});
|
|
63
86
|
const matched = cache.get(cacheKey);
|
|
64
87
|
if (matched) {
|
|
65
|
-
context.res.setHeader(
|
|
66
|
-
"content-type",
|
|
67
|
-
import_utils.mime.contentType("js")
|
|
68
|
-
);
|
|
88
|
+
context.res.setHeader("content-type", _utils.mime.contentType("js"));
|
|
69
89
|
return context.res.end(matched);
|
|
70
90
|
}
|
|
71
|
-
const polyfill = await (0,
|
|
91
|
+
const polyfill = await (0, _polyfilllib.getPolyfillString)({
|
|
72
92
|
uaString: context.headers["user-agent"],
|
|
73
93
|
minify,
|
|
74
94
|
features
|
|
75
95
|
});
|
|
76
96
|
cache.set(cacheKey, polyfill);
|
|
77
|
-
context.res.setHeader("content-type",
|
|
97
|
+
context.res.setHeader("content-type", _utils.mime.contentType("js"));
|
|
78
98
|
return context.res.end(polyfill);
|
|
79
99
|
};
|
|
80
100
|
}
|
|
81
101
|
})
|
|
82
102
|
});
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {});
|
package/dist/cjs/libs/cache.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var cache_exports = {};
|
|
29
|
-
__export(cache_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
30
13
|
default: () => Cache,
|
|
31
14
|
generateCacheKey: () => generateCacheKey
|
|
32
15
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
const _crypto = /* @__PURE__ */ _interop_require_default(require("crypto"));
|
|
17
|
+
const _lrucache = /* @__PURE__ */ _interop_require_default(require("lru-cache"));
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
36
|
const KB = 1024;
|
|
37
37
|
const MB = 1024 * KB;
|
|
38
|
-
const keyCache = new
|
|
38
|
+
const keyCache = new _lrucache.default(1e4);
|
|
39
39
|
const generateCacheKey = (options) => {
|
|
40
40
|
const { name, version, features, minify } = options;
|
|
41
41
|
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
@@ -43,25 +43,22 @@ const generateCacheKey = (options) => {
|
|
|
43
43
|
if (matched) {
|
|
44
44
|
return matched;
|
|
45
45
|
}
|
|
46
|
-
const hash =
|
|
46
|
+
const hash = _crypto.default.createHmac("sha256", "^polyfill$").update(str).digest("hex");
|
|
47
47
|
keyCache.set(str, hash);
|
|
48
48
|
return hash;
|
|
49
49
|
};
|
|
50
50
|
class Cache {
|
|
51
|
-
constructor() {
|
|
52
|
-
this.caches = new import_lru_cache.default({
|
|
53
|
-
max: 200 * MB,
|
|
54
|
-
length: (v) => v.length
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
51
|
get(hash) {
|
|
58
52
|
return this.caches.get(hash);
|
|
59
53
|
}
|
|
60
54
|
set(hash, content) {
|
|
61
55
|
this.caches.set(hash, content);
|
|
62
56
|
}
|
|
57
|
+
constructor() {
|
|
58
|
+
_define_property(this, "caches", void 0);
|
|
59
|
+
this.caches = new _lrucache.default({
|
|
60
|
+
max: 200 * MB,
|
|
61
|
+
length: (v) => v.length
|
|
62
|
+
});
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
-
0 && (module.exports = {
|
|
66
|
-
generateCacheKey
|
|
67
|
-
});
|
package/dist/cjs/type.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var type_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(type_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { defaultPolyfill } from "./const";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
};
|
|
2
|
+
export default function() {
|
|
3
|
+
return {
|
|
4
|
+
name: "@modern-js/plugin-polyfill",
|
|
5
|
+
setup: function(api) {
|
|
6
|
+
return {
|
|
7
|
+
htmlPartials: function htmlPartials(param) {
|
|
8
|
+
var entrypoint = param.entrypoint, partials = param.partials;
|
|
9
|
+
var resolvedConfig = api.useResolvedConfigContext();
|
|
10
|
+
if (resolvedConfig.output.polyfill === "ua") {
|
|
11
|
+
partials.top.push('<script src="'.concat(defaultPolyfill, '" crossorigin></script>'));
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
partials,
|
|
15
|
+
entrypoint
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
collectServerPlugins: function collectServerPlugins(param) {
|
|
19
|
+
var plugins = param.plugins;
|
|
20
|
+
plugins.push({
|
|
21
|
+
"@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/server"
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
plugins
|
|
25
|
+
};
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
;
|
package/dist/esm/const.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
var defaultPolyfill = "/__polyfill__";
|
|
2
|
-
var getDefaultFeatures = function() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export var defaultPolyfill = "/__polyfill__";
|
|
2
|
+
export var getDefaultFeatures = function() {
|
|
3
|
+
return {
|
|
4
|
+
es6: {
|
|
5
|
+
flags: [
|
|
6
|
+
"gated"
|
|
7
|
+
]
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
10
|
};
|
|
11
|
-
export { defaultPolyfill, getDefaultFeatures };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,203 +1,210 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
var __generator =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
var __generator = function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1)
|
|
35
|
+
throw t[1];
|
|
36
|
+
return t[1];
|
|
37
|
+
},
|
|
38
|
+
trys: [],
|
|
39
|
+
ops: []
|
|
40
|
+
};
|
|
41
|
+
return g = {
|
|
42
|
+
next: verb(0),
|
|
43
|
+
"throw": verb(1),
|
|
44
|
+
"return": verb(2)
|
|
45
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
46
|
+
return this;
|
|
47
|
+
}), g;
|
|
48
|
+
function verb(n) {
|
|
49
|
+
return function(v) {
|
|
50
|
+
return step([
|
|
51
|
+
n,
|
|
52
|
+
v
|
|
53
|
+
]);
|
|
39
54
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
break;
|
|
68
|
-
case 4:
|
|
69
|
-
_.label++;
|
|
70
|
-
return {
|
|
71
|
-
value: op[1],
|
|
72
|
-
done: false
|
|
73
|
-
};
|
|
74
|
-
case 5:
|
|
75
|
-
_.label++;
|
|
76
|
-
y = op[1];
|
|
77
|
-
op = [
|
|
78
|
-
0
|
|
79
|
-
];
|
|
80
|
-
continue;
|
|
81
|
-
case 7:
|
|
82
|
-
op = _.ops.pop();
|
|
83
|
-
_.trys.pop();
|
|
84
|
-
continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
-
_ = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
-
_.label = op[1];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
-
_.label = t[1];
|
|
96
|
-
t = op;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (t && _.label < t[2]) {
|
|
100
|
-
_.label = t[2];
|
|
101
|
-
_.ops.push(op);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
if (t[2]) _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
op = body.call(thisArg, _);
|
|
109
|
-
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f)
|
|
58
|
+
throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (_)
|
|
60
|
+
try {
|
|
61
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
62
|
+
return t;
|
|
63
|
+
if (y = 0, t)
|
|
64
|
+
op = [
|
|
65
|
+
op[0] & 2,
|
|
66
|
+
t.value
|
|
67
|
+
];
|
|
68
|
+
switch (op[0]) {
|
|
69
|
+
case 0:
|
|
70
|
+
case 1:
|
|
71
|
+
t = op;
|
|
72
|
+
break;
|
|
73
|
+
case 4:
|
|
74
|
+
_.label++;
|
|
75
|
+
return {
|
|
76
|
+
value: op[1],
|
|
77
|
+
done: false
|
|
78
|
+
};
|
|
79
|
+
case 5:
|
|
80
|
+
_.label++;
|
|
81
|
+
y = op[1];
|
|
110
82
|
op = [
|
|
111
|
-
|
|
112
|
-
e
|
|
83
|
+
0
|
|
113
84
|
];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
85
|
+
continue;
|
|
86
|
+
case 7:
|
|
87
|
+
op = _.ops.pop();
|
|
88
|
+
_.trys.pop();
|
|
89
|
+
continue;
|
|
90
|
+
default:
|
|
91
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
92
|
+
_ = 0;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
96
|
+
_.label = op[1];
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
100
|
+
_.label = t[1];
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t && _.label < t[2]) {
|
|
105
|
+
_.label = t[2];
|
|
106
|
+
_.ops.push(op);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (t[2])
|
|
110
|
+
_.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
op = body.call(thisArg, _);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
op = [
|
|
117
|
+
6,
|
|
118
|
+
e
|
|
119
|
+
];
|
|
120
|
+
y = 0;
|
|
121
|
+
} finally {
|
|
122
|
+
f = t = 0;
|
|
123
|
+
}
|
|
124
|
+
if (op[0] & 5)
|
|
125
|
+
throw op[1];
|
|
126
|
+
return {
|
|
127
|
+
value: op[0] ? op[1] : void 0,
|
|
128
|
+
done: true
|
|
129
|
+
};
|
|
130
|
+
}
|
|
124
131
|
};
|
|
125
132
|
import { getPolyfillString } from "@modern-js/polyfill-lib";
|
|
126
133
|
import { mime } from "@modern-js/utils";
|
|
127
134
|
import Parser from "ua-parser-js";
|
|
128
135
|
import { getDefaultFeatures, defaultPolyfill } from "./const";
|
|
129
136
|
import PolyfillCache, { generateCacheKey } from "./libs/cache";
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
return function(context, next) {
|
|
195
|
-
return _ref.apply(this, arguments);
|
|
196
|
-
};
|
|
197
|
-
}();
|
|
137
|
+
export default function() {
|
|
138
|
+
return {
|
|
139
|
+
name: "@modern-js/plugin-polyfill",
|
|
140
|
+
setup: function() {
|
|
141
|
+
return {
|
|
142
|
+
beforeProdServer: function beforeProdServer() {
|
|
143
|
+
var cache = new PolyfillCache();
|
|
144
|
+
var route = defaultPolyfill;
|
|
145
|
+
var features = getDefaultFeatures();
|
|
146
|
+
var minify = process.env.NODE_ENV === "production";
|
|
147
|
+
var featureDig = Object.keys(features).map(function(name) {
|
|
148
|
+
var _features_name = features[name], _features_name_flags = _features_name.flags, flags = _features_name_flags === void 0 ? [
|
|
149
|
+
"gated"
|
|
150
|
+
] : _features_name_flags;
|
|
151
|
+
var flagStr = flags.join(",");
|
|
152
|
+
return "".concat(name, "-").concat(flagStr);
|
|
153
|
+
}).join(",");
|
|
154
|
+
return function() {
|
|
155
|
+
var _ref = _async_to_generator(function(context, next) {
|
|
156
|
+
var parsedUA, _parsedUA_browser, _parsedUA_browser_name, name, _parsedUA_browser_version, version, cacheKey, matched, polyfill;
|
|
157
|
+
return __generator(this, function(_state) {
|
|
158
|
+
switch (_state.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
if (context.url !== route) {
|
|
161
|
+
return [
|
|
162
|
+
2,
|
|
163
|
+
next()
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
parsedUA = Parser(context.headers["user-agent"]);
|
|
167
|
+
_parsedUA_browser = parsedUA.browser, _parsedUA_browser_name = _parsedUA_browser.name, name = _parsedUA_browser_name === void 0 ? "" : _parsedUA_browser_name, _parsedUA_browser_version = _parsedUA_browser.version, version = _parsedUA_browser_version === void 0 ? "" : _parsedUA_browser_version;
|
|
168
|
+
cacheKey = generateCacheKey({
|
|
169
|
+
name,
|
|
170
|
+
version,
|
|
171
|
+
features: featureDig,
|
|
172
|
+
minify
|
|
173
|
+
});
|
|
174
|
+
matched = cache.get(cacheKey);
|
|
175
|
+
if (matched) {
|
|
176
|
+
context.res.setHeader("content-type", mime.contentType("js"));
|
|
177
|
+
return [
|
|
178
|
+
2,
|
|
179
|
+
context.res.end(matched)
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
return [
|
|
183
|
+
4,
|
|
184
|
+
getPolyfillString({
|
|
185
|
+
uaString: context.headers["user-agent"],
|
|
186
|
+
minify,
|
|
187
|
+
features
|
|
188
|
+
})
|
|
189
|
+
];
|
|
190
|
+
case 1:
|
|
191
|
+
polyfill = _state.sent();
|
|
192
|
+
cache.set(cacheKey, polyfill);
|
|
193
|
+
context.res.setHeader("content-type", mime.contentType("js"));
|
|
194
|
+
return [
|
|
195
|
+
2,
|
|
196
|
+
context.res.end(polyfill)
|
|
197
|
+
];
|
|
198
198
|
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return function(context, next) {
|
|
202
|
+
return _ref.apply(this, arguments);
|
|
199
203
|
};
|
|
204
|
+
}();
|
|
200
205
|
}
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
;
|
package/dist/esm/libs/cache.js
CHANGED
|
@@ -1,77 +1,80 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
6
|
function _defineProperties(target, props) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
for (var i = 0; i < props.length; i++) {
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor)
|
|
12
|
+
descriptor.writable = true;
|
|
13
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
17
|
+
if (protoProps)
|
|
18
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
19
|
+
if (staticProps)
|
|
20
|
+
_defineProperties(Constructor, staticProps);
|
|
21
|
+
return Constructor;
|
|
19
22
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
function _define_property(obj, key, value) {
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
32
35
|
}
|
|
33
36
|
import crypto from "crypto";
|
|
34
37
|
import LRUCache from "lru-cache";
|
|
35
38
|
var KB = 1024;
|
|
36
39
|
var MB = 1024 * KB;
|
|
37
40
|
var keyCache = new LRUCache(1e4);
|
|
38
|
-
var generateCacheKey = function(options) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
export var generateCacheKey = function(options) {
|
|
42
|
+
var name = options.name, version = options.version, features = options.features, minify = options.minify;
|
|
43
|
+
var str = "".concat(name, "-").concat(version, "-").concat(Number(minify), "-").concat(features);
|
|
44
|
+
var matched = keyCache.get(str);
|
|
45
|
+
if (matched) {
|
|
46
|
+
return matched;
|
|
47
|
+
}
|
|
48
|
+
var hash = crypto.createHmac("sha256", "^polyfill$").update(str).digest("hex");
|
|
49
|
+
keyCache.set(str, hash);
|
|
50
|
+
return hash;
|
|
48
51
|
};
|
|
49
|
-
var Cache =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
var Cache = /* @__PURE__ */ function() {
|
|
53
|
+
"use strict";
|
|
54
|
+
function Cache2() {
|
|
55
|
+
_class_call_check(this, Cache2);
|
|
56
|
+
_define_property(this, "caches", void 0);
|
|
57
|
+
this.caches = new LRUCache({
|
|
58
|
+
max: 200 * MB,
|
|
59
|
+
length: function(v) {
|
|
60
|
+
return v.length;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
_create_class(Cache2, [
|
|
65
|
+
{
|
|
66
|
+
key: "get",
|
|
67
|
+
value: function get(hash) {
|
|
68
|
+
return this.caches.get(hash);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
key: "set",
|
|
73
|
+
value: function set(hash, content) {
|
|
74
|
+
this.caches.set(hash, content);
|
|
75
|
+
}
|
|
60
76
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
key: "get",
|
|
64
|
-
value: function get(hash) {
|
|
65
|
-
return this.caches.get(hash);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
key: "set",
|
|
70
|
-
value: function set(hash, content) {
|
|
71
|
-
this.caches.set(hash, content);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
return Cache;
|
|
77
|
+
]);
|
|
78
|
+
return Cache2;
|
|
76
79
|
}();
|
|
77
|
-
export { Cache as default
|
|
80
|
+
export { Cache as default };
|
package/dist/esm/type.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/esm-node/cli.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { defaultPolyfill } from "./const";
|
|
2
|
-
|
|
2
|
+
export default () => ({
|
|
3
3
|
name: "@modern-js/plugin-polyfill",
|
|
4
4
|
setup: (api) => ({
|
|
5
5
|
htmlPartials({ entrypoint, partials }) {
|
|
6
6
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
7
7
|
if (resolvedConfig.output.polyfill === "ua") {
|
|
8
|
-
partials.top.push(
|
|
9
|
-
`<script src="${defaultPolyfill}" crossorigin></script>`
|
|
10
|
-
);
|
|
8
|
+
partials.top.push(`<script src="${defaultPolyfill}" crossorigin></script>`);
|
|
11
9
|
}
|
|
12
|
-
return {
|
|
10
|
+
return {
|
|
11
|
+
partials,
|
|
12
|
+
entrypoint
|
|
13
|
+
};
|
|
13
14
|
},
|
|
14
15
|
collectServerPlugins({ plugins }) {
|
|
15
16
|
plugins.push({
|
|
16
17
|
"@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/server"
|
|
17
18
|
});
|
|
18
|
-
return {
|
|
19
|
+
return {
|
|
20
|
+
plugins
|
|
21
|
+
};
|
|
19
22
|
}
|
|
20
23
|
})
|
|
21
24
|
});
|
|
22
|
-
export {
|
|
23
|
-
cli_default as default
|
|
24
|
-
};
|
package/dist/esm-node/const.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const defaultPolyfill = "/__polyfill__";
|
|
2
|
-
const getDefaultFeatures = () => ({
|
|
3
|
-
es6: {
|
|
1
|
+
export const defaultPolyfill = "/__polyfill__";
|
|
2
|
+
export const getDefaultFeatures = () => ({
|
|
3
|
+
es6: {
|
|
4
|
+
flags: [
|
|
5
|
+
"gated"
|
|
6
|
+
]
|
|
7
|
+
}
|
|
4
8
|
});
|
|
5
|
-
export {
|
|
6
|
-
defaultPolyfill,
|
|
7
|
-
getDefaultFeatures
|
|
8
|
-
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { mime } from "@modern-js/utils";
|
|
|
3
3
|
import Parser from "ua-parser-js";
|
|
4
4
|
import { getDefaultFeatures, defaultPolyfill } from "./const";
|
|
5
5
|
import PolyfillCache, { generateCacheKey } from "./libs/cache";
|
|
6
|
-
|
|
6
|
+
export default () => ({
|
|
7
7
|
name: "@modern-js/plugin-polyfill",
|
|
8
8
|
setup: () => ({
|
|
9
9
|
beforeProdServer() {
|
|
@@ -12,7 +12,9 @@ var src_default = () => ({
|
|
|
12
12
|
const features = getDefaultFeatures();
|
|
13
13
|
const minify = process.env.NODE_ENV === "production";
|
|
14
14
|
const featureDig = Object.keys(features).map((name) => {
|
|
15
|
-
const { flags = [
|
|
15
|
+
const { flags = [
|
|
16
|
+
"gated"
|
|
17
|
+
] } = features[name];
|
|
16
18
|
const flagStr = flags.join(",");
|
|
17
19
|
return `${name}-${flagStr}`;
|
|
18
20
|
}).join(",");
|
|
@@ -30,10 +32,7 @@ var src_default = () => ({
|
|
|
30
32
|
});
|
|
31
33
|
const matched = cache.get(cacheKey);
|
|
32
34
|
if (matched) {
|
|
33
|
-
context.res.setHeader(
|
|
34
|
-
"content-type",
|
|
35
|
-
mime.contentType("js")
|
|
36
|
-
);
|
|
35
|
+
context.res.setHeader("content-type", mime.contentType("js"));
|
|
37
36
|
return context.res.end(matched);
|
|
38
37
|
}
|
|
39
38
|
const polyfill = await getPolyfillString({
|
|
@@ -48,6 +47,3 @@ var src_default = () => ({
|
|
|
48
47
|
}
|
|
49
48
|
})
|
|
50
49
|
});
|
|
51
|
-
export {
|
|
52
|
-
src_default as default
|
|
53
|
-
};
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
import crypto from "crypto";
|
|
2
15
|
import LRUCache from "lru-cache";
|
|
3
16
|
const KB = 1024;
|
|
4
17
|
const MB = 1024 * KB;
|
|
5
18
|
const keyCache = new LRUCache(1e4);
|
|
6
|
-
const generateCacheKey = (options) => {
|
|
19
|
+
export const generateCacheKey = (options) => {
|
|
7
20
|
const { name, version, features, minify } = options;
|
|
8
21
|
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
9
22
|
const matched = keyCache.get(str);
|
|
@@ -15,20 +28,18 @@ const generateCacheKey = (options) => {
|
|
|
15
28
|
return hash;
|
|
16
29
|
};
|
|
17
30
|
class Cache {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.caches = new LRUCache({
|
|
20
|
-
max: 200 * MB,
|
|
21
|
-
length: (v) => v.length
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
31
|
get(hash) {
|
|
25
32
|
return this.caches.get(hash);
|
|
26
33
|
}
|
|
27
34
|
set(hash, content) {
|
|
28
35
|
this.caches.set(hash, content);
|
|
29
36
|
}
|
|
37
|
+
constructor() {
|
|
38
|
+
_define_property(this, "caches", void 0);
|
|
39
|
+
this.caches = new LRUCache({
|
|
40
|
+
max: 200 * MB,
|
|
41
|
+
length: (v) => v.length
|
|
42
|
+
});
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
|
-
export {
|
|
32
|
-
Cache as default,
|
|
33
|
-
generateCacheKey
|
|
34
|
-
};
|
|
45
|
+
export { Cache as default };
|
package/dist/esm-node/type.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/web-infra-dev/modern.js",
|
|
9
|
+
"directory": "packages/server/plugin-polyfill"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"keywords": [
|
|
9
13
|
"react",
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
"modern",
|
|
12
16
|
"modern.js"
|
|
13
17
|
],
|
|
14
|
-
"version": "2.
|
|
18
|
+
"version": "2.16.0",
|
|
15
19
|
"jsnext:source": "./src/cli.ts",
|
|
16
20
|
"types": "./dist/types/cli.d.ts",
|
|
17
21
|
"main": "./dist/cjs/cli.js",
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
"@modern-js/polyfill-lib": "^1.0.0",
|
|
48
52
|
"lru-cache": "^6.0.0",
|
|
49
53
|
"ua-parser-js": "^0.7.28",
|
|
50
|
-
"@modern-js/utils": "2.
|
|
54
|
+
"@modern-js/utils": "2.16.0"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
57
|
"@types/jest": "^29",
|
|
@@ -56,12 +60,12 @@
|
|
|
56
60
|
"@types/ua-parser-js": "^0.7.36",
|
|
57
61
|
"typescript": "^4",
|
|
58
62
|
"jest": "^29",
|
|
59
|
-
"@modern-js/server-core": "2.
|
|
60
|
-
"@modern-js/app-tools": "2.
|
|
61
|
-
"@modern-js/types": "2.
|
|
62
|
-
"@modern-js/core": "2.
|
|
63
|
-
"@scripts/build": "2.
|
|
64
|
-
"@scripts/jest-config": "2.
|
|
63
|
+
"@modern-js/server-core": "2.16.0",
|
|
64
|
+
"@modern-js/app-tools": "2.16.0",
|
|
65
|
+
"@modern-js/types": "2.16.0",
|
|
66
|
+
"@modern-js/core": "2.16.0",
|
|
67
|
+
"@scripts/build": "2.16.0",
|
|
68
|
+
"@scripts/jest-config": "2.16.0"
|
|
65
69
|
},
|
|
66
70
|
"sideEffects": false,
|
|
67
71
|
"publishConfig": {
|