Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-plugins-node-modules-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
369
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugins-node-modules-polyfill - npm Package Compare versions

Comparing version 1.5.0-next.c02060d.0 to 1.5.0

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Changelog

# [1.5.0](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/compare/v1.4.1...v1.5.0) - (2023-08-24)
## 🐛 Bug Fixes
- Use empty polyfill if browser field is false (#151) ([3946db8](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/commit/3946db8eca299559b708fdc1b0863b9d4582ef2c))
## 📝 Documentation
- Update readme ([12bc0dd](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/commit/12bc0dd100b138910f91d80f569815cbbe59fa12))
## 🚀 Features
- Allow modules to be marked as errors (#152) ([c02060d](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/commit/c02060d2c854b874fce98a2e4bada314f524faa6))
# [1.4.1](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/compare/v1.4.0...v1.4.1) - (2023-08-23)

@@ -7,0 +21,0 @@

2

package.json
{
"name": "esbuild-plugins-node-modules-polyfill",
"version": "1.5.0-next.c02060d.0",
"version": "1.5.0",
"description": "Polyfills nodejs builtin modules and globals for the browser.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -43,3 +43,3 @@ <div align="center">

Optionally configure which modules to polyfill:
### Inject globals when detected:

@@ -50,9 +50,14 @@ ```ts

build({
plugins: [nodeModulesPolyfillPlugin({
modules: ['crypto'],
})],
plugins: [
nodeModulesPolyfillPlugin({
globals: {
process: true,
Buffer: true,
},
}),
],
});
```
Optionally provide empty polyfills:
### Configure which modules to polyfill:

@@ -63,13 +68,29 @@ ```ts

build({
plugins: [nodeModulesPolyfillPlugin({
modules: {
fs: 'empty',
crypto: true,
}
})],
plugins: [
nodeModulesPolyfillPlugin({
modules: ['crypto'],
}),
],
});
```
Optionally provide empty fallbacks for any unpolyfilled or unconfigured modules:
```ts
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
modules: {
crypto: true,
fs: false,
},
}),
],
});
```
### Provide empty polyfills:
#### Provide empty polyfills for specific modules:
```ts

@@ -79,12 +100,14 @@ import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';

build({
plugins: [nodeModulesPolyfillPlugin({
fallback: 'empty',
modules: {
crypto: true,
}
})],
plugins: [
nodeModulesPolyfillPlugin({
modules: {
fs: 'empty',
crypto: true,
},
}),
],
});
```
Optionally inject globals when detected:
#### Provide empty fallbacks for any unpolyfilled modules:

@@ -95,12 +118,11 @@ ```ts

build({
plugins: [nodeModulesPolyfillPlugin({
globals: {
process: true,
Buffer: true,
}
})],
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'empty',
}),
],
});
```
Optionally fail the build when certain modules are used (note that the `write` build option must be `false` to support this):
#### Provide empty fallbacks for any unconfigured modules:

@@ -110,15 +132,40 @@ ```ts

import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'empty',
modules: {
crypto: true,
},
}),
],
});
```
### Fail the build when certain modules are used:
> **Warn**
> The `write` option in `esbuild` must be `false` to support this.
```ts
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
const buildResult = await build({
write: false,
plugins: [nodeModulesPolyfillPlugin({
modules: {
crypto: 'error',
path: true,
},
})],
plugins: [
nodeModulesPolyfillPlugin({
modules: {
crypto: 'error',
path: true,
},
}),
],
});
```
Optionally fail the build when a module is not polyfilled or configured (note that the `write` build option must be `false` to support this):
### Fail the build when a module is not polyfilled or configured:
> **Warn**
> The `write` option in `esbuild` must be `false` to support this.
```ts

@@ -129,8 +176,10 @@ import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';

write: false,
plugins: [nodeModulesPolyfillPlugin({
fallback: 'error',
modules: {
path: true,
}
})],
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'error',
modules: {
path: true,
},
}),
],
});

@@ -137,0 +186,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc