@rsbuild/plugin-node-polyfill 1.0.1 → 1.0.4

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @rsbuild/plugin-node-polyfill
2
2
 
3
- @rsbuild/plugin-node-polyfill is a Rsbuild plugin to do something.
3
+ An Rsbuild plugin to automatically inject polyfills for [Node.js builtin modules](https://nodejs.org/api/modules.html#built-in-modules) into the browser side.
4
4
 
5
5
  <p>
6
6
  <a href="https://npmjs.com/package/@rsbuild/plugin-node-polyfill">
@@ -9,6 +9,12 @@
9
9
  <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10
10
  </p>
11
11
 
12
+ ## When to use
13
+
14
+ Normally, we don't need to use Node builtin modules on the browser side. However, it is possible to use some Node builtin modules when the code will run on both the Node side and the browser side, and this plugin provides browser versions of polyfills for these Node builtin modules.
15
+
16
+ By using the Node Polyfill plugin, polyfills for Node builtin modules are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.
17
+
12
18
  ## Usage
13
19
 
14
20
  Install:
package/dist/index.cjs CHANGED
@@ -20,10 +20,10 @@ var __copyProps = (to, from, except, desc) => {
20
20
  };
21
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
22
 
23
- // node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js
23
+ // node_modules/.pnpm/tsup@8.0.2_postcss@8.4.39_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js
24
24
  var getImportMetaUrl, importMetaUrl;
25
25
  var init_cjs_shims = __esm({
26
- "node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js"() {
26
+ "node_modules/.pnpm/tsup@8.0.2_postcss@8.4.39_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js"() {
27
27
  "use strict";
28
28
  getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
29
29
  importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
@@ -191,14 +191,14 @@ function pluginNodePolyfill(options = {}) {
191
191
  return {
192
192
  name: PLUGIN_NODE_POLYFILL_NAME,
193
193
  setup(api) {
194
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, bundler }) => {
194
+ api.modifyBundlerChain(async (chain, { isServer, bundler }) => {
195
195
  if (isServer) {
196
196
  return;
197
197
  }
198
198
  chain.resolve.fallback.merge(getResolveFallback(protocolImports));
199
199
  const provideGlobals = await getProvideGlobals(options.globals);
200
200
  if (Object.keys(provideGlobals).length) {
201
- chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
201
+ chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
202
202
  }
203
203
  if (protocolImports) {
204
204
  const { ProtocolImportsPlugin: ProtocolImportsPlugin2 } = await Promise.resolve().then(() => (init_ProtocolImportsPlugin(), ProtocolImportsPlugin_exports));
package/dist/index.js CHANGED
@@ -123,14 +123,14 @@ function pluginNodePolyfill(options = {}) {
123
123
  return {
124
124
  name: PLUGIN_NODE_POLYFILL_NAME,
125
125
  setup(api) {
126
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, bundler }) => {
126
+ api.modifyBundlerChain(async (chain, { isServer, bundler }) => {
127
127
  if (isServer) {
128
128
  return;
129
129
  }
130
130
  chain.resolve.fallback.merge(getResolveFallback(protocolImports));
131
131
  const provideGlobals = await getProvideGlobals(options.globals);
132
132
  if (Object.keys(provideGlobals).length) {
133
- chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
133
+ chain.plugin("node-polyfill-provide").use(bundler.ProvidePlugin, [provideGlobals]);
134
134
  }
135
135
  if (protocolImports) {
136
136
  const { ProtocolImportsPlugin } = await import("./ProtocolImportsPlugin-HUSWFIAE.js");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-node-polyfill",
3
- "version": "1.0.1",
4
- "repository": "https://github.com/rspack-contrib/rsbuild-plugin-template",
3
+ "version": "1.0.4",
4
+ "repository": "https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
@@ -53,7 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@biomejs/biome": "^1.8.3",
55
55
  "@playwright/test": "^1.44.1",
56
- "@rsbuild/core": "^0.7.10",
56
+ "@rsbuild/core": "^1.0.1-beta.10",
57
57
  "@types/node": "^20.14.1",
58
58
  "nano-staged": "^0.8.0",
59
59
  "playwright": "^1.44.1",
@@ -62,7 +62,7 @@
62
62
  "typescript": "^5.5.2"
63
63
  },
64
64
  "peerDependencies": {
65
- "@rsbuild/core": "0.x || 1.x"
65
+ "@rsbuild/core": "1.x || ^1.0.1-beta.0"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "@rsbuild/core": {