Skip to content

Commit

Permalink
sup?
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Apr 17, 2024
1 parent 849cab2 commit 8f6a481
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "vite-plugin-node-polyfills",
"name": "@artursapek/vite-plugin-node-polyfills",
"type": "module",
"version": "0.21.0",
"packageManager": "pnpm@8.4.0",
"version": "0.21.1",
"packageManager": "pnpm@9.0.2",
"description": "A Vite plugin to polyfill Node's Core Modules for browser environments.",
"author": "David Myers <hello@davidmyers.dev>",
"license": "MIT",
Expand Down Expand Up @@ -126,5 +126,12 @@
"patchedDependencies": {
"buffer@6.0.3": "patches/buffer@6.0.3.patch"
}
},
"bugs": {
"url": "https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues"
},
"directories": {
"example": "examples",
"test": "test"
}
}
24 changes: 12 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export type PolyfillOptionsResolved = {
}

const globalShimsBanner = [
`import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,
`import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,
`import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,
`import __buffer_polyfill from '@artursapek/vite-plugin-node-polyfills/shims/buffer'`,
`import __global_polyfill from '@artursapek/vite-plugin-node-polyfills/shims/global'`,
`import __process_polyfill from '@artursapek/vite-plugin-node-polyfills/shims/process'`,
``,
`globalThis = globalThis ?? window`,
`globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,
Expand Down Expand Up @@ -130,9 +130,9 @@ const globalShimsBanner = [
export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {
const require = createRequire(import.meta.url)
const globalShimPaths = [
require.resolve('vite-plugin-node-polyfills/shims/buffer'),
require.resolve('vite-plugin-node-polyfills/shims/global'),
require.resolve('vite-plugin-node-polyfills/shims/process'),
require.resolve('@artursapek/vite-plugin-node-polyfills/shims/buffer'),
require.resolve('@artursapek/vite-plugin-node-polyfills/shims/global'),
require.resolve('@artursapek/vite-plugin-node-polyfills/shims/process'),
]
const optionsResolved: PolyfillOptionsResolved = {
include: [],
Expand All @@ -158,15 +158,15 @@ export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {

const toOverride = (name: ModuleNameWithoutNodePrefix): string | void => {
if (isEnabled(optionsResolved.globals.Buffer, 'dev') && /^buffer$/.test(name)) {
return 'vite-plugin-node-polyfills/shims/buffer'
return '@artursapek/vite-plugin-node-polyfills/shims/buffer'
}

if (isEnabled(optionsResolved.globals.global, 'dev') && /^global$/.test(name)) {
return 'vite-plugin-node-polyfills/shims/global'
return '@artursapek/vite-plugin-node-polyfills/shims/global'
}

if (isEnabled(optionsResolved.globals.process, 'dev') && /^process$/.test(name)) {
return 'vite-plugin-node-polyfills/shims/process'
return '@artursapek/vite-plugin-node-polyfills/shims/process'
}

if (name in optionsResolved.overrides) {
Expand Down Expand Up @@ -209,9 +209,9 @@ export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {
{
...inject({
// https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite
...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: 'vite-plugin-node-polyfills/shims/buffer' } : {}),
...(isEnabled(optionsResolved.globals.global, 'build') ? { global: 'vite-plugin-node-polyfills/shims/global' } : {}),
...(isEnabled(optionsResolved.globals.process, 'build') ? { process: 'vite-plugin-node-polyfills/shims/process' } : {}),
...(isEnabled(optionsResolved.globals.Buffer, 'build') ? { Buffer: '@artursapek/vite-plugin-node-polyfills/shims/buffer' } : {}),
...(isEnabled(optionsResolved.globals.global, 'build') ? { global: '@artursapek/vite-plugin-node-polyfills/shims/global' } : {}),
...(isEnabled(optionsResolved.globals.process, 'build') ? { process: '@artursapek/vite-plugin-node-polyfills/shims/process' } : {}),
}),
},
],
Expand Down

0 comments on commit 8f6a481

Please sign in to comment.