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

[BUG] npm publish <package-spec> in a workspace is not taking package-spec into account #7726

Closed
2 tasks done
Badisi opened this issue Aug 15, 2024 · 1 comment · Fixed by #7738
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Priority 2 secondary priority issue

Comments

@Badisi
Copy link

Badisi commented Aug 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Considering the following mono-repo workspace:

my-project
├── dist
│   └── a
│       └── src
│       │    ├── file.d.ts
│       │    └── file.js
│       └── package.json # { "name: "a", "version": "1.0.0" }
├── projects
│   └── a
│       └── src
│       │    └── file.ts
│       └── package.json # { "name: "a", "version": "1.0.0" }
└── package.json # { "name: "my-project", "workspaces": [ "projects/a" ] }

When releasing a new project the idea is to:

  1. Set the working-directory to the desired project (ex: cd projects/a)
  2. Build the project into the root dist folder (ex: npm run build)
  3. Publish the project (ex: npm run release which runs npm publish ../../dist/a --access=public)

Issue

When specifying workspaces in the root package.json, the step 3 does not work as expected.

It ignores the <package-spec> parameter completely and publish the files in the current directory instead:

$ npm run release

> a@1.0.0 publish
> npm publish ../../dist/a --dry-run

npm notice
npm notice 📦  a@1.0.0
npm notice Tarball Contents
npm notice 172B package.json
npm notice 0B src/file.ts
npm notice Tarball Details
npm notice name: a
npm notice version: 1.0.0
npm notice filename: a-1.0.0.tgz
...

The <package-spec> parameter has no effect at all. Even a wrong path will not display an error and publish the current directory instead (ex: npm publish ./unknown-dir --dry-run).

Note

The pack command on the contrary is working as expected and ignores the workspace:

$ npm pack ../../dist/a --dry-run

npm warn Ignoring workspaces for specified package(s)
npm notice
npm notice 📦  a@1.0.0
npm notice Tarball Contents
npm notice 44B package.json
npm notice 0B src/file.d.ts
npm notice 0B src/file.js
npm notice Tarball Details
npm notice name: a
npm notice version: 1.0.0
npm notice filename: a-1.0.0.tgz
...

Related

I had opened this issue, 2 years ago, that sounded similar at first, because npm publish <package-spec> was also not working as expected. But after looking at it again, it is the exact same problem, because I'm using cwd to navigate to a project and run the publish from there.

Expected Behavior

I would expect the command npm publish <package-spec> to publish what's located at the given path argument and not what's in the current directory.

Steps To Reproduce

  1. git clone https://github.com/Badisi/issue-npm-publish-with-workspaces-2
  2. npm install
  3. cd projects/a
  4. npm run release

Environment

  • platform: macOS Monterey 12.7.5
  • node: v20.15.1
  • npm: 10.8.2
@Badisi Badisi added Bug thing that needs fixing Needs Triage needs review for next steps labels Aug 15, 2024
Badisi added a commit to Badisi/wdio-harness that referenced this issue Aug 15, 2024
Badisi added a commit to DSI-HUG/ngx-schematics-utilities that referenced this issue Aug 15, 2024
@milaninfy
Copy link
Contributor

I believe this is the same cause/behaviour as mentioned in #5745

@milaninfy milaninfy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Aug 16, 2024
@milaninfy milaninfy self-assigned this Aug 16, 2024
wraithgar pushed a commit that referenced this issue Aug 21, 2024
This PR fixes an issue where the `npm publish` command would fail when
run from within a workspace directory with package-spec

fixes: #7726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants