Skip to content

Commit

Permalink
node fs compat pr #2 (#16422)
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Conway <[email protected]>
Co-authored-by: Meghan Denny <[email protected]>
Co-authored-by: dylan-conway <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
5 people authored Jan 21, 2025
1 parent 427f60c commit 5819fe4
Show file tree
Hide file tree
Showing 184 changed files with 12,180 additions and 3,838 deletions.
4 changes: 4 additions & 0 deletions .vscode/launch.json

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

10 changes: 5 additions & 5 deletions docs/runtime/nodejs-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ This page is updated regularly to reflect compatibility status of the latest ver

🟢 Fully implemented. `EventEmitterAsyncResource` uses `AsyncResource` underneath. 100% of Node.js's test suite for EventEmitter passes.

### [`node:fs`](https://nodejs.org/api/fs.html)

🟢 Fully implemented. 92% of Node.js's test suite passes.

### [`node:http`](https://nodejs.org/api/http.html)

🟢 Fully implemented. Outgoing client request body is currently buffered instead of streamed.
Expand Down Expand Up @@ -88,7 +92,7 @@ This page is updated regularly to reflect compatibility status of the latest ver

### [`node:async_hooks`](https://nodejs.org/api/async_hooks.html)

🟡 `AsyncLocalStorage`, and `AsyncResource` are implemented. `AsyncResource` is missing `bind`. v8 hooks are stubbed.
🟡 `AsyncLocalStorage`, and `AsyncResource` are implemented. v8 promise hooks are not called, and its usage is [strongly discouraged](https://nodejs.org/docs/latest/api/async_hooks.html#async-hooks).

### [`node:child_process`](https://nodejs.org/api/child_process.html)

Expand All @@ -108,10 +112,6 @@ Some methods are not optimized yet.

🟡 Missing `Domain` `active`

### [`node:fs`](https://nodejs.org/api/fs.html)

🟡 Missing `statfs` `statfsSync`, `opendirSync`. `Dir` is partially implemented.

### [`node:http2`](https://nodejs.org/api/http2.html)

🟡 Client & server are implemented (95.25% of gRPC's test suite passes). Missing `options.allowHTTP1`, `options.enableConnectProtocol`, ALTSVC extension, and `http2stream.pushStream`.
Expand Down
2 changes: 2 additions & 0 deletions jj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("fs").writeFileSync("awa2", "meowy", { flag: "a" });
require("fs").writeFileSync("awa2", "meowy", { flag: "a" });
3 changes: 2 additions & 1 deletion scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ async function runTests() {
const absoluteTestPath = join(testsPath, testPath);
const title = relative(cwd, absoluteTestPath).replaceAll(sep, "/");
if (isNodeParallelTest(testPath)) {
const subcommand = title.includes("needs-test") ? "test" : "run";
const runWithBunTest = title.includes("needs-test") || readFileSync(absoluteTestPath, "utf-8").includes('bun:test');
const subcommand = runWithBunTest ? "test" : "run";
await runTest(title, async () => {
const { ok, error, stdout } = await spawnBun(execPath, {
cwd: cwd,
Expand Down
24 changes: 11 additions & 13 deletions src/StandaloneModuleGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,11 @@ pub const StandaloneModuleGraph = struct {
const file = bun.sys.openFileAtWindows(
bun.invalid_fd,
out,
// access_mask
w.SYNCHRONIZE | w.GENERIC_WRITE | w.GENERIC_READ | w.DELETE,
// create disposition
w.FILE_OPEN,
// create options
w.FILE_SYNCHRONOUS_IO_NONALERT | w.FILE_OPEN_REPARSE_POINT,
.{
.access_mask = w.SYNCHRONIZE | w.GENERIC_WRITE | w.GENERIC_READ | w.DELETE,
.disposition = w.FILE_OPEN,
.options = w.FILE_SYNCHRONOUS_IO_NONALERT | w.FILE_OPEN_REPARSE_POINT,
},
).unwrap() catch |e| {
Output.prettyErrorln("<r><red>error<r><d>:<r> failed to open temporary file to copy bun into\n{}", .{e});
Global.exit(1);
Expand Down Expand Up @@ -953,7 +952,7 @@ pub const StandaloneModuleGraph = struct {
const image_path = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2];

var nt_path_buf: bun.WPathBuffer = undefined;
const nt_path = bun.strings.addNTPathPrefix(&nt_path_buf, image_path);
const nt_path = bun.strings.addNTPathPrefixIfNeeded(&nt_path_buf, image_path);

const basename_start = std.mem.lastIndexOfScalar(u16, nt_path, '\\') orelse
return error.FileNotFound;
Expand All @@ -965,12 +964,11 @@ pub const StandaloneModuleGraph = struct {
return bun.sys.openFileAtWindows(
bun.FileDescriptor.cwd(),
nt_path,
// access_mask
w.SYNCHRONIZE | w.GENERIC_READ,
// create disposition
w.FILE_OPEN,
// create options
w.FILE_SYNCHRONOUS_IO_NONALERT | w.FILE_OPEN_REPARSE_POINT,
.{
.access_mask = w.SYNCHRONIZE | w.GENERIC_READ,
.disposition = w.FILE_OPEN,
.options = w.FILE_SYNCHRONOUS_IO_NONALERT | w.FILE_OPEN_REPARSE_POINT,
},
).unwrap() catch {
return error.FileNotFound;
};
Expand Down
Loading

0 comments on commit 5819fe4

Please sign in to comment.