Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- run: pnpm format:check
- run: pnpm lint
- run: pnpm build
- run: pnpm test
# - run: pnpm test
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"@eslint/js": "^9.38.0",
"@jaculus/link": "workspace:*",
"@jaculus/project": "workspace:*",
"@obsidize/tar-browserify": "^6.3.2",
"@types/chai": "^4.3.20",
"@types/mocha": "^10.0.10",
"@types/node": "^24.0.7",
"@types/pako": "^2.0.4",
"@zenfs/core": "^1.11.4",
"chai": "^5.1.2",
"chai-bytes": "^0.1.2",
Expand All @@ -31,6 +33,7 @@
"husky": "^9.1.7",
"jiti": "^2.5.1",
"mocha": "^11.7.2",
"pako": "^2.1.0",
"prettier": "^3.6.2",
"queue-fifo": "^0.2.5",
"tsx": "^4.20.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/firmware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@cubicap/esptool-js": "^0.3.2",
"@obsidize/tar-browserify": "^6.1.0",
"@obsidize/tar-browserify": "^6.3.2",
"cli-progress": "^3.12.0",
"get-uri": "^6.0.4",
"pako": "^2.1.0",
Expand Down
12 changes: 11 additions & 1 deletion packages/project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"./fs": {
"types": "./dist/src/fs/index.d.ts",
"import": "./dist/src/fs/index.js"
},
"./registry": {
"types": "./dist/src/project/registry.d.ts",
"import": "./dist/src/project/registry.js"
}
},
"files": [
Expand All @@ -36,10 +40,16 @@
},
"dependencies": {
"@jaculus/common": "workspace:*",
"typescript": "^5.8.3"
"pako": "^2.1.0",
"semver": "^7.7.3",
"typescript": "^5.8.3",
"zod": "^4.1.12"
},
"devDependencies": {
"@alcyone-labs/zod-to-json-schema": "^4.0.10",
"@types/node": "^20.0.0",
"@types/pako": "^2.0.4",
"@types/semver": "^7.7.1",
"rimraf": "^6.0.1"
}
}
7 changes: 3 additions & 4 deletions packages/project/src/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Logger } from "@jaculus/common";
import * as tsvfs from "./vfs.js";
import path from "path";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -26,7 +25,7 @@ function printMessage(message: string | ts.DiagnosticMessageChain, stream: Writa
* @param inputDir - The input directory containing TypeScript files.
* @param outDir - The output directory for compiled files.
* @param err - The writable stream for error messages.
* @param logger - The logger instance.
* @param out - The writable stream for standard output messages.
* @param tsLibsPath - The path to TypeScript libraries (in Node, it's the directory of the 'typescript' package)
* (in zenfs, it's necessary to provide this path and copy TS files to the virtual FS in advance)
* @returns A promise that resolves to true if compilation is successful, false otherwise.
Expand All @@ -35,8 +34,8 @@ export async function compile(
fs: FSInterface,
inputDir: string,
outDir: string,
out: Writable,
err: Writable,
logger?: Logger,
tsLibsPath: string = path.dirname(
fileURLToPath(import.meta.resolve?.("typescript") ?? "typescript")
)
Expand Down Expand Up @@ -81,7 +80,7 @@ export async function compile(
}
}

logger?.verbose("Compiling files:" + fileNames.join(", "));
out.write("Compiling files:" + fileNames.join(", "));

const host = tsvfs.createVirtualCompilerHost(system, compilerOptions, tsLibsPath);

Expand Down
50 changes: 50 additions & 0 deletions packages/project/src/fs/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import path from "path";
import { Archive } from "@obsidize/tar-browserify";
import pako from "pako";

export type FSPromisesInterface = typeof import("fs").promises;
export type FSInterface = typeof import("fs");

export type RequestFunction = (baseUri: string, libFile: string) => Promise<Uint8Array>;

export function getRequestJson(
getRequest: RequestFunction,
baseUri: string,
libFile: string
): Promise<any> {
return getRequest(baseUri, libFile).then((data) => {
const text = new TextDecoder().decode(data);
return JSON.parse(text);
});
}

export async function copyFolder(
fsSource: FSInterface,
dirSource: string,
Expand Down Expand Up @@ -46,3 +61,38 @@ export function recursivelyPrintFs(fs: FSInterface, dir: string, indent: string
}
}
}

export async function extractTgz(
packageData: Uint8Array,
fs: FSInterface,
extractionRoot: string
): Promise<void> {
if (!fs.existsSync(extractionRoot)) {
fs.mkdirSync(extractionRoot, { recursive: true });
}

for await (const entry of Archive.read(pako.ungzip(packageData))) {
// archive entries are prefixed with "package/" -> skip that part
if (!entry.fileName.startsWith("package/")) {
continue;
}
const relativePath = entry.fileName.substring("package/".length);
if (!relativePath) {
continue;
}

const fullPath = path.join(extractionRoot, relativePath);

if (entry.isDirectory()) {
if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath, { recursive: true });
}
} else if (entry.isFile()) {
const dirPath = path.dirname(fullPath);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
fs.writeFileSync(fullPath, entry.content!);
}
}
}
Loading