UNPKG

7.95 kBJavaScriptView Raw
1/*
2 @license
3 Rollup.js v2.62.1
4 Sun, 13 Feb 2022 23:06:06 GMT - commit 159f1d7f9506bdd1266d9324efd48b2ec30f5f22
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.indexOf(id) === -1) {
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, 'watch')
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.indexOf(source) !== -1
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 = value => (typeof value === 'object' ? value : {})) => {
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, name) => config.watch !== false && getObjectOption(config, overrides, name);
111const normalizeObjectOptionValue = (optionValue, objectifyValue) => {
112 if (!optionValue) {
113 return optionValue;
114 }
115 if (Array.isArray(optionValue)) {
116 return optionValue.reduce((result, value) => value && result && { ...result, ...objectifyValue(value) }, {});
117 }
118 return objectifyValue(optionValue);
119};
120function mergeOutputOptions(config, overrides, warn) {
121 const getOption = (name) => { var _a; return (_a = overrides[name]) !== null && _a !== void 0 ? _a : config[name]; };
122 const outputOptions = {
123 amd: getObjectOption(config, overrides, 'amd'),
124 assetFileNames: getOption('assetFileNames'),
125 banner: getOption('banner'),
126 chunkFileNames: getOption('chunkFileNames'),
127 compact: getOption('compact'),
128 dir: getOption('dir'),
129 dynamicImportFunction: getOption('dynamicImportFunction'),
130 entryFileNames: getOption('entryFileNames'),
131 esModule: getOption('esModule'),
132 exports: getOption('exports'),
133 extend: getOption('extend'),
134 externalLiveBindings: getOption('externalLiveBindings'),
135 file: getOption('file'),
136 footer: getOption('footer'),
137 format: getOption('format'),
138 freeze: getOption('freeze'),
139 generatedCode: getObjectOption(config, overrides, 'generatedCode', rollup.objectifyOptionWithPresets(rollup.generatedCodePresets, 'output.generatedCode', '')),
140 globals: getOption('globals'),
141 hoistTransitiveImports: getOption('hoistTransitiveImports'),
142 indent: getOption('indent'),
143 inlineDynamicImports: getOption('inlineDynamicImports'),
144 interop: getOption('interop'),
145 intro: getOption('intro'),
146 manualChunks: getOption('manualChunks'),
147 minifyInternalExports: getOption('minifyInternalExports'),
148 name: getOption('name'),
149 namespaceToStringTag: getOption('namespaceToStringTag'),
150 noConflict: getOption('noConflict'),
151 outro: getOption('outro'),
152 paths: getOption('paths'),
153 plugins: rollup.ensureArray(config.plugins),
154 preferConst: getOption('preferConst'),
155 preserveModules: getOption('preserveModules'),
156 preserveModulesRoot: getOption('preserveModulesRoot'),
157 sanitizeFileName: getOption('sanitizeFileName'),
158 sourcemap: getOption('sourcemap'),
159 sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
160 sourcemapFile: getOption('sourcemapFile'),
161 sourcemapPathTransform: getOption('sourcemapPathTransform'),
162 strict: getOption('strict'),
163 systemNullSetters: getOption('systemNullSetters'),
164 validate: getOption('validate')
165 };
166 rollup.warnUnknownOptions(config, Object.keys(outputOptions), 'output options', warn);
167 return outputOptions;
168}
169
170exports.commandAliases = commandAliases;
171exports.mergeOptions = mergeOptions;
172//# sourceMappingURL=mergeOptions.js.map