Skip to content

Commit

Permalink
fix: packing the same file twice during publish (#7250)
Browse files Browse the repository at this point in the history
close #6997
  • Loading branch information
zkochan committed Oct 27, 2023
1 parent 8abd9be commit 5003636
Show file tree
Hide file tree
Showing 20 changed files with 838 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-mirrors-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/fs.packlist": major
---

Initial release.
10 changes: 10 additions & 0 deletions .changeset/rich-coins-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@pnpm/plugin-commands-publishing": patch
"@pnpm/plugin-commands-patching": patch
"@pnpm/directory-fetcher": patch
"pnpm": patch
---

`pnpm publish` should not pack the same file twice sometimes [#6997](https://github.com/pnpm/pnpm/issues/6997).

The fix was to update `npm-packlist` to the latest version.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"noproxy",
"nosystem",
"nothrow",
"npmcli",
"npmignore",
"npmjs",
"ofjergrg",
Expand Down
5 changes: 2 additions & 3 deletions fetching/directory-fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
},
"dependencies": {
"@pnpm/fetcher-base": "workspace:*",
"@pnpm/fs.packlist": "workspace:*",
"@pnpm/read-project-manifest": "workspace:*",
"@pnpm/resolver-base": "workspace:*",
"@pnpm/types": "workspace:*",
"npm-packlist": "^5.1.3"
"@pnpm/types": "workspace:*"
},
"devDependencies": {
"@pnpm/directory-fetcher": "workspace:*",
"@pnpm/test-fixtures": "workspace:*",
"@types/npm-packlist": "^3.0.0",
"@zkochan/rimraf": "^2.1.3"
},
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions fetching/directory-fetcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { promises as fs, type Stats } from 'fs'
import path from 'path'
import type { DirectoryFetcher, DirectoryFetcherOptions } from '@pnpm/fetcher-base'
import { logger } from '@pnpm/logger'
import { packlist } from '@pnpm/fs.packlist'
import { safeReadProjectManifestOnly } from '@pnpm/read-project-manifest'
import { type DependencyManifest } from '@pnpm/types'
import packlist from 'npm-packlist'

const directoryFetcherLogger = logger('directory-fetcher')

Expand Down Expand Up @@ -128,7 +128,7 @@ async function fetchPackageFilesFromDir (
dir: string,
opts: FetchFromDirOpts
) {
const files = await packlist({ path: dir })
const files = await packlist(dir)
const filesIndex: Record<string, string> = Object.fromEntries(files.map((file) => [file, path.join(dir, file)]))
let manifest: DependencyManifest | undefined
if (opts.readManifest) {
Expand Down
3 changes: 3 additions & 0 deletions fetching/directory-fetcher/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{
"path": "../../__utils__/test-fixtures"
},
{
"path": "../../fs/packlist"
},
{
"path": "../../packages/types"
},
Expand Down
25 changes: 25 additions & 0 deletions fs/packlist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @pnpm/fs.packlist

> Get a list of the files to add from a directory into an npm package
<!--@shields('npm')-->
[![npm version](https://img.shields.io/npm/v/packlist.svg)](https://www.npmjs.com/package/@pnpm/fs.packlist)
<!--/@-->

## Installation

```sh
pnpm add @pnpm/fs.packlist
```

## Usage

```js
const { packlist } = require('path')

const files = packlist('/package-dir')
```

## License

MIT © [Zoltan Kochan](https://www.kochan.io)
42 changes: 42 additions & 0 deletions fs/packlist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@pnpm/fs.packlist",
"version": "0.0.0",
"description": "Get a list of the files to add from a directory into an npm package",
"main": "lib/index.js",
"files": [
"lib",
"!*.map"
],
"types": "lib/index.d.ts",
"scripts": {
"lint": "eslint \"src/**/*.ts\"",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix",
"test": "pnpm run compile"
},
"repository": "https://github.com/pnpm/pnpm/blob/main/fs/packlist",
"keywords": [
"pnpm8"
],
"engines": {
"node": ">=16.14"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/pnpm/issues"
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/fs/packlist#readme",
"dependencies": {
"@npmcli/arborist": "7.2.0",
"npm-packlist": "^8.0.0"
},
"funding": "https://opencollective.com/pnpm",
"devDependencies": {
"@pnpm/fs.packlist": "workspace:*",
"@types/npm-packlist": "^7.0.2",
"@types/npmcli__arborist": "5.6.4"
},
"exports": {
".": "./lib/index.js"
}
}
8 changes: 8 additions & 0 deletions fs/packlist/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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)
}
13 changes: 13 additions & 0 deletions fs/packlist/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@pnpm/tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": [
"src/**/*.ts",
"../../__typings__/**/*.d.ts"
],
"references": [],
"composite": true
}
8 changes: 8 additions & 0 deletions fs/packlist/tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"test/**/*.ts",
"../../__typings__/**/*.d.ts"
]
}
3 changes: 1 addition & 2 deletions patching/plugin-commands-patching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@pnpm/registry-mock": "3.16.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/normalize-path": "^3.0.1",
"@types/npm-packlist": "^3.0.0",
"@types/ramda": "0.28.20",
"@types/semver": "7.5.3",
"write-yaml-file": "^5.0.0"
Expand All @@ -47,6 +46,7 @@
"@pnpm/config": "workspace:*",
"@pnpm/constants": "workspace:*",
"@pnpm/error": "workspace:*",
"@pnpm/fs.packlist": "workspace:*",
"@pnpm/lockfile-file": "workspace:*",
"@pnpm/lockfile-utils": "workspace:*",
"@pnpm/modules-yaml": "workspace:*",
Expand All @@ -62,7 +62,6 @@
"escape-string-regexp": "^4.0.0",
"fast-glob": "^3.3.1",
"normalize-path": "^3.0.0",
"npm-packlist": "^5.1.3",
"ramda": "npm:@pnpm/ramda@0.28.1",
"realpath-missing": "^1.1.0",
"render-help": "^1.0.3",
Expand Down
4 changes: 2 additions & 2 deletions patching/plugin-commands-patching/src/patchCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path'
import { docsUrl } from '@pnpm/cli-utils'
import { type Config, types as allTypes } from '@pnpm/config'
import { packlist } from '@pnpm/fs.packlist'
import { install } from '@pnpm/plugin-commands-installation'
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
Expand All @@ -15,7 +16,6 @@ import renderHelp from 'render-help'
import tempy from 'tempy'
import { writePackage } from './writePackage'
import { type ParseWantedDependencyResult, parseWantedDependency } from '@pnpm/parse-wanted-dependency'
import packlist from 'npm-packlist'
import { type GetPatchedDependencyOptions, getVersionsFromLockfile } from './getPatchedDependency'

export const rcOptionsTypes = cliOptionsTypes
Expand Down Expand Up @@ -157,7 +157,7 @@ function removeTrailingAndLeadingSlash (p: string) {
* This is required in order for the diff to not include files that are not part of the package.
*/
async function preparePkgFilesForDiff (src: string): Promise<string> {
const files = Array.from(new Set((await packlist({ path: src })).map((f) => path.join(f))))
const files = Array.from(new Set((await packlist(src)).map((f) => path.join(f))))
// If there are no extra files in the source directories, then there is no reason
// to copy.
if (await areAllFilesInPkg(files, src)) {
Expand Down
3 changes: 3 additions & 0 deletions patching/plugin-commands-patching/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
{
"path": "../../fetching/pick-fetcher"
},
{
"path": "../../fs/packlist"
},
{
"path": "../../lockfile/lockfile-file"
},
Expand Down

0 comments on commit 5003636

Please sign in to comment.