@utoo/web 1.1.0 → 1.2.0-rc.10
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.
- package/README.md +55 -0
- package/esm/a0a815481b4ff49f8961.wasm +0 -0
- package/esm/index.d.ts +3 -2
- package/esm/index.js +3 -2
- package/esm/loaderWorker.js +2 -0
- package/esm/loaderWorker.js.LICENSE.txt +23 -0
- package/esm/{forkedProject.d.ts → project/ForkedProject.d.ts} +5 -3
- package/esm/{forkedProject.js → project/ForkedProject.js} +8 -0
- package/esm/{internalProject.d.ts → project/InternalProject.d.ts} +5 -3
- package/esm/project/InternalProject.js +132 -0
- package/esm/{project.d.ts → project/Project.d.ts} +4 -1
- package/esm/{project.js → project/Project.js} +21 -6
- package/esm/serviceWorker.js +4 -3
- package/esm/{type.d.ts → types.d.ts} +44 -0
- package/esm/types.js +56 -0
- package/esm/utils/sabcom.d.ts +61 -0
- package/esm/utils/sabcom.js +203 -0
- package/esm/utoo/index.d.ts +126 -66
- package/esm/utoo/index.js +351 -235
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/cjs.js +299 -0
- package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
- package/esm/webpackLoaders/loaderWorkerPool.js +90 -0
- package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
- package/esm/webpackLoaders/polyfills/fsPolyfill.js +279 -0
- package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
- package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
- package/esm/webpackLoaders/polyfills/nodePolyFills.d.ts +92 -0
- package/esm/webpackLoaders/polyfills/nodePolyFills.js +230 -0
- package/esm/webpackLoaders/polyfills/workerThreadsPolyfill.d.ts +7 -0
- package/esm/webpackLoaders/polyfills/workerThreadsPolyfill.js +16 -0
- package/esm/webpackLoaders/{worker/type.d.ts → types.d.ts} +2 -1
- package/esm/webpackLoaders/worker.d.ts +2 -0
- package/esm/webpackLoaders/worker.js +46 -0
- package/esm/worker.js +2 -2
- package/package.json +19 -18
- package/esm/internalProject.js +0 -185
- package/esm/type.js +0 -12
- package/esm/webpackLoaders/loaders/less-loader/index.d.ts +0 -3
- package/esm/webpackLoaders/loaders/less-loader/index.js +0 -103
- package/esm/webpackLoaders/loaders/less-loader/options.json +0 -67
- package/esm/webpackLoaders/loaders/less-loader/utils.d.ts +0 -14
- package/esm/webpackLoaders/loaders/less-loader/utils.js +0 -217
- package/esm/webpackLoaders/worker/cjs.js +0 -80
- package/esm/webpackLoaders/worker/index.d.ts +0 -2
- package/esm/webpackLoaders/worker/index.js +0 -31
- package/esm/webpackLoaders/worker/nodePolyFills.d.ts +0 -14
- package/esm/webpackLoaders/worker/nodePolyFills.js +0 -24
- package/esm/webpackLoaders/workerContent.d.ts +0 -2
- package/esm/webpackLoaders/workerContent.js +0 -1
- /package/esm/{installServiceWorker.d.ts → utils/installServiceWorker.d.ts} +0 -0
- /package/esm/{installServiceWorker.js → utils/installServiceWorker.js} +0 -0
- /package/esm/{message.d.ts → utils/message.d.ts} +0 -0
- /package/esm/{message.js → utils/message.js} +0 -0
- /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
- /package/esm/webpackLoaders/{worker/type.js → types.js} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SystemJS 6.15.1
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/*!
|
|
6
|
+
* The buffer module from node.js, for the browser.
|
|
7
|
+
*
|
|
8
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*!
|
|
13
|
+
* The buffer module from node.js, for the browser.
|
|
14
|
+
*
|
|
15
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
16
|
+
* @license MIT
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */
|
|
20
|
+
|
|
21
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
22
|
+
|
|
23
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { PackFile, ProjectEndpoint } from "
|
|
1
|
+
import { DepsOptions, PackFile, ProjectEndpoint, Stats } from "../types";
|
|
2
2
|
export declare class ForkedProject implements ProjectEndpoint {
|
|
3
3
|
private endpoint;
|
|
4
4
|
constructor(port: MessagePort);
|
|
5
|
+
deps(options?: DepsOptions): Promise<string>;
|
|
5
6
|
install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
|
|
6
|
-
build(): Promise<import("
|
|
7
|
+
build(): Promise<import("..").BuildOutput>;
|
|
7
8
|
readFile(path: string, encoding?: "utf8"): Promise<any>;
|
|
8
9
|
writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
|
|
9
10
|
copyFile(src: string, dst: string): Promise<void>;
|
|
10
11
|
readdir(path: string, options?: {
|
|
11
12
|
recursive?: boolean;
|
|
12
|
-
}): Promise<import("
|
|
13
|
+
}): Promise<import("..").Dirent[]>;
|
|
13
14
|
mkdir(path: string, options?: {
|
|
14
15
|
recursive?: boolean;
|
|
15
16
|
}): Promise<void>;
|
|
@@ -19,6 +20,7 @@ export declare class ForkedProject implements ProjectEndpoint {
|
|
|
19
20
|
rmdir(path: string, options?: {
|
|
20
21
|
recursive?: boolean;
|
|
21
22
|
}): Promise<void>;
|
|
23
|
+
stat(path: string): Promise<Stats>;
|
|
22
24
|
gzip(files: PackFile[]): Promise<Uint8Array>;
|
|
23
25
|
sigMd5(content: Uint8Array): Promise<string>;
|
|
24
26
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as comlink from "comlink";
|
|
2
|
+
import { Stats, } from "../types";
|
|
2
3
|
export class ForkedProject {
|
|
3
4
|
constructor(port) {
|
|
4
5
|
var _a;
|
|
5
6
|
(_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
|
|
6
7
|
}
|
|
8
|
+
async deps(options) {
|
|
9
|
+
return await this.endpoint.deps(options);
|
|
10
|
+
}
|
|
7
11
|
async install(packageLock, maxConcurrentDownloads) {
|
|
8
12
|
return await this.endpoint.install(packageLock, maxConcurrentDownloads);
|
|
9
13
|
}
|
|
@@ -31,6 +35,10 @@ export class ForkedProject {
|
|
|
31
35
|
async rmdir(path, options) {
|
|
32
36
|
return await this.endpoint.rmdir(path, options);
|
|
33
37
|
}
|
|
38
|
+
async stat(path) {
|
|
39
|
+
const raw = (await this.endpoint.stat(path));
|
|
40
|
+
return new Stats(raw);
|
|
41
|
+
}
|
|
34
42
|
async gzip(files) {
|
|
35
43
|
return await this.endpoint.gzip(files);
|
|
36
44
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { PackFile, ProjectEndpoint, ProjectOptions } from "
|
|
2
|
-
import initWasm
|
|
1
|
+
import { DepsOptions, PackFile, ProjectEndpoint, ProjectOptions, Stats } from "../types";
|
|
2
|
+
import initWasm from "../utoo";
|
|
3
3
|
declare class InternalEndpoint implements ProjectEndpoint {
|
|
4
|
-
projectInternal?: ProjectInternal;
|
|
5
4
|
wasmInit?: ReturnType<typeof initWasm>;
|
|
6
5
|
options?: Omit<ProjectOptions, "workerUrl" | "serviceWorker">;
|
|
6
|
+
loaderWorkerPoolInitialized: boolean;
|
|
7
7
|
mount(opt: Omit<ProjectOptions, "workerUrl" | "serviceWorker">): Promise<void>;
|
|
8
|
+
deps(options?: DepsOptions): Promise<string>;
|
|
8
9
|
install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
|
|
9
10
|
build(): Promise<any>;
|
|
10
11
|
readFile(path: string, encoding?: "utf8"): Promise<any>;
|
|
11
12
|
writeFile(path: string, content: string | Uint8Array, _encoding?: "utf8"): Promise<void>;
|
|
12
13
|
copyFile(src: string, dst: string): Promise<void>;
|
|
14
|
+
stat(path: string): Promise<Stats>;
|
|
13
15
|
readdir(path: string, options?: {
|
|
14
16
|
recursive?: boolean;
|
|
15
17
|
}): Promise<any>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as comlink from "comlink";
|
|
2
|
+
import initWasm, { initLogFilter, Project as ProjectInternal, } from "../utoo";
|
|
3
|
+
import { runLoaderWorkerPool } from "../webpackLoaders/loaderWorkerPool";
|
|
4
|
+
class InternalEndpoint {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.loaderWorkerPoolInitialized = false;
|
|
7
|
+
}
|
|
8
|
+
// This should be called only once
|
|
9
|
+
async mount(opt) {
|
|
10
|
+
var _a;
|
|
11
|
+
this.options = opt;
|
|
12
|
+
const { cwd, wasmUrl, threadWorkerUrl, logFilter } = opt;
|
|
13
|
+
(_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
|
|
14
|
+
await this.wasmInit;
|
|
15
|
+
// Initialize log filter after wasm init
|
|
16
|
+
const filter = logFilter ||
|
|
17
|
+
"pack_core=info,pack_api=info,utoo_wasm=info,utoo_ruborist=info";
|
|
18
|
+
initLogFilter(filter);
|
|
19
|
+
const absoluteCwd = cwd.startsWith("/") ? cwd : "/" + cwd;
|
|
20
|
+
ProjectInternal.init(threadWorkerUrl || "");
|
|
21
|
+
ProjectInternal.setCwd(absoluteCwd);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
async deps(options) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
await this.wasmInit;
|
|
27
|
+
return await ProjectInternal.deps((_a = options === null || options === void 0 ? void 0 : options.registry) !== null && _a !== void 0 ? _a : undefined, (_b = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _b !== void 0 ? _b : undefined);
|
|
28
|
+
}
|
|
29
|
+
async install(packageLock, maxConcurrentDownloads) {
|
|
30
|
+
await this.wasmInit;
|
|
31
|
+
await ProjectInternal.install(packageLock, maxConcurrentDownloads);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
async build() {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const binding = await this.wasmInit;
|
|
37
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.loaderWorkerUrl) && !this.loaderWorkerPoolInitialized) {
|
|
38
|
+
runLoaderWorkerPool(binding, this.options.cwd, this.options.loaderWorkerUrl, (_b = this.options) === null || _b === void 0 ? void 0 : _b.loadersImportMap);
|
|
39
|
+
this.loaderWorkerPoolInitialized = true;
|
|
40
|
+
}
|
|
41
|
+
return await ProjectInternal.build();
|
|
42
|
+
}
|
|
43
|
+
async readFile(path, encoding) {
|
|
44
|
+
await this.wasmInit;
|
|
45
|
+
let ret;
|
|
46
|
+
if (encoding === "utf8") {
|
|
47
|
+
ret = await ProjectInternal.readToString(path);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
ret = await ProjectInternal.read(path);
|
|
51
|
+
return comlink.transfer(ret, [ret.buffer]);
|
|
52
|
+
}
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
async writeFile(path, content, _encoding) {
|
|
56
|
+
await this.wasmInit;
|
|
57
|
+
if (typeof content === "string") {
|
|
58
|
+
return await ProjectInternal.writeString(path, content);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return await ProjectInternal.write(path, content);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async copyFile(src, dst) {
|
|
65
|
+
await this.wasmInit;
|
|
66
|
+
return await ProjectInternal.copyFile(src, dst);
|
|
67
|
+
}
|
|
68
|
+
async stat(path) {
|
|
69
|
+
await this.wasmInit;
|
|
70
|
+
const metadata = await ProjectInternal.metadata(path);
|
|
71
|
+
const json = metadata.toJSON();
|
|
72
|
+
const raw = {
|
|
73
|
+
type: json.type,
|
|
74
|
+
size: Number(json.file_size),
|
|
75
|
+
};
|
|
76
|
+
// WARN: This is a hack, functions can not be structurally cloned
|
|
77
|
+
return raw;
|
|
78
|
+
}
|
|
79
|
+
async readdir(path, options) {
|
|
80
|
+
await this.wasmInit;
|
|
81
|
+
const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
|
|
82
|
+
? await ProjectInternal.readDir(path)
|
|
83
|
+
: // TODO: support recursive readDirAll
|
|
84
|
+
await ProjectInternal.readDir(path);
|
|
85
|
+
const rawDirents = dirEntries.map((e) => {
|
|
86
|
+
const dir = e.toJSON();
|
|
87
|
+
return {
|
|
88
|
+
name: dir.name,
|
|
89
|
+
type: dir.type,
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
// WARN: This is a hack, functions can not be structurally cloned
|
|
93
|
+
return rawDirents;
|
|
94
|
+
}
|
|
95
|
+
async mkdir(path, options) {
|
|
96
|
+
await this.wasmInit;
|
|
97
|
+
if (options === null || options === void 0 ? void 0 : options.recursive) {
|
|
98
|
+
return await ProjectInternal.createDirAll(path);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return await ProjectInternal.createDir(path);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async rm(path, options) {
|
|
105
|
+
await this.wasmInit;
|
|
106
|
+
let metadata = (await ProjectInternal.metadata(path)).toJSON();
|
|
107
|
+
switch (metadata.type) {
|
|
108
|
+
case "file":
|
|
109
|
+
return await ProjectInternal.removeFile(path);
|
|
110
|
+
case "directory":
|
|
111
|
+
return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
|
|
112
|
+
default:
|
|
113
|
+
// nothing to remove now
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async rmdir(path, options) {
|
|
118
|
+
await this.wasmInit;
|
|
119
|
+
return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
|
|
120
|
+
}
|
|
121
|
+
async gzip(files) {
|
|
122
|
+
await this.wasmInit;
|
|
123
|
+
const ret = await ProjectInternal.gzip(files);
|
|
124
|
+
return comlink.transfer(ret, [ret.buffer]);
|
|
125
|
+
}
|
|
126
|
+
async sigMd5(content) {
|
|
127
|
+
await this.wasmInit;
|
|
128
|
+
return await ProjectInternal.sigMd5(content);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const internalEndpoint = new InternalEndpoint();
|
|
132
|
+
export { internalEndpoint };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions } from "
|
|
1
|
+
import { BuildOutput, DepsOptions, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "../types";
|
|
2
2
|
export declare class Project implements ProjectEndpoint {
|
|
3
3
|
#private;
|
|
4
|
+
private options;
|
|
4
5
|
readonly cwd: string;
|
|
5
6
|
readonly serviceWorkerOptions?: ServiceWorkerOptions;
|
|
6
7
|
private remote;
|
|
@@ -8,6 +9,7 @@ export declare class Project implements ProjectEndpoint {
|
|
|
8
9
|
private connectWorker;
|
|
9
10
|
installServiceWorker(): Promise<void>;
|
|
10
11
|
mount(): Promise<void>;
|
|
12
|
+
deps(options?: DepsOptions): Promise<string>;
|
|
11
13
|
install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
|
|
12
14
|
build(): Promise<BuildOutput>;
|
|
13
15
|
readFile(path: string, encoding?: "utf8"): Promise<any>;
|
|
@@ -25,6 +27,7 @@ export declare class Project implements ProjectEndpoint {
|
|
|
25
27
|
rmdir(path: string, options?: {
|
|
26
28
|
recursive?: boolean;
|
|
27
29
|
}): Promise<void>;
|
|
30
|
+
stat(path: string): Promise<Stats>;
|
|
28
31
|
gzip(files: PackFile[]): Promise<Uint8Array>;
|
|
29
32
|
sigMd5(content: Uint8Array): Promise<string>;
|
|
30
33
|
static fork(channel: MessageChannel, eventSource?: Client | DedicatedWorkerGlobalScope): ProjectEndpoint;
|
|
@@ -12,15 +12,16 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
12
12
|
var _Project_mount;
|
|
13
13
|
import { handleIssues } from "@utoo/pack-shared";
|
|
14
14
|
import * as comlink from "comlink";
|
|
15
|
-
import {
|
|
16
|
-
import { installServiceWorker } from "
|
|
17
|
-
import { Fork, HandShake } from "
|
|
18
|
-
import {
|
|
15
|
+
import { Dirent, Stats, } from "../types";
|
|
16
|
+
import { installServiceWorker } from "../utils/installServiceWorker";
|
|
17
|
+
import { Fork, HandShake } from "../utils/message";
|
|
18
|
+
import { ForkedProject } from "./ForkedProject";
|
|
19
19
|
let ProjectWorker;
|
|
20
20
|
const ConnectedPorts = new Set();
|
|
21
21
|
export class Project {
|
|
22
22
|
constructor(options) {
|
|
23
23
|
var _a, _b;
|
|
24
|
+
this.options = options;
|
|
24
25
|
_Project_mount.set(this, void 0);
|
|
25
26
|
const { cwd, workerUrl, wasmUrl, threadWorkerUrl, serviceWorker, logFilter, loadersImportMap, } = options;
|
|
26
27
|
this.cwd = cwd;
|
|
@@ -43,6 +44,7 @@ export class Project {
|
|
|
43
44
|
cwd,
|
|
44
45
|
wasmUrl,
|
|
45
46
|
threadWorkerUrl,
|
|
47
|
+
loaderWorkerUrl: this.options.loaderWorkerUrl,
|
|
46
48
|
loadersImportMap,
|
|
47
49
|
logFilter,
|
|
48
50
|
}), "f");
|
|
@@ -63,6 +65,10 @@ export class Project {
|
|
|
63
65
|
async mount() {
|
|
64
66
|
return await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
65
67
|
}
|
|
68
|
+
async deps(options) {
|
|
69
|
+
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
70
|
+
return await this.remote.deps(options);
|
|
71
|
+
}
|
|
66
72
|
async install(packageLock, maxConcurrentDownloads) {
|
|
67
73
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
68
74
|
return await this.remote.install(packageLock, maxConcurrentDownloads);
|
|
@@ -79,6 +85,9 @@ export class Project {
|
|
|
79
85
|
}
|
|
80
86
|
async writeFile(path, content, encoding) {
|
|
81
87
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
88
|
+
if (content instanceof Uint8Array) {
|
|
89
|
+
return await this.remote.writeFile(path, comlink.transfer(content, [content.buffer]), encoding);
|
|
90
|
+
}
|
|
82
91
|
return await this.remote.writeFile(path, content, encoding);
|
|
83
92
|
}
|
|
84
93
|
async copyFile(src, dst) {
|
|
@@ -102,13 +111,19 @@ export class Project {
|
|
|
102
111
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
103
112
|
return await this.remote.rmdir(path, options);
|
|
104
113
|
}
|
|
114
|
+
async stat(path) {
|
|
115
|
+
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
116
|
+
const raw = (await this.remote.stat(path));
|
|
117
|
+
return new Stats(raw);
|
|
118
|
+
}
|
|
105
119
|
async gzip(files) {
|
|
106
120
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
107
|
-
|
|
121
|
+
const buffers = files.map((f) => f.content.buffer);
|
|
122
|
+
return await this.remote.gzip(comlink.transfer(files, buffers));
|
|
108
123
|
}
|
|
109
124
|
async sigMd5(content) {
|
|
110
125
|
await __classPrivateFieldGet(this, _Project_mount, "f");
|
|
111
|
-
return await this.remote.sigMd5(content);
|
|
126
|
+
return await this.remote.sigMd5(comlink.transfer(content, [content.buffer]));
|
|
112
127
|
}
|
|
113
128
|
static fork(channel, eventSource) {
|
|
114
129
|
(eventSource || self).postMessage(Fork, {
|
package/esm/serviceWorker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Project } from "
|
|
2
|
-
import { ServiceWorkerHandShake } from "./message";
|
|
1
|
+
import { Project } from "./project/Project";
|
|
2
|
+
import { ServiceWorkerHandShake } from "./utils/message";
|
|
3
3
|
let _resolve;
|
|
4
4
|
let _promise = new Promise((resolve) => {
|
|
5
5
|
_resolve = resolve;
|
|
@@ -54,12 +54,13 @@ async function readFileFromProject(projectPath) {
|
|
|
54
54
|
headers: {
|
|
55
55
|
"Content-Type": mimeType,
|
|
56
56
|
...(mimeType === "text/html"
|
|
57
|
-
? { "Cross-Origin-Embedder-Policy": "
|
|
57
|
+
? { "Cross-Origin-Embedder-Policy": "credentialless" }
|
|
58
58
|
: {}),
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
catch (e) {
|
|
63
|
+
console.error(`File ${projectPath} not found`);
|
|
63
64
|
return new Response("Not Found", { status: 404 });
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -4,6 +4,43 @@ export interface RawDirent {
|
|
|
4
4
|
name: string;
|
|
5
5
|
type: DirEntryType;
|
|
6
6
|
}
|
|
7
|
+
export interface RawStats {
|
|
8
|
+
type: DirEntryType;
|
|
9
|
+
size: number;
|
|
10
|
+
atimeMs?: number;
|
|
11
|
+
mtimeMs?: number;
|
|
12
|
+
ctimeMs?: number;
|
|
13
|
+
birthtimeMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class Stats {
|
|
16
|
+
private raw;
|
|
17
|
+
dev: number;
|
|
18
|
+
ino: number;
|
|
19
|
+
mode: number;
|
|
20
|
+
nlink: number;
|
|
21
|
+
uid: number;
|
|
22
|
+
gid: number;
|
|
23
|
+
rdev: number;
|
|
24
|
+
size: number;
|
|
25
|
+
blksize: number;
|
|
26
|
+
blocks: number;
|
|
27
|
+
atimeMs: number;
|
|
28
|
+
mtimeMs: number;
|
|
29
|
+
ctimeMs: number;
|
|
30
|
+
birthtimeMs: number;
|
|
31
|
+
atime: Date;
|
|
32
|
+
mtime: Date;
|
|
33
|
+
ctime: Date;
|
|
34
|
+
birthtime: Date;
|
|
35
|
+
constructor(raw: RawStats);
|
|
36
|
+
isDirectory(): boolean;
|
|
37
|
+
isFile(): boolean;
|
|
38
|
+
isSymbolicLink(): boolean;
|
|
39
|
+
isBlockDevice(): boolean;
|
|
40
|
+
isCharacterDevice(): boolean;
|
|
41
|
+
isFIFO(): boolean;
|
|
42
|
+
isSocket(): boolean;
|
|
43
|
+
}
|
|
7
44
|
export declare class Dirent {
|
|
8
45
|
private rawDirent;
|
|
9
46
|
name: string;
|
|
@@ -18,7 +55,12 @@ export interface PackFile {
|
|
|
18
55
|
path: string;
|
|
19
56
|
content: Uint8Array;
|
|
20
57
|
}
|
|
58
|
+
export interface DepsOptions {
|
|
59
|
+
registry?: string | null;
|
|
60
|
+
concurrency?: number | null;
|
|
61
|
+
}
|
|
21
62
|
export interface ProjectEndpoint {
|
|
63
|
+
deps: (options?: DepsOptions) => Promise<string>;
|
|
22
64
|
install: (packageLock: string, maxConcurrentDownloads?: number) => Promise<void>;
|
|
23
65
|
build: () => Promise<BuildOutput>;
|
|
24
66
|
readFile(path: string): Promise<Uint8Array>;
|
|
@@ -37,6 +79,7 @@ export interface ProjectEndpoint {
|
|
|
37
79
|
recursive?: boolean;
|
|
38
80
|
}): Promise<void>;
|
|
39
81
|
copyFile(src: string, dst: string): Promise<void>;
|
|
82
|
+
stat(path: string): Promise<Stats>;
|
|
40
83
|
gzip: (files: PackFile[]) => Promise<Uint8Array>;
|
|
41
84
|
sigMd5: (content: Uint8Array) => Promise<string>;
|
|
42
85
|
}
|
|
@@ -44,6 +87,7 @@ export interface ProjectOptions {
|
|
|
44
87
|
cwd: string;
|
|
45
88
|
workerUrl: string;
|
|
46
89
|
threadWorkerUrl: string;
|
|
90
|
+
loaderWorkerUrl?: string;
|
|
47
91
|
wasmUrl?: string;
|
|
48
92
|
serviceWorker?: ServiceWorkerOptions;
|
|
49
93
|
logFilter?: string;
|
package/esm/types.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class Stats {
|
|
2
|
+
constructor(raw) {
|
|
3
|
+
this.raw = raw;
|
|
4
|
+
this.dev = 0;
|
|
5
|
+
this.ino = 0;
|
|
6
|
+
this.nlink = 1;
|
|
7
|
+
this.uid = 0;
|
|
8
|
+
this.gid = 0;
|
|
9
|
+
this.rdev = 0;
|
|
10
|
+
this.blksize = 4096;
|
|
11
|
+
this.blocks = 0;
|
|
12
|
+
this.size = raw.size;
|
|
13
|
+
this.mode = raw.type === "directory" ? 16877 : 33188;
|
|
14
|
+
this.atimeMs = raw.atimeMs || 0;
|
|
15
|
+
this.mtimeMs = raw.mtimeMs || 0;
|
|
16
|
+
this.ctimeMs = raw.ctimeMs || 0;
|
|
17
|
+
this.birthtimeMs = raw.birthtimeMs || 0;
|
|
18
|
+
this.atime = new Date(this.atimeMs);
|
|
19
|
+
this.mtime = new Date(this.mtimeMs);
|
|
20
|
+
this.ctime = new Date(this.ctimeMs);
|
|
21
|
+
this.birthtime = new Date(this.birthtimeMs);
|
|
22
|
+
}
|
|
23
|
+
isDirectory() {
|
|
24
|
+
return this.raw.type === "directory";
|
|
25
|
+
}
|
|
26
|
+
isFile() {
|
|
27
|
+
return this.raw.type === "file";
|
|
28
|
+
}
|
|
29
|
+
isSymbolicLink() {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
isBlockDevice() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
isCharacterDevice() {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
isFIFO() {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
isSocket() {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class Dirent {
|
|
46
|
+
constructor(rawDirent) {
|
|
47
|
+
this.rawDirent = rawDirent;
|
|
48
|
+
this.name = this.rawDirent.name;
|
|
49
|
+
}
|
|
50
|
+
isDirectory() {
|
|
51
|
+
return this.rawDirent.type === "directory";
|
|
52
|
+
}
|
|
53
|
+
isFile() {
|
|
54
|
+
return this.rawDirent.type === "file";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const SAB_STATE_IDLE = 0;
|
|
2
|
+
export declare const SAB_STATE_REQUEST = 1;
|
|
3
|
+
export declare const SAB_STATE_RESPONSE = 2;
|
|
4
|
+
export declare const SAB_STATE_ERROR = 3;
|
|
5
|
+
export declare const SAB_OP_READ_FILE = 1;
|
|
6
|
+
export declare const SAB_OP_READ_DIR = 2;
|
|
7
|
+
export declare const SAB_OP_WRITE_FILE = 3;
|
|
8
|
+
export declare const SAB_OP_MKDIR = 4;
|
|
9
|
+
export declare const SAB_OP_RM = 5;
|
|
10
|
+
export declare const SAB_OP_RMDIR = 6;
|
|
11
|
+
export declare const SAB_OP_COPY_FILE = 7;
|
|
12
|
+
export declare const SAB_OP_STAT = 8;
|
|
13
|
+
export declare const STAT_TYPE_FILE = 0;
|
|
14
|
+
export declare const STAT_TYPE_DIR = 1;
|
|
15
|
+
export declare const SAB_INDEX_STATE = 0;
|
|
16
|
+
export declare const SAB_INDEX_OP = 1;
|
|
17
|
+
export declare const SAB_INDEX_DATA_LEN = 2;
|
|
18
|
+
export declare const SAB_DATA_OFFSET = 12;
|
|
19
|
+
export declare class SabComHost {
|
|
20
|
+
private sab;
|
|
21
|
+
private int32;
|
|
22
|
+
private uint8;
|
|
23
|
+
private dataView;
|
|
24
|
+
constructor(sab: SharedArrayBuffer);
|
|
25
|
+
readRequest(): {
|
|
26
|
+
op: number;
|
|
27
|
+
data: string;
|
|
28
|
+
};
|
|
29
|
+
writeResponse(data: Uint8Array | string): void;
|
|
30
|
+
writeError(message: string): void;
|
|
31
|
+
writeStat(type: number, size: bigint, atimeMs: number, mtimeMs: number, ctimeMs: number, birthtimeMs: number): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class SabComClient {
|
|
34
|
+
private sab;
|
|
35
|
+
private notifyHost;
|
|
36
|
+
private int32;
|
|
37
|
+
private uint8;
|
|
38
|
+
private dataView;
|
|
39
|
+
constructor(sab: SharedArrayBuffer, notifyHost: () => void);
|
|
40
|
+
call(op: number, data: string): Uint8Array<ArrayBuffer>;
|
|
41
|
+
callStat(path: string): {
|
|
42
|
+
type: number;
|
|
43
|
+
size: bigint;
|
|
44
|
+
atimeMs: number;
|
|
45
|
+
mtimeMs: number;
|
|
46
|
+
ctimeMs: number;
|
|
47
|
+
birthtimeMs: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface SabFileSystem {
|
|
51
|
+
read(path: string): Promise<Uint8Array>;
|
|
52
|
+
readDir(path: string): Promise<any[]>;
|
|
53
|
+
writeString(path: string, content: string): Promise<void>;
|
|
54
|
+
createDirAll(path: string): Promise<void>;
|
|
55
|
+
createDir(path: string): Promise<void>;
|
|
56
|
+
metadata(path: string): Promise<any>;
|
|
57
|
+
removeFile(path: string): Promise<void>;
|
|
58
|
+
removeDir(path: string, recursive: boolean): Promise<void>;
|
|
59
|
+
copyFile(src: string, dst: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export declare const handleSabRequest: (sabHost: SabComHost, fs: SabFileSystem) => Promise<void>;
|