fix(build): modernize project configuration and tighten Node.js typing support

This commit is contained in:
2026-04-30 18:19:27 +00:00
parent ff0bc72408
commit 8ed7413e62
13 changed files with 2224 additions and 2657 deletions
+28 -26
View File
@@ -17,8 +17,8 @@ export class GitRepo {
const dirArg = plugins.path.resolve(toArg);
await plugins.isomorphicGit.clone({
dir: toArg,
fs: smartgitRefArg.envDeps.fs,
http: smartgitRefArg.envDeps.http,
fs: smartgitRefArg.fs,
http: smartgitRefArg.http,
url: fromArg,
});
return new GitRepo(smartgitRefArg, toArg);
@@ -31,12 +31,12 @@ export class GitRepo {
dirArg = plugins.path.resolve(dirArg);
await plugins.isomorphicGit.init({
dir: dirArg,
fs: smartgitRefArg.envDeps.fs,
fs: smartgitRefArg.fs,
});
return new GitRepo(smartgitRefArg, dirArg);
}
public static async fromOpeningRepoDir(smartgitRefArg: Smartgit, dirArg: string) {
public static async fromOpeningRepoDir(smartgitRefArg: Smartgit, dirArg: string): Promise<GitRepo> {
dirArg = plugins.path.resolve(dirArg);
return new GitRepo(smartgitRefArg, dirArg);
}
@@ -60,7 +60,7 @@ export class GitRepo {
}[]
> {
const remotes = await plugins.isomorphicGit.listRemotes({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
});
return remotes;
@@ -78,7 +78,7 @@ export class GitRepo {
if (existingRemote.url !== remoteUrlArg) {
await plugins.isomorphicGit.deleteRemote({
remote: remoteNameArg,
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
});
} else {
@@ -87,7 +87,7 @@ export class GitRepo {
}
await plugins.isomorphicGit.addRemote({
remote: remoteNameArg,
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
url: remoteUrlArg,
});
}
@@ -95,16 +95,16 @@ export class GitRepo {
/**
* gets the url for a specific remote
*/
public async getUrlForRemote(remoteName: string): Promise<string> {
public async getUrlForRemote(remoteName: string): Promise<string | undefined> {
const remotes = await this.listRemotes();
const existingRemote = remotes.find((remoteArg) => remoteArg.remote === remoteName);
return existingRemote?.url;
}
public async pushBranchToRemote(branchName: string, remoteName: string) {
public async pushBranchToRemote(branchName: string, remoteName: string): Promise<void> {
await plugins.isomorphicGit.push({
fs: this.smartgitRef.envDeps.fs,
http: this.smartgitRef.envDeps.http,
fs: this.smartgitRef.fs,
http: this.smartgitRef.http,
ref: branchName,
remote: remoteName,
});
@@ -115,7 +115,7 @@ export class GitRepo {
*/
public async getUncommittedDiff(excludeFiles: string[] = []): Promise<string[]> {
const statusMatrix = await plugins.isomorphicGit.statusMatrix({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
});
@@ -133,10 +133,10 @@ export class GitRepo {
if (head !== 0 && workdir !== 0 && head !== workdir) {
headContent = await plugins.isomorphicGit
.readBlob({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
oid: await plugins.isomorphicGit.resolveRef({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
ref: 'HEAD',
}),
@@ -144,7 +144,7 @@ export class GitRepo {
})
.then((result) => new TextDecoder().decode(result.blob));
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
workdirContent = await this.smartgitRef.fs.promises.readFile(
plugins.path.join(this.repoDir, filepath),
'utf8'
);
@@ -152,7 +152,7 @@ export class GitRepo {
// Handle added files
if (head === 0 && workdir !== 0) {
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
workdirContent = await this.smartgitRef.fs.promises.readFile(
plugins.path.join(this.repoDir, filepath),
'utf8'
);
@@ -162,10 +162,10 @@ export class GitRepo {
try {
headContent = await plugins.isomorphicGit
.readBlob({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
oid: await plugins.isomorphicGit.resolveRef({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
ref: 'HEAD',
}),
@@ -175,7 +175,7 @@ export class GitRepo {
} catch (err) {
// Check if this is a symlink false positive
// Error: "was anticipated to be a tree but it is a blob" means parent path is a symlink
if (err.message && err.message.includes('anticipated to be a tree but it is a blob')) {
if (err instanceof Error && err.message.includes('anticipated to be a tree but it is a blob')) {
// This file is inside a symlinked directory - skip it entirely
continue;
}
@@ -187,10 +187,10 @@ export class GitRepo {
if (head !== 0 && workdir === 0) {
headContent = await plugins.isomorphicGit
.readBlob({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
oid: await plugins.isomorphicGit.resolveRef({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
ref: 'HEAD',
}),
@@ -225,23 +225,25 @@ export class GitRepo {
{ date: string; version: string; message: string }[]
> {
const commits = await plugins.isomorphicGit.log({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
});
const results = [];
const results: { date: string; version: string; message: string }[] = [];
for (const commit of commits) {
let version = 'unknown';
try {
const packageJsonBlob = await plugins.isomorphicGit.readBlob({
fs: this.smartgitRef.envDeps.fs,
fs: this.smartgitRef.fs,
dir: this.repoDir,
oid: commit.oid,
filepath: 'package.json',
});
const packageJson = JSON.parse(new TextDecoder().decode(packageJsonBlob.blob));
version = packageJson.version;
const packageJson = JSON.parse(new TextDecoder().decode(packageJsonBlob.blob)) as {
version?: string;
};
version = packageJson.version ?? 'unknown';
} catch (error) {
// If package.json does not exist or any error occurs, leave version as 'unknown'
}