Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: make empty-import-meta warning more actionable (#1561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Sep 6, 2023
1 parent 54b79e3 commit 8788624
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/runtimes/node/bundlers/esbuild/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ var __glob = (map) => (path) => {
const cleanTempFiles = getCleanupFunction([...bundlePaths.keys()])
const additionalPaths = includedFilesFromModuleDetection

const updatedWarnings = warnings.map((warning) => {
if (warning.id === 'empty-import-meta') {
return {
...warning,
text: `"import.meta" is not available and will be empty, use __dirname instead`,
}
}

return warning
})

return {
additionalPaths,
bundlePaths,
Expand All @@ -215,7 +226,7 @@ var __glob = (map) => (path) => {
moduleFormat,
nativeNodeModules,
outputExtension,
warnings,
warnings: updatedWarnings,
}
} catch (error) {
throw FunctionBundlingUserError.addCustomErrorInfo(error, {
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/import-meta-warning/function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const handler = async () => ({
statusCode: 200,
body: JSON.stringify({
msg: "Hello from .ts",
v: 2,
// @ts-ignore Error expected
importMetaURL: import.meta.url,
dirname: typeof __dirname === "undefined" ? undefined : __dirname,
}),
});
13 changes: 13 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2765,4 +2765,17 @@ describe('zip-it-and-ship-it', () => {
expect(handler()).toBe(true)
}
})

testMany('esbuild hides unactionable import.meta warning', ['bundler_esbuild'], async (options) => {
const {
files: [{ bundlerWarnings }],
} = await zipFixture('import-meta-warning', {
length: 1,
opts: options,
})
expect(bundlerWarnings).toHaveLength(1)
expect((bundlerWarnings?.[0] as any).text).toEqual(
`"import.meta" is not available and will be empty, use __dirname instead`,
)
})
})

1 comment on commit 8788624

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 3.5s
  • largeDepsNft: 11.2s
  • largeDepsZisi: 21s

Please sign in to comment.