first commit
This commit is contained in:
2
node_modules/@oclif/core/lib/util/aggregate-flags.d.ts
generated
vendored
Normal file
2
node_modules/@oclif/core/lib/util/aggregate-flags.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { FlagInput, FlagOutput } from '../interfaces/parser';
|
||||
export declare function aggregateFlags<F extends FlagOutput, B extends FlagOutput>(flags: FlagInput<F> | undefined, baseFlags: FlagInput<B> | undefined, enableJsonFlag: boolean | undefined): FlagInput<F>;
|
||||
12
node_modules/@oclif/core/lib/util/aggregate-flags.js
generated
vendored
Normal file
12
node_modules/@oclif/core/lib/util/aggregate-flags.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aggregateFlags = aggregateFlags;
|
||||
const flags_1 = require("../flags");
|
||||
const json = (0, flags_1.boolean)({
|
||||
description: 'Format output as json.',
|
||||
helpGroup: 'GLOBAL',
|
||||
});
|
||||
function aggregateFlags(flags, baseFlags, enableJsonFlag) {
|
||||
const combinedFlags = { ...baseFlags, ...flags };
|
||||
return (enableJsonFlag ? { json, ...combinedFlags } : combinedFlags);
|
||||
}
|
||||
3
node_modules/@oclif/core/lib/util/cache-command.d.ts
generated
vendored
Normal file
3
node_modules/@oclif/core/lib/util/cache-command.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Command } from '../command';
|
||||
import { Plugin as IPlugin } from '../interfaces/plugin';
|
||||
export declare function cacheCommand(uncachedCmd: Command.Class, plugin?: IPlugin, respectNoCacheDefault?: boolean): Promise<Command.Cached>;
|
||||
119
node_modules/@oclif/core/lib/util/cache-command.js
generated
vendored
Normal file
119
node_modules/@oclif/core/lib/util/cache-command.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.cacheCommand = cacheCommand;
|
||||
const aggregate_flags_1 = require("./aggregate-flags");
|
||||
const cache_default_value_1 = require("./cache-default-value");
|
||||
const ensure_arg_object_1 = require("./ensure-arg-object");
|
||||
const util_1 = require("./util");
|
||||
// In order to collect static properties up the inheritance chain, we need to recursively
|
||||
// access the prototypes until there's nothing left. This allows us to combine baseFlags
|
||||
// and flags as well as add in the json flag if enableJsonFlag is enabled.
|
||||
function mergePrototype(result, cmd) {
|
||||
const proto = Object.getPrototypeOf(cmd);
|
||||
const filteredProto = (0, util_1.pickBy)(proto, (v) => v !== undefined);
|
||||
return Object.keys(proto).length > 0 ? mergePrototype({ ...filteredProto, ...result }, proto) : result;
|
||||
}
|
||||
async function cacheFlags(cmdFlags, respectNoCacheDefault) {
|
||||
const promises = Object.entries(cmdFlags).map(async ([name, flag]) => [
|
||||
name,
|
||||
{
|
||||
aliases: flag.aliases,
|
||||
char: flag.char,
|
||||
charAliases: flag.charAliases,
|
||||
combinable: flag.combinable,
|
||||
dependsOn: flag.dependsOn,
|
||||
deprecateAliases: flag.deprecateAliases,
|
||||
deprecated: flag.deprecated,
|
||||
description: flag.description,
|
||||
env: flag.env,
|
||||
exclusive: flag.exclusive,
|
||||
helpGroup: flag.helpGroup,
|
||||
helpLabel: flag.helpLabel,
|
||||
hidden: flag.hidden,
|
||||
name,
|
||||
noCacheDefault: flag.noCacheDefault,
|
||||
relationships: flag.relationships,
|
||||
required: flag.required,
|
||||
summary: flag.summary,
|
||||
...(flag.type === 'boolean'
|
||||
? {
|
||||
allowNo: flag.allowNo,
|
||||
type: flag.type,
|
||||
}
|
||||
: {
|
||||
default: await (0, cache_default_value_1.cacheDefaultValue)(flag, respectNoCacheDefault),
|
||||
delimiter: flag.delimiter,
|
||||
hasDynamicHelp: typeof flag.defaultHelp === 'function',
|
||||
helpValue: flag.helpValue,
|
||||
multiple: flag.multiple,
|
||||
options: flag.options,
|
||||
type: flag.type,
|
||||
}),
|
||||
},
|
||||
]);
|
||||
return Object.fromEntries(await Promise.all(promises));
|
||||
}
|
||||
async function cacheArgs(cmdArgs, respectNoCacheDefault) {
|
||||
const promises = Object.entries(cmdArgs).map(async ([name, arg]) => [
|
||||
name,
|
||||
{
|
||||
default: await (0, cache_default_value_1.cacheDefaultValue)(arg, respectNoCacheDefault),
|
||||
description: arg.description,
|
||||
hidden: arg.hidden,
|
||||
name,
|
||||
noCacheDefault: arg.noCacheDefault,
|
||||
options: arg.options,
|
||||
required: arg.required,
|
||||
},
|
||||
]);
|
||||
return Object.fromEntries(await Promise.all(promises));
|
||||
}
|
||||
async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false) {
|
||||
const cmd = mergePrototype(uncachedCmd, uncachedCmd);
|
||||
// @ts-expect-error because v2 commands have flags stored in _flags
|
||||
const uncachedFlags = cmd.flags ?? cmd._flags;
|
||||
// @ts-expect-error because v2 commands have base flags stored in _baseFlags
|
||||
const uncachedBaseFlags = cmd.baseFlags ?? cmd._baseFlags;
|
||||
const [flags, args] = await Promise.all([
|
||||
cacheFlags((0, aggregate_flags_1.aggregateFlags)(uncachedFlags, uncachedBaseFlags, cmd.enableJsonFlag), respectNoCacheDefault),
|
||||
cacheArgs((0, ensure_arg_object_1.ensureArgObject)(cmd.args), respectNoCacheDefault),
|
||||
]);
|
||||
const stdProperties = {
|
||||
// Replace all spaces in aliases with colons to standardize them.
|
||||
aliases: (cmd.aliases ?? []).map((a) => a.replaceAll(' ', ':')),
|
||||
args,
|
||||
deprecateAliases: cmd.deprecateAliases,
|
||||
deprecationOptions: cmd.deprecationOptions,
|
||||
description: cmd.description,
|
||||
// Support both `examples` and `example` for backwards compatibility.
|
||||
examples: cmd.examples ?? cmd.example,
|
||||
flags,
|
||||
hasDynamicHelp: Object.values(flags).some((f) => f.hasDynamicHelp),
|
||||
hidden: cmd.hidden,
|
||||
hiddenAliases: cmd.hiddenAliases ?? [],
|
||||
id: cmd.id,
|
||||
pluginAlias: plugin && plugin.alias,
|
||||
pluginName: plugin && plugin.name,
|
||||
pluginType: plugin && plugin.type,
|
||||
state: cmd.state,
|
||||
strict: cmd.strict,
|
||||
summary: cmd.summary,
|
||||
usage: cmd.usage,
|
||||
};
|
||||
// do not include these properties in manifest
|
||||
const ignoreCommandProperties = [
|
||||
'plugin',
|
||||
'_flags',
|
||||
'_enableJsonFlag',
|
||||
'_globalFlags',
|
||||
'_baseFlags',
|
||||
'baseFlags',
|
||||
'_--',
|
||||
'_base',
|
||||
];
|
||||
// Add in any additional properties that are not standard command properties.
|
||||
const stdKeysAndIgnored = new Set([...ignoreCommandProperties, ...Object.keys(stdProperties)]);
|
||||
const keysToAdd = Object.keys(cmd).filter((property) => !stdKeysAndIgnored.has(property));
|
||||
const additionalProperties = Object.fromEntries(keysToAdd.map((key) => [key, cmd[key]]));
|
||||
return { ...stdProperties, ...additionalProperties };
|
||||
}
|
||||
2
node_modules/@oclif/core/lib/util/cache-default-value.d.ts
generated
vendored
Normal file
2
node_modules/@oclif/core/lib/util/cache-default-value.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Arg, OptionFlag } from '../interfaces/parser';
|
||||
export declare const cacheDefaultValue: (flagOrArg: Arg<any> | OptionFlag<any>, respectNoCacheDefault: boolean) => Promise<any>;
|
||||
28
node_modules/@oclif/core/lib/util/cache-default-value.js
generated
vendored
Normal file
28
node_modules/@oclif/core/lib/util/cache-default-value.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.cacheDefaultValue = void 0;
|
||||
// when no manifest exists, the default is calculated. This may throw, so we need to catch it
|
||||
const cacheDefaultValue = async (flagOrArg, respectNoCacheDefault) => {
|
||||
if (respectNoCacheDefault && flagOrArg.noCacheDefault)
|
||||
return;
|
||||
// Prefer the defaultHelp function (returns a friendly string for complex types)
|
||||
if (typeof flagOrArg.defaultHelp === 'function') {
|
||||
try {
|
||||
return await flagOrArg.defaultHelp({ flags: {}, options: flagOrArg });
|
||||
}
|
||||
catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if not specified, try the default function
|
||||
if (typeof flagOrArg.default === 'function') {
|
||||
try {
|
||||
return await flagOrArg.default({ flags: {}, options: flagOrArg });
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else {
|
||||
return flagOrArg.default;
|
||||
}
|
||||
};
|
||||
exports.cacheDefaultValue = cacheDefaultValue;
|
||||
18
node_modules/@oclif/core/lib/util/determine-priority.d.ts
generated
vendored
Normal file
18
node_modules/@oclif/core/lib/util/determine-priority.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Command } from '../command';
|
||||
/**
|
||||
* This function is responsible for locating the correct plugin to use for a named command id
|
||||
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
||||
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
||||
* create the same command or command alias.
|
||||
*
|
||||
* In the case of more than one found command, the function will select the command based on the order in which
|
||||
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
||||
* is selected as the command to run.
|
||||
*
|
||||
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
||||
* is present, this function defers to the core plugin.
|
||||
*
|
||||
* If there is not a core plugin command present, this function will return the first
|
||||
* plugin as discovered (will not change the order)
|
||||
*/
|
||||
export declare function determinePriority(plugins: string[], commands: Command.Loadable[]): Command.Loadable;
|
||||
51
node_modules/@oclif/core/lib/util/determine-priority.js
generated
vendored
Normal file
51
node_modules/@oclif/core/lib/util/determine-priority.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.determinePriority = determinePriority;
|
||||
/**
|
||||
* This function is responsible for locating the correct plugin to use for a named command id
|
||||
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
||||
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
||||
* create the same command or command alias.
|
||||
*
|
||||
* In the case of more than one found command, the function will select the command based on the order in which
|
||||
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
||||
* is selected as the command to run.
|
||||
*
|
||||
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
||||
* is present, this function defers to the core plugin.
|
||||
*
|
||||
* If there is not a core plugin command present, this function will return the first
|
||||
* plugin as discovered (will not change the order)
|
||||
*/
|
||||
function determinePriority(plugins, commands) {
|
||||
const commandPlugins = commands.sort((a, b) => {
|
||||
const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
|
||||
const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
|
||||
const aIndex = plugins.indexOf(pluginAliasA);
|
||||
const bIndex = plugins.indexOf(pluginAliasB);
|
||||
// When both plugin types are 'core' plugins sort based on index
|
||||
if (a.pluginType === 'core' && b.pluginType === 'core') {
|
||||
// If b appears first in the pjson.plugins sort it first
|
||||
return aIndex - bIndex;
|
||||
}
|
||||
// if b is a core plugin and a is not sort b first
|
||||
if (b.pluginType === 'core' && a.pluginType !== 'core') {
|
||||
return 1;
|
||||
}
|
||||
// if a is a core plugin and b is not sort a first
|
||||
if (a.pluginType === 'core' && b.pluginType !== 'core') {
|
||||
return -1;
|
||||
}
|
||||
// if a is a jit plugin and b is not sort b first
|
||||
if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
|
||||
return 1;
|
||||
}
|
||||
// if b is a jit plugin and a is not sort a first
|
||||
if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
|
||||
return -1;
|
||||
}
|
||||
// neither plugin is core, so do not change the order
|
||||
return 0;
|
||||
});
|
||||
return commandPlugins[0];
|
||||
}
|
||||
12
node_modules/@oclif/core/lib/util/ensure-arg-object.d.ts
generated
vendored
Normal file
12
node_modules/@oclif/core/lib/util/ensure-arg-object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Command } from '../command';
|
||||
import { ArgInput } from '../interfaces/parser';
|
||||
/**
|
||||
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
||||
* defined args as an array.
|
||||
*
|
||||
* @param args Either an array of args or an object of args
|
||||
* @returns ArgInput
|
||||
*/
|
||||
export declare function ensureArgObject(args?: {
|
||||
[name: string]: Command.Arg.Cached;
|
||||
} | ArgInput | any[]): ArgInput;
|
||||
13
node_modules/@oclif/core/lib/util/ensure-arg-object.js
generated
vendored
Normal file
13
node_modules/@oclif/core/lib/util/ensure-arg-object.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ensureArgObject = ensureArgObject;
|
||||
/**
|
||||
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
||||
* defined args as an array.
|
||||
*
|
||||
* @param args Either an array of args or an object of args
|
||||
* @returns ArgInput
|
||||
*/
|
||||
function ensureArgObject(args) {
|
||||
return (Array.isArray(args) ? (args ?? []).reduce((x, y) => ({ ...x, [y.name]: y }), {}) : args ?? {});
|
||||
}
|
||||
16
node_modules/@oclif/core/lib/util/find-root.d.ts
generated
vendored
Normal file
16
node_modules/@oclif/core/lib/util/find-root.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare function debug(...scope: string[]): (..._: any) => void;
|
||||
/**
|
||||
* Returns the root directory of the plugin.
|
||||
*
|
||||
* It first attempts to use require.resolve to find the plugin root.
|
||||
* If that returns a path, it will `cd` up the file system until if finds the package.json for the plugin
|
||||
* Example: node_modules/@oclif/plugin-version/dist/index.js -> node_modules/@oclif/plugin-version
|
||||
*
|
||||
* If require.resolve throws an error, it will attempt to find the plugin root by traversing the file system.
|
||||
* If we're in a PnP environment (determined by process.versions.pnp), it will use the pnpapi module to
|
||||
* traverse the dependency tree. Otherwise, it will traverse the node_modules until it finds a package.json
|
||||
* with a matching name.
|
||||
*
|
||||
* If no path is found, undefined is returned which will eventually result in a thrown Error from Plugin.
|
||||
*/
|
||||
export declare function findRoot(name: string | undefined, root: string): Promise<string | undefined>;
|
||||
185
node_modules/@oclif/core/lib/util/find-root.js
generated
vendored
Normal file
185
node_modules/@oclif/core/lib/util/find-root.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.debug = debug;
|
||||
exports.findRoot = findRoot;
|
||||
const node_path_1 = require("node:path");
|
||||
const logger_1 = require("../logger");
|
||||
const fs_1 = require("./fs");
|
||||
function debug(...scope) {
|
||||
return (formatter, ...args) => (0, logger_1.getLogger)(['find-root', ...scope].join(':')).debug(formatter, ...args);
|
||||
}
|
||||
// essentially just "cd .."
|
||||
function* up(from) {
|
||||
while ((0, node_path_1.dirname)(from) !== from) {
|
||||
yield from;
|
||||
from = (0, node_path_1.dirname)(from);
|
||||
}
|
||||
yield from;
|
||||
}
|
||||
/**
|
||||
* Return the plugin root directory from a given file. This will `cd` up the file system until it finds
|
||||
* a package.json and then return the dirname of that path.
|
||||
*
|
||||
* Example: node_modules/@oclif/plugin-version/dist/index.js -> node_modules/@oclif/plugin-version
|
||||
*/
|
||||
async function findPluginRoot(root, name) {
|
||||
// If we know the plugin name then we just need to traverse the file
|
||||
// system until we find the directory that matches the plugin name.
|
||||
debug(name ?? 'root-plugin')(`Finding root starting at ${root}`);
|
||||
if (name) {
|
||||
for (const next of up(root)) {
|
||||
if (next.endsWith((0, node_path_1.basename)(name))) {
|
||||
debug(name)('Found root based on plugin name!');
|
||||
return next;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If there's no plugin name (typically just the root plugin), then we need
|
||||
// to traverse the file system until we find a directory with a package.json
|
||||
for (const next of up(root)) {
|
||||
// Skip the bin directory
|
||||
if ((0, node_path_1.basename)((0, node_path_1.dirname)(next)) === 'bin' &&
|
||||
['dev', 'dev.cmd', 'dev.js', 'run', 'run.cmd', 'run.js'].includes((0, node_path_1.basename)(next))) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const cur = (0, node_path_1.join)(next, 'package.json');
|
||||
debug(name ?? 'root-plugin')(`Checking ${cur}`);
|
||||
if (await (0, fs_1.safeReadJson)(cur)) {
|
||||
debug(name ?? 'root-plugin')('Found root by traversing up from starting point!');
|
||||
return (0, node_path_1.dirname)(cur);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Find plugin root directory for plugins installed into node_modules that don't have a `main` or `export`.
|
||||
* This will go up directories until it finds a directory with the plugin installed into it.
|
||||
*
|
||||
* See https://github.com/oclif/config/pull/289#issuecomment-983904051
|
||||
*/
|
||||
async function findRootLegacy(name, root) {
|
||||
debug(name ?? 'root-plugin')('Finding root using legacy method');
|
||||
for (const next of up(root)) {
|
||||
let cur;
|
||||
if (name) {
|
||||
cur = (0, node_path_1.join)(next, 'node_modules', name, 'package.json');
|
||||
if (await (0, fs_1.safeReadJson)(cur))
|
||||
return (0, node_path_1.dirname)(cur);
|
||||
const pkg = await (0, fs_1.safeReadJson)((0, node_path_1.join)(next, 'package.json'));
|
||||
if (pkg?.name === name)
|
||||
return next;
|
||||
}
|
||||
else {
|
||||
cur = (0, node_path_1.join)(next, 'package.json');
|
||||
if (await (0, fs_1.safeReadJson)(cur))
|
||||
return (0, node_path_1.dirname)(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
let pnp;
|
||||
/**
|
||||
* The pnpapi module is only available if running in a pnp environment. Because of that
|
||||
* we have to require it from the plugin.
|
||||
*
|
||||
* Solution taken from here: https://github.com/yarnpkg/berry/issues/1467#issuecomment-642869600
|
||||
*/
|
||||
function maybeRequirePnpApi(root) {
|
||||
if (pnp)
|
||||
return pnp;
|
||||
try {
|
||||
// eslint-disable-next-line n/no-missing-require
|
||||
pnp = require(require.resolve('pnpapi', { paths: [root] }));
|
||||
return pnp;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
const getKey = (locator) => JSON.stringify(locator);
|
||||
const isPeerDependency = (pkg, parentPkg, name) => getKey(pkg?.packageDependencies.get(name)) === getKey(parentPkg?.packageDependencies.get(name));
|
||||
/**
|
||||
* Traverse PnP dependency tree to find plugin root directory.
|
||||
*
|
||||
* Implementation adapted from https://yarnpkg.com/advanced/pnpapi#traversing-the-dependency-tree
|
||||
*/
|
||||
function findPnpRoot(name, root) {
|
||||
maybeRequirePnpApi(root);
|
||||
if (!pnp)
|
||||
return;
|
||||
debug(name)('Finding root for using pnp method');
|
||||
const seen = new Set();
|
||||
const traverseDependencyTree = (locator, parentPkg) => {
|
||||
// Prevent infinite recursion when A depends on B which depends on A
|
||||
const key = getKey(locator);
|
||||
if (seen.has(key))
|
||||
return;
|
||||
const pkg = pnp.getPackageInformation(locator);
|
||||
if (locator.name === name) {
|
||||
return pkg.packageLocation;
|
||||
}
|
||||
seen.add(key);
|
||||
for (const [name, referencish] of pkg.packageDependencies) {
|
||||
// Unmet peer dependencies
|
||||
if (referencish === null)
|
||||
continue;
|
||||
// Avoid iterating on peer dependencies - very expensive
|
||||
if (parentPkg !== null && isPeerDependency(pkg, parentPkg, name))
|
||||
continue;
|
||||
const childLocator = pnp.getLocator(name, referencish);
|
||||
const foundSomething = traverseDependencyTree(childLocator, pkg);
|
||||
if (foundSomething)
|
||||
return foundSomething;
|
||||
}
|
||||
// Important: This `delete` here causes the traversal to go over nodes even
|
||||
// if they have already been traversed in another branch. If you don't need
|
||||
// that, remove this line for a hefty speed increase.
|
||||
seen.delete(key);
|
||||
};
|
||||
// Iterate on each workspace
|
||||
for (const locator of pnp.getDependencyTreeRoots()) {
|
||||
const foundSomething = traverseDependencyTree(locator);
|
||||
if (foundSomething)
|
||||
return foundSomething;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the root directory of the plugin.
|
||||
*
|
||||
* It first attempts to use require.resolve to find the plugin root.
|
||||
* If that returns a path, it will `cd` up the file system until if finds the package.json for the plugin
|
||||
* Example: node_modules/@oclif/plugin-version/dist/index.js -> node_modules/@oclif/plugin-version
|
||||
*
|
||||
* If require.resolve throws an error, it will attempt to find the plugin root by traversing the file system.
|
||||
* If we're in a PnP environment (determined by process.versions.pnp), it will use the pnpapi module to
|
||||
* traverse the dependency tree. Otherwise, it will traverse the node_modules until it finds a package.json
|
||||
* with a matching name.
|
||||
*
|
||||
* If no path is found, undefined is returned which will eventually result in a thrown Error from Plugin.
|
||||
*/
|
||||
async function findRoot(name, root) {
|
||||
if (name) {
|
||||
debug(name)(`Finding root using ${root}`);
|
||||
let pkgPath;
|
||||
try {
|
||||
pkgPath = require.resolve(name, { paths: [root] });
|
||||
debug(name)(`Found starting point with require.resolve`);
|
||||
}
|
||||
catch {
|
||||
debug(name)(`require.resolve could not find plugin starting point`);
|
||||
}
|
||||
if (pkgPath) {
|
||||
const found = await findPluginRoot((0, node_path_1.dirname)(pkgPath), name);
|
||||
if (found) {
|
||||
debug(name)(`Found root at ${found}`);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
const found = process.versions.pnp ? findPnpRoot(name, root) : await findRootLegacy(name, root);
|
||||
debug(name)(found ? `Found root at ${found}` : 'No root found!');
|
||||
return found;
|
||||
}
|
||||
debug('root-plugin')(`Finding root plugin using ${root}`);
|
||||
const found = await findPluginRoot(root);
|
||||
debug('root-plugin')(found ? `Found root at ${found}` : 'No root found!');
|
||||
return found;
|
||||
}
|
||||
35
node_modules/@oclif/core/lib/util/fs.d.ts
generated
vendored
Normal file
35
node_modules/@oclif/core/lib/util/fs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Parser for Args.directory and Flags.directory. Checks that the provided path
|
||||
* exists and is a directory.
|
||||
* @param input flag or arg input
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
export declare const dirExists: (input: string) => Promise<string>;
|
||||
/**
|
||||
* Parser for Args.file and Flags.file. Checks that the provided path
|
||||
* exists and is a file.
|
||||
* @param input flag or arg input
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
export declare const fileExists: (input: string) => Promise<string>;
|
||||
/**
|
||||
* Read a file from disk and cache its contents if in production environment.
|
||||
*
|
||||
* Will throw an error if the file does not exist.
|
||||
*
|
||||
* @param path file path of JSON file
|
||||
* @param useCache if false, ignore cache and read file from disk
|
||||
* @returns <T>
|
||||
*/
|
||||
export declare function readJson<T = unknown>(path: string, useCache?: boolean): Promise<T>;
|
||||
/**
|
||||
* Safely read a file from disk and cache its contents if in production environment.
|
||||
*
|
||||
* Will return undefined if the file does not exist.
|
||||
*
|
||||
* @param path file path of JSON file
|
||||
* @param useCache if false, ignore cache and read file from disk
|
||||
* @returns <T> or undefined
|
||||
*/
|
||||
export declare function safeReadJson<T>(path: string, useCache?: boolean): Promise<T | undefined>;
|
||||
export declare function existsSync(path: string): boolean;
|
||||
93
node_modules/@oclif/core/lib/util/fs.js
generated
vendored
Normal file
93
node_modules/@oclif/core/lib/util/fs.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fileExists = exports.dirExists = void 0;
|
||||
exports.readJson = readJson;
|
||||
exports.safeReadJson = safeReadJson;
|
||||
exports.existsSync = existsSync;
|
||||
const node_fs_1 = require("node:fs");
|
||||
const promises_1 = require("node:fs/promises");
|
||||
const util_1 = require("./util");
|
||||
/**
|
||||
* Parser for Args.directory and Flags.directory. Checks that the provided path
|
||||
* exists and is a directory.
|
||||
* @param input flag or arg input
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
const dirExists = async (input) => {
|
||||
let dirStat;
|
||||
try {
|
||||
dirStat = await (0, promises_1.stat)(input);
|
||||
}
|
||||
catch {
|
||||
throw new Error(`No directory found at ${input}`);
|
||||
}
|
||||
if (!dirStat.isDirectory()) {
|
||||
throw new Error(`${input} exists but is not a directory`);
|
||||
}
|
||||
return input;
|
||||
};
|
||||
exports.dirExists = dirExists;
|
||||
/**
|
||||
* Parser for Args.file and Flags.file. Checks that the provided path
|
||||
* exists and is a file.
|
||||
* @param input flag or arg input
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
const fileExists = async (input) => {
|
||||
let fileStat;
|
||||
try {
|
||||
fileStat = await (0, promises_1.stat)(input);
|
||||
}
|
||||
catch {
|
||||
throw new Error(`No file found at ${input}`);
|
||||
}
|
||||
if (!fileStat.isFile()) {
|
||||
throw new Error(`${input} exists but is not a file`);
|
||||
}
|
||||
return input;
|
||||
};
|
||||
exports.fileExists = fileExists;
|
||||
class ProdOnlyCache extends Map {
|
||||
set(key, value) {
|
||||
if ((0, util_1.isProd)() ?? false) {
|
||||
super.set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
const cache = new ProdOnlyCache();
|
||||
/**
|
||||
* Read a file from disk and cache its contents if in production environment.
|
||||
*
|
||||
* Will throw an error if the file does not exist.
|
||||
*
|
||||
* @param path file path of JSON file
|
||||
* @param useCache if false, ignore cache and read file from disk
|
||||
* @returns <T>
|
||||
*/
|
||||
async function readJson(path, useCache = true) {
|
||||
if (useCache && cache.has(path)) {
|
||||
return JSON.parse(cache.get(path));
|
||||
}
|
||||
const contents = await (0, promises_1.readFile)(path, 'utf8');
|
||||
cache.set(path, contents);
|
||||
return JSON.parse(contents);
|
||||
}
|
||||
/**
|
||||
* Safely read a file from disk and cache its contents if in production environment.
|
||||
*
|
||||
* Will return undefined if the file does not exist.
|
||||
*
|
||||
* @param path file path of JSON file
|
||||
* @param useCache if false, ignore cache and read file from disk
|
||||
* @returns <T> or undefined
|
||||
*/
|
||||
async function safeReadJson(path, useCache = true) {
|
||||
try {
|
||||
return await readJson(path, useCache);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
function existsSync(path) {
|
||||
return (0, node_fs_1.existsSync)(path);
|
||||
}
|
||||
3
node_modules/@oclif/core/lib/util/ids.d.ts
generated
vendored
Normal file
3
node_modules/@oclif/core/lib/util/ids.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { type Config } from '../interfaces/config';
|
||||
export declare function toStandardizedId(commandID: string, config: Config): string;
|
||||
export declare function toConfiguredId(commandID: string, config: Config): string;
|
||||
11
node_modules/@oclif/core/lib/util/ids.js
generated
vendored
Normal file
11
node_modules/@oclif/core/lib/util/ids.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toStandardizedId = toStandardizedId;
|
||||
exports.toConfiguredId = toConfiguredId;
|
||||
function toStandardizedId(commandID, config) {
|
||||
return commandID.replaceAll(new RegExp(config.topicSeparator, 'g'), ':');
|
||||
}
|
||||
function toConfiguredId(commandID, config) {
|
||||
const defaultTopicSeparator = ':';
|
||||
return commandID.replaceAll(new RegExp(defaultTopicSeparator, 'g'), config.topicSeparator || defaultTopicSeparator);
|
||||
}
|
||||
18
node_modules/@oclif/core/lib/util/os.d.ts
generated
vendored
Normal file
18
node_modules/@oclif/core/lib/util/os.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Call os.homedir() and return the result
|
||||
*
|
||||
* Wrapping this allows us to stub these in tests since os.homedir() is
|
||||
* non-configurable and non-writable.
|
||||
*
|
||||
* @returns The user's home directory
|
||||
*/
|
||||
export declare function getHomeDir(): string;
|
||||
/**
|
||||
* Call os.platform() and return the result
|
||||
*
|
||||
* Wrapping this allows us to stub these in tests since os.platform() is
|
||||
* non-configurable and non-writable.
|
||||
*
|
||||
* @returns The process' platform
|
||||
*/
|
||||
export declare function getPlatform(): NodeJS.Platform;
|
||||
27
node_modules/@oclif/core/lib/util/os.js
generated
vendored
Normal file
27
node_modules/@oclif/core/lib/util/os.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getHomeDir = getHomeDir;
|
||||
exports.getPlatform = getPlatform;
|
||||
const node_os_1 = require("node:os");
|
||||
/**
|
||||
* Call os.homedir() and return the result
|
||||
*
|
||||
* Wrapping this allows us to stub these in tests since os.homedir() is
|
||||
* non-configurable and non-writable.
|
||||
*
|
||||
* @returns The user's home directory
|
||||
*/
|
||||
function getHomeDir() {
|
||||
return (0, node_os_1.homedir)();
|
||||
}
|
||||
/**
|
||||
* Call os.platform() and return the result
|
||||
*
|
||||
* Wrapping this allows us to stub these in tests since os.platform() is
|
||||
* non-configurable and non-writable.
|
||||
*
|
||||
* @returns The process' platform
|
||||
*/
|
||||
function getPlatform() {
|
||||
return (0, node_os_1.platform)();
|
||||
}
|
||||
7
node_modules/@oclif/core/lib/util/read-pjson.d.ts
generated
vendored
Normal file
7
node_modules/@oclif/core/lib/util/read-pjson.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { PJSON } from '../interfaces';
|
||||
/**
|
||||
* Read the package.json file from a given path and add the oclif config (found by lilconfig) if it exists.
|
||||
*
|
||||
* We can assume that the package.json file exists because the plugin root has already been loaded at this point.
|
||||
*/
|
||||
export declare function readPjson(path: string): Promise<PJSON>;
|
||||
55
node_modules/@oclif/core/lib/util/read-pjson.js
generated
vendored
Normal file
55
node_modules/@oclif/core/lib/util/read-pjson.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readPjson = readPjson;
|
||||
const lilconfig_1 = require("lilconfig");
|
||||
const node_path_1 = require("node:path");
|
||||
const logger_1 = require("../logger");
|
||||
const fs_1 = require("./fs");
|
||||
const debug = (0, logger_1.makeDebug)('read-pjson');
|
||||
/**
|
||||
* Read the package.json file from a given path and add the oclif config (found by lilconfig) if it exists.
|
||||
*
|
||||
* We can assume that the package.json file exists because the plugin root has already been loaded at this point.
|
||||
*/
|
||||
async function readPjson(path) {
|
||||
const pjsonPath = (0, node_path_1.join)(path, 'package.json');
|
||||
if (process.env.OCLIF_DISABLE_RC) {
|
||||
debug('OCLIF_DISABLE_RC is set, skipping rc search');
|
||||
return (0, fs_1.readJson)(pjsonPath);
|
||||
}
|
||||
const pjson = await (0, fs_1.readJson)(pjsonPath);
|
||||
// don't bother with lilconfig if the plugin's package.json already has an oclif config
|
||||
if (pjson.oclif) {
|
||||
debug(`found oclif config in ${pjsonPath}`);
|
||||
return pjson;
|
||||
}
|
||||
debug(`searching for oclif config in ${path}`);
|
||||
const explorer = (0, lilconfig_1.lilconfig)('oclif', {
|
||||
/**
|
||||
* Remove the following from the defaults:
|
||||
* - package.json
|
||||
* - any files under .config/
|
||||
*/
|
||||
searchPlaces: [
|
||||
'.oclifrc',
|
||||
'.oclifrc.json',
|
||||
'.oclifrc.js',
|
||||
'.oclifrc.mjs',
|
||||
'.oclifrc.cjs',
|
||||
'oclif.config.js',
|
||||
'oclif.config.mjs',
|
||||
'oclif.config.cjs',
|
||||
],
|
||||
stopDir: path,
|
||||
});
|
||||
const result = await explorer.search(path);
|
||||
if (!result?.config) {
|
||||
debug(`no oclif config found in ${path}`);
|
||||
return pjson;
|
||||
}
|
||||
debug(`found oclif config for ${path}: %O`, result);
|
||||
return {
|
||||
...pjson,
|
||||
oclif: result?.config ?? {},
|
||||
};
|
||||
}
|
||||
2
node_modules/@oclif/core/lib/util/read-tsconfig.d.ts
generated
vendored
Normal file
2
node_modules/@oclif/core/lib/util/read-tsconfig.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { TSConfig } from '../interfaces';
|
||||
export declare function readTSConfig(root: string, tsconfigName?: string): Promise<TSConfig | undefined>;
|
||||
77
node_modules/@oclif/core/lib/util/read-tsconfig.js
generated
vendored
Normal file
77
node_modules/@oclif/core/lib/util/read-tsconfig.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readTSConfig = readTSConfig;
|
||||
const promises_1 = require("node:fs/promises");
|
||||
const node_path_1 = require("node:path");
|
||||
const warn_1 = require("../errors/warn");
|
||||
const logger_1 = require("../logger");
|
||||
const util_1 = require("./util");
|
||||
const debug = (0, logger_1.makeDebug)('read-tsconfig');
|
||||
function resolve(root, name) {
|
||||
try {
|
||||
return require.resolve(name, { paths: [root] });
|
||||
}
|
||||
catch {
|
||||
// return undefined
|
||||
}
|
||||
}
|
||||
async function upUntil(path, test) {
|
||||
let result;
|
||||
try {
|
||||
result = await test(path);
|
||||
}
|
||||
catch {
|
||||
result = false;
|
||||
}
|
||||
if (result)
|
||||
return path;
|
||||
const parent = (0, node_path_1.dirname)(path);
|
||||
if (parent === path)
|
||||
return;
|
||||
return upUntil(parent, test);
|
||||
}
|
||||
async function readTSConfig(root, tsconfigName = 'tsconfig.json') {
|
||||
const found = [];
|
||||
let typescript;
|
||||
try {
|
||||
typescript = require('typescript');
|
||||
}
|
||||
catch {
|
||||
try {
|
||||
typescript = require(root + '/node_modules/typescript');
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if (!typescript) {
|
||||
(0, warn_1.memoizedWarn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
|
||||
return;
|
||||
}
|
||||
const read = async (path) => {
|
||||
const localRoot = await upUntil(path, async (p) => (await (0, promises_1.readdir)(p)).includes('package.json'));
|
||||
if (!localRoot)
|
||||
return;
|
||||
try {
|
||||
const contents = await (0, promises_1.readFile)(path, 'utf8');
|
||||
const parsed = typescript?.parseConfigFileTextToJson(path, contents).config;
|
||||
found.push(parsed);
|
||||
if (parsed.extends) {
|
||||
if (parsed.extends.startsWith('.')) {
|
||||
const nextPath = resolve(localRoot, parsed.extends);
|
||||
return nextPath ? read(nextPath) : undefined;
|
||||
}
|
||||
const resolved = resolve(localRoot, parsed.extends);
|
||||
if (resolved)
|
||||
return read(resolved);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
};
|
||||
await read((0, node_path_1.join)(root, tsconfigName));
|
||||
return {
|
||||
compilerOptions: (0, util_1.mergeNestedObjects)(found, 'compilerOptions'),
|
||||
'ts-node': (0, util_1.mergeNestedObjects)(found, 'ts-node'),
|
||||
};
|
||||
}
|
||||
23
node_modules/@oclif/core/lib/util/util.d.ts
generated
vendored
Normal file
23
node_modules/@oclif/core/lib/util/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
export declare function pickBy<T extends {
|
||||
[s: string]: T[keyof T];
|
||||
} | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
|
||||
export declare function compact<T>(a: (T | undefined)[]): T[];
|
||||
export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
|
||||
export declare function last<T>(arr?: T[]): T | undefined;
|
||||
type SortTypes = boolean | number | string | undefined;
|
||||
export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
|
||||
export declare function castArray<T>(input?: T | T[]): T[];
|
||||
export declare function isProd(): boolean;
|
||||
export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
|
||||
export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
|
||||
export declare function capitalize(s: string): string;
|
||||
export declare function isTruthy(input: string): boolean;
|
||||
export declare function isNotFalsy(input: string): boolean;
|
||||
export declare function uniq<T>(arr: T[]): T[];
|
||||
export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
||||
[P in keyof T]: T[P];
|
||||
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
||||
[P in keyof T]: TResult;
|
||||
};
|
||||
export declare function mergeNestedObjects(objs: Record<string, any>[], path: string): Record<string, any>;
|
||||
export {};
|
||||
104
node_modules/@oclif/core/lib/util/util.js
generated
vendored
Normal file
104
node_modules/@oclif/core/lib/util/util.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pickBy = pickBy;
|
||||
exports.compact = compact;
|
||||
exports.uniqBy = uniqBy;
|
||||
exports.last = last;
|
||||
exports.sortBy = sortBy;
|
||||
exports.castArray = castArray;
|
||||
exports.isProd = isProd;
|
||||
exports.maxBy = maxBy;
|
||||
exports.sumBy = sumBy;
|
||||
exports.capitalize = capitalize;
|
||||
exports.isTruthy = isTruthy;
|
||||
exports.isNotFalsy = isNotFalsy;
|
||||
exports.uniq = uniq;
|
||||
exports.mapValues = mapValues;
|
||||
exports.mergeNestedObjects = mergeNestedObjects;
|
||||
function pickBy(obj, fn) {
|
||||
return Object.entries(obj).reduce((o, [k, v]) => {
|
||||
if (fn(v))
|
||||
o[k] = v;
|
||||
return o;
|
||||
}, {});
|
||||
}
|
||||
function compact(a) {
|
||||
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
||||
return a.filter((a) => Boolean(a));
|
||||
}
|
||||
function uniqBy(arr, fn) {
|
||||
return arr.filter((a, i) => {
|
||||
const aVal = fn(a);
|
||||
return !arr.some((b, j) => j > i && fn(b) === aVal);
|
||||
});
|
||||
}
|
||||
function last(arr) {
|
||||
if (!arr)
|
||||
return;
|
||||
return arr.at(-1);
|
||||
}
|
||||
function compare(a, b) {
|
||||
a = a === undefined ? 0 : a;
|
||||
b = b === undefined ? 0 : b;
|
||||
if (Array.isArray(a) && Array.isArray(b)) {
|
||||
if (a.length === 0 && b.length === 0)
|
||||
return 0;
|
||||
const diff = compare(a[0], b[0]);
|
||||
if (diff !== 0)
|
||||
return diff;
|
||||
return compare(a.slice(1), b.slice(1));
|
||||
}
|
||||
if (a < b)
|
||||
return -1;
|
||||
if (a > b)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
function sortBy(arr, fn) {
|
||||
return arr.sort((a, b) => compare(fn(a), fn(b)));
|
||||
}
|
||||
function castArray(input) {
|
||||
if (input === undefined)
|
||||
return [];
|
||||
return Array.isArray(input) ? input : [input];
|
||||
}
|
||||
function isProd() {
|
||||
return !['development', 'test'].includes(process.env.NODE_ENV ?? '');
|
||||
}
|
||||
function maxBy(arr, fn) {
|
||||
if (arr.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return arr.reduce((maxItem, i) => {
|
||||
const curr = fn(i);
|
||||
const max = fn(maxItem);
|
||||
return curr > max ? i : maxItem;
|
||||
});
|
||||
}
|
||||
function sumBy(arr, fn) {
|
||||
return arr.reduce((sum, i) => sum + fn(i), 0);
|
||||
}
|
||||
function capitalize(s) {
|
||||
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
|
||||
}
|
||||
function isTruthy(input) {
|
||||
return ['1', 'true', 'y', 'yes'].includes(input.toLowerCase());
|
||||
}
|
||||
function isNotFalsy(input) {
|
||||
return !['0', 'false', 'n', 'no'].includes(input.toLowerCase());
|
||||
}
|
||||
function uniq(arr) {
|
||||
return [...new Set(arr)].sort();
|
||||
}
|
||||
function mapValues(obj, fn) {
|
||||
return Object.entries(obj).reduce((o, [k, v]) => {
|
||||
o[k] = fn(v, k);
|
||||
return o;
|
||||
}, {});
|
||||
}
|
||||
function get(obj, path) {
|
||||
return path.split('.').reduce((o, p) => o?.[p], obj);
|
||||
}
|
||||
function mergeNestedObjects(objs, path) {
|
||||
return Object.fromEntries(objs.flatMap((o) => Object.entries(get(o, path) ?? {})).reverse());
|
||||
}
|
||||
Reference in New Issue
Block a user