@b9g/shovel 0.1.8 → 0.1.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/bin/shovel.js +1 -0
- package/package.json +12 -12
- package/src/develop.js +7 -2
- package/src/static.js +9 -72
package/bin/shovel.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/shovel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Dig for treasure",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -11,21 +11,21 @@
|
|
|
11
11
|
"test": "node --experimental-fetch node_modules/.bin/uvu"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"commander": "^
|
|
15
|
-
"esbuild": "^0.
|
|
16
|
-
"is-core-module": "^2.
|
|
17
|
-
"magic-string": "^0.30.
|
|
18
|
-
"resolve.exports": "^2.0.
|
|
14
|
+
"commander": "^13.1.0",
|
|
15
|
+
"esbuild": "^0.25.0",
|
|
16
|
+
"is-core-module": "^2.16.1",
|
|
17
|
+
"magic-string": "^0.30.17",
|
|
18
|
+
"resolve.exports": "^2.0.3",
|
|
19
19
|
"source-map": "^0.7.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@b9g/crank": "^0.
|
|
23
|
-
"@emotion/css": "^11.
|
|
24
|
-
"@flydotio/dockerfile": "^0.
|
|
22
|
+
"@b9g/crank": "^0.6.0",
|
|
23
|
+
"@emotion/css": "^11.13.5",
|
|
24
|
+
"@flydotio/dockerfile": "^0.7.8",
|
|
25
25
|
"@types/bun": "^1.2.2",
|
|
26
|
-
"fkill": "^
|
|
27
|
-
"sinon": "^
|
|
28
|
-
"typescript": "^5.
|
|
26
|
+
"fkill": "^9.0.0",
|
|
27
|
+
"sinon": "^19.0.2",
|
|
28
|
+
"typescript": "^5.7.3",
|
|
29
29
|
"uvu": "^0.5.6"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
package/src/develop.js
CHANGED
|
@@ -7,20 +7,25 @@ export async function develop(entry, options) {
|
|
|
7
7
|
throw new Error("Invalid port", options.port);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
const module = await import(entry);
|
|
10
11
|
const server = Bun.serve({
|
|
11
12
|
port,
|
|
12
13
|
async fetch(req) {
|
|
13
14
|
console.log(`${req.method}: ${req.url}`);
|
|
14
|
-
const module = await import(entry);
|
|
15
15
|
if (typeof module?.default?.fetch === "function") {
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
const res = await module?.default?.fetch(req);
|
|
18
|
+
return res;
|
|
18
19
|
} catch (err) {
|
|
19
20
|
return new Response(err.stack, {
|
|
20
21
|
status: 500,
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
return new Response("fetch not defined on default export", {
|
|
27
|
+
status: 500,
|
|
28
|
+
});
|
|
24
29
|
},
|
|
25
30
|
});
|
|
26
31
|
|
package/src/static.js
CHANGED
|
@@ -1,84 +1,21 @@
|
|
|
1
1
|
import * as Path from "path";
|
|
2
2
|
import * as FS from "fs/promises";
|
|
3
3
|
import {pathToFileURL} from "url";
|
|
4
|
-
import * as VM from "vm";
|
|
5
|
-
import {formatMessages} from "esbuild";
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// TODO: This code is duplicated in ./develop.js so it should be moved to a
|
|
12
|
-
// module-specific file.
|
|
13
|
-
|
|
14
|
-
//interface ModuleCacheValue {
|
|
15
|
-
// module: VM.SourceTextModule;
|
|
16
|
-
// dependents: Set<string>;
|
|
17
|
-
// hot: Hot;
|
|
18
|
-
//}
|
|
19
|
-
export async function static_(file, options) {
|
|
20
|
-
file = Path.resolve(process.cwd(), file);
|
|
21
|
-
process.on("SIGINT", async () => {
|
|
22
|
-
await observer.dispose();
|
|
23
|
-
process.exit(0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
process.on("SIGTERM", async () => {
|
|
27
|
-
await observer.dispose();
|
|
28
|
-
process.exit(0);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const observer = new BuildObserver(async (record) => {
|
|
32
|
-
if (record.result.errors.length > 0) {
|
|
33
|
-
const formatted = await formatMessages(record.result.errors, {
|
|
34
|
-
kind: "error",
|
|
35
|
-
});
|
|
36
|
-
console.error(formatted.join("\n"));
|
|
37
|
-
process.exit(1);
|
|
38
|
-
} else if (record.result.warnings.length > 0) {
|
|
39
|
-
const formatted = await formatMessages(record.result.warnings, {
|
|
40
|
-
kind: "warning",
|
|
41
|
-
});
|
|
42
|
-
console.warn(formatted.join("\n"));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const link = createLink(observer);
|
|
47
|
-
const result = await observer.build(file);
|
|
48
|
-
const code = result.outputFiles.find((file) => file.path.endsWith(".js"))?.text || "";
|
|
49
|
-
const url = pathToFileURL(file).href;
|
|
50
|
-
const module = new VM.SourceTextModule(code, {
|
|
51
|
-
identifier: url,
|
|
52
|
-
initializeImportMeta(meta) {
|
|
53
|
-
meta.url = url;
|
|
54
|
-
},
|
|
55
|
-
async importModuleDynamically(specifier, referencingModule) {
|
|
56
|
-
// TODO: link is not defined so I dunno how this works.
|
|
57
|
-
const linked = await link(specifier, referencingModule);
|
|
58
|
-
await linked.link(link);
|
|
59
|
-
await linked.evaluate();
|
|
60
|
-
return linked;
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
await module.link(link);
|
|
65
|
-
await module.evaluate();
|
|
66
|
-
const namespace = module.namespace;
|
|
5
|
+
export async function static_(entry, options) {
|
|
6
|
+
entry = Path.resolve(process.cwd(), entry);
|
|
7
|
+
const module = await import(entry);
|
|
67
8
|
const dist = Path.resolve(process.cwd(), options.outDir);
|
|
68
|
-
const paths =
|
|
9
|
+
const paths = module.default?.staticPaths?.(dist);
|
|
69
10
|
if (paths) {
|
|
70
11
|
for await (const path of paths) {
|
|
71
12
|
const req = new Request(pathToFileURL(path).href);
|
|
72
|
-
const res = await
|
|
13
|
+
const res = await module.default?.fetch?.(req);
|
|
73
14
|
const body = await res.text();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await FS.mkdir(Path.dirname(file), {recursive: true});
|
|
79
|
-
await FS.writeFile(file, body);
|
|
15
|
+
const htmlPath = Path.resolve(dist, path.replace(/^\//, ""), "index.html");
|
|
16
|
+
console.info(`Writing: ${htmlPath}`);
|
|
17
|
+
await FS.mkdir(Path.dirname(htmlPath), {recursive: true});
|
|
18
|
+
await FS.writeFile(htmlPath, body);
|
|
80
19
|
}
|
|
81
20
|
}
|
|
82
|
-
|
|
83
|
-
process.exit(0);
|
|
84
21
|
}
|