Skip to content

Commit

Permalink
Merge 7cb461e into 843e8d3
Browse files Browse the repository at this point in the history
  • Loading branch information
yaodingyd committed Jun 20, 2020
2 parents 843e8d3 + 7cb461e commit dca5248
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 63 deletions.
5 changes: 1 addition & 4 deletions packages/modules-cleaner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
49 changes: 2 additions & 47 deletions packages/modules-cleaner/src/removeDirectDependency.ts
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
}
5 changes: 1 addition & 4 deletions packages/modules-cleaner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions packages/remove-bins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @pnpm/remove-bins

> Remove bins from ./bin
## Install

```
pnpm install @pnpm/remove-bins
```

## API

### `remove(...args)`

### `removeBins(...args)`

## License

MIT
46 changes: 46 additions & 0 deletions packages/remove-bins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@pnpm/remove-bins",
"version": "0.0.0",
"description": "Remove bins from .bin",
"author": "Zoltan Kochan <z@kochan.io> (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"
}
6 changes: 6 additions & 0 deletions packages/remove-bins/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { remove, removeBins } from './removeBins'

export {
remove,
removeBins,
}
50 changes: 50 additions & 0 deletions packages/remove-bins/src/removeBins.ts
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions packages/remove-bins/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions packages/supi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/supi/src/install/extendInstallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface StrictInstallOptions {
forceShamefullyHoist: boolean,

global: boolean,
globalBin: string,
}

export type InstallOptions = Partial<StrictInstallOptions> &
Expand Down
4 changes: 4 additions & 0 deletions packages/supi/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions packages/supi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
{
"path": "../read-project-manifest"
},
{
"path": "../remove-bins"
},
{
"path": "../resolve-dependencies"
},
Expand Down
34 changes: 26 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dca5248

Please sign in to comment.