Skip to content

Commit a7e9f80

Browse files
feat(unenv-preset): add support for native node:inspector/promises module (#11744)
* use the native implementation of `inspector/promises` when available * add changeset for inspector/promises support Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 69979a3 commit a7e9f80

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"@cloudflare/unenv-preset": minor
3+
---
4+
5+
Add support for native `node:inspector/promises` module when the `enable_nodejs_inspector_module` compatibility flag is enabled. This extends the existing `node:inspector` support to include the promises-based API.
6+
7+
To enable the native inspector/promises module, add the following to your `wrangler.jsonc`:
8+
9+
```jsonc
10+
{
11+
"compatibility_flags": ["experimental", "enable_nodejs_inspector_module"],
12+
}
13+
```
14+
15+
Then you can import and use the inspector/promises module in your Worker:
16+
17+
```javascript
18+
import inspector from "node:inspector/promises";
19+
20+
// Access inspector APIs (note: workerd's implementation is a non-functional stub)
21+
inspector.url(); // returns undefined
22+
inspector.close(); // no-op
23+
```

packages/unenv-preset/src/preset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ function getVmOverrides({
601601
}
602602

603603
/**
604-
* Returns the overrides for `node:inspector` (unenv or workerd)
604+
* Returns the overrides for `node:inspector` and `node:inspector/promises` (unenv or workerd)
605605
*
606606
* The native inspector implementation:
607607
* - is experimental and has no default enable date
@@ -627,7 +627,7 @@ function getInspectorOverrides({
627627
// When enabled, use the native `inspector` module from workerd
628628
return enabled
629629
? {
630-
nativeModules: ["inspector"],
630+
nativeModules: ["inspector/promises", "inspector"],
631631
hybridModules: [],
632632
}
633633
: {

packages/wrangler/e2e/unenv-preset/preset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ const localTestConfigs: TestConfig[] = [
410410
},
411411
},
412412
],
413-
// node:inspector (experimental, no default enable date)
413+
// node:inspector and node:inspector/promises (experimental, no default enable date)
414414
[
415415
{
416416
name: "inspector enabled by flag",

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,37 @@ export const WorkerdTests: Record<string, () => void> = {
752752
Network: "object",
753753
});
754754
},
755+
756+
async testInspectorPromises() {
757+
const inspectorPromises = await import("node:inspector/promises");
758+
assertTypeOfProperties(inspectorPromises, {
759+
Session: "function",
760+
close: "function",
761+
console: "object",
762+
open: "function",
763+
url: "function",
764+
waitForDebugger: "function",
765+
});
766+
767+
if (getRuntimeFlagValue("enable_nodejs_inspector_module")) {
768+
// In unenv this object is polyfilled by a "notImplementedClass" which has type function.
769+
assertTypeOf(inspectorPromises, "Network", "object");
770+
}
771+
772+
assertTypeOfProperties(inspectorPromises.default, {
773+
Session: "function",
774+
close: "function",
775+
console: "object",
776+
open: "function",
777+
url: "function",
778+
waitForDebugger: "function",
779+
});
780+
781+
if (getRuntimeFlagValue("enable_nodejs_inspector_module")) {
782+
// In unenv this object is polyfilled by a "notImplementedClass" which has type function.
783+
assertTypeOf(inspectorPromises.default, "Network", "object");
784+
}
785+
},
755786
};
756787

757788
/**

0 commit comments

Comments
 (0)