rollup 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. #!/usr/bin/env node
  2. /*
  3. @license
  4. Rollup.js v2.77.3
  5. Thu, 11 Aug 2022 05:48:58 GMT - commit 1165d46685ef3c70617b2f150ab245ff5de5e783
  6. https://github.com/rollup/rollup
  7. Released under the MIT License.
  8. */
  9. 'use strict';
  10. Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
  11. const process$1 = require('process');
  12. const rollup = require('../shared/rollup.js');
  13. const require$$2 = require('util');
  14. const require$$0$1 = require('fs');
  15. const require$$0 = require('path');
  16. const mergeOptions = require('../shared/mergeOptions.js');
  17. const loadConfigFile_js = require('../shared/loadConfigFile.js');
  18. require('perf_hooks');
  19. require('crypto');
  20. require('events');
  21. require('url');
  22. require('tty');
  23. const help = "rollup version __VERSION__\n=====================================\n\nUsage: rollup [options] <entry file>\n\nBasic options:\n\n-c, --config <filename> Use this config file (if argument is used but value\n is unspecified, defaults to rollup.config.js)\n-d, --dir <dirname> Directory for chunks (if absent, prints to stdout)\n-e, --external <ids> Comma-separate list of module IDs to exclude\n-f, --format <format> Type of output (amd, cjs, es, iife, umd, system)\n-g, --globals <pairs> Comma-separate list of `moduleID:Global` pairs\n-h, --help Show this help message\n-i, --input <filename> Input (alternative to <entry file>)\n-m, --sourcemap Generate sourcemap (`-m inline` for inline map)\n-n, --name <name> Name for UMD export\n-o, --file <output> Single output file (if absent, prints to stdout)\n-p, --plugin <plugin> Use the plugin specified (may be repeated)\n-v, --version Show version number\n-w, --watch Watch files in bundle and rebuild on changes\n--amd.id <id> ID for AMD module (default is anonymous)\n--amd.autoId Generate the AMD ID based off the chunk name\n--amd.basePath <prefix> Path to prepend to auto generated AMD ID\n--amd.define <name> Function to use in place of `define`\n--assetFileNames <pattern> Name pattern for emitted assets\n--banner <text> Code to insert at top of bundle (outside wrapper)\n--chunkFileNames <pattern> Name pattern for emitted secondary chunks\n--compact Minify wrapper code\n--context <variable> Specify top-level `this` value\n--entryFileNames <pattern> Name pattern for emitted entry chunks\n--environment <values> Settings passed to config file (see example)\n--no-esModule Do not add __esModule property\n--exports <mode> Specify export mode (auto, default, named, none)\n--extend Extend global variable defined by --name\n--no-externalLiveBindings Do not generate code to support live bindings\n--failAfterWarnings Exit with an error if the build produced warnings\n--footer <text> Code to insert at end of bundle (outside wrapper)\n--no-freeze Do not freeze namespace objects\n--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks\n--no-indent Don't indent result\n--no-interop Do not include interop block\n--inlineDynamicImports Create single bundle when using dynamic imports\n--intro <text> Code to insert at top of bundle (inside wrapper)\n--minifyInternalExports Force or disable minification of internal exports\n--namespaceToStringTag Create proper `.toString` methods for namespaces\n--noConflict Generate a noConflict method for UMD globals\n--outro <text> Code to insert at end of bundle (inside wrapper)\n--preferConst Use `const` instead of `var` for exports\n--no-preserveEntrySignatures Avoid facade chunks for entry points\n--preserveModules Preserve module structure\n--preserveModulesRoot Put preserved modules under this path at root level\n--preserveSymlinks Do not follow symlinks when resolving files\n--no-sanitizeFileName Do not replace invalid characters in file names\n--shimMissingExports Create shim variables for missing exports\n--silent Don't print warnings\n--sourcemapBaseUrl <url> Emit absolute sourcemap URLs with given base\n--sourcemapExcludeSources Do not include source code in source maps\n--sourcemapFile <file> Specify bundle position for source maps\n--stdin=ext Specify file extension used for stdin input\n--no-stdin Do not read \"-\" from stdin\n--no-strict Don't emit `\"use strict\";` in the generated modules\n--strictDeprecations Throw errors for deprecated features\n--systemNullSetters Replace empty SystemJS setters with `null`\n--no-treeshake Disable tree-shaking optimisations\n--no-treeshake.annotations Ignore pure call annotations\n--no-treeshake.moduleSideEffects Assume modules have no side-effects\n--no-treeshake.propertyReadSideEffects Ignore property access side-effects\n--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking\n--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw\n--waitForBundleInput Wait for bundle input files\n--watch.buildDelay <number> Throttle watch rebuilds\n--no-watch.clearScreen Do not clear the screen when rebuilding\n--watch.skipWrite Do not write files to disk when watching\n--watch.exclude <files> Exclude files from being watched\n--watch.include <files> Limit watching to specified files\n--watch.onStart <cmd> Shell command to run on `\"START\"` event\n--watch.onBundleStart <cmd> Shell command to run on `\"BUNDLE_START\"` event\n--watch.onBundleEnd <cmd> Shell command to run on `\"BUNDLE_END\"` event\n--watch.onEnd <cmd> Shell command to run on `\"END\"` event\n--watch.onError <cmd> Shell command to run on `\"ERROR\"` event\n--validate Validate output\n\nExamples:\n\n# use settings in config file\nrollup -c\n\n# in config file, process.env.INCLUDE_DEPS === 'true'\n# and process.env.BUILD === 'production'\nrollup -c --environment INCLUDE_DEPS,BUILD:production\n\n# create CommonJS bundle.js from src/main.js\nrollup --format=cjs --file=bundle.js -- src/main.js\n\n# create self-executing IIFE using `window.jQuery`\n# and `window._` as external globals\nrollup -f iife --globals jquery:jQuery,lodash:_ \\\n -i src/app.js -o build/app.js -m build/app.js.map\n\nNotes:\n\n* When piping to stdout, only inline sourcemaps are permitted\n\nFor more information visit https://rollupjs.org\n";
  24. /**
  25. * @license
  26. * Copyright (c) 2016, Contributors
  27. * SPDX-License-Identifier: ISC
  28. */
  29. function camelCase(str) {
  30. // Handle the case where an argument is provided as camel case, e.g., fooBar.
  31. // by ensuring that the string isn't already mixed case:
  32. const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
  33. if (!isCamelCase) {
  34. str = str.toLowerCase();
  35. }
  36. if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
  37. return str;
  38. }
  39. else {
  40. let camelcase = '';
  41. let nextChrUpper = false;
  42. const leadingHyphens = str.match(/^-+/);
  43. for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {
  44. let chr = str.charAt(i);
  45. if (nextChrUpper) {
  46. nextChrUpper = false;
  47. chr = chr.toUpperCase();
  48. }
  49. if (i !== 0 && (chr === '-' || chr === '_')) {
  50. nextChrUpper = true;
  51. }
  52. else if (chr !== '-' && chr !== '_') {
  53. camelcase += chr;
  54. }
  55. }
  56. return camelcase;
  57. }
  58. }
  59. function decamelize(str, joinString) {
  60. const lowercase = str.toLowerCase();
  61. joinString = joinString || '-';
  62. let notCamelcase = '';
  63. for (let i = 0; i < str.length; i++) {
  64. const chrLower = lowercase.charAt(i);
  65. const chrString = str.charAt(i);
  66. if (chrLower !== chrString && i > 0) {
  67. notCamelcase += `${joinString}${lowercase.charAt(i)}`;
  68. }
  69. else {
  70. notCamelcase += chrString;
  71. }
  72. }
  73. return notCamelcase;
  74. }
  75. function looksLikeNumber(x) {
  76. if (x === null || x === undefined)
  77. return false;
  78. // if loaded from config, may already be a number.
  79. if (typeof x === 'number')
  80. return true;
  81. // hexadecimal.
  82. if (/^0x[0-9a-f]+$/i.test(x))
  83. return true;
  84. // don't treat 0123 as a number; as it drops the leading '0'.
  85. if (/^0[^.]/.test(x))
  86. return false;
  87. return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  88. }
  89. /**
  90. * @license
  91. * Copyright (c) 2016, Contributors
  92. * SPDX-License-Identifier: ISC
  93. */
  94. // take an un-split argv string and tokenize it.
  95. function tokenizeArgString(argString) {
  96. if (Array.isArray(argString)) {
  97. return argString.map(e => typeof e !== 'string' ? e + '' : e);
  98. }
  99. argString = argString.trim();
  100. let i = 0;
  101. let prevC = null;
  102. let c = null;
  103. let opening = null;
  104. const args = [];
  105. for (let ii = 0; ii < argString.length; ii++) {
  106. prevC = c;
  107. c = argString.charAt(ii);
  108. // split on spaces unless we're in quotes.
  109. if (c === ' ' && !opening) {
  110. if (!(prevC === ' ')) {
  111. i++;
  112. }
  113. continue;
  114. }
  115. // don't split the string if we're in matching
  116. // opening or closing single and double quotes.
  117. if (c === opening) {
  118. opening = null;
  119. }
  120. else if ((c === "'" || c === '"') && !opening) {
  121. opening = c;
  122. }
  123. if (!args[i])
  124. args[i] = '';
  125. args[i] += c;
  126. }
  127. return args;
  128. }
  129. /**
  130. * @license
  131. * Copyright (c) 2016, Contributors
  132. * SPDX-License-Identifier: ISC
  133. */
  134. var DefaultValuesForTypeKey;
  135. (function (DefaultValuesForTypeKey) {
  136. DefaultValuesForTypeKey["BOOLEAN"] = "boolean";
  137. DefaultValuesForTypeKey["STRING"] = "string";
  138. DefaultValuesForTypeKey["NUMBER"] = "number";
  139. DefaultValuesForTypeKey["ARRAY"] = "array";
  140. })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
  141. /**
  142. * @license
  143. * Copyright (c) 2016, Contributors
  144. * SPDX-License-Identifier: ISC
  145. */
  146. let mixin;
  147. class YargsParser {
  148. constructor(_mixin) {
  149. mixin = _mixin;
  150. }
  151. parse(argsInput, options) {
  152. const opts = Object.assign({
  153. alias: undefined,
  154. array: undefined,
  155. boolean: undefined,
  156. config: undefined,
  157. configObjects: undefined,
  158. configuration: undefined,
  159. coerce: undefined,
  160. count: undefined,
  161. default: undefined,
  162. envPrefix: undefined,
  163. narg: undefined,
  164. normalize: undefined,
  165. string: undefined,
  166. number: undefined,
  167. __: undefined,
  168. key: undefined
  169. }, options);
  170. // allow a string argument to be passed in rather
  171. // than an argv array.
  172. const args = tokenizeArgString(argsInput);
  173. // aliases might have transitive relationships, normalize this.
  174. const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
  175. const configuration = Object.assign({
  176. 'boolean-negation': true,
  177. 'camel-case-expansion': true,
  178. 'combine-arrays': false,
  179. 'dot-notation': true,
  180. 'duplicate-arguments-array': true,
  181. 'flatten-duplicate-arrays': true,
  182. 'greedy-arrays': true,
  183. 'halt-at-non-option': false,
  184. 'nargs-eats-options': false,
  185. 'negation-prefix': 'no-',
  186. 'parse-numbers': true,
  187. 'parse-positional-numbers': true,
  188. 'populate--': false,
  189. 'set-placeholder-key': false,
  190. 'short-option-groups': true,
  191. 'strip-aliased': false,
  192. 'strip-dashed': false,
  193. 'unknown-options-as-args': false
  194. }, opts.configuration);
  195. const defaults = Object.assign(Object.create(null), opts.default);
  196. const configObjects = opts.configObjects || [];
  197. const envPrefix = opts.envPrefix;
  198. const notFlagsOption = configuration['populate--'];
  199. const notFlagsArgv = notFlagsOption ? '--' : '_';
  200. const newAliases = Object.create(null);
  201. const defaulted = Object.create(null);
  202. // allow a i18n handler to be passed in, default to a fake one (util.format).
  203. const __ = opts.__ || mixin.format;
  204. const flags = {
  205. aliases: Object.create(null),
  206. arrays: Object.create(null),
  207. bools: Object.create(null),
  208. strings: Object.create(null),
  209. numbers: Object.create(null),
  210. counts: Object.create(null),
  211. normalize: Object.create(null),
  212. configs: Object.create(null),
  213. nargs: Object.create(null),
  214. coercions: Object.create(null),
  215. keys: []
  216. };
  217. const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
  218. const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');
  219. [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {
  220. const key = typeof opt === 'object' ? opt.key : opt;
  221. // assign to flags[bools|strings|numbers]
  222. const assignment = Object.keys(opt).map(function (key) {
  223. const arrayFlagKeys = {
  224. boolean: 'bools',
  225. string: 'strings',
  226. number: 'numbers'
  227. };
  228. return arrayFlagKeys[key];
  229. }).filter(Boolean).pop();
  230. // assign key to be coerced
  231. if (assignment) {
  232. flags[assignment][key] = true;
  233. }
  234. flags.arrays[key] = true;
  235. flags.keys.push(key);
  236. });
  237. [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {
  238. flags.bools[key] = true;
  239. flags.keys.push(key);
  240. });
  241. [].concat(opts.string || []).filter(Boolean).forEach(function (key) {
  242. flags.strings[key] = true;
  243. flags.keys.push(key);
  244. });
  245. [].concat(opts.number || []).filter(Boolean).forEach(function (key) {
  246. flags.numbers[key] = true;
  247. flags.keys.push(key);
  248. });
  249. [].concat(opts.count || []).filter(Boolean).forEach(function (key) {
  250. flags.counts[key] = true;
  251. flags.keys.push(key);
  252. });
  253. [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {
  254. flags.normalize[key] = true;
  255. flags.keys.push(key);
  256. });
  257. if (typeof opts.narg === 'object') {
  258. Object.entries(opts.narg).forEach(([key, value]) => {
  259. if (typeof value === 'number') {
  260. flags.nargs[key] = value;
  261. flags.keys.push(key);
  262. }
  263. });
  264. }
  265. if (typeof opts.coerce === 'object') {
  266. Object.entries(opts.coerce).forEach(([key, value]) => {
  267. if (typeof value === 'function') {
  268. flags.coercions[key] = value;
  269. flags.keys.push(key);
  270. }
  271. });
  272. }
  273. if (typeof opts.config !== 'undefined') {
  274. if (Array.isArray(opts.config) || typeof opts.config === 'string') {
  275. [].concat(opts.config).filter(Boolean).forEach(function (key) {
  276. flags.configs[key] = true;
  277. });
  278. }
  279. else if (typeof opts.config === 'object') {
  280. Object.entries(opts.config).forEach(([key, value]) => {
  281. if (typeof value === 'boolean' || typeof value === 'function') {
  282. flags.configs[key] = value;
  283. }
  284. });
  285. }
  286. }
  287. // create a lookup table that takes into account all
  288. // combinations of aliases: {f: ['foo'], foo: ['f']}
  289. extendAliases(opts.key, aliases, opts.default, flags.arrays);
  290. // apply default values to all aliases.
  291. Object.keys(defaults).forEach(function (key) {
  292. (flags.aliases[key] || []).forEach(function (alias) {
  293. defaults[alias] = defaults[key];
  294. });
  295. });
  296. let error = null;
  297. checkConfiguration();
  298. let notFlags = [];
  299. const argv = Object.assign(Object.create(null), { _: [] });
  300. // TODO(bcoe): for the first pass at removing object prototype we didn't
  301. // remove all prototypes from objects returned by this API, we might want
  302. // to gradually move towards doing so.
  303. const argvReturn = {};
  304. for (let i = 0; i < args.length; i++) {
  305. const arg = args[i];
  306. const truncatedArg = arg.replace(/^-{3,}/, '---');
  307. let broken;
  308. let key;
  309. let letters;
  310. let m;
  311. let next;
  312. let value;
  313. // any unknown option (except for end-of-options, "--")
  314. if (arg !== '--' && isUnknownOptionAsArg(arg)) {
  315. pushPositional(arg);
  316. // ---, ---=, ----, etc,
  317. }
  318. else if (truncatedArg.match(/---+(=|$)/)) {
  319. // options without key name are invalid.
  320. pushPositional(arg);
  321. continue;
  322. // -- separated by =
  323. }
  324. else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {
  325. // Using [\s\S] instead of . because js doesn't support the
  326. // 'dotall' regex modifier. See:
  327. // http://stackoverflow.com/a/1068308/13216
  328. m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
  329. // arrays format = '--f=a b c'
  330. if (m !== null && Array.isArray(m) && m.length >= 3) {
  331. if (checkAllAliases(m[1], flags.arrays)) {
  332. i = eatArray(i, m[1], args, m[2]);
  333. }
  334. else if (checkAllAliases(m[1], flags.nargs) !== false) {
  335. // nargs format = '--f=monkey washing cat'
  336. i = eatNargs(i, m[1], args, m[2]);
  337. }
  338. else {
  339. setArg(m[1], m[2]);
  340. }
  341. }
  342. }
  343. else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
  344. m = arg.match(negatedBoolean);
  345. if (m !== null && Array.isArray(m) && m.length >= 2) {
  346. key = m[1];
  347. setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
  348. }
  349. // -- separated by space.
  350. }
  351. else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {
  352. m = arg.match(/^--?(.+)/);
  353. if (m !== null && Array.isArray(m) && m.length >= 2) {
  354. key = m[1];
  355. if (checkAllAliases(key, flags.arrays)) {
  356. // array format = '--foo a b c'
  357. i = eatArray(i, key, args);
  358. }
  359. else if (checkAllAliases(key, flags.nargs) !== false) {
  360. // nargs format = '--foo a b c'
  361. // should be truthy even if: flags.nargs[key] === 0
  362. i = eatNargs(i, key, args);
  363. }
  364. else {
  365. next = args[i + 1];
  366. if (next !== undefined && (!next.match(/^-/) ||
  367. next.match(negative)) &&
  368. !checkAllAliases(key, flags.bools) &&
  369. !checkAllAliases(key, flags.counts)) {
  370. setArg(key, next);
  371. i++;
  372. }
  373. else if (/^(true|false)$/.test(next)) {
  374. setArg(key, next);
  375. i++;
  376. }
  377. else {
  378. setArg(key, defaultValue(key));
  379. }
  380. }
  381. }
  382. // dot-notation flag separated by '='.
  383. }
  384. else if (arg.match(/^-.\..+=/)) {
  385. m = arg.match(/^-([^=]+)=([\s\S]*)$/);
  386. if (m !== null && Array.isArray(m) && m.length >= 3) {
  387. setArg(m[1], m[2]);
  388. }
  389. // dot-notation flag separated by space.
  390. }
  391. else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
  392. next = args[i + 1];
  393. m = arg.match(/^-(.\..+)/);
  394. if (m !== null && Array.isArray(m) && m.length >= 2) {
  395. key = m[1];
  396. if (next !== undefined && !next.match(/^-/) &&
  397. !checkAllAliases(key, flags.bools) &&
  398. !checkAllAliases(key, flags.counts)) {
  399. setArg(key, next);
  400. i++;
  401. }
  402. else {
  403. setArg(key, defaultValue(key));
  404. }
  405. }
  406. }
  407. else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
  408. letters = arg.slice(1, -1).split('');
  409. broken = false;
  410. for (let j = 0; j < letters.length; j++) {
  411. next = arg.slice(j + 2);
  412. if (letters[j + 1] && letters[j + 1] === '=') {
  413. value = arg.slice(j + 3);
  414. key = letters[j];
  415. if (checkAllAliases(key, flags.arrays)) {
  416. // array format = '-f=a b c'
  417. i = eatArray(i, key, args, value);
  418. }
  419. else if (checkAllAliases(key, flags.nargs) !== false) {
  420. // nargs format = '-f=monkey washing cat'
  421. i = eatNargs(i, key, args, value);
  422. }
  423. else {
  424. setArg(key, value);
  425. }
  426. broken = true;
  427. break;
  428. }
  429. if (next === '-') {
  430. setArg(letters[j], next);
  431. continue;
  432. }
  433. // current letter is an alphabetic character and next value is a number
  434. if (/[A-Za-z]/.test(letters[j]) &&
  435. /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
  436. checkAllAliases(next, flags.bools) === false) {
  437. setArg(letters[j], next);
  438. broken = true;
  439. break;
  440. }
  441. if (letters[j + 1] && letters[j + 1].match(/\W/)) {
  442. setArg(letters[j], next);
  443. broken = true;
  444. break;
  445. }
  446. else {
  447. setArg(letters[j], defaultValue(letters[j]));
  448. }
  449. }
  450. key = arg.slice(-1)[0];
  451. if (!broken && key !== '-') {
  452. if (checkAllAliases(key, flags.arrays)) {
  453. // array format = '-f a b c'
  454. i = eatArray(i, key, args);
  455. }
  456. else if (checkAllAliases(key, flags.nargs) !== false) {
  457. // nargs format = '-f a b c'
  458. // should be truthy even if: flags.nargs[key] === 0
  459. i = eatNargs(i, key, args);
  460. }
  461. else {
  462. next = args[i + 1];
  463. if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||
  464. next.match(negative)) &&
  465. !checkAllAliases(key, flags.bools) &&
  466. !checkAllAliases(key, flags.counts)) {
  467. setArg(key, next);
  468. i++;
  469. }
  470. else if (/^(true|false)$/.test(next)) {
  471. setArg(key, next);
  472. i++;
  473. }
  474. else {
  475. setArg(key, defaultValue(key));
  476. }
  477. }
  478. }
  479. }
  480. else if (arg.match(/^-[0-9]$/) &&
  481. arg.match(negative) &&
  482. checkAllAliases(arg.slice(1), flags.bools)) {
  483. // single-digit boolean alias, e.g: xargs -0
  484. key = arg.slice(1);
  485. setArg(key, defaultValue(key));
  486. }
  487. else if (arg === '--') {
  488. notFlags = args.slice(i + 1);
  489. break;
  490. }
  491. else if (configuration['halt-at-non-option']) {
  492. notFlags = args.slice(i);
  493. break;
  494. }
  495. else {
  496. pushPositional(arg);
  497. }
  498. }
  499. // order of precedence:
  500. // 1. command line arg
  501. // 2. value from env var
  502. // 3. value from config file
  503. // 4. value from config objects
  504. // 5. configured default value
  505. applyEnvVars(argv, true); // special case: check env vars that point to config file
  506. applyEnvVars(argv, false);
  507. setConfig(argv);
  508. setConfigObjects();
  509. applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
  510. applyCoercions(argv);
  511. if (configuration['set-placeholder-key'])
  512. setPlaceholderKeys(argv);
  513. // for any counts either not in args or without an explicit default, set to 0
  514. Object.keys(flags.counts).forEach(function (key) {
  515. if (!hasKey(argv, key.split('.')))
  516. setArg(key, 0);
  517. });
  518. // '--' defaults to undefined.
  519. if (notFlagsOption && notFlags.length)
  520. argv[notFlagsArgv] = [];
  521. notFlags.forEach(function (key) {
  522. argv[notFlagsArgv].push(key);
  523. });
  524. if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {
  525. Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {
  526. delete argv[key];
  527. });
  528. }
  529. if (configuration['strip-aliased']) {
  530. [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
  531. if (configuration['camel-case-expansion'] && alias.includes('-')) {
  532. delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];
  533. }
  534. delete argv[alias];
  535. });
  536. }
  537. // Push argument into positional array, applying numeric coercion:
  538. function pushPositional(arg) {
  539. const maybeCoercedNumber = maybeCoerceNumber('_', arg);
  540. if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {
  541. argv._.push(maybeCoercedNumber);
  542. }
  543. }
  544. // how many arguments should we consume, based
  545. // on the nargs option?
  546. function eatNargs(i, key, args, argAfterEqualSign) {
  547. let ii;
  548. let toEat = checkAllAliases(key, flags.nargs);
  549. // NaN has a special meaning for the array type, indicating that one or
  550. // more values are expected.
  551. toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;
  552. if (toEat === 0) {
  553. if (!isUndefined(argAfterEqualSign)) {
  554. error = Error(__('Argument unexpected for: %s', key));
  555. }
  556. setArg(key, defaultValue(key));
  557. return i;
  558. }
  559. let available = isUndefined(argAfterEqualSign) ? 0 : 1;
  560. if (configuration['nargs-eats-options']) {
  561. // classic behavior, yargs eats positional and dash arguments.
  562. if (args.length - (i + 1) + available < toEat) {
  563. error = Error(__('Not enough arguments following: %s', key));
  564. }
  565. available = toEat;
  566. }
  567. else {
  568. // nargs will not consume flag arguments, e.g., -abc, --foo,
  569. // and terminates when one is observed.
  570. for (ii = i + 1; ii < args.length; ii++) {
  571. if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))
  572. available++;
  573. else
  574. break;
  575. }
  576. if (available < toEat)
  577. error = Error(__('Not enough arguments following: %s', key));
  578. }
  579. let consumed = Math.min(available, toEat);
  580. if (!isUndefined(argAfterEqualSign) && consumed > 0) {
  581. setArg(key, argAfterEqualSign);
  582. consumed--;
  583. }
  584. for (ii = i + 1; ii < (consumed + i + 1); ii++) {
  585. setArg(key, args[ii]);
  586. }
  587. return (i + consumed);
  588. }
  589. // if an option is an array, eat all non-hyphenated arguments
  590. // following it... YUM!
  591. // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
  592. function eatArray(i, key, args, argAfterEqualSign) {
  593. let argsToSet = [];
  594. let next = argAfterEqualSign || args[i + 1];
  595. // If both array and nargs are configured, enforce the nargs count:
  596. const nargsCount = checkAllAliases(key, flags.nargs);
  597. if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
  598. argsToSet.push(true);
  599. }
  600. else if (isUndefined(next) ||
  601. (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
  602. // for keys without value ==> argsToSet remains an empty []
  603. // set user default value, if available
  604. if (defaults[key] !== undefined) {
  605. const defVal = defaults[key];
  606. argsToSet = Array.isArray(defVal) ? defVal : [defVal];
  607. }
  608. }
  609. else {
  610. // value in --option=value is eaten as is
  611. if (!isUndefined(argAfterEqualSign)) {
  612. argsToSet.push(processValue(key, argAfterEqualSign));
  613. }
  614. for (let ii = i + 1; ii < args.length; ii++) {
  615. if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
  616. (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))
  617. break;
  618. next = args[ii];
  619. if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
  620. break;
  621. i = ii;
  622. argsToSet.push(processValue(key, next));
  623. }
  624. }
  625. // If both array and nargs are configured, create an error if less than
  626. // nargs positionals were found. NaN has special meaning, indicating
  627. // that at least one value is required (more are okay).
  628. if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
  629. (isNaN(nargsCount) && argsToSet.length === 0))) {
  630. error = Error(__('Not enough arguments following: %s', key));
  631. }
  632. setArg(key, argsToSet);
  633. return i;
  634. }
  635. function setArg(key, val) {
  636. if (/-/.test(key) && configuration['camel-case-expansion']) {
  637. const alias = key.split('.').map(function (prop) {
  638. return camelCase(prop);
  639. }).join('.');
  640. addNewAlias(key, alias);
  641. }
  642. const value = processValue(key, val);
  643. const splitKey = key.split('.');
  644. setKey(argv, splitKey, value);
  645. // handle populating aliases of the full key
  646. if (flags.aliases[key]) {
  647. flags.aliases[key].forEach(function (x) {
  648. const keyProperties = x.split('.');
  649. setKey(argv, keyProperties, value);
  650. });
  651. }
  652. // handle populating aliases of the first element of the dot-notation key
  653. if (splitKey.length > 1 && configuration['dot-notation']) {
  654. (flags.aliases[splitKey[0]] || []).forEach(function (x) {
  655. let keyProperties = x.split('.');
  656. // expand alias with nested objects in key
  657. const a = [].concat(splitKey);
  658. a.shift(); // nuke the old key.
  659. keyProperties = keyProperties.concat(a);
  660. // populate alias only if is not already an alias of the full key
  661. // (already populated above)
  662. if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {
  663. setKey(argv, keyProperties, value);
  664. }
  665. });
  666. }
  667. // Set normalize getter and setter when key is in 'normalize' but isn't an array
  668. if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
  669. const keys = [key].concat(flags.aliases[key] || []);
  670. keys.forEach(function (key) {
  671. Object.defineProperty(argvReturn, key, {
  672. enumerable: true,
  673. get() {
  674. return val;
  675. },
  676. set(value) {
  677. val = typeof value === 'string' ? mixin.normalize(value) : value;
  678. }
  679. });
  680. });
  681. }
  682. }
  683. function addNewAlias(key, alias) {
  684. if (!(flags.aliases[key] && flags.aliases[key].length)) {
  685. flags.aliases[key] = [alias];
  686. newAliases[alias] = true;
  687. }
  688. if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
  689. addNewAlias(alias, key);
  690. }
  691. }
  692. function processValue(key, val) {
  693. // strings may be quoted, clean this up as we assign values.
  694. if (typeof val === 'string' &&
  695. (val[0] === "'" || val[0] === '"') &&
  696. val[val.length - 1] === val[0]) {
  697. val = val.substring(1, val.length - 1);
  698. }
  699. // handle parsing boolean arguments --foo=true --bar false.
  700. if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
  701. if (typeof val === 'string')
  702. val = val === 'true';
  703. }
  704. let value = Array.isArray(val)
  705. ? val.map(function (v) { return maybeCoerceNumber(key, v); })
  706. : maybeCoerceNumber(key, val);
  707. // increment a count given as arg (either no value or value parsed as boolean)
  708. if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
  709. value = increment();
  710. }
  711. // Set normalized value when key is in 'normalize' and in 'arrays'
  712. if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
  713. if (Array.isArray(val))
  714. value = val.map((val) => { return mixin.normalize(val); });
  715. else
  716. value = mixin.normalize(val);
  717. }
  718. return value;
  719. }
  720. function maybeCoerceNumber(key, value) {
  721. if (!configuration['parse-positional-numbers'] && key === '_')
  722. return value;
  723. if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
  724. const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));
  725. if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {
  726. value = Number(value);
  727. }
  728. }
  729. return value;
  730. }
  731. // set args from config.json file, this should be
  732. // applied last so that defaults can be applied.
  733. function setConfig(argv) {
  734. const configLookup = Object.create(null);
  735. // expand defaults/aliases, in-case any happen to reference
  736. // the config.json file.
  737. applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
  738. Object.keys(flags.configs).forEach(function (configKey) {
  739. const configPath = argv[configKey] || configLookup[configKey];
  740. if (configPath) {
  741. try {
  742. let config = null;
  743. const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath);
  744. const resolveConfig = flags.configs[configKey];
  745. if (typeof resolveConfig === 'function') {
  746. try {
  747. config = resolveConfig(resolvedConfigPath);
  748. }
  749. catch (e) {
  750. config = e;
  751. }
  752. if (config instanceof Error) {
  753. error = config;
  754. return;
  755. }
  756. }
  757. else {
  758. config = mixin.require(resolvedConfigPath);
  759. }
  760. setConfigObject(config);
  761. }
  762. catch (ex) {
  763. // Deno will receive a PermissionDenied error if an attempt is
  764. // made to load config without the --allow-read flag:
  765. if (ex.name === 'PermissionDenied')
  766. error = ex;
  767. else if (argv[configKey])
  768. error = Error(__('Invalid JSON config file: %s', configPath));
  769. }
  770. }
  771. });
  772. }
  773. // set args from config object.
  774. // it recursively checks nested objects.
  775. function setConfigObject(config, prev) {
  776. Object.keys(config).forEach(function (key) {
  777. const value = config[key];
  778. const fullKey = prev ? prev + '.' + key : key;
  779. // if the value is an inner object and we have dot-notation
  780. // enabled, treat inner objects in config the same as
  781. // heavily nested dot notations (foo.bar.apple).
  782. if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
  783. // if the value is an object but not an array, check nested object
  784. setConfigObject(value, fullKey);
  785. }
  786. else {
  787. // setting arguments via CLI takes precedence over
  788. // values within the config file.
  789. if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
  790. setArg(fullKey, value);
  791. }
  792. }
  793. });
  794. }
  795. // set all config objects passed in opts
  796. function setConfigObjects() {
  797. if (typeof configObjects !== 'undefined') {
  798. configObjects.forEach(function (configObject) {
  799. setConfigObject(configObject);
  800. });
  801. }
  802. }
  803. function applyEnvVars(argv, configOnly) {
  804. if (typeof envPrefix === 'undefined')
  805. return;
  806. const prefix = typeof envPrefix === 'string' ? envPrefix : '';
  807. const env = mixin.env();
  808. Object.keys(env).forEach(function (envVar) {
  809. if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
  810. // get array of nested keys and convert them to camel case
  811. const keys = envVar.split('__').map(function (key, i) {
  812. if (i === 0) {
  813. key = key.substring(prefix.length);
  814. }
  815. return camelCase(key);
  816. });
  817. if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {
  818. setArg(keys.join('.'), env[envVar]);
  819. }
  820. }
  821. });
  822. }
  823. function applyCoercions(argv) {
  824. let coerce;
  825. const applied = new Set();
  826. Object.keys(argv).forEach(function (key) {
  827. if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
  828. coerce = checkAllAliases(key, flags.coercions);
  829. if (typeof coerce === 'function') {
  830. try {
  831. const value = maybeCoerceNumber(key, coerce(argv[key]));
  832. ([].concat(flags.aliases[key] || [], key)).forEach(ali => {
  833. applied.add(ali);
  834. argv[ali] = value;
  835. });
  836. }
  837. catch (err) {
  838. error = err;
  839. }
  840. }
  841. }
  842. });
  843. }
  844. function setPlaceholderKeys(argv) {
  845. flags.keys.forEach((key) => {
  846. // don't set placeholder keys for dot notation options 'foo.bar'.
  847. if (~key.indexOf('.'))
  848. return;
  849. if (typeof argv[key] === 'undefined')
  850. argv[key] = undefined;
  851. });
  852. return argv;
  853. }
  854. function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {
  855. Object.keys(defaults).forEach(function (key) {
  856. if (!hasKey(obj, key.split('.'))) {
  857. setKey(obj, key.split('.'), defaults[key]);
  858. if (canLog)
  859. defaulted[key] = true;
  860. (aliases[key] || []).forEach(function (x) {
  861. if (hasKey(obj, x.split('.')))
  862. return;
  863. setKey(obj, x.split('.'), defaults[key]);
  864. });
  865. }
  866. });
  867. }
  868. function hasKey(obj, keys) {
  869. let o = obj;
  870. if (!configuration['dot-notation'])
  871. keys = [keys.join('.')];
  872. keys.slice(0, -1).forEach(function (key) {
  873. o = (o[key] || {});
  874. });
  875. const key = keys[keys.length - 1];
  876. if (typeof o !== 'object')
  877. return false;
  878. else
  879. return key in o;
  880. }
  881. function setKey(obj, keys, value) {
  882. let o = obj;
  883. if (!configuration['dot-notation'])
  884. keys = [keys.join('.')];
  885. keys.slice(0, -1).forEach(function (key) {
  886. // TODO(bcoe): in the next major version of yargs, switch to
  887. // Object.create(null) for dot notation:
  888. key = sanitizeKey(key);
  889. if (typeof o === 'object' && o[key] === undefined) {
  890. o[key] = {};
  891. }
  892. if (typeof o[key] !== 'object' || Array.isArray(o[key])) {
  893. // ensure that o[key] is an array, and that the last item is an empty object.
  894. if (Array.isArray(o[key])) {
  895. o[key].push({});
  896. }
  897. else {
  898. o[key] = [o[key], {}];
  899. }
  900. // we want to update the empty object at the end of the o[key] array, so set o to that object
  901. o = o[key][o[key].length - 1];
  902. }
  903. else {
  904. o = o[key];
  905. }
  906. });
  907. // TODO(bcoe): in the next major version of yargs, switch to
  908. // Object.create(null) for dot notation:
  909. const key = sanitizeKey(keys[keys.length - 1]);
  910. const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
  911. const isValueArray = Array.isArray(value);
  912. let duplicate = configuration['duplicate-arguments-array'];
  913. // nargs has higher priority than duplicate
  914. if (!duplicate && checkAllAliases(key, flags.nargs)) {
  915. duplicate = true;
  916. if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {
  917. o[key] = undefined;
  918. }
  919. }
  920. if (value === increment()) {
  921. o[key] = increment(o[key]);
  922. }
  923. else if (Array.isArray(o[key])) {
  924. if (duplicate && isTypeArray && isValueArray) {
  925. o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
  926. }
  927. else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
  928. o[key] = value;
  929. }
  930. else {
  931. o[key] = o[key].concat([value]);
  932. }
  933. }
  934. else if (o[key] === undefined && isTypeArray) {
  935. o[key] = isValueArray ? value : [value];
  936. }
  937. else if (duplicate && !(o[key] === undefined ||
  938. checkAllAliases(key, flags.counts) ||
  939. checkAllAliases(key, flags.bools))) {
  940. o[key] = [o[key], value];
  941. }
  942. else {
  943. o[key] = value;
  944. }
  945. }
  946. // extend the aliases list with inferred aliases.
  947. function extendAliases(...args) {
  948. args.forEach(function (obj) {
  949. Object.keys(obj || {}).forEach(function (key) {
  950. // short-circuit if we've already added a key
  951. // to the aliases array, for example it might
  952. // exist in both 'opts.default' and 'opts.key'.
  953. if (flags.aliases[key])
  954. return;
  955. flags.aliases[key] = [].concat(aliases[key] || []);
  956. // For "--option-name", also set argv.optionName
  957. flags.aliases[key].concat(key).forEach(function (x) {
  958. if (/-/.test(x) && configuration['camel-case-expansion']) {
  959. const c = camelCase(x);
  960. if (c !== key && flags.aliases[key].indexOf(c) === -1) {
  961. flags.aliases[key].push(c);
  962. newAliases[c] = true;
  963. }
  964. }
  965. });
  966. // For "--optionName", also set argv['option-name']
  967. flags.aliases[key].concat(key).forEach(function (x) {
  968. if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
  969. const c = decamelize(x, '-');
  970. if (c !== key && flags.aliases[key].indexOf(c) === -1) {
  971. flags.aliases[key].push(c);
  972. newAliases[c] = true;
  973. }
  974. }
  975. });
  976. flags.aliases[key].forEach(function (x) {
  977. flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {
  978. return x !== y;
  979. }));
  980. });
  981. });
  982. });
  983. }
  984. function checkAllAliases(key, flag) {
  985. const toCheck = [].concat(flags.aliases[key] || [], key);
  986. const keys = Object.keys(flag);
  987. const setAlias = toCheck.find(key => keys.includes(key));
  988. return setAlias ? flag[setAlias] : false;
  989. }
  990. function hasAnyFlag(key) {
  991. const flagsKeys = Object.keys(flags);
  992. const toCheck = [].concat(flagsKeys.map(k => flags[k]));
  993. return toCheck.some(function (flag) {
  994. return Array.isArray(flag) ? flag.includes(key) : flag[key];
  995. });
  996. }
  997. function hasFlagsMatching(arg, ...patterns) {
  998. const toCheck = [].concat(...patterns);
  999. return toCheck.some(function (pattern) {
  1000. const match = arg.match(pattern);
  1001. return match && hasAnyFlag(match[1]);
  1002. });
  1003. }
  1004. // based on a simplified version of the short flag group parsing logic
  1005. function hasAllShortFlags(arg) {
  1006. // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
  1007. if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
  1008. return false;
  1009. }
  1010. let hasAllFlags = true;
  1011. let next;
  1012. const letters = arg.slice(1).split('');
  1013. for (let j = 0; j < letters.length; j++) {
  1014. next = arg.slice(j + 2);
  1015. if (!hasAnyFlag(letters[j])) {
  1016. hasAllFlags = false;
  1017. break;
  1018. }
  1019. if ((letters[j + 1] && letters[j + 1] === '=') ||
  1020. next === '-' ||
  1021. (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||
  1022. (letters[j + 1] && letters[j + 1].match(/\W/))) {
  1023. break;
  1024. }
  1025. }
  1026. return hasAllFlags;
  1027. }
  1028. function isUnknownOptionAsArg(arg) {
  1029. return configuration['unknown-options-as-args'] && isUnknownOption(arg);
  1030. }
  1031. function isUnknownOption(arg) {
  1032. arg = arg.replace(/^-{3,}/, '--');
  1033. // ignore negative numbers
  1034. if (arg.match(negative)) {
  1035. return false;
  1036. }
  1037. // if this is a short option group and all of them are configured, it isn't unknown
  1038. if (hasAllShortFlags(arg)) {
  1039. return false;
  1040. }
  1041. // e.g. '--count=2'
  1042. const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
  1043. // e.g. '-a' or '--arg'
  1044. const normalFlag = /^-+([^=]+?)$/;
  1045. // e.g. '-a-'
  1046. const flagEndingInHyphen = /^-+([^=]+?)-$/;
  1047. // e.g. '-abc123'
  1048. const flagEndingInDigits = /^-+([^=]+?\d+)$/;
  1049. // e.g. '-a/usr/local'
  1050. const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
  1051. // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
  1052. return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
  1053. }
  1054. // make a best effort to pick a default value
  1055. // for an option based on name and type.
  1056. function defaultValue(key) {
  1057. if (!checkAllAliases(key, flags.bools) &&
  1058. !checkAllAliases(key, flags.counts) &&
  1059. `${key}` in defaults) {
  1060. return defaults[key];
  1061. }
  1062. else {
  1063. return defaultForType(guessType(key));
  1064. }
  1065. }
  1066. // return a default value, given the type of a flag.,
  1067. function defaultForType(type) {
  1068. const def = {
  1069. [DefaultValuesForTypeKey.BOOLEAN]: true,
  1070. [DefaultValuesForTypeKey.STRING]: '',
  1071. [DefaultValuesForTypeKey.NUMBER]: undefined,
  1072. [DefaultValuesForTypeKey.ARRAY]: []
  1073. };
  1074. return def[type];
  1075. }
  1076. // given a flag, enforce a default type.
  1077. function guessType(key) {
  1078. let type = DefaultValuesForTypeKey.BOOLEAN;
  1079. if (checkAllAliases(key, flags.strings))
  1080. type = DefaultValuesForTypeKey.STRING;
  1081. else if (checkAllAliases(key, flags.numbers))
  1082. type = DefaultValuesForTypeKey.NUMBER;
  1083. else if (checkAllAliases(key, flags.bools))
  1084. type = DefaultValuesForTypeKey.BOOLEAN;
  1085. else if (checkAllAliases(key, flags.arrays))
  1086. type = DefaultValuesForTypeKey.ARRAY;
  1087. return type;
  1088. }
  1089. function isUndefined(num) {
  1090. return num === undefined;
  1091. }
  1092. // check user configuration settings for inconsistencies
  1093. function checkConfiguration() {
  1094. // count keys should not be set as array/narg
  1095. Object.keys(flags.counts).find(key => {
  1096. if (checkAllAliases(key, flags.arrays)) {
  1097. error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));
  1098. return true;
  1099. }
  1100. else if (checkAllAliases(key, flags.nargs)) {
  1101. error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));
  1102. return true;
  1103. }
  1104. return false;
  1105. });
  1106. }
  1107. return {
  1108. aliases: Object.assign({}, flags.aliases),
  1109. argv: Object.assign(argvReturn, argv),
  1110. configuration: configuration,
  1111. defaulted: Object.assign({}, defaulted),
  1112. error: error,
  1113. newAliases: Object.assign({}, newAliases)
  1114. };
  1115. }
  1116. }
  1117. // if any aliases reference each other, we should
  1118. // merge them together.
  1119. function combineAliases(aliases) {
  1120. const aliasArrays = [];
  1121. const combined = Object.create(null);
  1122. let change = true;
  1123. // turn alias lookup hash {key: ['alias1', 'alias2']} into
  1124. // a simple array ['key', 'alias1', 'alias2']
  1125. Object.keys(aliases).forEach(function (key) {
  1126. aliasArrays.push([].concat(aliases[key], key));
  1127. });
  1128. // combine arrays until zero changes are
  1129. // made in an iteration.
  1130. while (change) {
  1131. change = false;
  1132. for (let i = 0; i < aliasArrays.length; i++) {
  1133. for (let ii = i + 1; ii < aliasArrays.length; ii++) {
  1134. const intersect = aliasArrays[i].filter(function (v) {
  1135. return aliasArrays[ii].indexOf(v) !== -1;
  1136. });
  1137. if (intersect.length) {
  1138. aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
  1139. aliasArrays.splice(ii, 1);
  1140. change = true;
  1141. break;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. // map arrays back to the hash-lookup (de-dupe while
  1147. // we're at it).
  1148. aliasArrays.forEach(function (aliasArray) {
  1149. aliasArray = aliasArray.filter(function (v, i, self) {
  1150. return self.indexOf(v) === i;
  1151. });
  1152. const lastAlias = aliasArray.pop();
  1153. if (lastAlias !== undefined && typeof lastAlias === 'string') {
  1154. combined[lastAlias] = aliasArray;
  1155. }
  1156. });
  1157. return combined;
  1158. }
  1159. // this function should only be called when a count is given as an arg
  1160. // it is NOT called to set a default value
  1161. // thus we can start the count at 1 instead of 0
  1162. function increment(orig) {
  1163. return orig !== undefined ? orig + 1 : 1;
  1164. }
  1165. // TODO(bcoe): in the next major version of yargs, switch to
  1166. // Object.create(null) for dot notation:
  1167. function sanitizeKey(key) {
  1168. if (key === '__proto__')
  1169. return '___proto___';
  1170. return key;
  1171. }
  1172. /**
  1173. * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
  1174. * CJS and ESM environments.
  1175. *
  1176. * @license
  1177. * Copyright (c) 2016, Contributors
  1178. * SPDX-License-Identifier: ISC
  1179. */
  1180. // See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
  1181. // version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
  1182. const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
  1183. ? Number(process.env.YARGS_MIN_NODE_VERSION)
  1184. : 10;
  1185. if (process && process.version) {
  1186. const major = Number(process.version.match(/v([^.]+)/)[1]);
  1187. if (major < minNodeVersion) {
  1188. throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
  1189. }
  1190. }
  1191. // Creates a yargs-parser instance using Node.js standard libraries:
  1192. const env = process ? process.env : {};
  1193. const parser = new YargsParser({
  1194. cwd: process.cwd,
  1195. env: () => {
  1196. return env;
  1197. },
  1198. format: require$$2.format,
  1199. normalize: require$$0.normalize,
  1200. resolve: require$$0.resolve,
  1201. // TODO: figure out a way to combine ESM and CJS coverage, such that
  1202. // we can exercise all the lines below:
  1203. require: (path) => {
  1204. if (typeof require !== 'undefined') {
  1205. return require(path);
  1206. }
  1207. else if (path.match(/\.json$/)) {
  1208. return require$$0$1.readFileSync(path, 'utf8');
  1209. }
  1210. else {
  1211. throw Error('only .json config files are supported in ESM');
  1212. }
  1213. }
  1214. });
  1215. const yargsParser = function Parser(args, opts) {
  1216. const result = parser.parse(args.slice(), opts);
  1217. return result.argv;
  1218. };
  1219. yargsParser.detailed = function (args, opts) {
  1220. return parser.parse(args.slice(), opts);
  1221. };
  1222. yargsParser.camelCase = camelCase;
  1223. yargsParser.decamelize = decamelize;
  1224. yargsParser.looksLikeNumber = looksLikeNumber;
  1225. const argParser = yargsParser;
  1226. var parseMs = milliseconds => {
  1227. if (typeof milliseconds !== 'number') {
  1228. throw new TypeError('Expected a number');
  1229. }
  1230. const roundTowardsZero = milliseconds > 0 ? Math.floor : Math.ceil;
  1231. return {
  1232. days: roundTowardsZero(milliseconds / 86400000),
  1233. hours: roundTowardsZero(milliseconds / 3600000) % 24,
  1234. minutes: roundTowardsZero(milliseconds / 60000) % 60,
  1235. seconds: roundTowardsZero(milliseconds / 1000) % 60,
  1236. milliseconds: roundTowardsZero(milliseconds) % 1000,
  1237. microseconds: roundTowardsZero(milliseconds * 1000) % 1000,
  1238. nanoseconds: roundTowardsZero(milliseconds * 1e6) % 1000
  1239. };
  1240. };
  1241. const parseMilliseconds = parseMs;
  1242. const pluralize = (word, count) => count === 1 ? word : `${word}s`;
  1243. const SECOND_ROUNDING_EPSILON = 0.0000001;
  1244. var prettyMs = (milliseconds, options = {}) => {
  1245. if (!Number.isFinite(milliseconds)) {
  1246. throw new TypeError('Expected a finite number');
  1247. }
  1248. if (options.colonNotation) {
  1249. options.compact = false;
  1250. options.formatSubMilliseconds = false;
  1251. options.separateMilliseconds = false;
  1252. options.verbose = false;
  1253. }
  1254. if (options.compact) {
  1255. options.secondsDecimalDigits = 0;
  1256. options.millisecondsDecimalDigits = 0;
  1257. }
  1258. const result = [];
  1259. const floorDecimals = (value, decimalDigits) => {
  1260. const flooredInterimValue = Math.floor((value * (10 ** decimalDigits)) + SECOND_ROUNDING_EPSILON);
  1261. const flooredValue = Math.round(flooredInterimValue) / (10 ** decimalDigits);
  1262. return flooredValue.toFixed(decimalDigits);
  1263. };
  1264. const add = (value, long, short, valueString) => {
  1265. if ((result.length === 0 || !options.colonNotation) && value === 0 && !(options.colonNotation && short === 'm')) {
  1266. return;
  1267. }
  1268. valueString = (valueString || value || '0').toString();
  1269. let prefix;
  1270. let suffix;
  1271. if (options.colonNotation) {
  1272. prefix = result.length > 0 ? ':' : '';
  1273. suffix = '';
  1274. const wholeDigits = valueString.includes('.') ? valueString.split('.')[0].length : valueString.length;
  1275. const minLength = result.length > 0 ? 2 : 1;
  1276. valueString = '0'.repeat(Math.max(0, minLength - wholeDigits)) + valueString;
  1277. } else {
  1278. prefix = '';
  1279. suffix = options.verbose ? ' ' + pluralize(long, value) : short;
  1280. }
  1281. result.push(prefix + valueString + suffix);
  1282. };
  1283. const parsed = parseMilliseconds(milliseconds);
  1284. add(Math.trunc(parsed.days / 365), 'year', 'y');
  1285. add(parsed.days % 365, 'day', 'd');
  1286. add(parsed.hours, 'hour', 'h');
  1287. add(parsed.minutes, 'minute', 'm');
  1288. if (
  1289. options.separateMilliseconds ||
  1290. options.formatSubMilliseconds ||
  1291. (!options.colonNotation && milliseconds < 1000)
  1292. ) {
  1293. add(parsed.seconds, 'second', 's');
  1294. if (options.formatSubMilliseconds) {
  1295. add(parsed.milliseconds, 'millisecond', 'ms');
  1296. add(parsed.microseconds, 'microsecond', 'µs');
  1297. add(parsed.nanoseconds, 'nanosecond', 'ns');
  1298. } else {
  1299. const millisecondsAndBelow =
  1300. parsed.milliseconds +
  1301. (parsed.microseconds / 1000) +
  1302. (parsed.nanoseconds / 1e6);
  1303. const millisecondsDecimalDigits =
  1304. typeof options.millisecondsDecimalDigits === 'number' ?
  1305. options.millisecondsDecimalDigits :
  1306. 0;
  1307. const roundedMiliseconds = millisecondsAndBelow >= 1 ?
  1308. Math.round(millisecondsAndBelow) :
  1309. Math.ceil(millisecondsAndBelow);
  1310. const millisecondsString = millisecondsDecimalDigits ?
  1311. millisecondsAndBelow.toFixed(millisecondsDecimalDigits) :
  1312. roundedMiliseconds;
  1313. add(
  1314. Number.parseFloat(millisecondsString, 10),
  1315. 'millisecond',
  1316. 'ms',
  1317. millisecondsString
  1318. );
  1319. }
  1320. } else {
  1321. const seconds = (milliseconds / 1000) % 60;
  1322. const secondsDecimalDigits =
  1323. typeof options.secondsDecimalDigits === 'number' ?
  1324. options.secondsDecimalDigits :
  1325. 1;
  1326. const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
  1327. const secondsString = options.keepDecimalsOnWholeSeconds ?
  1328. secondsFixed :
  1329. secondsFixed.replace(/\.0+$/, '');
  1330. add(Number.parseFloat(secondsString, 10), 'second', 's', secondsString);
  1331. }
  1332. if (result.length === 0) {
  1333. return '0' + (options.verbose ? ' milliseconds' : 'ms');
  1334. }
  1335. if (options.compact) {
  1336. return result[0];
  1337. }
  1338. if (typeof options.unitCount === 'number') {
  1339. const separator = options.colonNotation ? '' : ' ';
  1340. return result.slice(0, Math.max(options.unitCount, 1)).join(separator);
  1341. }
  1342. return options.colonNotation ? result.join('') : result.join(' ');
  1343. };
  1344. const ms = prettyMs;
  1345. const BYTE_UNITS = [
  1346. 'B',
  1347. 'kB',
  1348. 'MB',
  1349. 'GB',
  1350. 'TB',
  1351. 'PB',
  1352. 'EB',
  1353. 'ZB',
  1354. 'YB'
  1355. ];
  1356. const BIBYTE_UNITS = [
  1357. 'B',
  1358. 'kiB',
  1359. 'MiB',
  1360. 'GiB',
  1361. 'TiB',
  1362. 'PiB',
  1363. 'EiB',
  1364. 'ZiB',
  1365. 'YiB'
  1366. ];
  1367. const BIT_UNITS = [
  1368. 'b',
  1369. 'kbit',
  1370. 'Mbit',
  1371. 'Gbit',
  1372. 'Tbit',
  1373. 'Pbit',
  1374. 'Ebit',
  1375. 'Zbit',
  1376. 'Ybit'
  1377. ];
  1378. const BIBIT_UNITS = [
  1379. 'b',
  1380. 'kibit',
  1381. 'Mibit',
  1382. 'Gibit',
  1383. 'Tibit',
  1384. 'Pibit',
  1385. 'Eibit',
  1386. 'Zibit',
  1387. 'Yibit'
  1388. ];
  1389. /*
  1390. Formats the given number using `Number#toLocaleString`.
  1391. - If locale is a string, the value is expected to be a locale-key (for example: `de`).
  1392. - If locale is true, the system default locale is used for translation.
  1393. - If no value for locale is specified, the number is returned unmodified.
  1394. */
  1395. const toLocaleString = (number, locale, options) => {
  1396. let result = number;
  1397. if (typeof locale === 'string' || Array.isArray(locale)) {
  1398. result = number.toLocaleString(locale, options);
  1399. } else if (locale === true || options !== undefined) {
  1400. result = number.toLocaleString(undefined, options);
  1401. }
  1402. return result;
  1403. };
  1404. var prettyBytes = (number, options) => {
  1405. if (!Number.isFinite(number)) {
  1406. throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
  1407. }
  1408. options = Object.assign({bits: false, binary: false}, options);
  1409. const UNITS = options.bits ?
  1410. (options.binary ? BIBIT_UNITS : BIT_UNITS) :
  1411. (options.binary ? BIBYTE_UNITS : BYTE_UNITS);
  1412. if (options.signed && number === 0) {
  1413. return ` 0 ${UNITS[0]}`;
  1414. }
  1415. const isNegative = number < 0;
  1416. const prefix = isNegative ? '-' : (options.signed ? '+' : '');
  1417. if (isNegative) {
  1418. number = -number;
  1419. }
  1420. let localeOptions;
  1421. if (options.minimumFractionDigits !== undefined) {
  1422. localeOptions = {minimumFractionDigits: options.minimumFractionDigits};
  1423. }
  1424. if (options.maximumFractionDigits !== undefined) {
  1425. localeOptions = Object.assign({maximumFractionDigits: options.maximumFractionDigits}, localeOptions);
  1426. }
  1427. if (number < 1) {
  1428. const numberString = toLocaleString(number, options.locale, localeOptions);
  1429. return prefix + numberString + ' ' + UNITS[0];
  1430. }
  1431. const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
  1432. // eslint-disable-next-line unicorn/prefer-exponentiation-operator
  1433. number /= Math.pow(options.binary ? 1024 : 1000, exponent);
  1434. if (!localeOptions) {
  1435. number = number.toPrecision(3);
  1436. }
  1437. const numberString = toLocaleString(Number(number), options.locale, localeOptions);
  1438. const unit = UNITS[exponent];
  1439. return prefix + numberString + ' ' + unit;
  1440. };
  1441. const prettyBytes$1 = prettyBytes;
  1442. function printTimings(timings) {
  1443. Object.entries(timings).forEach(([label, [time, memory, total]]) => {
  1444. const appliedColor = label[0] === '#' ? (label[1] !== '#' ? loadConfigFile_js.underline : loadConfigFile_js.bold) : (text) => text;
  1445. const row = `${label}: ${time.toFixed(0)}ms, ${prettyBytes$1(memory)} / ${prettyBytes$1(total)}`;
  1446. console.info(appliedColor(row));
  1447. });
  1448. }
  1449. async function build(inputOptions, warnings, silent = false) {
  1450. const outputOptions = inputOptions.output;
  1451. const useStdout = !outputOptions[0].file && !outputOptions[0].dir;
  1452. const start = Date.now();
  1453. const files = useStdout ? ['stdout'] : outputOptions.map(t => rollup.relativeId(t.file || t.dir));
  1454. if (!silent) {
  1455. let inputFiles;
  1456. if (typeof inputOptions.input === 'string') {
  1457. inputFiles = inputOptions.input;
  1458. }
  1459. else if (inputOptions.input instanceof Array) {
  1460. inputFiles = inputOptions.input.join(', ');
  1461. }
  1462. else if (typeof inputOptions.input === 'object' && inputOptions.input !== null) {
  1463. inputFiles = Object.values(inputOptions.input).join(', ');
  1464. }
  1465. loadConfigFile_js.stderr(loadConfigFile_js.cyan(`\n${loadConfigFile_js.bold(inputFiles)} → ${loadConfigFile_js.bold(files.join(', '))}...`));
  1466. }
  1467. const bundle = await rollup.rollup(inputOptions);
  1468. if (useStdout) {
  1469. const output = outputOptions[0];
  1470. if (output.sourcemap && output.sourcemap !== 'inline') {
  1471. loadConfigFile_js.handleError({
  1472. code: 'ONLY_INLINE_SOURCEMAPS',
  1473. message: 'Only inline sourcemaps are supported when bundling to stdout.'
  1474. });
  1475. }
  1476. const { output: outputs } = await bundle.generate(output);
  1477. for (const file of outputs) {
  1478. let source;
  1479. if (file.type === 'asset') {
  1480. source = file.source;
  1481. }
  1482. else {
  1483. source = file.code;
  1484. if (output.sourcemap === 'inline') {
  1485. source += `\n//# ${rollup.SOURCEMAPPING_URL}=${file.map.toUrl()}\n`;
  1486. }
  1487. }
  1488. if (outputs.length > 1)
  1489. process$1.stdout.write(`\n${loadConfigFile_js.cyan(loadConfigFile_js.bold(`//→ ${file.fileName}:`))}\n`);
  1490. process$1.stdout.write(source);
  1491. }
  1492. if (!silent) {
  1493. warnings.flush();
  1494. }
  1495. return;
  1496. }
  1497. await Promise.all(outputOptions.map(bundle.write));
  1498. await bundle.close();
  1499. if (!silent) {
  1500. warnings.flush();
  1501. loadConfigFile_js.stderr(loadConfigFile_js.green(`created ${loadConfigFile_js.bold(files.join(', '))} in ${loadConfigFile_js.bold(ms(Date.now() - start))}`));
  1502. if (bundle && bundle.getTimings) {
  1503. printTimings(bundle.getTimings());
  1504. }
  1505. }
  1506. }
  1507. const DEFAULT_CONFIG_BASE = 'rollup.config';
  1508. async function getConfigPath(commandConfig) {
  1509. if (commandConfig === true) {
  1510. return require$$0.resolve(await findConfigFileNameInCwd());
  1511. }
  1512. if (commandConfig.slice(0, 5) === 'node:') {
  1513. const pkgName = commandConfig.slice(5);
  1514. try {
  1515. return require.resolve(`rollup-config-${pkgName}`, { paths: [process$1.cwd()] });
  1516. }
  1517. catch (_a) {
  1518. try {
  1519. return require.resolve(pkgName, { paths: [process$1.cwd()] });
  1520. }
  1521. catch (err) {
  1522. if (err.code === 'MODULE_NOT_FOUND') {
  1523. loadConfigFile_js.handleError({
  1524. code: 'MISSING_EXTERNAL_CONFIG',
  1525. message: `Could not resolve config file "${commandConfig}"`
  1526. });
  1527. }
  1528. throw err;
  1529. }
  1530. }
  1531. }
  1532. return require$$0.resolve(commandConfig);
  1533. }
  1534. async function findConfigFileNameInCwd() {
  1535. const filesInWorkingDir = new Set(await require$$0$1.promises.readdir(process$1.cwd()));
  1536. for (const extension of ['mjs', 'cjs', 'ts']) {
  1537. const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
  1538. if (filesInWorkingDir.has(fileName))
  1539. return fileName;
  1540. }
  1541. return `${DEFAULT_CONFIG_BASE}.js`;
  1542. }
  1543. async function loadConfigFromCommand(command) {
  1544. const warnings = loadConfigFile_js.batchWarnings();
  1545. if (!command.input && (command.stdin || !process$1.stdin.isTTY)) {
  1546. command.input = loadConfigFile_js.stdinName;
  1547. }
  1548. const options = mergeOptions.mergeOptions({ input: [] }, command, warnings.add);
  1549. await loadConfigFile_js.addCommandPluginsToInputOptions(options, command);
  1550. return { options: [options], warnings };
  1551. }
  1552. async function runRollup(command) {
  1553. let inputSource;
  1554. if (command._.length > 0) {
  1555. if (command.input) {
  1556. loadConfigFile_js.handleError({
  1557. code: 'DUPLICATE_IMPORT_OPTIONS',
  1558. message: 'Either use --input, or pass input path as argument'
  1559. });
  1560. }
  1561. inputSource = command._;
  1562. }
  1563. else if (typeof command.input === 'string') {
  1564. inputSource = [command.input];
  1565. }
  1566. else {
  1567. inputSource = command.input;
  1568. }
  1569. if (inputSource && inputSource.length > 0) {
  1570. if (inputSource.some((input) => input.includes('='))) {
  1571. command.input = {};
  1572. inputSource.forEach((input) => {
  1573. const equalsIndex = input.indexOf('=');
  1574. const value = input.substring(equalsIndex + 1);
  1575. const key = input.substring(0, equalsIndex) || rollup.getAliasName(input);
  1576. command.input[key] = value;
  1577. });
  1578. }
  1579. else {
  1580. command.input = inputSource;
  1581. }
  1582. }
  1583. if (command.environment) {
  1584. const environment = Array.isArray(command.environment)
  1585. ? command.environment
  1586. : [command.environment];
  1587. environment.forEach((arg) => {
  1588. arg.split(',').forEach((pair) => {
  1589. const [key, ...value] = pair.split(':');
  1590. process$1.env[key] = value.length === 0 ? String(true) : value.join(':');
  1591. });
  1592. });
  1593. }
  1594. if (mergeOptions.isWatchEnabled(command.watch)) {
  1595. await rollup.loadFsEvents();
  1596. const { watch } = await Promise.resolve().then(() => require('../shared/watch-cli.js'));
  1597. watch(command);
  1598. }
  1599. else {
  1600. try {
  1601. const { options, warnings } = await getConfigs(command);
  1602. try {
  1603. for (const inputOptions of options) {
  1604. await build(inputOptions, warnings, command.silent);
  1605. }
  1606. if (command.failAfterWarnings && warnings.warningOccurred) {
  1607. warnings.flush();
  1608. loadConfigFile_js.handleError({
  1609. code: 'FAIL_AFTER_WARNINGS',
  1610. message: 'Warnings occurred and --failAfterWarnings flag present'
  1611. });
  1612. }
  1613. }
  1614. catch (err) {
  1615. warnings.flush();
  1616. loadConfigFile_js.handleError(err);
  1617. }
  1618. }
  1619. catch (err) {
  1620. loadConfigFile_js.handleError(err);
  1621. }
  1622. }
  1623. }
  1624. async function getConfigs(command) {
  1625. if (command.config) {
  1626. const configFile = await getConfigPath(command.config);
  1627. const { options, warnings } = await loadConfigFile_js.loadAndParseConfigFile(configFile, command);
  1628. return { options, warnings };
  1629. }
  1630. return await loadConfigFromCommand(command);
  1631. }
  1632. const command = argParser(process$1.argv.slice(2), {
  1633. alias: mergeOptions.commandAliases,
  1634. configuration: { 'camel-case-expansion': false }
  1635. });
  1636. if (command.help || (process$1.argv.length <= 2 && process$1.stdin.isTTY)) {
  1637. console.log(`\n${help.replace('__VERSION__', rollup.version)}\n`);
  1638. }
  1639. else if (command.version) {
  1640. console.log(`rollup v${rollup.version}`);
  1641. }
  1642. else {
  1643. try {
  1644. require('source-map-support').install();
  1645. }
  1646. catch (_a) {
  1647. // do nothing
  1648. }
  1649. runRollup(command);
  1650. }
  1651. exports.getConfigPath = getConfigPath;
  1652. exports.loadConfigFromCommand = loadConfigFromCommand;
  1653. exports.ms = ms;
  1654. exports.printTimings = printTimings;
  1655. //# sourceMappingURL=rollup.map