@utoo/web 1.2.0-rc.4 → 1.2.0-rc.6

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.
Files changed (38) hide show
  1. package/esm/{3ec3463a197b5c4bac1e.wasm → fe3ccd485f4eb7cd1a1e.wasm} +0 -0
  2. package/esm/forkedProject.d.ts +2 -1
  3. package/esm/forkedProject.js +5 -0
  4. package/esm/internalProject.d.ts +3 -3
  5. package/esm/internalProject.js +33 -20
  6. package/esm/loaderWorker.js +1 -1
  7. package/esm/project.d.ts +2 -1
  8. package/esm/project.js +6 -1
  9. package/esm/sabcom.d.ts +6 -0
  10. package/esm/sabcom.js +53 -5
  11. package/esm/serviceWorker.js +1 -0
  12. package/esm/type.d.ts +38 -0
  13. package/esm/type.js +44 -0
  14. package/esm/utoo/index.d.ts +27 -24
  15. package/esm/utoo/index.js +97 -95
  16. package/esm/utoo/index_bg.wasm +0 -0
  17. package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +71 -64
  18. package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
  19. package/esm/{loaderWorkerPool.js → webpackLoaders/loaderWorkerPool.js} +30 -18
  20. package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
  21. package/esm/webpackLoaders/polyfills/fsPolyfill.js +279 -0
  22. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  23. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  24. package/esm/webpackLoaders/{worker/type.d.ts → type.d.ts} +1 -0
  25. package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
  26. package/package.json +4 -3
  27. package/esm/loaderWorkerPool.d.ts +0 -3
  28. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -244
  29. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.js +0 -369
  30. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
  31. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
  32. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  33. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -0
  34. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +0 -0
  35. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
  36. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
  37. /package/esm/webpackLoaders/{worker/type.js → type.js} +0 -0
  38. /package/esm/webpackLoaders/{worker/index.d.ts → worker.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { PackFile, ProjectEndpoint } from "./type";
1
+ import { PackFile, ProjectEndpoint, Stats } from "./type";
2
2
  export declare class ForkedProject implements ProjectEndpoint {
3
3
  private endpoint;
4
4
  constructor(port: MessagePort);
@@ -19,6 +19,7 @@ export declare class ForkedProject implements ProjectEndpoint {
19
19
  rmdir(path: string, options?: {
20
20
  recursive?: boolean;
21
21
  }): Promise<void>;
22
+ stat(path: string): Promise<Stats>;
22
23
  gzip(files: PackFile[]): Promise<Uint8Array>;
23
24
  sigMd5(content: Uint8Array): Promise<string>;
24
25
  }
@@ -1,4 +1,5 @@
1
1
  import * as comlink from "comlink";
2
+ import { Stats } from "./type";
2
3
  export class ForkedProject {
3
4
  constructor(port) {
4
5
  var _a;
@@ -31,6 +32,10 @@ export class ForkedProject {
31
32
  async rmdir(path, options) {
32
33
  return await this.endpoint.rmdir(path, options);
33
34
  }
35
+ async stat(path) {
36
+ const raw = (await this.endpoint.stat(path));
37
+ return new Stats(raw);
38
+ }
34
39
  async gzip(files) {
35
40
  return await this.endpoint.gzip(files);
36
41
  }
@@ -1,7 +1,6 @@
1
- import { PackFile, ProjectEndpoint, ProjectOptions } from "./type";
2
- import initWasm, { Project as ProjectInternal } from "./utoo";
1
+ import { PackFile, ProjectEndpoint, ProjectOptions, Stats } from "./type";
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">;
7
6
  loaderWorkerPoolInitialized: boolean;
@@ -11,6 +10,7 @@ declare class InternalEndpoint implements ProjectEndpoint {
11
10
  readFile(path: string, encoding?: "utf8"): Promise<any>;
12
11
  writeFile(path: string, content: string | Uint8Array, _encoding?: "utf8"): Promise<void>;
13
12
  copyFile(src: string, dst: string): Promise<void>;
13
+ stat(path: string): Promise<Stats>;
14
14
  readdir(path: string, options?: {
15
15
  recursive?: boolean;
16
16
  }): Promise<any>;
@@ -1,5 +1,5 @@
1
- import { runLoaderWorkerPool } from "./loaderWorkerPool";
2
1
  import initWasm, { init_log_filter, Project as ProjectInternal, } from "./utoo";
2
+ import { runLoaderWorkerPool } from "./webpackLoaders/loaderWorkerPool";
3
3
  class InternalEndpoint {
4
4
  constructor() {
5
5
  this.loaderWorkerPoolInitialized = false;
@@ -14,53 +14,66 @@ class InternalEndpoint {
14
14
  // Initialize log filter after wasm init
15
15
  const filter = logFilter || "pack_core=info,pack_api=info,utoo_wasm=info";
16
16
  init_log_filter(filter);
17
- this.projectInternal = new ProjectInternal(cwd, threadWorkerUrl);
17
+ const absoluteCwd = cwd.startsWith("/") ? cwd : "/" + cwd;
18
+ ProjectInternal.init(threadWorkerUrl || "");
19
+ ProjectInternal.setCwd(absoluteCwd);
18
20
  return;
19
21
  }
20
22
  async install(packageLock, maxConcurrentDownloads) {
21
23
  await this.wasmInit;
22
- await this.projectInternal.install(packageLock, maxConcurrentDownloads);
24
+ await ProjectInternal.install(packageLock, maxConcurrentDownloads);
23
25
  return;
24
26
  }
25
27
  async build() {
26
28
  var _a, _b;
27
29
  const binding = await this.wasmInit;
28
30
  if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.loaderWorkerUrl) && !this.loaderWorkerPoolInitialized) {
29
- runLoaderWorkerPool(binding, this.options.cwd, this.projectInternal, this.options.loaderWorkerUrl, (_b = this.options) === null || _b === void 0 ? void 0 : _b.loadersImportMap);
31
+ runLoaderWorkerPool(binding, this.options.cwd, this.options.loaderWorkerUrl, (_b = this.options) === null || _b === void 0 ? void 0 : _b.loadersImportMap);
30
32
  this.loaderWorkerPoolInitialized = true;
31
33
  }
32
- return await this.projectInternal.build();
34
+ return await ProjectInternal.build();
33
35
  }
34
36
  async readFile(path, encoding) {
35
37
  await this.wasmInit;
36
38
  let ret;
37
39
  if (encoding === "utf8") {
38
- ret = await this.projectInternal.readToString(path);
40
+ ret = await ProjectInternal.readToString(path);
39
41
  }
40
42
  else {
41
- ret = await this.projectInternal.read(path);
43
+ ret = await ProjectInternal.read(path);
42
44
  }
43
45
  return ret;
44
46
  }
45
47
  async writeFile(path, content, _encoding) {
46
48
  await this.wasmInit;
47
49
  if (typeof content === "string") {
48
- return await this.projectInternal.writeString(path, content);
50
+ return await ProjectInternal.writeString(path, content);
49
51
  }
50
52
  else {
51
- return await this.projectInternal.write(path, content);
53
+ return await ProjectInternal.write(path, content);
52
54
  }
53
55
  }
54
56
  async copyFile(src, dst) {
55
57
  await this.wasmInit;
56
- return await this.projectInternal.copyFile(src, dst);
58
+ return await ProjectInternal.copyFile(src, dst);
59
+ }
60
+ async stat(path) {
61
+ await this.wasmInit;
62
+ const metadata = await ProjectInternal.metadata(path);
63
+ const json = metadata.toJSON();
64
+ const raw = {
65
+ type: json.type,
66
+ size: Number(json.file_size),
67
+ };
68
+ // WARN: This is a hack, functions can not be structurally cloned
69
+ return raw;
57
70
  }
58
71
  async readdir(path, options) {
59
72
  await this.wasmInit;
60
73
  const dirEntries = (options === null || options === void 0 ? void 0 : options.recursive)
61
- ? await this.projectInternal.readDir(path)
74
+ ? await ProjectInternal.readDir(path)
62
75
  : // TODO: support recursive readDirAll
63
- await this.projectInternal.readDir(path);
76
+ await ProjectInternal.readDir(path);
64
77
  const rawDirents = dirEntries.map((e) => {
65
78
  const dir = e.toJSON();
66
79
  return {
@@ -74,20 +87,20 @@ class InternalEndpoint {
74
87
  async mkdir(path, options) {
75
88
  await this.wasmInit;
76
89
  if (options === null || options === void 0 ? void 0 : options.recursive) {
77
- return await this.projectInternal.createDirAll(path);
90
+ return await ProjectInternal.createDirAll(path);
78
91
  }
79
92
  else {
80
- return await this.projectInternal.createDir(path);
93
+ return await ProjectInternal.createDir(path);
81
94
  }
82
95
  }
83
96
  async rm(path, options) {
84
97
  await this.wasmInit;
85
- let metadata = (await this.projectInternal.metadata(path)).toJSON();
98
+ let metadata = (await ProjectInternal.metadata(path)).toJSON();
86
99
  switch (metadata.type) {
87
100
  case "file":
88
- return await this.projectInternal.removeFile(path);
101
+ return await ProjectInternal.removeFile(path);
89
102
  case "directory":
90
- return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
103
+ return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
91
104
  default:
92
105
  // nothing to remove now
93
106
  break;
@@ -95,15 +108,15 @@ class InternalEndpoint {
95
108
  }
96
109
  async rmdir(path, options) {
97
110
  await this.wasmInit;
98
- return await this.projectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
111
+ return await ProjectInternal.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
99
112
  }
100
113
  async gzip(files) {
101
114
  await this.wasmInit;
102
- return await this.projectInternal.gzip(files);
115
+ return await ProjectInternal.gzip(files);
103
116
  }
104
117
  async sigMd5(content) {
105
118
  await this.wasmInit;
106
- return await this.projectInternal.sigMd5(content);
119
+ return await ProjectInternal.sigMd5(content);
107
120
  }
108
121
  }
109
122
  const internalEndpoint = new InternalEndpoint();