From 8825cdbabea4616a61f06cddc78e1d114523d8d5 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 2 Apr 2019 06:28:40 +0200 Subject: [PATCH] Support Node-style format aliases (#2783) * support Node-style format aliases * remove unnecessary fallback * add formats to typings --- src/rollup/types.d.ts | 11 ++++++++++- src/utils/mergeOptions.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 9fec100e5fc..189c49e8265 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -287,7 +287,16 @@ export interface InputOptions { watch?: WatcherOptions; } -export type ModuleFormat = 'amd' | 'cjs' | 'system' | 'es' | 'esm' | 'iife' | 'umd'; +export type ModuleFormat = + | 'amd' + | 'cjs' + | 'commonjs' + | 'es' + | 'esm' + | 'iife' + | 'module' + | 'system' + | 'umd'; export type OptionsPaths = Record | ((id: string) => string); diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index 8f8c2629a98..00455edc6e9 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -229,7 +229,17 @@ function getOutputOptions( command: GenericConfigObject = {} ): OutputOptions { const getOption = createGetOption(config, command); - const format = getOption('format'); + let format = getOption('format'); + + // Handle format aliases + switch (format) { + case 'esm': + case 'module': + format = 'es'; + break; + case 'commonjs': + format = 'cjs'; + } return { amd: { ...config.amd, ...command.amd },