@modern-js/plugin-module-node-polyfill 0.0.0-next-20241106094038 → 0.0.0-next-20241107125533

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 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 defualtModules, string>>;
4
+ overrides?: Partial<Record<keyof typeof modules, string>>;
5
5
  }
6
- declare const defualtModules: {
6
+ declare let modules: {
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
- const defualtModules = {
37
+ let modules = {
38
38
  assert: require.resolve("assert/"),
39
39
  buffer: require.resolve("buffer/"),
40
40
  child_process: null,
@@ -75,12 +75,11 @@ const defualtModules = {
75
75
  zlib: require.resolve("browserify-zlib")
76
76
  };
77
77
  const getNodePolyfillHook = (polyfillOption = {}) => {
78
- const modules = {
79
- ...defualtModules
80
- };
78
+ const nodeModules = (0, import_utils.addNodePrefix)(modules);
79
+ modules = Object.assign(modules, nodeModules);
81
80
  var _polyfillOption_excludes;
82
81
  const polyfillModules = {
83
- ...(0, import_utils.excludeObjectKeys)((0, import_utils.fillResolveAndFallback)(modules, polyfillOption.overrides), (_polyfillOption_excludes = polyfillOption.excludes) !== null && _polyfillOption_excludes !== void 0 ? _polyfillOption_excludes : [])
82
+ ...(0, import_utils.excludeObjectKeys)((0, import_utils.addResolveFallback)(modules, polyfillOption.overrides), (_polyfillOption_excludes = polyfillOption.excludes) !== null && _polyfillOption_excludes !== void 0 ? _polyfillOption_excludes : [])
84
83
  };
85
84
  const polyfillModulesKeys = Object.keys(polyfillModules);
86
85
  return {
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function excludeObjectKeys(object: Record<string, string>, keys: string[]): Record<string, string>;
2
- export declare function fillResolveAndFallback(object: Record<string, string | null>, overrides?: Record<string, string>): Record<string, string>;
2
+ export declare function addResolveFallback(object: Record<string, string | null>, overrides?: Record<string, string>): Record<string, string>;
3
+ export declare function addNodePrefix(modules: Record<string, string | null>): Record<string, string | null>;
package/dist/utils.js CHANGED
@@ -28,8 +28,9 @@ 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
- excludeObjectKeys: () => excludeObjectKeys,
32
- fillResolveAndFallback: () => fillResolveAndFallback
31
+ addNodePrefix: () => addNodePrefix,
32
+ addResolveFallback: () => addResolveFallback,
33
+ excludeObjectKeys: () => excludeObjectKeys
33
34
  });
34
35
  module.exports = __toCommonJS(utils_exports);
35
36
  var import_path = __toESM(require("path"));
@@ -45,19 +46,14 @@ function filterObject(object, filter) {
45
46
  function excludeObjectKeys(object, keys) {
46
47
  return filterObject(object, (key) => !keys.includes(key));
47
48
  }
48
- function fillResolveAndFallback(object, overrides = {}) {
49
+ function addResolveFallback(object, overrides = {}) {
49
50
  const keys = Object.keys(object);
50
51
  const newObject = {};
51
52
  for (const key of keys) {
52
- let resultModule;
53
53
  if (object[key] === null) {
54
- resultModule = import_path.default.join(__dirname, `./mock/${key}.js`);
54
+ newObject[key] = import_path.default.join(__dirname, `./mock/${key}.js`);
55
55
  } else {
56
- resultModule = object[key];
57
- }
58
- newObject[key] = resultModule;
59
- if (!key.startsWith("_")) {
60
- newObject[`node:${key}`] = resultModule;
56
+ newObject[key] = object[key];
61
57
  }
62
58
  }
63
59
  const overridesKeys = Object.keys(overrides);
@@ -68,8 +64,23 @@ function fillResolveAndFallback(object, overrides = {}) {
68
64
  }
69
65
  return newObject;
70
66
  }
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
+ }
71
81
  // Annotate the CommonJS export names for ESM import in node:
72
82
  0 && (module.exports = {
73
- excludeObjectKeys,
74
- fillResolveAndFallback
83
+ addNodePrefix,
84
+ addResolveFallback,
85
+ excludeObjectKeys
75
86
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/plugin-module-node-polyfill",
3
- "version": "0.0.0-next-20241106094038",
3
+ "version": "0.0.0-next-20241107125533",
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.1",
28
+ "crypto-browserify": "3.12.0",
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": "0.0.0-next-20241106094038",
52
- "@scripts/build": "0.0.0-next-20241106094038"
51
+ "@modern-js/module-tools": "0.0.0-next-20241107125533",
52
+ "@scripts/build": "0.0.0-next-20241107125533"
53
53
  },
54
54
  "peerDependencies": {
55
- "@modern-js/module-tools": "0.0.0-next-20241106094038"
55
+ "@modern-js/module-tools": "0.0.0-next-20241107125533"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "@modern-js/module-tools": {