@modern-js/plugin-module-node-polyfill 2.60.4 → 2.60.6
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/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +12 -23
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CliPlugin, ICompiler, ModuleTools } from '@modern-js/module-tools';
|
|
2
2
|
export interface NodePolyfillPluginOptions {
|
|
3
3
|
excludes?: string[];
|
|
4
|
-
overrides?: Partial<Record<keyof typeof
|
|
4
|
+
overrides?: Partial<Record<keyof typeof defualtModules, string>>;
|
|
5
5
|
}
|
|
6
|
-
declare
|
|
6
|
+
declare const defualtModules: {
|
|
7
7
|
assert: string;
|
|
8
8
|
buffer: string;
|
|
9
9
|
child_process: null;
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(src_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("./utils");
|
|
37
|
-
|
|
37
|
+
const defualtModules = {
|
|
38
38
|
assert: require.resolve("assert/"),
|
|
39
39
|
buffer: require.resolve("buffer/"),
|
|
40
40
|
child_process: null,
|
|
@@ -75,11 +75,12 @@ let modules = {
|
|
|
75
75
|
zlib: require.resolve("browserify-zlib")
|
|
76
76
|
};
|
|
77
77
|
const getNodePolyfillHook = (polyfillOption = {}) => {
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const modules = {
|
|
79
|
+
...defualtModules
|
|
80
|
+
};
|
|
80
81
|
var _polyfillOption_excludes;
|
|
81
82
|
const polyfillModules = {
|
|
82
|
-
...(0, import_utils.excludeObjectKeys)((0, import_utils.
|
|
83
|
+
...(0, import_utils.excludeObjectKeys)((0, import_utils.fillResolveAndFallback)(modules, polyfillOption.overrides), (_polyfillOption_excludes = polyfillOption.excludes) !== null && _polyfillOption_excludes !== void 0 ? _polyfillOption_excludes : [])
|
|
83
84
|
};
|
|
84
85
|
const polyfillModulesKeys = Object.keys(polyfillModules);
|
|
85
86
|
return {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export declare function excludeObjectKeys(object: Record<string, string>, keys: string[]): Record<string, string>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function addNodePrefix(modules: Record<string, string | null>): Record<string, string | null>;
|
|
2
|
+
export declare function fillResolveAndFallback(object: Record<string, string | null>, overrides?: Record<string, string>): Record<string, string>;
|
package/dist/utils.js
CHANGED
|
@@ -28,9 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var utils_exports = {};
|
|
30
30
|
__export(utils_exports, {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
excludeObjectKeys: () => excludeObjectKeys
|
|
31
|
+
excludeObjectKeys: () => excludeObjectKeys,
|
|
32
|
+
fillResolveAndFallback: () => fillResolveAndFallback
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(utils_exports);
|
|
36
35
|
var import_path = __toESM(require("path"));
|
|
@@ -46,14 +45,19 @@ function filterObject(object, filter) {
|
|
|
46
45
|
function excludeObjectKeys(object, keys) {
|
|
47
46
|
return filterObject(object, (key) => !keys.includes(key));
|
|
48
47
|
}
|
|
49
|
-
function
|
|
48
|
+
function fillResolveAndFallback(object, overrides = {}) {
|
|
50
49
|
const keys = Object.keys(object);
|
|
51
50
|
const newObject = {};
|
|
52
51
|
for (const key of keys) {
|
|
52
|
+
let resultModule;
|
|
53
53
|
if (object[key] === null) {
|
|
54
|
-
|
|
54
|
+
resultModule = import_path.default.join(__dirname, `./mock/${key}.js`);
|
|
55
55
|
} else {
|
|
56
|
-
|
|
56
|
+
resultModule = object[key];
|
|
57
|
+
}
|
|
58
|
+
newObject[key] = resultModule;
|
|
59
|
+
if (!key.startsWith("_")) {
|
|
60
|
+
newObject[`node:${key}`] = resultModule;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
const overridesKeys = Object.keys(overrides);
|
|
@@ -64,23 +68,8 @@ function addResolveFallback(object, overrides = {}) {
|
|
|
64
68
|
}
|
|
65
69
|
return newObject;
|
|
66
70
|
}
|
|
67
|
-
function addNodePrefix(modules) {
|
|
68
|
-
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
69
|
-
if (!key.startsWith("_")) {
|
|
70
|
-
return [
|
|
71
|
-
`node:${key}`,
|
|
72
|
-
value
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
|
-
return [
|
|
76
|
-
key,
|
|
77
|
-
value
|
|
78
|
-
];
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
72
|
0 && (module.exports = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
excludeObjectKeys
|
|
73
|
+
excludeObjectKeys,
|
|
74
|
+
fillResolveAndFallback
|
|
86
75
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/plugin-module-node-polyfill",
|
|
3
|
-
"version": "2.60.
|
|
3
|
+
"version": "2.60.6",
|
|
4
4
|
"description": "The node polyfill plugin of Modern.js Module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"buffer": "6.0.3",
|
|
26
26
|
"console-browserify": "1.2.0",
|
|
27
27
|
"constants-browserify": "1.0.0",
|
|
28
|
-
"crypto-browserify": "3.12.
|
|
28
|
+
"crypto-browserify": "3.12.1",
|
|
29
29
|
"domain-browser": "4.19.0",
|
|
30
30
|
"events": "3.3.0",
|
|
31
31
|
"filter-obj": "2.0.2",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^14",
|
|
50
50
|
"typescript": "^5",
|
|
51
|
-
"@modern-js/module-tools": "2.60.
|
|
52
|
-
"@scripts/build": "2.60.
|
|
51
|
+
"@modern-js/module-tools": "2.60.6",
|
|
52
|
+
"@scripts/build": "2.60.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@modern-js/module-tools": "^2.60.
|
|
55
|
+
"@modern-js/module-tools": "^2.60.6"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@modern-js/module-tools": {
|