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