Skip to content

Commit

Permalink
fix: import with query with exports field (#7073)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Feb 24, 2022
1 parent a9dfce3 commit 88ded7f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/playground/resolve/__tests__/resolve.spec.ts
Expand Up @@ -16,6 +16,10 @@ test('deep import with exports field', async () => {
expect(await page.textContent('.exports-deep')).toMatch('[success]')
})

test('deep import with query with exports field', async () => {
expect(await page.textContent('.exports-deep-query')).not.toMatch('fail')
})

test('deep import with exports field + exposed dir', async () => {
expect(await page.textContent('.exports-deep-exposed-dir')).toMatch(
'[success]'
Expand Down
3 changes: 3 additions & 0 deletions packages/playground/resolve/exports-path/deep.json
@@ -0,0 +1,3 @@
{
"foo": "json"
}
1 change: 1 addition & 0 deletions packages/playground/resolve/exports-path/package.json
Expand Up @@ -8,6 +8,7 @@
"require": "./cjs.js"
},
"./deep.js": "./deep.js",
"./deep.json": "./deep.json",
"./dir/": "./dir/",
"./dir-mapped/*": {
"import": "./dir/*",
Expand Down
7 changes: 7 additions & 0 deletions packages/playground/resolve/index.html
Expand Up @@ -12,6 +12,9 @@ <h2>Entry resolving with exports field</h2>
<h2>Deep import with exports field</h2>
<p class="exports-deep">fail</p>

<h2>Deep import with query with exports field</h2>
<p class="exports-deep-query">fail</p>

<h2>Deep import with exports field + exposed directory</h2>
<p class="exports-deep-exposed-dir">fail</p>

Expand Down Expand Up @@ -100,6 +103,10 @@ <h2>resolve package that contains # in path</h2>
import { msg as deepMsg } from 'resolve-exports-path/deep.js'
text('.exports-deep', deepMsg)

// deep import w/ exports w/ query
import deepPath from 'resolve-exports-path/deep.json?url'
text('.exports-deep-query', deepPath)

// deep import w/ exposed dir
import { msg as exposedDirMsg } from 'resolve-exports-path/dir/dir'
text('.exports-deep-exposed-dir', exposedDirMsg)
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -813,7 +813,12 @@ function resolveDeepImport(
// map relative based on exports data
if (exportsField) {
if (isObject(exportsField) && !Array.isArray(exportsField)) {
relativeId = resolveExports(data, relativeId, options, targetWeb)
relativeId = resolveExports(
data,
cleanUrl(relativeId),
options,
targetWeb
)
} else {
// not exposed
relativeId = undefined
Expand Down

0 comments on commit 88ded7f

Please sign in to comment.