@modern-js/plugin-polyfill 2.15.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 CHANGED
@@ -1,5 +1,18 @@
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
+
3
16
  ## 2.15.0
4
17
 
5
18
  ### Patch Changes
package/dist/cjs/cli.js CHANGED
@@ -1,45 +1,32 @@
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
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
21
4
  });
22
- module.exports = __toCommonJS(cli_exports);
23
- var import_const = require("./const");
24
- var cli_default = () => ({
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 { partials, entrypoint };
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 { plugins };
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
- 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) => {
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
- __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, {
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: { flags: ["gated"] }
27
- });
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {
30
- defaultPolyfill,
31
- getDefaultFeatures
18
+ es6: {
19
+ flags: [
20
+ "gated"
21
+ ]
22
+ }
32
23
  });
package/dist/cjs/index.js CHANGED
@@ -1,50 +1,73 @@
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
- // 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
- module.exports = __toCommonJS(src_exports);
33
- var import_polyfill_lib = require("@modern-js/polyfill-lib");
34
- var import_utils = require("@modern-js/utils");
35
- var import_ua_parser_js = __toESM(require("ua-parser-js"));
36
- var import_const = require("./const");
37
- var import_cache = __toESM(require("./libs/cache"));
38
- var src_default = () => ({
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 import_cache.default();
43
- const route = import_const.defaultPolyfill;
44
- const features = (0, import_const.getDefaultFeatures)();
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 = ["gated"] } = features[name];
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, import_ua_parser_js.default)(context.headers["user-agent"]);
78
+ const parsedUA = (0, _uaparserjs.default)(context.headers["user-agent"]);
56
79
  const { name = "", version = "" } = parsedUA.browser;
57
- const cacheKey = (0, import_cache.generateCacheKey)({
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, import_polyfill_lib.getPolyfillString)({
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", import_utils.mime.contentType("js"));
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 = {});
@@ -1,41 +1,41 @@
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) => {
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
- __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 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
- module.exports = __toCommonJS(cache_exports);
34
- var import_crypto = __toESM(require("crypto"));
35
- var import_lru_cache = __toESM(require("lru-cache"));
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 import_lru_cache.default(1e4);
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 = import_crypto.default.createHmac("sha256", "^polyfill$").update(str).digest("hex");
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
- 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
+ "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
- 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
- };
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
- export { cli_default as default };
27
+ };
28
+ }
29
+ };
30
+ }
31
+ ;
package/dist/esm/const.js CHANGED
@@ -1,11 +1,10 @@
1
- var defaultPolyfill = "/__polyfill__";
2
- var getDefaultFeatures = function() {
3
- return {
4
- es6: {
5
- flags: [
6
- "gated"
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
- 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
- }
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 _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
- };
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 = 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: []
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
- 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) {
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
- 6,
112
- e
83
+ 0
113
84
  ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
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
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
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
- 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
- }();
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
- export { src_default as default };
206
+ };
207
+ }
208
+ };
209
+ }
210
+ ;
@@ -1,77 +1,80 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
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
- 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
- }
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 _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
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 _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;
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
- 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;
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 = /*#__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
- });
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
- _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;
77
+ ]);
78
+ return Cache2;
76
79
  }();
77
- export { Cache as default, generateCacheKey };
80
+ export { Cache as default };
package/dist/esm/type.js CHANGED
@@ -1 +1 @@
1
- "use strict";
1
+ export {};
@@ -1,24 +1,24 @@
1
1
  import { defaultPolyfill } from "./const";
2
- var cli_default = () => ({
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 { partials, entrypoint };
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 { plugins };
19
+ return {
20
+ plugins
21
+ };
19
22
  }
20
23
  })
21
24
  });
22
- export {
23
- cli_default as default
24
- };
@@ -1,8 +1,8 @@
1
- const defaultPolyfill = "/__polyfill__";
2
- const getDefaultFeatures = () => ({
3
- es6: { flags: ["gated"] }
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
- };
@@ -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
- var src_default = () => ({
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 = ["gated"] } = features[name];
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 };
@@ -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": "web-infra-dev/modern.js",
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.15.0",
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.15.0"
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.15.0",
60
- "@modern-js/app-tools": "2.15.0",
61
- "@modern-js/types": "2.15.0",
62
- "@modern-js/core": "2.15.0",
63
- "@scripts/build": "2.15.0",
64
- "@scripts/jest-config": "2.15.0"
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": {