@joshski/dust 0.1.34 → 0.1.36
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/dist/dust.js +58 -31
- package/package.json +1 -1
package/dist/dust.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
|
-
|
|
5
2
|
// lib/cli/run.ts
|
|
6
3
|
import { existsSync } from "node:fs";
|
|
7
|
-
import { chmod, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { chmod as chmod2, mkdir as mkdir2, readdir as readdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
8
5
|
|
|
9
6
|
// lib/config/settings.ts
|
|
10
7
|
import { join } from "node:path";
|
|
@@ -543,6 +540,9 @@ async function audit(dependencies) {
|
|
|
543
540
|
|
|
544
541
|
// lib/cli/commands/bucket.ts
|
|
545
542
|
import { spawn as nodeSpawn3 } from "node:child_process";
|
|
543
|
+
import { accessSync } from "node:fs";
|
|
544
|
+
import { chmod, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
545
|
+
import { createServer as httpCreateServer } from "node:http";
|
|
546
546
|
import { homedir, tmpdir } from "node:os";
|
|
547
547
|
|
|
548
548
|
// lib/bucket/auth.ts
|
|
@@ -578,7 +578,24 @@ async function clearToken(fileSystem, homeDir) {
|
|
|
578
578
|
await fileSystem.writeFile(path, "{}");
|
|
579
579
|
} catch {}
|
|
580
580
|
}
|
|
581
|
+
async function defaultExchangeCode(code) {
|
|
582
|
+
const host = getDustbucketHost();
|
|
583
|
+
const response = await fetch(`${host}/auth/cli/exchange`, {
|
|
584
|
+
method: "POST",
|
|
585
|
+
headers: { "Content-Type": "application/json" },
|
|
586
|
+
body: JSON.stringify({ code })
|
|
587
|
+
});
|
|
588
|
+
if (!response.ok) {
|
|
589
|
+
throw new Error(`Token exchange failed: ${response.status}`);
|
|
590
|
+
}
|
|
591
|
+
const body = await response.json();
|
|
592
|
+
if (typeof body.token !== "string") {
|
|
593
|
+
throw new Error("Invalid token exchange response");
|
|
594
|
+
}
|
|
595
|
+
return body.token;
|
|
596
|
+
}
|
|
581
597
|
async function authenticate(authDeps) {
|
|
598
|
+
const exchange = authDeps.exchangeCode ?? defaultExchangeCode;
|
|
582
599
|
return new Promise((resolve, reject) => {
|
|
583
600
|
let timer = null;
|
|
584
601
|
let serverHandle = null;
|
|
@@ -595,13 +612,13 @@ async function authenticate(authDeps) {
|
|
|
595
612
|
const handler = (request) => {
|
|
596
613
|
const url = new URL(request.url);
|
|
597
614
|
if (url.pathname === "/callback") {
|
|
598
|
-
const
|
|
599
|
-
if (
|
|
615
|
+
const code = url.searchParams.get("code");
|
|
616
|
+
if (code) {
|
|
600
617
|
cleanup();
|
|
601
|
-
|
|
618
|
+
exchange(code).then(resolve, reject);
|
|
602
619
|
return new Response("<html><body><p>Authentication successful! You can close this tab.</p></body></html>", { headers: { "Content-Type": "text/html" } });
|
|
603
620
|
}
|
|
604
|
-
return new Response("Missing
|
|
621
|
+
return new Response("Missing code", { status: 400 });
|
|
605
622
|
}
|
|
606
623
|
return new Response("Not found", { status: 404 });
|
|
607
624
|
};
|
|
@@ -2071,11 +2088,30 @@ function defaultWriteStdout(data) {
|
|
|
2071
2088
|
process.stdout.write(data);
|
|
2072
2089
|
}
|
|
2073
2090
|
function defaultCreateServer(handler) {
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2091
|
+
let resolvedPort = 0;
|
|
2092
|
+
const server = httpCreateServer(async (nodeRequest, nodeResponse) => {
|
|
2093
|
+
const url = new URL(nodeRequest.url ?? "/", `http://localhost:${resolvedPort}`);
|
|
2094
|
+
const request = new Request(url.toString(), {
|
|
2095
|
+
method: nodeRequest.method ?? "GET"
|
|
2096
|
+
});
|
|
2097
|
+
const response = handler(request);
|
|
2098
|
+
const body = await response.text();
|
|
2099
|
+
nodeResponse.writeHead(response.status, {
|
|
2100
|
+
"Content-Type": response.headers.get("content-type") ?? "text/plain"
|
|
2101
|
+
});
|
|
2102
|
+
nodeResponse.end(body);
|
|
2103
|
+
});
|
|
2104
|
+
server.listen(0, () => {
|
|
2105
|
+
const addr2 = server.address();
|
|
2106
|
+
if (addr2 && typeof addr2 === "object") {
|
|
2107
|
+
resolvedPort = addr2.port;
|
|
2108
|
+
}
|
|
2077
2109
|
});
|
|
2078
|
-
|
|
2110
|
+
const addr = server.address();
|
|
2111
|
+
if (addr && typeof addr === "object") {
|
|
2112
|
+
resolvedPort = addr.port;
|
|
2113
|
+
}
|
|
2114
|
+
return { port: resolvedPort, stop: () => server.close() };
|
|
2079
2115
|
}
|
|
2080
2116
|
function defaultOpenBrowser(url) {
|
|
2081
2117
|
const cmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
@@ -2085,26 +2121,17 @@ function createDefaultBucketDependencies() {
|
|
|
2085
2121
|
const authFileSystem = {
|
|
2086
2122
|
exists: (path) => {
|
|
2087
2123
|
try {
|
|
2088
|
-
|
|
2089
|
-
return
|
|
2124
|
+
accessSync(path);
|
|
2125
|
+
return true;
|
|
2090
2126
|
} catch {
|
|
2091
2127
|
return false;
|
|
2092
2128
|
}
|
|
2093
2129
|
},
|
|
2094
|
-
readFile: (path) =>
|
|
2095
|
-
writeFile: (path, content) =>
|
|
2096
|
-
mkdir: (path, options) => {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
},
|
|
2100
|
-
readdir: (path) => {
|
|
2101
|
-
const { readdir } = __require("node:fs/promises");
|
|
2102
|
-
return readdir(path);
|
|
2103
|
-
},
|
|
2104
|
-
chmod: (path, mode) => {
|
|
2105
|
-
const { chmod } = __require("node:fs/promises");
|
|
2106
|
-
return chmod(path, mode);
|
|
2107
|
-
}
|
|
2130
|
+
readFile: (path) => readFile(path, "utf8"),
|
|
2131
|
+
writeFile: (path, content) => writeFile(path, content, "utf8"),
|
|
2132
|
+
mkdir: (path, options) => mkdir(path, options).then(() => {}),
|
|
2133
|
+
readdir: (path) => readdir(path),
|
|
2134
|
+
chmod: (path, mode) => chmod(path, mode)
|
|
2108
2135
|
};
|
|
2109
2136
|
return {
|
|
2110
2137
|
spawn: nodeSpawn3,
|
|
@@ -3766,10 +3793,10 @@ function createFileSystem(primitives) {
|
|
|
3766
3793
|
chmod: (path, mode) => primitives.chmod(path, mode)
|
|
3767
3794
|
};
|
|
3768
3795
|
}
|
|
3769
|
-
function createGlobScanner(
|
|
3796
|
+
function createGlobScanner(readdir2) {
|
|
3770
3797
|
return {
|
|
3771
3798
|
scan: async function* (dir) {
|
|
3772
|
-
for (const entry of await
|
|
3799
|
+
for (const entry of await readdir2(dir, { recursive: true })) {
|
|
3773
3800
|
if (entry.endsWith(".md"))
|
|
3774
3801
|
yield entry;
|
|
3775
3802
|
}
|
|
@@ -3793,4 +3820,4 @@ async function wireEntry(fsPrimitives, processPrimitives, consolePrimitives) {
|
|
|
3793
3820
|
}
|
|
3794
3821
|
|
|
3795
3822
|
// lib/cli/run.ts
|
|
3796
|
-
await wireEntry({ existsSync, readFile, writeFile, mkdir, readdir, chmod }, { argv: process.argv, cwd: () => process.cwd(), exit: process.exit }, { log: console.log, error: console.error });
|
|
3823
|
+
await wireEntry({ existsSync, readFile: readFile2, writeFile: writeFile2, mkdir: mkdir2, readdir: readdir2, chmod: chmod2 }, { argv: process.argv, cwd: () => process.cwd(), exit: process.exit }, { log: console.log, error: console.error });
|