@modern-js/plugin-module-node-polyfill 2.35.0 → 2.36.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.
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ export namespace buffer {
3
+ export { Buffer };
4
+ }
5
+ import Buffer from 'buffer';
6
+ export { processBrowser as process, console };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var globals_exports = {};
30
+ __export(globals_exports, {
31
+ buffer: () => buffer,
32
+ console: () => import_console_browserify.default,
33
+ process: () => import_browser.default
34
+ });
35
+ module.exports = __toCommonJS(globals_exports);
36
+ var import_buffer = __toESM(require("buffer"));
37
+ var import_browser = __toESM(require("process/browser"));
38
+ var import_console_browserify = __toESM(require("console-browserify"));
39
+ const buffer = {
40
+ Buffer: import_buffer.default
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ buffer,
45
+ console,
46
+ process
47
+ });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,50 @@
1
- import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';
2
- import type { NodePolyfillPluginOptions } from '@modern-js/libuild-plugin-node-polyfill';
1
+ import type { CliPlugin, ModuleTools, ICompiler } from '@modern-js/module-tools';
2
+ export interface NodePolyfillPluginOptions {
3
+ excludes?: string[];
4
+ overrides?: Partial<Record<keyof typeof modules, string>>;
5
+ }
6
+ export declare const modules: {
7
+ assert: string;
8
+ buffer: string;
9
+ child_process: null;
10
+ cluster: null;
11
+ console: string;
12
+ constants: string;
13
+ crypto: string;
14
+ dgram: null;
15
+ dns: null;
16
+ domain: string;
17
+ events: string;
18
+ fs: null;
19
+ http: string;
20
+ https: string;
21
+ module: null;
22
+ net: null;
23
+ os: string;
24
+ path: string;
25
+ punycode: string;
26
+ process: string;
27
+ querystring: string;
28
+ readline: null;
29
+ repl: null;
30
+ stream: string;
31
+ _stream_duplex: string;
32
+ _stream_passthrough: string;
33
+ _stream_readable: string;
34
+ _stream_transform: string;
35
+ _stream_writable: string;
36
+ string_decoder: string;
37
+ sys: string;
38
+ timers: string;
39
+ tls: null;
40
+ tty: string;
41
+ url: string;
42
+ util: string;
43
+ vm: string;
44
+ zlib: string;
45
+ };
46
+ export declare const getNodePolyfillHook: (polyfillOption?: NodePolyfillPluginOptions) => {
47
+ name: string;
48
+ apply(compiler: ICompiler): void;
49
+ };
3
50
  export declare const modulePluginNodePolyfill: (polyfillOption?: NodePolyfillPluginOptions) => CliPlugin<ModuleTools>;
package/dist/index.js CHANGED
@@ -1,26 +1,137 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "modulePluginNodePolyfill", {
6
- enumerable: true,
7
- get: function() {
8
- return modulePluginNodePolyfill;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
17
  }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ getNodePolyfillHook: () => getNodePolyfillHook,
32
+ modulePluginNodePolyfill: () => modulePluginNodePolyfill,
33
+ modules: () => modules
10
34
  });
11
- const _libuildpluginnodepolyfill = require("@modern-js/libuild-plugin-node-polyfill");
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_utils = require("./utils");
38
+ const modules = {
39
+ assert: require.resolve("assert/"),
40
+ buffer: require.resolve("buffer/"),
41
+ child_process: null,
42
+ cluster: null,
43
+ console: require.resolve("console-browserify"),
44
+ constants: require.resolve("constants-browserify"),
45
+ crypto: require.resolve("crypto-browserify"),
46
+ dgram: null,
47
+ dns: null,
48
+ domain: require.resolve("domain-browser"),
49
+ events: require.resolve("events/"),
50
+ fs: null,
51
+ http: require.resolve("stream-http"),
52
+ https: require.resolve("https-browserify"),
53
+ module: null,
54
+ net: null,
55
+ os: require.resolve("os-browserify/browser"),
56
+ path: require.resolve("path-browserify"),
57
+ punycode: require.resolve("punycode/"),
58
+ process: require.resolve("process/browser"),
59
+ querystring: require.resolve("querystring-es3"),
60
+ readline: null,
61
+ repl: null,
62
+ stream: require.resolve("stream-browserify"),
63
+ _stream_duplex: require.resolve("readable-stream/lib/_stream_duplex"),
64
+ _stream_passthrough: require.resolve("readable-stream/lib/_stream_passthrough"),
65
+ _stream_readable: require.resolve("readable-stream/lib/_stream_readable"),
66
+ _stream_transform: require.resolve("readable-stream/lib/_stream_transform"),
67
+ _stream_writable: require.resolve("readable-stream/lib/_stream_writable"),
68
+ string_decoder: require.resolve("string_decoder/"),
69
+ sys: require.resolve("util/"),
70
+ timers: require.resolve("timers-browserify"),
71
+ tls: null,
72
+ tty: require.resolve("tty-browserify"),
73
+ url: require.resolve("url/"),
74
+ util: require.resolve("util/"),
75
+ vm: require.resolve("vm-browserify"),
76
+ zlib: require.resolve("browserify-zlib")
77
+ };
78
+ const getNodePolyfillHook = (polyfillOption = {}) => {
79
+ var _polyfillOption_excludes;
80
+ const polyfillModules = {
81
+ ...(0, import_utils.excludeObjectKeys)((0, import_utils.addResolveFallback)(modules, polyfillOption.overrides), (_polyfillOption_excludes = polyfillOption.excludes) !== null && _polyfillOption_excludes !== void 0 ? _polyfillOption_excludes : [])
82
+ };
83
+ const polyfillModulesKeys = Object.keys(polyfillModules);
84
+ return {
85
+ name: "node-polyfill",
86
+ apply(compiler) {
87
+ const plugins = [
88
+ {
89
+ name: "example",
90
+ setup(build) {
91
+ build.onResolve({
92
+ filter: /.*/
93
+ }, (args) => {
94
+ if (polyfillModulesKeys.includes(args.path)) {
95
+ return {
96
+ path: polyfillModules[args.path]
97
+ };
98
+ }
99
+ return void 0;
100
+ });
101
+ }
102
+ }
103
+ ];
104
+ const lastBuildOptions = compiler.buildOptions;
105
+ var _lastBuildOptions_inject, _lastBuildOptions_plugins;
106
+ compiler.buildOptions = {
107
+ ...lastBuildOptions,
108
+ inject: [
109
+ ...(_lastBuildOptions_inject = lastBuildOptions.inject) !== null && _lastBuildOptions_inject !== void 0 ? _lastBuildOptions_inject : [],
110
+ import_path.default.join(__dirname, "globals.js")
111
+ ],
112
+ plugins: [
113
+ plugins[0],
114
+ ...(_lastBuildOptions_plugins = lastBuildOptions.plugins) !== null && _lastBuildOptions_plugins !== void 0 ? _lastBuildOptions_plugins : []
115
+ ]
116
+ };
117
+ }
118
+ };
119
+ };
12
120
  const modulePluginNodePolyfill = (polyfillOption = {}) => ({
13
- name: "polyfill-plugin",
121
+ name: "@modern-js/plugin-module-node-polyfill",
14
122
  setup() {
15
123
  return {
16
- modifyLibuild(config, next) {
17
- var _config_plugins;
18
- config.plugins = [
19
- ...(_config_plugins = config.plugins) !== null && _config_plugins !== void 0 ? _config_plugins : [],
20
- (0, _libuildpluginnodepolyfill.nodePolyfillPlugin)(polyfillOption)
21
- ];
22
- return next(config);
124
+ beforeBuildTask(config) {
125
+ const hook = getNodePolyfillHook(polyfillOption);
126
+ config.hooks.push(hook);
127
+ return config;
23
128
  }
24
129
  };
25
130
  }
26
131
  });
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ getNodePolyfillHook,
135
+ modulePluginNodePolyfill,
136
+ modules
137
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = {};
@@ -0,0 +1,2 @@
1
+ export declare function excludeObjectKeys(object: Record<string, string>, keys: string[]): Record<string, string>;
2
+ export declare function addResolveFallback(object: Record<string, string | null>, overrides?: Record<string, string>): Record<string, string>;
package/dist/utils.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ addResolveFallback: () => addResolveFallback,
32
+ excludeObjectKeys: () => excludeObjectKeys
33
+ });
34
+ module.exports = __toCommonJS(utils_exports);
35
+ var import_path = __toESM(require("path"));
36
+ function filterObject(object, filter) {
37
+ const filtered = {};
38
+ Object.keys(object).forEach((key) => {
39
+ if (filter(key)) {
40
+ filtered[key] = object[key];
41
+ }
42
+ });
43
+ return filtered;
44
+ }
45
+ function excludeObjectKeys(object, keys) {
46
+ return filterObject(object, (key) => !keys.includes(key));
47
+ }
48
+ function addResolveFallback(object, overrides = {}) {
49
+ const keys = Object.keys(object);
50
+ const newObject = {};
51
+ for (const key of keys) {
52
+ if (object[key] === null) {
53
+ newObject[key] = import_path.default.join(__dirname, `./mock/${key}.js`);
54
+ } else {
55
+ newObject[key] = object[key];
56
+ }
57
+ }
58
+ const overridesKeys = Object.keys(overrides);
59
+ for (const key of overridesKeys) {
60
+ if (overrides[key]) {
61
+ newObject[key] = overrides[key];
62
+ }
63
+ }
64
+ return newObject;
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ addResolveFallback,
69
+ excludeObjectKeys
70
+ });
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "@modern-js/plugin-module-node-polyfill",
3
- "description": "The node polyfill plugin of Modern.js Module.",
3
+ "version": "2.36.0",
4
+ "description": "The node polyfill plugin of Modern.js Module",
5
+ "keywords": [
6
+ "react",
7
+ "framework",
8
+ "modern",
9
+ "modern.js"
10
+ ],
4
11
  "homepage": "https://modernjs.dev/module-tools",
5
12
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
13
  "repository": {
@@ -9,44 +16,57 @@
9
16
  "directory": "packages/module/plugin-module-node-polyfill"
10
17
  },
11
18
  "license": "MIT",
12
- "keywords": [
13
- "react",
14
- "framework",
15
- "modern",
16
- "modern.js"
17
- ],
18
- "version": "2.35.0",
19
- "types": "./dist/index.d.ts",
20
19
  "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "dependencies": {
22
+ "@swc/helpers": "0.5.1",
23
+ "assert": "2.0.0",
24
+ "browserify-zlib": "0.2.0",
25
+ "buffer": "6.0.3",
26
+ "console-browserify": "1.2.0",
27
+ "constants-browserify": "1.0.0",
28
+ "crypto-browserify": "3.12.0",
29
+ "domain-browser": "4.19.0",
30
+ "events": "3.3.0",
31
+ "filter-obj": "2.0.2",
32
+ "https-browserify": "1.0.0",
33
+ "os-browserify": "0.3.0",
34
+ "path-browserify": "1.0.1",
35
+ "process": "0.11.10",
36
+ "punycode": "2.1.1",
37
+ "querystring-es3": "0.2.1",
38
+ "readable-stream": "3.6.0",
39
+ "stream-browserify": "3.0.0",
40
+ "stream-http": "3.2.0",
41
+ "string_decoder": "1.3.0",
42
+ "timers-browserify": "2.0.12",
43
+ "tty-browserify": "0.0.1",
44
+ "url": "0.11.0",
45
+ "util": "0.12.4",
46
+ "vm-browserify": "1.1.2"
47
+ },
21
48
  "devDependencies": {
22
- "@types/jest": "^29",
23
49
  "@types/node": "^14",
24
50
  "typescript": "^5",
25
- "jest": "^29",
26
- "@swc/helpers": "0.5.1",
27
- "@modern-js/module-tools": "2.35.0",
28
- "@scripts/jest-config": "2.35.0",
29
- "@scripts/build": "2.35.0"
51
+ "@modern-js/module-tools": "2.36.0",
52
+ "@scripts/build": "2.36.0"
30
53
  },
31
54
  "peerDependencies": {
32
- "@modern-js/module-tools": "^2.35.0"
55
+ "@modern-js/module-tools": "^2.36.0"
33
56
  },
34
57
  "peerDependenciesMeta": {
35
58
  "@modern-js/module-tools": {
36
59
  "optional": true
37
60
  }
38
61
  },
39
- "dependencies": {
40
- "@modern-js/libuild-plugin-node-polyfill": "2.35.0"
41
- },
42
62
  "publishConfig": {
43
- "registry": "https://registry.npmjs.org/",
44
63
  "access": "public",
45
- "provenance": true
64
+ "provenance": true,
65
+ "registry": "https://registry.npmjs.org/"
46
66
  },
47
67
  "scripts": {
48
- "dev": "mdn build --watch",
49
68
  "build": "mdn build",
69
+ "dev": "mdn build --watch",
50
70
  "test": "jest --passWithNoTests"
51
71
  }
52
72
  }