Skip to content

Commit

Permalink
fix: downgrade npm-packlist to improve performance (#7301)
Browse files Browse the repository at this point in the history
ref #6997
ref #7250
  • Loading branch information
zkochan committed Nov 12, 2023
1 parent fe1f0f7 commit 74432d6
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 690 deletions.
8 changes: 8 additions & 0 deletions .changeset/rude-laws-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@pnpm/fs.packlist": patch
"pnpm": patch
---

Downgraded `npm-packlist` because the newer version significantly slows down the installation of local directory dependencies, making it unbearably slow.

`npm-packlist` was upgraded in [this PR](https://github.com/pnpm/pnpm/pull/7250) to fix [#6997](https://github.com/pnpm/pnpm/issues/6997). We added our own file deduplication to fix the issue of duplicate file entries.
5 changes: 5 additions & 0 deletions __typings__/typed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,8 @@ declare module '@pnpm/npm-conf/lib/types' {
const npmTypes: npmType
export = npmTypes
}

declare module 'npm-packlist' {
function npmPacklist (opts: { path: string }): Promise<string[]>
export = npmPacklist
}
2 changes: 1 addition & 1 deletion fs/packlist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pnpm add @pnpm/fs.packlist
## Usage

```js
const { packlist } = require('path')
const { packlist } = require('@pnpm/fs.packlist')

const files = packlist('/package-dir')
```
Expand Down
7 changes: 2 additions & 5 deletions fs/packlist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/fs/packlist#readme",
"dependencies": {
"@npmcli/arborist": "npm:@pnpm/arborist__fork@7.2.1",
"npm-packlist": "^8.0.0"
"npm-packlist": "5.1.3"
},
"funding": "https://opencollective.com/pnpm",
"devDependencies": {
"@pnpm/fs.packlist": "workspace:*",
"@types/npm-packlist": "^7.0.2",
"@types/npmcli__arborist": "5.6.4"
"@pnpm/fs.packlist": "workspace:*"
},
"exports": {
".": "./lib/index.js"
Expand Down
13 changes: 8 additions & 5 deletions fs/packlist/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Arborist from '@npmcli/arborist'
import npmPacklist from 'npm-packlist'

export async function packlist (pkgDir: string) {
const arborist = new Arborist(({ path: pkgDir }))
const tree = await arborist.loadActual()
return npmPacklist(tree)
export async function packlist (pkgDir: string): Promise<string[]> {
const files = await npmPacklist({ path: pkgDir })
// There's a bug in the npm-packlist version that we use,
// it sometimes returns duplicates.
// Related issue: https://github.com/pnpm/pnpm/issues/6997
// Unfortunately, we cannot upgrade the library
// newer versions of npm-packlist are very slow.
return Array.from(new Set(files.map((file) => file.replace(/^\.[/\\]/, ''))))
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"is-port-reachable",
"load-json-file",
"mem",
"npm-packlist",
"node-fetch",
"normalize-newline",
"p-any",
Expand Down

0 comments on commit 74432d6

Please sign in to comment.