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.
fix: output mjs and ts v2 functions with mjs extension (#1505)
* fix: output mjs and ts v2 functions with mjs extension * feat: use right extension for TS files * chore: formatting * chore: update paths in tests * chore: update paths in test * refactor: rename variable * refactor: remove unnecessary check * chore: update test * chore: rename variable * feat: ensure `package.json` with `type: "module"` * refactor: move logic to ZIP generator * refactor: reuse common method * chore: restructure code * feat: read tsconfig * chore: hello * refactor: revert abstraction * chore: add comment * chore: update vitest config * refactor: revert default value * fix: account for CJS and ESM entry files * feat: plant `package.json` * chore: add placeholder tsconfig * refactor: remove check for ESM * fix: emit ESM for `es6` and `es2015` * feat: set boundary to `tsconfig.json` * feat: add boundary for `package.json` search --------- Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
- Loading branch information
1 parent
9d3cc9a
commit 4bc75ba
Showing
27 changed files
with
211 additions
and
89 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
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
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,27 @@ | ||
import { dirname, relative } from 'path' | ||
|
||
import { getTsconfig } from 'get-tsconfig' | ||
|
||
import { MODULE_FORMAT } from './module_format.js' | ||
|
||
const esmModuleValues = new Set(['es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext']) | ||
|
||
// Returns the module format that should be used for a TypeScript file at a | ||
// given path, by reading the associated `tsconfig.json` file if it exists. | ||
export const getModuleFormat = (path: string, boundary?: string) => { | ||
const file = getTsconfig(path) | ||
|
||
if (!file) { | ||
return MODULE_FORMAT.COMMONJS | ||
} | ||
|
||
// If there is a boundary defined and the file we found is outside of it, | ||
// discard the file. | ||
if (boundary !== undefined && relative(boundary, dirname(file.path)).startsWith('..')) { | ||
return MODULE_FORMAT.COMMONJS | ||
} | ||
|
||
const moduleProp = file.config.compilerOptions?.module?.toLowerCase() ?? '' | ||
|
||
return esmModuleValues.has(moduleProp) ? MODULE_FORMAT.ESM : MODULE_FORMAT.COMMONJS | ||
} |
Oops, something went wrong.
4bc75ba
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