diff --git a/src/_utils.ts b/src/_utils.ts index 45bb86d..67e800f 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -73,7 +73,7 @@ export const NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG = export async function resolveOperationOptions( options: OperationOptions = {}, ): Promise< - NonPartial> & + NonPartial> & Pick & { packageManager: PackageManager; } @@ -96,6 +96,7 @@ export async function resolveOperationOptions( packageManager, dev: options.dev ?? false, workspace: options.workspace, + global: options.global ?? false, }; } diff --git a/src/api.ts b/src/api.ts index d322bae..33c8863 100644 --- a/src/api.ts +++ b/src/api.ts @@ -35,6 +35,7 @@ export async function installDependencies( * @param options.packageManager - The package manager info to use (auto-detected). * @param options.dev - Whether to add the dependency as dev dependency. * @param options.workspace - The name of the workspace to use. + * @param options.global - Whether to run the command in global mode. */ export async function addDependency( name: string | string[], @@ -56,6 +57,7 @@ export async function addDependency( resolvedOptions.packageManager.name === "npm" ? "install" : "add", ...getWorkspaceArgs(resolvedOptions), resolvedOptions.dev ? "-D" : "", + resolvedOptions.global ? "-g" : "", ...names, ] ).filter(Boolean); @@ -75,6 +77,7 @@ export async function addDependency( * @param options.silent - Whether to run the command in silent mode. * @param options.packageManager - The package manager info to use (auto-detected). * @param options.workspace - The name of the workspace to use. + * @param options.global - Whether to run the command in global mode. * */ export async function addDevDependency( @@ -94,6 +97,7 @@ export async function addDevDependency( * @param options.packageManager - The package manager info to use (auto-detected). * @param options.dev - Whether to remove dev dependency. * @param options.workspace - The name of the workspace to use. + * @param options.global - Whether to run the command in global mode. */ export async function removeDependency( name: string, @@ -104,9 +108,15 @@ export async function removeDependency( const args = ( resolvedOptions.packageManager.name === "yarn" ? [ + resolvedOptions.global + ? resolvedOptions.packageManager.majorVersion === "1" + ? "dlx" + : "global" + : "", ...getWorkspaceArgs(resolvedOptions), "remove", resolvedOptions.dev ? "-D" : "", + resolvedOptions.global ? "-g" : "", name, ] : [ @@ -115,6 +125,7 @@ export async function removeDependency( : "remove", ...getWorkspaceArgs(resolvedOptions), resolvedOptions.dev ? "-D" : "", + resolvedOptions.global ? "-g" : "", name, ] ).filter(Boolean); diff --git a/src/cli.ts b/src/cli.ts index 5a0a827..77ae93a 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -34,6 +34,11 @@ const install = defineCommand({ alias: "D", description: "Add as dev dependency", }, + global: { + type: "boolean", + alias: "g", + description: "Add globally", + }, }, run: async ({ args }) => { await (args._.length > 0 diff --git a/src/types.ts b/src/types.ts index 05ff9a1..975c32e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,4 +15,5 @@ export type OperationOptions = { packageManager?: PackageManager | PackageManagerName; dev?: boolean; workspace?: boolean | string; + global?: boolean; };