Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly annotate transpilation errors in nft bundler (#1086)
Add `customErrorInfo` to errors happening during transpilation of esm with esbuild in the nft bundler Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
- Loading branch information
1 parent
61e5b72
commit 28a85fb
Showing
5 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import { build } from '@netlify/esbuild' | ||
|
||
import type { FunctionConfig } from '../../../../config.js' | ||
import type { RuntimeName } from '../../../runtime.js' | ||
import { getBundlerTarget } from '../esbuild/bundler_target.js' | ||
import type { NodeBundlerName } from '../index.js' | ||
|
||
export const transpile = async (path: string, config: FunctionConfig) => { | ||
export const transpile = async (path: string, config: FunctionConfig, functionName: string) => { | ||
// The version of ECMAScript to use as the build target. This will determine | ||
// whether certain features are transpiled down or left untransformed. | ||
const nodeTarget = getBundlerTarget(config.nodeVersion) | ||
const transpiled = await build({ | ||
bundle: false, | ||
entryPoints: [path], | ||
format: 'cjs', | ||
logLevel: 'error', | ||
platform: 'node', | ||
sourcemap: Boolean(config.nodeSourcemap), | ||
target: [nodeTarget], | ||
write: false, | ||
}) | ||
|
||
return transpiled.outputFiles[0].text | ||
try { | ||
const transpiled = await build({ | ||
bundle: false, | ||
entryPoints: [path], | ||
format: 'cjs', | ||
logLevel: 'error', | ||
platform: 'node', | ||
sourcemap: Boolean(config.nodeSourcemap), | ||
target: [nodeTarget], | ||
write: false, | ||
}) | ||
|
||
return transpiled.outputFiles[0].text | ||
} catch (error) { | ||
const bundler: NodeBundlerName = 'nft' | ||
const runtime: RuntimeName = 'js' | ||
|
||
error.customErrorInfo = { | ||
type: 'functionsBundling', | ||
location: { bundler, functionName, runtime }, | ||
} | ||
|
||
throw error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const func = async () => {} | ||
|
||
await func() | ||
|
||
export { func } //makes nft detect this file as esm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28a85fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏱ Benchmark results
largeDepsEsbuild: 6.3s
largeDepsNft: 29.1s
largeDepsZisi: 45.1s