Skip to content

Commit

Permalink
feat: respect publishCmd also with --snapshot flag
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Apr 9, 2023
1 parent 1fc7156 commit 50521d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ yarn add zx-bulk-release
```shell
GH_TOKEN=ghtoken GH_USER=username NPM_TOKEN=npmtoken npx zx-bulk-release [opts]
```
| Flag | Description | Default |
|------------------------------|----------------------------------------------------------------------------------------|------------------|
| `--ignore` | Packages to ignore: `a, b` | |
| `--include-private` | Include `private` packages | `false` |
| `--concurrency` | `build/publish` threads limit | `os.cpus.length` |
| `--no-build` | Skip `buildCmd` invoke | |
| `--no-npm-fetch` | Disable npm artifacts fetching | |
| `--only-workspace-deps` | Recognize only `workspace:` deps as graph edges | |
| `--dry-run` / `--no-publish` | Disable any publish logic | |
| `--report` | Persist release state to file | |
| `--snapshot` | Disable any publishing steps except of npm and push packages to the `snapshot` channel | |
| `--debug` | Enable [zx](https://github.com/google/zx#verbose) verbose mode | |
| Flag | Description | Default |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------|------------------|
| `--ignore` | Packages to ignore: `a, b` | |
| `--include-private` | Include `private` packages | `false` |
| `--concurrency` | `build/publish` threads limit | `os.cpus.length` |
| `--no-build` | Skip `buildCmd` invoke | |
| `--no-npm-fetch` | Disable npm artifacts fetching | |
| `--only-workspace-deps` | Recognize only `workspace:` deps as graph edges | |
| `--dry-run` / `--no-publish` | Disable any publish logic | |
| `--report` | Persist release state to file | |
| `--snapshot` | Disable any publishing steps except of `npm` and `publishCmd` (if defined), then push packages to the `snapshot` channel | |
| `--debug` | Enable [zx](https://github.com/google/zx#verbose) verbose mode | |

### JS API
```js
Expand Down
5 changes: 1 addition & 4 deletions src/main/js/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ export const fetchManifest = async (pkg, {nothrow} = {}) => {
}

export const npmPublish = async (pkg) => {
const {absPath: cwd, name, version, manifest, manifestPath, manifestRaw, config: {npmPublish, npmRegistry, npmToken, npmConfig} } = pkg
const {absPath: cwd, name, version, manifest, config: {npmPublish, npmRegistry, npmToken, npmConfig} } = pkg

if (manifest.private || npmPublish === false) return

log({pkg})(`publishing npm package ${name} ${version} to ${npmRegistry}`)

await fs.writeJson(manifestPath, manifest, {spaces: 2})

const npmTag = pkg.preversion ? 'snapshot' : 'latest'
const npmrc = await getNpmrc({npmConfig, npmToken, npmRegistry})

await $.o({cwd})`npm publish --no-git-tag-version --registry=${npmRegistry} --userconfig ${npmrc} --tag ${npmTag} --no-workspaces`
await fs.writeFile(manifestPath, manifestRaw, {encoding: 'utf8'})
}

export const getNpmrc = async ({npmConfig, npmToken, npmRegistry}) => {
Expand Down
17 changes: 14 additions & 3 deletions src/main/js/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within
.setStatus('failure')
throw e
} finally {
await unsetUserConfig(cwd)
await clean(cwd, packages)
}
report
.setStatus('success')
Expand Down Expand Up @@ -142,8 +142,13 @@ const publish = memoizeBy(async (pkg, run = runCmd) => within(async () => {
throw new Error('package.json version not synced')
}

await fs.writeJson(pkg.manifestPath, pkg.manifest, {spaces: 2})

if (pkg.context.flags.snapshot) {
await npmPublish(pkg)
await Promise.all([
npmPublish(pkg),
run(pkg, 'publishCmd')
])
} else {
await pushReleaseTag(pkg)
await Promise.all([
Expand All @@ -155,6 +160,12 @@ const publish = memoizeBy(async (pkg, run = runCmd) => within(async () => {
run(pkg, 'publishCmd')
])
}

pkg.published = true
}))

const clean = async (cwd, packages) => {
await unsetUserConfig(cwd)
await Promise.all(Object.values(packages).map(({manifestPath, manifestRaw}) =>
fs.writeFile(manifestPath, manifestRaw, {encoding: 'utf8'})
))
}

0 comments on commit 50521d2

Please sign in to comment.