Skip to content

Commit

Permalink
refactor: upgrade resolve.exports (#11712)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jan 18, 2023
1 parent a6df6b4 commit 00a79ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"postcss-import": "^15.1.0",
"postcss-load-config": "^4.0.1",
"postcss-modules": "^6.0.0",
"resolve.exports": "^1.1.1",
"resolve.exports": "^2.0.0",
"rollup-plugin-license": "^3.0.1",
"sirv": "^2.0.2",
"source-map-js": "^1.0.2",
Expand Down
8 changes: 5 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs'
import path from 'node:path'
import colors from 'picocolors'
import type { PartialResolvedId } from 'rollup'
import { resolve as _resolveExports } from 'resolve.exports'
import { exports } from 'resolve.exports'
import { hasESMSyntax } from 'mlly'
import type { Plugin } from '../plugin'
import {
Expand Down Expand Up @@ -937,7 +937,7 @@ export function resolvePackageEntry(
return cached
}
try {
let entryPoint: string | undefined | void
let entryPoint: string | undefined

// resolve exports field with highest priority
// using https://github.com/lukeed/resolve.exports
Expand Down Expand Up @@ -1099,11 +1099,13 @@ function resolveExports(
conditions.push(...options.conditions)
}

return _resolveExports(pkg, key, {
const result = exports(pkg, key, {
browser: targetWeb && !conditions.includes('node'),
require: options.isRequire && !conditions.includes('import'),
conditions,
})

return result ? result[0] : undefined
}

function resolveDeepImport(
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00a79ec

Please sign in to comment.