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

Publishing of subfolders is broken since npm v8.5 #656

Open
Romanchuk opened this issue Jul 22, 2022 · 2 comments
Open

Publishing of subfolders is broken since npm v8.5 #656

Romanchuk opened this issue Jul 22, 2022 · 2 comments

Comments

@Romanchuk
Copy link

Romanchuk commented Jul 22, 2022

Description

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

Steps to reproduce

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

Expected behavior

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 =)

Additional Notes

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.

Environment

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

@Azumi0
Copy link

Azumi0 commented Nov 30, 2022

I am having the same issue

@Baoyx007
Copy link

same issue

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

No branches or pull requests

4 participants