Skip to content

Commit

Permalink
deps: remove modern-node-polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel-G committed Jun 28, 2023
1 parent 726a57e commit 81270a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 313 deletions.
1 change: 0 additions & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"vitest": ">=0.31.0"
},
"dependencies": {
"modern-node-polyfills": "^0.1.3",
"sirv": "^2.0.3"
},
"devDependencies": {
Expand Down
64 changes: 0 additions & 64 deletions packages/browser/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { fileURLToPath } from 'node:url'

import { resolve } from 'node:path'
import { builtinModules } from 'node:module'
import { polyfillPath } from 'modern-node-polyfills'
import sirv from 'sirv'
import type { Plugin } from 'vite'
import { injectVitestModule } from './esmInjector'

const polyfills = [
'util',
]

// don't expose type to not bundle it here
export default (project: any, base = '/'): Plugin[] => {
const pkgRoot = resolve(fileURLToPath(import.meta.url), '../..')
Expand All @@ -35,51 +29,6 @@ export default (project: any, base = '/'): Plugin[] => {
)
},
},
{
name: 'modern-node-polyfills',
enforce: 'pre',
config() {
return {
optimizeDeps: {
exclude: [
...polyfills,
...builtinModules,
'vitest',
'vitest/utils',
'vitest/browser',
'vitest/runners',
'@vitest/utils',
],
include: [
'vitest > diff-sequences',
'vitest > loupe',
'vitest > pretty-format',
'vitest > pretty-format > ansi-styles',
'vitest > pretty-format > ansi-regex',
'vitest > chai',
],
},
}
},
async resolveId(id) {
if (!builtinModules.includes(id) && !polyfills.includes(id) && !id.startsWith('node:')) {
if (!/\?browserv=\w+$/.test(id))
return

let useId = id.slice(0, id.lastIndexOf('?'))
if (useId.startsWith('/@fs/'))
useId = useId.slice(5)

if (/^\w:/.test(useId))
useId = useId.replace(/\\/g, '/')

return useId
}

id = normalizeId(id)
return { id: await polyfillPath(id), moduleSideEffects: false }
},
},
{
name: 'vitest:browser:esm-injector',
enforce: 'post',
Expand All @@ -92,16 +41,3 @@ export default (project: any, base = '/'): Plugin[] => {
},
]
}

function normalizeId(id: string, base?: string): string {
if (base && id.startsWith(base))
id = `/${id.slice(base.length)}`

return id
.replace(/^\/@id\/__x00__/, '\0') // virtual modules start with `\0`
.replace(/^\/@id\//, '')
.replace(/^__vite-browser-external:/, '')
.replace(/^node:/, '')
.replace(/[?&]v=\w+/, '?') // remove ?v= query
.replace(/\?$/, '') // remove end query mark
}
Loading

0 comments on commit 81270a8

Please sign in to comment.