vite-plugin-node-polyfills
Advanced tools
+2
-2
@@ -1,3 +0,3 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("node:module"),x=require("@rollup/plugin-inject"),O=require("node-stdlib-browser"),P=require("node-stdlib-browser/helpers/rollup/plugin"),R=require("node-stdlib-browser/helpers/esbuild/plugin");var h=typeof document<"u"?document.currentScript:null;const g=l=>l&&l.__esModule?l:{default:l},S=g(x),q=g(O),w=g(R),_=(l,e)=>b(l)===b(e),s=(l,e)=>l?l===!0?!0:l===e:!1,$=l=>l.startsWith("node:"),I=l=>{const e=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${e}$`)},b=l=>l.replace(/^node:/,""),a={buffer:["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill"],global:["import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","globalThis.global = globalThis.global || __global_polyfill"],process:["import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","globalThis.process = globalThis.process || __process_polyfill"]},D=(l={})=>{const e={include:[],exclude:[],overrides:{},protocolImports:!0,...l,globals:{Buffer:!0,global:!0,process:!0,...l.globals}},y=o=>e.include.length>0?!e.include.some(r=>_(o,r)):e.exclude.some(r=>_(o,r)),B=o=>{if(s(e.globals.Buffer,"dev")&&/^buffer$/.test(o))return"vite-plugin-node-polyfills/shims/buffer";if(s(e.globals.global,"dev")&&/^global$/.test(o))return"vite-plugin-node-polyfills/shims/global";if(s(e.globals.process,"dev")&&/^process$/.test(o))return"vite-plugin-node-polyfills/shims/process";if(o in e.overrides)return e.overrides[o]},u=Object.entries(q.default).reduce((o,[r,i])=>(!e.protocolImports&&$(r)||y(r)||(o[r]=B(b(r))||i),o),{}),f=T.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:h&&h.src||new URL("index.cjs",document.baseURI).href),p=[...s(e.globals.Buffer,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/buffer")]:[],...s(e.globals.global,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/global")]:[],...s(e.globals.process,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/process")]:[]],d=[...s(e.globals.Buffer,"dev")?a.buffer:[],...s(e.globals.global,"dev")?a.global:[],...s(e.globals.process,"dev")?a.process:[],""].join(` | ||
| `);return{name:"vite-plugin-node-polyfills",config(o,r){const i=r.command==="serve",v=!!this?.meta?.rolldownVersion,m={...i&&s(e.globals.Buffer,"dev")?{Buffer:"Buffer"}:{},...i&&s(e.globals.global,"dev")?{global:"global"}:{},...i&&s(e.globals.process,"dev")?{process:"process"}:{}},c={...s(e.globals.Buffer,"build")?{Buffer:"vite-plugin-node-polyfills/shims/buffer"}:{},...s(e.globals.global,"build")?{global:"vite-plugin-node-polyfills/shims/global"}:{},...s(e.globals.process,"build")?{process:"vite-plugin-node-polyfills/shims/process"}:{}};return{build:{rollupOptions:{onwarn:(t,n)=>{P.handleCircularDependancyWarning(t,()=>{if(o.build?.rollupOptions?.onwarn)return o.build.rollupOptions.onwarn(t,n);n(t)})},...Object.keys(c).length>0?v?{inject:c}:{plugins:[S.default(c)]}:{}}},esbuild:{banner:i?d:void 0},optimizeDeps:{exclude:[...p],...v?{rollupOptions:{define:m,resolve:{alias:{...u}},plugins:[{name:"vite-plugin-node-polyfills:optimizer",banner:i?d:void 0}]}}:{esbuildOptions:{banner:i?{js:d}:void 0,define:m,inject:[...p],plugins:[w.default(u),{name:"vite-plugin-node-polyfills-shims-resolver",setup(t){for(const n of p){const j=I(n);t.onResolve({filter:j},()=>({external:!1,path:n}))}}}]}}},resolve:{alias:{...u}}}}}};exports.nodePolyfills=D; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("node:module"),w=require("@rollup/plugin-inject"),x=require("node-stdlib-browser"),O=require("node-stdlib-browser/helpers/rollup/plugin"),P=require("node-stdlib-browser/helpers/esbuild/plugin");var h=typeof document<"u"?document.currentScript:null;const g=l=>l&&l.__esModule?l:{default:l},R=g(w),S=g(x),q=g(P),_=(l,e)=>b(l)===b(e),s=(l,e)=>l?l===!0?!0:l===e:!1,$=l=>l.startsWith("node:"),I=l=>{const e=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${e}$`)},b=l=>l.replace(/^node:/,""),a={buffer:["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill"],global:["import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","globalThis.global = globalThis.global || __global_polyfill"],process:["import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","globalThis.process = globalThis.process || __process_polyfill"]},D=(l={})=>{const e={include:[],exclude:[],overrides:{},protocolImports:!0,...l,globals:{Buffer:!0,global:!0,process:!0,...l.globals}},y=o=>e.include.length>0?!e.include.some(r=>_(o,r)):e.exclude.some(r=>_(o,r)),B=o=>{if(s(e.globals.Buffer,"dev")&&/^buffer$/.test(o))return"vite-plugin-node-polyfills/shims/buffer";if(s(e.globals.global,"dev")&&/^global$/.test(o))return"vite-plugin-node-polyfills/shims/global";if(s(e.globals.process,"dev")&&/^process$/.test(o))return"vite-plugin-node-polyfills/shims/process";if(o in e.overrides)return e.overrides[o]},u=Object.entries(S.default).reduce((o,[r,i])=>(!e.protocolImports&&$(r)||y(r)||(o[r]=B(b(r))||i),o),{}),f=T.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:h&&h.src||new URL("index.cjs",document.baseURI).href),p=[...s(e.globals.Buffer,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/buffer")]:[],...s(e.globals.global,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/global")]:[],...s(e.globals.process,"dev")?[f.resolve("vite-plugin-node-polyfills/shims/process")]:[]],d=[...s(e.globals.Buffer,"dev")?a.buffer:[],...s(e.globals.global,"dev")?a.global:[],...s(e.globals.process,"dev")?a.process:[],""].join(` | ||
| `);return{name:"vite-plugin-node-polyfills",config(o,r){const i=r.command==="serve",v=!!this?.meta?.rolldownVersion,m={...i&&s(e.globals.Buffer,"dev")?{Buffer:"Buffer"}:{},...i&&s(e.globals.global,"dev")?{global:"global"}:{},...i&&s(e.globals.process,"dev")?{process:"process"}:{}},c={...s(e.globals.Buffer,"build")?{Buffer:"vite-plugin-node-polyfills/shims/buffer"}:{},...s(e.globals.global,"build")?{global:"vite-plugin-node-polyfills/shims/global"}:{},...s(e.globals.process,"build")?{process:"vite-plugin-node-polyfills/shims/process"}:{}};return{build:{rollupOptions:{onwarn:(t,n)=>{O.handleCircularDependancyWarning(t,()=>{if(o.build?.rollupOptions?.onwarn)return o.build.rollupOptions.onwarn(t,n);n(t)})},...Object.keys(c).length>0?v?{transform:{inject:c}}:{plugins:[R.default(c)]}:{}}},esbuild:{banner:i?d:void 0},optimizeDeps:{exclude:[...p],...v?{rolldownOptions:{resolve:{alias:{...u}},transform:{define:m},plugins:[{name:"vite-plugin-node-polyfills:optimizer",banner:i?d:void 0}]}}:{esbuildOptions:{banner:i?{js:d}:void 0,define:m,inject:[...p],plugins:[q.default(u),{name:"vite-plugin-node-polyfills-shims-resolver",setup(t){for(const n of p){const j=I(n);t.onResolve({filter:j},()=>({external:!1,path:n}))}}}]}}},resolve:{alias:{...u}}}}}};exports.nodePolyfills=D; | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { BooleanOrBuildTarget, ModuleName, ModuleNameWithoutNodePrefix } from './index'\n\nexport const compareModuleNames = (moduleA: ModuleName, moduleB: ModuleName) => {\n return withoutNodeProtocol(moduleA) === withoutNodeProtocol(moduleB)\n}\n\nexport const isEnabled = (value: BooleanOrBuildTarget, mode: 'build' | 'dev') => {\n if (!value) return false\n if (value === true) return true\n\n return value === mode\n}\n\nexport const isNodeProtocolImport = (name: string) => {\n return name.startsWith('node:')\n}\n\nexport const toRegExp = (text: string) => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\n const escapedText = text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return new RegExp(`^${escapedText}$`)\n}\n\nexport const withoutNodeProtocol = (name: ModuleName): ModuleNameWithoutNodePrefix => {\n return name.replace(/^node:/, '') as ModuleNameWithoutNodePrefix\n}\n","import { createRequire } from 'node:module'\nimport inject from '@rollup/plugin-inject'\nimport stdLibBrowser from 'node-stdlib-browser'\nimport { handleCircularDependancyWarning } from 'node-stdlib-browser/helpers/rollup/plugin'\nimport esbuildPlugin from 'node-stdlib-browser/helpers/esbuild/plugin'\nimport type { Plugin } from 'vite'\nimport { compareModuleNames, isEnabled, isNodeProtocolImport, toRegExp, withoutNodeProtocol } from './utils'\n\nexport type BuildTarget = 'build' | 'dev'\nexport type BooleanOrBuildTarget = boolean | BuildTarget\nexport type ModuleName = keyof typeof stdLibBrowser\nexport type ModuleNameWithoutNodePrefix<T = ModuleName> = T extends `node:${infer P}` ? P : never\n\nexport type PolyfillOptions = {\n /**\n * Includes specific modules. If empty, includes all modules\n * @example\n *\n * ```ts\n * nodePolyfills({\n * include: ['fs', 'path'],\n * })\n * ```\n */\n include?: ModuleNameWithoutNodePrefix[],\n /**\n * @example\n *\n * ```ts\n * nodePolyfills({\n * exclude: ['fs', 'path'],\n * })\n * ```\n */\n exclude?: ModuleNameWithoutNodePrefix[],\n /**\n * Specify whether specific globals should be polyfilled.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * globals: {\n * Buffer: false,\n * global: true,\n * process: 'build',\n * },\n * })\n * ```\n */\n globals?: {\n Buffer?: BooleanOrBuildTarget,\n global?: BooleanOrBuildTarget,\n process?: BooleanOrBuildTarget,\n },\n /**\n * Specify alternative modules to use in place of the default polyfills.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * overrides: {\n * fs: 'memfs',\n * },\n * })\n * ```\n */\n overrides?: { [Key in ModuleNameWithoutNodePrefix]?: string },\n /**\n * Specify whether the Node protocol version of an import (e.g. `node:buffer`) should be polyfilled too.\n *\n * @default true\n */\n protocolImports?: boolean,\n}\n\nexport type PolyfillOptionsResolved = {\n include: ModuleNameWithoutNodePrefix[],\n exclude: ModuleNameWithoutNodePrefix[],\n globals: {\n Buffer: BooleanOrBuildTarget,\n global: BooleanOrBuildTarget,\n process: BooleanOrBuildTarget,\n },\n overrides: { [Key in ModuleNameWithoutNodePrefix]?: string },\n protocolImports: boolean,\n}\n\nconst globalShimBanners = {\n buffer: [\n `import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,\n `globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,\n ],\n global: [\n `import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,\n `globalThis.global = globalThis.global || __global_polyfill`,\n ],\n process: [\n `import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,\n `globalThis.process = globalThis.process || __process_polyfill`,\n ],\n}\n\n/**\n * Returns a Vite plugin to polyfill Node's Core Modules for browser environments. Supports `node:` protocol imports.\n *\n * @example\n *\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite'\n * import { nodePolyfills } from 'vite-plugin-node-polyfills'\n *\n * export default defineConfig({\n * plugins: [\n * nodePolyfills({\n * // Specific modules that should not be polyfilled.\n * exclude: [],\n * // Whether to polyfill specific globals.\n * globals: {\n * Buffer: true, // can also be 'build', 'dev', or false\n * global: true,\n * process: true,\n * },\n * // Whether to polyfill `node:` protocol imports.\n * protocolImports: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {\n const optionsResolved: PolyfillOptionsResolved = {\n include: [],\n exclude: [],\n overrides: {},\n protocolImports: true,\n ...options,\n globals: {\n Buffer: true,\n global: true,\n process: true,\n ...options.globals,\n },\n }\n\n const isExcluded = (moduleName: ModuleName) => {\n if (optionsResolved.include.length > 0) {\n return !optionsResolved.include.some((includedName) => compareModuleNames(moduleName, includedName))\n }\n\n return optionsResolved.exclude.some((excludedName) => compareModuleNames(moduleName, excludedName))\n }\n\n const toOverride = (name: ModuleNameWithoutNodePrefix): string | void => {\n if (isEnabled(optionsResolved.globals.Buffer, 'dev') && /^buffer$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/buffer'\n }\n\n if (isEnabled(optionsResolved.globals.global, 'dev') && /^global$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/global'\n }\n\n if (isEnabled(optionsResolved.globals.process, 'dev') && /^process$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/process'\n }\n\n if (name in optionsResolved.overrides) {\n return optionsResolved.overrides[name]\n }\n }\n\n const polyfills = (Object.entries(stdLibBrowser) as Array<[ModuleName, string]>).reduce<Record<ModuleName, string>>((included, [name, value]) => {\n if (!optionsResolved.protocolImports) {\n if (isNodeProtocolImport(name)) {\n return included\n }\n }\n\n if (!isExcluded(name)) {\n included[name] = toOverride(withoutNodeProtocol(name)) || value\n }\n\n return included\n }, {} as Record<ModuleName, string>)\n\n const require = createRequire(import.meta.url)\n const globalShimPaths = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/buffer')] : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/global')] : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/process')] : []),\n ]\n\n const globalShimsBanner = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? globalShimBanners.buffer : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? globalShimBanners.global : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? globalShimBanners.process : []),\n ``,\n ].join('\\n')\n\n return {\n name: 'vite-plugin-node-polyfills',\n config(config, env) {\n const isDev = env.command === 'serve'\n // @ts-expect-error - this.meta.rolldownVersion only exists with rolldown-vite 7+\n const isRolldownVite = !!this?.meta?.rolldownVersion\n\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L203-L209\n const defines = {\n ...((isDev && isEnabled(optionsResolved.globals.Buffer, 'dev')) ? { Buffer: 'Buffer' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.global, 'dev')) ? { global: 'global' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.process, 'dev')) ? { process: 'process' } : {}),\n }\n\n const shimsToInject = {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite\n ...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: 'vite-plugin-node-polyfills/shims/buffer' } : {}),\n ...(isEnabled(optionsResolved.globals.global, 'build') ? { global: 'vite-plugin-node-polyfills/shims/global' } : {}),\n ...(isEnabled(optionsResolved.globals.process, 'build') ? { process: 'vite-plugin-node-polyfills/shims/process' } : {}),\n }\n\n return {\n build: {\n rollupOptions: {\n onwarn: (warning, rollupWarn) => {\n handleCircularDependancyWarning(warning, () => {\n if (config.build?.rollupOptions?.onwarn) {\n return config.build.rollupOptions.onwarn(warning, rollupWarn)\n }\n\n rollupWarn(warning)\n })\n },\n ...Object.keys(shimsToInject).length > 0\n ? isRolldownVite\n ? { inject: shimsToInject }\n : { plugins: [inject(shimsToInject)] }\n : {},\n },\n },\n esbuild: {\n // In dev, the global polyfills need to be injected as a banner in order for isolated scripts (such as Vue SFCs) to have access to them.\n banner: isDev ? globalShimsBanner : undefined,\n },\n optimizeDeps: {\n exclude: [\n ...globalShimPaths,\n ],\n ...isRolldownVite\n ? {\n rollupOptions: {\n define: defines,\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n plugins: [\n {\n name: 'vite-plugin-node-polyfills:optimizer',\n banner: isDev ? globalShimsBanner : undefined,\n },\n ],\n },\n }\n : {\n esbuildOptions: {\n banner: isDev ? { js: globalShimsBanner } : undefined,\n define: defines,\n inject: [\n ...globalShimPaths,\n ],\n plugins: [\n esbuildPlugin(polyfills),\n // Supress the 'injected path \"...\" cannot be marked as external' error in Vite 4 (emitted by esbuild).\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1469\n {\n name: 'vite-plugin-node-polyfills-shims-resolver',\n setup(build) {\n for (const globalShimPath of globalShimPaths) {\n const globalShimsFilter = toRegExp(globalShimPath)\n\n // https://esbuild.github.io/plugins/#on-resolve\n build.onResolve({ filter: globalShimsFilter }, () => {\n return {\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1468\n external: false,\n path: globalShimPath,\n }\n })\n }\n },\n },\n ],\n },\n },\n },\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n }\n },\n }\n}\n"],"names":["compareModuleNames","moduleA","moduleB","withoutNodeProtocol","isEnabled","value","mode","isNodeProtocolImport","name","toRegExp","text","escapedText","globalShimBanners","nodePolyfills","options","optionsResolved","isExcluded","moduleName","includedName","excludedName","toOverride","polyfills","stdLibBrowser","included","require","createRequire","_documentCurrentScript","globalShimPaths","globalShimsBanner","config","env","isDev","isRolldownVite","defines","shimsToInject","warning","rollupWarn","handleCircularDependancyWarning","inject","esbuildPlugin","build","globalShimPath","globalShimsFilter"],"mappings":"sZAEaA,EAAqB,CAACC,EAAqBC,IAC/CC,EAAoBF,CAAO,IAAME,EAAoBD,CAAO,EAGxDE,EAAY,CAACC,EAA6BC,IAChDD,EACDA,IAAU,GAAa,GAEpBA,IAAUC,EAHE,GAMRC,EAAwBC,GAC5BA,EAAK,WAAW,OAAO,EAGnBC,EAAYC,G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ACL,GAAGpB,CACL,CACF,CAAA,CAEJ,CAAA,CAEJ"} | ||
| {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { BooleanOrBuildTarget, ModuleName, ModuleNameWithoutNodePrefix } from './index'\n\nexport const compareModuleNames = (moduleA: ModuleName, moduleB: ModuleName) => {\n return withoutNodeProtocol(moduleA) === withoutNodeProtocol(moduleB)\n}\n\nexport const isEnabled = (value: BooleanOrBuildTarget, mode: 'build' | 'dev') => {\n if (!value) return false\n if (value === true) return true\n\n return value === mode\n}\n\nexport const isNodeProtocolImport = (name: string) => {\n return name.startsWith('node:')\n}\n\nexport const toRegExp = (text: string) => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\n const escapedText = text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return new RegExp(`^${escapedText}$`)\n}\n\nexport const withoutNodeProtocol = (name: ModuleName): ModuleNameWithoutNodePrefix => {\n return name.replace(/^node:/, '') as ModuleNameWithoutNodePrefix\n}\n","import { createRequire } from 'node:module'\nimport inject from '@rollup/plugin-inject'\nimport stdLibBrowser from 'node-stdlib-browser'\nimport { handleCircularDependancyWarning } from 'node-stdlib-browser/helpers/rollup/plugin'\nimport esbuildPlugin from 'node-stdlib-browser/helpers/esbuild/plugin'\nimport type { Plugin } from 'vite'\nimport { compareModuleNames, isEnabled, isNodeProtocolImport, toRegExp, withoutNodeProtocol } from './utils'\n\nexport type BuildTarget = 'build' | 'dev'\nexport type BooleanOrBuildTarget = boolean | BuildTarget\nexport type ModuleName = keyof typeof stdLibBrowser\nexport type ModuleNameWithoutNodePrefix<T = ModuleName> = T extends `node:${infer P}` ? P : never\n\nexport type PolyfillOptions = {\n /**\n * Includes specific modules. If empty, includes all modules\n * @example\n *\n * ```ts\n * nodePolyfills({\n * include: ['fs', 'path'],\n * })\n * ```\n */\n include?: ModuleNameWithoutNodePrefix[],\n /**\n * @example\n *\n * ```ts\n * nodePolyfills({\n * exclude: ['fs', 'path'],\n * })\n * ```\n */\n exclude?: ModuleNameWithoutNodePrefix[],\n /**\n * Specify whether specific globals should be polyfilled.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * globals: {\n * Buffer: false,\n * global: true,\n * process: 'build',\n * },\n * })\n * ```\n */\n globals?: {\n Buffer?: BooleanOrBuildTarget,\n global?: BooleanOrBuildTarget,\n process?: BooleanOrBuildTarget,\n },\n /**\n * Specify alternative modules to use in place of the default polyfills.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * overrides: {\n * fs: 'memfs',\n * },\n * })\n * ```\n */\n overrides?: { [Key in ModuleNameWithoutNodePrefix]?: string },\n /**\n * Specify whether the Node protocol version of an import (e.g. `node:buffer`) should be polyfilled too.\n *\n * @default true\n */\n protocolImports?: boolean,\n}\n\nexport type PolyfillOptionsResolved = {\n include: ModuleNameWithoutNodePrefix[],\n exclude: ModuleNameWithoutNodePrefix[],\n globals: {\n Buffer: BooleanOrBuildTarget,\n global: BooleanOrBuildTarget,\n process: BooleanOrBuildTarget,\n },\n overrides: { [Key in ModuleNameWithoutNodePrefix]?: string },\n protocolImports: boolean,\n}\n\nconst globalShimBanners = {\n buffer: [\n `import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,\n `globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,\n ],\n global: [\n `import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,\n `globalThis.global = globalThis.global || __global_polyfill`,\n ],\n process: [\n `import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,\n `globalThis.process = globalThis.process || __process_polyfill`,\n ],\n}\n\n/**\n * Returns a Vite plugin to polyfill Node's Core Modules for browser environments. Supports `node:` protocol imports.\n *\n * @example\n *\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite'\n * import { nodePolyfills } from 'vite-plugin-node-polyfills'\n *\n * export default defineConfig({\n * plugins: [\n * nodePolyfills({\n * // Specific modules that should not be polyfilled.\n * exclude: [],\n * // Whether to polyfill specific globals.\n * globals: {\n * Buffer: true, // can also be 'build', 'dev', or false\n * global: true,\n * process: true,\n * },\n * // Whether to polyfill `node:` protocol imports.\n * protocolImports: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {\n const optionsResolved: PolyfillOptionsResolved = {\n include: [],\n exclude: [],\n overrides: {},\n protocolImports: true,\n ...options,\n globals: {\n Buffer: true,\n global: true,\n process: true,\n ...options.globals,\n },\n }\n\n const isExcluded = (moduleName: ModuleName) => {\n if (optionsResolved.include.length > 0) {\n return !optionsResolved.include.some((includedName) => compareModuleNames(moduleName, includedName))\n }\n\n return optionsResolved.exclude.some((excludedName) => compareModuleNames(moduleName, excludedName))\n }\n\n const toOverride = (name: ModuleNameWithoutNodePrefix): string | void => {\n if (isEnabled(optionsResolved.globals.Buffer, 'dev') && /^buffer$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/buffer'\n }\n\n if (isEnabled(optionsResolved.globals.global, 'dev') && /^global$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/global'\n }\n\n if (isEnabled(optionsResolved.globals.process, 'dev') && /^process$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/process'\n }\n\n if (name in optionsResolved.overrides) {\n return optionsResolved.overrides[name]\n }\n }\n\n const polyfills = (Object.entries(stdLibBrowser) as Array<[ModuleName, string]>).reduce<Record<ModuleName, string>>((included, [name, value]) => {\n if (!optionsResolved.protocolImports) {\n if (isNodeProtocolImport(name)) {\n return included\n }\n }\n\n if (!isExcluded(name)) {\n included[name] = toOverride(withoutNodeProtocol(name)) || value\n }\n\n return included\n }, {} as Record<ModuleName, string>)\n\n const require = createRequire(import.meta.url)\n const globalShimPaths = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/buffer')] : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/global')] : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/process')] : []),\n ]\n\n const globalShimsBanner = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? globalShimBanners.buffer : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? globalShimBanners.global : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? globalShimBanners.process : []),\n ``,\n ].join('\\n')\n\n return {\n name: 'vite-plugin-node-polyfills',\n config(config, env) {\n const isDev = env.command === 'serve'\n // @ts-expect-error - this.meta.rolldownVersion only exists with rolldown-vite 7+\n const isRolldownVite = !!this?.meta?.rolldownVersion\n\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L203-L209\n const defines = {\n ...((isDev && isEnabled(optionsResolved.globals.Buffer, 'dev')) ? { Buffer: 'Buffer' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.global, 'dev')) ? { global: 'global' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.process, 'dev')) ? { process: 'process' } : {}),\n }\n\n const shimsToInject = {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite\n ...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: 'vite-plugin-node-polyfills/shims/buffer' } : {}),\n ...(isEnabled(optionsResolved.globals.global, 'build') ? { global: 'vite-plugin-node-polyfills/shims/global' } : {}),\n ...(isEnabled(optionsResolved.globals.process, 'build') ? { process: 'vite-plugin-node-polyfills/shims/process' } : {}),\n }\n\n return {\n build: {\n rollupOptions: {\n onwarn: (warning, rollupWarn) => {\n handleCircularDependancyWarning(warning, () => {\n if (config.build?.rollupOptions?.onwarn) {\n return config.build.rollupOptions.onwarn(warning, rollupWarn)\n }\n\n rollupWarn(warning)\n })\n },\n ...Object.keys(shimsToInject).length > 0\n ? isRolldownVite\n ? { transform: { inject: shimsToInject } }\n : { plugins: [inject(shimsToInject)] }\n : {},\n },\n },\n esbuild: {\n // In dev, the global polyfills need to be injected as a banner in order for isolated scripts (such as Vue SFCs) to have access to them.\n banner: isDev ? globalShimsBanner : undefined,\n },\n optimizeDeps: {\n exclude: [\n ...globalShimPaths,\n ],\n ...isRolldownVite\n ? {\n rolldownOptions: {\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n transform: {\n define: defines,\n },\n plugins: [\n {\n name: 'vite-plugin-node-polyfills:optimizer',\n banner: isDev ? globalShimsBanner : undefined,\n },\n ],\n },\n }\n : {\n esbuildOptions: {\n banner: isDev ? { js: globalShimsBanner } : undefined,\n define: defines,\n inject: [\n ...globalShimPaths,\n ],\n plugins: [\n esbuildPlugin(polyfills),\n // Supress the 'injected path \"...\" cannot be marked as external' error in Vite 4 (emitted by esbuild).\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1469\n {\n name: 'vite-plugin-node-polyfills-shims-resolver',\n setup(build) {\n for (const globalShimPath of globalShimPaths) {\n const globalShimsFilter = toRegExp(globalShimPath)\n\n // https://esbuild.github.io/plugins/#on-resolve\n build.onResolve({ filter: globalShimsFilter }, () => {\n return {\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1468\n external: false,\n path: globalShimPath,\n }\n })\n }\n },\n },\n ],\n },\n },\n },\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n }\n },\n }\n}\n"],"names":["compareModuleNames","moduleA","moduleB","withoutNodeProtocol","isEnabled","value","mode","isNodeProtocolImport","name","toRegExp","text","escapedText","globalShimBanners","nodePolyfills","options","optionsResolved","isExcluded","moduleName","includedName","excludedName","toOverride","polyfills","stdLibBrowser","included","require","createRequire","_documentCurrentScript","globalShimPaths","globalShimsBanner","config","env","isDev","isRolldownVite","defines","shimsToInject","warning","rollupWarn","handleCircularDependancyWarning","inject","esbuildPlugin","build","globalShimPath","globalShimsFilter"],"mappings":"sZAEaA,EAAqB,CAACC,EAAqBC,IAC/CC,EAAoBF,CAAO,IAAME,EAAoBD,CAAO,EAGxDE,EAAY,CAACC,EAA6BC,IAChDD,EACDA,IAAU,GAAa,GAEpBA,IAAUC,EAHE,GAMRC,EAAwBC,GAC5BA,EAAK,WAAW,OAAO,EAGnBC,EAAYC,GAAiB,CAExC,MAAMC,EAAcD,EAAK,QAAQ,sBAAuB,MAAM,EAE9D,OAAO,IAAI,OAAO,IAAIC,CAAW,GAAG,CACtC,EAEaR,EAAuBK,GAC3BA,EAAK,QAAQ,SAAU,EAAE,ECgE5BI,EAAoB,CACxB,OAAQ,CACN,0EACA,4DACF,EACA,OAAQ,CACN,0EACA,4DACF,EACA,QAAS,CACP,4EACA,+DACF,CACF,EA8BaC,EAAgB,CAACC,EAA2B,KAAe,CACtE,MAAMC,EAA2C,CAC/C,QAAS,CAAC,EACV,QAAS,CAAC,EACV,UAAW,CAAC,EACZ,gBAAiB,GACjB,GAAGD,EACH,QAAS,CACP,OAAQ,GACR,OAAQ,GACR,QAAS,GACT,GAAGA,EAAQ,OACb,CAAA,EAGIE,EAAcC,GACdF,EAAgB,QAAQ,OAAS,EAC5B,CAACA,EAAgB,QAAQ,KAAMG,GAAiBlB,EAAmBiB,EAAYC,CAAY,CAAC,EAG9FH,EAAgB,QAAQ,KAAMI,GAAiBnB,EAAmBiB,EAAYE,CAAY,CAAC,EAG9FC,EAAcZ,GAAqD,CACnE,GAAAJ,EAAUW,EAAgB,QAAQ,OAAQ,KAAK,GAAK,WAAW,KAAKP,CAAI,EACnE,MAAA,0CAGL,GAAAJ,EAAUW,EAAgB,QAA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,CACT,OAAQY,CACV,EACA,QAAS,CACP,CACE,KAAM,uCACN,OAAQF,EAAQH,EAAoB,MACtC,CACF,CACF,CAAA,EAEF,CACE,eAAgB,CACd,OAAQG,EAAQ,CAAE,GAAIH,GAAsB,OAC5C,OAAQK,EACR,OAAQ,CACN,GAAGN,CACL,EACA,QAAS,CACPY,EAAAA,QAAclB,CAAS,EAGvB,CACE,KAAM,4CACN,MAAMmB,EAAO,CACX,UAAWC,KAAkBd,EAAiB,CACtC,MAAAe,EAAoBjC,EAASgC,CAAc,EAGjDD,EAAM,UAAU,CAAE,OAAQE,GAAqB,KACtC,CAEL,SAAU,GACV,KAAMD,CAAA,EAET,CACH,CACF,CACF,CACF,CACF,CACF,CACN,EACA,QAAS,CAEP,MAAO,CACL,GAAGpB,CACL,CACF,CAAA,CAEJ,CAAA,CAEJ"} |
+37
-35
@@ -6,6 +6,6 @@ import { createRequire as B } from "node:module"; | ||
| import T from "node-stdlib-browser/helpers/esbuild/plugin"; | ||
| const v = (s, l) => c(s) === c(l), o = (s, l) => s ? s === !0 ? !0 : s === l : !1, $ = (s) => s.startsWith("node:"), w = (s) => { | ||
| const v = (s, l) => d(s) === d(l), e = (s, l) => s ? s === !0 ? !0 : s === l : !1, w = (s) => s.startsWith("node:"), $ = (s) => { | ||
| const l = s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| return new RegExp(`^${l}$`); | ||
| }, c = (s) => s.replace(/^node:/, ""), g = { | ||
| }, d = (s) => s.replace(/^node:/, ""), g = { | ||
| buffer: [ | ||
@@ -36,19 +36,19 @@ "import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'", | ||
| } | ||
| }, h = (e) => l.include.length > 0 ? !l.include.some((r) => v(e, r)) : l.exclude.some((r) => v(e, r)), y = (e) => { | ||
| if (o(l.globals.Buffer, "dev") && /^buffer$/.test(e)) | ||
| }, h = (o) => l.include.length > 0 ? !l.include.some((r) => v(o, r)) : l.exclude.some((r) => v(o, r)), y = (o) => { | ||
| if (e(l.globals.Buffer, "dev") && /^buffer$/.test(o)) | ||
| return "vite-plugin-node-polyfills/shims/buffer"; | ||
| if (o(l.globals.global, "dev") && /^global$/.test(e)) | ||
| if (e(l.globals.global, "dev") && /^global$/.test(o)) | ||
| return "vite-plugin-node-polyfills/shims/global"; | ||
| if (o(l.globals.process, "dev") && /^process$/.test(e)) | ||
| if (e(l.globals.process, "dev") && /^process$/.test(o)) | ||
| return "vite-plugin-node-polyfills/shims/process"; | ||
| if (e in l.overrides) | ||
| return l.overrides[e]; | ||
| }, p = Object.entries(j).reduce((e, [r, i]) => (!l.protocolImports && $(r) || h(r) || (e[r] = y(c(r)) || i), e), {}), f = B(import.meta.url), u = [ | ||
| ...o(l.globals.Buffer, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/buffer")] : [], | ||
| ...o(l.globals.global, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/global")] : [], | ||
| ...o(l.globals.process, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/process")] : [] | ||
| ], b = [ | ||
| ...o(l.globals.Buffer, "dev") ? g.buffer : [], | ||
| ...o(l.globals.global, "dev") ? g.global : [], | ||
| ...o(l.globals.process, "dev") ? g.process : [], | ||
| if (o in l.overrides) | ||
| return l.overrides[o]; | ||
| }, p = Object.entries(j).reduce((o, [r, i]) => (!l.protocolImports && w(r) || h(r) || (o[r] = y(d(r)) || i), o), {}), f = B(import.meta.url), u = [ | ||
| ...e(l.globals.Buffer, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/buffer")] : [], | ||
| ...e(l.globals.global, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/global")] : [], | ||
| ...e(l.globals.process, "dev") ? [f.resolve("vite-plugin-node-polyfills/shims/process")] : [] | ||
| ], a = [ | ||
| ...e(l.globals.Buffer, "dev") ? g.buffer : [], | ||
| ...e(l.globals.global, "dev") ? g.global : [], | ||
| ...e(l.globals.process, "dev") ? g.process : [], | ||
| "" | ||
@@ -59,12 +59,12 @@ ].join(` | ||
| name: "vite-plugin-node-polyfills", | ||
| config(e, r) { | ||
| const i = r.command === "serve", d = !!this?.meta?.rolldownVersion, m = { | ||
| ...i && o(l.globals.Buffer, "dev") ? { Buffer: "Buffer" } : {}, | ||
| ...i && o(l.globals.global, "dev") ? { global: "global" } : {}, | ||
| ...i && o(l.globals.process, "dev") ? { process: "process" } : {} | ||
| }, a = { | ||
| config(o, r) { | ||
| const i = r.command === "serve", c = !!this?.meta?.rolldownVersion, m = { | ||
| ...i && e(l.globals.Buffer, "dev") ? { Buffer: "Buffer" } : {}, | ||
| ...i && e(l.globals.global, "dev") ? { global: "global" } : {}, | ||
| ...i && e(l.globals.process, "dev") ? { process: "process" } : {} | ||
| }, b = { | ||
| // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite | ||
| ...o(l.globals.Buffer, "build") ? { Buffer: "vite-plugin-node-polyfills/shims/buffer" } : {}, | ||
| ...o(l.globals.global, "build") ? { global: "vite-plugin-node-polyfills/shims/global" } : {}, | ||
| ...o(l.globals.process, "build") ? { process: "vite-plugin-node-polyfills/shims/process" } : {} | ||
| ...e(l.globals.Buffer, "build") ? { Buffer: "vite-plugin-node-polyfills/shims/buffer" } : {}, | ||
| ...e(l.globals.global, "build") ? { global: "vite-plugin-node-polyfills/shims/global" } : {}, | ||
| ...e(l.globals.process, "build") ? { process: "vite-plugin-node-polyfills/shims/process" } : {} | ||
| }; | ||
@@ -76,8 +76,8 @@ return { | ||
| O(t, () => { | ||
| if (e.build?.rollupOptions?.onwarn) | ||
| return e.build.rollupOptions.onwarn(t, n); | ||
| if (o.build?.rollupOptions?.onwarn) | ||
| return o.build.rollupOptions.onwarn(t, n); | ||
| n(t); | ||
| }); | ||
| }, | ||
| ...Object.keys(a).length > 0 ? d ? { inject: a } : { plugins: [x(a)] } : {} | ||
| ...Object.keys(b).length > 0 ? c ? { transform: { inject: b } } : { plugins: [x(b)] } : {} | ||
| } | ||
@@ -87,3 +87,3 @@ }, | ||
| // In dev, the global polyfills need to be injected as a banner in order for isolated scripts (such as Vue SFCs) to have access to them. | ||
| banner: i ? b : void 0 | ||
| banner: i ? a : void 0 | ||
| }, | ||
@@ -94,5 +94,4 @@ optimizeDeps: { | ||
| ], | ||
| ...d ? { | ||
| rollupOptions: { | ||
| define: m, | ||
| ...c ? { | ||
| rolldownOptions: { | ||
| resolve: { | ||
@@ -104,6 +103,9 @@ // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150 | ||
| }, | ||
| transform: { | ||
| define: m | ||
| }, | ||
| plugins: [ | ||
| { | ||
| name: "vite-plugin-node-polyfills:optimizer", | ||
| banner: i ? b : void 0 | ||
| banner: i ? a : void 0 | ||
| } | ||
@@ -114,3 +116,3 @@ ] | ||
| esbuildOptions: { | ||
| banner: i ? { js: b } : void 0, | ||
| banner: i ? { js: a } : void 0, | ||
| define: m, | ||
@@ -128,3 +130,3 @@ inject: [ | ||
| for (const n of u) { | ||
| const _ = w(n); | ||
| const _ = $(n); | ||
| t.onResolve({ filter: _ }, () => ({ | ||
@@ -131,0 +133,0 @@ // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1468 |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { BooleanOrBuildTarget, ModuleName, ModuleNameWithoutNodePrefix } from './index'\n\nexport const compareModuleNames = (moduleA: ModuleName, moduleB: ModuleName) => {\n return withoutNodeProtocol(moduleA) === withoutNodeProtocol(moduleB)\n}\n\nexport const isEnabled = (value: BooleanOrBuildTarget, mode: 'build' | 'dev') => {\n if (!value) return false\n if (value === true) return true\n\n return value === mode\n}\n\nexport const isNodeProtocolImport = (name: string) => {\n return name.startsWith('node:')\n}\n\nexport const toRegExp = (text: string) => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\n const escapedText = text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return new RegExp(`^${escapedText}$`)\n}\n\nexport const withoutNodeProtocol = (name: ModuleName): ModuleNameWithoutNodePrefix => {\n return name.replace(/^node:/, '') as ModuleNameWithoutNodePrefix\n}\n","import { createRequire } from 'node:module'\nimport inject from '@rollup/plugin-inject'\nimport stdLibBrowser from 'node-stdlib-browser'\nimport { handleCircularDependancyWarning } from 'node-stdlib-browser/helpers/rollup/plugin'\nimport esbuildPlugin from 'node-stdlib-browser/helpers/esbuild/plugin'\nimport type { Plugin } from 'vite'\nimport { compareModuleNames, isEnabled, isNodeProtocolImport, toRegExp, withoutNodeProtocol } from './utils'\n\nexport type BuildTarget = 'build' | 'dev'\nexport type BooleanOrBuildTarget = boolean | BuildTarget\nexport type ModuleName = keyof typeof stdLibBrowser\nexport type ModuleNameWithoutNodePrefix<T = ModuleName> = T extends `node:${infer P}` ? P : never\n\nexport type PolyfillOptions = {\n /**\n * Includes specific modules. If empty, includes all modules\n * @example\n *\n * ```ts\n * nodePolyfills({\n * include: ['fs', 'path'],\n * })\n * ```\n */\n include?: ModuleNameWithoutNodePrefix[],\n /**\n * @example\n *\n * ```ts\n * nodePolyfills({\n * exclude: ['fs', 'path'],\n * })\n * ```\n */\n exclude?: ModuleNameWithoutNodePrefix[],\n /**\n * Specify whether specific globals should be polyfilled.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * globals: {\n * Buffer: false,\n * global: true,\n * process: 'build',\n * },\n * })\n * ```\n */\n globals?: {\n Buffer?: BooleanOrBuildTarget,\n global?: BooleanOrBuildTarget,\n process?: BooleanOrBuildTarget,\n },\n /**\n * Specify alternative modules to use in place of the default polyfills.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * overrides: {\n * fs: 'memfs',\n * },\n * })\n * ```\n */\n overrides?: { [Key in ModuleNameWithoutNodePrefix]?: string },\n /**\n * Specify whether the Node protocol version of an import (e.g. `node:buffer`) should be polyfilled too.\n *\n * @default true\n */\n protocolImports?: boolean,\n}\n\nexport type PolyfillOptionsResolved = {\n include: ModuleNameWithoutNodePrefix[],\n exclude: ModuleNameWithoutNodePrefix[],\n globals: {\n Buffer: BooleanOrBuildTarget,\n global: BooleanOrBuildTarget,\n process: BooleanOrBuildTarget,\n },\n overrides: { [Key in ModuleNameWithoutNodePrefix]?: string },\n protocolImports: boolean,\n}\n\nconst globalShimBanners = {\n buffer: [\n `import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,\n `globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,\n ],\n global: [\n `import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,\n `globalThis.global = globalThis.global || __global_polyfill`,\n ],\n process: [\n `import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,\n `globalThis.process = globalThis.process || __process_polyfill`,\n ],\n}\n\n/**\n * Returns a Vite plugin to polyfill Node's Core Modules for browser environments. Supports `node:` protocol imports.\n *\n * @example\n *\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite'\n * import { nodePolyfills } from 'vite-plugin-node-polyfills'\n *\n * export default defineConfig({\n * plugins: [\n * nodePolyfills({\n * // Specific modules that should not be polyfilled.\n * exclude: [],\n * // Whether to polyfill specific globals.\n * globals: {\n * Buffer: true, // can also be 'build', 'dev', or false\n * global: true,\n * process: true,\n * },\n * // Whether to polyfill `node:` protocol imports.\n * protocolImports: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {\n const optionsResolved: PolyfillOptionsResolved = {\n include: [],\n exclude: [],\n overrides: {},\n protocolImports: true,\n ...options,\n globals: {\n Buffer: true,\n global: true,\n process: true,\n ...options.globals,\n },\n }\n\n const isExcluded = (moduleName: ModuleName) => {\n if (optionsResolved.include.length > 0) {\n return !optionsResolved.include.some((includedName) => compareModuleNames(moduleName, includedName))\n }\n\n return optionsResolved.exclude.some((excludedName) => compareModuleNames(moduleName, excludedName))\n }\n\n const toOverride = (name: ModuleNameWithoutNodePrefix): string | void => {\n if (isEnabled(optionsResolved.globals.Buffer, 'dev') && /^buffer$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/buffer'\n }\n\n if (isEnabled(optionsResolved.globals.global, 'dev') && /^global$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/global'\n }\n\n if (isEnabled(optionsResolved.globals.process, 'dev') && /^process$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/process'\n }\n\n if (name in optionsResolved.overrides) {\n return optionsResolved.overrides[name]\n }\n }\n\n const polyfills = (Object.entries(stdLibBrowser) as Array<[ModuleName, string]>).reduce<Record<ModuleName, string>>((included, [name, value]) => {\n if (!optionsResolved.protocolImports) {\n if (isNodeProtocolImport(name)) {\n return included\n }\n }\n\n if (!isExcluded(name)) {\n included[name] = toOverride(withoutNodeProtocol(name)) || value\n }\n\n return included\n }, {} as Record<ModuleName, string>)\n\n const require = createRequire(import.meta.url)\n const globalShimPaths = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/buffer')] : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/global')] : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/process')] : []),\n ]\n\n const globalShimsBanner = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? globalShimBanners.buffer : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? globalShimBanners.global : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? globalShimBanners.process : []),\n ``,\n ].join('\\n')\n\n return {\n name: 'vite-plugin-node-polyfills',\n config(config, env) {\n const isDev = env.command === 'serve'\n // @ts-expect-error - this.meta.rolldownVersion only exists with rolldown-vite 7+\n const isRolldownVite = !!this?.meta?.rolldownVersion\n\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L203-L209\n const defines = {\n ...((isDev && isEnabled(optionsResolved.globals.Buffer, 'dev')) ? { Buffer: 'Buffer' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.global, 'dev')) ? { global: 'global' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.process, 'dev')) ? { process: 'process' } : {}),\n }\n\n const shimsToInject = {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite\n ...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: 'vite-plugin-node-polyfills/shims/buffer' } : {}),\n ...(isEnabled(optionsResolved.globals.global, 'build') ? { global: 'vite-plugin-node-polyfills/shims/global' } : {}),\n ...(isEnabled(optionsResolved.globals.process, 'build') ? { process: 'vite-plugin-node-polyfills/shims/process' } : {}),\n }\n\n return {\n build: {\n rollupOptions: {\n onwarn: (warning, rollupWarn) => {\n handleCircularDependancyWarning(warning, () => {\n if (config.build?.rollupOptions?.onwarn) {\n return config.build.rollupOptions.onwarn(warning, rollupWarn)\n }\n\n rollupWarn(warning)\n })\n },\n ...Object.keys(shimsToInject).length > 0\n ? isRolldownVite\n ? { inject: shimsToInject }\n : { plugins: [inject(shimsToInject)] }\n : {},\n },\n },\n esbuild: {\n // In dev, the global polyfills need to be injected as a banner in order for isolated scripts (such as Vue SFCs) to have access to them.\n banner: isDev ? globalShimsBanner : undefined,\n },\n optimizeDeps: {\n exclude: [\n ...globalShimPaths,\n ],\n ...isRolldownVite\n ? {\n rollupOptions: {\n define: defines,\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n plugins: [\n {\n name: 'vite-plugin-node-polyfills:optimizer',\n banner: isDev ? globalShimsBanner : undefined,\n },\n ],\n },\n }\n : {\n esbuildOptions: {\n banner: isDev ? { js: globalShimsBanner } : undefined,\n define: defines,\n inject: [\n ...globalShimPaths,\n ],\n plugins: [\n esbuildPlugin(polyfills),\n // Supress the 'injected path \"...\" cannot be marked as external' error in Vite 4 (emitted by esbuild).\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1469\n {\n name: 'vite-plugin-node-polyfills-shims-resolver',\n setup(build) {\n for (const globalShimPath of globalShimPaths) {\n const globalShimsFilter = toRegExp(globalShimPath)\n\n // https://esbuild.github.io/plugins/#on-resolve\n build.onResolve({ filter: globalShimsFilter }, () => {\n return {\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1468\n external: false,\n path: globalShimPath,\n }\n })\n }\n },\n },\n ],\n },\n },\n },\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n }\n },\n }\n}\n"],"names":["compareModuleNames","moduleA","moduleB","withoutNodeProtocol","isEnabled","value","mode","isNodeProtocolImport","name","toRegExp","text","escapedText","globalShimBanners","nodePolyfills","options","optionsResolved","isExcluded","moduleName","includedName","excludedName","toOverride","polyfills","stdLibBrowser","included","require","createRequire","globalShimPaths","globalShimsBanner","config","env","isDev","isRolldownVite","defines","shimsToInject","warning","rollupWarn","handleCircularDependancyWarning","inject","esbuildPlugin","build","globalShimPath","globalShimsFilter"],"mappings":";;;;;AAEa,MAAAA,IAAqB,CAACC,GAAqBC,MAC/CC,EAAoBF,CAAO,MAAME,EAAoBD,CAAO,GAGxDE,IAAY,CAACC,GAA6BC,MAChDD,IACDA,MAAU,KAAa,KAEpBA,MAAUC,IAHE,IAMRC,IAAuB,CAACC,MAC5BA,EAAK,WAAW,OAAO,GAGnBC,IAAW,CAACC,MAAiB;AAExC,QA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AAgB;AAAA,cACd,QAAQG,IAAQ,EAAE,IAAIH,MAAsB;AAAA,cAC5C,QAAQK;AAAA,cACR,QAAQ;AAAA,gBACN,GAAGN;AAAA,cACL;AAAA,cACA,SAAS;AAAA,gBACPY,EAAcjB,CAAS;AAAA;AAAA;AAAA,gBAGvB;AAAA,kBACE,MAAM;AAAA,kBACN,MAAMkB,GAAO;AACX,+BAAWC,KAAkBd,GAAiB;AACtC,4BAAAe,IAAoBhC,EAAS+B,CAAc;AAGjD,sBAAAD,EAAM,UAAU,EAAE,QAAQE,KAAqB,OACtC;AAAA;AAAA,wBAEL,UAAU;AAAA,wBACV,MAAMD;AAAA,sBAAA,EAET;AAAA,oBACH;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACN;AAAA,QACA,SAAS;AAAA;AAAA,UAEP,OAAO;AAAA,YACL,GAAGnB;AAAA,UACL;AAAA,QACF;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAEJ;"} | ||
| {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { BooleanOrBuildTarget, ModuleName, ModuleNameWithoutNodePrefix } from './index'\n\nexport const compareModuleNames = (moduleA: ModuleName, moduleB: ModuleName) => {\n return withoutNodeProtocol(moduleA) === withoutNodeProtocol(moduleB)\n}\n\nexport const isEnabled = (value: BooleanOrBuildTarget, mode: 'build' | 'dev') => {\n if (!value) return false\n if (value === true) return true\n\n return value === mode\n}\n\nexport const isNodeProtocolImport = (name: string) => {\n return name.startsWith('node:')\n}\n\nexport const toRegExp = (text: string) => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\n const escapedText = text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\n return new RegExp(`^${escapedText}$`)\n}\n\nexport const withoutNodeProtocol = (name: ModuleName): ModuleNameWithoutNodePrefix => {\n return name.replace(/^node:/, '') as ModuleNameWithoutNodePrefix\n}\n","import { createRequire } from 'node:module'\nimport inject from '@rollup/plugin-inject'\nimport stdLibBrowser from 'node-stdlib-browser'\nimport { handleCircularDependancyWarning } from 'node-stdlib-browser/helpers/rollup/plugin'\nimport esbuildPlugin from 'node-stdlib-browser/helpers/esbuild/plugin'\nimport type { Plugin } from 'vite'\nimport { compareModuleNames, isEnabled, isNodeProtocolImport, toRegExp, withoutNodeProtocol } from './utils'\n\nexport type BuildTarget = 'build' | 'dev'\nexport type BooleanOrBuildTarget = boolean | BuildTarget\nexport type ModuleName = keyof typeof stdLibBrowser\nexport type ModuleNameWithoutNodePrefix<T = ModuleName> = T extends `node:${infer P}` ? P : never\n\nexport type PolyfillOptions = {\n /**\n * Includes specific modules. If empty, includes all modules\n * @example\n *\n * ```ts\n * nodePolyfills({\n * include: ['fs', 'path'],\n * })\n * ```\n */\n include?: ModuleNameWithoutNodePrefix[],\n /**\n * @example\n *\n * ```ts\n * nodePolyfills({\n * exclude: ['fs', 'path'],\n * })\n * ```\n */\n exclude?: ModuleNameWithoutNodePrefix[],\n /**\n * Specify whether specific globals should be polyfilled.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * globals: {\n * Buffer: false,\n * global: true,\n * process: 'build',\n * },\n * })\n * ```\n */\n globals?: {\n Buffer?: BooleanOrBuildTarget,\n global?: BooleanOrBuildTarget,\n process?: BooleanOrBuildTarget,\n },\n /**\n * Specify alternative modules to use in place of the default polyfills.\n *\n * @example\n *\n * ```ts\n * nodePolyfills({\n * overrides: {\n * fs: 'memfs',\n * },\n * })\n * ```\n */\n overrides?: { [Key in ModuleNameWithoutNodePrefix]?: string },\n /**\n * Specify whether the Node protocol version of an import (e.g. `node:buffer`) should be polyfilled too.\n *\n * @default true\n */\n protocolImports?: boolean,\n}\n\nexport type PolyfillOptionsResolved = {\n include: ModuleNameWithoutNodePrefix[],\n exclude: ModuleNameWithoutNodePrefix[],\n globals: {\n Buffer: BooleanOrBuildTarget,\n global: BooleanOrBuildTarget,\n process: BooleanOrBuildTarget,\n },\n overrides: { [Key in ModuleNameWithoutNodePrefix]?: string },\n protocolImports: boolean,\n}\n\nconst globalShimBanners = {\n buffer: [\n `import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,\n `globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,\n ],\n global: [\n `import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,\n `globalThis.global = globalThis.global || __global_polyfill`,\n ],\n process: [\n `import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,\n `globalThis.process = globalThis.process || __process_polyfill`,\n ],\n}\n\n/**\n * Returns a Vite plugin to polyfill Node's Core Modules for browser environments. Supports `node:` protocol imports.\n *\n * @example\n *\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite'\n * import { nodePolyfills } from 'vite-plugin-node-polyfills'\n *\n * export default defineConfig({\n * plugins: [\n * nodePolyfills({\n * // Specific modules that should not be polyfilled.\n * exclude: [],\n * // Whether to polyfill specific globals.\n * globals: {\n * Buffer: true, // can also be 'build', 'dev', or false\n * global: true,\n * process: true,\n * },\n * // Whether to polyfill `node:` protocol imports.\n * protocolImports: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {\n const optionsResolved: PolyfillOptionsResolved = {\n include: [],\n exclude: [],\n overrides: {},\n protocolImports: true,\n ...options,\n globals: {\n Buffer: true,\n global: true,\n process: true,\n ...options.globals,\n },\n }\n\n const isExcluded = (moduleName: ModuleName) => {\n if (optionsResolved.include.length > 0) {\n return !optionsResolved.include.some((includedName) => compareModuleNames(moduleName, includedName))\n }\n\n return optionsResolved.exclude.some((excludedName) => compareModuleNames(moduleName, excludedName))\n }\n\n const toOverride = (name: ModuleNameWithoutNodePrefix): string | void => {\n if (isEnabled(optionsResolved.globals.Buffer, 'dev') && /^buffer$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/buffer'\n }\n\n if (isEnabled(optionsResolved.globals.global, 'dev') && /^global$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/global'\n }\n\n if (isEnabled(optionsResolved.globals.process, 'dev') && /^process$/.test(name)) {\n return 'vite-plugin-node-polyfills/shims/process'\n }\n\n if (name in optionsResolved.overrides) {\n return optionsResolved.overrides[name]\n }\n }\n\n const polyfills = (Object.entries(stdLibBrowser) as Array<[ModuleName, string]>).reduce<Record<ModuleName, string>>((included, [name, value]) => {\n if (!optionsResolved.protocolImports) {\n if (isNodeProtocolImport(name)) {\n return included\n }\n }\n\n if (!isExcluded(name)) {\n included[name] = toOverride(withoutNodeProtocol(name)) || value\n }\n\n return included\n }, {} as Record<ModuleName, string>)\n\n const require = createRequire(import.meta.url)\n const globalShimPaths = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/buffer')] : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/global')] : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? [require.resolve('vite-plugin-node-polyfills/shims/process')] : []),\n ]\n\n const globalShimsBanner = [\n ...((isEnabled(optionsResolved.globals.Buffer, 'dev')) ? globalShimBanners.buffer : []),\n ...((isEnabled(optionsResolved.globals.global, 'dev')) ? globalShimBanners.global : []),\n ...((isEnabled(optionsResolved.globals.process, 'dev')) ? globalShimBanners.process : []),\n ``,\n ].join('\\n')\n\n return {\n name: 'vite-plugin-node-polyfills',\n config(config, env) {\n const isDev = env.command === 'serve'\n // @ts-expect-error - this.meta.rolldownVersion only exists with rolldown-vite 7+\n const isRolldownVite = !!this?.meta?.rolldownVersion\n\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L203-L209\n const defines = {\n ...((isDev && isEnabled(optionsResolved.globals.Buffer, 'dev')) ? { Buffer: 'Buffer' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.global, 'dev')) ? { global: 'global' } : {}),\n ...((isDev && isEnabled(optionsResolved.globals.process, 'dev')) ? { process: 'process' } : {}),\n }\n\n const shimsToInject = {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite\n ...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: 'vite-plugin-node-polyfills/shims/buffer' } : {}),\n ...(isEnabled(optionsResolved.globals.global, 'build') ? { global: 'vite-plugin-node-polyfills/shims/global' } : {}),\n ...(isEnabled(optionsResolved.globals.process, 'build') ? { process: 'vite-plugin-node-polyfills/shims/process' } : {}),\n }\n\n return {\n build: {\n rollupOptions: {\n onwarn: (warning, rollupWarn) => {\n handleCircularDependancyWarning(warning, () => {\n if (config.build?.rollupOptions?.onwarn) {\n return config.build.rollupOptions.onwarn(warning, rollupWarn)\n }\n\n rollupWarn(warning)\n })\n },\n ...Object.keys(shimsToInject).length > 0\n ? isRolldownVite\n ? { transform: { inject: shimsToInject } }\n : { plugins: [inject(shimsToInject)] }\n : {},\n },\n },\n esbuild: {\n // In dev, the global polyfills need to be injected as a banner in order for isolated scripts (such as Vue SFCs) to have access to them.\n banner: isDev ? globalShimsBanner : undefined,\n },\n optimizeDeps: {\n exclude: [\n ...globalShimPaths,\n ],\n ...isRolldownVite\n ? {\n rolldownOptions: {\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n transform: {\n define: defines,\n },\n plugins: [\n {\n name: 'vite-plugin-node-polyfills:optimizer',\n banner: isDev ? globalShimsBanner : undefined,\n },\n ],\n },\n }\n : {\n esbuildOptions: {\n banner: isDev ? { js: globalShimsBanner } : undefined,\n define: defines,\n inject: [\n ...globalShimPaths,\n ],\n plugins: [\n esbuildPlugin(polyfills),\n // Supress the 'injected path \"...\" cannot be marked as external' error in Vite 4 (emitted by esbuild).\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1469\n {\n name: 'vite-plugin-node-polyfills-shims-resolver',\n setup(build) {\n for (const globalShimPath of globalShimPaths) {\n const globalShimsFilter = toRegExp(globalShimPath)\n\n // https://esbuild.github.io/plugins/#on-resolve\n build.onResolve({ filter: globalShimsFilter }, () => {\n return {\n // https://github.com/evanw/esbuild/blob/edede3c49ad6adddc6ea5b3c78c6ea7507e03020/internal/bundler/bundler.go#L1468\n external: false,\n path: globalShimPath,\n }\n })\n }\n },\n },\n ],\n },\n },\n },\n resolve: {\n // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md?plain=1#L150\n alias: {\n ...polyfills,\n },\n },\n }\n },\n }\n}\n"],"names":["compareModuleNames","moduleA","moduleB","withoutNodeProtocol","isEnabled","value","mode","isNodeProtocolImport","name","toRegExp","text","escapedText","globalShimBanners","nodePolyfills","options","optionsResolved","isExcluded","moduleName","includedName","excludedName","toOverride","polyfills","stdLibBrowser","included","require","createRequire","globalShimPaths","globalShimsBanner","config","env","isDev","isRolldownVite","defines","shimsToInject","warning","rollupWarn","handleCircularDependancyWarning","inject","esbuildPlugin","build","globalShimPath","globalShimsFilter"],"mappings":";;;;;AAEa,MAAAA,IAAqB,CAACC,GAAqBC,MAC/CC,EAAoBF,CAAO,MAAME,EAAoBD,CAAO,GAGxDE,IAAY,CAACC,GAA6BC,MAChDD,IACDA,MAAU,KAAa,KAEpBA,MAAUC,IAHE,IAMRC,IAAuB,CAACC,MAC5BA,EAAK,WAAW,OAAO,GAGnBC,IAAW,CAACC,MAAiB;AAExC,QAAMC,IAAcD,EAAK,QAAQ,uBAAuB,MAAM;AAE9D,SAAO,IAAI,OAAO,IAAIC,CAAW,GAAG;AACtC,GAEaR,IAAsB,CAACK,MAC3BA,EAAK,QAAQ,UAAU,EAAE,GCgE5BI,IAAoB;AAAA,EACxB,QAAQ;AAAA,IACN;AAAA,IACA;A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PY,EAAcjB,CAAS;AAAA;AAAA;AAAA,gBAGvB;AAAA,kBACE,MAAM;AAAA,kBACN,MAAMkB,GAAO;AACX,+BAAWC,KAAkBd,GAAiB;AACtC,4BAAAe,IAAoBhC,EAAS+B,CAAc;AAGjD,sBAAAD,EAAM,UAAU,EAAE,QAAQE,KAAqB,OACtC;AAAA;AAAA,wBAEL,UAAU;AAAA,wBACV,MAAMD;AAAA,sBAAA,EAET;AAAA,oBACH;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACN;AAAA,QACA,SAAS;AAAA;AAAA,UAEP,OAAO;AAAA,YACL,GAAGnB;AAAA,UACL;AAAA,QACF;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAEJ;"} |
+3
-3
| { | ||
| "name": "vite-plugin-node-polyfills", | ||
| "type": "module", | ||
| "version": "0.24.0", | ||
| "version": "0.25.0", | ||
| "description": "A Vite plugin to polyfill Node's Core Modules for browser environments.", | ||
@@ -70,3 +70,3 @@ "author": "David Myers <hello@davidmyers.dev>", | ||
| "@rollup/plugin-inject": "^5.0.5", | ||
| "node-stdlib-browser": "^1.2.0" | ||
| "node-stdlib-browser": "^1.3.1" | ||
| }, | ||
@@ -89,3 +89,3 @@ "devDependencies": { | ||
| "vitest": "^1.2.2", | ||
| "vite-plugin-node-polyfills": "0.24.0" | ||
| "vite-plugin-node-polyfills": "0.25.0" | ||
| }, | ||
@@ -92,0 +92,0 @@ "publishConfig": { |
516860
0.06%4789
0.04%Updated