@akiojin/gwt 6.27.1 → 6.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/gwt.js CHANGED
@@ -12,61 +12,19 @@ import { dirname, join } from 'path';
12
12
  import { fileURLToPath } from 'url';
13
13
  import { existsSync, createWriteStream, mkdirSync, chmodSync, unlinkSync } from 'fs';
14
14
  import { get } from 'https';
15
+ import {
16
+ REPO,
17
+ getPlatformArtifact,
18
+ getSupportedPlatformKeys,
19
+ getVersionedDownloadUrl,
20
+ } from '../scripts/release-download.js';
15
21
 
16
22
  const __filename = fileURLToPath(import.meta.url);
17
23
  const __dirname = dirname(__filename);
18
24
 
19
- const REPO = 'akiojin/gwt';
20
25
  const BIN_NAME = process.platform === 'win32' ? 'gwt.exe' : 'gwt';
21
26
  const BIN_PATH = join(__dirname, BIN_NAME);
22
27
 
23
- function getPlatformArtifact() {
24
- const platform = process.platform;
25
- const arch = process.arch;
26
-
27
- const mapping = {
28
- 'darwin-x64': 'gwt-macos-x86_64',
29
- 'darwin-arm64': 'gwt-macos-aarch64',
30
- 'linux-x64': 'gwt-linux-x86_64',
31
- 'linux-arm64': 'gwt-linux-aarch64',
32
- 'win32-x64': 'gwt-windows-x86_64.exe',
33
- };
34
-
35
- const key = `${platform}-${arch}`;
36
- return mapping[key];
37
- }
38
-
39
- async function getLatestReleaseUrl(artifact) {
40
- return new Promise((resolve, reject) => {
41
- const options = {
42
- hostname: 'api.github.com',
43
- path: `/repos/${REPO}/releases/latest`,
44
- headers: {
45
- 'User-Agent': 'gwt-wrapper',
46
- 'Accept': 'application/vnd.github.v3+json',
47
- },
48
- };
49
-
50
- get(options, (res) => {
51
- let data = '';
52
- res.on('data', (chunk) => data += chunk);
53
- res.on('end', () => {
54
- try {
55
- const release = JSON.parse(data);
56
- const asset = release.assets?.find(a => a.name === artifact);
57
- if (asset) {
58
- resolve(asset.browser_download_url);
59
- } else {
60
- resolve(`https://github.com/${REPO}/releases/latest/download/${artifact}`);
61
- }
62
- } catch {
63
- resolve(`https://github.com/${REPO}/releases/latest/download/${artifact}`);
64
- }
65
- });
66
- }).on('error', reject);
67
- });
68
- }
69
-
70
28
  async function downloadFile(url, dest) {
71
29
  return new Promise((resolve, reject) => {
72
30
  const file = createWriteStream(dest);
@@ -98,20 +56,17 @@ async function downloadFile(url, dest) {
98
56
  });
99
57
  }
100
58
 
101
- async function downloadBinary() {
59
+ function requirePlatformArtifact() {
102
60
  const artifact = getPlatformArtifact();
103
-
104
61
  if (!artifact) {
105
62
  console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
106
- console.error('Supported platforms: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64');
63
+ console.error(`Supported platforms: ${getSupportedPlatformKeys().join(', ')}`);
107
64
  process.exit(1);
108
65
  }
66
+ return artifact;
67
+ }
109
68
 
110
- console.log(`Downloading gwt binary for ${process.platform}-${process.arch}...`);
111
-
112
- const url = await getLatestReleaseUrl(artifact);
113
- console.log(`Downloading from: ${url}`);
114
-
69
+ async function downloadBinary(url) {
115
70
  if (!existsSync(__dirname)) {
116
71
  mkdirSync(__dirname, { recursive: true });
117
72
  }
@@ -148,12 +103,21 @@ function runBinary() {
148
103
 
149
104
  async function main() {
150
105
  if (!existsSync(BIN_PATH)) {
106
+ const artifact = requirePlatformArtifact();
107
+ let versionedUrl = null;
151
108
  try {
152
- await downloadBinary();
109
+ const resolved = getVersionedDownloadUrl(artifact);
110
+ versionedUrl = resolved.url;
111
+ console.log(`Downloading gwt binary for ${process.platform}-${process.arch}...`);
112
+ console.log(`Downloading from: ${versionedUrl}`);
113
+ await downloadBinary(versionedUrl);
153
114
  } catch (error) {
154
115
  console.error('Failed to download gwt binary:', error.message);
155
116
  console.error('');
156
117
  console.error('You can manually download the binary from:');
118
+ if (versionedUrl) {
119
+ console.error(versionedUrl);
120
+ }
157
121
  console.error(`https://github.com/${REPO}/releases`);
158
122
  console.error('');
159
123
  console.error('Or build from source with: cargo build --release');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akiojin/gwt",
3
- "version": "6.27.1",
3
+ "version": "6.28.1",
4
4
  "description": "Interactive Git worktree manager with Coding Agent selection (Claude Code / Codex CLI / Gemini CLI)",
5
5
  "bin": {
6
6
  "gwt": "bin/gwt.js"
@@ -3,22 +3,23 @@ set -euo pipefail
3
3
 
4
4
  # Git設定(node:22-bookwormにはGitが含まれている)
5
5
  # グローバルGit設定(安全なディレクトリを追加)
6
- git config --global --add safe.directory /gwt
6
+ # Worktreeの.gitがホストパスを参照するため、CWD依存を避けて実行する
7
+ git -C / config --global --add safe.directory /gwt
7
8
 
8
9
  # ユーザー名とメールの設定(環境変数から)
9
10
  if [ -n "${GITHUB_USERNAME:-}" ]; then
10
- git config --global user.name "$GITHUB_USERNAME"
11
+ git -C / config --global user.name "$GITHUB_USERNAME"
11
12
  fi
12
13
 
13
14
  if [ -n "${GIT_USER_EMAIL:-}" ]; then
14
- git config --global user.email "$GIT_USER_EMAIL"
15
+ git -C / config --global user.email "$GIT_USER_EMAIL"
15
16
  fi
16
17
 
17
18
  # Git認証ファイルを環境変数から作成
18
19
  if [ -n "${GITHUB_USERNAME:-}" ] && [ -n "${GITHUB_PERSONAL_ACCESS_TOKEN:-}" ]; then
19
20
  printf '%s\n' "https://${GITHUB_USERNAME}:${GITHUB_PERSONAL_ACCESS_TOKEN}@github.com" > /root/.git-credentials
20
21
  chmod 600 /root/.git-credentials
21
- git config --global credential.helper store
22
+ git -C / config --global credential.helper store
22
23
  fi
23
24
 
24
25
  # GitHub CLIの認証(GITHUB_TOKENが設定されている場合)
@@ -10,16 +10,21 @@ import {
10
10
  mkdirSync,
11
11
  chmodSync,
12
12
  unlinkSync,
13
- readFileSync,
14
13
  } from 'fs';
15
14
  import { dirname, join } from 'path';
16
15
  import { fileURLToPath, pathToFileURL } from 'url';
17
16
  import { get } from 'https';
17
+ import {
18
+ REPO,
19
+ buildReleaseDownloadUrl,
20
+ getPackageVersion,
21
+ getPlatformArtifact,
22
+ getSupportedPlatformKeys,
23
+ } from './release-download.js';
18
24
 
19
25
  const __filename = fileURLToPath(import.meta.url);
20
26
  const __dirname = dirname(__filename);
21
27
 
22
- const REPO = 'akiojin/gwt';
23
28
  const BIN_DIR = join(__dirname, '..', 'bin');
24
29
  const BIN_NAME = process.platform === 'win32' ? 'gwt.exe' : 'gwt';
25
30
  const BIN_PATH = join(BIN_DIR, BIN_NAME);
@@ -33,43 +38,16 @@ const RETRY_CONFIG = {
33
38
 
34
39
  const MAX_REDIRECTS = 5;
35
40
 
36
- function getPlatformArtifact() {
37
- const platform = process.platform;
38
- const arch = process.arch;
39
-
40
- const mapping = {
41
- 'darwin-x64': 'gwt-macos-x86_64',
42
- 'darwin-arm64': 'gwt-macos-aarch64',
43
- 'linux-x64': 'gwt-linux-x86_64',
44
- 'linux-arm64': 'gwt-linux-aarch64',
45
- 'win32-x64': 'gwt-windows-x86_64.exe',
46
- };
47
-
48
- const key = `${platform}-${arch}`;
49
- const artifact = mapping[key];
50
-
41
+ function requirePlatformArtifact() {
42
+ const artifact = getPlatformArtifact();
51
43
  if (!artifact) {
52
- console.error(`Unsupported platform: ${platform}-${arch}`);
53
- console.error('Supported platforms: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64');
44
+ console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
45
+ console.error(`Supported platforms: ${getSupportedPlatformKeys().join(', ')}`);
54
46
  process.exit(1);
55
47
  }
56
-
57
48
  return artifact;
58
49
  }
59
50
 
60
- function getPackageVersion() {
61
- const packagePath = join(__dirname, '..', 'package.json');
62
- const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
63
- if (!pkg.version) {
64
- throw new Error('package.json does not contain a version field');
65
- }
66
- return pkg.version;
67
- }
68
-
69
- function buildReleaseDownloadUrl(version, artifact) {
70
- return `https://github.com/${REPO}/releases/download/v${version}/${artifact}`;
71
- }
72
-
73
51
  function getRetryDelayMs(attempt, config = RETRY_CONFIG) {
74
52
  const delay = config.initialDelayMs * Math.pow(config.backoffFactor, Math.max(0, attempt - 1));
75
53
  return Math.min(delay, config.maxDelayMs);
@@ -226,7 +204,7 @@ async function main() {
226
204
  return;
227
205
  }
228
206
 
229
- const artifact = getPlatformArtifact();
207
+ const artifact = requirePlatformArtifact();
230
208
  let version = 'unknown';
231
209
  console.log(`Downloading gwt binary for ${process.platform}-${process.arch}...`);
232
210
 
@@ -9,6 +9,10 @@ import {
9
9
  isRetryableError,
10
10
  isRetryableStatus,
11
11
  } from './postinstall.js';
12
+ import {
13
+ getPackageVersion,
14
+ getVersionedDownloadUrl,
15
+ } from './release-download.js';
12
16
 
13
17
  test('buildReleaseDownloadUrl uses version tag', () => {
14
18
  const url = buildReleaseDownloadUrl('6.17.0', 'gwt-linux-x86_64');
@@ -55,3 +59,13 @@ test('formatFailureGuidance includes versioned URL and release page', () => {
55
59
  assert.equal(guidance.releasePageUrl, 'https://github.com/akiojin/gwt/releases');
56
60
  assert.equal(guidance.buildCommand, 'cargo build --release');
57
61
  });
62
+
63
+ test('getVersionedDownloadUrl uses package.json version', () => {
64
+ const version = getPackageVersion();
65
+ const result = getVersionedDownloadUrl('gwt-linux-x86_64');
66
+ assert.equal(result.version, version);
67
+ assert.equal(
68
+ result.url,
69
+ `https://github.com/akiojin/gwt/releases/download/v${version}/gwt-linux-x86_64`,
70
+ );
71
+ });
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Shared helpers for resolving gwt release download URLs.
4
+ */
5
+
6
+ import { readFileSync } from 'fs';
7
+ import { dirname, join } from 'path';
8
+ import { fileURLToPath } from 'url';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ const REPO = 'akiojin/gwt';
14
+
15
+ const PLATFORM_ARTIFACTS = [
16
+ ['darwin-x64', 'gwt-macos-x86_64'],
17
+ ['darwin-arm64', 'gwt-macos-aarch64'],
18
+ ['linux-x64', 'gwt-linux-x86_64'],
19
+ ['linux-arm64', 'gwt-linux-aarch64'],
20
+ ['win32-x64', 'gwt-windows-x86_64.exe'],
21
+ ];
22
+
23
+ function getSupportedPlatformKeys() {
24
+ return PLATFORM_ARTIFACTS.map(([key]) => key);
25
+ }
26
+
27
+ function resolvePlatformArtifact(platform = process.platform, arch = process.arch) {
28
+ const key = `${platform}-${arch}`;
29
+ const entry = PLATFORM_ARTIFACTS.find(([platformKey]) => platformKey === key);
30
+ return entry ? entry[1] : null;
31
+ }
32
+
33
+ function getPlatformArtifact() {
34
+ return resolvePlatformArtifact();
35
+ }
36
+
37
+ function getPackageVersion() {
38
+ const packagePath = join(__dirname, '..', 'package.json');
39
+ const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
40
+ if (!pkg.version) {
41
+ throw new Error('package.json does not contain a version field');
42
+ }
43
+ return pkg.version;
44
+ }
45
+
46
+ function buildReleaseDownloadUrl(version, artifact) {
47
+ return `https://github.com/${REPO}/releases/download/v${version}/${artifact}`;
48
+ }
49
+
50
+ function getVersionedDownloadUrl(artifact) {
51
+ const version = getPackageVersion();
52
+ return {
53
+ version,
54
+ url: buildReleaseDownloadUrl(version, artifact),
55
+ };
56
+ }
57
+
58
+ export {
59
+ REPO,
60
+ buildReleaseDownloadUrl,
61
+ getPackageVersion,
62
+ getPlatformArtifact,
63
+ getSupportedPlatformKeys,
64
+ getVersionedDownloadUrl,
65
+ resolvePlatformArtifact,
66
+ };