full site update
This commit is contained in:
36
node_modules/package-manager-detector/dist/commands.d.mts
generated
vendored
Normal file
36
node_modules/package-manager-detector/dist/commands.d.mts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { c as AgentCommands, b as AgentCommandValue, R as ResolvedCommand, A as Agent, C as Command } from './shared/package-manager-detector.pUYRhiOu.mjs';
|
||||
|
||||
declare const COMMANDS: {
|
||||
npm: AgentCommands;
|
||||
yarn: AgentCommands;
|
||||
'yarn@berry': AgentCommands;
|
||||
pnpm: AgentCommands;
|
||||
'pnpm@6': AgentCommands;
|
||||
bun: AgentCommands;
|
||||
deno: AgentCommands;
|
||||
};
|
||||
/**
|
||||
* Resolve the command for the agent merging the command arguments with the provided arguments.
|
||||
*
|
||||
* For example, to show how to install `@antfu/ni` globally using `pnpm`:
|
||||
* ```js
|
||||
* import { resolveCommand } from 'package-manager-detector/commands'
|
||||
* const { command, args } = resolveCommand('pnpm', 'global', ['@antfu/ni'])
|
||||
* console.log(`${command} ${args.join(' ')}`) // 'pnpm add -g @antfu/ni'
|
||||
* ```
|
||||
*
|
||||
* @param agent The agent to use.
|
||||
* @param command the command to resolve.
|
||||
* @param args The arguments to pass to the command.
|
||||
* @returns {ResolvedCommand} The resolved command or `null` if the agent command is not found.
|
||||
*/
|
||||
declare function resolveCommand(agent: Agent, command: Command, args: string[]): ResolvedCommand | null;
|
||||
/**
|
||||
* Construct the command from the agent command merging the command arguments with the provided arguments.
|
||||
* @param value {AgentCommandValue} The agent command to use.
|
||||
* @param args The arguments to pass to the command.
|
||||
* @returns {ResolvedCommand} The resolved command or `null` if the command is `null`.
|
||||
*/
|
||||
declare function constructCommand(value: AgentCommandValue, args: string[]): ResolvedCommand | null;
|
||||
|
||||
export { COMMANDS, constructCommand, resolveCommand };
|
127
node_modules/package-manager-detector/dist/commands.mjs
generated
vendored
Normal file
127
node_modules/package-manager-detector/dist/commands.mjs
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
function dashDashArg(agent, agentCommand) {
|
||||
return (args) => {
|
||||
if (args.length > 1) {
|
||||
return [agent, agentCommand, args[0], "--", ...args.slice(1)];
|
||||
} else {
|
||||
return [agent, agentCommand, args[0]];
|
||||
}
|
||||
};
|
||||
}
|
||||
function denoExecute() {
|
||||
return (args) => {
|
||||
return ["deno", "run", `npm:${args[0]}`, ...args.slice(1)];
|
||||
};
|
||||
}
|
||||
const npm = {
|
||||
"agent": ["npm", 0],
|
||||
"run": dashDashArg("npm", "run"),
|
||||
"install": ["npm", "i", 0],
|
||||
"frozen": ["npm", "ci", 0],
|
||||
"global": ["npm", "i", "-g", 0],
|
||||
"add": ["npm", "i", 0],
|
||||
"upgrade": ["npm", "update", 0],
|
||||
"upgrade-interactive": null,
|
||||
"execute": ["npx", 0],
|
||||
"execute-local": ["npx", 0],
|
||||
"uninstall": ["npm", "uninstall", 0],
|
||||
"global_uninstall": ["npm", "uninstall", "-g", 0]
|
||||
};
|
||||
const yarn = {
|
||||
"agent": ["yarn", 0],
|
||||
"run": ["yarn", "run", 0],
|
||||
"install": ["yarn", "install", 0],
|
||||
"frozen": ["yarn", "install", "--frozen-lockfile", 0],
|
||||
"global": ["yarn", "global", "add", 0],
|
||||
"add": ["yarn", "add", 0],
|
||||
"upgrade": ["yarn", "upgrade", 0],
|
||||
"upgrade-interactive": ["yarn", "upgrade-interactive", 0],
|
||||
"execute": ["npx", 0],
|
||||
"execute-local": dashDashArg("yarn", "exec"),
|
||||
"uninstall": ["yarn", "remove", 0],
|
||||
"global_uninstall": ["yarn", "global", "remove", 0]
|
||||
};
|
||||
const yarnBerry = {
|
||||
...yarn,
|
||||
"frozen": ["yarn", "install", "--immutable", 0],
|
||||
"upgrade": ["yarn", "up", 0],
|
||||
"upgrade-interactive": ["yarn", "up", "-i", 0],
|
||||
"execute": ["yarn", "dlx", 0],
|
||||
"execute-local": ["yarn", "exec", 0],
|
||||
// Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
|
||||
"global": ["npm", "i", "-g", 0],
|
||||
"global_uninstall": ["npm", "uninstall", "-g", 0]
|
||||
};
|
||||
const pnpm = {
|
||||
"agent": ["pnpm", 0],
|
||||
"run": ["pnpm", "run", 0],
|
||||
"install": ["pnpm", "i", 0],
|
||||
"frozen": ["pnpm", "i", "--frozen-lockfile", 0],
|
||||
"global": ["pnpm", "add", "-g", 0],
|
||||
"add": ["pnpm", "add", 0],
|
||||
"upgrade": ["pnpm", "update", 0],
|
||||
"upgrade-interactive": ["pnpm", "update", "-i", 0],
|
||||
"execute": ["pnpm", "dlx", 0],
|
||||
"execute-local": ["pnpm", "exec", 0],
|
||||
"uninstall": ["pnpm", "remove", 0],
|
||||
"global_uninstall": ["pnpm", "remove", "--global", 0]
|
||||
};
|
||||
const bun = {
|
||||
"agent": ["bun", 0],
|
||||
"run": ["bun", "run", 0],
|
||||
"install": ["bun", "install", 0],
|
||||
"frozen": ["bun", "install", "--frozen-lockfile", 0],
|
||||
"global": ["bun", "add", "-g", 0],
|
||||
"add": ["bun", "add", 0],
|
||||
"upgrade": ["bun", "update", 0],
|
||||
"upgrade-interactive": ["bun", "update", 0],
|
||||
"execute": ["bun", "x", 0],
|
||||
"execute-local": ["bun", "x", 0],
|
||||
"uninstall": ["bun", "remove", 0],
|
||||
"global_uninstall": ["bun", "remove", "-g", 0]
|
||||
};
|
||||
const deno = {
|
||||
"agent": ["deno", 0],
|
||||
"run": ["deno", "task", 0],
|
||||
"install": ["deno", "install", 0],
|
||||
"frozen": ["deno", "install", "--frozen", 0],
|
||||
"global": ["deno", "install", "-g", 0],
|
||||
"add": ["deno", "add", 0],
|
||||
"upgrade": ["deno", "outdated", "--update", 0],
|
||||
"upgrade-interactive": ["deno", "outdated", "--update", 0],
|
||||
"execute": denoExecute(),
|
||||
"execute-local": ["deno", "task", "--eval", 0],
|
||||
"uninstall": ["deno", "remove", 0],
|
||||
"global_uninstall": ["deno", "uninstall", "-g", 0]
|
||||
};
|
||||
const COMMANDS = {
|
||||
"npm": npm,
|
||||
"yarn": yarn,
|
||||
"yarn@berry": yarnBerry,
|
||||
"pnpm": pnpm,
|
||||
// pnpm v6.x or below
|
||||
"pnpm@6": {
|
||||
...pnpm,
|
||||
run: dashDashArg("pnpm", "run")
|
||||
},
|
||||
"bun": bun,
|
||||
"deno": deno
|
||||
};
|
||||
function resolveCommand(agent, command, args) {
|
||||
const value = COMMANDS[agent][command];
|
||||
return constructCommand(value, args);
|
||||
}
|
||||
function constructCommand(value, args) {
|
||||
if (value == null)
|
||||
return null;
|
||||
const list = typeof value === "function" ? value(args) : value.flatMap((v) => {
|
||||
if (typeof v === "number")
|
||||
return args;
|
||||
return [v];
|
||||
});
|
||||
return {
|
||||
command: list[0],
|
||||
args: list.slice(1)
|
||||
};
|
||||
}
|
||||
|
||||
export { COMMANDS, constructCommand, resolveCommand };
|
8
node_modules/package-manager-detector/dist/constants.d.mts
generated
vendored
Normal file
8
node_modules/package-manager-detector/dist/constants.d.mts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { A as Agent, a as AgentName } from './shared/package-manager-detector.pUYRhiOu.mjs';
|
||||
|
||||
declare const AGENTS: Agent[];
|
||||
declare const LOCKS: Record<string, AgentName>;
|
||||
declare const INSTALL_METADATA: Record<string, AgentName>;
|
||||
declare const INSTALL_PAGE: Record<Agent, string>;
|
||||
|
||||
export { AGENTS, INSTALL_METADATA, INSTALL_PAGE, LOCKS };
|
45
node_modules/package-manager-detector/dist/constants.mjs
generated
vendored
Normal file
45
node_modules/package-manager-detector/dist/constants.mjs
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
const AGENTS = [
|
||||
"npm",
|
||||
"yarn",
|
||||
"yarn@berry",
|
||||
"pnpm",
|
||||
"pnpm@6",
|
||||
"bun",
|
||||
"deno"
|
||||
];
|
||||
const LOCKS = {
|
||||
"bun.lock": "bun",
|
||||
"bun.lockb": "bun",
|
||||
"deno.lock": "deno",
|
||||
"pnpm-lock.yaml": "pnpm",
|
||||
"pnpm-workspace.yaml": "pnpm",
|
||||
"yarn.lock": "yarn",
|
||||
"package-lock.json": "npm",
|
||||
"npm-shrinkwrap.json": "npm"
|
||||
};
|
||||
const INSTALL_METADATA = {
|
||||
"node_modules/.deno/": "deno",
|
||||
"node_modules/.pnpm/": "pnpm",
|
||||
"node_modules/.yarn-state.yml": "yarn",
|
||||
// yarn v2+ (node-modules)
|
||||
"node_modules/.yarn_integrity": "yarn",
|
||||
// yarn v1
|
||||
"node_modules/.package-lock.json": "npm",
|
||||
".pnp.cjs": "yarn",
|
||||
// yarn v3+ (pnp)
|
||||
".pnp.js": "yarn",
|
||||
// yarn v2 (pnp)
|
||||
"bun.lock": "bun",
|
||||
"bun.lockb": "bun"
|
||||
};
|
||||
const INSTALL_PAGE = {
|
||||
"bun": "https://bun.sh",
|
||||
"deno": "https://deno.com",
|
||||
"pnpm": "https://pnpm.io/installation",
|
||||
"pnpm@6": "https://pnpm.io/6.x/installation",
|
||||
"yarn": "https://classic.yarnpkg.com/en/docs/install",
|
||||
"yarn@berry": "https://yarnpkg.com/getting-started/install",
|
||||
"npm": "https://docs.npmjs.com/cli/configuring-npm/install"
|
||||
};
|
||||
|
||||
export { AGENTS, INSTALL_METADATA, INSTALL_PAGE, LOCKS };
|
16
node_modules/package-manager-detector/dist/detect.d.mts
generated
vendored
Normal file
16
node_modules/package-manager-detector/dist/detect.d.mts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { d as DetectOptions, e as DetectResult, a as AgentName } from './shared/package-manager-detector.pUYRhiOu.mjs';
|
||||
|
||||
/**
|
||||
* Detects the package manager used in the running process.
|
||||
*
|
||||
* This method will check for `process.env.npm_config_user_agent`.
|
||||
*/
|
||||
declare function getUserAgent(): AgentName | null;
|
||||
/**
|
||||
* Detects the package manager used in the project.
|
||||
* @param options {DetectOptions} The options to use when detecting the package manager.
|
||||
* @returns {Promise<DetectResult | null>} The detected package manager or `null` if not found.
|
||||
*/
|
||||
declare function detect(options?: DetectOptions): Promise<DetectResult | null>;
|
||||
|
||||
export { detect, getUserAgent };
|
132
node_modules/package-manager-detector/dist/detect.mjs
generated
vendored
Normal file
132
node_modules/package-manager-detector/dist/detect.mjs
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { INSTALL_METADATA, LOCKS, AGENTS } from './constants.mjs';
|
||||
|
||||
async function pathExists(path2, type) {
|
||||
try {
|
||||
const stat = await fs.stat(path2);
|
||||
return type === "file" ? stat.isFile() : stat.isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getUserAgent() {
|
||||
const userAgent = process.env.npm_config_user_agent;
|
||||
if (!userAgent) {
|
||||
return null;
|
||||
}
|
||||
const name = userAgent.split("/")[0];
|
||||
return AGENTS.includes(name) ? name : null;
|
||||
}
|
||||
function* lookup(cwd = process.cwd()) {
|
||||
let directory = path.resolve(cwd);
|
||||
const { root } = path.parse(directory);
|
||||
while (directory && directory !== root) {
|
||||
yield directory;
|
||||
directory = path.dirname(directory);
|
||||
}
|
||||
}
|
||||
async function parsePackageJson(filepath, onUnknown) {
|
||||
return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
|
||||
}
|
||||
async function detect(options = {}) {
|
||||
const {
|
||||
cwd,
|
||||
strategies = ["lockfile", "packageManager-field", "devEngines-field"],
|
||||
onUnknown
|
||||
} = options;
|
||||
let stopDir;
|
||||
if (typeof options.stopDir === "string") {
|
||||
const resolved = path.resolve(options.stopDir);
|
||||
stopDir = (dir) => dir === resolved;
|
||||
} else {
|
||||
stopDir = options.stopDir;
|
||||
}
|
||||
for (const directory of lookup(cwd)) {
|
||||
for (const strategy of strategies) {
|
||||
switch (strategy) {
|
||||
case "lockfile": {
|
||||
for (const lock of Object.keys(LOCKS)) {
|
||||
if (await pathExists(path.join(directory, lock), "file")) {
|
||||
const name = LOCKS[lock];
|
||||
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
||||
if (result)
|
||||
return result;
|
||||
else
|
||||
return { name, agent: name };
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "packageManager-field":
|
||||
case "devEngines-field": {
|
||||
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
||||
if (result)
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
case "install-metadata": {
|
||||
for (const metadata of Object.keys(INSTALL_METADATA)) {
|
||||
const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
|
||||
if (await pathExists(path.join(directory, metadata), fileOrDir)) {
|
||||
const name = INSTALL_METADATA[metadata];
|
||||
const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
|
||||
return { name, agent };
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stopDir?.(directory))
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getNameAndVer(pkg) {
|
||||
const handelVer = (version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
|
||||
if (typeof pkg.packageManager === "string") {
|
||||
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
||||
return { name, ver: handelVer(ver) };
|
||||
}
|
||||
if (typeof pkg.devEngines?.packageManager?.name === "string") {
|
||||
return {
|
||||
name: pkg.devEngines.packageManager.name,
|
||||
ver: handelVer(pkg.devEngines.packageManager.version)
|
||||
};
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
async function handlePackageManager(filepath, onUnknown) {
|
||||
try {
|
||||
const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
|
||||
let agent;
|
||||
const nameAndVer = getNameAndVer(pkg);
|
||||
if (nameAndVer) {
|
||||
const name = nameAndVer.name;
|
||||
const ver = nameAndVer.ver;
|
||||
let version = ver;
|
||||
if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
|
||||
agent = "yarn@berry";
|
||||
version = "berry";
|
||||
return { name, agent, version };
|
||||
} else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
|
||||
agent = "pnpm@6";
|
||||
return { name, agent, version };
|
||||
} else if (AGENTS.includes(name)) {
|
||||
agent = name;
|
||||
return { name, agent, version };
|
||||
} else {
|
||||
return onUnknown?.(pkg.packageManager) ?? null;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function isMetadataYarnClassic(metadataPath) {
|
||||
return metadataPath.endsWith(".yarn_integrity");
|
||||
}
|
||||
|
||||
export { detect, getUserAgent };
|
4
node_modules/package-manager-detector/dist/index.d.mts
generated
vendored
Normal file
4
node_modules/package-manager-detector/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export { COMMANDS, constructCommand, resolveCommand } from './commands.mjs';
|
||||
export { AGENTS, INSTALL_METADATA, INSTALL_PAGE, LOCKS } from './constants.mjs';
|
||||
export { detect, getUserAgent } from './detect.mjs';
|
||||
export { A as Agent, b as AgentCommandValue, c as AgentCommands, a as AgentName, C as Command, d as DetectOptions, e as DetectResult, D as DetectStrategy, R as ResolvedCommand } from './shared/package-manager-detector.pUYRhiOu.mjs';
|
6
node_modules/package-manager-detector/dist/index.mjs
generated
vendored
Normal file
6
node_modules/package-manager-detector/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export { COMMANDS, constructCommand, resolveCommand } from './commands.mjs';
|
||||
export { AGENTS, INSTALL_METADATA, INSTALL_PAGE, LOCKS } from './constants.mjs';
|
||||
export { detect, getUserAgent } from './detect.mjs';
|
||||
import 'node:fs/promises';
|
||||
import 'node:path';
|
||||
import 'node:process';
|
79
node_modules/package-manager-detector/dist/shared/package-manager-detector.pUYRhiOu.d.mts
generated
vendored
Normal file
79
node_modules/package-manager-detector/dist/shared/package-manager-detector.pUYRhiOu.d.mts
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
type Agent = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'pnpm@6' | 'bun' | 'deno';
|
||||
type AgentName = 'npm' | 'yarn' | 'pnpm' | 'bun' | 'deno';
|
||||
type AgentCommandValue = (string | number)[] | ((args: string[]) => string[]) | null;
|
||||
interface AgentCommands {
|
||||
'agent': AgentCommandValue;
|
||||
'run': AgentCommandValue;
|
||||
'install': AgentCommandValue;
|
||||
'frozen': AgentCommandValue;
|
||||
'global': AgentCommandValue;
|
||||
'add': AgentCommandValue;
|
||||
'upgrade': AgentCommandValue;
|
||||
'upgrade-interactive': AgentCommandValue;
|
||||
'execute': AgentCommandValue;
|
||||
'execute-local': AgentCommandValue;
|
||||
'uninstall': AgentCommandValue;
|
||||
'global_uninstall': AgentCommandValue;
|
||||
}
|
||||
type Command = keyof AgentCommands;
|
||||
interface ResolvedCommand {
|
||||
/**
|
||||
* CLI command.
|
||||
*/
|
||||
command: string;
|
||||
/**
|
||||
* Arguments for the CLI command, merged with user arguments.
|
||||
*/
|
||||
args: string[];
|
||||
}
|
||||
type DetectStrategy = 'lockfile' | 'packageManager-field' | 'devEngines-field' | 'install-metadata';
|
||||
interface DetectOptions {
|
||||
/**
|
||||
* Current working directory to start looking up for package manager.
|
||||
* @default `process.cwd()`
|
||||
*/
|
||||
cwd?: string;
|
||||
/**
|
||||
* The strategies to use for detecting the package manager. The strategies
|
||||
* are executed in the order it's specified for every directory that it iterates
|
||||
* upwards from the `cwd`.
|
||||
*
|
||||
* - `'lockfile'`: Look up for lock files.
|
||||
* - `'packageManager-field'`: Look up for the `packageManager` field in package.json.
|
||||
* - `'devEngines-field'`: Look up for the `devEngines.packageManager` field in package.json.
|
||||
* - `'install-metadata'`: Look up for installation metadata added by package managers.
|
||||
*
|
||||
* @default ['lockfile', 'packageManager-field', 'devEngines-field']
|
||||
*/
|
||||
strategies?: DetectStrategy[];
|
||||
/**
|
||||
* Callback when unknown package manager from package.json.
|
||||
* @param packageManager - The `packageManager` value from package.json file.
|
||||
*/
|
||||
onUnknown?: (packageManager: string) => DetectResult | null | undefined;
|
||||
/**
|
||||
* The path to stop traversing up the directory.
|
||||
*/
|
||||
stopDir?: string | ((currentDir: string) => boolean);
|
||||
}
|
||||
interface DetectResult {
|
||||
/**
|
||||
* Agent name without the specifier.
|
||||
*
|
||||
* Can be `npm`, `yarn`, `pnpm`, `bun`, or `deno`.
|
||||
*/
|
||||
name: AgentName;
|
||||
/**
|
||||
* Agent specifier to resolve the command.
|
||||
*
|
||||
* May contain '@' to differentiate the version (e.g. 'yarn@berry').
|
||||
* Use `name` for the agent name without the specifier.
|
||||
*/
|
||||
agent: Agent;
|
||||
/**
|
||||
* Specific version of the agent, read from `packageManager` field in package.json.
|
||||
*/
|
||||
version?: string;
|
||||
}
|
||||
|
||||
export type { Agent as A, Command as C, DetectStrategy as D, ResolvedCommand as R, AgentName as a, AgentCommandValue as b, AgentCommands as c, DetectOptions as d, DetectResult as e };
|
Reference in New Issue
Block a user