Skip to content

Commit

Permalink
feat(cloudflare): use workerd implementation of node:dns (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Dec 16, 2024
1 parent af71c96 commit 7e05819
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 77 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"typescript": "^5.7.2",
"unbuild": "^2.0.0",
"vitest": "^2.1.8",
"workerd": "^1.20241202.0",
"wrangler": "^3.91.0"
"workerd": "^1.20241216.0",
"wrangler": "^3.95.0"
},
"packageManager": "[email protected]"
}
143 changes: 68 additions & 75 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/presets/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const cloudflareNodeCompatModules = [
"assert/strict",
"buffer",
"diagnostics_channel",
"dns",
"dns/promises",
"events",
"path",
"path/posix",
Expand Down
28 changes: 28 additions & 0 deletions test/workerd/tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ export const workerd_path = {
},
};

// --- node:dns

export const workerd_dns = {
async test() {
const dns = await import("node:dns");
await new Promise((resolve, reject) => {
dns.resolveTxt("nodejs.org", (error, results) => {
if (error) {
reject(error);
return;
}
assert.ok(Array.isArray(results[0]));
assert.strictEqual(results.length, 1);
assert.ok(results[0][0].startsWith("v=spf1"));
resolve(null);
});
});

const dnsPromises = await import("node:dns/promises");
const results = await dnsPromises.resolveCaa("google.com");
assert.ok(Array.isArray(results));
assert.strictEqual(results.length, 1);
assert.strictEqual(typeof results[0].critical, "number");
assert.strictEqual(results[0].critical, 0);
assert.strictEqual(results[0].issue, "pki.goog");
},
};

// --- unenv:fetch

// https://github.com/unjs/unenv/issues/364
Expand Down

0 comments on commit 7e05819

Please sign in to comment.