|
2 | 2 |
|
3 | 3 | /** |
4 | 4 | * 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. |
7 | 6 | * |
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. |
14 | 9 | */ |
15 | 10 |
|
16 | 11 | const { execSync } = require('child_process'); |
17 | | -const fs = require('fs'); |
18 | 12 | const path = require('path'); |
19 | 13 |
|
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'; |
25 | 16 |
|
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'); |
39 | 19 |
|
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'; |
44 | 24 | } |
45 | | -} catch (error) { |
46 | | - console.error('Error syncing version:', error.message); |
47 | | - process.exit(1); |
48 | | -} |
49 | 25 |
|
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}`); |
58 | 28 |
|
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