diff --git a/packages/modules-cleaner/package.json b/packages/modules-cleaner/package.json index 011eb261c93..c4f4e31c03e 100644 --- a/packages/modules-cleaner/package.json +++ b/packages/modules-cleaner/package.json @@ -31,21 +31,18 @@ "@pnpm/filter-lockfile": "workspace:4.0.3", "@pnpm/lockfile-types": "workspace:2.0.1", "@pnpm/lockfile-utils": "workspace:2.0.14", - "@pnpm/package-bins": "workspace:4.0.6", "@pnpm/pkgid-to-filename": "^3.0.0", "@pnpm/read-modules-dir": "workspace:2.0.1", - "@pnpm/read-package-json": "workspace:3.1.2", + "@pnpm/remove-bins": "workspace:1.0.0", "@pnpm/store-controller-types": "workspace:8.0.1", "@pnpm/types": "workspace:6.1.0", "@zkochan/rimraf": "1.0.0", "dependency-path": "workspace:5.0.1", - "is-windows": "1.0.2", "ramda": "0.27.0" }, "devDependencies": { "@pnpm/logger": "3.2.2", "@pnpm/modules-cleaner": "link:", - "@types/is-windows": "^1.0.0", "@types/ramda": "^0.27.6" }, "bugs": { diff --git a/packages/modules-cleaner/src/removeDirectDependency.ts b/packages/modules-cleaner/src/removeDirectDependency.ts index 1d1ce8abeb5..83888f27b1e 100644 --- a/packages/modules-cleaner/src/removeDirectDependency.ts +++ b/packages/modules-cleaner/src/removeDirectDependency.ts @@ -1,12 +1,8 @@ import { - removalLogger, rootLogger, } from '@pnpm/core-loggers' -import binify from '@pnpm/package-bins' -import { safeReadPackageFromDir } from '@pnpm/read-package-json' -import { DependenciesField, DependencyManifest } from '@pnpm/types' -import rimraf = require('@zkochan/rimraf') -import isWindows = require('is-windows') +import { remove, removeBins } from '@pnpm/remove-bins' +import { DependenciesField } from '@pnpm/types' import path = require('path') export default async function removeDirectDependency ( @@ -42,44 +38,3 @@ export default async function removeDirectDependency ( }) } } - -async function removeOnWin (cmd: string) { - removalLogger.debug(cmd) - await Promise.all([ - rimraf(cmd), - rimraf(`${cmd}.ps1`), - rimraf(`${cmd}.cmd`), - ]) -} - -function removeOnNonWin (p: string) { - removalLogger.debug(p) - return rimraf(p) -} - -const remove = isWindows() ? removeOnWin : removeOnNonWin - -async function removeBins ( - uninstalledPkg: string, - opts: { - dryRun?: boolean, - modulesDir: string, - binsDir: string, - } -) { - const uninstalledPkgPath = path.join(opts.modulesDir, uninstalledPkg) - const uninstalledPkgJson = await safeReadPackageFromDir(uninstalledPkgPath) as DependencyManifest - - if (!uninstalledPkgJson) return - const cmds = await binify(uninstalledPkgJson, uninstalledPkgPath) - - if (!opts.dryRun) { - await Promise.all( - cmds - .map((cmd) => path.join(opts.binsDir, cmd.name)) - .map(remove) - ) - } - - return uninstalledPkgJson -} diff --git a/packages/modules-cleaner/tsconfig.json b/packages/modules-cleaner/tsconfig.json index fbf61664081..caf008f36c5 100644 --- a/packages/modules-cleaner/tsconfig.json +++ b/packages/modules-cleaner/tsconfig.json @@ -21,14 +21,11 @@ { "path": "../lockfile-utils" }, - { - "path": "../package-bins" - }, { "path": "../read-modules-dir" }, { - "path": "../read-package-json" + "path": "../remove-bins" }, { "path": "../store-controller-types" diff --git a/packages/remove-bins/README.md b/packages/remove-bins/README.md new file mode 100644 index 00000000000..b94793e296d --- /dev/null +++ b/packages/remove-bins/README.md @@ -0,0 +1,19 @@ +# @pnpm/remove-bins + +> Remove bins from ./bin + +## Install + +``` +pnpm install @pnpm/remove-bins +``` + +## API + +### `remove(...args)` + +### `removeBins(...args)` + +## License + +MIT diff --git a/packages/remove-bins/package.json b/packages/remove-bins/package.json new file mode 100644 index 00000000000..f8fac457fd3 --- /dev/null +++ b/packages/remove-bins/package.json @@ -0,0 +1,46 @@ +{ + "name": "@pnpm/remove-bins", + "version": "0.0.0", + "description": "Remove bins from .bin", + "author": "Zoltan Kochan (https://www.kochan.io/)", + "main": "lib/index.js", + "typings": "lib/index.d.ts", + "files": [ + "lib", + "!*.map" + ], + "peerDependencies": { + "@pnpm/logger": "^3.1.0" + }, + "keywords": [], + "license": "MIT", + "engines": { + "node": ">=10.13" + }, + "repository": "https://github.com/pnpm/pnpm/blob/master/packages/remove-bins", + "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/remove-bins#readme", + "scripts": { + "start": "pnpm run tsc -- --watch", + "test": "pnpm run compile", + "lint": "tslint -c ../../tslint.json src/**/*.ts test/**/*.ts", + "prepublishOnly": "pnpm run compile", + "compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build" + }, + "dependencies": { + "@pnpm/core-loggers": "workspace:4.1.1", + "@pnpm/package-bins": "workspace:4.0.6", + "@pnpm/read-package-json": "workspace:3.1.2", + "@pnpm/types": "workspace:6.1.0", + "@zkochan/rimraf": "1.0.0", + "is-windows": "1.0.2" + }, + "devDependencies": { + "@pnpm/logger": "3.2.2", + "@types/is-windows": "^1.0.0", + "@types/ramda": "^0.27.6" + }, + "bugs": { + "url": "https://github.com/pnpm/pnpm/issues" + }, + "funding": "https://opencollective.com/pnpm" +} diff --git a/packages/remove-bins/src/index.ts b/packages/remove-bins/src/index.ts new file mode 100644 index 00000000000..2990bd73958 --- /dev/null +++ b/packages/remove-bins/src/index.ts @@ -0,0 +1,6 @@ +import { remove, removeBins } from './removeBins' + +export { + remove, + removeBins, +} diff --git a/packages/remove-bins/src/removeBins.ts b/packages/remove-bins/src/removeBins.ts new file mode 100644 index 00000000000..5b326d24183 --- /dev/null +++ b/packages/remove-bins/src/removeBins.ts @@ -0,0 +1,50 @@ +import { + removalLogger, +} from '@pnpm/core-loggers' +import binify from '@pnpm/package-bins' +import { safeReadPackageFromDir } from '@pnpm/read-package-json' +import { DependencyManifest } from '@pnpm/types' +import rimraf = require('@zkochan/rimraf') +import isWindows = require('is-windows') +import path = require('path') + +async function removeOnWin (cmd: string) { + removalLogger.debug(cmd) + await Promise.all([ + rimraf(cmd), + rimraf(`${cmd}.ps1`), + rimraf(`${cmd}.cmd`), + ]) +} + +function removeOnNonWin (p: string) { + removalLogger.debug(p) + return rimraf(p) +} + +export const remove = isWindows() ? removeOnWin : removeOnNonWin + +export async function removeBins ( + uninstalledPkg: string, + opts: { + dryRun?: boolean, + modulesDir: string, + binsDir: string, + } +) { + const uninstalledPkgPath = path.join(opts.modulesDir, uninstalledPkg) + const uninstalledPkgJson = await safeReadPackageFromDir(uninstalledPkgPath) as DependencyManifest + + if (!uninstalledPkgJson) return + const cmds = await binify(uninstalledPkgJson, uninstalledPkgPath) + + if (!opts.dryRun) { + await Promise.all( + cmds + .map((cmd) => path.join(opts.binsDir, cmd.name)) + .map(remove) + ) + } + + return uninstalledPkgJson +} diff --git a/packages/remove-bins/tsconfig.json b/packages/remove-bins/tsconfig.json new file mode 100644 index 00000000000..63bd189f3ff --- /dev/null +++ b/packages/remove-bins/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "@pnpm/tsconfig", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" + }, + "include": [ + "src/**/*.ts", + "../../typings/**/*.d.ts" + ], + "references": [ + { + "path": "../core-loggers" + }, + { + "path": "../package-bins" + }, + { + "path": "../read-package-json" + }, + { + "path": "../types" + } + ] +} diff --git a/packages/supi/package.json b/packages/supi/package.json index 361c185ad64..c475020b680 100644 --- a/packages/supi/package.json +++ b/packages/supi/package.json @@ -40,6 +40,7 @@ "@pnpm/read-modules-dir": "workspace:2.0.1", "@pnpm/read-package-json": "workspace:3.1.2", "@pnpm/read-project-manifest": "workspace:1.0.8", + "@pnpm/remove-bins": "workspace:1.0.0", "@pnpm/resolve-dependencies": "workspace:16.0.1", "@pnpm/resolver-base": "workspace:7.0.2", "@pnpm/store-controller-types": "workspace:8.0.1", diff --git a/packages/supi/src/install/extendInstallOptions.ts b/packages/supi/src/install/extendInstallOptions.ts index a2e0c7a20f7..c99b77b9f23 100644 --- a/packages/supi/src/install/extendInstallOptions.ts +++ b/packages/supi/src/install/extendInstallOptions.ts @@ -71,6 +71,7 @@ export interface StrictInstallOptions { forceShamefullyHoist: boolean, global: boolean, + globalBin: string, } export type InstallOptions = Partial & diff --git a/packages/supi/src/install/index.ts b/packages/supi/src/install/index.ts index 8dc6b648d98..e1e56cf9b16 100644 --- a/packages/supi/src/install/index.ts +++ b/packages/supi/src/install/index.ts @@ -27,6 +27,7 @@ import { getAllDependenciesFromManifest } from '@pnpm/manifest-utils' import { write as writeModulesYaml } from '@pnpm/modules-yaml' import readModulesDirs from '@pnpm/read-modules-dir' import { safeReadPackageFromDir as safeReadPkgFromDir } from '@pnpm/read-package-json' +import { remove } from '@pnpm/remove-bins' import resolveDependencies, { ResolvedDirectDependency, ResolvedPackage, @@ -304,6 +305,9 @@ export async function mutateModules ( break } case 'unlinkSome': { + if (project.manifest?.name && opts.globalBin) { + await remove(path.join(opts.globalBin, project.manifest?.name)) + } const packagesToInstall: string[] = [] const allDeps = getAllDependenciesFromManifest(project.manifest) for (const depName of project.dependencyNames) { diff --git a/packages/supi/tsconfig.json b/packages/supi/tsconfig.json index d7bd1ac9ca5..9e234b2a95c 100644 --- a/packages/supi/tsconfig.json +++ b/packages/supi/tsconfig.json @@ -78,6 +78,9 @@ { "path": "../read-project-manifest" }, + { + "path": "../remove-bins" + }, { "path": "../resolve-dependencies" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0af82e15665..20e749efcd9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1000,20 +1000,17 @@ importers: '@pnpm/filter-lockfile': 'link:../filter-lockfile' '@pnpm/lockfile-types': 'link:../lockfile-types' '@pnpm/lockfile-utils': 'link:../lockfile-utils' - '@pnpm/package-bins': 'link:../package-bins' '@pnpm/pkgid-to-filename': 3.0.0 '@pnpm/read-modules-dir': 'link:../read-modules-dir' - '@pnpm/read-package-json': 'link:../read-package-json' + '@pnpm/remove-bins': 'link:../remove-bins' '@pnpm/store-controller-types': 'link:../store-controller-types' '@pnpm/types': 'link:../types' '@zkochan/rimraf': 1.0.0 dependency-path: 'link:../dependency-path' - is-windows: 1.0.2 ramda: 0.27.0 devDependencies: '@pnpm/logger': 3.2.2 '@pnpm/modules-cleaner': 'link:' - '@types/is-windows': 1.0.0 '@types/ramda': 0.27.6 specifiers: '@pnpm/core-loggers': 'workspace:4.1.1' @@ -1022,17 +1019,14 @@ importers: '@pnpm/lockfile-utils': 'workspace:2.0.14' '@pnpm/logger': 3.2.2 '@pnpm/modules-cleaner': 'link:' - '@pnpm/package-bins': 'workspace:4.0.6' '@pnpm/pkgid-to-filename': ^3.0.0 '@pnpm/read-modules-dir': 'workspace:2.0.1' - '@pnpm/read-package-json': 'workspace:3.1.2' + '@pnpm/remove-bins': 'workspace:1.0.0' '@pnpm/store-controller-types': 'workspace:8.0.1' '@pnpm/types': 'workspace:6.1.0' - '@types/is-windows': ^1.0.0 '@types/ramda': ^0.27.6 '@zkochan/rimraf': 1.0.0 dependency-path: 'workspace:5.0.1' - is-windows: 1.0.2 ramda: 0.27.0 packages/modules-yaml: dependencies: @@ -2388,6 +2382,28 @@ importers: '@pnpm/normalize-registries': 'workspace:1.0.2' '@pnpm/types': 'workspace:6.1.0' realpath-missing: 1.0.0 + packages/remove-bins: + dependencies: + '@pnpm/core-loggers': 'link:../core-loggers' + '@pnpm/package-bins': 'link:../package-bins' + '@pnpm/read-package-json': 'link:../read-package-json' + '@pnpm/types': 'link:../types' + '@zkochan/rimraf': 1.0.0 + is-windows: 1.0.2 + devDependencies: + '@pnpm/logger': 3.2.2 + '@types/is-windows': 1.0.0 + '@types/ramda': 0.27.6 + specifiers: + '@pnpm/core-loggers': 'workspace:4.1.1' + '@pnpm/logger': 3.2.2 + '@pnpm/package-bins': 'workspace:4.0.6' + '@pnpm/read-package-json': 'workspace:3.1.2' + '@pnpm/types': 'workspace:6.1.0' + '@types/is-windows': ^1.0.0 + '@types/ramda': ^0.27.6 + '@zkochan/rimraf': 1.0.0 + is-windows: 1.0.2 packages/resolve-dependencies: dependencies: '@pnpm/core-loggers': 'link:../core-loggers' @@ -2586,6 +2602,7 @@ importers: '@pnpm/read-modules-dir': 'link:../read-modules-dir' '@pnpm/read-package-json': 'link:../read-package-json' '@pnpm/read-project-manifest': 'link:../read-project-manifest' + '@pnpm/remove-bins': 'link:../remove-bins' '@pnpm/resolve-dependencies': 'link:../resolve-dependencies' '@pnpm/resolver-base': 'link:../resolver-base' '@pnpm/store-controller-types': 'link:../store-controller-types' @@ -2689,6 +2706,7 @@ importers: '@pnpm/read-modules-dir': 'workspace:2.0.1' '@pnpm/read-package-json': 'workspace:3.1.2' '@pnpm/read-project-manifest': 'workspace:1.0.8' + '@pnpm/remove-bins': 'workspace:1.0.0' '@pnpm/resolve-dependencies': 'workspace:16.0.1' '@pnpm/resolver-base': 'workspace:7.0.2' '@pnpm/store-controller-types': 'workspace:8.0.1'