esbuild-plugins-node-modules-polyfill
Advanced tools
Comparing version 1.4.0-next.0dd078c.0 to 1.4.0-next.5b26071.0
@@ -5,2 +5,8 @@ # Changelog | ||
# [1.3.2](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/compare/v1.3.1...v1.3.2) - (2023-08-16) | ||
## 🐛 Bug Fixes | ||
- Support `esbuild` 0.19 (#145) ([d5d0412](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/commit/d5d0412b5e52a6e88a13f13668fc9f0fb6f72f18)) | ||
# [1.3.1](https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/compare/v1.3.0...v1.3.1) - (2023-08-14) | ||
@@ -7,0 +13,0 @@ |
@@ -10,2 +10,3 @@ import { Plugin } from 'esbuild'; | ||
interface NodePolyfillsOptions { | ||
fallback?: 'empty' | 'none'; | ||
globals?: { | ||
@@ -12,0 +13,0 @@ Buffer?: boolean; |
@@ -118,3 +118,3 @@ 'use strict'; | ||
var nodeModulesPolyfillPlugin = /* @__PURE__ */ __name((options = {}) => { | ||
const { globals = {}, modules: modulesOption = module$1.builtinModules, namespace = NAME, name = NAME } = options; | ||
const { globals = {}, modules: modulesOption = module$1.builtinModules, fallback, namespace = NAME, name = NAME } = options; | ||
if (namespace.endsWith("commonjs")) { | ||
@@ -155,20 +155,21 @@ throw new Error(`namespace ${namespace} must not end with commonjs`); | ||
onLoad({ filter: /.*/, namespace: commonjsNamespace }, loader); | ||
const filter = new RegExp( | ||
`^(?:node:)?(?:${Object.keys(modules).filter((moduleName) => module$1.builtinModules.includes(moduleName)).map(escapeRegex).join("|")})$` | ||
); | ||
const bundledModules = fallback === "empty" ? module$1.builtinModules : Object.keys(modules).filter((moduleName) => module$1.builtinModules.includes(moduleName)); | ||
const filter = new RegExp(`^(?:node:)?(?:${bundledModules.map(escapeRegex).join("|")})$`); | ||
const resolver = /* @__PURE__ */ __name(async (args) => { | ||
const moduleName = normalizeNodeBuiltinPath(args.path); | ||
const emptyResult = { | ||
namespace: emptyNamespace, | ||
path: args.path, | ||
sideEffects: false | ||
}; | ||
const fallbackResult = fallback === "empty" ? emptyResult : void 0; | ||
if (!modules[moduleName]) { | ||
return; | ||
return fallbackResult; | ||
} | ||
if (modules[moduleName] === "empty") { | ||
return { | ||
namespace: emptyNamespace, | ||
path: args.path, | ||
sideEffects: false | ||
}; | ||
return emptyResult; | ||
} | ||
const polyfill = await getCachedPolyfillPath(moduleName).catch(() => null); | ||
if (!polyfill) { | ||
return; | ||
return fallbackResult; | ||
} | ||
@@ -175,0 +176,0 @@ const ignoreRequire = args.namespace === commonjsNamespace; |
{ | ||
"name": "esbuild-plugins-node-modules-polyfill", | ||
"version": "1.4.0-next.0dd078c.0", | ||
"version": "1.4.0-next.5b26071.0", | ||
"description": "Polyfills nodejs builtin modules and globals for the browser.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -23,2 +23,3 @@ <div align="center"> | ||
- Optionally injects globals | ||
- Optionally provides empty fallbacks | ||
@@ -69,2 +70,17 @@ ## Install | ||
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({ | ||
fallback: 'empty', | ||
modules: { | ||
crypto: true, | ||
} | ||
})], | ||
}); | ||
``` | ||
Optionally inject globals when detected: | ||
@@ -71,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35926
210
113
1