Skip to content

Commit

Permalink
Handle imports from dot directories (#3739)
Browse files Browse the repository at this point in the history
Co-authored-by: patak <matias.capeletto@gmail.com>
  • Loading branch information
hpx7 and patak-dev committed Jul 23, 2021
1 parent c90b7d9 commit f4f0100
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/playground/optimize-deps/.hidden-dir/foo.js
@@ -0,0 +1 @@
export const greeting = 'hello!'
Expand Up @@ -67,3 +67,7 @@ test('esbuild-plugin', async () => {
isBuild ? `Hello from a package` : `Hello from an esbuild plugin`
)
})

test('import from hidden dir', async () => {
expect(await page.textContent('.hidden-dir')).toBe('hello!')
})
6 changes: 6 additions & 0 deletions packages/playground/optimize-deps/index.html
Expand Up @@ -43,6 +43,9 @@ <h2>Vue & Vuex</h2>
<h2>Dep with changes from esbuild plugin</h2>
<div>This should show a greeting: <span class="esbuild-plugin"></span></div>

<h2>Dep from hidden dir</h2>
<div>This should show hello!: <span class="hidden-dir"></span></div>

<script type="module">
// test dep detection in globbed files
const globbed = import.meta.globEager('./glob/*.js')
Expand All @@ -69,6 +72,9 @@ <h2>Dep with changes from esbuild plugin</h2>
import { hello } from 'dep-esbuild-plugin-transform'
text('.esbuild-plugin', hello())

import { greeting } from './.hidden-dir/foo.js'
text('.hidden-dir', greeting)

function text(el, text) {
document.querySelector(el).textContent = text
}
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Expand Up @@ -145,7 +145,11 @@ export function esbuildDepPlugin(
const entryFile = qualified[id]

let relativePath = normalizePath(path.relative(root, entryFile))
if (!relativePath.startsWith('.')) {
if (
!relativePath.startsWith('./') &&
!relativePath.startsWith('../') &&
relativePath !== '.'
) {
relativePath = `./${relativePath}`
}

Expand Down

0 comments on commit f4f0100

Please sign in to comment.