Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1#!/usr/bin/env node2/*3 @license4 Rollup.js v4.61.15 Thu, 04 Jun 2026 05:21:21 GMT - commit b77daf0a97cf96e61870cc02de584e923bc70fad6 7 https://github.com/rollup/rollup8 9 Released under the MIT License.10*/11'use strict';12 13Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });14 15const process$1 = require('node:process');16const rollup = require('../shared/rollup.js');17const require$$2 = require('util');18const require$$0 = require('path');19const require$$0$1 = require('fs');20const parseAst_js = require('../shared/parseAst.js');21const fseventsImporter = require('../shared/fsevents-importer.js');22const promises = require('node:fs/promises');23const path = require('node:path');24const loadConfigFile_js = require('../shared/loadConfigFile.js');25require('../native.js');26require('node:perf_hooks');27require('node:url');28require('../getLogFilter.js');29 30const help = "rollup version 4.61.1\n=====================================\n\nUsage: rollup [options] <entry file>\n\nOptions:\n\n-c, --config <filename> Use this config file (if argument is used but value\n is unspecified, Rollup will try to load configuration files in\n the following order:\n rollup.config.mjs -> rollup.config.cjs -> 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.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--amd.forceJsExtensionForImports Use `.js` extension in AMD imports\n--amd.id <id> ID for AMD module (default is anonymous)\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--no-dynamicImportInCjs Write external dynamic CommonJS imports as require\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-externalImportAttributes Omit import attributes in \"es\" output\n--no-externalLiveBindings Do not generate code to support live bindings\n--failAfterWarnings Exit with an error if the build produced warnings\n--filterLogs <filter> Filter log messages\n--footer <text> Code to insert at end of bundle (outside wrapper)\n--forceExit Force exit the process when done\n--no-freeze Do not freeze namespace objects\n--generatedCode <preset> Which code features to use (es5/es2015)\n--generatedCode.arrowFunctions Use arrow functions in generated code\n--generatedCode.constBindings Use \"const\" in generated code\n--generatedCode.objectShorthand Use shorthand properties in generated code\n--no-generatedCode.reservedNamesAsProps Always quote reserved names as props\n--generatedCode.symbols Use symbols in generated code\n--hashCharacters <name> Use the specified character set for file hashes\n--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks\n--importAttributesKey <name> Use the specified keyword for import attributes\n--no-indent Don't indent result\n--inlineDynamicImports Create single bundle when using dynamic imports\n--no-interop Do not include interop block\n--intro <text> Code to insert at top of bundle (inside wrapper)\n--logLevel <level> Which kind of logs to display\n--no-makeAbsoluteExternalsRelative Prevent normalization of external imports\n--maxParallelFileOps <value> How many files to read in parallel\n--minifyInternalExports Force or disable minification of internal exports\n--noConflict Generate a noConflict method for UMD globals\n--outro <text> Code to insert at end of bundle (inside wrapper)\n--perf Display performance timings\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-reexportProtoFromExternal Ignore `__proto__` in star re-exports\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--sourcemapDebugIds Emit unique debug ids in source and sourcemaps\n--sourcemapExcludeSources Do not include source code in source maps\n--sourcemapFile <file> Specify bundle position for source maps\n--sourcemapFileNames <pattern> Name pattern for emitted sourcemaps\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--no-systemNullSetters Do not replace empty SystemJS setters with `null`\n--no-treeshake Disable tree-shaking optimisations\n--no-treeshake.annotations Ignore pure call annotations\n--treeshake.correctVarValueBeforeDeclaration Deoptimize variables until declared\n--treeshake.manualPureFunctions <names> Manually declare functions as pure\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--validate Validate output\n--waitForBundleInput Wait for bundle input files\n--watch.allowInputInsideOutputPath Whether the input path is allowed to be a\n subpath of the output path\n--watch.buildDelay <number> Throttle watch rebuilds\n--no-watch.clearScreen Do not clear the screen when rebuilding\n--watch.exclude <files> Exclude files from being watched\n--watch.include <files> Limit watching to specified files\n--watch.onBundleEnd <cmd> Shell command to run on `\"BUNDLE_END\"` event\n--watch.onBundleStart <cmd> Shell command to run on `\"BUNDLE_START\"` event\n--watch.onEnd <cmd> Shell command to run on `\"END\"` event\n--watch.onError <cmd> Shell command to run on `\"ERROR\"` event\n--watch.onStart <cmd> Shell command to run on `\"START\"` event\n--watch.skipWrite Do not write files to disk when watching\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";31 32/**33 * @license34 * Copyright (c) 2016, Contributors35 * SPDX-License-Identifier: ISC36 */37function camelCase(str) {38 // Handle the case where an argument is provided as camel case, e.g., fooBar.39 // by ensuring that the string isn't already mixed case:40 const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();41 if (!isCamelCase) {42 str = str.toLowerCase();43 }44 if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {45 return str;46 }47 else {48 let camelcase = '';49 let nextChrUpper = false;50 const leadingHyphens = str.match(/^-+/);51 for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {52 let chr = str.charAt(i);53 if (nextChrUpper) {54 nextChrUpper = false;55 chr = chr.toUpperCase();56 }57 if (i !== 0 && (chr === '-' || chr === '_')) {58 nextChrUpper = true;59 }60 else if (chr !== '-' && chr !== '_') {61 camelcase += chr;62 }63 }64 return camelcase;65 }66}67function decamelize(str, joinString) {68 const lowercase = str.toLowerCase();69 joinString = joinString || '-';70 let notCamelcase = '';71 for (let i = 0; i < str.length; i++) {72 const chrLower = lowercase.charAt(i);73 const chrString = str.charAt(i);74 if (chrLower !== chrString && i > 0) {75 notCamelcase += `${joinString}${lowercase.charAt(i)}`;76 }77 else {78 notCamelcase += chrString;79 }80 }81 return notCamelcase;82}83function looksLikeNumber(x) {84 if (x === null || x === undefined)85 return false;86 // if loaded from config, may already be a number.87 if (typeof x === 'number')88 return true;89 // hexadecimal.90 if (/^0x[0-9a-f]+$/i.test(x))91 return true;92 // don't treat 0123 as a number; as it drops the leading '0'.93 if (/^0[^.]/.test(x))94 return false;95 return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);96}97 98/**99 * @license100 * Copyright (c) 2016, Contributors101 * SPDX-License-Identifier: ISC102 */103// take an un-split argv string and tokenize it.104function tokenizeArgString(argString) {105 if (Array.isArray(argString)) {106 return argString.map(e => typeof e !== 'string' ? e + '' : e);107 }108 argString = argString.trim();109 let i = 0;110 let prevC = null;111 let c = null;112 let opening = null;113 const args = [];114 for (let ii = 0; ii < argString.length; ii++) {115 prevC = c;116 c = argString.charAt(ii);117 // split on spaces unless we're in quotes.118 if (c === ' ' && !opening) {119 if (!(prevC === ' ')) {120 i++;121 }122 continue;123 }124 // don't split the string if we're in matching125 // opening or closing single and double quotes.126 if (c === opening) {127 opening = null;128 }129 else if ((c === "'" || c === '"') && !opening) {130 opening = c;131 }132 if (!args[i])133 args[i] = '';134 args[i] += c;135 }136 return args;137}138 139/**140 * @license141 * Copyright (c) 2016, Contributors142 * SPDX-License-Identifier: ISC143 */144var DefaultValuesForTypeKey;145(function (DefaultValuesForTypeKey) {146 DefaultValuesForTypeKey["BOOLEAN"] = "boolean";147 DefaultValuesForTypeKey["STRING"] = "string";148 DefaultValuesForTypeKey["NUMBER"] = "number";149 DefaultValuesForTypeKey["ARRAY"] = "array";150})(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));151 152/**153 * @license154 * Copyright (c) 2016, Contributors155 * SPDX-License-Identifier: ISC156 */157let mixin;158class YargsParser {159 constructor(_mixin) {160 mixin = _mixin;161 }162 parse(argsInput, options) {163 const opts = Object.assign({164 alias: undefined,165 array: undefined,166 boolean: undefined,167 config: undefined,168 configObjects: undefined,169 configuration: undefined,170 coerce: undefined,171 count: undefined,172 default: undefined,173 envPrefix: undefined,174 narg: undefined,175 normalize: undefined,176 string: undefined,177 number: undefined,178 __: undefined,179 key: undefined180 }, options);181 // allow a string argument to be passed in rather182 // than an argv array.183 const args = tokenizeArgString(argsInput);184 // tokenizeArgString adds extra quotes to args if argsInput is a string185 // only strip those extra quotes in processValue if argsInput is a string186 const inputIsString = typeof argsInput === 'string';187 // aliases might have transitive relationships, normalize this.188 const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));189 const configuration = Object.assign({190 'boolean-negation': true,191 'camel-case-expansion': true,192 'combine-arrays': false,193 'dot-notation': true,194 'duplicate-arguments-array': true,195 'flatten-duplicate-arrays': true,196 'greedy-arrays': true,197 'halt-at-non-option': false,198 'nargs-eats-options': false,199 'negation-prefix': 'no-',200 'parse-numbers': true,201 'parse-positional-numbers': true,202 'populate--': false,203 'set-placeholder-key': false,204 'short-option-groups': true,205 'strip-aliased': false,206 'strip-dashed': false,207 'unknown-options-as-args': false208 }, opts.configuration);209 const defaults = Object.assign(Object.create(null), opts.default);210 const configObjects = opts.configObjects || [];211 const envPrefix = opts.envPrefix;212 const notFlagsOption = configuration['populate--'];213 const notFlagsArgv = notFlagsOption ? '--' : '_';214 const newAliases = Object.create(null);215 const defaulted = Object.create(null);216 // allow a i18n handler to be passed in, default to a fake one (util.format).217 const __ = opts.__ || mixin.format;218 const flags = {219 aliases: Object.create(null),220 arrays: Object.create(null),221 bools: Object.create(null),222 strings: Object.create(null),223 numbers: Object.create(null),224 counts: Object.create(null),225 normalize: Object.create(null),226 configs: Object.create(null),227 nargs: Object.create(null),228 coercions: Object.create(null),229 keys: []230 };231 const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;232 const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');233 [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {234 const key = typeof opt === 'object' ? opt.key : opt;235 // assign to flags[bools|strings|numbers]236 const assignment = Object.keys(opt).map(function (key) {237 const arrayFlagKeys = {238 boolean: 'bools',239 string: 'strings',240 number: 'numbers'241 };242 return arrayFlagKeys[key];243 }).filter(Boolean).pop();244 // assign key to be coerced245 if (assignment) {246 flags[assignment][key] = true;247 }248 flags.arrays[key] = true;249 flags.keys.push(key);250 });251 [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {252 flags.bools[key] = true;253 flags.keys.push(key);254 });255 [].concat(opts.string || []).filter(Boolean).forEach(function (key) {256 flags.strings[key] = true;257 flags.keys.push(key);258 });259 [].concat(opts.number || []).filter(Boolean).forEach(function (key) {260 flags.numbers[key] = true;261 flags.keys.push(key);262 });263 [].concat(opts.count || []).filter(Boolean).forEach(function (key) {264 flags.counts[key] = true;265 flags.keys.push(key);266 });267 [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {268 flags.normalize[key] = true;269 flags.keys.push(key);270 });271 if (typeof opts.narg === 'object') {272 Object.entries(opts.narg).forEach(([key, value]) => {273 if (typeof value === 'number') {274 flags.nargs[key] = value;275 flags.keys.push(key);276 }277 });278 }279 if (typeof opts.coerce === 'object') {280 Object.entries(opts.coerce).forEach(([key, value]) => {281 if (typeof value === 'function') {282 flags.coercions[key] = value;283 flags.keys.push(key);284 }285 });286 }287 if (typeof opts.config !== 'undefined') {288 if (Array.isArray(opts.config) || typeof opts.config === 'string') {289 [].concat(opts.config).filter(Boolean).forEach(function (key) {290 flags.configs[key] = true;291 });292 }293 else if (typeof opts.config === 'object') {294 Object.entries(opts.config).forEach(([key, value]) => {295 if (typeof value === 'boolean' || typeof value === 'function') {296 flags.configs[key] = value;297 }298 });299 }300 }301 // create a lookup table that takes into account all302 // combinations of aliases: {f: ['foo'], foo: ['f']}303 extendAliases(opts.key, aliases, opts.default, flags.arrays);304 // apply default values to all aliases.305 Object.keys(defaults).forEach(function (key) {306 (flags.aliases[key] || []).forEach(function (alias) {307 defaults[alias] = defaults[key];308 });309 });310 let error = null;311 checkConfiguration();312 let notFlags = [];313 const argv = Object.assign(Object.create(null), { _: [] });314 // TODO(bcoe): for the first pass at removing object prototype we didn't315 // remove all prototypes from objects returned by this API, we might want316 // to gradually move towards doing so.317 const argvReturn = {};318 for (let i = 0; i < args.length; i++) {319 const arg = args[i];320 const truncatedArg = arg.replace(/^-{3,}/, '---');321 let broken;322 let key;323 let letters;324 let m;325 let next;326 let value;327 // any unknown option (except for end-of-options, "--")328 if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {329 pushPositional(arg);330 // ---, ---=, ----, etc,331 }332 else if (truncatedArg.match(/^---+(=|$)/)) {333 // options without key name are invalid.334 pushPositional(arg);335 continue;336 // -- separated by =337 }338 else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {339 // Using [\s\S] instead of . because js doesn't support the340 // 'dotall' regex modifier. See:341 // http://stackoverflow.com/a/1068308/13216342 m = arg.match(/^--?([^=]+)=([\s\S]*)$/);343 // arrays format = '--f=a b c'344 if (m !== null && Array.isArray(m) && m.length >= 3) {345 if (checkAllAliases(m[1], flags.arrays)) {346 i = eatArray(i, m[1], args, m[2]);347 }348 else if (checkAllAliases(m[1], flags.nargs) !== false) {349 // nargs format = '--f=monkey washing cat'350 i = eatNargs(i, m[1], args, m[2]);351 }352 else {353 setArg(m[1], m[2], true);354 }355 }356 }357 else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {358 m = arg.match(negatedBoolean);359 if (m !== null && Array.isArray(m) && m.length >= 2) {360 key = m[1];361 setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);362 }363 // -- separated by space.364 }365 else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {366 m = arg.match(/^--?(.+)/);367 if (m !== null && Array.isArray(m) && m.length >= 2) {368 key = m[1];369 if (checkAllAliases(key, flags.arrays)) {370 // array format = '--foo a b c'371 i = eatArray(i, key, args);372 }373 else if (checkAllAliases(key, flags.nargs) !== false) {374 // nargs format = '--foo a b c'375 // should be truthy even if: flags.nargs[key] === 0376 i = eatNargs(i, key, args);377 }378 else {379 next = args[i + 1];380 if (next !== undefined && (!next.match(/^-/) ||381 next.match(negative)) &&382 !checkAllAliases(key, flags.bools) &&383 !checkAllAliases(key, flags.counts)) {384 setArg(key, next);385 i++;386 }387 else if (/^(true|false)$/.test(next)) {388 setArg(key, next);389 i++;390 }391 else {392 setArg(key, defaultValue(key));393 }394 }395 }396 // dot-notation flag separated by '='.397 }398 else if (arg.match(/^-.\..+=/)) {399 m = arg.match(/^-([^=]+)=([\s\S]*)$/);400 if (m !== null && Array.isArray(m) && m.length >= 3) {401 setArg(m[1], m[2]);402 }403 // dot-notation flag separated by space.404 }405 else if (arg.match(/^-.\..+/) && !arg.match(negative)) {406 next = args[i + 1];407 m = arg.match(/^-(.\..+)/);408 if (m !== null && Array.isArray(m) && m.length >= 2) {409 key = m[1];410 if (next !== undefined && !next.match(/^-/) &&411 !checkAllAliases(key, flags.bools) &&412 !checkAllAliases(key, flags.counts)) {413 setArg(key, next);414 i++;415 }416 else {417 setArg(key, defaultValue(key));418 }419 }420 }421 else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {422 letters = arg.slice(1, -1).split('');423 broken = false;424 for (let j = 0; j < letters.length; j++) {425 next = arg.slice(j + 2);426 if (letters[j + 1] && letters[j + 1] === '=') {427 value = arg.slice(j + 3);428 key = letters[j];429 if (checkAllAliases(key, flags.arrays)) {430 // array format = '-f=a b c'431 i = eatArray(i, key, args, value);432 }433 else if (checkAllAliases(key, flags.nargs) !== false) {434 // nargs format = '-f=monkey washing cat'435 i = eatNargs(i, key, args, value);436 }437 else {438 setArg(key, value);439 }440 broken = true;441 break;442 }443 if (next === '-') {444 setArg(letters[j], next);445 continue;446 }447 // current letter is an alphabetic character and next value is a number448 if (/[A-Za-z]/.test(letters[j]) &&449 /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&450 checkAllAliases(next, flags.bools) === false) {451 setArg(letters[j], next);452 broken = true;453 break;454 }455 if (letters[j + 1] && letters[j + 1].match(/\W/)) {456 setArg(letters[j], next);457 broken = true;458 break;459 }460 else {461 setArg(letters[j], defaultValue(letters[j]));462 }463 }464 key = arg.slice(-1)[0];465 if (!broken && key !== '-') {466 if (checkAllAliases(key, flags.arrays)) {467 // array format = '-f a b c'468 i = eatArray(i, key, args);469 }470 else if (checkAllAliases(key, flags.nargs) !== false) {471 // nargs format = '-f a b c'472 // should be truthy even if: flags.nargs[key] === 0473 i = eatNargs(i, key, args);474 }475 else {476 next = args[i + 1];477 if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||478 next.match(negative)) &&479 !checkAllAliases(key, flags.bools) &&480 !checkAllAliases(key, flags.counts)) {481 setArg(key, next);482 i++;483 }484 else if (/^(true|false)$/.test(next)) {485 setArg(key, next);486 i++;487 }488 else {489 setArg(key, defaultValue(key));490 }491 }492 }493 }494 else if (arg.match(/^-[0-9]$/) &&495 arg.match(negative) &&496 checkAllAliases(arg.slice(1), flags.bools)) {497 // single-digit boolean alias, e.g: xargs -0498 key = arg.slice(1);499 setArg(key, defaultValue(key));500 }501 else if (arg === '--') {502 notFlags = args.slice(i + 1);503 break;504 }505 else if (configuration['halt-at-non-option']) {506 notFlags = args.slice(i);507 break;508 }509 else {510 pushPositional(arg);511 }512 }513 // order of precedence:514 // 1. command line arg515 // 2. value from env var516 // 3. value from config file517 // 4. value from config objects518 // 5. configured default value519 applyEnvVars(argv, true); // special case: check env vars that point to config file520 applyEnvVars(argv, false);521 setConfig(argv);522 setConfigObjects();523 applyDefaultsAndAliases(argv, flags.aliases, defaults, true);524 applyCoercions(argv);525 if (configuration['set-placeholder-key'])526 setPlaceholderKeys(argv);527 // for any counts either not in args or without an explicit default, set to 0528 Object.keys(flags.counts).forEach(function (key) {529 if (!hasKey(argv, key.split('.')))530 setArg(key, 0);531 });532 // '--' defaults to undefined.533 if (notFlagsOption && notFlags.length)534 argv[notFlagsArgv] = [];535 notFlags.forEach(function (key) {536 argv[notFlagsArgv].push(key);537 });538 if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {539 Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {540 delete argv[key];541 });542 }543 if (configuration['strip-aliased']) {544 [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {545 if (configuration['camel-case-expansion'] && alias.includes('-')) {546 delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];547 }548 delete argv[alias];549 });550 }551 // Push argument into positional array, applying numeric coercion:552 function pushPositional(arg) {553 const maybeCoercedNumber = maybeCoerceNumber('_', arg);554 if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {555 argv._.push(maybeCoercedNumber);556 }557 }558 // how many arguments should we consume, based559 // on the nargs option?560 function eatNargs(i, key, args, argAfterEqualSign) {561 let ii;562 let toEat = checkAllAliases(key, flags.nargs);563 // NaN has a special meaning for the array type, indicating that one or564 // more values are expected.565 toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;566 if (toEat === 0) {567 if (!isUndefined(argAfterEqualSign)) {568 error = Error(__('Argument unexpected for: %s', key));569 }570 setArg(key, defaultValue(key));571 return i;572 }573 let available = isUndefined(argAfterEqualSign) ? 0 : 1;574 if (configuration['nargs-eats-options']) {575 // classic behavior, yargs eats positional and dash arguments.576 if (args.length - (i + 1) + available < toEat) {577 error = Error(__('Not enough arguments following: %s', key));578 }579 available = toEat;580 }581 else {582 // nargs will not consume flag arguments, e.g., -abc, --foo,583 // and terminates when one is observed.584 for (ii = i + 1; ii < args.length; ii++) {585 if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))586 available++;587 else588 break;589 }590 if (available < toEat)591 error = Error(__('Not enough arguments following: %s', key));592 }593 let consumed = Math.min(available, toEat);594 if (!isUndefined(argAfterEqualSign) && consumed > 0) {595 setArg(key, argAfterEqualSign);596 consumed--;597 }598 for (ii = i + 1; ii < (consumed + i + 1); ii++) {599 setArg(key, args[ii]);600 }601 return (i + consumed);602 }603 // if an option is an array, eat all non-hyphenated arguments604 // following it... YUM!605 // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]606 function eatArray(i, key, args, argAfterEqualSign) {607 let argsToSet = [];608 let next = argAfterEqualSign || args[i + 1];609 // If both array and nargs are configured, enforce the nargs count:610 const nargsCount = checkAllAliases(key, flags.nargs);611 if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {612 argsToSet.push(true);613 }614 else if (isUndefined(next) ||615 (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {616 // for keys without value ==> argsToSet remains an empty []617 // set user default value, if available618 if (defaults[key] !== undefined) {619 const defVal = defaults[key];620 argsToSet = Array.isArray(defVal) ? defVal : [defVal];621 }622 }623 else {624 // value in --option=value is eaten as is625 if (!isUndefined(argAfterEqualSign)) {626 argsToSet.push(processValue(key, argAfterEqualSign, true));627 }628 for (let ii = i + 1; ii < args.length; ii++) {629 if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||630 (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))631 break;632 next = args[ii];633 if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))634 break;635 i = ii;636 argsToSet.push(processValue(key, next, inputIsString));637 }638 }639 // If both array and nargs are configured, create an error if less than640 // nargs positionals were found. NaN has special meaning, indicating641 // that at least one value is required (more are okay).642 if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||643 (isNaN(nargsCount) && argsToSet.length === 0))) {644 error = Error(__('Not enough arguments following: %s', key));645 }646 setArg(key, argsToSet);647 return i;648 }649 function setArg(key, val, shouldStripQuotes = inputIsString) {650 if (/-/.test(key) && configuration['camel-case-expansion']) {651 const alias = key.split('.').map(function (prop) {652 return camelCase(prop);653 }).join('.');654 addNewAlias(key, alias);655 }656 const value = processValue(key, val, shouldStripQuotes);657 const splitKey = key.split('.');658 setKey(argv, splitKey, value);659 // handle populating aliases of the full key660 if (flags.aliases[key]) {661 flags.aliases[key].forEach(function (x) {662 const keyProperties = x.split('.');663 setKey(argv, keyProperties, value);664 });665 }666 // handle populating aliases of the first element of the dot-notation key667 if (splitKey.length > 1 && configuration['dot-notation']) {668 (flags.aliases[splitKey[0]] || []).forEach(function (x) {669 let keyProperties = x.split('.');670 // expand alias with nested objects in key671 const a = [].concat(splitKey);672 a.shift(); // nuke the old key.673 keyProperties = keyProperties.concat(a);674 // populate alias only if is not already an alias of the full key675 // (already populated above)676 if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {677 setKey(argv, keyProperties, value);678 }679 });680 }681 // Set normalize getter and setter when key is in 'normalize' but isn't an array682 if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {683 const keys = [key].concat(flags.aliases[key] || []);684 keys.forEach(function (key) {685 Object.defineProperty(argvReturn, key, {686 enumerable: true,687 get() {688 return val;689 },690 set(value) {691 val = typeof value === 'string' ? mixin.normalize(value) : value;692 }693 });694 });695 }696 }697 function addNewAlias(key, alias) {698 if (!(flags.aliases[key] && flags.aliases[key].length)) {699 flags.aliases[key] = [alias];700 newAliases[alias] = true;701 }702 if (!(flags.aliases[alias] && flags.aliases[alias].length)) {703 addNewAlias(alias, key);704 }705 }706 function processValue(key, val, shouldStripQuotes) {707 // strings may be quoted, clean this up as we assign values.708 if (shouldStripQuotes) {709 val = stripQuotes(val);710 }711 // handle parsing boolean arguments --foo=true --bar false.712 if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {713 if (typeof val === 'string')714 val = val === 'true';715 }716 let value = Array.isArray(val)717 ? val.map(function (v) { return maybeCoerceNumber(key, v); })718 : maybeCoerceNumber(key, val);719 // increment a count given as arg (either no value or value parsed as boolean)720 if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {721 value = increment();722 }723 // Set normalized value when key is in 'normalize' and in 'arrays'724 if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {725 if (Array.isArray(val))726 value = val.map((val) => { return mixin.normalize(val); });727 else728 value = mixin.normalize(val);729 }730 return value;731 }732 function maybeCoerceNumber(key, value) {733 if (!configuration['parse-positional-numbers'] && key === '_')734 return value;735 if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {736 const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));737 if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {738 value = Number(value);739 }740 }741 return value;742 }743 // set args from config.json file, this should be744 // applied last so that defaults can be applied.745 function setConfig(argv) {746 const configLookup = Object.create(null);747 // expand defaults/aliases, in-case any happen to reference748 // the config.json file.749 applyDefaultsAndAliases(configLookup, flags.aliases, defaults);750 Object.keys(flags.configs).forEach(function (configKey) {751 const configPath = argv[configKey] || configLookup[configKey];752 if (configPath) {753 try {754 let config = null;755 const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath);756 const resolveConfig = flags.configs[configKey];757 if (typeof resolveConfig === 'function') {758 try {759 config = resolveConfig(resolvedConfigPath);760 }761 catch (e) {762 config = e;763 }764 if (config instanceof Error) {765 error = config;766 return;767 }768 }769 else {770 config = mixin.require(resolvedConfigPath);771 }772 setConfigObject(config);773 }774 catch (ex) {775 // Deno will receive a PermissionDenied error if an attempt is776 // made to load config without the --allow-read flag:777 if (ex.name === 'PermissionDenied')778 error = ex;779 else if (argv[configKey])780 error = Error(__('Invalid JSON config file: %s', configPath));781 }782 }783 });784 }785 // set args from config object.786 // it recursively checks nested objects.787 function setConfigObject(config, prev) {788 Object.keys(config).forEach(function (key) {789 const value = config[key];790 const fullKey = prev ? prev + '.' + key : key;791 // if the value is an inner object and we have dot-notation792 // enabled, treat inner objects in config the same as793 // heavily nested dot notations (foo.bar.apple).794 if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {795 // if the value is an object but not an array, check nested object796 setConfigObject(value, fullKey);797 }798 else {799 // setting arguments via CLI takes precedence over800 // values within the config file.801 if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {802 setArg(fullKey, value);803 }804 }805 });806 }807 // set all config objects passed in opts808 function setConfigObjects() {809 if (typeof configObjects !== 'undefined') {810 configObjects.forEach(function (configObject) {811 setConfigObject(configObject);812 });813 }814 }815 function applyEnvVars(argv, configOnly) {816 if (typeof envPrefix === 'undefined')817 return;818 const prefix = typeof envPrefix === 'string' ? envPrefix : '';819 const env = mixin.env();820 Object.keys(env).forEach(function (envVar) {821 if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {822 // get array of nested keys and convert them to camel case823 const keys = envVar.split('__').map(function (key, i) {824 if (i === 0) {825 key = key.substring(prefix.length);826 }827 return camelCase(key);828 });829 if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {830 setArg(keys.join('.'), env[envVar]);831 }832 }833 });834 }835 function applyCoercions(argv) {836 let coerce;837 const applied = new Set();838 Object.keys(argv).forEach(function (key) {839 if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases840 coerce = checkAllAliases(key, flags.coercions);841 if (typeof coerce === 'function') {842 try {843 const value = maybeCoerceNumber(key, coerce(argv[key]));844 ([].concat(flags.aliases[key] || [], key)).forEach(ali => {845 applied.add(ali);846 argv[ali] = value;847 });848 }849 catch (err) {850 error = err;851 }852 }853 }854 });855 }856 function setPlaceholderKeys(argv) {857 flags.keys.forEach((key) => {858 // don't set placeholder keys for dot notation options 'foo.bar'.859 if (~key.indexOf('.'))860 return;861 if (typeof argv[key] === 'undefined')862 argv[key] = undefined;863 });864 return argv;865 }866 function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {867 Object.keys(defaults).forEach(function (key) {868 if (!hasKey(obj, key.split('.'))) {869 setKey(obj, key.split('.'), defaults[key]);870 if (canLog)871 defaulted[key] = true;872 (aliases[key] || []).forEach(function (x) {873 if (hasKey(obj, x.split('.')))874 return;875 setKey(obj, x.split('.'), defaults[key]);876 });877 }878 });879 }880 function hasKey(obj, keys) {881 let o = obj;882 if (!configuration['dot-notation'])883 keys = [keys.join('.')];884 keys.slice(0, -1).forEach(function (key) {885 o = (o[key] || {});886 });887 const key = keys[keys.length - 1];888 if (typeof o !== 'object')889 return false;890 else891 return key in o;892 }893 function setKey(obj, keys, value) {894 let o = obj;895 if (!configuration['dot-notation'])896 keys = [keys.join('.')];897 keys.slice(0, -1).forEach(function (key) {898 // TODO(bcoe): in the next major version of yargs, switch to899 // Object.create(null) for dot notation:900 key = sanitizeKey(key);901 if (typeof o === 'object' && o[key] === undefined) {902 o[key] = {};903 }904 if (typeof o[key] !== 'object' || Array.isArray(o[key])) {905 // ensure that o[key] is an array, and that the last item is an empty object.906 if (Array.isArray(o[key])) {907 o[key].push({});908 }909 else {910 o[key] = [o[key], {}];911 }912 // we want to update the empty object at the end of the o[key] array, so set o to that object913 o = o[key][o[key].length - 1];914 }915 else {916 o = o[key];917 }918 });919 // TODO(bcoe): in the next major version of yargs, switch to920 // Object.create(null) for dot notation:921 const key = sanitizeKey(keys[keys.length - 1]);922 const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);923 const isValueArray = Array.isArray(value);924 let duplicate = configuration['duplicate-arguments-array'];925 // nargs has higher priority than duplicate926 if (!duplicate && checkAllAliases(key, flags.nargs)) {927 duplicate = true;928 if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {929 o[key] = undefined;930 }931 }932 if (value === increment()) {933 o[key] = increment(o[key]);934 }935 else if (Array.isArray(o[key])) {936 if (duplicate && isTypeArray && isValueArray) {937 o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);938 }939 else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {940 o[key] = value;941 }942 else {943 o[key] = o[key].concat([value]);944 }945 }946 else if (o[key] === undefined && isTypeArray) {947 o[key] = isValueArray ? value : [value];948 }949 else if (duplicate && !(o[key] === undefined ||950 checkAllAliases(key, flags.counts) ||951 checkAllAliases(key, flags.bools))) {952 o[key] = [o[key], value];953 }954 else {955 o[key] = value;956 }957 }958 // extend the aliases list with inferred aliases.959 function extendAliases(...args) {960 args.forEach(function (obj) {961 Object.keys(obj || {}).forEach(function (key) {962 // short-circuit if we've already added a key963 // to the aliases array, for example it might964 // exist in both 'opts.default' and 'opts.key'.965 if (flags.aliases[key])966 return;967 flags.aliases[key] = [].concat(aliases[key] || []);968 // For "--option-name", also set argv.optionName969 flags.aliases[key].concat(key).forEach(function (x) {970 if (/-/.test(x) && configuration['camel-case-expansion']) {971 const c = camelCase(x);972 if (c !== key && flags.aliases[key].indexOf(c) === -1) {973 flags.aliases[key].push(c);974 newAliases[c] = true;975 }976 }977 });978 // For "--optionName", also set argv['option-name']979 flags.aliases[key].concat(key).forEach(function (x) {980 if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {981 const c = decamelize(x, '-');982 if (c !== key && flags.aliases[key].indexOf(c) === -1) {983 flags.aliases[key].push(c);984 newAliases[c] = true;985 }986 }987 });988 flags.aliases[key].forEach(function (x) {989 flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {990 return x !== y;991 }));992 });993 });994 });995 }996 function checkAllAliases(key, flag) {997 const toCheck = [].concat(flags.aliases[key] || [], key);998 const keys = Object.keys(flag);999 const setAlias = toCheck.find(key => keys.includes(key));1000 return setAlias ? flag[setAlias] : false;1001 }1002 function hasAnyFlag(key) {1003 const flagsKeys = Object.keys(flags);1004 const toCheck = [].concat(flagsKeys.map(k => flags[k]));1005 return toCheck.some(function (flag) {1006 return Array.isArray(flag) ? flag.includes(key) : flag[key];1007 });1008 }1009 function hasFlagsMatching(arg, ...patterns) {1010 const toCheck = [].concat(...patterns);1011 return toCheck.some(function (pattern) {1012 const match = arg.match(pattern);1013 return match && hasAnyFlag(match[1]);1014 });1015 }1016 // based on a simplified version of the short flag group parsing logic1017 function hasAllShortFlags(arg) {1018 // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group1019 if (arg.match(negative) || !arg.match(/^-[^-]+/)) {1020 return false;1021 }1022 let hasAllFlags = true;1023 let next;1024 const letters = arg.slice(1).split('');1025 for (let j = 0; j < letters.length; j++) {1026 next = arg.slice(j + 2);1027 if (!hasAnyFlag(letters[j])) {1028 hasAllFlags = false;1029 break;1030 }1031 if ((letters[j + 1] && letters[j + 1] === '=') ||1032 next === '-' ||1033 (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||1034 (letters[j + 1] && letters[j + 1].match(/\W/))) {1035 break;1036 }1037 }1038 return hasAllFlags;1039 }1040 function isUnknownOptionAsArg(arg) {1041 return configuration['unknown-options-as-args'] && isUnknownOption(arg);1042 }1043 function isUnknownOption(arg) {1044 arg = arg.replace(/^-{3,}/, '--');1045 // ignore negative numbers1046 if (arg.match(negative)) {1047 return false;1048 }1049 // if this is a short option group and all of them are configured, it isn't unknown1050 if (hasAllShortFlags(arg)) {1051 return false;1052 }1053 // e.g. '--count=2'1054 const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;1055 // e.g. '-a' or '--arg'1056 const normalFlag = /^-+([^=]+?)$/;1057 // e.g. '-a-'1058 const flagEndingInHyphen = /^-+([^=]+?)-$/;1059 // e.g. '-abc123'1060 const flagEndingInDigits = /^-+([^=]+?\d+)$/;1061 // e.g. '-a/usr/local'1062 const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;1063 // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method1064 return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);1065 }1066 // make a best effort to pick a default value1067 // for an option based on name and type.1068 function defaultValue(key) {1069 if (!checkAllAliases(key, flags.bools) &&1070 !checkAllAliases(key, flags.counts) &&1071 `${key}` in defaults) {1072 return defaults[key];1073 }1074 else {1075 return defaultForType(guessType(key));1076 }1077 }1078 // return a default value, given the type of a flag.,1079 function defaultForType(type) {1080 const def = {1081 [DefaultValuesForTypeKey.BOOLEAN]: true,1082 [DefaultValuesForTypeKey.STRING]: '',1083 [DefaultValuesForTypeKey.NUMBER]: undefined,1084 [DefaultValuesForTypeKey.ARRAY]: []1085 };1086 return def[type];1087 }1088 // given a flag, enforce a default type.1089 function guessType(key) {1090 let type = DefaultValuesForTypeKey.BOOLEAN;1091 if (checkAllAliases(key, flags.strings))1092 type = DefaultValuesForTypeKey.STRING;1093 else if (checkAllAliases(key, flags.numbers))1094 type = DefaultValuesForTypeKey.NUMBER;1095 else if (checkAllAliases(key, flags.bools))1096 type = DefaultValuesForTypeKey.BOOLEAN;1097 else if (checkAllAliases(key, flags.arrays))1098 type = DefaultValuesForTypeKey.ARRAY;1099 return type;1100 }1101 function isUndefined(num) {1102 return num === undefined;1103 }1104 // check user configuration settings for inconsistencies1105 function checkConfiguration() {1106 // count keys should not be set as array/narg1107 Object.keys(flags.counts).find(key => {1108 if (checkAllAliases(key, flags.arrays)) {1109 error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));1110 return true;1111 }1112 else if (checkAllAliases(key, flags.nargs)) {1113 error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));1114 return true;1115 }1116 return false;1117 });1118 }1119 return {1120 aliases: Object.assign({}, flags.aliases),1121 argv: Object.assign(argvReturn, argv),1122 configuration: configuration,1123 defaulted: Object.assign({}, defaulted),1124 error: error,1125 newAliases: Object.assign({}, newAliases)1126 };1127 }1128}1129// if any aliases reference each other, we should1130// merge them together.1131function combineAliases(aliases) {1132 const aliasArrays = [];1133 const combined = Object.create(null);1134 let change = true;1135 // turn alias lookup hash {key: ['alias1', 'alias2']} into1136 // a simple array ['key', 'alias1', 'alias2']1137 Object.keys(aliases).forEach(function (key) {1138 aliasArrays.push([].concat(aliases[key], key));1139 });1140 // combine arrays until zero changes are1141 // made in an iteration.1142 while (change) {1143 change = false;1144 for (let i = 0; i < aliasArrays.length; i++) {1145 for (let ii = i + 1; ii < aliasArrays.length; ii++) {1146 const intersect = aliasArrays[i].filter(function (v) {1147 return aliasArrays[ii].indexOf(v) !== -1;1148 });1149 if (intersect.length) {1150 aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);1151 aliasArrays.splice(ii, 1);1152 change = true;1153 break;1154 }1155 }1156 }1157 }1158 // map arrays back to the hash-lookup (de-dupe while1159 // we're at it).1160 aliasArrays.forEach(function (aliasArray) {1161 aliasArray = aliasArray.filter(function (v, i, self) {1162 return self.indexOf(v) === i;1163 });1164 const lastAlias = aliasArray.pop();1165 if (lastAlias !== undefined && typeof lastAlias === 'string') {1166 combined[lastAlias] = aliasArray;1167 }1168 });1169 return combined;1170}1171// this function should only be called when a count is given as an arg1172// it is NOT called to set a default value1173// thus we can start the count at 1 instead of 01174function increment(orig) {1175 return orig !== undefined ? orig + 1 : 1;1176}1177// TODO(bcoe): in the next major version of yargs, switch to1178// Object.create(null) for dot notation:1179function sanitizeKey(key) {1180 if (key === '__proto__')1181 return '___proto___';1182 return key;1183}1184function stripQuotes(val) {1185 return (typeof val === 'string' &&1186 (val[0] === "'" || val[0] === '"') &&1187 val[val.length - 1] === val[0])1188 ? val.substring(1, val.length - 1)1189 : val;1190}1191 1192/**1193 * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js1194 * CJS and ESM environments.1195 *1196 * @license1197 * Copyright (c) 2016, Contributors1198 * SPDX-License-Identifier: ISC1199 */1200var _a, _b, _c;