diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index c658fbc0..f07d5c91 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -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() + }, +) diff --git a/src/utils.js b/src/utils.js index 0f761e57..a515cead 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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('')