Skip to content

Commit

Permalink
fix(resolve): revert ensure exports has precedence over mainFields (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikg authored Dec 8, 2022
1 parent a9850be commit 8d05daf
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 35 deletions.
6 changes: 1 addition & 5 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,6 @@ export function resolvePackageEntry(
entryPoint = resolveExports(data, '.', options, targetWeb)
}

const resolvedFromExports = !!entryPoint

// if exports resolved to .mjs, still resolve other fields.
// This is because .mjs files can technically import .cjs files which would
// make them invalid for pure ESM environments - so if other module/browser
Expand Down Expand Up @@ -982,9 +980,7 @@ export function resolvePackageEntry(
}
}

// fallback to mainFields if still not resolved
// TODO: review if `.mjs` check is still needed
if (!resolvedFromExports && (!entryPoint || entryPoint.endsWith('.mjs'))) {
if (!entryPoint || entryPoint.endsWith('.mjs')) {
for (const field of options.mainFields) {
if (field === 'browser') continue // already checked above
if (typeof data[field] === 'string') {
Expand Down
4 changes: 0 additions & 4 deletions playground/resolve/__tests__/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ test('Respect production/development conditionals', async () => {
)
})

test('Respect exports to take precedence over mainFields', async () => {
expect(await page.textContent('.exports-with-module')).toMatch('[success]')
})

test('implicit dir/index.js', async () => {
expect(await page.textContent('.index')).toMatch('[success]')
})
Expand Down
2 changes: 0 additions & 2 deletions playground/resolve/exports-with-module/import.mjs

This file was deleted.

2 changes: 0 additions & 2 deletions playground/resolve/exports-with-module/module.mjs

This file was deleted.

10 changes: 0 additions & 10 deletions playground/resolve/exports-with-module/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions playground/resolve/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ <h2>Exports field env priority</h2>
<h2>Exports with legacy fallback</h2>
<p class="exports-legacy-fallback">fail</p>

<h2>Exports with module</h2>
<p class="exports-with-module">fail</p>

<h2>Resolve /index.*</h2>
<p class="index">fail</p>

Expand Down Expand Up @@ -172,9 +169,6 @@ <h2>resolve package that contains # in path</h2>
import { msg as exportsLegacyFallbackMsg } from '@vitejs/test-resolve-exports-legacy-fallback/dir'
text('.exports-legacy-fallback', exportsLegacyFallbackMsg)

import { msg as exportsWithModule } from '@vitejs/test-resolve-exports-with-module'
text('.exports-with-module', exportsWithModule)

// implicit index resolving
import { foo } from './util'
text('.index', foo())
Expand Down
1 change: 0 additions & 1 deletion playground/resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@vitejs/test-resolve-exports-env": "link:./exports-env",
"@vitejs/test-resolve-exports-legacy-fallback": "link:./exports-legacy-fallback",
"@vitejs/test-resolve-exports-path": "link:./exports-path",
"@vitejs/test-resolve-exports-with-module": "link:./exports-with-module",
"@vitejs/test-resolve-linked": "workspace:*"
}
}
5 changes: 0 additions & 5 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 8d05daf

Please sign in to comment.