Skip to content

Commit 62a3e6d

Browse files
Fix download with main version
1 parent c56281f commit 62a3e6d

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

editor/src/ctx.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as net from 'net';
1717
import { Logger } from "./logger";
1818
import { existsSync, readdirSync, rmdirSync, rm } from "fs";
1919
import * as path from "path";
20-
import { FetchOptions, FetchResult, PackageManager } from "@4dsas/package-manager";
20+
import { FetchOptions, PackageManager } from "@4dsas/package-manager";
2121
import * as fsSync from 'fs';
2222

2323
export type CommandCallback = {
@@ -286,14 +286,25 @@ export class Ctx {
286286
const parsed = vscode.Uri.parse(params.uri).fsPath;
287287
const packageFolder = path.dirname(path.dirname(parsed));
288288

289-
const packageManager = new PackageManager(packageFolder, session.accessToken,
290-
this.get4DVersion().toString(false), undefined);
291-
await packageManager.initialize();
292-
let options: FetchOptions = {};
293-
packageManager.fetch(options).then(() => {
294-
statusBarItem.text = "$(sync~spin) Install components...";
295-
this._client.sendNotification(ext.notif_installComponents, params);
296-
});
289+
try {
290+
Logger.debugLog("4D Version", this.get4DVersion().toString(false));
291+
292+
const packageManager = new PackageManager(packageFolder,
293+
this.get4DVersion().toString(false), session.accessToken, undefined, (dependencyName) => {
294+
statusBarItem.text = `$(sync~spin) Fetch components... (${dependencyName})`;
295+
});
296+
await packageManager.initialize();
297+
let options: FetchOptions = {};
298+
packageManager.fetch(options).then(() => {
299+
statusBarItem.text = "$(sync~spin) Install components...";
300+
this._client.sendNotification(ext.notif_installComponents, params);
301+
});
302+
} catch (error) {
303+
statusBarItem.hide();
304+
Logger.debugLog(error);
305+
vscode.window.showErrorMessage(error);
306+
}
307+
297308
return true;
298309
});
299310

packageManager/src/PackageManager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,23 @@ export class PackageManager {
2727
private lock: LockFile | null = null;
2828
private reconciled: Map<string, GitHubDependency> = new Map();
2929
private ideVersion: Version;
30+
private callback?: (message: string) => void;
3031

31-
constructor(projectPath: string, ideVersion: string, authToken?: string, cacheFolder?: string) {
32+
constructor(projectPath: string, ideVersion: string, authToken?: string, cacheFolder?: string, callback?: (message: string) => void) {
3233
// Validate inputs
3334
if (!projectPath || typeof projectPath !== 'string') {
3435
throw new Error('Project path is required and must be a string');
3536
}
3637
if (!path.isAbsolute(projectPath)) {
3738
throw new Error('Project path must be an absolute path');
3839
}
39-
if (ideVersion && !/^\d+\.\d+(\.\d+)?$/.test(ideVersion)) {
40-
throw new Error('IDE version must be in format X.Y or X.Y.Z (e.g., "20.0" or "20.0.1")');
41-
}
4240

4341
this.configReader = new ConfigReader(projectPath);
4442
this.cacheManager = new CacheManager(cacheFolder);
4543
this.fetcher = new GithubFetcher(authToken);
4644
this.ideVersion = new Version(ideVersion);
45+
this.callback = callback;
4746
}
48-
4947
/**
5048
* Read all configuration files and prepare for fetching
5149
*/
@@ -199,6 +197,7 @@ export class PackageManager {
199197
}
200198

201199
const lockEntry = this.lock!.dependencies[name];
200+
this.callback?.(name);
202201
const fetched = await dep.fetch(
203202
this.ideVersion,
204203
this.environment!,

packageManager/src/dependency/Dependency.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ export class Dependency {
147147

148148
// If "4d" keyword, match IDE version
149149
if (this._version.toLowerCase() === '4d') {
150-
const range = new Range(this._version, ideVersion);
151-
return await this.resolveRange(fetcher, owner, repo, range);
152150

151+
//main means latest
152+
if (ideVersion.isMain) {
153+
const release = await fetcher.getLatestRelease(owner, repo);
154+
return release.tag_name;
155+
}
156+
else {
157+
const range = new Range(this._version, ideVersion);
158+
return await this.resolveRange(fetcher, owner, repo, range);
159+
}
153160
}
154161

155162
// Parse as version range
@@ -183,8 +190,8 @@ export class Dependency {
183190

184191
//Find matching tag name
185192
let index = 0;
186-
for(const tag of tags) {
187-
if(tag == tagFound) {
193+
for (const tag of tags) {
194+
if (tag == tagFound) {
188195
return validReleases[index].tag_name;
189196
}
190197
index++;
@@ -319,7 +326,7 @@ export class Dependency {
319326
return "";
320327
}
321328

322-
async getPackage(root : string) : Promise<Package|null> {
329+
async getPackage(root: string): Promise<Package | null> {
323330
return Package.Create(root)
324331
}
325332

packageManager/src/version/Version.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class Version {
1212
public raw: string;
1313

1414
constructor(versionString: string) {
15+
16+
//No version means main
17+
if (versionString === "0") {
18+
versionString = "0.0.0";
19+
this.isMain = true;
20+
}
1521
this.raw = versionString;
1622

1723
// Clean version string (remove 'v' prefix)

0 commit comments

Comments
 (0)