esbuild-plugins-node-modules-polyfill
Advanced tools
Comparing version 1.6.5-next.77cdbea.0 to 1.6.5-next.83da049.0
@@ -20,4 +20,3 @@ 'use strict'; | ||
}) : x)(function(x) { | ||
if (typeof require !== "undefined") | ||
return require.apply(this, arguments); | ||
if (typeof require !== "undefined") return require.apply(this, arguments); | ||
throw Error('Dynamic require of "' + x + '" is not supported'); | ||
@@ -55,4 +54,3 @@ }); | ||
const cachedPromise = polyfillPathCache.get(normalizedImportPath); | ||
if (cachedPromise) | ||
return cachedPromise; | ||
if (cachedPromise) return cachedPromise; | ||
const promise = polyfillPath(normalizedImportPath); | ||
@@ -71,4 +69,3 @@ polyfillPathCache.set(normalizedImportPath, promise); | ||
const cachedPromise = polyfillContentCache.get(normalizedImportPath); | ||
if (cachedPromise) | ||
return cachedPromise; | ||
if (cachedPromise) return cachedPromise; | ||
const promise = polyfillContentAndTransform(normalizedImportPath); | ||
@@ -118,8 +115,5 @@ polyfillContentCache.set(normalizedImportPath, promise); | ||
} = options; | ||
if (namespace.endsWith("commonjs")) | ||
throw new Error(`namespace ${namespace} must not end with commonjs`); | ||
if (namespace.endsWith("empty")) | ||
throw new Error(`namespace ${namespace} must not end with empty`); | ||
if (namespace.endsWith("error")) | ||
throw new Error(`namespace ${namespace} must not end with error`); | ||
if (namespace.endsWith("commonjs")) throw new Error(`namespace ${namespace} must not end with commonjs`); | ||
if (namespace.endsWith("empty")) throw new Error(`namespace ${namespace} must not end with empty`); | ||
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; | ||
@@ -132,15 +126,11 @@ const commonjsNamespace = `${namespace}-commonjs`; | ||
name, | ||
setup: ({ onLoad, onResolve, onEnd, initialOptions }) => { | ||
setup: /* @__PURE__ */ __name(({ onLoad, onResolve, onEnd, initialOptions }) => { | ||
if (shouldDetectErrorModules && initialOptions.write !== false) | ||
throw new Error(`The "write" build option must be set to false when using the "error" polyfill type`); | ||
const root = initialOptions.absWorkingDir ?? process__default.default.cwd(); | ||
if (initialOptions.define && !initialOptions.define.global) | ||
initialOptions.define.global = "globalThis"; | ||
else if (!initialOptions.define) | ||
initialOptions.define = { global: "globalThis" }; | ||
if (initialOptions.define && !initialOptions.define.global) initialOptions.define.global = "globalThis"; | ||
else if (!initialOptions.define) initialOptions.define = { global: "globalThis" }; | ||
initialOptions.inject = initialOptions.inject ?? []; | ||
if (globals.Buffer) | ||
initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/Buffer.js")); | ||
if (globals.process) | ||
initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/process.js")); | ||
if (globals.Buffer) initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/Buffer.js")); | ||
if (globals.process) initialOptions.inject.push(path__default.default.resolve(__dirname, "../globals/process.js")); | ||
onLoad({ filter: /.*/, namespace: emptyNamespace }, () => ({ | ||
@@ -184,19 +174,13 @@ loader: "js", | ||
const browserFieldValue = packageJson?.browser; | ||
if (typeof browserFieldValue === "string") | ||
return; | ||
if (typeof browserFieldValue === "string") return; | ||
const browserFieldValueForModule = browserFieldValue?.[args.path]; | ||
if (browserFieldValueForModule === false) | ||
return result.empty; | ||
if (browserFieldValueForModule !== void 0) | ||
return; | ||
if (browserFieldValueForModule === false) return result.empty; | ||
if (browserFieldValueForModule !== void 0) return; | ||
} | ||
const moduleName = normalizeNodeBuiltinPath(args.path); | ||
const polyfillOption = modules[moduleName]; | ||
if (!polyfillOption) | ||
return result[fallback]; | ||
if (polyfillOption === "error" || polyfillOption === "empty") | ||
return result[polyfillOption]; | ||
if (!polyfillOption) return result[fallback]; | ||
if (polyfillOption === "error" || polyfillOption === "empty") return result[polyfillOption]; | ||
const polyfillPath2 = await getCachedPolyfillPath(moduleName).catch(() => null); | ||
if (!polyfillPath2) | ||
return result[fallback]; | ||
if (!polyfillPath2) return result[fallback]; | ||
const ignoreRequire = args.namespace === commonjsNamespace; | ||
@@ -212,4 +196,3 @@ const isCommonjs = !ignoreRequire && args.kind === "require-call"; | ||
onEnd(async ({ outputFiles = [] }) => { | ||
if (!shouldDetectErrorModules) | ||
return; | ||
if (!shouldDetectErrorModules) return; | ||
const errors = []; | ||
@@ -235,3 +218,3 @@ const { outfile, outExtension = {} } = initialOptions; | ||
}); | ||
} | ||
}, "setup") | ||
}; | ||
@@ -238,0 +221,0 @@ }, "nodeModulesPolyfillPlugin"); |
{ | ||
"name": "esbuild-plugins-node-modules-polyfill", | ||
"version": "1.6.5-next.77cdbea.0", | ||
"version": "1.6.5-next.83da049.0", | ||
"description": "Polyfills nodejs builtin modules and globals for the browser.", | ||
@@ -43,12 +43,12 @@ "main": "dist/index.js", | ||
"@favware/npm-deprecate": "^1.0.7", | ||
"@types/node": "^20.12.12", | ||
"@types/node": "^20.14.2", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"esbuild": "^0.21.4", | ||
"esbuild": "^0.21.5", | ||
"eslint": "^8.57.0", | ||
"eslint-config-mahir": "^0.0.43", | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.5", | ||
"lint-staged": "^15.2.7", | ||
"pinst": "^3.0.0", | ||
"prettier": "^3.2.5", | ||
"tsup": "^8.0.2", | ||
"prettier": "^3.3.2", | ||
"tsup": "^8.1.0", | ||
"typescript": "^5.4.5", | ||
@@ -94,3 +94,3 @@ "vitest": "^1.6.0" | ||
}, | ||
"packageManager": "yarn@4.2.2" | ||
"packageManager": "yarn@4.3.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
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
49740
237