This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use esbuild by default for es modules, if detected (#625)
* feat: poc for es module detection * fix: async calls to detect fn * fix(tests): remove invalid test case * fix: logical typo Co-authored-by: ehmicky <ehmicky@users.noreply.github.com> * test: assert that only imports and only exports work * test: added a failing test that I think should pass * fix(test): quirk in `requireExtractedFiles` * refactor: addressing code review * feat: surround in a feature flag * fix: sadly, I don't think I can use ?. just yet * chore: clean up as part of code review Co-Authored-By: Eduardo Bouças <mail@eduardoboucas.com> * fix: accidentally checked in test code Co-authored-by: ehmicky <ehmicky@users.noreply.github.com> Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
53d0281
commit 9b0c6d5
Showing
11 changed files
with
95 additions
and
13 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { readFile } = require('fs') | ||
const { promisify } = require('util') | ||
|
||
const pReadFile = promisify(readFile) | ||
|
||
const { init, parse } = require('es-module-lexer') | ||
|
||
const detectEsModule = async ({ mainFile }) => { | ||
if (!mainFile) { | ||
return false | ||
} | ||
|
||
try { | ||
const [mainFileContents] = await Promise.all([pReadFile(mainFile, 'utf8'), init]) | ||
const [imports, exports] = parse(mainFileContents) | ||
|
||
return imports.length !== 0 || exports.length !== 0 | ||
} catch { | ||
// If there are any problems with init or parsing, assume it's not an ES module | ||
return false | ||
} | ||
} | ||
|
||
module.exports = { detectEsModule } |
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
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
tests/fixtures/local-require-esm/function_export_only/function_export_only.js
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,2 @@ | ||
// eslint-disable-next-line node/no-unsupported-features/es-syntax | ||
export const howdy = 'Yee haw!' |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/local-require-esm/function_import_only/function_import_only.js
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,4 @@ | ||
// eslint-disable-next-line node/no-unsupported-features/es-syntax | ||
import getZero from '../function/file' | ||
|
||
getZero() |
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
9b0c6d5
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: 10.6s
largeDepsZisi: 58s