Skip to content

Commit c03bbe7

Browse files
fix(publish): align package metadata and harden npm publish flow (#47)
Make the npm publish path more reliable by aligning package metadata with the real GitHub repository and adding small publish workflow safeguards. Also: - update `repository.url` to `git+https://github.com/synsoftworksdev/gitrole.git` - update `bugs.url` to `https://github.com/synsoftworksdev/gitrole/issues` - normalize `bin.gitrole` to `dist/cli/index.js` - add publish diagnostics for package name, version, and repository URL - add an npm preflight that skips publish when the exact version already exists - keep tag/version verification, release-confidence tests, dry-run pack, and trusted publishing intact - update package-smoke expectations for the normalized bin path Verified with: - npm run build - npm test - npm run test:release - npm pack --dry-run
1 parent cef0e19 commit c03bbe7

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,35 @@ jobs:
5555
- name: Dry-run pack
5656
run: npm pack --dry-run
5757

58+
- name: Print publish metadata
59+
run: |
60+
PACKAGE_NAME="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).name")"
61+
PACKAGE_VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version")"
62+
REPOSITORY_URL="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).repository.url")"
63+
64+
echo "package name: $PACKAGE_NAME"
65+
echo "package version: $PACKAGE_VERSION"
66+
echo "repository.url: $REPOSITORY_URL"
67+
68+
- name: Check if version is already published
69+
id: npm-version
70+
run: |
71+
PACKAGE_NAME="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).name")"
72+
PACKAGE_VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version")"
73+
74+
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
75+
echo "already_published=true" >> "$GITHUB_OUTPUT"
76+
else
77+
echo "already_published=false" >> "$GITHUB_OUTPUT"
78+
fi
79+
80+
- name: Skip publish when version already exists
81+
if: steps.npm-version.outputs.already_published == 'true'
82+
run: |
83+
PACKAGE_NAME="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).name")"
84+
PACKAGE_VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version")"
85+
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} is already published on npm; skipping publish"
86+
5887
- name: Publish to npm
88+
if: steps.npm-version.outputs.already_published != 'true'
5989
run: npm publish --provenance --access public

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Switch your full git identity in one command.",
55
"type": "module",
66
"bin": {
7-
"gitrole": "./dist/cli/index.js"
7+
"gitrole": "dist/cli/index.js"
88
},
99
"files": [
1010
"dist"
@@ -38,11 +38,11 @@
3838
"license": "MIT",
3939
"repository": {
4040
"type": "git",
41-
"url": "git+https://github.com/synsoftworks/gitrole.git"
41+
"url": "git+https://github.com/synsoftworksdev/gitrole.git"
4242
},
4343
"homepage": "https://docs.gitrole.dev",
4444
"bugs": {
45-
"url": "https://github.com/synsoftworks/gitrole/issues"
45+
"url": "https://github.com/synsoftworksdev/gitrole/issues"
4646
},
4747
"dependencies": {
4848
"chalk": "^5.4.1",

test/e2e/package-smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test('package smoke: npm pack includes the published CLI entrypoint and metadata
6464
assert.equal(packedManifest.name, packageJson.name);
6565
assert.equal(packedManifest.version, packageJson.version);
6666
assert.deepEqual(packedManifest.bin, {
67-
gitrole: './dist/cli/index.js'
67+
gitrole: 'dist/cli/index.js'
6868
});
6969
});
7070

0 commit comments

Comments
 (0)