chvm 1.0.5 → 1.0.6

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.
Files changed (90) hide show
  1. package/README.md +7 -7
  2. package/dist/cli.d.ts +7 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/index.d.ts +9 -0
  7. package/dist/commands/index.d.ts.map +1 -0
  8. package/dist/commands/index.js +9 -0
  9. package/dist/commands/index.js.map +1 -0
  10. package/dist/commands/install.d.ts +11 -0
  11. package/dist/commands/install.d.ts.map +1 -0
  12. package/dist/commands/install.js +113 -0
  13. package/dist/commands/install.js.map +1 -0
  14. package/dist/commands/ls.d.ts +10 -0
  15. package/dist/commands/ls.d.ts.map +1 -0
  16. package/dist/commands/ls.js +43 -0
  17. package/dist/commands/ls.js.map +1 -0
  18. package/dist/commands/open.d.ts +10 -0
  19. package/dist/commands/open.d.ts.map +1 -0
  20. package/dist/commands/open.js +86 -0
  21. package/dist/commands/open.js.map +1 -0
  22. package/dist/commands/uninstall.d.ts +10 -0
  23. package/dist/commands/uninstall.d.ts.map +1 -0
  24. package/dist/commands/uninstall.js +65 -0
  25. package/dist/commands/uninstall.js.map +1 -0
  26. package/dist/commands/update.d.ts +10 -0
  27. package/dist/commands/update.d.ts.map +1 -0
  28. package/dist/commands/update.js +64 -0
  29. package/dist/commands/update.js.map +1 -0
  30. package/dist/lib/downloader.d.ts +40 -0
  31. package/dist/lib/downloader.d.ts.map +1 -0
  32. package/dist/lib/downloader.js +98 -0
  33. package/dist/lib/downloader.js.map +1 -0
  34. package/dist/lib/installer.d.ts +13 -0
  35. package/dist/lib/installer.d.ts.map +1 -0
  36. package/dist/lib/installer.js +137 -0
  37. package/dist/lib/installer.js.map +1 -0
  38. package/dist/lib/lock.d.ts +15 -0
  39. package/dist/lib/lock.d.ts.map +1 -0
  40. package/dist/lib/lock.js +66 -0
  41. package/dist/lib/lock.js.map +1 -0
  42. package/dist/lib/logger.d.ts +24 -0
  43. package/dist/lib/logger.d.ts.map +1 -0
  44. package/dist/lib/logger.js +80 -0
  45. package/dist/lib/logger.js.map +1 -0
  46. package/dist/lib/mapping.d.ts +40 -0
  47. package/dist/lib/mapping.d.ts.map +1 -0
  48. package/dist/lib/mapping.js +198 -0
  49. package/dist/lib/mapping.js.map +1 -0
  50. package/dist/lib/platform-check.d.ts +11 -0
  51. package/dist/lib/platform-check.d.ts.map +1 -0
  52. package/dist/lib/platform-check.js +14 -0
  53. package/dist/lib/platform-check.js.map +1 -0
  54. package/dist/lib/storage.d.ts +35 -0
  55. package/dist/lib/storage.d.ts.map +1 -0
  56. package/dist/lib/storage.js +62 -0
  57. package/dist/lib/storage.js.map +1 -0
  58. package/dist/manifest/fetch-revisions.d.ts +2 -0
  59. package/dist/manifest/fetch-revisions.d.ts.map +1 -0
  60. package/dist/manifest/fetch-revisions.js +28 -0
  61. package/dist/manifest/fetch-revisions.js.map +1 -0
  62. package/dist/manifest/fetch-versions.d.ts +2 -0
  63. package/dist/manifest/fetch-versions.d.ts.map +1 -0
  64. package/dist/manifest/fetch-versions.js +39 -0
  65. package/dist/manifest/fetch-versions.js.map +1 -0
  66. package/dist/manifest/generate-manifest.d.ts +2 -0
  67. package/dist/manifest/generate-manifest.d.ts.map +1 -0
  68. package/dist/manifest/generate-manifest.js +81 -0
  69. package/dist/manifest/generate-manifest.js.map +1 -0
  70. package/dist/manifest/shared/constants.d.ts +3 -0
  71. package/dist/manifest/shared/constants.d.ts.map +1 -0
  72. package/dist/manifest/shared/constants.js +3 -0
  73. package/dist/manifest/shared/constants.js.map +1 -0
  74. package/dist/manifest/shared/types.d.ts +27 -0
  75. package/dist/manifest/shared/types.d.ts.map +1 -0
  76. package/dist/manifest/shared/types.js +2 -0
  77. package/dist/manifest/shared/types.js.map +1 -0
  78. package/dist/manifest/split-revisions.d.ts +2 -0
  79. package/dist/manifest/split-revisions.d.ts.map +1 -0
  80. package/dist/manifest/split-revisions.js +60 -0
  81. package/dist/manifest/split-revisions.js.map +1 -0
  82. package/package.json +24 -16
  83. package/src/cli.js +0 -408
  84. package/src/lib/downloader.js +0 -132
  85. package/src/lib/installer.js +0 -159
  86. package/src/lib/lock.js +0 -76
  87. package/src/lib/logger.js +0 -99
  88. package/src/lib/mapping.js +0 -259
  89. package/src/lib/platform-check.js +0 -28
  90. package/src/lib/storage.js +0 -81
@@ -0,0 +1,60 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ const ROOT_PATH = path.join(__dirname, '../../public/manifest/revisions');
4
+ fs.rmSync(ROOT_PATH, { recursive: true, force: true });
5
+ fs.mkdirSync(ROOT_PATH, { recursive: true });
6
+ console.log('loading revisions');
7
+ const revisions = JSON.parse(fs
8
+ .readFileSync(path.resolve(__dirname, '../../public/manifest/revisions.json'))
9
+ .toString());
10
+ const keep = new Set([
11
+ 'chrome-mac.zip',
12
+ 'chrome-android.zip',
13
+ 'chrome-linux.zip',
14
+ 'chrome-android-desktop.zip',
15
+ 'chrome-chromeos.zip',
16
+ 'chrome-win.zip',
17
+ 'chrome-win32.zip',
18
+ ]);
19
+ const processedRevisions = {};
20
+ console.log('processing revisions');
21
+ for (const revision of revisions) {
22
+ const lastPartOfRevisionName = revision.name.split('/').slice(-1)[0];
23
+ if (!keep.has(lastPartOfRevisionName)) {
24
+ continue;
25
+ }
26
+ const platform = (() => {
27
+ const name = revision.name
28
+ .split('/')
29
+ .filter(segment => !/^[0-9]+$/.test(segment))
30
+ .join('/');
31
+ const matchers = {
32
+ 'Android/chrome-android.zip': 'android',
33
+ 'Android_Arm64/chrome-android.zip': 'android_arm64',
34
+ 'Arm/chrome-linux.zip': 'linux_arm',
35
+ 'Linux/chrome-linux.zip': 'linux',
36
+ 'Linux_x64/chrome-linux.zip': 'linux_x64',
37
+ 'Mac/chrome-mac.zip': 'mac',
38
+ 'Mac_Arm/chrome-mac.zip': 'mac_arm',
39
+ 'Win/chrome-win.zip': 'win',
40
+ 'Win/chrome-win32.zip': 'win32',
41
+ 'Win_Arm64/chrome-win.zip': 'win_arm64',
42
+ 'Win_x64/chrome-win.zip': 'win_x64',
43
+ 'Win_x64/chrome-win32.zip': 'win32_x64',
44
+ };
45
+ return matchers[name];
46
+ })();
47
+ if (!platform) {
48
+ continue;
49
+ }
50
+ if (processedRevisions[platform] === undefined) {
51
+ processedRevisions[platform] = [];
52
+ }
53
+ processedRevisions[platform].push(revision);
54
+ }
55
+ console.log('saving revisions');
56
+ for (const platform in processedRevisions) {
57
+ fs.writeFileSync(path.join(ROOT_PATH, `${platform}.json`), JSON.stringify(processedRevisions[platform]));
58
+ }
59
+ console.log('done');
60
+ //# sourceMappingURL=split-revisions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-revisions.js","sourceRoot":"","sources":["../../src/manifest/split-revisions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;AAC1E,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAE7C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAEjC,MAAM,SAAS,GAAe,IAAI,CAAC,KAAK,CACtC,EAAE;KACC,YAAY,CACX,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,sCAAsC,CAAC,CAChE;KACA,QAAQ,EAAE,CACd,CAAC;AAEF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,gBAAgB;IAChB,oBAAoB;IACpB,kBAAkB;IAClB,4BAA4B;IAC5B,qBAAqB;IACrB,gBAAgB;IAChB,kBAAkB;CACnB,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAA+B,EAAE,CAAC;AAE1D,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AACpC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;IACjC,MAAM,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACtC,SAAS;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE;QACrB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI;aACvB,KAAK,CAAC,GAAG,CAAC;aACV,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC5C,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb,MAAM,QAAQ,GAA2B;YACvC,4BAA4B,EAAE,SAAS;YACvC,kCAAkC,EAAE,eAAe;YACnD,sBAAsB,EAAE,WAAW;YACnC,wBAAwB,EAAE,OAAO;YACjC,4BAA4B,EAAE,WAAW;YACzC,oBAAoB,EAAE,KAAK;YAC3B,wBAAwB,EAAE,SAAS;YACnC,oBAAoB,EAAE,KAAK;YAC3B,sBAAsB,EAAE,OAAO;YAC/B,0BAA0B,EAAE,WAAW;YACvC,wBAAwB,EAAE,SAAS;YACnC,0BAA0B,EAAE,WAAW;SACxC,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,SAAS;IACX,CAAC;IAED,IAAI,kBAAkB,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAC/C,kBAAkB,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;IACD,kBAAkB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAChC,KAAK,MAAM,QAAQ,IAAI,kBAAkB,EAAE,CAAC;IAC1C,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,OAAO,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,11 @@
1
1
  {
2
2
  "name": "chvm",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Chrome Version Manager - Manage and run multiple Chromium versions on macOS ARM",
5
5
  "type": "module",
6
- "main": "./src/cli.js",
6
+ "main": "./dist/cli.js",
7
7
  "bin": {
8
- "chvm": "./src/cli.js"
9
- },
10
- "scripts": {
11
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
12
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
13
- "test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch='**/tests/e2e/**/*.test.js'",
14
- "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch='**/tests/unit/**/*.test.js'",
15
- "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage"
8
+ "chvm": "./dist/cli.js"
16
9
  },
17
10
  "keywords": [
18
11
  "chrome",
@@ -28,21 +21,36 @@
28
21
  "node": ">=18.0.0"
29
22
  },
30
23
  "files": [
31
- "src",
24
+ "dist",
32
25
  "README.md",
33
26
  "package.json"
34
27
  ],
35
28
  "dependencies": {
36
29
  "chalk": "^5.3.0",
30
+ "cli-progress": "^3.12.0",
37
31
  "commander": "^11.1.0",
38
32
  "ora": "^7.0.1",
39
- "cli-progress": "^3.12.0",
40
33
  "proper-lockfile": "^4.1.2"
41
34
  },
42
35
  "devDependencies": {
43
36
  "@jest/globals": "^29.7.0",
44
- "jest": "^29.7.0"
37
+ "@types/node": "^20.0.0",
38
+ "@types/proper-lockfile": "^4.1.4",
39
+ "jest": "^29.7.0",
40
+ "prettier": "^3.6.2",
41
+ "ts-jest": "^29.1.0",
42
+ "typescript": "^5.3.0"
43
+ },
44
+ "scripts": {
45
+ "manifest:fetch-versions": "bun ./src/manifest/fetch-versions.ts",
46
+ "build": "tsc",
47
+ "build:watch": "tsc --watch",
48
+ "clean": "rm -rf dist",
49
+ "prebuild": "npm run clean",
50
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
51
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
52
+ "test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch='**/tests/e2e/**/*.test.ts'",
53
+ "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch='**/tests/unit/**/*.test.ts'",
54
+ "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage"
45
55
  }
46
- }
47
-
48
-
56
+ }
package/src/cli.js DELETED
@@ -1,408 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * CHVM - Chrome Version Manager
5
- * Entry point for CLI
6
- */
7
-
8
- import { Command } from 'commander';
9
- import chalk from 'chalk';
10
- import { checkPlatform } from './lib/platform-check.js';
11
- import { getChvmHome, ensureChvmDir, readAvailableVersions, writeAvailableVersions, readInstalledVersions, addInstalledVersion, removeInstalledVersion } from './lib/storage.js';
12
- import { createLogger } from './lib/logger.js';
13
- import { fetchRevisions, fetchVersionMapping, mergeRevisionsWithVersions, resolveVersion, buildAvailableVersions } from './lib/mapping.js';
14
- import { getDownloadUrl, fetchRevisionMetadata, downloadWithProgress } from './lib/downloader.js';
15
- import { atomicInstall, extractZip, verifyAppBundle, calculateDirectorySize } from './lib/installer.js';
16
- import { withLock } from './lib/lock.js';
17
- import ora from 'ora';
18
- import { exec } from 'child_process';
19
- import { promisify } from 'util';
20
- import fs from 'fs/promises';
21
- import { existsSync } from 'fs';
22
- import { join } from 'path';
23
-
24
- const execAsync = promisify(exec);
25
-
26
- const program = new Command();
27
-
28
- program
29
- .name('chvm')
30
- .description('Chrome Version Manager - Manage multiple Chromium versions on macOS ARM')
31
- .version('1.0.0');
32
-
33
- // Help command (default)
34
- program
35
- .command('help', { isDefault: false })
36
- .description('Show help information')
37
- .action(() => {
38
- program.outputHelp();
39
- });
40
-
41
- // ls command
42
- program
43
- .command('ls')
44
- .description('List available and installed Chromium versions')
45
- .option('--json', 'Output in JSON format')
46
- .action(async (options) => {
47
- try {
48
- checkPlatform();
49
- const chvmHome = getChvmHome();
50
- await ensureChvmDir(chvmHome);
51
-
52
- const available = await readAvailableVersions(chvmHome);
53
- const installed = await readInstalledVersions(chvmHome);
54
-
55
- if (options.json) {
56
- console.log(JSON.stringify({ available, installed }, null, 2));
57
- } else {
58
- if (available.length === 0) {
59
- console.log(chalk.yellow('No versions available. Run "chvm update" first.'));
60
- return;
61
- }
62
-
63
- console.log(chalk.bold('\nAvailable Chromium Versions:\n'));
64
- console.log(chalk.gray('VERSION\tREVISION\tCHANNEL\tSTATUS'));
65
- console.log(chalk.gray('─'.repeat(60)));
66
-
67
- const printedMajors = new Set();
68
- for (const item of available) {
69
- if(!item.version){
70
- continue
71
- }
72
- const major = item.version.split('.')[0];
73
- if(printedMajors.has(major)){
74
- continue
75
- }
76
- printedMajors.add(major);
77
-
78
- const displayVersion = item.version || chalk.gray(`[${item.revision}]`);
79
- // Check both version and revision for installed status
80
- const installKey = item.version || item.revision;
81
- const isInstalled = installed[installKey];
82
- const status = isInstalled ? chalk.green('* installed') : '';
83
- console.log(`${displayVersion}\t${item.revision}\t${item.channel}\t${status}`);
84
- }
85
- console.log();
86
- }
87
- } catch (error) {
88
- console.error(chalk.red(`Error: ${error.message}`));
89
- process.exit(1);
90
- }
91
- });
92
-
93
- // update command
94
- program
95
- .command('update')
96
- .description('Update the list of available Chromium versions')
97
- .option('--force', 'Force update, bypass cache')
98
- .action(async (options) => {
99
- try {
100
- checkPlatform();
101
- const chvmHome = getChvmHome();
102
- await ensureChvmDir(chvmHome);
103
-
104
- const logger = createLogger({ chvmHome, level: 'info' });
105
- const spinner = ora('Fetching available Chromium versions...').start();
106
-
107
- try {
108
- const available = await buildAvailableVersions();
109
-
110
- if (available.length === 0) {
111
- spinner.warn(chalk.yellow('No versions found with matching revisions. Try again later.'));
112
- } else {
113
- await writeAvailableVersions(chvmHome, available);
114
- spinner.succeed(chalk.green(`Updated! ${available.length} versions available.`));
115
- }
116
- } catch (error) {
117
- spinner.fail(chalk.red(`Failed to update: ${error.message}`));
118
- throw error;
119
- }
120
- } catch (error) {
121
- console.error(chalk.red(`Error: ${error.message}`));
122
- process.exit(1);
123
- }
124
- });
125
-
126
- // install command
127
- program
128
- .command('install <version>')
129
- .alias('i')
130
- .description('Install a specific Chromium version')
131
- .option('--no-cache', 'Skip cache and download fresh')
132
- .option('--quiet', 'Minimal output')
133
- .action(async (version, options) => {
134
- try {
135
- checkPlatform();
136
- const chvmHome = getChvmHome();
137
- await ensureChvmDir(chvmHome);
138
-
139
- const logger = createLogger({ chvmHome, level: options.quiet ? 'error' : 'info' });
140
-
141
- await withLock(chvmHome, async () => {
142
- const available = await readAvailableVersions(chvmHome);
143
-
144
- if (available.length === 0) {
145
- throw new Error('No versions available. Please run "chvm update" first.');
146
- }
147
-
148
- const resolved = resolveVersion(version, available);
149
-
150
- if (!resolved) {
151
- throw new Error(`Version "${version}" not found. Run "chvm ls" to see available versions.`);
152
- }
153
-
154
- const displayVersion = resolved.version || `Revision ${resolved.revision}`;
155
- console.log(chalk.blue(`Resolving '${version}' -> ${displayVersion} (revision: ${resolved.revision})`));
156
-
157
- // Check if already installed
158
- const installed = await readInstalledVersions(chvmHome);
159
- const installKey = resolved.version || resolved.revision;
160
- if (installed[installKey]) {
161
- console.log(chalk.yellow(`Version ${displayVersion} is already installed.`));
162
- return;
163
- }
164
-
165
- const spinner = ora('Fetching revision metadata...').start();
166
-
167
- const metadata = await fetchRevisionMetadata(resolved.revision);
168
- const chromeMacZip = metadata.items.find(item => item.name.includes('chrome-mac.zip'));
169
-
170
-
171
- if (!chromeMacZip) {
172
- throw new Error('chrome-mac.zip not found in revision');
173
- }
174
-
175
- spinner.text = `Downloading Chromium ${displayVersion}...`;
176
-
177
- const tmpZip = join(chvmHome, 'tmp', `chrome-${resolved.revision}.zip`);
178
- await fs.mkdir(join(chvmHome, 'tmp'), { recursive: true });
179
-
180
- await downloadWithProgress(chromeMacZip.mediaLink, tmpZip, (progress) => {
181
- spinner.text = `Downloading: ${progress.percentage}% (${Math.round(progress.downloaded / 1024 / 1024)}MB / ${Math.round(progress.total / 1024 / 1024)}MB)`;
182
- });
183
-
184
- spinner.text = 'Extracting...';
185
-
186
- const finalPath = join(chvmHome, 'installs', `${installKey}.app`);
187
-
188
- await atomicInstall(async (tmpDir) => {
189
- const extractPath = join(tmpDir, 'extracted');
190
-
191
- spinner.text = 'Extracting zip...';
192
- await extractZip(tmpZip, extractPath, (progress) => {
193
- spinner.text = `Extracting: ${progress.extractedFiles} files...`;
194
- });
195
-
196
- spinner.text = 'Looking for app bundle...';
197
-
198
- // Find the .app bundle
199
- const files = await fs.readdir(extractPath);
200
- console.log('Extracted files:', files.slice(0, 10).join(', ')); // Debug
201
-
202
- const appBundle = files.find(f => f.endsWith('.app'));
203
-
204
- if (!appBundle) {
205
- // Maybe it's in a subdirectory like chrome-mac/
206
- const chromeMacDir = join(extractPath, 'chrome-mac');
207
- if (existsSync(chromeMacDir)) {
208
- const subFiles = await fs.readdir(chromeMacDir);
209
- const subAppBundle = subFiles.find(f => f.endsWith('.app'));
210
- if (subAppBundle) {
211
- return join(chromeMacDir, subAppBundle);
212
- }
213
- }
214
- throw new Error('App bundle not found in extracted files');
215
- }
216
-
217
- return join(extractPath, appBundle);
218
- }, finalPath, chvmHome);
219
-
220
- // Cleanup tmp zip
221
- await fs.unlink(tmpZip).catch(() => {});
222
-
223
- spinner.text = 'Verifying installation...';
224
- const isValid = await verifyAppBundle(finalPath);
225
-
226
- if (!isValid) {
227
- throw new Error('Installation verification failed: Invalid app bundle structure');
228
- }
229
-
230
- const size = await calculateDirectorySize(finalPath);
231
-
232
- await addInstalledVersion(chvmHome, {
233
- version: installKey,
234
- revision: resolved.revision,
235
- path: finalPath,
236
- size
237
- });
238
-
239
- spinner.succeed(chalk.green(`Installed ${displayVersion} to ${finalPath}`));
240
- logger.info(`Installed version ${displayVersion}`);
241
-
242
- }, { timeout: 600000 }); // 10 minute timeout
243
-
244
- } catch (error) {
245
- console.error(chalk.red(`Error: ${error.message}`));
246
- process.exit(1);
247
- }
248
- });
249
-
250
- // open command
251
- program
252
- .command('open <version>')
253
- .description('Open a specific Chromium version')
254
- .option('--disable-cors', 'Disable CORS (useful for development)')
255
- .action(async (version, options) => {
256
- try {
257
- checkPlatform();
258
- const chvmHome = getChvmHome();
259
- await ensureChvmDir(chvmHome);
260
-
261
- const installed = await readInstalledVersions(chvmHome);
262
- const available = await readAvailableVersions(chvmHome);
263
-
264
- let versionToOpen = null;
265
-
266
- // Try to find in installed (check both version and revision)
267
- if (installed[version]) {
268
- versionToOpen = { version, ...installed[version] };
269
- } else {
270
- // Try to resolve and install
271
- const resolved = resolveVersion(version, available);
272
- if (!resolved) {
273
- throw new Error(`Version "${version}" not found. Run "chvm ls" to see available versions.`);
274
- }
275
-
276
- const installKey = resolved.version || resolved.revision;
277
- const displayVersion = resolved.version || `Revision ${resolved.revision}`;
278
-
279
- if (!installed[installKey]) {
280
- console.log(chalk.blue(`${displayVersion} not installed. Installing...`));
281
- // Use revision for install if no version
282
- await execAsync(`node ${process.argv[1]} install ${resolved.revision}`);
283
-
284
- // Reload installed versions
285
- const reloaded = await readInstalledVersions(chvmHome);
286
- versionToOpen = { version: installKey, ...reloaded[installKey] };
287
- } else {
288
- versionToOpen = { version: installKey, ...installed[installKey] };
289
- }
290
- }
291
-
292
- if (!versionToOpen) {
293
- throw new Error('Failed to prepare version for opening');
294
- }
295
-
296
- if (options.disableCors) {
297
- console.log(chalk.yellow('⚠️ WARNING: Running with --disable-web-security. This is insecure and should only be used for development.'));
298
- }
299
-
300
- // Prepare profile directory
301
- const profileDir = join(chvmHome, 'profiles', versionToOpen.version);
302
- await fs.mkdir(profileDir, { recursive: true });
303
-
304
- // Find executable
305
- const appPath = versionToOpen.path;
306
- const execPath = join(appPath, 'Contents', 'MacOS', 'Chromium');
307
-
308
- if (!existsSync(execPath)) {
309
- throw new Error(`Chromium executable not found at ${execPath}`);
310
- }
311
-
312
- const args = [
313
- `--user-data-dir=${profileDir}`
314
- ];
315
-
316
- if (options.disableCors) {
317
- args.push('--disable-web-security');
318
- args.push(`--user-data-dir=${join(chvmHome, 'tmp', versionToOpen.version)}`);
319
- }
320
-
321
- console.log(chalk.green(`Opening Chromium ${versionToOpen.version}...`));
322
-
323
- // Use open command on macOS
324
- const command = `open -a "${appPath}" --args ${args.join(' ')}`;
325
-
326
- exec(command, (error) => {
327
- if (error) {
328
- console.error(chalk.red(`Failed to open: ${error.message}`));
329
- process.exit(1);
330
- }
331
- });
332
-
333
- } catch (error) {
334
- console.error(chalk.red(`Error: ${error.message}`));
335
- process.exit(1);
336
- }
337
- });
338
-
339
- // uninstall command
340
- program
341
- .command('uninstall <version>')
342
- .description('Uninstall a specific Chromium version')
343
- .option('--force', 'Force uninstall even if running')
344
- .action(async (version, options) => {
345
- try {
346
- checkPlatform();
347
- const chvmHome = getChvmHome();
348
- await ensureChvmDir(chvmHome);
349
-
350
- await withLock(chvmHome, async () => {
351
- const installed = await readInstalledVersions(chvmHome);
352
- const available = await readAvailableVersions(chvmHome);
353
-
354
- // Try to resolve version
355
- let versionToUninstall = version;
356
-
357
- if (!installed[version]) {
358
- const resolved = resolveVersion(version, available);
359
- if (resolved && installed[resolved.version]) {
360
- versionToUninstall = resolved.version;
361
- } else {
362
- throw new Error(`Version "${version}" is not installed.`);
363
- }
364
- }
365
-
366
- const versionInfo = installed[versionToUninstall];
367
- const spinner = ora(`Uninstalling ${versionToUninstall}...`).start();
368
-
369
- // Remove app directory
370
- if (existsSync(versionInfo.path)) {
371
- await fs.rm(versionInfo.path, { recursive: true, force: true });
372
- spinner.text = 'Removed app bundle...';
373
- }
374
-
375
- // Remove profile directory
376
- const profileDir = join(chvmHome, 'profiles', versionToUninstall);
377
- if (existsSync(profileDir)) {
378
- await fs.rm(profileDir, { recursive: true, force: true });
379
- spinner.text = 'Removed profile...';
380
- }
381
-
382
- // Remove tmp directories
383
- const tmpDir = join(chvmHome, 'tmp', versionToUninstall);
384
- if (existsSync(tmpDir)) {
385
- await fs.rm(tmpDir, { recursive: true, force: true });
386
- }
387
-
388
- // Remove from installed.json
389
- await removeInstalledVersion(chvmHome, versionToUninstall);
390
-
391
- spinner.succeed(chalk.green(`Uninstalled ${versionToUninstall}`));
392
- });
393
-
394
- } catch (error) {
395
- console.error(chalk.red(`Error: ${error.message}`));
396
- process.exit(1);
397
- }
398
- });
399
-
400
- // Show help if no command provided
401
- if (process.argv.length === 2) {
402
- program.outputHelp();
403
- process.exit(0);
404
- }
405
-
406
- program.parse();
407
-
408
-
@@ -1,132 +0,0 @@
1
- /**
2
- * Downloader module - Streaming download with progress
3
- */
4
-
5
- import fs from 'fs';
6
- import { pipeline } from 'stream/promises';
7
- import { createWriteStream, existsSync, statSync } from 'fs';
8
-
9
- export function getDownloadUrl(revision) {
10
- return `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Mac_Arm%2F${revision}%2Fchrome-mac.zip?alt=media`;
11
- }
12
-
13
- export async function fetchRevisionMetadata(revision) {
14
- const url = `https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o?delimiter=/&prefix=Mac_Arm/${revision}/&fields=items(kind,mediaLink,metadata,name,size,updated),kind,prefixes,nextPageToken`;
15
-
16
- const response = await fetch(url);
17
-
18
- if (!response.ok) {
19
- throw new Error(`Failed to fetch metadata for revision ${revision}: ${response.statusText}`);
20
- }
21
-
22
- const data = await response.json();
23
-
24
- if (!data.items || data.items.length === 0) {
25
- throw new Error(`No files found for revision ${revision}`);
26
- }
27
-
28
- return data;
29
- }
30
-
31
- export async function downloadWithProgress(url, outputPath, onProgress) {
32
- const response = await fetch(url);
33
-
34
- if (!response.ok) {
35
- throw new Error(`Failed to download: ${response.statusText}`);
36
- }
37
-
38
- const totalSize = parseInt(response.headers.get('content-length') || '0', 10);
39
- let downloadedSize = 0;
40
-
41
- const fileStream = createWriteStream(outputPath);
42
-
43
- if (!response.body) {
44
- throw new Error('Response body is null');
45
- }
46
-
47
- const reader = response.body.getReader();
48
-
49
- try {
50
- while (true) {
51
- const { done, value } = await reader.read();
52
-
53
- if (done) break;
54
-
55
- fileStream.write(value);
56
- downloadedSize += value.length;
57
-
58
- if (onProgress && totalSize > 0) {
59
- const progress = {
60
- downloaded: downloadedSize,
61
- total: totalSize,
62
- percentage: Math.round((downloadedSize / totalSize) * 100)
63
- };
64
- onProgress(progress);
65
- }
66
- }
67
-
68
- fileStream.end();
69
-
70
- // Wait for file stream to finish
71
- await new Promise((resolve, reject) => {
72
- fileStream.on('finish', resolve);
73
- fileStream.on('error', reject);
74
- });
75
-
76
- } catch (error) {
77
- fileStream.close();
78
- throw error;
79
- }
80
- }
81
-
82
- export async function retryFetch(fetchFn, options = {}) {
83
- const { retries = 3, delay = 1000, backoff = 2 } = options;
84
-
85
- let lastError;
86
-
87
- for (let attempt = 0; attempt <= retries; attempt++) {
88
- try {
89
- return await fetchFn();
90
- } catch (error) {
91
- lastError = error;
92
-
93
- if (attempt < retries) {
94
- const waitTime = delay * Math.pow(backoff, attempt);
95
- await new Promise(resolve => setTimeout(resolve, waitTime));
96
- }
97
- }
98
- }
99
-
100
- throw lastError;
101
- }
102
-
103
- export async function streamDownload(url) {
104
- const response = await fetch(url);
105
-
106
- if (!response.ok) {
107
- throw new Error(`Failed to download: ${response.statusText}`);
108
- }
109
-
110
- return response.body;
111
- }
112
-
113
- export async function validateDownload(filePath, options = {}) {
114
- const { expectedSize } = options;
115
-
116
- if (!existsSync(filePath)) {
117
- throw new Error('Downloaded file does not exist');
118
- }
119
-
120
- const stats = statSync(filePath);
121
-
122
- if (expectedSize && stats.size !== expectedSize) {
123
- throw new Error(`File size mismatch: expected ${expectedSize}, got ${stats.size}`);
124
- }
125
-
126
- return {
127
- valid: true,
128
- size: stats.size
129
- };
130
- }
131
-
132
-