token-usage-insights 0.9.2 → 0.9.3

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/README.en.md CHANGED
@@ -614,7 +614,7 @@ Environment variables can control the version and installation paths (all option
614
614
 
615
615
  | Variable | Platforms | Description |
616
616
  | --- | --- | --- |
617
- | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | Release tag to install, such as `v0.9.2`; defaults to `latest` |
617
+ | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | Release tag to install, such as `v0.9.3`; defaults to `latest` |
618
618
  | `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | Installation directory, passed to `install.sh` |
619
619
  | `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | Executable-link directory, passed to `install.sh` |
620
620
 
package/README.ja.md CHANGED
@@ -614,7 +614,7 @@ token-usage-insights
614
614
 
615
615
  | 変数 | 対応プラットフォーム | 説明 |
616
616
  | --- | --- | --- |
617
- | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | `v0.9.2` のようなインストール対象の Release tag。デフォルトは `latest` |
617
+ | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | `v0.9.3` のようなインストール対象の Release tag。デフォルトは `latest` |
618
618
  | `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | `install.sh` に渡すインストールディレクトリ |
619
619
  | `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | `install.sh` に渡す実行ファイルリンクディレクトリ |
620
620
 
package/README.ko.md CHANGED
@@ -614,7 +614,7 @@ token-usage-insights
614
614
 
615
615
  | 변수 | 대상 플랫폼 | 설명 |
616
616
  | --- | --- | --- |
617
- | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 설치할 Release tag(예: `v0.9.2`); 기본값은 `latest` |
617
+ | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 설치할 Release tag(예: `v0.9.3`); 기본값은 `latest` |
618
618
  | `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | `install.sh`에 전달할 설치 디렉터리 |
619
619
  | `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | `install.sh`에 전달할 실행 파일 링크 디렉터리 |
620
620
 
package/README.md CHANGED
@@ -639,7 +639,7 @@ token-usage-insights
639
639
 
640
640
  | 變數 | 適用平台 | 說明 |
641
641
  | --- | --- | --- |
642
- | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 指定要安裝的 Release tag,例如 `v0.9.2`。預設 `latest` |
642
+ | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 指定要安裝的 Release tag,例如 `v0.9.3`。預設 `latest` |
643
643
  | `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | 安裝目錄,會轉交給 `install.sh` |
644
644
  | `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | 執行檔連結目錄,會轉交給 `install.sh` |
645
645
 
package/README.zh-CN.md CHANGED
@@ -614,7 +614,7 @@ token-usage-insights
614
614
 
615
615
  | 变量 | 适用平台 | 说明 |
616
616
  | --- | --- | --- |
617
- | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 指定要安装的 Release tag,例如 `v0.9.2`。默认 `latest` |
617
+ | `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | 指定要安装的 Release tag,例如 `v0.9.3`。默认 `latest` |
618
618
  | `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | 安装目录,会传递给 `install.sh` |
619
619
  | `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | 可执行文件链接目录,会传递给 `install.sh` |
620
620
 
package/npm/install.cjs CHANGED
@@ -110,19 +110,53 @@ function run(command, args, options = {}) {
110
110
  if (result.status !== 0) throw new Error(`命令執行失敗:${command}`);
111
111
  }
112
112
 
113
+ // 以 .NET ZipFile API 解壓,不依賴 Microsoft.PowerShell.Archive 模組:
114
+ // 從 pwsh 7 啟動 npx 時,powershell.exe 會繼承 PowerShell 7 的 PSModulePath,
115
+ // 導致 Expand-Archive 因 PSEdition 檢查而無法自動載入。
116
+ const WINDOWS_ZIP_SCRIPT = [
117
+ "$ErrorActionPreference = 'Stop'",
118
+ 'Add-Type -AssemblyName System.IO.Compression.FileSystem',
119
+ '$root = [System.IO.Path]::GetFullPath($env:TUI_DESTINATION)',
120
+ "if (-not $root.EndsWith([System.IO.Path]::DirectorySeparatorChar)) { $root += [System.IO.Path]::DirectorySeparatorChar }",
121
+ '$zip = [System.IO.Compression.ZipFile]::OpenRead($env:TUI_ARCHIVE)',
122
+ 'try {',
123
+ ' foreach ($entry in $zip.Entries) {',
124
+ ' $target = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($root, $entry.FullName))',
125
+ ' if (-not $target.StartsWith($root, [System.StringComparison]::OrdinalIgnoreCase)) { throw "壓縮包含不安全路徑:$($entry.FullName)" }',
126
+ " if ($entry.FullName.EndsWith('/') -or $entry.FullName.EndsWith('\\')) {",
127
+ ' [System.IO.Directory]::CreateDirectory($target) | Out-Null',
128
+ ' continue',
129
+ ' }',
130
+ ' [System.IO.Directory]::CreateDirectory([System.IO.Path]::GetDirectoryName($target)) | Out-Null',
131
+ ' [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true)',
132
+ ' }',
133
+ '} finally {',
134
+ ' $zip.Dispose()',
135
+ '}',
136
+ ].join('\n');
137
+
138
+ function windowsPowerShellEnvironment(archive, destination, baseEnvironment = process.env) {
139
+ const env = { ...baseEnvironment, TUI_ARCHIVE: archive, TUI_DESTINATION: destination };
140
+ // 移除從 pwsh 7 繼承的 PSModulePath,讓 Windows PowerShell 5.1 使用自身預設模組路徑。
141
+ for (const key of Object.keys(env)) {
142
+ if (key.toLowerCase() === 'psmodulepath') delete env[key];
143
+ }
144
+ return env;
145
+ }
146
+
147
+ function extractWindowsZip(archive, destination) {
148
+ // Windows 10 1803 以後內建 bsdtar(tar.exe),可直接解壓 zip。
149
+ const tar = spawnSync('tar', ['-xf', archive, '-C', destination], { stdio: 'inherit' });
150
+ if (!tar.error && tar.status === 0) return;
151
+ run('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', WINDOWS_ZIP_SCRIPT], {
152
+ env: windowsPowerShellEnvironment(archive, destination),
153
+ });
154
+ }
155
+
113
156
  function extract(archive, destination) {
114
157
  mkdirSync(destination, { recursive: true });
115
158
  if (archive.endsWith('.zip') && process.platform === 'win32') {
116
- run(
117
- 'powershell.exe',
118
- [
119
- '-NoProfile',
120
- '-NonInteractive',
121
- '-Command',
122
- 'Expand-Archive -LiteralPath $env:TUI_ARCHIVE -DestinationPath $env:TUI_DESTINATION -Force',
123
- ],
124
- { env: { ...process.env, TUI_ARCHIVE: archive, TUI_DESTINATION: destination } },
125
- );
159
+ extractWindowsZip(archive, destination);
126
160
  return;
127
161
  }
128
162
  run('tar', [archive.endsWith('.tar.gz') ? '-xzf' : '-xf', archive, '-C', destination]);
@@ -218,6 +252,7 @@ if (require.main === module) {
218
252
 
219
253
  module.exports = {
220
254
  TARGETS,
255
+ WINDOWS_ZIP_SCRIPT,
221
256
  artifactName,
222
257
  cargoTarget,
223
258
  checksumForArtifact,
@@ -229,4 +264,5 @@ module.exports = {
229
264
  releaseBaseUrl,
230
265
  sha256,
231
266
  verifyChecksum,
267
+ windowsPowerShellEnvironment,
232
268
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "token-usage-insights",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Local-first AI coding agent token usage dashboard and CLI",
5
5
  "bin": {
6
6
  "token-usage-insights": "npm/cli.cjs"