@b9g/platform-node 0.1.1 → 0.1.2
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/package.json +1 -1
- package/src/platform.d.ts +2 -3
- package/src/platform.js +24 -14
package/package.json
CHANGED
package/src/platform.d.ts
CHANGED
|
@@ -25,12 +25,11 @@ export declare class NodePlatform extends BasePlatform {
|
|
|
25
25
|
private options;
|
|
26
26
|
private workerManager?;
|
|
27
27
|
private cacheStorage?;
|
|
28
|
-
private _dist?;
|
|
29
28
|
constructor(options?: NodePlatformOptions);
|
|
30
29
|
/**
|
|
31
|
-
*
|
|
30
|
+
* Get filesystem directory handle
|
|
32
31
|
*/
|
|
33
|
-
|
|
32
|
+
getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
|
|
34
33
|
/**
|
|
35
34
|
* THE MAIN JOB - Load and run a ServiceWorker-style entrypoint in Node.js
|
|
36
35
|
* Uses Worker threads with coordinated cache storage for isolation and standards compliance
|
package/src/platform.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
BasePlatform
|
|
5
5
|
} from "@b9g/platform";
|
|
6
6
|
import { CustomCacheStorage, MemoryCacheManager, PostMessageCache } from "@b9g/cache";
|
|
7
|
-
import { FileSystemRegistry, getFileSystemRoot, NodeFileSystemAdapter
|
|
7
|
+
import { FileSystemRegistry, getFileSystemRoot, NodeFileSystemAdapter } from "@b9g/filesystem";
|
|
8
8
|
import * as Http from "http";
|
|
9
9
|
import * as Path from "path";
|
|
10
10
|
import { Worker } from "worker_threads";
|
|
@@ -155,7 +155,6 @@ var NodePlatform = class extends BasePlatform {
|
|
|
155
155
|
options;
|
|
156
156
|
workerManager;
|
|
157
157
|
cacheStorage;
|
|
158
|
-
_dist;
|
|
159
158
|
constructor(options = {}) {
|
|
160
159
|
super(options);
|
|
161
160
|
this.options = {
|
|
@@ -170,14 +169,12 @@ var NodePlatform = class extends BasePlatform {
|
|
|
170
169
|
}));
|
|
171
170
|
}
|
|
172
171
|
/**
|
|
173
|
-
*
|
|
172
|
+
* Get filesystem directory handle
|
|
174
173
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
return this._dist;
|
|
174
|
+
async getDirectoryHandle(name) {
|
|
175
|
+
const distPath = Path.resolve(this.options.cwd, "dist");
|
|
176
|
+
const adapter = new NodeFileSystemAdapter({ rootPath: distPath });
|
|
177
|
+
return await adapter.getDirectoryHandle(name);
|
|
181
178
|
}
|
|
182
179
|
/**
|
|
183
180
|
* THE MAIN JOB - Load and run a ServiceWorker-style entrypoint in Node.js
|
|
@@ -308,19 +305,32 @@ var NodePlatform = class extends BasePlatform {
|
|
|
308
305
|
res.end("Internal Server Error");
|
|
309
306
|
}
|
|
310
307
|
});
|
|
308
|
+
let isListening = false;
|
|
311
309
|
return {
|
|
312
|
-
listen
|
|
310
|
+
async listen() {
|
|
313
311
|
return new Promise((resolve2) => {
|
|
314
312
|
httpServer.listen(port, host, () => {
|
|
315
313
|
console.info(`\u{1F680} Server running at http://${host}:${port}`);
|
|
314
|
+
isListening = true;
|
|
316
315
|
resolve2();
|
|
317
316
|
});
|
|
318
317
|
});
|
|
319
318
|
},
|
|
320
|
-
close
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
319
|
+
async close() {
|
|
320
|
+
return new Promise((resolve2) => {
|
|
321
|
+
httpServer.close(() => {
|
|
322
|
+
isListening = false;
|
|
323
|
+
resolve2();
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
address: () => ({ port, host }),
|
|
328
|
+
get url() {
|
|
329
|
+
return `http://${host}:${port}`;
|
|
330
|
+
},
|
|
331
|
+
get ready() {
|
|
332
|
+
return isListening;
|
|
333
|
+
}
|
|
324
334
|
};
|
|
325
335
|
}
|
|
326
336
|
/**
|