Skip to content

Commit

Permalink
fix: NPM bundling should use ESM format (#494)
Browse files Browse the repository at this point in the history
* chore: show how top-level await can throw esbuild off

* fix: specify ESM format
  • Loading branch information
Skn0tt committed Oct 9, 2023
1 parent 2a9024c commit 6bb800f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions node/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ test('Handles imports with the `node:` prefix', async () => {
})

test('Loads npm modules from bare specifiers', async () => {
const systemLogger = vi.fn()
const { basePath, cleanup, distPath } = await useFixture('imports_npm_module')
const sourceDirectory = join(basePath, 'functions')
const declarations: Declaration[] = [
Expand All @@ -501,7 +502,13 @@ test('Loads npm modules from bare specifiers', async () => {
featureFlags: { edge_functions_npm_modules: true },
importMapPaths: [join(basePath, 'import_map.json')],
vendorDirectory: vendorDirectory.path,
systemLogger,
})

expect(
systemLogger.mock.calls.find((call) => call[0] === 'Could not track dependencies in edge function:'),
).toBeUndefined()

const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8')
const manifest = JSON.parse(manifestFile)
const bundlePath = join(distPath, manifest.bundles[0].asset)
Expand Down
1 change: 1 addition & 0 deletions node/npm_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const vendorNPMSpecifiers = async ({
platform: 'node',
plugins: [getDependencyTrackerPlugin(specifiers, importMap.getContentsWithURLObjects(), pathToFileURL(basePath))],
write: false,
format: 'esm',
})
} catch (error) {
logger.system('Could not track dependencies in edge function:', error)
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/imports_npm_module/functions/func1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import parent2 from 'parent-2'
import parent3 from './lib/util.ts'
import { echo } from 'alias:helper'

await Promise.resolve()

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

Expand Down

0 comments on commit 6bb800f

Please sign in to comment.