Skip to content

Commit

Permalink
Fix(Semantic Release): No inclusion of NPM packages based on publishC…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
1aron committed Aug 15, 2023
1 parent 0b22ff1 commit 52444a0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
14 changes: 12 additions & 2 deletions packages/semantic-release-config/configure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const path = require('path')
const releaseRules = require('./rules')
const extend = require('@techor/extend').default
const { explorePackageManager, readPNPMWorkspaces, readWorkspaces, queryWorkspaces } = require('@techor/npm')
const { readJSONFileSync } = require('@techor/fs')
const log = require('@techor/log').default

const defaultConfig = {
branches: [
Expand Down Expand Up @@ -53,8 +56,15 @@ module.exports = (config) => {
}
if (workspaces?.length) {
const resolvedWorkspaces = queryWorkspaces(workspaces)
console.log('Workspaces found:', resolvedWorkspaces)
newConfig.plugins.push(...resolvedWorkspaces.map((eachWorkspace) => ['@semantic-release/npm', { pkgRoot: eachWorkspace }]))
for (const eachWorkspace of resolvedWorkspaces) {
const eachWorkspacePackage = readJSONFileSync(path.join(eachWorkspace, 'package.json'))
if (eachWorkspacePackage?.publishConfig?.access === 'public') {
log.add`Add npm release for **${eachWorkspace}**`
newConfig.plugins.push(['@semantic-release/npm', { pkgRoot: eachWorkspace }])
} else {
log.i`Skip npm release for **${eachWorkspace}**`
}
}
}
return newConfig
}
2 changes: 2 additions & 0 deletions packages/semantic-release-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"dependencies": {
"@techor/extend": "workspace:^",
"@techor/npm": "workspace:^",
"@techor/fs": "workspace:^",
"@techor/log": "workspace:^",
"conventional-changelog-techor": "workspace:^",
"techor-conventional-commits": "workspace:^"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/semantic-release-config/tests/publish/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"workspaces": [
"public",
"restricted"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@tests/semantic-release-config-public",
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@tests/semantic-release-config-restricted",
"publishConfig": {
"access": "restricted"
}
}
10 changes: 10 additions & 0 deletions packages/semantic-release-config/tests/publish/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import configure from '../../configure'

it('only publishs the public packages', () => {
process.chdir(__dirname)
const config: any = configure()
expect(config.plugins.filter((eachPlugin) => eachPlugin[0] === '@semantic-release/npm'))
.toEqual([
["@semantic-release/npm", { "pkgRoot": "public" }]
])
})
20 changes: 13 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52444a0

Please sign in to comment.