rollup 70 KB

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