UNPKG

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