| 1027 | } |
| 1028 | |
| 1029 | export function resolveBuildOutputs( |
| 1030 | outputs: OutputOptions | OutputOptions[] | undefined, |
| 1031 | libOptions: LibraryOptions | false, |
| 1032 | logger: Logger, |
| 1033 | ): OutputOptions | OutputOptions[] | undefined { |
| 1034 | if (libOptions) { |
| 1035 | const libHasMultipleEntries = |
| 1036 | typeof libOptions.entry !== 'string' && |
| 1037 | Object.values(libOptions.entry).length > 1 |
| 1038 | const libFormats = |
| 1039 | libOptions.formats || |
| 1040 | (libHasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']) |
| 1041 | |
| 1042 | if (!Array.isArray(outputs)) { |
| 1043 | if (libFormats.includes('umd') || libFormats.includes('iife')) { |
| 1044 | if (libHasMultipleEntries) { |
| 1045 | throw new Error( |
| 1046 | 'Multiple entry points are not supported when output formats include "umd" or "iife".', |
| 1047 | ) |
| 1048 | } |
| 1049 | |
| 1050 | if (!libOptions.name) { |
| 1051 | throw new Error( |
| 1052 | 'Option "build.lib.name" is required when output formats include "umd" or "iife".', |
| 1053 | ) |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | return libFormats.map((format) => ({ ...outputs, format })) |
| 1058 | } |
| 1059 | |
| 1060 | // By this point, we know "outputs" is an Array. |
| 1061 | if (libOptions.formats) { |
| 1062 | logger.warn( |
| 1063 | colors.yellow( |
| 1064 | '"build.lib.formats" will be ignored because "build.rolldownOptions.output" is already an array format.', |
| 1065 | ), |
| 1066 | ) |
| 1067 | } |
| 1068 | |
| 1069 | outputs.forEach((output) => { |
| 1070 | if ( |
| 1071 | (output.format === 'umd' || output.format === 'iife') && |
| 1072 | !output.name |
| 1073 | ) { |
| 1074 | throw new Error( |
| 1075 | 'Entries in "build.rolldownOptions.output" must specify "name" when the format is "umd" or "iife".', |
| 1076 | ) |
| 1077 | } |
| 1078 | }) |
| 1079 | } |
| 1080 | |
| 1081 | return outputs |
| 1082 | } |
| 1083 | |
| 1084 | const warningIgnoreList = [`CIRCULAR_DEPENDENCY`, `THIS_IS_UNDEFINED`] |
| 1085 | const dynamicImportWarningIgnoreList = [ |