feat(core): Add permission-controlled Deno execution, configurable script server port, improved downloader, dependency bumps and test updates

This commit is contained in:
2025-12-02 11:27:35 +00:00
parent 01dd40e599
commit fb0bfed4ab
20 changed files with 7919 additions and 3613 deletions

View File

@@ -14,9 +14,11 @@ interface IAsset {
}
export class DenoDownloader {
private denoBinaryPath: string | null = null;
private async getDenoDownloadUrl(): Promise<string> {
const osPlatform = platform(); // 'darwin', 'linux', 'win32', etc.
const arch = process.arch; // 'x64', 'arm64', etc.
const osPlatform = platform();
const arch = process.arch;
let osPart: string;
switch (osPlatform) {
@@ -36,9 +38,12 @@ export class DenoDownloader {
const archPart = arch === 'x64' ? 'x86_64' : 'aarch64';
const releasesResponse = await fetch('https://api.github.com/repos/denoland/deno/releases/latest');
if (!releasesResponse.ok) {
throw new Error(`Failed to fetch Deno releases: ${releasesResponse.statusText}`);
}
const release: IDenoRelease = await releasesResponse.json();
const executableName = `deno-${archPart}-${osPart}.zip`; // Adjust if naming convention changes
const executableName = `deno-${archPart}-${osPart}.zip`;
const asset = release.assets.find(a => a.name === executableName);
if (!asset) {
@@ -57,24 +62,60 @@ export class DenoDownloader {
await fs.writeFile(outputPath, Buffer.from(buffer));
}
public async download(outputPath: string = './deno.zip'): Promise<void> {
try {
const url = await this.getDenoDownloadUrl();
await this.downloadDeno(url, outputPath);
console.log(`Deno downloaded successfully to ${outputPath}`);
} catch (error) {
console.error(`Error downloading Deno: ${error.message}`);
}
if (await plugins.smartfile.fs.fileExists(plugins.path.join(paths.nogitDir, 'deno'))) {
return;
}
const smartarchive = await plugins.smartarchive.SmartArchive.fromArchiveFile(outputPath);
/**
* Get the path to the Deno binary after download
*/
public getDenoBinaryPath(): string | null {
return this.denoBinaryPath;
}
/**
* Download and extract Deno to the specified directory
* @param outputPath Path where the deno.zip will be downloaded
* @returns Path to the Deno binary
*/
public async download(outputPath: string = './deno.zip'): Promise<string> {
const fsInstance = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
const directory = plugins.path.dirname(outputPath);
const denoBinaryPath = plugins.path.join(directory, platform() === 'win32' ? 'deno.exe' : 'deno');
// Check if Deno is already downloaded
if (await fsInstance.file(denoBinaryPath).exists()) {
console.log(`Deno already exists at ${denoBinaryPath}`);
this.denoBinaryPath = denoBinaryPath;
return denoBinaryPath;
}
// Ensure the directory exists
await fsInstance.directory(directory).create();
// Download Deno
const url = await this.getDenoDownloadUrl();
await this.downloadDeno(url, outputPath);
console.log(`Deno downloaded successfully to ${outputPath}`);
// Extract the archive
console.log(`Extracting deno.zip to ${directory}`);
await smartarchive.exportToFs(directory);
const smartshellInstance = new plugins.smarthshell.Smartshell({
executor: 'bash'
});
await smartshellInstance.exec(`(cd ${paths.nogitDir} && chmod +x deno)`);
await plugins.smartarchive.SmartArchive.create()
.file(outputPath)
.extract(directory);
// Make the binary executable (Unix-like systems)
if (platform() !== 'win32') {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
await smartshellInstance.exec(`chmod +x "${denoBinaryPath}"`);
}
// Clean up the zip file
try {
await fsInstance.file(outputPath).delete();
} catch {
// Ignore cleanup errors
}
this.denoBinaryPath = denoBinaryPath;
return denoBinaryPath;
}
}