UNPKG

7.35 kBJavaScriptView Raw
1/*
2 @license
3 Rollup.js v2.29.0
4 Thu, 08 Oct 2020 04:24:04 GMT - commit 0b02e52bc7816c473784794670a2c3047ac62a07
5
6
7 https://github.com/rollup/rollup
8
9 Released under the MIT License.
10*/
11'use strict';
12
13var 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'), '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 manualChunks: getOption('manualChunks'),
76 moduleContext: getOption('moduleContext'),
77 onwarn: getOnWarn(config, defaultOnWarnHandler),
78 perf: getOption('perf'),
79 plugins: rollup.ensureArray(config.plugins),
80 preserveEntrySignatures: getOption('preserveEntrySignatures'),
81 preserveModules: getOption('preserveModules'),
82 preserveSymlinks: getOption('preserveSymlinks'),
83 shimMissingExports: getOption('shimMissingExports'),
84 strictDeprecations: getOption('strictDeprecations'),
85 treeshake: getObjectOption(config, overrides, 'treeshake'),
86 watch: getWatch(config, overrides, 'watch')
87 };
88 rollup.warnUnknownOptions(config, Object.keys(inputOptions), 'input options', inputOptions.onwarn, /^output$/);
89 return inputOptions;
90}
91const getExternal = (config, overrides) => {
92 const configExternal = config.external;
93 return typeof configExternal === 'function'
94 ? (source, importer, isResolved) => configExternal(source, importer, isResolved) || overrides.external.indexOf(source) !== -1
95 : rollup.ensureArray(configExternal).concat(overrides.external);
96};
97const getOnWarn = (config, defaultOnWarnHandler) => config.onwarn
98 ? warning => config.onwarn(warning, defaultOnWarnHandler)
99 : defaultOnWarnHandler;
100const getObjectOption = (config, overrides, name) => {
101 const commandOption = normalizeObjectOptionValue(overrides[name]);
102 const configOption = normalizeObjectOptionValue(config[name]);
103 if (commandOption !== undefined) {
104 return commandOption && { ...configOption, ...commandOption };
105 }
106 return configOption;
107};
108const getWatch = (config, overrides, name) => config.watch !== false && getObjectOption(config, overrides, name);
109const normalizeObjectOptionValue = (optionValue) => {
110 if (!optionValue) {
111 return optionValue;
112 }
113 if (Array.isArray(optionValue)) {
114 return optionValue.reduce((result, value) => value && result && { ...result, ...value }, {});
115 }
116 if (typeof optionValue !== 'object') {
117 return {};
118 }
119 return optionValue;
120};
121function mergeOutputOptions(config, overrides, warn) {
122 const getOption = (name) => { var _a; return (_a = overrides[name]) !== null && _a !== void 0 ? _a : config[name]; };
123 const outputOptions = {
124 amd: getObjectOption(config, overrides, 'amd'),
125 assetFileNames: getOption('assetFileNames'),
126 banner: getOption('banner'),
127 chunkFileNames: getOption('chunkFileNames'),
128 compact: getOption('compact'),
129 dir: getOption('dir'),
130 dynamicImportFunction: getOption('dynamicImportFunction'),
131 entryFileNames: getOption('entryFileNames'),
132 esModule: getOption('esModule'),
133 exports: getOption('exports'),
134 extend: getOption('extend'),
135 externalLiveBindings: getOption('externalLiveBindings'),
136 file: getOption('file'),
137 footer: getOption('footer'),
138 format: getOption('format'),
139 freeze: getOption('freeze'),
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 sourcemap: getOption('sourcemap'),
158 sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
159 sourcemapFile: getOption('sourcemapFile'),
160 sourcemapPathTransform: getOption('sourcemapPathTransform'),
161 strict: getOption('strict'),
162 systemNullSetters: getOption('systemNullSetters')
163 };
164 rollup.warnUnknownOptions(config, Object.keys(outputOptions), 'output options', warn);
165 return outputOptions;
166}
167
168exports.commandAliases = commandAliases;
169exports.mergeOptions = mergeOptions;
170//# sourceMappingURL=mergeOptions.js.map