From 052786223edce8258c73a72a49238e41e5b24850 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sun, 27 Sep 2020 21:24:45 -0400 Subject: [PATCH] Support "esm" as an alias of "es" format (#722) Co-authored-by: Leah --- .changeset/hip-papayas-pretend.md | 5 +++++ src/index.js | 2 ++ test/__snapshots__/index.test.js.snap | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/hip-papayas-pretend.md diff --git a/.changeset/hip-papayas-pretend.md b/.changeset/hip-papayas-pretend.md new file mode 100644 index 00000000..120a8ac4 --- /dev/null +++ b/.changeset/hip-papayas-pretend.md @@ -0,0 +1,5 @@ +--- +"microbundle": patch +--- + +Support "esm" (`-f esm`) as an alias of "es" format. diff --git a/src/index.js b/src/index.js index 668a5a9e..0fac47bd 100644 --- a/src/index.js +++ b/src/index.js @@ -83,6 +83,8 @@ export default async function microbundle(inputOptions) { options.multipleEntries = options.entries.length > 1; let formats = (options.format || options.formats).split(','); + // de-dupe formats and convert "esm" to "es": + formats = Array.from(new Set(formats.map(f => (f === 'esm' ? 'es' : f)))); // always compile cjs first if it's there: formats.sort((a, b) => (a === 'cjs' ? -1 : a > b ? 1 : 0)); diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index d78a502b..f7c747f6 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1615,14 +1615,14 @@ Directory tree: define-expression dist - define-expression.js + define-expression.esm.js index.js package.json Build \\"defineExpression\\" to dist: -56 B: define-expression.js.gz -40 B: define-expression.js.br" +56 B: define-expression.esm.js.gz +40 B: define-expression.esm.js.br" `; exports[`fixtures build define-expression with microbundle 2`] = `1`;