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: NPM parsing shouldn't try loading Deno URL imports #496

Merged
merged 2 commits into from
Oct 10, 2023
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
5 changes: 4 additions & 1 deletion node/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ test('Prints a nice error message when user tries importing an npm module and np
]

try {
await bundle([sourceDirectory], distPath, declarations, { basePath })
await bundle([sourceDirectory], distPath, declarations, {
basePath,
importMapPaths: [join(basePath, 'import_map.json')],
})
} catch (error) {
expect(error).toBeInstanceOf(BundleError)
expect((error as BundleError).message).toEqual(
Expand Down
4 changes: 4 additions & 0 deletions node/npm_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const getDependencyTrackerPlugin = (
// If it does, the resolved import is the specifier we'll evaluate going
// forward.
if (matched) {
if (resolvedImport.protocol !== 'file:') {
return { external: true }
}

specifier = fileURLToPath(resolvedImport).replace(/\\/g, '/')

result.path = specifier
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/imports_npm_module/functions/func1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import parent1 from 'parent-1'
import parent2 from 'parent-2'
import parent3 from './lib/util.ts'
import { echo } from 'alias:helper'
import { HTMLRewriter } from 'html-rewriter'

await Promise.resolve()

new HTMLRewriter()

export default async () => {
const text = [parent1('JavaScript'), parent2('APIs'), parent3('Markup')].join(', ')

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/imports_npm_module/import_map.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"imports": {
"alias:helper": "./helper.ts"
"alias:helper": "./helper.ts",
"html-rewriter": "https://ghuc.cc/worker-tools/html-rewriter/index.ts"
}
}