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
365
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.6.3-next.86f98ef.0 to 1.6.3-next.c1d82d0.0

4

dist/index.d.ts

@@ -11,7 +11,7 @@ import { PartialMessage, Plugin } from 'esbuild';

fallback?: 'empty' | 'error' | 'none';
formatError?(this: void, args: {
formatError?: (this: void, args: {
importer: string;
moduleName: string;
polyfillExists: boolean;
}): PartialMessage | Promise<PartialMessage>;
}) => PartialMessage | Promise<PartialMessage>;
globals?: {

@@ -18,0 +18,0 @@ Buffer?: boolean;

@@ -26,14 +26,9 @@ 'use strict';

// src/lib/utils/util.ts
var escapeRegex = /* @__PURE__ */ __name((str) => {
return str.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&").replace(/-/g, "\\x2d");
}, "escapeRegex");
var commonJsTemplate = /* @__PURE__ */ __name(({ importPath }) => {
return `export * from '${importPath}'`;
}, "commonJsTemplate");
var normalizeNodeBuiltinPath = /* @__PURE__ */ __name((path2) => {
return path2.replace(/^node:/, "").replace(/\/$/, "");
}, "normalizeNodeBuiltinPath");
var escapeRegex = /* @__PURE__ */ __name((str) => str.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&").replace(/-/g, "\\x2d"), "escapeRegex");
var commonJsTemplate = /* @__PURE__ */ __name(({ importPath }) => `export * from '${importPath}'`, "commonJsTemplate");
var normalizeNodeBuiltinPath = /* @__PURE__ */ __name((path2) => path2.replace(/^node:/, "").replace(/\/$/, ""), "normalizeNodeBuiltinPath");
async function polyfillPath(importPath) {
if (!module$1.builtinModules.includes(importPath))
if (!module$1.builtinModules.includes(importPath)) {
throw new Error(`Node.js does not have ${importPath} in its builtin modules`);
}
const jspmPath = path.resolve(

@@ -61,5 +56,4 @@ __require.resolve(`@jspm/core/nodelibs/${importPath}`),

const cachedPromise = polyfillPathCache.get(normalizedImportPath);
if (cachedPromise) {
if (cachedPromise)
return cachedPromise;
}
const promise = polyfillPath(normalizedImportPath);

@@ -78,5 +72,4 @@ polyfillPathCache.set(normalizedImportPath, promise);

const cachedPromise = polyfillContentCache.get(normalizedImportPath);
if (cachedPromise) {
if (cachedPromise)
return cachedPromise;
}
const promise = polyfillContentAndTransform(normalizedImportPath);

@@ -126,11 +119,8 @@ polyfillContentCache.set(normalizedImportPath, promise);

} = options;
if (namespace.endsWith("commonjs")) {
if (namespace.endsWith("commonjs"))
throw new Error(`namespace ${namespace} must not end with commonjs`);
}
if (namespace.endsWith("empty")) {
if (namespace.endsWith("empty"))
throw new Error(`namespace ${namespace} must not end with empty`);
}
if (namespace.endsWith("error")) {
if (namespace.endsWith("error"))
throw new Error(`namespace ${namespace} must not end with error`);
}
const modules = Array.isArray(modulesOption) ? Object.fromEntries(modulesOption.map((mod) => [mod, true])) : modulesOption;

@@ -148,32 +138,25 @@ const commonjsNamespace = `${namespace}-commonjs`;

const root = initialOptions.absWorkingDir ?? process__default.default.cwd();
if (initialOptions.define && !initialOptions.define.global) {
if (initialOptions.define && !initialOptions.define.global)
initialOptions.define.global = "globalThis";
} else if (!initialOptions.define) {
else if (!initialOptions.define)
initialOptions.define = { global: "globalThis" };
}
initialOptions.inject = initialOptions.inject ?? [];
if (globals.Buffer) {
if (globals.Buffer)
initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/Buffer.js"));
}
if (globals.process) {
if (globals.process)
initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/process.js"));
}
onLoad({ filter: /.*/, namespace: emptyNamespace }, () => {
return {
loader: "js",
// Use an empty CommonJS module here instead of ESM to avoid
// "No matching export" errors in esbuild for anything that
// is imported from this file.
contents: "module.exports = {}"
};
});
onLoad({ filter: /.*/, namespace: errorNamespace }, (args) => {
return {
loader: "js",
contents: `module.exports = ${JSON.stringify(
// This encoded string is detected and parsed at the end of the build to report errors
`__POLYFILL_ERROR_START__::MODULE::${args.path}::IMPORTER::${args.pluginData.importer}::__POLYFILL_ERROR_END__`
)}`
};
});
onLoad({ filter: /.*/, namespace: emptyNamespace }, () => ({
loader: "js",
// Use an empty CommonJS module here instead of ESM to avoid
// "No matching export" errors in esbuild for anything that
// is imported from this file.
contents: "module.exports = {}"
}));
onLoad({ filter: /.*/, namespace: errorNamespace }, (args) => ({
loader: "js",
contents: `module.exports = ${JSON.stringify(
// This encoded string is detected and parsed at the end of the build to report errors
`__POLYFILL_ERROR_START__::MODULE::${args.path}::IMPORTER::${args.pluginData.importer}::__POLYFILL_ERROR_END__`
)}`
}));
onLoad({ filter: /.*/, namespace }, loader);

@@ -206,21 +189,16 @@ onLoad({ filter: /.*/, namespace: commonjsNamespace }, loader);

const browserFieldValueForModule = browserFieldValue?.[args.path];
if (browserFieldValueForModule === false) {
if (browserFieldValueForModule === false)
return result.empty;
}
if (browserFieldValueForModule !== void 0) {
if (browserFieldValueForModule !== void 0)
return;
}
}
const moduleName = normalizeNodeBuiltinPath(args.path);
const polyfillOption = modules[moduleName];
if (!polyfillOption) {
if (!polyfillOption)
return result[fallback];
}
if (polyfillOption === "error" || polyfillOption === "empty") {
if (polyfillOption === "error" || polyfillOption === "empty")
return result[polyfillOption];
}
const polyfillPath2 = await getCachedPolyfillPath(moduleName).catch(() => null);
if (!polyfillPath2) {
if (!polyfillPath2)
return result[fallback];
}
const ignoreRequire = args.namespace === commonjsNamespace;

@@ -227,0 +205,0 @@ const isCommonjs = !ignoreRequire && args.kind === "require-call";

{
"name": "esbuild-plugins-node-modules-polyfill",
"version": "1.6.3-next.86f98ef.0",
"version": "1.6.3-next.c1d82d0.0",
"description": "Polyfills nodejs builtin modules and globals for the browser.",

@@ -39,18 +39,18 @@ "main": "dist/index.js",

"devDependencies": {
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@favware/cliff-jumper": "^2.2.3",
"@favware/npm-deprecate": "^1.0.7",
"@types/node": "^20.11.9",
"@types/node": "^20.11.19",
"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.20.0",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"eslint-config-mahir": "^0.0.36",
"husky": "^9.0.6",
"lint-staged": "^15.2.0",
"eslint-config-mahir": "^0.0.43",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"pinst": "^3.0.0",
"prettier": "^3.2.4",
"tsup": "^8.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"typescript": "^5.3.3",
"vitest": "^1.2.2"
"vitest": "^1.3.0"
},

@@ -94,3 +94,3 @@ "peerDependencies": {

},
"packageManager": "yarn@4.0.2"
"packageManager": "yarn@4.1.0"
}

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

> **Note**
> [!Note]
> If you are utilizing the [`modules`](#configure-which-modules-to-polyfill) option, ensure that you include polyfills for the global modules you are using.

@@ -63,0 +63,0 @@

Sorry, the diff of this file is not supported yet

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