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

Handle imports from dot directories #3739

Merged
merged 7 commits into from Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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