Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import with query with exports/browser field #7098

Merged
merged 7 commits into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/playground/resolve/__tests__/resolve.spec.ts
Expand Up @@ -17,7 +17,9 @@ test('deep import with exports field', async () => {
})

test('deep import with query with exports field', async () => {
expect(await page.textContent('.exports-deep-query')).not.toMatch('fail')
expect(await page.textContent('.exports-deep-query')).toMatch(
isBuild ? /base64/ : '/exports-path/deep.json'
)
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
})

test('deep import with exports field + exposed dir', async () => {
Expand Down
15 changes: 7 additions & 8 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -772,22 +772,26 @@ function packageEntryFailure(id: string, details?: string) {

function resolveExports(
pkg: PackageData['data'],
key: string,
keyWithQuery: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice if we can leave this back as key

options: InternalResolveOptions,
targetWeb: boolean
) {
const key = cleanUrl(keyWithQuery)
const query = keyWithQuery.slice(key.length)
bluwy marked this conversation as resolved.
Show resolved Hide resolved

const conditions = [options.isProduction ? 'production' : 'development']
if (!options.isRequire) {
conditions.push('module')
}
if (options.conditions) {
conditions.push(...options.conditions)
}
return _resolveExports(pkg, key, {
const resolved = _resolveExports(pkg, key, {
browser: targetWeb,
require: options.isRequire,
conditions
})
return resolved + query
}

function resolveDeepImport(
Expand All @@ -813,12 +817,7 @@ function resolveDeepImport(
// map relative based on exports data
if (exportsField) {
if (isObject(exportsField) && !Array.isArray(exportsField)) {
relativeId = resolveExports(
data,
cleanUrl(relativeId),
options,
targetWeb
)
relativeId = resolveExports(data, relativeId, options, targetWeb)
} else {
// not exposed
relativeId = undefined
Expand Down