-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
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:
- Set the working-directory to the desired project (ex:
cd projects/a) - Build the project into the root
distfolder (ex:npm run build) - Publish the project (ex:
npm run releasewhich runsnpm 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
> [email protected] publish
> npm publish ../../dist/a --dry-run
npm notice
npm notice 📦 [email protected]
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 📦 [email protected]
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
git clone https://github.com/Badisi/issue-npm-publish-with-workspaces-2npm installcd projects/anpm run release
Environment
- platform: macOS Monterey 12.7.5
- node: v20.15.1
- npm: 10.8.2