@plugjs/tsrun 0.4.0
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/LICENSE.md +211 -0
- package/NOTICE.md +13 -0
- package/README.md +21 -0
- package/dist/cli.d.mts +14 -0
- package/dist/cli.mjs +1119 -0
- package/dist/loader.mjs +266 -0
- package/dist/parser.d.mts +118 -0
- package/dist/parser.mjs +1039 -0
- package/dist/tsrun.mjs +1225 -0
- package/package.json +39 -0
- package/src/cli.mts +126 -0
- package/src/loader.mts +568 -0
- package/src/parser.mts +2 -0
- package/src/tsrun.mts +155 -0
package/dist/loader.mjs
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// src/loader.mts
|
|
2
|
+
import _fs from "node:fs";
|
|
3
|
+
import _module from "node:module";
|
|
4
|
+
import _path from "node:path";
|
|
5
|
+
import _url from "node:url";
|
|
6
|
+
import _util from "node:util";
|
|
7
|
+
import _esbuild from "esbuild";
|
|
8
|
+
var CJS = "commonjs";
|
|
9
|
+
var ESM = "module";
|
|
10
|
+
var _debugLog = _util.debuglog("plug:ts-loader");
|
|
11
|
+
var _debug = _debugLog.enabled;
|
|
12
|
+
function _log(type, arg, ...args) {
|
|
13
|
+
if (!_debug)
|
|
14
|
+
return;
|
|
15
|
+
const t = type === ESM ? "esm" : type === CJS ? "cjs" : "---";
|
|
16
|
+
_debugLog(`[${t}] ${arg}`, ...args);
|
|
17
|
+
}
|
|
18
|
+
function _throw(type, message, options = {}) {
|
|
19
|
+
const t = type === ESM ? "esm" : type === CJS ? "cjs" : "---";
|
|
20
|
+
const prefix = `[ts-loader|${t}|pid=${process.pid}]`;
|
|
21
|
+
const { start = _throw, ...extra } = options;
|
|
22
|
+
const error = new Error(`${prefix} ${message}`);
|
|
23
|
+
Error.captureStackTrace(error, start);
|
|
24
|
+
Object.assign(error, extra);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
function _checkType(type) {
|
|
28
|
+
if (type === CJS)
|
|
29
|
+
return CJS;
|
|
30
|
+
if (type === ESM)
|
|
31
|
+
return ESM;
|
|
32
|
+
_throw(null, `Invalid type "${process.env.__TS_LOADER_FORCE_TYPE}"`);
|
|
33
|
+
}
|
|
34
|
+
var _type = (() => {
|
|
35
|
+
if (process.env.__TS_LOADER_FORCE_TYPE) {
|
|
36
|
+
const type = process.env.__TS_LOADER_FORCE_TYPE;
|
|
37
|
+
_log(null, `Forcing type to "${type}" from environment`);
|
|
38
|
+
return _checkType(type);
|
|
39
|
+
}
|
|
40
|
+
const findType = (directory) => {
|
|
41
|
+
const packageFile = _path.join(directory, "package.json");
|
|
42
|
+
try {
|
|
43
|
+
const packageData = _fs.readFileSync(packageFile, "utf-8");
|
|
44
|
+
const packageJson = JSON.parse(packageData);
|
|
45
|
+
const packageType = packageJson.type;
|
|
46
|
+
switch (packageType) {
|
|
47
|
+
case void 0:
|
|
48
|
+
_log(null, `File "${packageFile}" does not declare a default type`);
|
|
49
|
+
return CJS;
|
|
50
|
+
case CJS:
|
|
51
|
+
case ESM:
|
|
52
|
+
_log(null, `File "${packageFile}" declares type as "${CJS}"`);
|
|
53
|
+
return packageType;
|
|
54
|
+
default:
|
|
55
|
+
_log(null, `File "${packageFile}" specifies unknown type "${packageType}"`);
|
|
56
|
+
return CJS;
|
|
57
|
+
}
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
if (cause.code !== "ENOENT" && cause.code !== "EISDIR") {
|
|
60
|
+
_throw(null, `Unable to read or parse "${packageFile}"`, { cause, start: findType });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const parent = _path.dirname(directory);
|
|
64
|
+
if (directory !== parent)
|
|
65
|
+
return findType(directory);
|
|
66
|
+
_log(null, `Type defaulted to "${CJS}"`);
|
|
67
|
+
return CJS;
|
|
68
|
+
};
|
|
69
|
+
return findType(process.cwd());
|
|
70
|
+
})();
|
|
71
|
+
var tsLoaderMarker = Symbol.for("plugjs:tsLoader");
|
|
72
|
+
Object.defineProperty(globalThis, tsLoaderMarker, {
|
|
73
|
+
set(type) {
|
|
74
|
+
_log(null, `Setting type to "${type}"`);
|
|
75
|
+
process.env.__TS_LOADER_FORCE_TYPE = _type = _checkType(type);
|
|
76
|
+
},
|
|
77
|
+
get() {
|
|
78
|
+
return _type;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
function _esbReport(kind, messages = []) {
|
|
82
|
+
const output = process.stderr;
|
|
83
|
+
const options = { color: !!output.isTTY, terminalWidth: output.columns || 80 };
|
|
84
|
+
const array = _esbuild.formatMessagesSync(messages, { kind, ...options });
|
|
85
|
+
array.forEach((message) => output.write(`${message}
|
|
86
|
+
`));
|
|
87
|
+
}
|
|
88
|
+
function _esbTranpile(filename, type) {
|
|
89
|
+
_log(type, `Transpiling "${filename}`);
|
|
90
|
+
const [format, __fileurl] = type === ESM ? ["esm", "import.meta.url"] : ["cjs", "__filename"];
|
|
91
|
+
const options = {
|
|
92
|
+
sourcefile: filename,
|
|
93
|
+
// the original filename we're parsing
|
|
94
|
+
format,
|
|
95
|
+
// what are we actually transpiling to???
|
|
96
|
+
loader: "ts",
|
|
97
|
+
// the format is always "typescript"
|
|
98
|
+
sourcemap: "inline",
|
|
99
|
+
// always inline source maps
|
|
100
|
+
sourcesContent: false,
|
|
101
|
+
// do not include sources content in sourcemap
|
|
102
|
+
platform: "node",
|
|
103
|
+
// d'oh! :-)
|
|
104
|
+
minifyWhitespace: true,
|
|
105
|
+
// https://github.com/evanw/esbuild/releases/tag/v0.16.14
|
|
106
|
+
logLevel: "silent",
|
|
107
|
+
// catching those in our _esbReport below
|
|
108
|
+
target: `node${process.versions["node"]}`,
|
|
109
|
+
// target _this_ version
|
|
110
|
+
define: { __fileurl }
|
|
111
|
+
// from "globals.d.ts"
|
|
112
|
+
};
|
|
113
|
+
if (_debug) {
|
|
114
|
+
if (format === "esm") {
|
|
115
|
+
options.banner = `;(await import('node:util')).debuglog('plug:ts-loader')('[esm] Loaded "%s"', ${__fileurl});`;
|
|
116
|
+
} else if (format === "cjs") {
|
|
117
|
+
options.banner = `;require('node:util').debuglog('plug:ts-loader')('[cjs] Loaded "%s"', ${__fileurl});`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
const source = _fs.readFileSync(filename, "utf-8");
|
|
123
|
+
result = _esbuild.transformSync(source, options);
|
|
124
|
+
} catch (cause) {
|
|
125
|
+
_esbReport("error", cause.errors);
|
|
126
|
+
_esbReport("warning", cause.warnings);
|
|
127
|
+
_throw(type, `ESBuild error transpiling "${filename}"`, { cause, start: _esbTranpile });
|
|
128
|
+
}
|
|
129
|
+
if (_debug)
|
|
130
|
+
_esbReport("warning", result.warnings);
|
|
131
|
+
return result.code;
|
|
132
|
+
}
|
|
133
|
+
function isFile(path) {
|
|
134
|
+
try {
|
|
135
|
+
return _fs.statSync(path).isFile();
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function isDirectory(path) {
|
|
141
|
+
try {
|
|
142
|
+
return _fs.statSync(path).isDirectory();
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
var resolve = (specifier, context, nextResolve) => {
|
|
148
|
+
_log(ESM, `Resolving "${specifier}" from "${context.parentURL}"`);
|
|
149
|
+
if (!specifier.match(/^\.\.?\//))
|
|
150
|
+
return nextResolve(specifier, context);
|
|
151
|
+
const parentURL = context.parentURL;
|
|
152
|
+
if (!parentURL)
|
|
153
|
+
return nextResolve(specifier, context);
|
|
154
|
+
if (!parentURL.startsWith("file:"))
|
|
155
|
+
return nextResolve(specifier, context);
|
|
156
|
+
if (!parentURL.match(/\.m?ts$/))
|
|
157
|
+
return nextResolve(specifier, context);
|
|
158
|
+
const url = new URL(specifier, parentURL).href;
|
|
159
|
+
const path = _url.fileURLToPath(url);
|
|
160
|
+
if (isFile(path)) {
|
|
161
|
+
_log(ESM, `Positive match for "${specifier}" as "${path}" (1)`);
|
|
162
|
+
return nextResolve(specifier, context);
|
|
163
|
+
}
|
|
164
|
+
const match = specifier.match(/(.*)(\.[mc]?js$)/);
|
|
165
|
+
if (match) {
|
|
166
|
+
const [, base, ext] = match;
|
|
167
|
+
const tsspecifier = base + ext.replace("js", "ts");
|
|
168
|
+
const tsurl = new URL(tsspecifier, parentURL).href;
|
|
169
|
+
const tspath = _url.fileURLToPath(tsurl);
|
|
170
|
+
if (isFile(tspath)) {
|
|
171
|
+
_log(ESM, `Positive match for "${specifier}" as "${tspath}" (2)`);
|
|
172
|
+
return nextResolve(tsspecifier, context);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (isFile(`${path}.ts`)) {
|
|
176
|
+
_log(ESM, `Positive match for "${specifier}.ts" as "${path}.ts" (3)`);
|
|
177
|
+
return nextResolve(`${specifier}.ts`, context);
|
|
178
|
+
}
|
|
179
|
+
if (isDirectory(path)) {
|
|
180
|
+
const file = _path.resolve(path, "index.ts");
|
|
181
|
+
if (isFile(file)) {
|
|
182
|
+
_log(ESM, `Positive match for "${specifier}" as "${file}" (4)`);
|
|
183
|
+
const spec = _url.pathToFileURL(file).pathname;
|
|
184
|
+
return nextResolve(spec, context);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return nextResolve(specifier, context);
|
|
188
|
+
};
|
|
189
|
+
var load = (url, context, nextLoad) => {
|
|
190
|
+
_log(ESM, `Attempting to load "${url}"`);
|
|
191
|
+
if (!url.startsWith("file:"))
|
|
192
|
+
return nextLoad(url, context);
|
|
193
|
+
const ext = url.match(/\.[cm]?ts$/)?.[0];
|
|
194
|
+
if (!ext)
|
|
195
|
+
return nextLoad(url, context);
|
|
196
|
+
if (ext === ".cts") {
|
|
197
|
+
if (_debug) {
|
|
198
|
+
_log(null, `Switching type from "module" to "commonjs" for "${url}"`);
|
|
199
|
+
_log(null, "Please note that named import WILL NOT WORK in this case, as Node.js performs a");
|
|
200
|
+
_log(null, "static analisys on the CommonJS source code, and this file is transpiled from.");
|
|
201
|
+
_log(null, "TypeScript to CommonJS dynamically.");
|
|
202
|
+
}
|
|
203
|
+
return { format: CJS, shortCircuit: true };
|
|
204
|
+
}
|
|
205
|
+
const filename = _url.fileURLToPath(url);
|
|
206
|
+
if (ext === ".ts") {
|
|
207
|
+
if (_type === CJS) {
|
|
208
|
+
if (_debug) {
|
|
209
|
+
_log(null, `Switching type from "module" to "commonjs" for "${url}"`);
|
|
210
|
+
_log(null, "Please note that named import WILL NOT WORK in this case, as Node.js performs a");
|
|
211
|
+
_log(null, "static analisys on the CommonJS source code, and this file is transpiled from.");
|
|
212
|
+
_log(null, "TypeScript to CommonJS dynamically.");
|
|
213
|
+
}
|
|
214
|
+
return { format: CJS, shortCircuit: true };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const source = _esbTranpile(filename, ESM);
|
|
218
|
+
return { source, format: ESM, shortCircuit: true };
|
|
219
|
+
};
|
|
220
|
+
var loader = (module, filename) => {
|
|
221
|
+
_log(CJS, `Attempting to load "${filename}"`);
|
|
222
|
+
const ext = _path.extname(filename);
|
|
223
|
+
if (ext === ".ts") {
|
|
224
|
+
if (_type === ESM) {
|
|
225
|
+
_throw(CJS, `Must use import to load ES Module: ${filename}`, { code: "ERR_REQUIRE_ESM" });
|
|
226
|
+
}
|
|
227
|
+
} else if (ext !== ".cts") {
|
|
228
|
+
_throw(CJS, `Unsupported filename "${filename}"`);
|
|
229
|
+
}
|
|
230
|
+
const source = _esbTranpile(filename, CJS);
|
|
231
|
+
try {
|
|
232
|
+
module._compile(source, filename);
|
|
233
|
+
} catch (cause) {
|
|
234
|
+
console.error(`Error compiling module "${filename}"`, cause);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
_module._extensions[".ts"] = _module._extensions[".cts"] = loader;
|
|
238
|
+
var _oldResolveFilename = _module._resolveFilename;
|
|
239
|
+
_module._resolveFilename = function(request, parent, ...args) {
|
|
240
|
+
try {
|
|
241
|
+
return _oldResolveFilename.call(this, request, parent, ...args);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error.code !== "MODULE_NOT_FOUND")
|
|
244
|
+
throw error;
|
|
245
|
+
const match = request.match(/(.*)(\.[mc]?js$)/);
|
|
246
|
+
if (parent && match) {
|
|
247
|
+
const [, name, ext] = match;
|
|
248
|
+
const tsrequest = name + ext.replace("js", "ts");
|
|
249
|
+
try {
|
|
250
|
+
const result = _oldResolveFilename.call(this, tsrequest, parent, ...args);
|
|
251
|
+
_log(CJS, `Resolution for "${request}" intercepted as "${tsrequest}`);
|
|
252
|
+
return result;
|
|
253
|
+
} catch (discard) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
export {
|
|
261
|
+
isDirectory,
|
|
262
|
+
isFile,
|
|
263
|
+
load,
|
|
264
|
+
resolve
|
|
265
|
+
};
|
|
266
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2xvYWRlci5tdHMiXSwKICAibWFwcGluZ3MiOiAiO0FBcUJBLE9BQU8sU0FBUztBQUNoQixPQUFPLGFBQWE7QUFDcEIsT0FBTyxXQUFXO0FBQ2xCLE9BQU8sVUFBVTtBQUNqQixPQUFPLFdBQVc7QUFHbEIsT0FBTyxjQUFjO0FBV3JCLElBQU0sTUFBTTtBQUVaLElBQU0sTUFBTTtBQUdaLElBQU0sWUFBWSxNQUFNLFNBQVMsZ0JBQWdCO0FBQ2pELElBQU0sU0FBUyxVQUFVO0FBR3pCLFNBQVMsS0FBSyxNQUFtQixRQUFnQixNQUFvQjtBQUNuRSxNQUFJLENBQUU7QUFBUTtBQUVkLFFBQU0sSUFBSSxTQUFTLE1BQU0sUUFBUSxTQUFTLE1BQU0sUUFBUTtBQUN4RCxZQUFVLElBQUksTUFBTSxPQUFPLE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|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Type definitions for yargs-parser 21.0
|
|
2
|
+
// Project: https://github.com/yargs/yargs-parser#readme
|
|
3
|
+
// Definitions by: Miles Johnson <https://github.com/milesj>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
// TypeScript Version: 2.2
|
|
6
|
+
|
|
7
|
+
declare namespace yargsParser {
|
|
8
|
+
interface Arguments {
|
|
9
|
+
/** Non-option arguments */
|
|
10
|
+
_: Array<string | number>;
|
|
11
|
+
/** Arguments after the end-of-options flag `--` */
|
|
12
|
+
'--'?: Array<string | number>;
|
|
13
|
+
/** All remaining options */
|
|
14
|
+
[argName: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface DetailedArguments {
|
|
18
|
+
/** An object representing the parsed value of `args` */
|
|
19
|
+
argv: Arguments;
|
|
20
|
+
/** Populated with an error object if an exception occurred during parsing. */
|
|
21
|
+
error: Error | null;
|
|
22
|
+
/** The inferred list of aliases built by combining lists in opts.alias. */
|
|
23
|
+
aliases: { [alias: string]: string[] };
|
|
24
|
+
/** Any new aliases added via camel-case expansion. */
|
|
25
|
+
newAliases: { [alias: string]: boolean };
|
|
26
|
+
/** The configuration loaded from the yargs stanza in package.json. */
|
|
27
|
+
configuration: Configuration;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Configuration {
|
|
31
|
+
/** Should variables prefixed with --no be treated as negations? Default is `true` */
|
|
32
|
+
'boolean-negation': boolean;
|
|
33
|
+
/** Should hyphenated arguments be expanded into camel-case aliases? Default is `true` */
|
|
34
|
+
'camel-case-expansion': boolean;
|
|
35
|
+
/** Should arrays be combined when provided by both command line arguments and a configuration file. Default is `false` */
|
|
36
|
+
'combine-arrays': boolean;
|
|
37
|
+
/** Should keys that contain . be treated as objects? Default is `true` */
|
|
38
|
+
'dot-notation': boolean;
|
|
39
|
+
/** Should arguments be coerced into an array when duplicated. Default is `true` */
|
|
40
|
+
'duplicate-arguments-array': boolean;
|
|
41
|
+
/** Should array arguments be coerced into a single array when duplicated. Default is `true` */
|
|
42
|
+
'flatten-duplicate-arrays': boolean;
|
|
43
|
+
/** Should arrays consume more than one positional argument following their flag. Default is `true` */
|
|
44
|
+
'greedy-arrays': boolean;
|
|
45
|
+
/** Should nargs consume dash options as well as positional arguments. Default is `false` */
|
|
46
|
+
'nargs-eats-options': boolean;
|
|
47
|
+
/** Should parsing stop at the first text argument? This is similar to how e.g. ssh parses its command line. Default is `false` */
|
|
48
|
+
'halt-at-non-option': boolean;
|
|
49
|
+
/** The prefix to use for negated boolean variables. Default is `'no-'` */
|
|
50
|
+
'negation-prefix': string;
|
|
51
|
+
/** Should keys that look like numbers be treated as such? Default is `true` */
|
|
52
|
+
'parse-numbers': boolean;
|
|
53
|
+
/** Should positional keys that look like numbers be treated as such? Default is `true` */
|
|
54
|
+
'parse-positional-numbers': boolean;
|
|
55
|
+
/** Should unparsed flags be stored in -- or _. Default is `false` */
|
|
56
|
+
'populate--': boolean;
|
|
57
|
+
/** Should a placeholder be added for keys not set via the corresponding CLI argument? Default is `false` */
|
|
58
|
+
'set-placeholder-key': boolean;
|
|
59
|
+
/** Should a group of short-options be treated as boolean flags? Default is `true` */
|
|
60
|
+
'short-option-groups': boolean;
|
|
61
|
+
/** Should aliases be removed before returning results? Default is `false` */
|
|
62
|
+
'strip-aliased': boolean;
|
|
63
|
+
/** Should dashed keys be removed before returning results? This option has no effect if camel-case-expansion is disabled. Default is `false` */
|
|
64
|
+
'strip-dashed': boolean;
|
|
65
|
+
/** Should unknown options be treated like regular arguments? An unknown option is one that is not configured in opts. Default is `false` */
|
|
66
|
+
'unknown-options-as-args': boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface Options {
|
|
70
|
+
/** An object representing the set of aliases for a key: `{ alias: { foo: ['f']} }`. */
|
|
71
|
+
alias?: { [key: string]: string | string[] } | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Indicate that keys should be parsed as an array: `{ array: ['foo', 'bar'] }`.
|
|
74
|
+
* Indicate that keys should be parsed as an array and coerced to booleans / numbers:
|
|
75
|
+
* { array: [ { key: 'foo', boolean: true }, {key: 'bar', number: true} ] }`.
|
|
76
|
+
*/
|
|
77
|
+
array?:
|
|
78
|
+
| string[]
|
|
79
|
+
| Array<{ key: string; boolean?: boolean | undefined; number?: boolean | undefined }>
|
|
80
|
+
| undefined;
|
|
81
|
+
/** Arguments should be parsed as booleans: `{ boolean: ['x', 'y'] }`. */
|
|
82
|
+
boolean?: string[] | undefined;
|
|
83
|
+
/** Indicate a key that represents a path to a configuration file (this file will be loaded and parsed). */
|
|
84
|
+
config?: string | string[] | { [key: string]: boolean } | undefined;
|
|
85
|
+
/** Provide configuration options to the yargs-parser. */
|
|
86
|
+
configuration?: Partial<Configuration> | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Provide a custom synchronous function that returns a coerced value from the argument provided (or throws an error), e.g.
|
|
89
|
+
* `{ coerce: { foo: function (arg) { return modifiedArg } } }`.
|
|
90
|
+
*/
|
|
91
|
+
coerce?: { [key: string]: (arg: any) => any } | undefined;
|
|
92
|
+
/** Indicate a key that should be used as a counter, e.g., `-vvv = {v: 3}`. */
|
|
93
|
+
count?: string[] | undefined;
|
|
94
|
+
/** Provide default values for keys: `{ default: { x: 33, y: 'hello world!' } }`. */
|
|
95
|
+
default?: { [key: string]: any } | undefined;
|
|
96
|
+
/** Environment variables (`process.env`) with the prefix provided should be parsed. */
|
|
97
|
+
envPrefix?: string | undefined;
|
|
98
|
+
/** Specify that a key requires n arguments: `{ narg: {x: 2} }`. */
|
|
99
|
+
narg?: { [key: string]: number } | undefined;
|
|
100
|
+
/** `path.normalize()` will be applied to values set to this key. */
|
|
101
|
+
normalize?: string[] | undefined;
|
|
102
|
+
/** Keys should be treated as strings (even if they resemble a number `-x 33`). */
|
|
103
|
+
string?: string[] | undefined;
|
|
104
|
+
/** Keys should be treated as numbers. */
|
|
105
|
+
number?: string[] | undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface Parser {
|
|
109
|
+
(argv: string | string[], opts?: Options): Arguments;
|
|
110
|
+
detailed(argv: string | string[], opts?: Options): DetailedArguments;
|
|
111
|
+
camelCase(str: string): string;
|
|
112
|
+
decamelize(str: string, joinString?: string): string;
|
|
113
|
+
looksLikeNumber(value: string | number | null | undefined): boolean;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
declare var yargsParser: yargsParser.Parser;
|
|
118
|
+
export = yargsParser;
|