@modern-js/plugin-polyfill 0.0.0-next-0bf5ec13d2 → 0.0.0-next-cb457b8
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 +2 -2
- package/package.json +9 -9
- package/dist/js/modern/cli.js +0 -24
- package/dist/js/modern/const.js +0 -8
- package/dist/js/modern/index.js +0 -73
- package/dist/js/modern/libs/cache.js +0 -34
- package/dist/js/modern/type.js +0 -0
- package/dist/js/node/cli.js +0 -45
- package/dist/js/node/const.js +0 -32
- package/dist/js/node/index.js +0 -100
- package/dist/js/node/libs/cache.js +0 -63
- package/dist/js/node/type.js +0 -15
- package/dist/js/treeshaking/cli.js +0 -31
- package/dist/js/treeshaking/const.js +0 -11
- package/dist/js/treeshaking/index.js +0 -203
- package/dist/js/treeshaking/libs/cache.js +0 -77
- package/dist/js/treeshaking/type.js +0 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.0-next-
|
|
14
|
+
"version": "0.0.0-next-cb457b8",
|
|
15
15
|
"jsnext:source": "./src/cli.ts",
|
|
16
16
|
"types": "./dist/types/cli.d.ts",
|
|
17
17
|
"main": "./dist/cjs/cli.js",
|
|
@@ -44,24 +44,24 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.18.0",
|
|
47
|
-
"@modern-js/utils": "0.0.0-next-0bf5ec13d2",
|
|
48
47
|
"@modern-js/polyfill-lib": "^1.0.0",
|
|
49
48
|
"lru-cache": "^6.0.0",
|
|
50
|
-
"ua-parser-js": "^0.7.28"
|
|
49
|
+
"ua-parser-js": "^0.7.28",
|
|
50
|
+
"@modern-js/utils": "0.0.0-next-cb457b8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@modern-js/server-core": "0.0.0-next-0bf5ec13d2",
|
|
54
|
-
"@modern-js/app-tools": "0.0.0-next-0bf5ec13d2",
|
|
55
|
-
"@modern-js/types": "0.0.0-next-0bf5ec13d2",
|
|
56
53
|
"@types/jest": "^27",
|
|
57
54
|
"@types/lru-cache": "^5.1.1",
|
|
58
55
|
"@types/node": "^14",
|
|
59
56
|
"@types/ua-parser-js": "^0.7.36",
|
|
60
57
|
"typescript": "^4",
|
|
61
|
-
"@modern-js/core": "0.0.0-next-0bf5ec13d2",
|
|
62
|
-
"@scripts/build": "0.0.0-next-0bf5ec13d2",
|
|
63
58
|
"jest": "^27",
|
|
64
|
-
"@
|
|
59
|
+
"@modern-js/server-core": "0.0.0-next-cb457b8",
|
|
60
|
+
"@modern-js/app-tools": "0.0.0-next-cb457b8",
|
|
61
|
+
"@modern-js/types": "0.0.0-next-cb457b8",
|
|
62
|
+
"@modern-js/core": "0.0.0-next-cb457b8",
|
|
63
|
+
"@scripts/jest-config": "0.0.0-next-cb457b8",
|
|
64
|
+
"@scripts/build": "0.0.0-next-cb457b8"
|
|
65
65
|
},
|
|
66
66
|
"sideEffects": false,
|
|
67
67
|
"publishConfig": {
|
package/dist/js/modern/cli.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defaultPolyfill } from "./const";
|
|
2
|
-
var cli_default = () => ({
|
|
3
|
-
name: "@modern-js/plugin-polyfill",
|
|
4
|
-
setup: (api) => ({
|
|
5
|
-
htmlPartials({ entrypoint, partials }) {
|
|
6
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
|
7
|
-
if (resolvedConfig.output.polyfill === "ua") {
|
|
8
|
-
partials.top.push(
|
|
9
|
-
`<script src="${defaultPolyfill}" crossorigin><\/script>`
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
return { partials, entrypoint };
|
|
13
|
-
},
|
|
14
|
-
collectServerPlugins({ plugins }) {
|
|
15
|
-
plugins.push({
|
|
16
|
-
"@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/server"
|
|
17
|
-
});
|
|
18
|
-
return { plugins };
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
export {
|
|
23
|
-
cli_default as default
|
|
24
|
-
};
|
package/dist/js/modern/const.js
DELETED
package/dist/js/modern/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { getPolyfillString } from "@modern-js/polyfill-lib";
|
|
22
|
-
import { mime } from "@modern-js/utils";
|
|
23
|
-
import Parser from "ua-parser-js";
|
|
24
|
-
import { getDefaultFeatures, defaultPolyfill } from "./const";
|
|
25
|
-
import PolyfillCache, { generateCacheKey } from "./libs/cache";
|
|
26
|
-
var src_default = () => ({
|
|
27
|
-
name: "@modern-js/plugin-polyfill",
|
|
28
|
-
setup: () => ({
|
|
29
|
-
beforeProdServer() {
|
|
30
|
-
const cache = new PolyfillCache();
|
|
31
|
-
const route = defaultPolyfill;
|
|
32
|
-
const features = getDefaultFeatures();
|
|
33
|
-
const minify = process.env.NODE_ENV === "production";
|
|
34
|
-
const featureDig = Object.keys(features).map((name) => {
|
|
35
|
-
const { flags = ["gated"] } = features[name];
|
|
36
|
-
const flagStr = flags.join(",");
|
|
37
|
-
return `${name}-${flagStr}`;
|
|
38
|
-
}).join(",");
|
|
39
|
-
return (context, next) => __async(this, null, function* () {
|
|
40
|
-
if (context.url !== route) {
|
|
41
|
-
return next();
|
|
42
|
-
}
|
|
43
|
-
const parsedUA = Parser(context.headers["user-agent"]);
|
|
44
|
-
const { name = "", version = "" } = parsedUA.browser;
|
|
45
|
-
const cacheKey = generateCacheKey({
|
|
46
|
-
name,
|
|
47
|
-
version,
|
|
48
|
-
features: featureDig,
|
|
49
|
-
minify
|
|
50
|
-
});
|
|
51
|
-
const matched = cache.get(cacheKey);
|
|
52
|
-
if (matched) {
|
|
53
|
-
context.res.setHeader(
|
|
54
|
-
"content-type",
|
|
55
|
-
mime.contentType("js")
|
|
56
|
-
);
|
|
57
|
-
return context.res.end(matched);
|
|
58
|
-
}
|
|
59
|
-
const polyfill = yield getPolyfillString({
|
|
60
|
-
uaString: context.headers["user-agent"],
|
|
61
|
-
minify,
|
|
62
|
-
features
|
|
63
|
-
});
|
|
64
|
-
cache.set(cacheKey, polyfill);
|
|
65
|
-
context.res.setHeader("content-type", mime.contentType("js"));
|
|
66
|
-
return context.res.end(polyfill);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
});
|
|
71
|
-
export {
|
|
72
|
-
src_default as default
|
|
73
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
import LRUCache from "lru-cache";
|
|
3
|
-
const KB = 1024;
|
|
4
|
-
const MB = 1024 * KB;
|
|
5
|
-
const keyCache = new LRUCache(1e4);
|
|
6
|
-
const generateCacheKey = (options) => {
|
|
7
|
-
const { name, version, features, minify } = options;
|
|
8
|
-
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
9
|
-
const matched = keyCache.get(str);
|
|
10
|
-
if (matched) {
|
|
11
|
-
return matched;
|
|
12
|
-
}
|
|
13
|
-
const hash = crypto.createHmac("sha256", "^polyfill$").update(str).digest("hex");
|
|
14
|
-
keyCache.set(str, hash);
|
|
15
|
-
return hash;
|
|
16
|
-
};
|
|
17
|
-
class Cache {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.caches = new LRUCache({
|
|
20
|
-
max: 200 * MB,
|
|
21
|
-
length: (v) => v.length
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
get(hash) {
|
|
25
|
-
return this.caches.get(hash);
|
|
26
|
-
}
|
|
27
|
-
set(hash, content) {
|
|
28
|
-
this.caches.set(hash, content);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
Cache as default,
|
|
33
|
-
generateCacheKey
|
|
34
|
-
};
|
package/dist/js/modern/type.js
DELETED
|
File without changes
|
package/dist/js/node/cli.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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 cli_exports = {};
|
|
19
|
-
__export(cli_exports, {
|
|
20
|
-
default: () => cli_default
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(cli_exports);
|
|
23
|
-
var import_const = require("./const");
|
|
24
|
-
var cli_default = () => ({
|
|
25
|
-
name: "@modern-js/plugin-polyfill",
|
|
26
|
-
setup: (api) => ({
|
|
27
|
-
htmlPartials({ entrypoint, partials }) {
|
|
28
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
|
29
|
-
if (resolvedConfig.output.polyfill === "ua") {
|
|
30
|
-
partials.top.push(
|
|
31
|
-
`<script src="${import_const.defaultPolyfill}" crossorigin><\/script>`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return { partials, entrypoint };
|
|
35
|
-
},
|
|
36
|
-
collectServerPlugins({ plugins }) {
|
|
37
|
-
plugins.push({
|
|
38
|
-
"@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/server"
|
|
39
|
-
});
|
|
40
|
-
return { plugins };
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
});
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {});
|
package/dist/js/node/const.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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 const_exports = {};
|
|
19
|
-
__export(const_exports, {
|
|
20
|
-
defaultPolyfill: () => defaultPolyfill,
|
|
21
|
-
getDefaultFeatures: () => getDefaultFeatures
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(const_exports);
|
|
24
|
-
const defaultPolyfill = "/__polyfill__";
|
|
25
|
-
const getDefaultFeatures = () => ({
|
|
26
|
-
es6: { flags: ["gated"] }
|
|
27
|
-
});
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
defaultPolyfill,
|
|
31
|
-
getDefaultFeatures
|
|
32
|
-
});
|
package/dist/js/node/index.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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 src_exports = {};
|
|
45
|
-
__export(src_exports, {
|
|
46
|
-
default: () => src_default
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(src_exports);
|
|
49
|
-
var import_polyfill_lib = require("@modern-js/polyfill-lib");
|
|
50
|
-
var import_utils = require("@modern-js/utils");
|
|
51
|
-
var import_ua_parser_js = __toESM(require("ua-parser-js"));
|
|
52
|
-
var import_const = require("./const");
|
|
53
|
-
var import_cache = __toESM(require("./libs/cache"));
|
|
54
|
-
var src_default = () => ({
|
|
55
|
-
name: "@modern-js/plugin-polyfill",
|
|
56
|
-
setup: () => ({
|
|
57
|
-
beforeProdServer() {
|
|
58
|
-
const cache = new import_cache.default();
|
|
59
|
-
const route = import_const.defaultPolyfill;
|
|
60
|
-
const features = (0, import_const.getDefaultFeatures)();
|
|
61
|
-
const minify = process.env.NODE_ENV === "production";
|
|
62
|
-
const featureDig = Object.keys(features).map((name) => {
|
|
63
|
-
const { flags = ["gated"] } = features[name];
|
|
64
|
-
const flagStr = flags.join(",");
|
|
65
|
-
return `${name}-${flagStr}`;
|
|
66
|
-
}).join(",");
|
|
67
|
-
return (context, next) => __async(this, null, function* () {
|
|
68
|
-
if (context.url !== route) {
|
|
69
|
-
return next();
|
|
70
|
-
}
|
|
71
|
-
const parsedUA = (0, import_ua_parser_js.default)(context.headers["user-agent"]);
|
|
72
|
-
const { name = "", version = "" } = parsedUA.browser;
|
|
73
|
-
const cacheKey = (0, import_cache.generateCacheKey)({
|
|
74
|
-
name,
|
|
75
|
-
version,
|
|
76
|
-
features: featureDig,
|
|
77
|
-
minify
|
|
78
|
-
});
|
|
79
|
-
const matched = cache.get(cacheKey);
|
|
80
|
-
if (matched) {
|
|
81
|
-
context.res.setHeader(
|
|
82
|
-
"content-type",
|
|
83
|
-
import_utils.mime.contentType("js")
|
|
84
|
-
);
|
|
85
|
-
return context.res.end(matched);
|
|
86
|
-
}
|
|
87
|
-
const polyfill = yield (0, import_polyfill_lib.getPolyfillString)({
|
|
88
|
-
uaString: context.headers["user-agent"],
|
|
89
|
-
minify,
|
|
90
|
-
features
|
|
91
|
-
});
|
|
92
|
-
cache.set(cacheKey, polyfill);
|
|
93
|
-
context.res.setHeader("content-type", import_utils.mime.contentType("js"));
|
|
94
|
-
return context.res.end(polyfill);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
-
0 && (module.exports = {});
|
|
@@ -1,63 +0,0 @@
|
|
|
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 cache_exports = {};
|
|
25
|
-
__export(cache_exports, {
|
|
26
|
-
default: () => Cache,
|
|
27
|
-
generateCacheKey: () => generateCacheKey
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(cache_exports);
|
|
30
|
-
var import_crypto = __toESM(require("crypto"));
|
|
31
|
-
var import_lru_cache = __toESM(require("lru-cache"));
|
|
32
|
-
const KB = 1024;
|
|
33
|
-
const MB = 1024 * KB;
|
|
34
|
-
const keyCache = new import_lru_cache.default(1e4);
|
|
35
|
-
const generateCacheKey = (options) => {
|
|
36
|
-
const { name, version, features, minify } = options;
|
|
37
|
-
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
38
|
-
const matched = keyCache.get(str);
|
|
39
|
-
if (matched) {
|
|
40
|
-
return matched;
|
|
41
|
-
}
|
|
42
|
-
const hash = import_crypto.default.createHmac("sha256", "^polyfill$").update(str).digest("hex");
|
|
43
|
-
keyCache.set(str, hash);
|
|
44
|
-
return hash;
|
|
45
|
-
};
|
|
46
|
-
class Cache {
|
|
47
|
-
constructor() {
|
|
48
|
-
this.caches = new import_lru_cache.default({
|
|
49
|
-
max: 200 * MB,
|
|
50
|
-
length: (v) => v.length
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
get(hash) {
|
|
54
|
-
return this.caches.get(hash);
|
|
55
|
-
}
|
|
56
|
-
set(hash, content) {
|
|
57
|
-
this.caches.set(hash, content);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
-
0 && (module.exports = {
|
|
62
|
-
generateCacheKey
|
|
63
|
-
});
|
package/dist/js/node/type.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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,31 +0,0 @@
|
|
|
1
|
-
import { defaultPolyfill } from "./const";
|
|
2
|
-
var cli_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: partials,
|
|
15
|
-
entrypoint: 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: plugins
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export { cli_default as default };
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
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
|
-
}
|
|
15
|
-
function _asyncToGenerator(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(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
-
var f, y, t, g, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
};
|
|
40
|
-
return(g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
-
return this;
|
|
46
|
-
}), g);
|
|
47
|
-
function verb(n) {
|
|
48
|
-
return function(v) {
|
|
49
|
-
return step([
|
|
50
|
-
n,
|
|
51
|
-
v
|
|
52
|
-
]);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function step(op) {
|
|
56
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while(_)try {
|
|
58
|
-
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) return t;
|
|
59
|
-
if (y = 0, t) op = [
|
|
60
|
-
op[0] & 2,
|
|
61
|
-
t.value
|
|
62
|
-
];
|
|
63
|
-
switch(op[0]){
|
|
64
|
-
case 0:
|
|
65
|
-
case 1:
|
|
66
|
-
t = op;
|
|
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) {
|
|
110
|
-
op = [
|
|
111
|
-
6,
|
|
112
|
-
e
|
|
113
|
-
];
|
|
114
|
-
y = 0;
|
|
115
|
-
} finally{
|
|
116
|
-
f = t = 0;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] & 5) throw op[1];
|
|
119
|
-
return {
|
|
120
|
-
value: op[0] ? op[1] : void 0,
|
|
121
|
-
done: true
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
import { getPolyfillString } from "@modern-js/polyfill-lib";
|
|
126
|
-
import { mime } from "@modern-js/utils";
|
|
127
|
-
import Parser from "ua-parser-js";
|
|
128
|
-
import { getDefaultFeatures, defaultPolyfill } from "./const";
|
|
129
|
-
import PolyfillCache, { generateCacheKey } from "./libs/cache";
|
|
130
|
-
var src_default = function() {
|
|
131
|
-
return {
|
|
132
|
-
name: "@modern-js/plugin-polyfill",
|
|
133
|
-
setup: function() {
|
|
134
|
-
return {
|
|
135
|
-
beforeProdServer: function beforeProdServer() {
|
|
136
|
-
var cache = new PolyfillCache();
|
|
137
|
-
var route = defaultPolyfill;
|
|
138
|
-
var features = getDefaultFeatures();
|
|
139
|
-
var minify = process.env.NODE_ENV === "production";
|
|
140
|
-
var featureDig = Object.keys(features).map(function(name) {
|
|
141
|
-
var _features_name = features[name], _features_name_flags = _features_name.flags, flags = _features_name_flags === void 0 ? [
|
|
142
|
-
"gated"
|
|
143
|
-
] : _features_name_flags;
|
|
144
|
-
var flagStr = flags.join(",");
|
|
145
|
-
return "".concat(name, "-").concat(flagStr);
|
|
146
|
-
}).join(",");
|
|
147
|
-
return function() {
|
|
148
|
-
var _ref = _asyncToGenerator(function(context, next) {
|
|
149
|
-
var parsedUA, _parsedUA_browser, _parsedUA_browser_name, name, _parsedUA_browser_version, version, cacheKey, matched, polyfill;
|
|
150
|
-
return __generator(this, function(_state) {
|
|
151
|
-
switch(_state.label){
|
|
152
|
-
case 0:
|
|
153
|
-
if (context.url !== route) {
|
|
154
|
-
return [
|
|
155
|
-
2,
|
|
156
|
-
next()
|
|
157
|
-
];
|
|
158
|
-
}
|
|
159
|
-
parsedUA = Parser(context.headers["user-agent"]);
|
|
160
|
-
_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;
|
|
161
|
-
cacheKey = generateCacheKey({
|
|
162
|
-
name: name,
|
|
163
|
-
version: version,
|
|
164
|
-
features: featureDig,
|
|
165
|
-
minify: minify
|
|
166
|
-
});
|
|
167
|
-
matched = cache.get(cacheKey);
|
|
168
|
-
if (matched) {
|
|
169
|
-
context.res.setHeader("content-type", mime.contentType("js"));
|
|
170
|
-
return [
|
|
171
|
-
2,
|
|
172
|
-
context.res.end(matched)
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
return [
|
|
176
|
-
4,
|
|
177
|
-
getPolyfillString({
|
|
178
|
-
uaString: context.headers["user-agent"],
|
|
179
|
-
minify: minify,
|
|
180
|
-
features: features
|
|
181
|
-
})
|
|
182
|
-
];
|
|
183
|
-
case 1:
|
|
184
|
-
polyfill = _state.sent();
|
|
185
|
-
cache.set(cacheKey, polyfill);
|
|
186
|
-
context.res.setHeader("content-type", mime.contentType("js"));
|
|
187
|
-
return [
|
|
188
|
-
2,
|
|
189
|
-
context.res.end(polyfill)
|
|
190
|
-
];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
return function(context, next) {
|
|
195
|
-
return _ref.apply(this, arguments);
|
|
196
|
-
};
|
|
197
|
-
}();
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
export { src_default as default };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _defineProperties(target, props) {
|
|
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) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
return Constructor;
|
|
19
|
-
}
|
|
20
|
-
function _defineProperty(obj, key, value) {
|
|
21
|
-
if (key in obj) {
|
|
22
|
-
Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
obj[key] = value;
|
|
30
|
-
}
|
|
31
|
-
return obj;
|
|
32
|
-
}
|
|
33
|
-
import crypto from "crypto";
|
|
34
|
-
import LRUCache from "lru-cache";
|
|
35
|
-
var KB = 1024;
|
|
36
|
-
var MB = 1024 * KB;
|
|
37
|
-
var keyCache = new LRUCache(1e4);
|
|
38
|
-
var generateCacheKey = function(options) {
|
|
39
|
-
var name = options.name, version = options.version, features = options.features, minify = options.minify;
|
|
40
|
-
var str = "".concat(name, "-").concat(version, "-").concat(Number(minify), "-").concat(features);
|
|
41
|
-
var matched = keyCache.get(str);
|
|
42
|
-
if (matched) {
|
|
43
|
-
return matched;
|
|
44
|
-
}
|
|
45
|
-
var hash = crypto.createHmac("sha256", "^polyfill$").update(str).digest("hex");
|
|
46
|
-
keyCache.set(str, hash);
|
|
47
|
-
return hash;
|
|
48
|
-
};
|
|
49
|
-
var Cache = /*#__PURE__*/ function() {
|
|
50
|
-
"use strict";
|
|
51
|
-
function Cache() {
|
|
52
|
-
_classCallCheck(this, Cache);
|
|
53
|
-
_defineProperty(this, "caches", void 0);
|
|
54
|
-
this.caches = new LRUCache({
|
|
55
|
-
max: 200 * MB,
|
|
56
|
-
length: function(v) {
|
|
57
|
-
return v.length;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
_createClass(Cache, [
|
|
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;
|
|
76
|
-
}();
|
|
77
|
-
export { Cache as default, generateCacheKey };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|