@modern-js/plugin-polyfill 1.1.0 → 1.2.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 +26 -67
- package/dist/types/cli.d.ts +3 -0
- package/jest.config.js +8 -0
- package/package.json +15 -10
- package/tsconfig.json +1 -3
- package/src/cli.ts +0 -20
- package/src/const.ts +0 -5
- package/src/global.d.ts +0 -7
- package/src/index.ts +0 -66
- package/src/libs/cache.ts +0 -49
- package/src/type.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,85 +1,44 @@
|
|
|
1
1
|
# @modern-js/plugin-polyfill
|
|
2
2
|
|
|
3
|
-
## 1.1
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 96119db2: Relese v1.1.0
|
|
8
|
-
|
|
9
|
-
1. 全面支持 Windows 平台
|
|
10
|
-
|
|
11
|
-
ISSUE:
|
|
12
|
-
|
|
13
|
-
- [182](https://github.com/modern-js-dev/modern.js/issues/182)
|
|
14
|
-
- [236](https://github.com/modern-js-dev/modern.js/issues/236)
|
|
15
|
-
|
|
16
|
-
PR
|
|
17
|
-
|
|
18
|
-
- [219](https://github.com/modern-js-dev/modern.js/pull/219)
|
|
19
|
-
- [247](https://github.com/modern-js-dev/modern.js/pull/247)
|
|
20
|
-
- [249](https://github.com/modern-js-dev/modern.js/pull/249)
|
|
21
|
-
- [253](https://github.com/modern-js-dev/modern.js/pull/253)
|
|
22
|
-
- [268](https://github.com/modern-js-dev/modern.js/pull/268)
|
|
23
|
-
- [270](https://github.com/modern-js-dev/modern.js/pull/270)
|
|
24
|
-
- [273](https://github.com/modern-js-dev/modern.js/pull/273)
|
|
25
|
-
- [276](https://github.com/modern-js-dev/modern.js/pull/276)
|
|
26
|
-
|
|
27
|
-
2. 修复 Unbundled 模式启用问题
|
|
28
|
-
|
|
29
|
-
ISSUE
|
|
30
|
-
|
|
31
|
-
- [186](https://github.com/modern-js-dev/modern.js/issues/186)
|
|
32
|
-
- [224](https://github.com/modern-js-dev/modern.js/issues/224)
|
|
33
|
-
- [225](https://github.com/modern-js-dev/modern.js/issues/225)
|
|
34
|
-
- [238](https://github.com/modern-js-dev/modern.js/issues/238)
|
|
35
|
-
|
|
36
|
-
PR
|
|
37
|
-
|
|
38
|
-
- [226](https://github.com/modern-js-dev/modern.js/pull/226)
|
|
39
|
-
- [264](https://github.com/modern-js-dev/modern.js/pull/264)
|
|
40
|
-
- [codesmith-12](https://github.com/modern-js-dev/codesmith/pull/12)
|
|
3
|
+
## 1.2.1
|
|
41
4
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ISSUE
|
|
45
|
-
|
|
46
|
-
- [198](https://github.com/modern-js-dev/modern.js/issues/198)
|
|
47
|
-
|
|
48
|
-
PR
|
|
49
|
-
|
|
50
|
-
- [209](https://github.com/modern-js-dev/modern.js/pull/209)
|
|
51
|
-
|
|
52
|
-
4. 修复 Storybook 使用时浏览器打开页面报错
|
|
53
|
-
|
|
54
|
-
ISSUE
|
|
55
|
-
|
|
56
|
-
- [228](https://github.com/modern-js-dev/modern.js/issues/228)
|
|
5
|
+
### Patch Changes
|
|
57
6
|
|
|
58
|
-
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- Updated dependencies [83166714]
|
|
9
|
+
- Updated dependencies [c3de9882]
|
|
10
|
+
- Updated dependencies [33ff48af]
|
|
11
|
+
- @modern-js/core@1.3.2
|
|
12
|
+
- @modern-js/server-plugin@1.2.1
|
|
59
13
|
|
|
60
|
-
|
|
14
|
+
## 1.2.0
|
|
61
15
|
|
|
62
|
-
|
|
16
|
+
### Minor Changes
|
|
63
17
|
|
|
64
|
-
|
|
18
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
65
19
|
|
|
66
|
-
|
|
67
|
-
- [257](https://github.com/modern-js-dev/modern.js/issues/257)
|
|
20
|
+
### Patch Changes
|
|
68
21
|
|
|
69
|
-
|
|
22
|
+
- Updated dependencies [fc71e36f]
|
|
23
|
+
- Updated dependencies [cfe11628]
|
|
24
|
+
- @modern-js/core@1.3.0
|
|
25
|
+
- @modern-js/server-plugin@1.2.0
|
|
70
26
|
|
|
71
|
-
|
|
72
|
-
- [271](https://github.com/modern-js-dev/modern.js/pull/271)
|
|
27
|
+
## 1.1.1
|
|
73
28
|
|
|
74
|
-
|
|
29
|
+
### Patch Changes
|
|
75
30
|
|
|
76
|
-
|
|
31
|
+
- 0fa83663: support more .env files
|
|
32
|
+
- Updated dependencies [6f7fe574]
|
|
33
|
+
- Updated dependencies [0fa83663]
|
|
34
|
+
- @modern-js/core@1.1.2
|
|
35
|
+
- @modern-js/server-plugin@1.1.1
|
|
77
36
|
|
|
78
|
-
|
|
37
|
+
## 1.1.0
|
|
79
38
|
|
|
80
|
-
|
|
39
|
+
### Minor Changes
|
|
81
40
|
|
|
82
|
-
|
|
41
|
+
- 96119db2: Relese v1.1.0
|
|
83
42
|
|
|
84
43
|
### Patch Changes
|
|
85
44
|
|
package/dist/types/cli.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
|
|
2
2
|
config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
3
|
+
resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
|
|
4
|
+
resolved: import("@modern-js/core").NormalizedConfig;
|
|
5
|
+
}>;
|
|
3
6
|
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
4
7
|
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
5
8
|
commands: import("@modern-js/core").AsyncWorkflow<{
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1
|
|
14
|
+
"version": "1.2.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/index.ts",
|
|
23
24
|
"import": "./dist/js/modern/index.js",
|
|
24
25
|
"require": "./dist/js/node/index.js"
|
|
25
26
|
},
|
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
|
27
28
|
},
|
|
28
29
|
"./cli": {
|
|
30
|
+
"jsnext:source": "./src/cli.ts",
|
|
29
31
|
"node": {
|
|
30
32
|
"import": "./dist/js/node/cli.js",
|
|
31
33
|
"require": "./dist/js/node/cli.js"
|
|
@@ -36,13 +38,13 @@
|
|
|
36
38
|
"dependencies": {
|
|
37
39
|
"@babel/runtime": "^7",
|
|
38
40
|
"@modern-js/polyfill-lib": "^1.0.0",
|
|
39
|
-
"@modern-js/server-plugin": "^1.1
|
|
41
|
+
"@modern-js/server-plugin": "^1.2.1",
|
|
40
42
|
"lru-cache": "^6.0.0",
|
|
41
43
|
"mime-types": "^2.1.32",
|
|
42
44
|
"ua-parser-js": "^0.7.28"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
|
-
"@modern-js/types": "^1.1
|
|
47
|
+
"@modern-js/types": "^1.2.1",
|
|
46
48
|
"@types/jest": "^26",
|
|
47
49
|
"@types/lru-cache": "^5.1.1",
|
|
48
50
|
"@types/mime-types": "^2.1.1",
|
|
@@ -51,12 +53,13 @@
|
|
|
51
53
|
"@types/react-dom": "^17",
|
|
52
54
|
"@types/ua-parser-js": "^0.7.36",
|
|
53
55
|
"typescript": "^4",
|
|
54
|
-
"@modern-js/core": "^1.
|
|
55
|
-
"@
|
|
56
|
-
"
|
|
56
|
+
"@modern-js/core": "^1.3.2",
|
|
57
|
+
"@scripts/build": "0.0.0",
|
|
58
|
+
"jest": "^27",
|
|
59
|
+
"@scripts/jest-config": "0.0.0"
|
|
57
60
|
},
|
|
58
61
|
"peerDependencies": {
|
|
59
|
-
"@modern-js/core": "^1.
|
|
62
|
+
"@modern-js/core": "^1.3.2"
|
|
60
63
|
},
|
|
61
64
|
"sideEffects": false,
|
|
62
65
|
"modernConfig": {
|
|
@@ -66,12 +69,14 @@
|
|
|
66
69
|
},
|
|
67
70
|
"publishConfig": {
|
|
68
71
|
"registry": "https://registry.npmjs.org/",
|
|
69
|
-
"access": "public"
|
|
72
|
+
"access": "public",
|
|
73
|
+
"types": "./dist/types/index.d.ts"
|
|
70
74
|
},
|
|
71
75
|
"scripts": {
|
|
72
76
|
"new": "modern new",
|
|
73
77
|
"build": "modern build",
|
|
74
78
|
"dev": "modern build --watch",
|
|
75
|
-
"test": "
|
|
76
|
-
}
|
|
79
|
+
"test": "jest --passWithNoTests"
|
|
80
|
+
},
|
|
81
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
77
82
|
}
|
package/tsconfig.json
CHANGED
package/src/cli.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createPlugin, useResolvedConfigContext } from '@modern-js/core';
|
|
2
|
-
import { defaultPolyfill } from './const';
|
|
3
|
-
|
|
4
|
-
export default createPlugin(
|
|
5
|
-
() =>
|
|
6
|
-
({
|
|
7
|
-
htmlPartials({ entrypoint, partials }: any) {
|
|
8
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
9
|
-
const resolvedConfig = useResolvedConfigContext();
|
|
10
|
-
if (resolvedConfig.output.polyfill === 'ua') {
|
|
11
|
-
partials.top.push(
|
|
12
|
-
`<script src="${defaultPolyfill}" crossorigin></script>`,
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return { partials, entrypoint };
|
|
17
|
-
},
|
|
18
|
-
} as any),
|
|
19
|
-
{ name: '@modern-js/plugin-polyfill' },
|
|
20
|
-
);
|
package/src/const.ts
DELETED
package/src/global.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { createPlugin } from '@modern-js/server-plugin';
|
|
2
|
-
import { NextFunction, ModernServerContext } from '@modern-js/types/server';
|
|
3
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
4
|
-
import { getPolyfillString } from '@modern-js/polyfill-lib';
|
|
5
|
-
import mime from 'mime-types';
|
|
6
|
-
import Parser from 'ua-parser-js';
|
|
7
|
-
import { defaultFeatures, defaultPolyfill } from './const';
|
|
8
|
-
import PolyfillCache, { generateCacheKey } from './libs/cache';
|
|
9
|
-
|
|
10
|
-
export default createPlugin(
|
|
11
|
-
() => ({
|
|
12
|
-
preServerInit(_: NormalizedConfig) {
|
|
13
|
-
const cache = new PolyfillCache();
|
|
14
|
-
const route = defaultPolyfill;
|
|
15
|
-
const features = defaultFeatures;
|
|
16
|
-
const minify = process.env.NODE_ENV === 'production';
|
|
17
|
-
|
|
18
|
-
const featureDig = Object.keys(features)
|
|
19
|
-
.map(name => {
|
|
20
|
-
const { flags = ['gated'] } = features[name];
|
|
21
|
-
const flagStr = flags.join(',');
|
|
22
|
-
|
|
23
|
-
return `${name}-${flagStr}`;
|
|
24
|
-
})
|
|
25
|
-
.join(',');
|
|
26
|
-
|
|
27
|
-
return async (context: ModernServerContext, next: NextFunction) => {
|
|
28
|
-
if (context.url !== route) {
|
|
29
|
-
return next();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const parsedUA = Parser(context.headers['user-agent']);
|
|
33
|
-
const { name = '', version = '' } = parsedUA.browser;
|
|
34
|
-
|
|
35
|
-
const cacheKey = generateCacheKey({
|
|
36
|
-
name,
|
|
37
|
-
version,
|
|
38
|
-
features: featureDig,
|
|
39
|
-
minify,
|
|
40
|
-
});
|
|
41
|
-
const matched = cache.get(cacheKey);
|
|
42
|
-
if (matched) {
|
|
43
|
-
context.res.setHeader(
|
|
44
|
-
'content-type',
|
|
45
|
-
mime.contentType('js') as string,
|
|
46
|
-
);
|
|
47
|
-
return context.res.end(matched);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const polyfill = await getPolyfillString({
|
|
51
|
-
uaString: context.headers['user-agent'] as string,
|
|
52
|
-
minify,
|
|
53
|
-
features,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
cache.set(cacheKey, polyfill);
|
|
57
|
-
|
|
58
|
-
context.res.setHeader('content-type', mime.contentType('js') as string);
|
|
59
|
-
return context.res.end(polyfill);
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
{
|
|
64
|
-
name: '@modern-js/plugin-polyfill',
|
|
65
|
-
},
|
|
66
|
-
) as any;
|
package/src/libs/cache.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import LRUCache from 'lru-cache';
|
|
3
|
-
|
|
4
|
-
type CacheQueryOptions = {
|
|
5
|
-
features: string;
|
|
6
|
-
minify: boolean;
|
|
7
|
-
name: string;
|
|
8
|
-
version: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const KB = 1024;
|
|
12
|
-
const MB = 1024 * KB;
|
|
13
|
-
|
|
14
|
-
const keyCache = new LRUCache<string, string>(10000);
|
|
15
|
-
export const generateCacheKey = (options: CacheQueryOptions) => {
|
|
16
|
-
const { name, version, features, minify } = options;
|
|
17
|
-
|
|
18
|
-
const str = `${name}-${version}-${Number(minify)}-${features}`;
|
|
19
|
-
const matched = keyCache.get(str);
|
|
20
|
-
if (matched) {
|
|
21
|
-
return matched;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const hash = crypto
|
|
25
|
-
.createHmac('sha256', '^polyfill$')
|
|
26
|
-
.update(str)
|
|
27
|
-
.digest('hex');
|
|
28
|
-
keyCache.set(str, hash);
|
|
29
|
-
return hash;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default class Cache {
|
|
33
|
-
private readonly caches: LRUCache<string, string>;
|
|
34
|
-
|
|
35
|
-
constructor() {
|
|
36
|
-
this.caches = new LRUCache({
|
|
37
|
-
max: 200 * MB,
|
|
38
|
-
length: v => v.length,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public get(hash: string) {
|
|
43
|
-
return this.caches.get(hash);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public set(hash: string, content: string) {
|
|
47
|
-
this.caches.set(hash, content);
|
|
48
|
-
}
|
|
49
|
-
}
|