Skip to content

Commit 613d2b8

Browse files
chore(release): 🔧 remove @release-it-plugins/workspaces and refactor workspace publish flow
* Remove `@release-it-plugins/workspaces` from dependencies and release-it config. * Refactor `publish-workspace.js` to handle publishing directly, using CLI args for dry-run detection. * Update release workflow to use `npm run release:ci` and call the custom publish script after npm release. * Simplify and streamline workspace publishing logic for maintainability. Signed-off-by: Justin Wiegmann <wiegmann@e-spirit.com>
1 parent e785a65 commit 613d2b8

5 files changed

Lines changed: 25 additions & 212 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3535

3636
- name: Release
37-
run: npm run release
37+
run: npm run release:ci
3838
env:
3939
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.release-it.json‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
"node scripts/sync-workspace-versions.js",
2626
"npm run build"
2727
],
28+
"after:npm:release": [
29+
"node scripts/publish-workspace.js"
30+
],
2831
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
2932
},
3033
"plugins": {
@@ -33,14 +36,6 @@
3336
"infile": "CHANGELOG.md",
3437
"header": "# Changelog\n\nAll notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.",
3538
"ignoreRecommendedBump": false
36-
},
37-
"@release-it-plugins/workspaces": {
38-
"workspaces": [
39-
"proxy"
40-
],
41-
"publish": true,
42-
"skipChecks": true,
43-
"publishCommand": "node scripts/publish-workspace.js"
4439
}
4540
}
4641
}

‎package-lock.json‎

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

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
"@commitlint/cli": "^20.1.0",
110110
"@commitlint/config-conventional": "^20.0.0",
111111
"@faker-js/faker": "^9.3.0",
112-
"@release-it-plugins/workspaces": "^5.0.3",
113112
"@release-it/conventional-changelog": "^10.0.2",
114113
"@types/cors": "^2.8.19",
115114
"@types/express": "^5.0.5",

‎scripts/publish-workspace.js‎

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,35 @@
22

33
/**
44
* Custom publish script for workspace packages.
5-
* This script handles the actual npm publish for workspaces,
6-
* and correctly handles dry-run mode by syncing versions first.
5+
* This script handles the actual npm publish for workspaces.
76
*
8-
* Environment variables provided by @release-it-plugins/workspaces:
9-
* - RELEASE_IT_WORKSPACES_PATH_TO_WORKSPACE: relative path to workspace
10-
* - RELEASE_IT_WORKSPACES_TAG: npm dist-tag (e.g., 'latest')
11-
* - RELEASE_IT_WORKSPACES_ACCESS: access level ('public' or 'restricted')
12-
* - RELEASE_IT_WORKSPACES_OTP: one-time password for 2FA (optional)
13-
* - RELEASE_IT_WORKSPACES_DRY_RUN: 'true' if this is a dry run
7+
* Called from release-it after:npm:release hook.
8+
* Uses --dry-run flag from npm command line args if present.
149
*/
1510

1611
const { execSync } = require('child_process');
17-
const fs = require('fs');
1812
const path = require('path');
1913

20-
const workspacePath = process.env.RELEASE_IT_WORKSPACES_PATH_TO_WORKSPACE;
21-
const tag = process.env.RELEASE_IT_WORKSPACES_TAG || 'latest';
22-
const access = process.env.RELEASE_IT_WORKSPACES_ACCESS || 'public';
23-
const otp = process.env.RELEASE_IT_WORKSPACES_OTP;
24-
const isDryRun = process.env.RELEASE_IT_WORKSPACES_DRY_RUN === 'true';
14+
const workspaces = ['proxy'];
15+
const isDryRun = process.argv.includes('--dry-run') || process.env.RELEASE_IT_DRY_RUN === 'true';
2516

26-
if (!workspacePath) {
27-
console.error('Error: RELEASE_IT_WORKSPACES_PATH_TO_WORKSPACE not set');
28-
process.exit(1);
29-
}
30-
31-
// Sync version from root package.json to workspace package.json
32-
// This is needed because in dry-run mode, the after:bump hook doesn't execute
33-
const rootPackagePath = path.join(__dirname, '..', 'package.json');
34-
const workspacePackagePath = path.join(__dirname, '..', workspacePath, 'package.json');
35-
36-
try {
37-
const rootPackage = JSON.parse(fs.readFileSync(rootPackagePath, 'utf8'));
38-
const workspacePackage = JSON.parse(fs.readFileSync(workspacePackagePath, 'utf8'));
17+
workspaces.forEach((workspacePath) => {
18+
const workspacePackagePath = path.join(__dirname, '..', workspacePath, 'package.json');
3919

40-
if (rootPackage.version !== workspacePackage.version) {
41-
console.log(`Syncing version: ${workspacePackage.version} -> ${rootPackage.version}`);
42-
workspacePackage.version = rootPackage.version;
43-
fs.writeFileSync(workspacePackagePath, JSON.stringify(workspacePackage, null, 2) + '\n');
20+
// Build the npm publish command
21+
let command = `npm publish ./${workspacePath} --tag latest --access public`;
22+
if (isDryRun) {
23+
command += ' --dry-run';
4424
}
45-
} catch (error) {
46-
console.error('Error syncing version:', error.message);
47-
process.exit(1);
48-
}
4925

50-
// Build the npm publish command
51-
let command = `npm publish ./${workspacePath} --tag ${tag} --access ${access}`;
52-
if (otp) {
53-
command += ` --otp ${otp}`;
54-
}
55-
if (isDryRun) {
56-
command += ' --dry-run';
57-
}
26+
console.log(`Publishing ${workspacePath}...`);
27+
console.log(`Command: ${command}`);
5828

59-
console.log(`Publishing ${workspacePath}...`);
60-
console.log(`Command: ${command}`);
61-
62-
try {
63-
execSync(command, { stdio: 'inherit' });
64-
console.log(`Successfully published ${workspacePath}`);
65-
} catch (error) {
66-
console.error(`Failed to publish ${workspacePath}:`, error.message);
67-
process.exit(1);
68-
}
29+
try {
30+
execSync(command, { stdio: 'inherit', cwd: path.join(__dirname, '..') });
31+
console.log(`Successfully published ${workspacePath}`);
32+
} catch (error) {
33+
console.error(`Failed to publish ${workspacePath}:`, error.message);
34+
process.exit(1);
35+
}
36+
});

0 commit comments

Comments
 (0)