npm changed the way npm publish
command works. From npm v8.5.0 my previous release setup broke (final version it works - 8.4.1).
When np does command npm publish <np contents folder>
(for instance npm publish ./dist
) it will pack original package.json, readme.md and /dist folder will be packed too, but it will not be flatten as it was before.
npm publish doc:
All files are included by default, with the following exceptions:
Certain files that are relevant to package installation and distribution are always included. For example, package.json, README.md, LICENSE, and so on.
If there is a "files" list in package.json, then only the files specified will be included. (If directories are specified, then they will be walked recursively and their contents included, subject to the same ignore rules.)
If there is a .gitignore or .npmignore file, then ignored files in that and all child directories will be excluded from the package. If both files exist, then the .gitignore is ignored, and only the .npmignore is used.
.npmignore files follow the same pattern rules as .gitignore files
If the file matches certain patterns, then it will never be included, unless explicitly added to the "files" list in package.json, or un-ignored with a ! rule in a .npmignore or .gitignore file.
At the end we got in .tgz:
/package
- package.json - original
- readme.md - original
/dist/
- package.json - modified by np
.... other dist files
0. Setup
package.json
"files": ["./dist/"],
"np": {
"contents": "./dist",
"yolo": true,
"anyBranch": true,
"2fa": false
},
.npmignore
**
!dist/**
1. Your build script should put future package content to /dist
2. Run np npm exec np
or run right away command npm publish ./dist
which will be build and run by np at the end
To test without trying to publish you can also run npm pack
I expect that my package would contain files that specified in "contents" and "files" props of package.json (as it was before npm 8.5).
Also it should not contain original package.json from source, but modified by np clean package.json.
It is not bug of npm because behavior matches with their docs for 8.x =)
If you run npm publish
from /dist
folder it will do it correctly - /dist would become the root of the package and it will contain single package.json fixed by np. So it looks like np (since npm v8.5) should do "cd /dist" before running publish command.
np - 7.6.2
Node.js - v16.13.2
npm - 8.15.0 (problem appeared at v8.5.0)
Git - 2.37.1.windows.1
OS - win 10 / also tested on MacOs
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too