UNPKG

8.17 kBJavaScriptView Raw
1/*
2 @license
3 Rollup.js v2.75.7
4 Mon, 20 Jun 2022 07:24:02 GMT - commit 057171c2d3bc2092b7f543fc05ead01f12595f12
5
6 https://github.com/rollup/rollup
7
8 Released under the MIT License.
9*/
10'use strict';
11
12const rollup = require('./rollup.js');
13
14const commandAliases = {
15 c: 'config',
16 d: 'dir',
17 e: 'external',
18 f: 'format',
19 g: 'globals',
20 h: 'help',
21 i: 'input',
22 m: 'sourcemap',
23 n: 'name',
24 o: 'file',
25 p: 'plugin',
26 v: 'version',
27 w: 'watch'
28};
29function mergeOptions(config, rawCommandOptions = { external: [], globals: undefined }, defaultOnWarnHandler = rollup.defaultOnWarn) {
30 const command = getCommandOptions(rawCommandOptions);
31 const inputOptions = mergeInputOptions(config, command, defaultOnWarnHandler);
32 const warn = inputOptions.onwarn;
33 if (command.output) {
34 Object.assign(command, command.output);
35 }
36 const outputOptionsArray = rollup.ensureArray(config.output);
37 if (outputOptionsArray.length === 0)
38 outputOptionsArray.push({});
39 const outputOptions = outputOptionsArray.map(singleOutputOptions => mergeOutputOptions(singleOutputOptions, command, warn));
40 rollup.warnUnknownOptions(command, Object.keys(inputOptions).concat(Object.keys(outputOptions[0]).filter(option => option !== 'sourcemapPathTransform'), Object.keys(commandAliases), 'config', 'environment', 'plugin', 'silent', 'failAfterWarnings', 'stdin', 'waitForBundleInput', 'configPlugin'), 'CLI flags', warn, /^_$|output$|config/);
41 inputOptions.output = outputOptions;
42 return inputOptions;
43}
44function getCommandOptions(rawCommandOptions) {
45 const external = rawCommandOptions.external && typeof rawCommandOptions.external === 'string'
46 ? rawCommandOptions.external.split(',')
47 : [];
48 return {
49 ...rawCommandOptions,
50 external,
51 globals: typeof rawCommandOptions.globals === 'string'
52 ? rawCommandOptions.globals.split(',').reduce((globals, globalDefinition) => {
53 const [id, variableName] = globalDefinition.split(':');
54 globals[id] = variableName;
55 if (!external.includes(id)) {
56 external.push(id);
57 }
58 return globals;
59 }, Object.create(null))
60 : undefined
61 };
62}
63function mergeInputOptions(config, overrides, defaultOnWarnHandler) {
64 const getOption = (name) => { var _a; return (_a = overrides[name]) !== null && _a !== void 0 ? _a : config[name]; };
65 const inputOptions = {
66 acorn: getOption('acorn'),
67 acornInjectPlugins: config.acornInjectPlugins,
68 cache: config.cache,
69 context: getOption('context'),
70 experimentalCacheExpiry: getOption('experimentalCacheExpiry'),
71 external: getExternal(config, overrides),
72 inlineDynamicImports: getOption('inlineDynamicImports'),
73 input: getOption('input') || [],
74 makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
75 manualChunks: getOption('manualChunks'),
76 maxParallelFileReads: getOption('maxParallelFileReads'),
77 moduleContext: getOption('moduleContext'),
78 onwarn: getOnWarn(config, defaultOnWarnHandler),
79 perf: getOption('perf'),
80 plugins: rollup.ensureArray(config.plugins),
81 preserveEntrySignatures: getOption('preserveEntrySignatures'),
82 preserveModules: getOption('preserveModules'),
83 preserveSymlinks: getOption('preserveSymlinks'),
84 shimMissingExports: getOption('shimMissingExports'),
85 strictDeprecations: getOption('strictDeprecations'),
86 treeshake: getObjectOption(config, overrides, 'treeshake', rollup.objectifyOptionWithPresets(rollup.treeshakePresets, 'treeshake', 'false, true, ')),
87 watch: getWatch(config, overrides)
88 };
89 rollup.warnUnknownOptions(config, Object.keys(inputOptions), 'input options', inputOptions.onwarn, /^output$/);
90 return inputOptions;
91}
92const getExternal = (config, overrides) => {
93 const configExternal = config.external;
94 return typeof configExternal === 'function'
95 ? (source, importer, isResolved) => configExternal(source, importer, isResolved) || overrides.external.includes(source)
96 : rollup.ensureArray(configExternal).concat(overrides.external);
97};
98const getOnWarn = (config, defaultOnWarnHandler) => config.onwarn
99 ? warning => config.onwarn(warning, defaultOnWarnHandler)
100 : defaultOnWarnHandler;
101const getObjectOption = (config, overrides, name, objectifyValue = rollup.objectifyOption) => {
102 const commandOption = normalizeObjectOptionValue(overrides[name], objectifyValue);
103 const configOption = normalizeObjectOptionValue(config[name], objectifyValue);
104 if (commandOption !== undefined) {
105 return commandOption && { ...configOption, ...commandOption };
106 }
107 return configOption;
108};
109const getWatch = (config, overrides) => config.watch !== false && getObjectOption(config, overrides, 'watch');
110const isWatchEnabled = (optionValue) => {
111 if (Array.isArray(optionValue)) {
112 return optionValue.reduce((result, value) => (typeof value === 'boolean' ? value : result), false);
113 }
114 return optionValue === true;
115};
116const normalizeObjectOptionValue = (optionValue, objectifyValue) => {
117 if (!optionValue) {
118 return optionValue;
119 }
120 if (Array.isArray(optionValue)) {
121 return optionValue.reduce((result, value) => value && result && { ...result, ...objectifyValue(value) }, {});
122 }
123 return objectifyValue(optionValue);
124};
125function mergeOutputOptions(config, overrides, warn) {
126 const getOption = (name) => { var _a; return (_a = overrides[name]) !== null && _a !== void 0 ? _a : config[name]; };
127 const outputOptions = {
128 amd: getObjectOption(config, overrides, 'amd'),
129 assetFileNames: getOption('assetFileNames'),
130 banner: getOption('banner'),
131 chunkFileNames: getOption('chunkFileNames'),
132 compact: getOption('compact'),
133 dir: getOption('dir'),
134 dynamicImportFunction: getOption('dynamicImportFunction'),
135 entryFileNames: getOption('entryFileNames'),
136 esModule: getOption('esModule'),
137 exports: getOption('exports'),
138 extend: getOption('extend'),
139 externalLiveBindings: getOption('externalLiveBindings'),
140 file: getOption('file'),
141 footer: getOption('footer'),
142 format: getOption('format'),
143 freeze: getOption('freeze'),
144 generatedCode: getObjectOption(config, overrides, 'generatedCode', rollup.objectifyOptionWithPresets(rollup.generatedCodePresets, 'output.generatedCode', '')),
145 globals: getOption('globals'),
146 hoistTransitiveImports: getOption('hoistTransitiveImports'),
147 indent: getOption('indent'),
148 inlineDynamicImports: getOption('inlineDynamicImports'),
149 interop: getOption('interop'),
150 intro: getOption('intro'),
151 manualChunks: getOption('manualChunks'),
152 minifyInternalExports: getOption('minifyInternalExports'),
153 name: getOption('name'),
154 namespaceToStringTag: getOption('namespaceToStringTag'),
155 noConflict: getOption('noConflict'),
156 outro: getOption('outro'),
157 paths: getOption('paths'),
158 plugins: rollup.ensureArray(config.plugins),
159 preferConst: getOption('preferConst'),
160 preserveModules: getOption('preserveModules'),
161 preserveModulesRoot: getOption('preserveModulesRoot'),
162 sanitizeFileName: getOption('sanitizeFileName'),
163 sourcemap: getOption('sourcemap'),
164 sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
165 sourcemapFile: getOption('sourcemapFile'),
166 sourcemapPathTransform: getOption('sourcemapPathTransform'),
167 strict: getOption('strict'),
168 systemNullSetters: getOption('systemNullSetters'),
169 validate: getOption('validate')
170 };
171 rollup.warnUnknownOptions(config, Object.keys(outputOptions), 'output options', warn);
172 return outputOptions;
173}
174
175exports.commandAliases = commandAliases;
176exports.isWatchEnabled = isWatchEnabled;
177exports.mergeOptions = mergeOptions;
178//# sourceMappingURL=mergeOptions.js.map