dhoulb / multi-semantic-release

Proof of concept that wraps semantic-release to work with monorepos.
BSD Zero Clause License
200 stars 37 forks source link

question: how to actually publish multiple packages to npm ? #104

Closed Badisi closed 2 years ago

Badisi commented 2 years ago

Let say I have a workspace with 2 packages (A and B) and I want to release and publish them to npm.

root
└── dist
    ├── A
    └── B
└── projects
    ├── A
    └── B

The documentation of @semantic-release/npm states that pkgRoot should be used to specify the directory path to publish.

As A and B have both different distribution directory paths it was clear that a global configuration file (in the root-level dir) was not appropriate. So I have put a .releaserc.json file in both projects/A and projects/B containing the following:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/npm",
      {
        "pkgRoot": "dist/A" // for A, and "dist/B" for B
      }
    ],
    "@semantic-release/github"
  ]
}

But running MSR in dry-run mode throws the following error :

ENOPKG Missing `package.json` file.
A package.json file (https://docs.npmjs.com/files/package.json) at the root of your project is required to release on npm.

Please follow the npm guideline (https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid package.json file.

[multi-semantic-release]: AggregateError: 
    SemanticReleaseError: Missing `package.json` file.
        at module.exports (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/@semantic-release/npm/lib/get-error.js:6:10)
        at module.exports (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/@semantic-release/npm/lib/get-pkg.js:17:33)
        at async verifyConditions (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/@semantic-release/npm/index.js:32:17)
        at async validator (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
        at async /Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
        at async Promise.all (index 0)
        at async next (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/p-reduce/index.js:16:18)
    at /Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at async Object.pluginsConf.<computed> [as verifyConditions] (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/lib/plugins/index.js:80:11)
    at async run (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/index.js:94:5)
    at async module.exports (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/semantic-release/index.js:258:28)
    at async releasePackage (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/multi-semantic-release/lib/multiSemanticRelease.js:201:15)
    at async Promise.all (index 1)
    at async multiSemanticRelease (/Users/badisi/.npm/_npx/fc5f6a55a6a495a8/node_modules/multi-semantic-release/lib/multiSemanticRelease.js:96:2)

There is a package.json file in root, projects/A, projects/B, dist/A and dist/B folders.

So before further investigating this issue, I was wondering what's the MSR recommendation in such a case ?

Thanks!

Badisi commented 2 years ago

Forget it.. I just found the issue by re-reading my post 😅. Paths are relatives to the .releaserc.json file, not the workspace. So it should be ../../dist/A and ../../dist/B.