Skip to content

Commit

Permalink
fix(utils): setup extension by format in getRollupOutput (#244)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Built files now have `.mjs` or `.cjs` for ESM and CJS respectively. You may need to update your exports configuration for your library.
  • Loading branch information
syi0808 authored Jul 11, 2024
1 parent e68fecc commit 530b9ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,17 @@ function mockCosmiconfig(result = null) {

cosmiconfigSync.mockImplementationOnce(() => ({search: () => result}))
}

test.each([
{format: 'cjs', extension: '.cjs'},
{format: 'esm', extension: '.mjs'},
{format: 'umd', extension: '.js'},
{format: 'amd', extension: '.js'},
])(
'file extension in rollupOutput with $format should be $extension',
({format, extension}) => {
expect(
require('../utils').getRollupOutput(format).filename.endsWith(extension),
).toBeTruthy()
},
)
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,17 @@ function getRollupInputs() {
function getRollupOutput(format = process.env.BUILD_FORMAT) {
const minify = parseEnv('BUILD_MINIFY', false)
const filenameSuffix = process.env.BUILD_FILENAME_SUFFIX || ''
const ext =
{
esm: '.mjs',
cjs: '.cjs',
}[format] || '.js'
const filename = [
pkg.name,
filenameSuffix,
`.${format}`,
minify ? '.min' : null,
'.js',
ext,
]
.filter(Boolean)
.join('')
Expand Down

0 comments on commit 530b9ea

Please sign in to comment.