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
+24 -6
View File
@@ -1,9 +1,11 @@
import * as plugins from './smartgit.plugins.js';
import { GitRepo } from './smartgit.classes.gitrepo.js';
type TNodeFs = typeof import('node:fs');
interface IEnvDeps {
fs: typeof import('fs') | null;
http: any | null; // isomorphic-git http interface
fs?: TNodeFs;
http?: plugins.HttpClient;
}
/**
@@ -13,8 +15,8 @@ interface IEnvDeps {
export class Smartgit {
public smartenvInstance = new plugins.smartenv.Smartenv();
public envDeps: IEnvDeps = {
fs: null,
http: null,
fs: undefined,
http: undefined,
};
/**
@@ -24,8 +26,8 @@ export class Smartgit {
public async init(): Promise<void> {
try {
if (this.smartenvInstance.isNode) {
this.envDeps.fs = await this.smartenvInstance.getSafeNodeModule('fs');
this.envDeps.http = await this.smartenvInstance.getSafeNodeModule(
this.envDeps.fs = await this.smartenvInstance.getSafeNodeModule<TNodeFs>('fs');
this.envDeps.http = await this.smartenvInstance.getSafeNodeModule<plugins.HttpClient>(
'isomorphic-git/http/node'
);
} else {
@@ -42,6 +44,22 @@ export class Smartgit {
}
}
public get fs(): TNodeFs {
const fs = this.envDeps.fs;
if (!fs) {
throw new Error('Smartgit must be initialized before use. Call init() first.');
}
return fs;
}
public get http(): plugins.HttpClient {
const http = this.envDeps.http;
if (!http) {
throw new Error('Smartgit must be initialized before use. Call init() first.');
}
return http;
}
/**
* creates a new GitRepo instance by cloning from a remote URL
* @param fromUrlArg the URL to clone from