@utoo/web 0.0.1-alpha.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ import { PackFile, ProjectEndpoint } from "./type";
2
+ export declare class ForkedProject implements ProjectEndpoint {
3
+ private endpoint;
4
+ constructor(port: MessagePort);
5
+ install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
6
+ build(): Promise<import("./type").BuildOutput>;
7
+ readFile(path: string, encoding?: "utf8"): Promise<any>;
8
+ writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
9
+ copyFile(src: string, dst: string): Promise<void>;
10
+ readdir(path: string, options?: {
11
+ recursive?: boolean;
12
+ }): Promise<import("./type").Dirent[]>;
13
+ mkdir(path: string, options?: {
14
+ recursive?: boolean;
15
+ }): Promise<void>;
16
+ rm(path: string, options?: {
17
+ recursive?: boolean;
18
+ }): Promise<void>;
19
+ rmdir(path: string, options?: {
20
+ recursive?: boolean;
21
+ }): Promise<void>;
22
+ gzip(files: PackFile[]): Promise<Uint8Array>;
23
+ sigMd5(content: Uint8Array): Promise<string>;
24
+ }
@@ -0,0 +1,40 @@
1
+ import * as comlink from "comlink";
2
+ export class ForkedProject {
3
+ constructor(port) {
4
+ var _a;
5
+ (_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
6
+ }
7
+ async install(packageLock, maxConcurrentDownloads) {
8
+ return await this.endpoint.install(packageLock, maxConcurrentDownloads);
9
+ }
10
+ async build() {
11
+ return await this.endpoint.build();
12
+ }
13
+ async readFile(path, encoding) {
14
+ return (await this.endpoint.readFile(path, encoding));
15
+ }
16
+ async writeFile(path, content, encoding) {
17
+ return await this.endpoint.writeFile(path, content, encoding);
18
+ }
19
+ async copyFile(src, dst) {
20
+ return await this.endpoint.copyFile(src, dst);
21
+ }
22
+ async readdir(path, options) {
23
+ return await this.endpoint.readdir(path, options);
24
+ }
25
+ async mkdir(path, options) {
26
+ return await this.endpoint.mkdir(path, options);
27
+ }
28
+ async rm(path, options) {
29
+ return await this.endpoint.rm(path, options);
30
+ }
31
+ async rmdir(path, options) {
32
+ return await this.endpoint.rmdir(path, options);
33
+ }
34
+ async gzip(files) {
35
+ return await this.endpoint.gzip(files);
36
+ }
37
+ async sigMd5(content) {
38
+ return await this.endpoint.sigMd5(content);
39
+ }
40
+ }
package/esm/index.d.ts CHANGED
@@ -1,22 +1,2 @@
1
- import { Dirent, ProjectEndpoint } from "./type";
2
- import { MountOpt } from "./worker";
3
- export declare class Project implements ProjectEndpoint {
4
- #private;
5
- private remote;
6
- constructor(opt: MountOpt & {
7
- worker?: Worker;
8
- });
9
- install(packageLock: string): Promise<void>;
10
- build(): Promise<void>;
11
- readFile(path: string, encoding?: "utf8"): Promise<any>;
12
- writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
13
- copyFile(src: string, dst: string): Promise<void>;
14
- readdir(path: string, options?: {
15
- recursive?: boolean;
16
- }): Promise<Dirent[]>;
17
- mkdir(path: string, options?: {
18
- recursive?: boolean;
19
- }): Promise<void>;
20
- static fork(channel: MessageChannel): ProjectEndpoint;
21
- }
1
+ export { Project } from "./project";
22
2
  export * from "./type";
package/esm/index.js CHANGED
@@ -1,103 +1,2 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _Project_tunnel;
13
- import * as comlink from "comlink";
14
- import { Fork, HandShake } from "./message";
15
- import { Dirent } from "./type";
16
- let ProjectWorker;
17
- const ConnectedPorts = new Set();
18
- export class Project {
19
- constructor(opt) {
20
- var _a, _b;
21
- _Project_tunnel.set(this, void 0);
22
- const { cwd, worker, wasmUrl } = opt;
23
- const { port1, port2 } = new MessageChannel();
24
- (_a = this.remote) !== null && _a !== void 0 ? _a : (this.remote = comlink.wrap(port1));
25
- if (!ProjectWorker) {
26
- ProjectWorker =
27
- worker || new Worker(new URL("./worker", import.meta.url));
28
- self.addEventListener("message", (e) => {
29
- const port = e.ports[0];
30
- if (e.data === Fork && !ConnectedPorts.has(port)) {
31
- ProjectWorker.postMessage(HandShake, [port]);
32
- }
33
- });
34
- }
35
- ProjectWorker.postMessage(HandShake, [port2]);
36
- __classPrivateFieldSet(this, _Project_tunnel, (_b = __classPrivateFieldGet(this, _Project_tunnel, "f")) !== null && _b !== void 0 ? _b : this.remote.mount({ cwd, wasmUrl }), "f");
37
- }
38
- async install(packageLock) {
39
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
40
- return await this.remote.install(packageLock);
41
- }
42
- async build() {
43
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
44
- return await this.remote.build();
45
- }
46
- async readFile(path, encoding) {
47
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
48
- return (await this.remote.readFile(path, encoding));
49
- }
50
- async writeFile(path, content, encoding) {
51
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
52
- return await this.remote.writeFile(path, content, encoding);
53
- }
54
- async copyFile(src, dst) {
55
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
56
- return await this.remote.copyFile(src, dst);
57
- }
58
- async readdir(path, options) {
59
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
60
- const dirEntry = (await this.remote.readdir(path, options));
61
- return dirEntry.map((e) => new Dirent(e));
62
- }
63
- async mkdir(path, options) {
64
- await __classPrivateFieldGet(this, _Project_tunnel, "f");
65
- return await this.remote.mkdir(path, options);
66
- }
67
- static fork(channel) {
68
- self.postMessage(Fork, {
69
- targetOrigin: "*",
70
- transfer: [channel.port2],
71
- });
72
- return new ForkedProject(channel.port1);
73
- }
74
- }
75
- _Project_tunnel = new WeakMap();
76
- class ForkedProject {
77
- constructor(port) {
78
- var _a;
79
- (_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
80
- }
81
- async install(packageLock) {
82
- return await this.endpoint.install(packageLock);
83
- }
84
- async build() {
85
- return await this.endpoint.build();
86
- }
87
- async readFile(path, encoding) {
88
- return (await this.endpoint.readFile(path, encoding));
89
- }
90
- async writeFile(path, content, encoding) {
91
- return await this.endpoint.writeFile(path, content, encoding);
92
- }
93
- async copyFile(src, dst) {
94
- return await this.endpoint.copyFile(src, dst);
95
- }
96
- async readdir(path, options) {
97
- return await this.endpoint.readdir(path, options);
98
- }
99
- async mkdir(path, options) {
100
- return await this.endpoint.mkdir(path, options);
101
- }
102
- }
1
+ export { Project } from "./project";
103
2
  export * from "./type";
@@ -0,0 +1 @@
1
+ export declare function installServiceWorker(url: string, scope: string): Promise<void>;
@@ -0,0 +1,36 @@
1
+ import { ServiceWorkerHandShake } from "./message";
2
+ export async function installServiceWorker(url, scope) {
3
+ const registration = await navigator.serviceWorker.register(url, {
4
+ scope: "/",
5
+ });
6
+ return new Promise((resolve) => {
7
+ function sendMessage(sw) {
8
+ sw.postMessage({
9
+ [ServiceWorkerHandShake]: true,
10
+ scope,
11
+ });
12
+ resolve();
13
+ }
14
+ function listenForActivation(sw) {
15
+ sw.addEventListener("statechange", () => {
16
+ if (sw.state === "activated") {
17
+ sendMessage(sw);
18
+ }
19
+ });
20
+ }
21
+ function checkSWState(registration) {
22
+ if (registration.active) {
23
+ sendMessage(registration.active);
24
+ }
25
+ else if (registration.installing) {
26
+ listenForActivation(registration.installing);
27
+ }
28
+ registration.addEventListener("updatefound", () => {
29
+ if (registration.installing) {
30
+ listenForActivation(registration.installing);
31
+ }
32
+ });
33
+ }
34
+ checkSWState(registration);
35
+ });
36
+ }
package/esm/message.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const HandShake = "__handshake__";
2
+ export declare const ServiceWorkerHandShake = "__service_worker_handshake__";
2
3
  export declare const Fork = "__fork__";
package/esm/message.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export const HandShake = "__handshake__";
2
+ export const ServiceWorkerHandShake = "__service_worker_handshake__";
2
3
  export const Fork = "__fork__";
@@ -0,0 +1,30 @@
1
+ import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions } from "./type";
2
+ export declare class Project implements ProjectEndpoint {
3
+ #private;
4
+ private serviceWorkerOptions?;
5
+ private remote;
6
+ constructor(options: ProjectOptions);
7
+ private connectWorker;
8
+ installServiceWorker(): Promise<void>;
9
+ mount(): Promise<void>;
10
+ install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
11
+ build(): Promise<BuildOutput>;
12
+ readFile(path: string, encoding?: "utf8"): Promise<any>;
13
+ writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
14
+ copyFile(src: string, dst: string): Promise<void>;
15
+ readdir(path: string, options?: {
16
+ recursive?: boolean;
17
+ }): Promise<Dirent[]>;
18
+ mkdir(path: string, options?: {
19
+ recursive?: boolean;
20
+ }): Promise<void>;
21
+ rm(path: string, options?: {
22
+ recursive?: boolean;
23
+ }): Promise<void>;
24
+ rmdir(path: string, options?: {
25
+ recursive?: boolean;
26
+ }): Promise<void>;
27
+ gzip(files: PackFile[]): Promise<Uint8Array>;
28
+ sigMd5(content: Uint8Array): Promise<string>;
29
+ static fork(channel: MessageChannel, eventSource?: Client | DedicatedWorkerGlobalScope): ProjectEndpoint;
30
+ }
package/esm/project.js ADDED
@@ -0,0 +1,120 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _Project_mount;
13
+ import { handleIssues } from "@utoo/pack-shared";
14
+ import * as comlink from "comlink";
15
+ import { ForkedProject } from "./forkedProject";
16
+ import { installServiceWorker } from "./installServiceWorker";
17
+ import { Fork, HandShake } from "./message";
18
+ import { Dirent, } from "./type";
19
+ let ProjectWorker;
20
+ const ConnectedPorts = new Set();
21
+ export class Project {
22
+ constructor(options) {
23
+ var _a, _b;
24
+ _Project_mount.set(this, void 0);
25
+ const { cwd, workerUrl, wasmUrl, threadWorkerUrl, serviceWorker, logFilter, } = options;
26
+ this.serviceWorkerOptions = serviceWorker;
27
+ const { port1, port2 } = new MessageChannel();
28
+ (_a = this.remote) !== null && _a !== void 0 ? _a : (this.remote = comlink.wrap(port1));
29
+ if (!ProjectWorker) {
30
+ ProjectWorker = workerUrl
31
+ ? new Worker(workerUrl)
32
+ : new Worker(new URL("./worker", import.meta.url));
33
+ window.addEventListener("message", (e) => {
34
+ this.connectWorker(e);
35
+ });
36
+ if (this.serviceWorkerOptions) {
37
+ navigator.serviceWorker.addEventListener("message", (e) => {
38
+ this.connectWorker(e);
39
+ });
40
+ }
41
+ }
42
+ ProjectWorker.postMessage(HandShake, [port2]);
43
+ __classPrivateFieldSet(this, _Project_mount, (_b = __classPrivateFieldGet(this, _Project_mount, "f")) !== null && _b !== void 0 ? _b : this.remote.mount({
44
+ cwd,
45
+ wasmUrl,
46
+ threadWorkerUrl,
47
+ logFilter,
48
+ }), "f");
49
+ }
50
+ connectWorker(e) {
51
+ const port = e.ports[0];
52
+ if (e.data === Fork && !ConnectedPorts.has(port)) {
53
+ ProjectWorker.postMessage(HandShake, [port]);
54
+ }
55
+ }
56
+ async installServiceWorker() {
57
+ if (this.serviceWorkerOptions) {
58
+ const { url, scope } = this.serviceWorkerOptions;
59
+ // Should add "Service-Worker-Allowed": "/" in page root response headers,
60
+ return await installServiceWorker(url, scope);
61
+ }
62
+ }
63
+ async mount() {
64
+ return await __classPrivateFieldGet(this, _Project_mount, "f");
65
+ }
66
+ async install(packageLock, maxConcurrentDownloads) {
67
+ await __classPrivateFieldGet(this, _Project_mount, "f");
68
+ return await this.remote.install(packageLock, maxConcurrentDownloads);
69
+ }
70
+ async build() {
71
+ await __classPrivateFieldGet(this, _Project_mount, "f");
72
+ const res = await this.remote.build();
73
+ handleIssues(res.issues, false, false);
74
+ return res;
75
+ }
76
+ async readFile(path, encoding) {
77
+ await __classPrivateFieldGet(this, _Project_mount, "f");
78
+ return (await this.remote.readFile(path, encoding));
79
+ }
80
+ async writeFile(path, content, encoding) {
81
+ await __classPrivateFieldGet(this, _Project_mount, "f");
82
+ return await this.remote.writeFile(path, content, encoding);
83
+ }
84
+ async copyFile(src, dst) {
85
+ await __classPrivateFieldGet(this, _Project_mount, "f");
86
+ return await this.remote.copyFile(src, dst);
87
+ }
88
+ async readdir(path, options) {
89
+ await __classPrivateFieldGet(this, _Project_mount, "f");
90
+ const dirEntry = (await this.remote.readdir(path, options));
91
+ return dirEntry.map((e) => new Dirent(e));
92
+ }
93
+ async mkdir(path, options) {
94
+ await __classPrivateFieldGet(this, _Project_mount, "f");
95
+ return await this.remote.mkdir(path, options);
96
+ }
97
+ async rm(path, options) {
98
+ await __classPrivateFieldGet(this, _Project_mount, "f");
99
+ return await this.remote.rm(path, options);
100
+ }
101
+ async rmdir(path, options) {
102
+ await __classPrivateFieldGet(this, _Project_mount, "f");
103
+ return await this.remote.rmdir(path, options);
104
+ }
105
+ async gzip(files) {
106
+ await __classPrivateFieldGet(this, _Project_mount, "f");
107
+ return await this.remote.gzip(files);
108
+ }
109
+ async sigMd5(content) {
110
+ await __classPrivateFieldGet(this, _Project_mount, "f");
111
+ return await this.remote.sigMd5(content);
112
+ }
113
+ static fork(channel, eventSource) {
114
+ (eventSource || self).postMessage(Fork, {
115
+ transfer: [channel.port2],
116
+ });
117
+ return new ForkedProject(channel.port1);
118
+ }
119
+ }
120
+ _Project_mount = new WeakMap();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { Project } from ".";
2
+ import { ServiceWorkerHandShake } from "./message";
3
+ let _resolve;
4
+ let _promise = new Promise((resolve) => {
5
+ _resolve = resolve;
6
+ });
7
+ let _projectEndpoint;
8
+ let _serviceWorkerScope;
9
+ self.addEventListener("install", (event) => {
10
+ event.waitUntil(self.skipWaiting());
11
+ });
12
+ self.addEventListener("activate", (event) => {
13
+ event.waitUntil(self.clients.claim());
14
+ });
15
+ self.addEventListener("message", (event) => {
16
+ if (event.data && event.data[ServiceWorkerHandShake] === true) {
17
+ _serviceWorkerScope = event.data.scope;
18
+ _projectEndpoint = Project.fork(new MessageChannel(), event.source);
19
+ _resolve();
20
+ }
21
+ });
22
+ self.addEventListener("fetch", async (event) => {
23
+ await _promise;
24
+ const { url, referrer } = event.request;
25
+ if (new URL(url).pathname.startsWith(_serviceWorkerScope) ||
26
+ (referrer && new URL(referrer).pathname.startsWith(_serviceWorkerScope))) {
27
+ const projectPath = "." + new URL(url).pathname.replace(_serviceWorkerScope, "");
28
+ event.respondWith(readFileFromProject(projectPath));
29
+ }
30
+ else {
31
+ return;
32
+ }
33
+ });
34
+ async function readFileFromProject(projectPath) {
35
+ try {
36
+ const content = await _projectEndpoint.readFile(projectPath);
37
+ let mimeType = "application/octet-stream";
38
+ if (projectPath.endsWith(".js")) {
39
+ mimeType = "application/javascript";
40
+ }
41
+ else if (projectPath.endsWith(".css")) {
42
+ mimeType = "text/css";
43
+ }
44
+ else if (projectPath.endsWith(".html")) {
45
+ mimeType = "text/html";
46
+ }
47
+ else if (projectPath.endsWith(".json")) {
48
+ mimeType = "application/json";
49
+ }
50
+ return new Response(content, {
51
+ headers: {
52
+ "Content-Type": mimeType,
53
+ ...(mimeType === "text/html"
54
+ ? { "Cross-Origin-Embedder-Policy": "require-corp" }
55
+ : {}),
56
+ },
57
+ });
58
+ }
59
+ catch (e) {
60
+ return new Response("Not Found", { status: 404 });
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import initWasm from "./utoo";
2
+ // Read logFilter from URL query string and set to globalThis
3
+ const urlParams = new URLSearchParams(self.location.search);
4
+ const logFilter = urlParams.get("logFilter");
5
+ if (logFilter) {
6
+ globalThis.__UTOO_LOG_FILTER__ = logFilter;
7
+ }
8
+ // this is for wasm_thread to spawn new worker thread.
9
+ // see: https://github.com/utooland/wasm_thread/blob/94438ff771ee0a6a55d79e49a655707970acb615/src/wasm32/js/web_worker.js#L10
10
+ self.wasm_bindgen = initWasm;
package/esm/type.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Issue } from "@utoo/pack-shared";
1
2
  import { DirEntryType } from "./utoo";
2
3
  export interface RawDirent {
3
4
  name: string;
@@ -10,9 +11,16 @@ export declare class Dirent {
10
11
  isDirectory(): boolean;
11
12
  isFile(): boolean;
12
13
  }
14
+ export interface BuildOutput {
15
+ issues: Issue[];
16
+ }
17
+ export interface PackFile {
18
+ path: string;
19
+ content: Uint8Array;
20
+ }
13
21
  export interface ProjectEndpoint {
14
- install: (packageLock: string) => Promise<void>;
15
- build: () => Promise<void>;
22
+ install: (packageLock: string, maxConcurrentDownloads?: number) => Promise<void>;
23
+ build: () => Promise<BuildOutput>;
16
24
  readFile(path: string): Promise<Uint8Array>;
17
25
  readFile(path: string, encoding?: "utf8"): Promise<string>;
18
26
  writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
@@ -22,7 +30,25 @@ export interface ProjectEndpoint {
22
30
  mkdir(path: string, options?: {
23
31
  recursive?: boolean;
24
32
  }): Promise<void>;
33
+ rm(path: string, options?: {
34
+ recursive?: boolean;
35
+ }): Promise<void>;
36
+ rmdir(path: string, options?: {
37
+ recursive?: boolean;
38
+ }): Promise<void>;
25
39
  copyFile(src: string, dst: string): Promise<void>;
40
+ gzip: (files: PackFile[]) => Promise<Uint8Array>;
41
+ sigMd5: (content: Uint8Array) => Promise<string>;
26
42
  }
27
- export interface ProjectEndpoint {
43
+ export interface ProjectOptions {
44
+ cwd: string;
45
+ workerUrl?: string;
46
+ threadWorkerUrl: string;
47
+ wasmUrl?: string;
48
+ serviceWorker?: ServiceWorkerOptions;
49
+ logFilter?: string;
50
+ }
51
+ export interface ServiceWorkerOptions {
52
+ url: string;
53
+ scope: string;
28
54
  }
@@ -37,37 +37,75 @@ export class DirEntry {
37
37
  */
38
38
  get type(): DirEntryType;
39
39
  }
40
+ export class Metadata {
41
+ static __wrap(ptr: any): any;
42
+ toJSON(): {};
43
+ toString(): string;
44
+ __destroy_into_raw(): number | undefined;
45
+ __wbg_ptr: number | undefined;
46
+ free(): void;
47
+ }
40
48
  export class Project {
41
49
  /**
42
50
  * @param {string} cwd
51
+ * @param {string} thread_url
43
52
  */
44
- constructor(cwd: string);
53
+ constructor(cwd: string, thread_url: string);
45
54
  __destroy_into_raw(): number;
46
55
  __wbg_ptr: number;
47
56
  free(): void;
48
57
  /**
49
- * @returns {string}
58
+ * @param {string} path
59
+ * @returns {Promise<void>}
50
60
  */
51
- get cwd(): string;
61
+ createDir(path: string): Promise<void>;
52
62
  /**
53
- * @param {string} package_lock
63
+ * @param {string} path
64
+ * @param {boolean} recursive
54
65
  * @returns {Promise<void>}
55
66
  */
56
- install(package_lock: string): Promise<void>;
67
+ removeDir(path: string, recursive: boolean): Promise<void>;
57
68
  /**
58
- * @returns {Promise<any>}
69
+ * @param {string} path
70
+ * @returns {Promise<void>}
59
71
  */
60
- build(): Promise<any>;
72
+ removeFile(path: string): Promise<void>;
61
73
  /**
62
74
  * @param {string} path
63
- * @returns {Promise<Uint8Array>}
75
+ * @param {string} content
76
+ * @returns {Promise<void>}
64
77
  */
65
- read(path: string): Promise<Uint8Array>;
78
+ writeString(path: string, content: string): Promise<void>;
79
+ /**
80
+ * @param {string} path
81
+ * @returns {Promise<void>}
82
+ */
83
+ createDirAll(path: string): Promise<void>;
66
84
  /**
67
85
  * @param {string} path
68
86
  * @returns {Promise<string>}
69
87
  */
70
88
  readToString(path: string): Promise<string>;
89
+ /**
90
+ * @returns {string}
91
+ */
92
+ get cwd(): string;
93
+ /**
94
+ * Create a tar.gz archive and return bytes (no file I/O)
95
+ * This is useful for main thread execution without OPFS access
96
+ * @param {any} files
97
+ * @returns {Uint8Array}
98
+ */
99
+ gzip(files: any): Uint8Array;
100
+ /**
101
+ * @param {string} path
102
+ * @returns {Promise<Uint8Array>}
103
+ */
104
+ read(path: string): Promise<Uint8Array>;
105
+ /**
106
+ * @returns {Promise<any>}
107
+ */
108
+ build(): Promise<any>;
71
109
  /**
72
110
  * @param {string} path
73
111
  * @param {Uint8Array} content
@@ -75,26 +113,27 @@ export class Project {
75
113
  */
76
114
  write(path: string, content: Uint8Array): Promise<void>;
77
115
  /**
78
- * @param {string} path
79
- * @param {string} content
116
+ * @param {string} package_lock
117
+ * @param {number | null} [max_concurrent_downloads]
80
118
  * @returns {Promise<void>}
81
119
  */
82
- writeString(path: string, content: string): Promise<void>;
120
+ install(package_lock: string, max_concurrent_downloads?: number | null): Promise<void>;
83
121
  /**
84
- * @param {string} path
85
- * @returns {Promise<DirEntry[]>}
122
+ * Calculate MD5 hash of byte content
123
+ * @param {Uint8Array} content
124
+ * @returns {string}
86
125
  */
87
- readDir(path: string): Promise<DirEntry[]>;
126
+ sigMd5(content: Uint8Array): string;
88
127
  /**
89
128
  * @param {string} path
90
- * @returns {Promise<void>}
129
+ * @returns {Promise<Metadata>}
91
130
  */
92
- createDir(path: string): Promise<void>;
131
+ metadata(path: string): Promise<Metadata>;
93
132
  /**
94
133
  * @param {string} path
95
- * @returns {Promise<void>}
134
+ * @returns {Promise<DirEntry[]>}
96
135
  */
97
- createDirAll(path: string): Promise<void>;
136
+ readDir(path: string): Promise<DirEntry[]>;
98
137
  /**
99
138
  * @param {string} src
100
139
  * @param {string} dst