Fix: estimates geo v2

This commit is contained in:
Arsen
2026-02-04 00:11:19 +05:00
commit 3f0086f88e
22567 changed files with 4348823 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { CommandInfo } from '../command';
/**
* A command parser encapsulates a specific logic for mapping `CommandInfo` objects
* into another `CommandInfo`.
*
* A prime example is turning an abstract `npm:foo` into `npm run foo`, but it could also turn
* the prefix color of a command brighter, or maybe even prefixing each command with `time(1)`.
*/
export interface CommandParser {
/**
* Parses `commandInfo` and returns one or more `CommandInfo`s.
*
* Returning multiple `CommandInfo` is used when there are multiple possibilities of commands to
* run given the original input.
* An example of this is when the command contains a wildcard and it must be expanded into all
* viable options so that the consumer can decide which ones to run.
*/
parse(commandInfo: CommandInfo): CommandInfo | CommandInfo[];
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,17 @@
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';
/**
* Replace placeholders with additional arguments.
*/
export declare class ExpandArguments implements CommandParser {
private readonly additionalArguments;
constructor(additionalArguments: string[]);
parse(commandInfo: CommandInfo): {
command: string;
name: string;
env?: Record<string, unknown> | undefined;
cwd?: string | undefined;
prefixColor?: string | undefined;
raw?: boolean | undefined;
};
}

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpandArguments = void 0;
const shell_quote_1 = require("shell-quote");
/**
* Replace placeholders with additional arguments.
*/
class ExpandArguments {
constructor(additionalArguments) {
this.additionalArguments = additionalArguments;
}
parse(commandInfo) {
const command = commandInfo.command.replace(/\\?\{([@*]|[1-9][0-9]*)\}/g, (match, placeholderTarget) => {
// Don't replace the placeholder if it is escaped by a backslash.
if (match.startsWith('\\')) {
return match.slice(1);
}
// Replace numeric placeholder if value exists in additional arguments.
if (!isNaN(placeholderTarget) &&
placeholderTarget <= this.additionalArguments.length) {
return (0, shell_quote_1.quote)([this.additionalArguments[placeholderTarget - 1]]);
}
// Replace all arguments placeholder.
if (placeholderTarget === '@') {
return (0, shell_quote_1.quote)(this.additionalArguments);
}
// Replace combined arguments placeholder.
if (placeholderTarget === '*') {
return (0, shell_quote_1.quote)([this.additionalArguments.join(' ')]);
}
// Replace placeholder with empty string
// if value doesn't exist in additional arguments.
return '';
});
return { ...commandInfo, command };
}
}
exports.ExpandArguments = ExpandArguments;

View File

@@ -0,0 +1,8 @@
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';
/**
* Expands commands prefixed with `npm:`, `yarn:`, `pnpm:`, or `bun:` into the full version `npm run <command>` and so on.
*/
export declare class ExpandNpmShortcut implements CommandParser {
parse(commandInfo: CommandInfo): CommandInfo;
}

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpandNpmShortcut = void 0;
/**
* Expands commands prefixed with `npm:`, `yarn:`, `pnpm:`, or `bun:` into the full version `npm run <command>` and so on.
*/
class ExpandNpmShortcut {
parse(commandInfo) {
const [, npmCmd, cmdName, args] = commandInfo.command.match(/^(npm|yarn|pnpm|bun):(\S+)(.*)/) || [];
if (!cmdName) {
return commandInfo;
}
return {
...commandInfo,
name: commandInfo.name || cmdName,
command: `${npmCmd} run ${cmdName}${args}`,
};
}
}
exports.ExpandNpmShortcut = ExpandNpmShortcut;

View File

@@ -0,0 +1,13 @@
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';
/**
* Finds wildcards in npm/yarn/pnpm/bun run commands and replaces them with all matching scripts in the
* `package.json` file of the current directory.
*/
export declare class ExpandNpmWildcard implements CommandParser {
private readonly readPackage;
static readPackage(): any;
private scripts?;
constructor(readPackage?: typeof ExpandNpmWildcard.readPackage);
parse(commandInfo: CommandInfo): CommandInfo | CommandInfo[];
}

View File

@@ -0,0 +1,68 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpandNpmWildcard = void 0;
const fs_1 = __importDefault(require("fs"));
const lodash_1 = __importDefault(require("lodash"));
const OMISSION = /\(!([^)]+)\)/;
/**
* Finds wildcards in npm/yarn/pnpm/bun run commands and replaces them with all matching scripts in the
* `package.json` file of the current directory.
*/
class ExpandNpmWildcard {
static readPackage() {
try {
const json = fs_1.default.readFileSync('package.json', { encoding: 'utf-8' });
return JSON.parse(json);
}
catch (e) {
return {};
}
}
constructor(readPackage = ExpandNpmWildcard.readPackage) {
this.readPackage = readPackage;
}
parse(commandInfo) {
const [, npmCmd, cmdName, args] = commandInfo.command.match(/(npm|yarn|pnpm|bun) run (\S+)([^&]*)/) || [];
const wildcardPosition = (cmdName || '').indexOf('*');
// If the regex didn't match an npm script, or it has no wildcard,
// then we have nothing to do here
if (!cmdName || wildcardPosition === -1) {
return commandInfo;
}
if (!this.scripts) {
this.scripts = Object.keys(this.readPackage().scripts || {});
}
const omissionRegex = cmdName.match(OMISSION);
const cmdNameSansOmission = cmdName.replace(OMISSION, '');
const preWildcard = lodash_1.default.escapeRegExp(cmdNameSansOmission.slice(0, wildcardPosition));
const postWildcard = lodash_1.default.escapeRegExp(cmdNameSansOmission.slice(wildcardPosition + 1));
const wildcardRegex = new RegExp(`^${preWildcard}(.*?)${postWildcard}$`);
// If 'commandInfo.name' doesn't match 'cmdName', this means a custom name
// has been specified and thus becomes the prefix (as described in the README).
const prefix = commandInfo.name !== cmdName ? commandInfo.name : '';
return this.scripts
.map((script) => {
const match = script.match(wildcardRegex);
if (omissionRegex) {
const toOmit = script.match(new RegExp(omissionRegex[1]));
if (toOmit) {
return;
}
}
if (match) {
return {
...commandInfo,
command: `${npmCmd} run ${script}${args}`,
// Will use an empty command name if no prefix has been specified and
// the wildcard match is empty, e.g. if `npm:watch-*` matches `npm run watch-`.
name: prefix + match[1],
};
}
})
.filter((commandInfo) => !!commandInfo);
}
}
exports.ExpandNpmWildcard = ExpandNpmWildcard;

View File

@@ -0,0 +1,15 @@
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';
/**
* Strips quotes around commands so that they can run on the current shell.
*/
export declare class StripQuotes implements CommandParser {
parse(commandInfo: CommandInfo): {
command: string;
name: string;
env?: Record<string, unknown> | undefined;
cwd?: string | undefined;
prefixColor?: string | undefined;
raw?: boolean | undefined;
};
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StripQuotes = void 0;
/**
* Strips quotes around commands so that they can run on the current shell.
*/
class StripQuotes {
parse(commandInfo) {
let { command } = commandInfo;
// Removes the quotes surrounding a command.
if (/^"(.+?)"$/.test(command) || /^'(.+?)'$/.test(command)) {
command = command.slice(1, command.length - 1);
}
return { ...commandInfo, command };
}
}
exports.StripQuotes = StripQuotes;