@miniflare/cli-parser
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.0-rc.4
@@ -0,13 +1,151 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
// node_modules/mri/lib/index.js | ||
var require_lib = __commonJS({ | ||
"node_modules/mri/lib/index.js"(exports, module2) { | ||
function toArr(any) { | ||
return any == null ? [] : Array.isArray(any) ? any : [any]; | ||
} | ||
function toVal(out, key, val, opts) { | ||
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val; | ||
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt]; | ||
} | ||
module2.exports = function(args, opts) { | ||
args = args || []; | ||
opts = opts || {}; | ||
var k, arr, arg, name, val, out = { _: [] }; | ||
var i = 0, j = 0, idx = 0, len = args.length; | ||
const alibi = opts.alias !== void 0; | ||
const strict = opts.unknown !== void 0; | ||
const defaults = opts.default !== void 0; | ||
opts.alias = opts.alias || {}; | ||
opts.string = toArr(opts.string); | ||
opts.boolean = toArr(opts.boolean); | ||
if (alibi) { | ||
for (k in opts.alias) { | ||
arr = opts.alias[k] = toArr(opts.alias[k]); | ||
for (i = 0; i < arr.length; i++) { | ||
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1); | ||
} | ||
} | ||
} | ||
for (i = opts.boolean.length; i-- > 0; ) { | ||
arr = opts.alias[opts.boolean[i]] || []; | ||
for (j = arr.length; j-- > 0; ) | ||
opts.boolean.push(arr[j]); | ||
} | ||
for (i = opts.string.length; i-- > 0; ) { | ||
arr = opts.alias[opts.string[i]] || []; | ||
for (j = arr.length; j-- > 0; ) | ||
opts.string.push(arr[j]); | ||
} | ||
if (defaults) { | ||
for (k in opts.default) { | ||
name = typeof opts.default[k]; | ||
arr = opts.alias[k] = opts.alias[k] || []; | ||
if (opts[name] !== void 0) { | ||
opts[name].push(k); | ||
for (i = 0; i < arr.length; i++) { | ||
opts[name].push(arr[i]); | ||
} | ||
} | ||
} | ||
} | ||
const keys = strict ? Object.keys(opts.alias) : []; | ||
for (i = 0; i < len; i++) { | ||
arg = args[i]; | ||
if (arg === "--") { | ||
out._ = out._.concat(args.slice(++i)); | ||
break; | ||
} | ||
for (j = 0; j < arg.length; j++) { | ||
if (arg.charCodeAt(j) !== 45) | ||
break; | ||
} | ||
if (j === 0) { | ||
out._.push(arg); | ||
} else if (arg.substring(j, j + 3) === "no-") { | ||
name = arg.substring(j + 3); | ||
if (strict && !~keys.indexOf(name)) { | ||
return opts.unknown(arg); | ||
} | ||
out[name] = false; | ||
} else { | ||
for (idx = j + 1; idx < arg.length; idx++) { | ||
if (arg.charCodeAt(idx) === 61) | ||
break; | ||
} | ||
name = arg.substring(j, idx); | ||
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]); | ||
arr = j === 2 ? [name] : name; | ||
for (idx = 0; idx < arr.length; idx++) { | ||
name = arr[idx]; | ||
if (strict && !~keys.indexOf(name)) | ||
return opts.unknown("-".repeat(j) + name); | ||
toVal(out, name, idx + 1 < arr.length || val, opts); | ||
} | ||
} | ||
} | ||
if (defaults) { | ||
for (k in opts.default) { | ||
if (out[k] === void 0) { | ||
out[k] = opts.default[k]; | ||
} | ||
} | ||
} | ||
if (alibi) { | ||
for (k in out) { | ||
arr = opts.alias[k] || []; | ||
while (arr.length > 0) { | ||
out[arr.shift()] = out[k]; | ||
} | ||
} | ||
} | ||
return out; | ||
}; | ||
} | ||
}); | ||
// packages/cli-parser/src/index.ts | ||
__export(exports, { | ||
ParseError: () => ParseError, | ||
_wrapLines: () => _wrapLines, | ||
buildHelp: () => buildHelp, | ||
parseArgv: () => parseArgv | ||
}); | ||
// packages/cli-parser/src/help.ts | ||
import { | ||
OptionType as OptionType2, | ||
spaceCase | ||
} from "@miniflare/shared"; | ||
import { bold, grey } from "kleur/colors"; | ||
var import_shared2 = __toModule(require("@miniflare/shared")); | ||
var import_colors = __toModule(require("kleur/colors")); | ||
// packages/cli-parser/src/helpers.ts | ||
import { OptionType, kebabCase } from "@miniflare/shared"; | ||
var import_shared = __toModule(require("@miniflare/shared")); | ||
function argName(key, { name, type }) { | ||
name ??= kebabCase(key); | ||
if ((type === OptionType.ARRAY || type === OptionType.OBJECT) && name.endsWith("s")) { | ||
name ??= (0, import_shared.kebabCase)(key); | ||
if ((type === import_shared.OptionType.ARRAY || type === import_shared.OptionType.OBJECT) && name.endsWith("s")) { | ||
name = name.substring(0, name.length - 1); | ||
@@ -20,3 +158,3 @@ } | ||
var helpMeta = { | ||
type: OptionType2.BOOLEAN, | ||
type: import_shared2.OptionType.BOOLEAN, | ||
alias: "h", | ||
@@ -26,3 +164,3 @@ description: "Show help" | ||
var versionMeta = { | ||
type: OptionType2.BOOLEAN, | ||
type: import_shared2.OptionType.BOOLEAN, | ||
alias: "v", | ||
@@ -53,3 +191,3 @@ description: "Show version number" | ||
const pluginLines = []; | ||
const sectionName = spaceCase(pluginName.replace("Plugin", "Options")); | ||
const sectionName = (0, import_shared2.spaceCase)(pluginName.replace("Plugin", "Options")); | ||
const entries = [...plugin.prototype.opts.entries()]; | ||
@@ -61,3 +199,3 @@ if (sectionName === "Core Options") { | ||
const { type, typeFormat, alias, description = "", negatable } = meta; | ||
if (type === OptionType2.NONE || typeof key === "symbol") | ||
if (type === import_shared2.OptionType.NONE || typeof key === "symbol") | ||
continue; | ||
@@ -67,10 +205,10 @@ let name = argName(key, meta); | ||
name = `(no-)${name}`; | ||
if (type === OptionType2.STRING_POSITIONAL) { | ||
if (type === import_shared2.OptionType.STRING_POSITIONAL) { | ||
positionalName = name; | ||
continue; | ||
} | ||
let typeName = OptionType2[type].toLowerCase(); | ||
if (type === OptionType2.BOOLEAN_STRING) | ||
let typeName = import_shared2.OptionType[type].toLowerCase(); | ||
if (type === import_shared2.OptionType.BOOLEAN_STRING) | ||
typeName = "boolean/string"; | ||
if (type === OptionType2.OBJECT) { | ||
if (type === import_shared2.OptionType.OBJECT) { | ||
typeName = `array:${typeFormat ?? "KEY=VALUE"}`; | ||
@@ -94,3 +232,3 @@ } | ||
columns = Math.min(leftPaddingLength + maxDescriptionLength + maxTypeLength + 3, columns); | ||
let out = `${bold("Usage:")} ${exec} [${positionalName}] [options] | ||
let out = `${(0, import_colors.bold)("Usage:")} ${exec} [${positionalName}] [options] | ||
`; | ||
@@ -100,6 +238,6 @@ for (const [sectionName, pluginLines] of sections) { | ||
out += ` | ||
${bold(sectionName + ":")} | ||
${(0, import_colors.bold)(sectionName + ":")} | ||
`; | ||
for (const { alias, name, description, typeName } of pluginLines) { | ||
out += grey(alias ? ` -${alias}, ` : " "); | ||
out += (0, import_colors.grey)(alias ? ` -${alias}, ` : " "); | ||
out += `--${name}`.padEnd(maxNameLength + 3, " "); | ||
@@ -109,3 +247,3 @@ const lineLength = columns - (leftPaddingLength + typeName.length + 3); | ||
out += lines[0].padEnd(lineLength, " "); | ||
out += grey(` [${typeName}]`); | ||
out += (0, import_colors.grey)(` [${typeName}]`); | ||
for (let i = 1; i < lines.length; i++) { | ||
@@ -122,114 +260,7 @@ out += ` | ||
// packages/cli-parser/src/parse.ts | ||
import { readFileSync } from "fs"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { | ||
MiniflareError, | ||
OptionType as OptionType3 | ||
} from "@miniflare/shared"; | ||
// node_modules/mri/lib/index.mjs | ||
function toArr(any) { | ||
return any == null ? [] : Array.isArray(any) ? any : [any]; | ||
} | ||
function toVal(out, key, val, opts) { | ||
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val; | ||
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt]; | ||
} | ||
function lib_default(args, opts) { | ||
args = args || []; | ||
opts = opts || {}; | ||
var k, arr, arg, name, val, out = { _: [] }; | ||
var i = 0, j = 0, idx = 0, len = args.length; | ||
const alibi = opts.alias !== void 0; | ||
const strict = opts.unknown !== void 0; | ||
const defaults = opts.default !== void 0; | ||
opts.alias = opts.alias || {}; | ||
opts.string = toArr(opts.string); | ||
opts.boolean = toArr(opts.boolean); | ||
if (alibi) { | ||
for (k in opts.alias) { | ||
arr = opts.alias[k] = toArr(opts.alias[k]); | ||
for (i = 0; i < arr.length; i++) { | ||
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1); | ||
} | ||
} | ||
} | ||
for (i = opts.boolean.length; i-- > 0; ) { | ||
arr = opts.alias[opts.boolean[i]] || []; | ||
for (j = arr.length; j-- > 0; ) | ||
opts.boolean.push(arr[j]); | ||
} | ||
for (i = opts.string.length; i-- > 0; ) { | ||
arr = opts.alias[opts.string[i]] || []; | ||
for (j = arr.length; j-- > 0; ) | ||
opts.string.push(arr[j]); | ||
} | ||
if (defaults) { | ||
for (k in opts.default) { | ||
name = typeof opts.default[k]; | ||
arr = opts.alias[k] = opts.alias[k] || []; | ||
if (opts[name] !== void 0) { | ||
opts[name].push(k); | ||
for (i = 0; i < arr.length; i++) { | ||
opts[name].push(arr[i]); | ||
} | ||
} | ||
} | ||
} | ||
const keys = strict ? Object.keys(opts.alias) : []; | ||
for (i = 0; i < len; i++) { | ||
arg = args[i]; | ||
if (arg === "--") { | ||
out._ = out._.concat(args.slice(++i)); | ||
break; | ||
} | ||
for (j = 0; j < arg.length; j++) { | ||
if (arg.charCodeAt(j) !== 45) | ||
break; | ||
} | ||
if (j === 0) { | ||
out._.push(arg); | ||
} else if (arg.substring(j, j + 3) === "no-") { | ||
name = arg.substring(j + 3); | ||
if (strict && !~keys.indexOf(name)) { | ||
return opts.unknown(arg); | ||
} | ||
out[name] = false; | ||
} else { | ||
for (idx = j + 1; idx < arg.length; idx++) { | ||
if (arg.charCodeAt(idx) === 61) | ||
break; | ||
} | ||
name = arg.substring(j, idx); | ||
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]); | ||
arr = j === 2 ? [name] : name; | ||
for (idx = 0; idx < arr.length; idx++) { | ||
name = arr[idx]; | ||
if (strict && !~keys.indexOf(name)) | ||
return opts.unknown("-".repeat(j) + name); | ||
toVal(out, name, idx + 1 < arr.length || val, opts); | ||
} | ||
} | ||
} | ||
if (defaults) { | ||
for (k in opts.default) { | ||
if (out[k] === void 0) { | ||
out[k] = opts.default[k]; | ||
} | ||
} | ||
} | ||
if (alibi) { | ||
for (k in out) { | ||
arr = opts.alias[k] || []; | ||
while (arr.length > 0) { | ||
out[arr.shift()] = out[k]; | ||
} | ||
} | ||
} | ||
return out; | ||
} | ||
// packages/cli-parser/src/parse.ts | ||
var ParseError = class extends MiniflareError { | ||
var import_fs = __toModule(require("fs")); | ||
var import_path = __toModule(require("path")); | ||
var import_shared3 = __toModule(require("@miniflare/shared")); | ||
var import_mri = __toModule(require_lib()); | ||
var ParseError = class extends import_shared3.MiniflareError { | ||
}; | ||
@@ -250,14 +281,14 @@ function parseArgv(plugins, argv) { | ||
const type = meta.type; | ||
if (type === OptionType3.NONE || typeof key === "symbol") | ||
if (type === import_shared3.OptionType.NONE || typeof key === "symbol") | ||
continue; | ||
const name = argName(key, meta); | ||
args.push({ name, key, meta }); | ||
if (type === OptionType3.STRING_POSITIONAL) { | ||
if (type === import_shared3.OptionType.STRING_POSITIONAL) { | ||
positionalName = name; | ||
continue; | ||
} | ||
if (type === OptionType3.BOOLEAN) { | ||
if (type === import_shared3.OptionType.BOOLEAN) { | ||
booleans.push(name); | ||
} | ||
if (type === OptionType3.STRING || type === OptionType3.ARRAY || type === OptionType3.OBJECT) { | ||
if (type === import_shared3.OptionType.STRING || type === import_shared3.OptionType.ARRAY || type === import_shared3.OptionType.OBJECT) { | ||
strings.push(name); | ||
@@ -268,3 +299,3 @@ } | ||
} | ||
const parsed = lib_default(argv, { | ||
const parsed = (0, import_mri.default)(argv, { | ||
boolean: booleans, | ||
@@ -280,6 +311,4 @@ string: strings, | ||
if (parsed.version) { | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const pkgPath = path.join(__dirname, "..", "..", "package.json"); | ||
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")); | ||
const pkgPath = import_path.default.join(__dirname, "..", "..", "package.json"); | ||
const pkg = JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf8")); | ||
throw new ParseError("ERR_VERSION", pkg.version); | ||
@@ -297,3 +326,3 @@ } | ||
let value = parsed[name]; | ||
if (type === OptionType3.STRING_POSITIONAL) { | ||
if (type === import_shared3.OptionType.STRING_POSITIONAL) { | ||
if (parsed._.length === 1) | ||
@@ -307,12 +336,12 @@ value = parsed._[0]; | ||
let parsedValue = value; | ||
if (type === OptionType3.BOOLEAN) { | ||
if (type === import_shared3.OptionType.BOOLEAN) { | ||
if (typeof value !== "boolean") | ||
unexpected(name, value, "boolean"); | ||
} else if (type === OptionType3.NUMBER) { | ||
} else if (type === import_shared3.OptionType.NUMBER) { | ||
if (typeof value !== "number") | ||
unexpected(name, value, "number"); | ||
} else if (type === OptionType3.STRING || type === OptionType3.STRING_POSITIONAL) { | ||
} else if (type === import_shared3.OptionType.STRING || type === import_shared3.OptionType.STRING_POSITIONAL) { | ||
if (typeof value !== "string") | ||
unexpected(name, value, "string"); | ||
} else if (type === OptionType3.BOOLEAN_STRING) { | ||
} else if (type === import_shared3.OptionType.BOOLEAN_STRING) { | ||
if (Array.isArray(value)) | ||
@@ -322,7 +351,7 @@ unexpected(name, value, "boolean/string"); | ||
parsedValue = value.toString(); | ||
} else if (type === OptionType3.ARRAY || type === OptionType3.OBJECT) { | ||
} else if (type === import_shared3.OptionType.ARRAY || type === import_shared3.OptionType.OBJECT) { | ||
if (!Array.isArray(value)) | ||
value = [value]; | ||
const array = value.map((element) => element.toString()); | ||
if (type === OptionType3.OBJECT) { | ||
if (type === import_shared3.OptionType.OBJECT) { | ||
parsedValue = array.map((element) => { | ||
@@ -344,3 +373,4 @@ const equals = element.indexOf("="); | ||
} | ||
export { | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ParseError, | ||
@@ -350,3 +380,3 @@ _wrapLines, | ||
parseArgv | ||
}; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@miniflare/cli-parser", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.4", | ||
"description": "CLI option parsing module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -14,4 +14,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": "./dist/src/index.js", | ||
"main": "./dist/src/index.js", | ||
"types": "./dist/src/index.d.ts", | ||
@@ -40,8 +39,8 @@ "files": [ | ||
"dependencies": { | ||
"@miniflare/shared": "2.0.0-rc.3", | ||
"@miniflare/shared": "2.0.0-rc.4", | ||
"kleur": "^4.1.4" | ||
}, | ||
"devDependencies": { | ||
"@miniflare/core": "2.0.0-rc.3", | ||
"@miniflare/shared-test": "2.0.0-rc.3", | ||
"@miniflare/core": "2.0.0-rc.4", | ||
"@miniflare/shared-test": "2.0.0-rc.4", | ||
"@types/mri": "^1.1.1", | ||
@@ -48,0 +47,0 @@ "mri": "^1.1.6" |
@@ -6,3 +6,3 @@ # `@miniflare/cli-parser` | ||
fully-local simulator for Cloudflare Workers. See | ||
[💻 Using the CLI](https://miniflare.dev/cli.html) for more details. | ||
[💻 Using the CLI](https://v2.miniflare.dev/get-started/cli) for more details. | ||
@@ -9,0 +9,0 @@ ## Example |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23045
369
No
+ Added@miniflare/shared@2.0.0-rc.4(transitive)
- Removed@miniflare/shared@2.0.0-rc.3(transitive)
Updated@miniflare/shared@2.0.0-rc.4