@modern-js/plugin-polyfill 1.21.5 → 2.0.0-beta.1
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 +38 -14
- package/dist/js/modern/cli.js +0 -3
- package/dist/js/modern/index.js +0 -4
- package/dist/js/modern/libs/cache.js +0 -7
- package/dist/js/node/cli.js +0 -6
- package/dist/js/node/const.js +0 -2
- package/dist/js/node/index.js +0 -14
- package/dist/js/node/libs/cache.js +0 -16
- package/dist/types/cli.d.ts +0 -2
- package/dist/types/index.d.ts +0 -2
- package/package.json +9 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,26 +1,50 @@
|
|
|
1
1
|
# @modern-js/plugin-polyfill
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- 2971dd6: fix(plugin-polyfill): failed to join flags when restart CLI
|
|
8
|
-
|
|
9
|
-
fix(plugin-polyfill): 修复重启 CLI 时报错 join flags 失败的问题
|
|
5
|
+
### Major Changes
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## 1.21.4
|
|
7
|
+
- dda38c9: chore: v2
|
|
14
8
|
|
|
15
9
|
### Patch Changes
|
|
16
10
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
## 1.21.3
|
|
11
|
+
- ebbeed1: fix(plugin-polyfill): failed to join flags when restart CLI
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
fix(plugin-polyfill): 修复重启 CLI 时报错 join flags 失败的问题
|
|
22
14
|
|
|
23
|
-
-
|
|
15
|
+
- Updated dependencies [92f0ead]
|
|
16
|
+
- Updated dependencies [edd1cfb1af]
|
|
17
|
+
- Updated dependencies [cc971eabfc]
|
|
18
|
+
- Updated dependencies [5b9049f]
|
|
19
|
+
- Updated dependencies [92004d1]
|
|
20
|
+
- Updated dependencies [b8bbe036c7]
|
|
21
|
+
- Updated dependencies [d5a31df781]
|
|
22
|
+
- Updated dependencies [dda38c9]
|
|
23
|
+
- Updated dependencies [3bbea92b2a]
|
|
24
|
+
- Updated dependencies [abf3421]
|
|
25
|
+
- Updated dependencies [543be9558e]
|
|
26
|
+
- Updated dependencies [14b712d]
|
|
27
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
28
|
+
|
|
29
|
+
## 2.0.0-beta.0
|
|
30
|
+
|
|
31
|
+
### Major Changes
|
|
32
|
+
|
|
33
|
+
- dda38c9: chore: v2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [edd1cfb1a]
|
|
38
|
+
- Updated dependencies [cc971eabf]
|
|
39
|
+
- Updated dependencies [5b9049f]
|
|
40
|
+
- Updated dependencies [b8bbe036c]
|
|
41
|
+
- Updated dependencies [d5a31df78]
|
|
42
|
+
- Updated dependencies [dda38c9]
|
|
43
|
+
- Updated dependencies [3bbea92b2]
|
|
44
|
+
- Updated dependencies [abf3421]
|
|
45
|
+
- Updated dependencies [543be95]
|
|
46
|
+
- Updated dependencies [14b712d]
|
|
47
|
+
- @modern-js/utils@2.0.0-beta.0
|
|
24
48
|
|
|
25
49
|
## 1.21.2
|
|
26
50
|
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -7,16 +7,13 @@ export default (() => ({
|
|
|
7
7
|
partials
|
|
8
8
|
}) {
|
|
9
9
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
10
|
-
|
|
11
10
|
if (resolvedConfig.output.polyfill === 'ua') {
|
|
12
11
|
partials.top.push(`<script src="${defaultPolyfill}" crossorigin></script>`);
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
return {
|
|
16
14
|
partials,
|
|
17
15
|
entrypoint
|
|
18
16
|
};
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
})
|
|
22
19
|
}));
|
package/dist/js/modern/index.js
CHANGED
|
@@ -22,7 +22,6 @@ export default (() => ({
|
|
|
22
22
|
if (context.url !== route) {
|
|
23
23
|
return next();
|
|
24
24
|
}
|
|
25
|
-
|
|
26
25
|
const parsedUA = Parser(context.headers['user-agent']);
|
|
27
26
|
const {
|
|
28
27
|
name = '',
|
|
@@ -35,12 +34,10 @@ export default (() => ({
|
|
|
35
34
|
minify
|
|
36
35
|
});
|
|
37
36
|
const matched = cache.get(cacheKey);
|
|
38
|
-
|
|
39
37
|
if (matched) {
|
|
40
38
|
context.res.setHeader('content-type', mime.contentType('js'));
|
|
41
39
|
return context.res.end(matched);
|
|
42
40
|
}
|
|
43
|
-
|
|
44
41
|
const polyfill = await getPolyfillString({
|
|
45
42
|
uaString: context.headers['user-agent'],
|
|
46
43
|
minify,
|
|
@@ -51,6 +48,5 @@ export default (() => ({
|
|
|
51
48
|
return context.res.end(polyfill);
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
|
-
|
|
55
51
|
})
|
|
56
52
|
}));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
2
|
import crypto from 'crypto';
|
|
4
3
|
import LRUCache from 'lru-cache';
|
|
5
4
|
const KB = 1024;
|
|
@@ -14,11 +13,9 @@ export const generateCacheKey = options => {
|
|
|
14
13
|
} = options;
|
|
15
14
|
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
16
15
|
const matched = keyCache.get(str);
|
|
17
|
-
|
|
18
16
|
if (matched) {
|
|
19
17
|
return matched;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
const hash = crypto.createHmac('sha256', '^polyfill$').update(str).digest('hex');
|
|
23
20
|
keyCache.set(str, hash);
|
|
24
21
|
return hash;
|
|
@@ -26,19 +23,15 @@ export const generateCacheKey = options => {
|
|
|
26
23
|
export default class Cache {
|
|
27
24
|
constructor() {
|
|
28
25
|
_defineProperty(this, "caches", void 0);
|
|
29
|
-
|
|
30
26
|
this.caches = new LRUCache({
|
|
31
27
|
max: 200 * MB,
|
|
32
28
|
length: v => v.length
|
|
33
29
|
});
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
get(hash) {
|
|
37
32
|
return this.caches.get(hash);
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
set(hash, content) {
|
|
41
35
|
this.caches.set(hash, content);
|
|
42
36
|
}
|
|
43
|
-
|
|
44
37
|
}
|
package/dist/js/node/cli.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _const = require("./const");
|
|
9
|
-
|
|
10
8
|
var _default = () => ({
|
|
11
9
|
name: '@modern-js/plugin-polyfill',
|
|
12
10
|
setup: api => ({
|
|
@@ -15,18 +13,14 @@ var _default = () => ({
|
|
|
15
13
|
partials
|
|
16
14
|
}) {
|
|
17
15
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
18
|
-
|
|
19
16
|
if (resolvedConfig.output.polyfill === 'ua') {
|
|
20
17
|
partials.top.push(`<script src="${_const.defaultPolyfill}" crossorigin></script>`);
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
return {
|
|
24
20
|
partials,
|
|
25
21
|
entrypoint
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
})
|
|
30
25
|
});
|
|
31
|
-
|
|
32
26
|
exports.default = _default;
|
package/dist/js/node/const.js
CHANGED
|
@@ -6,11 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getDefaultFeatures = exports.defaultPolyfill = void 0;
|
|
7
7
|
const defaultPolyfill = '/__polyfill__';
|
|
8
8
|
exports.defaultPolyfill = defaultPolyfill;
|
|
9
|
-
|
|
10
9
|
const getDefaultFeatures = () => ({
|
|
11
10
|
es6: {
|
|
12
11
|
flags: ['gated']
|
|
13
12
|
}
|
|
14
13
|
});
|
|
15
|
-
|
|
16
14
|
exports.getDefaultFeatures = getDefaultFeatures;
|
package/dist/js/node/index.js
CHANGED
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _polyfillLib = require("@modern-js/polyfill-lib");
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _uaParserJs = _interopRequireDefault(require("ua-parser-js"));
|
|
13
|
-
|
|
14
10
|
var _const = require("./const");
|
|
15
|
-
|
|
16
11
|
var _cache = _interopRequireWildcard(require("./libs/cache"));
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
15
|
var _default = () => ({
|
|
25
16
|
name: '@modern-js/plugin-polyfill',
|
|
26
17
|
setup: () => ({
|
|
@@ -40,7 +31,6 @@ var _default = () => ({
|
|
|
40
31
|
if (context.url !== route) {
|
|
41
32
|
return next();
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
const parsedUA = (0, _uaParserJs.default)(context.headers['user-agent']);
|
|
45
35
|
const {
|
|
46
36
|
name = '',
|
|
@@ -53,12 +43,10 @@ var _default = () => ({
|
|
|
53
43
|
minify
|
|
54
44
|
});
|
|
55
45
|
const matched = cache.get(cacheKey);
|
|
56
|
-
|
|
57
46
|
if (matched) {
|
|
58
47
|
context.res.setHeader('content-type', _utils.mime.contentType('js'));
|
|
59
48
|
return context.res.end(matched);
|
|
60
49
|
}
|
|
61
|
-
|
|
62
50
|
const polyfill = await (0, _polyfillLib.getPolyfillString)({
|
|
63
51
|
uaString: context.headers['user-agent'],
|
|
64
52
|
minify,
|
|
@@ -69,8 +57,6 @@ var _default = () => ({
|
|
|
69
57
|
return context.res.end(polyfill);
|
|
70
58
|
};
|
|
71
59
|
}
|
|
72
|
-
|
|
73
60
|
})
|
|
74
61
|
});
|
|
75
|
-
|
|
76
62
|
exports.default = _default;
|
|
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateCacheKey = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
9
|
-
|
|
10
8
|
var _lruCache = _interopRequireDefault(require("lru-cache"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
-
|
|
16
11
|
const KB = 1024;
|
|
17
12
|
const MB = 1024 * KB;
|
|
18
13
|
const keyCache = new _lruCache.default(10000);
|
|
19
|
-
|
|
20
14
|
const generateCacheKey = options => {
|
|
21
15
|
const {
|
|
22
16
|
name,
|
|
@@ -26,37 +20,27 @@ const generateCacheKey = options => {
|
|
|
26
20
|
} = options;
|
|
27
21
|
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
28
22
|
const matched = keyCache.get(str);
|
|
29
|
-
|
|
30
23
|
if (matched) {
|
|
31
24
|
return matched;
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
const hash = _crypto.default.createHmac('sha256', '^polyfill$').update(str).digest('hex');
|
|
35
|
-
|
|
36
27
|
keyCache.set(str, hash);
|
|
37
28
|
return hash;
|
|
38
29
|
};
|
|
39
|
-
|
|
40
30
|
exports.generateCacheKey = generateCacheKey;
|
|
41
|
-
|
|
42
31
|
class Cache {
|
|
43
32
|
constructor() {
|
|
44
33
|
_defineProperty(this, "caches", void 0);
|
|
45
|
-
|
|
46
34
|
this.caches = new _lruCache.default({
|
|
47
35
|
max: 200 * MB,
|
|
48
36
|
length: v => v.length
|
|
49
37
|
});
|
|
50
38
|
}
|
|
51
|
-
|
|
52
39
|
get(hash) {
|
|
53
40
|
return this.caches.get(hash);
|
|
54
41
|
}
|
|
55
|
-
|
|
56
42
|
set(hash, content) {
|
|
57
43
|
this.caches.set(hash, content);
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
}
|
|
61
|
-
|
|
62
46
|
exports.default = Cache;
|
package/dist/types/cli.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "2.0.0-beta.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@modern-js/polyfill-lib": "^1.0.0",
|
|
41
41
|
"lru-cache": "^6.0.0",
|
|
42
42
|
"ua-parser-js": "^0.7.28",
|
|
43
|
-
"@modern-js/utils": "
|
|
43
|
+
"@modern-js/utils": "2.0.0-beta.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/jest": "^27",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"@types/ua-parser-js": "^0.7.36",
|
|
50
50
|
"typescript": "^4",
|
|
51
51
|
"jest": "^27",
|
|
52
|
-
"@modern-js/server-core": "
|
|
53
|
-
"@modern-js/types": "
|
|
54
|
-
"@modern-js/core": "
|
|
55
|
-
"@scripts/build": "
|
|
56
|
-
"@scripts/jest-config": "
|
|
52
|
+
"@modern-js/server-core": "2.0.0-beta.1",
|
|
53
|
+
"@modern-js/types": "2.0.0-beta.1",
|
|
54
|
+
"@modern-js/core": "2.0.0-beta.1",
|
|
55
|
+
"@scripts/build": "2.0.0-beta.1",
|
|
56
|
+
"@scripts/jest-config": "2.0.0-beta.1"
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"modernConfig": {
|
|
@@ -65,33 +65,10 @@
|
|
|
65
65
|
"registry": "https://registry.npmjs.org/",
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"wireit": {
|
|
69
|
-
"build": {
|
|
70
|
-
"command": "modern build",
|
|
71
|
-
"files": [
|
|
72
|
-
"src/**/*",
|
|
73
|
-
"tsconfig.json",
|
|
74
|
-
"package.json"
|
|
75
|
-
],
|
|
76
|
-
"output": [
|
|
77
|
-
"dist/**/*"
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
"test": {
|
|
81
|
-
"command": "jest --passWithNoTests",
|
|
82
|
-
"files": [
|
|
83
|
-
"src/**/*",
|
|
84
|
-
"tsconfig.json",
|
|
85
|
-
"package.json",
|
|
86
|
-
"tests/**/*"
|
|
87
|
-
],
|
|
88
|
-
"output": []
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
68
|
"scripts": {
|
|
92
69
|
"new": "modern new",
|
|
93
|
-
"build": "
|
|
70
|
+
"build": "modern build",
|
|
94
71
|
"dev": "modern build --watch",
|
|
95
|
-
"test": "
|
|
72
|
+
"test": "jest --passWithNoTests"
|
|
96
73
|
}
|
|
97
74
|
}
|