Skip to content

Commit

Permalink
fix: Allow subset of node.js APIs for edge (#69675)
Browse files Browse the repository at this point in the history
### What?

Allow using modules listed in
https://developers.cloudflare.com/workers/runtime-apis/nodejs/ in edge
runtime.

### Why?

It's supported.

### How?
  • Loading branch information
kdy1 authored Sep 4, 2024
1 parent 2aa2bca commit b3e434e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ const NODEJS_MODULE_NAMES: &[&str] = &[
"_stream_writable",
"_tls_common",
"_tls_wrap",
"assert",
"assert/strict",
"async_hooks",
"buffer",
// "assert",
// "assert/strict",
// "async_hooks",
// "buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
// "crypto",
"dgram",
"diagnostics_channel",
// "diagnostics_channel",
"dns",
"dns/promises",
"domain",
"events",
// "events",
"fs",
"fs/promises",
"http",
Expand All @@ -100,30 +100,30 @@ const NODEJS_MODULE_NAMES: &[&str] = &[
"module",
"net",
"os",
"path",
"path/posix",
"path/win32",
// "path",
// "path/posix",
// "path/win32",
"perf_hooks",
"process",
// "process",
"punycode",
"querystring",
"readline",
"readline/promises",
"repl",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
// "stream",
// "stream/consumers",
// "stream/promises",
// "stream/web",
// "string_decoder",
"sys",
"timers",
"timers/promises",
"tls",
"trace_events",
"tty",
"url",
"util",
"util/types",
// "util",
// "util/types",
"v8",
"vm",
"wasi",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Allowed because a subset of Node.js APIs are allowed.
import 'node:util'
import 'node:stream'
import 'node:process'
import 'node:path'
import 'node:events'
import 'node:diagnostics_channel'
import 'node:crypto'
import 'node:buffer'
import 'node:async_hooks'
import 'node:assert'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Allowed because a subset of Node.js APIs are allowed.
import 'node:util';
import 'node:stream';
import 'node:process';
import 'node:path';
import 'node:events';
import 'node:diagnostics_channel';
import 'node:crypto';
import 'node:buffer';
import 'node:async_hooks';
import 'node:assert';
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Edge runtime code with imports', () => {
},
},
])('$title statically importing node.js module', ({ init, url }) => {
const moduleName = 'path'
const moduleName = 'fs'
const importStatement = `import { basename } from "${moduleName}"`

beforeEach(() => init(importStatement))
Expand Down

0 comments on commit b3e434e

Please sign in to comment.