Skip to content

Commit 6379768

Browse files
refactor(publish): Improve manual tagging (#94)
1 parent ad4a350 commit 6379768

File tree

6 files changed

+13
-22
lines changed

6 files changed

+13
-22
lines changed

bin/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { fileURLToPath, pathToFileURL } from 'node:url'
44
import { createRequire } from 'node:module'
55
import { readFileSync } from 'node:fs'
66
import { dirname, join } from 'node:path'
7-
import chalk from 'chalk'
87
import Liftoff from 'liftoff'
98
import minimist from 'minimist'
109
import v8flags from 'v8flags'
@@ -55,10 +54,9 @@ function checkForConfigFile(configPath) {
5554
if (configPath) return
5655
console.error(
5756
[
58-
chalk.red('No tanstack.config.js file found!'),
57+
'No tanstack.config.js file found!',
5958
'This may be because you\'re not passing the --config or --cwd flags.',
6059
'If you are passing these flags, check that the path is correct.',
61-
'',
6260
'Otherwise, you can create a `tanstack.config.js` file in your project root.',
6361
].join('\n'),
6462
)

docs/publish.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pnpm run tanstack-config publish
2323
To use the TanStack Config programmatically, you can import the `publish` function:
2424

2525
```ts
26-
import { publish } from '@tanstack/config'
26+
import { publish } from '@tanstack/config/publish'
2727

2828
publish({
2929
branchConfigs: configOpts.branchConfigs,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
},
6565
"dependencies": {
6666
"@commitlint/parse": "^19.0.3",
67-
"chalk": "^5.3.0",
6867
"commander": "^12.0.0",
6968
"current-git-branch": "^1.1.0",
7069
"esbuild-register": "^3.5.0",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/publish/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import path from 'node:path'
55
import { execSync } from 'node:child_process'
66
import { existsSync, readdirSync } from 'node:fs'
7-
import chalk from 'chalk'
87
import * as semver from 'semver'
98
import currentGitBranch from 'current-git-branch'
109
import { parse as parseCommit } from '@commitlint/parse'
@@ -62,35 +61,32 @@ export const publish = async (options) => {
6261
let latestTag = /** @type {string} */ ([...tags].pop())
6362

6463
let range = `${latestTag}..HEAD`
65-
// let range = ``;
6664

6765
// If RELEASE_ALL is set via a commit subject or body, all packages will be
6866
// released regardless if they have changed files matching the package srcDir.
6967
let RELEASE_ALL = false
7068

7169
if (!latestTag || tag) {
7270
if (tag) {
71+
if (!semver.valid(tag)) {
72+
throw new Error(`tag '${tag}' is not a semantically valid version`)
73+
}
7374
if (!tag.startsWith('v')) {
74-
throw new Error(
75-
`tag must start with "v", eg. v0.0.0. You supplied ${tag}`,
76-
)
75+
throw new Error(`tag must start with "v" (e.g. v0.0.0). You supplied ${tag}`)
7776
}
78-
console.info(
79-
chalk.yellow(
80-
`Tag is set to ${tag}. This will force release all packages. Publishing...`,
81-
),
82-
)
77+
if (tags.includes(tag)) {
78+
throw new Error(`tag ${tag} has already been released`)
79+
}
80+
console.info(`Tag is set to ${tag}. This will force release all packages. Publishing...`)
8381
RELEASE_ALL = true
8482

8583
// Is it the first release? Is it a major version?
86-
if (!latestTag || (!semver.patch(tag) && !semver.minor(tag))) {
84+
if (!latestTag || (semver.patch(tag) === 0 && semver.minor(tag) === 0)) {
8785
range = `origin/main..HEAD`
8886
latestTag = tag
8987
}
9088
} else {
91-
throw new Error(
92-
'Could not find latest tag! To make a release tag of v0.0.1, run with TAG=v0.0.1',
93-
)
89+
throw new Error('Could not find latest tag! To make a release tag of v0.0.1, run with TAG=v0.0.1')
9490
}
9591
}
9692

src/publish/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type RunOptions = {
4949
branchConfigs: Record<string, BranchConfig>
5050
// List your npm packages here. The first package will be used as the versioner.
5151
packages: Array<Package>
52+
// Path to root directory of your project.
5253
rootDir: string
5354
// The branch to publish. Defaults to the current branch if none supplied.
5455
branch?: string

0 commit comments

Comments
 (0)