Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original main file included in published package when using publishConfig.main #4195

Closed
popeindustries opened this issue Jan 5, 2022 · 4 comments · Fixed by #7538
Closed

Comments

@popeindustries
Copy link

When using publishConfig.main, it is expected that the original package.json#main file not be included with the published package, but both package.json#main and package.json#publishConfig#main are included in the final tarball.

pnpm version: 6.24.4

Code to reproduce the issue:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.ts",
  "publishConfig": {
    "main": "index.js"
  },
  "files": [
    "index.js"
  ]
}
$ pnpm publish --dry-run

Expected behavior:

test $ pnpm publish --dry-run
npm notice 
npm notice 📦  test@1.0.0
npm notice === Tarball Contents === 
npm notice 0B   index.js    
npm notice 146B package.json
npm notice === Tarball Details === 
npm notice name:          test                                    
npm notice version:       1.0.0                                   
npm notice filename:      test-1.0.0.tgz                          
npm notice package size:  215 B                                   
npm notice unpacked size: 146 B                                   
npm notice shasum:        e8eb81c73d443997932b32e2053f9421084057fd
npm notice integrity:     sha512-jJXoLwzxxTW4M[...]KYv+hLJf40fHg==
npm notice total files:   2                                       
npm notice 
+ test@1.0.0

Actual behavior:

test $ pnpm publish --dry-run
npm notice 
npm notice 📦  test@1.0.0
npm notice === Tarball Contents === 
npm notice 0B   index.js    
npm notice 0B   index.ts                       <--- should not be included!
npm notice 146B package.json
npm notice === Tarball Details === 
npm notice name:          test                                    
npm notice version:       1.0.0                                   
npm notice filename:      test-1.0.0.tgz                          
npm notice package size:  228 B                                   
npm notice unpacked size: 146 B                                   
npm notice shasum:        06ffa8fdb20a358c1a019d732fe9deda672742a0
npm notice integrity:     sha512-IcNX54PNvFF+U[...]2E0kSIKPxzr8Q==
npm notice total files:   3                                       
npm notice 
+ test@1.0.0

Additional information:

npm-packlist, as used here, includes main by default, so specifically ignoring index.ts in this example via package.json#files (or .npmignore) doesn't help.

One approach may be to generate publishManifest before adding the packaged files to specifically enable filtering of package.json#main in cases where it is overridden by package.json#publishConfig#main. I suspect, however, that replacing package.json on disk with the generated exportableManifest before calling npm-packlist would also be an option, and may simplify additional publishConfig edge-case handling.

  • node -v prints: v17.3.0
  • Windows, macOS, or Linux?: macOS
@Caoqingda
Copy link

Caoqingda commented Feb 22, 2022

pnpm version 6.10.0 can ignore index.ts. you can try it.

@harry-gocity
Copy link

Any update on this issue?

chancancode referenced this issue in glimmerjs/glimmer-vm Dec 9, 2023
@NullVoxPopuli
Copy link
Contributor

Just ran in to this a couple weeks ago

@unleashit
Copy link

Same issue with pnpm 8.12.1. Overriding the main field works as expected as far as the exported package.json. But original main file is included in the tar ball (and I'm also using a files property which theoretically should exclude it).

Also tried explicitly adding to an .npmignore, but it still didn't do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants