@modern-js/plugin-polyfill 1.2.2 → 1.2.5
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/.eslintrc.js +7 -0
- package/CHANGELOG.md +19 -0
- package/dist/js/modern/cli.js +18 -19
- package/dist/js/modern/index.js +47 -47
- package/dist/js/node/cli.js +18 -20
- package/dist/js/node/index.js +48 -49
- package/dist/types/cli.d.ts +3 -18
- package/dist/types/index.d.ts +3 -1
- package/jest.config.js +0 -1
- package/package.json +5 -9
- package/tsconfig.json +1 -1
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/plugin-polyfill
|
|
2
2
|
|
|
3
|
+
## 1.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
8
|
+
|
|
9
|
+
## 1.2.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
14
|
+
|
|
15
|
+
## 1.2.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- c7dc7f54: migrate to new plugin style
|
|
20
|
+
- 2008fdbd: convert two packages server part, support server load plugin itself
|
|
21
|
+
|
|
3
22
|
## 1.2.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { createPlugin, useResolvedConfigContext } from '@modern-js/core';
|
|
2
1
|
import { defaultPolyfill } from "./const";
|
|
3
|
-
export default
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export default (() => ({
|
|
3
|
+
name: '@modern-js/plugin-polyfill',
|
|
4
|
+
setup: api => ({
|
|
5
|
+
htmlPartials({
|
|
6
|
+
entrypoint,
|
|
7
|
+
partials
|
|
8
|
+
}) {
|
|
9
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (resolvedConfig.output.polyfill === 'ua') {
|
|
12
|
+
partials.top.push(`<script src="${defaultPolyfill}" crossorigin></script>`);
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
return {
|
|
16
|
+
partials,
|
|
17
|
+
entrypoint
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
});
|
|
21
|
+
})
|
|
22
|
+
}));
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { createPlugin } from '@modern-js/server-core';
|
|
2
1
|
import { getPolyfillString } from '@modern-js/polyfill-lib';
|
|
3
2
|
import mime from 'mime-types';
|
|
4
3
|
import Parser from 'ua-parser-js';
|
|
5
4
|
import { defaultFeatures, defaultPolyfill } from "./const";
|
|
6
5
|
import PolyfillCache, { generateCacheKey } from "./libs/cache";
|
|
7
|
-
export default
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
export default (() => ({
|
|
7
|
+
name: '@modern-js/plugin-polyfill',
|
|
8
|
+
setup: () => ({
|
|
9
|
+
preServerInit(_) {
|
|
10
|
+
const cache = new PolyfillCache();
|
|
11
|
+
const route = defaultPolyfill;
|
|
12
|
+
const features = defaultFeatures;
|
|
13
|
+
const minify = process.env.NODE_ENV === 'production';
|
|
14
|
+
const featureDig = Object.keys(features).map(name => {
|
|
15
|
+
const {
|
|
16
|
+
flags = ['gated']
|
|
17
|
+
} = features[name];
|
|
18
|
+
const flagStr = flags.join(',');
|
|
19
|
+
return `${name}-${flagStr}`;
|
|
20
|
+
}).join(',');
|
|
21
|
+
return async (context, next) => {
|
|
22
|
+
if (context.url !== route) {
|
|
23
|
+
return next();
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
const parsedUA = Parser(context.headers['user-agent']);
|
|
27
|
+
const {
|
|
28
|
+
name = '',
|
|
29
|
+
version = ''
|
|
30
|
+
} = parsedUA.browser;
|
|
31
|
+
const cacheKey = generateCacheKey({
|
|
32
|
+
name,
|
|
33
|
+
version,
|
|
34
|
+
features: featureDig,
|
|
35
|
+
minify
|
|
36
|
+
});
|
|
37
|
+
const matched = cache.get(cacheKey);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (matched) {
|
|
40
|
+
context.res.setHeader('content-type', mime.contentType('js'));
|
|
41
|
+
return context.res.end(matched);
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
const polyfill = await getPolyfillString({
|
|
45
|
+
uaString: context.headers['user-agent'],
|
|
46
|
+
minify,
|
|
47
|
+
features
|
|
48
|
+
});
|
|
49
|
+
cache.set(cacheKey, polyfill);
|
|
50
|
+
context.res.setHeader('content-type', mime.contentType('js'));
|
|
51
|
+
return context.res.end(polyfill);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
53
54
|
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
});
|
|
55
|
+
})
|
|
56
|
+
}));
|
package/dist/js/node/cli.js
CHANGED
|
@@ -5,30 +5,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _core = require("@modern-js/core");
|
|
9
|
-
|
|
10
8
|
var _const = require("./const");
|
|
11
9
|
|
|
12
|
-
var _default = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
var _default = () => ({
|
|
11
|
+
name: '@modern-js/plugin-polyfill',
|
|
12
|
+
setup: api => ({
|
|
13
|
+
htmlPartials({
|
|
14
|
+
entrypoint,
|
|
15
|
+
partials
|
|
16
|
+
}) {
|
|
17
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
18
|
+
|
|
19
|
+
if (resolvedConfig.output.polyfill === 'ua') {
|
|
20
|
+
partials.top.push(`<script src="${_const.defaultPolyfill}" crossorigin></script>`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
partials,
|
|
25
|
+
entrypoint
|
|
26
|
+
};
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
partials,
|
|
26
|
-
entrypoint
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}), {
|
|
31
|
-
name: '@modern-js/plugin-polyfill'
|
|
29
|
+
})
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
exports.default = _default;
|
package/dist/js/node/index.js
CHANGED
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _serverCore = require("@modern-js/server-core");
|
|
9
|
-
|
|
10
8
|
var _polyfillLib = require("@modern-js/polyfill-lib");
|
|
11
9
|
|
|
12
10
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
@@ -23,55 +21,56 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
23
21
|
|
|
24
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
23
|
|
|
26
|
-
var _default = (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
var _default = () => ({
|
|
25
|
+
name: '@modern-js/plugin-polyfill',
|
|
26
|
+
setup: () => ({
|
|
27
|
+
preServerInit(_) {
|
|
28
|
+
const cache = new _cache.default();
|
|
29
|
+
const route = _const.defaultPolyfill;
|
|
30
|
+
const features = _const.defaultFeatures;
|
|
31
|
+
const minify = process.env.NODE_ENV === 'production';
|
|
32
|
+
const featureDig = Object.keys(features).map(name => {
|
|
33
|
+
const {
|
|
34
|
+
flags = ['gated']
|
|
35
|
+
} = features[name];
|
|
36
|
+
const flagStr = flags.join(',');
|
|
37
|
+
return `${name}-${flagStr}`;
|
|
38
|
+
}).join(',');
|
|
39
|
+
return async (context, next) => {
|
|
40
|
+
if (context.url !== route) {
|
|
41
|
+
return next();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parsedUA = (0, _uaParserJs.default)(context.headers['user-agent']);
|
|
45
|
+
const {
|
|
46
|
+
name = '',
|
|
47
|
+
version = ''
|
|
48
|
+
} = parsedUA.browser;
|
|
49
|
+
const cacheKey = (0, _cache.generateCacheKey)({
|
|
50
|
+
name,
|
|
51
|
+
version,
|
|
52
|
+
features: featureDig,
|
|
53
|
+
minify
|
|
54
|
+
});
|
|
55
|
+
const matched = cache.get(cacheKey);
|
|
56
|
+
|
|
57
|
+
if (matched) {
|
|
58
|
+
context.res.setHeader('content-type', _mimeTypes.default.contentType('js'));
|
|
59
|
+
return context.res.end(matched);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const polyfill = await (0, _polyfillLib.getPolyfillString)({
|
|
63
|
+
uaString: context.headers['user-agent'],
|
|
64
|
+
minify,
|
|
65
|
+
features
|
|
66
|
+
});
|
|
67
|
+
cache.set(cacheKey, polyfill);
|
|
58
68
|
context.res.setHeader('content-type', _mimeTypes.default.contentType('js'));
|
|
59
|
-
return context.res.end(
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const polyfill = await (0, _polyfillLib.getPolyfillString)({
|
|
63
|
-
uaString: context.headers['user-agent'],
|
|
64
|
-
minify,
|
|
65
|
-
features
|
|
66
|
-
});
|
|
67
|
-
cache.set(cacheKey, polyfill);
|
|
68
|
-
context.res.setHeader('content-type', _mimeTypes.default.contentType('js'));
|
|
69
|
-
return context.res.end(polyfill);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
69
|
+
return context.res.end(polyfill);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
72
|
|
|
73
|
-
})
|
|
74
|
-
name: '@modern-js/plugin-polyfill'
|
|
73
|
+
})
|
|
75
74
|
});
|
|
76
75
|
|
|
77
76
|
exports.default = _default;
|
package/dist/types/cli.d.ts
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
resolved: import("@modern-js/core").NormalizedConfig;
|
|
5
|
-
}>;
|
|
6
|
-
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
7
|
-
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
8
|
-
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
9
|
-
program: import("commander").Command;
|
|
10
|
-
}, void>;
|
|
11
|
-
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
12
|
-
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
13
|
-
filename: string;
|
|
14
|
-
eventType: "add" | "unlink" | "change";
|
|
15
|
-
}, void>;
|
|
16
|
-
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
17
|
-
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
18
|
-
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
1
|
+
import type { CliPlugin } from '@modern-js/core';
|
|
2
|
+
|
|
3
|
+
declare const _default: () => CliPlugin;
|
|
19
4
|
|
|
20
5
|
export default _default;
|
package/dist/types/index.d.ts
CHANGED
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.5",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@babel/runtime": "^7",
|
|
40
40
|
"@modern-js/polyfill-lib": "^1.0.0",
|
|
41
|
-
"@modern-js/server-core": "^1.2.2",
|
|
42
41
|
"lru-cache": "^6.0.0",
|
|
43
42
|
"mime-types": "^2.1.32",
|
|
44
43
|
"ua-parser-js": "^0.7.28"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@modern-js/
|
|
46
|
+
"@modern-js/server-core": "1.3.1",
|
|
47
|
+
"@modern-js/types": "^1.5.0",
|
|
48
48
|
"@types/jest": "^26",
|
|
49
49
|
"@types/lru-cache": "^5.1.1",
|
|
50
50
|
"@types/mime-types": "^2.1.1",
|
|
@@ -53,14 +53,11 @@
|
|
|
53
53
|
"@types/react-dom": "^17",
|
|
54
54
|
"@types/ua-parser-js": "^0.7.36",
|
|
55
55
|
"typescript": "^4",
|
|
56
|
-
"@modern-js/core": "
|
|
56
|
+
"@modern-js/core": "1.8.0",
|
|
57
57
|
"@scripts/build": "0.0.0",
|
|
58
58
|
"jest": "^27",
|
|
59
59
|
"@scripts/jest-config": "0.0.0"
|
|
60
60
|
},
|
|
61
|
-
"peerDependencies": {
|
|
62
|
-
"@modern-js/core": "^1.4.0"
|
|
63
|
-
},
|
|
64
61
|
"sideEffects": false,
|
|
65
62
|
"modernConfig": {
|
|
66
63
|
"output": {
|
|
@@ -69,8 +66,7 @@
|
|
|
69
66
|
},
|
|
70
67
|
"publishConfig": {
|
|
71
68
|
"registry": "https://registry.npmjs.org/",
|
|
72
|
-
"access": "public"
|
|
73
|
-
"types": "./dist/types/index.d.ts"
|
|
69
|
+
"access": "public"
|
|
74
70
|
},
|
|
75
71
|
"scripts": {
|
|
76
72
|
"new": "modern new",
|