UNPKG

@lit-protocol/esbuild-plugin-polyfill-node

Version:

ESBuild plugin for polyfilling Node.js builtins for edge and Deno

157 lines (154 loc) 5.09 kB
import { Plugin } from 'esbuild'; interface PolyfillNodeOptions { /** * Whether to inject globals. * * Set to `false` to disable all globals. */ globals?: false | { /** * Whether to inject the `global` global. * * It is set as an alias of `globalThis`. * * @default true */ global?: boolean; /** * Whether to inject the `__dirname` global. * * Always defined as `/`. * * @default true */ __dirname?: boolean; /** * Whether to inject the `__filename` global. * * Always defined as `/index.js`. * * @default true */ __filename?: boolean; /** * Whether to inject the `Buffer` global. * * Disable it to prevent code like `if (typeof Buffer !== "undefined")` * from pulling in the (quite large) Buffer polyfill. * * @default true */ buffer?: boolean; /** * Whether to inject the `process` global. * * Disable it to prevent `process.env.NODE_ENV` from pulling in the * `process-es6` polyfill. You can use the `define` option to replace * `process.env.NODE_ENV` instead. * * @default true */ process?: boolean; /** * Whether to inject the `navigator` global. * * It is used by some of the polyfills. * * @default false */ navigator?: boolean; denoBuildOs?: string | false; }; polyfills?: { _stream_duplex?: boolean | "empty"; _stream_passthrough?: boolean | "empty"; _stream_readable?: boolean | "empty"; _stream_transform?: boolean | "empty"; _stream_writable?: boolean | "empty"; assert?: boolean | "empty"; "assert/strict"?: boolean | "empty"; async_hooks?: boolean | "empty"; buffer?: boolean | "empty"; child_process?: boolean | "empty"; cluster?: boolean | "empty"; console?: boolean | "empty"; constants?: boolean | "empty"; crypto?: boolean | "empty"; dgram?: boolean | "empty"; diagnostics_channel?: boolean | "empty"; dns?: boolean | "empty"; domain?: boolean | "empty"; events?: boolean | "empty"; fs?: boolean | "empty"; "fs/promises"?: boolean | "empty"; http?: boolean | "empty"; http2?: boolean | "empty"; https?: boolean | "empty"; module?: boolean | "empty"; net?: boolean | "empty"; os?: boolean | "empty"; path?: boolean | "empty"; perf_hooks?: boolean | "empty"; process?: boolean | "empty"; punycode?: boolean | "empty"; querystring?: boolean | "empty"; readline?: boolean | "empty"; repl?: boolean | "empty"; stream?: boolean | "empty"; string_decoder?: boolean | "empty"; sys?: boolean | "empty"; timers?: boolean | "empty"; "timers/promises"?: boolean | "empty"; tls?: boolean | "empty"; tty?: boolean | "empty"; url?: boolean | "empty"; util?: boolean | "empty"; v8?: boolean | "empty"; vm?: boolean | "empty"; wasi?: boolean | "empty"; worker_threads?: boolean | "empty"; zlib?: boolean | "empty"; }; } declare function polyfillNode(options?: PolyfillNodeOptions): Plugin; interface PolyfillNodeForDenoOptions { stdVersion?: string; globals?: boolean; polyfills?: { assert?: boolean | "empty"; "assert/strict"?: boolean | "empty"; buffer?: boolean | "empty"; child_process?: boolean | "empty"; console?: boolean | "empty"; constants?: boolean | "empty"; crypto?: boolean | "empty"; domain?: false | "empty"; events?: boolean | "empty"; fs?: boolean | "empty"; "fs/promises"?: boolean | "empty"; http?: boolean | "empty"; https?: boolean | "empty"; module?: boolean | "empty"; net?: boolean | "empty"; os?: boolean | "empty"; path?: boolean | "empty"; perf_hooks?: boolean | "empty"; process?: boolean | "empty"; punycode?: false | "empty"; querystring?: boolean | "empty"; readline?: boolean | "empty"; stream?: boolean | "empty"; string_decoder?: boolean | "empty"; sys?: boolean | "empty"; timers?: boolean | "empty"; "timers/promises"?: boolean | "empty"; tty?: boolean | "empty"; url?: boolean | "empty"; util?: boolean | "empty"; vm?: false | "empty"; worker_threads?: boolean | "empty"; zlib?: false | "empty"; }; } declare function polyfillNodeForDeno(options?: PolyfillNodeForDenoOptions): Plugin; export { type PolyfillNodeForDenoOptions, type PolyfillNodeOptions, polyfillNode, polyfillNodeForDeno };