From ad13b044cc86e6de199651c8ec2cbe28a0ab8663 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 7 Mar 2024 03:07:48 -0800 Subject: [PATCH] Merge and hopefully don't breka things along teh way --- .vscode/launch.json | 18 +- packages/bun-inspector-frontend/bun.lockb | Bin 9984 -> 11431 bytes packages/bun-internal-test/bun.lockb | Bin 3658 -> 3682 bytes packages/bun-usockets/src/eventing/libuv.c | 1 + src/bun.js/webcore/blob/ReadFile.zig | 5 +- src/io/PipeWriter.zig | 1 + src/js/builtins/ProcessObjectInternals.ts | 4 + src/js/node/child_process.js | 3 +- .../__snapshots__/bun-build-api.test.ts.snap | 234 +++++++++--------- .../child_process/child-process-stdio.test.js | 4 +- .../fixtures/child-process-echo-options.js | 3 +- test/js/node/fs/fs.test.ts | 2 +- test/js/node/process/process-stdin-echo.js | 6 +- .../es-module-lexer/es-module-lexer.test.ts | 10 +- 14 files changed, 157 insertions(+), 134 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1940f06653..d443761407 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -430,9 +430,13 @@ "name": "BUN_DEBUG_QUIET_LOGS", "value": "1" }, + { + "name": "BUN_DEBUG_jest", + "value": "1" + }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "1" } ] }, @@ -452,6 +456,18 @@ "name": "BUN_DEBUG_QUIET_LOGS", "value": "1" }, + { + "name": "BUN_DEBUG_EventLoop", + "value": "1" + }, + { + "name": "BUN_DEBUG_SYS", + "value": "1" + }, + { + "name": "BUN_DEBUG_PipeWriter", + "value": "1" + }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", "value": "2" diff --git a/packages/bun-inspector-frontend/bun.lockb b/packages/bun-inspector-frontend/bun.lockb index 9133cce88cd61685558aca8f0420c76a1d838c28..053ac067926ce392d265a461820d8da6df11a74d 100755 GIT binary patch delta 2137 zcmaJ?eN>ZG7=Pcn!8Rl|nBdsn@s-#>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(;#4MyOXx z1ubJ_pj4z-N}ySgkp?AXRD=mZQbbf3f@$Zycb|{`0lTpMe&_c)@0@qvyYGw^wdlLG z2RtK#tS9GgN;a$Jt&)w+4*6BEl7+6KuUYU|ik| zFfPwULNp&euq1eJ%yz*>PB@>6!p+h-Y>_TZ6uTEmQhJ}edkwT{JMQ*RrL~Il$I|X? zt^{v)CFKlxD5~2}x2O1t#~dD}c#SnGzt2|iu`jXfO`#)0*8Zy!<-A`pK}DIJ+DfJP z(-RJT+?k$xr`g$K`yU#UzVsz<8_D3fMB_L`a`5&Jx0o{) z1iuHw4hqJX6_NO%qEMO{%$Nv`Gm;u-hgL{eiBzS)uR=BO86o^TRGH-l2Z#TLB~*2( z#aM4ah(B81`;(71xcMUBS(`XFj1K1q zeq#3G)JX57P4Fib+;g5(;C<>8=_&~;G`LW$(je4eG(=a{)|-uGmh*Md25YV5qS;tq iR#$1ZKoHGF6GQ4W306e~y6Losv~gNXxed1l^#29#S)_0P diff --git a/packages/bun-internal-test/bun.lockb b/packages/bun-internal-test/bun.lockb index cef9d5e7e632bb9dfdcb8885c53cb4891fadbdd6..78a096d6a2da153439745a11a81f6f3d2cb5ebab 100755 GIT binary patch delta 199 zcmX>l^GIfbo?=?f-xD5RIO|R(Y-Q8T;Y|?tdR(Y-VUD((Ep|vuF3HT#E7niWFG`(!fm>p7BCqsjNghKc0JBg(z5oCK delta 182 zcmaDPb4q4{p5mVAQ`1%EmmAH#H;XNnf1d8Nt*0y=2#8Nu78Y^MuEWl0*F=9$#*B$G z_cQ8Ej%2iF?3_FkNba0`6G$>lmSnPLbeuv_loop); uv_run(loop->uv_loop, UV_RUN_ONCE); } diff --git a/src/bun.js/webcore/blob/ReadFile.zig b/src/bun.js/webcore/blob/ReadFile.zig index 6febb718cd..5e045134d3 100644 --- a/src/bun.js/webcore/blob/ReadFile.zig +++ b/src/bun.js/webcore/blob/ReadFile.zig @@ -564,7 +564,7 @@ pub const ReadFileUV = struct { on_complete_fn: ReadFile.OnReadFileCallback, is_regular_file: bool = false, - req: libuv.fs_t = libuv.fs_t.uninitialized, + req: libuv.fs_t = std.mem.zeroes(libuv.fs_t), pub fn start(loop: *libuv.Loop, store: *Store, off: SizeType, max_len: SizeType, comptime Handler: type, handler: *anyopaque) void { log("ReadFileUV.start", .{}); @@ -630,7 +630,8 @@ pub const ReadFileUV = struct { return; } - this.req.assertCleanedUp(); + this.req.deinit(); + this.req.data = this; if (libuv.uv_fs_fstat(this.loop, &this.req, bun.uvfdcast(opened_fd), &onFileInitialStat).errEnum()) |errno| { this.errno = bun.errnoToZigErr(errno); diff --git a/src/io/PipeWriter.zig b/src/io/PipeWriter.zig index 053e8de714..3d53546e00 100644 --- a/src/io/PipeWriter.zig +++ b/src/io/PipeWriter.zig @@ -1092,6 +1092,7 @@ pub fn WindowsStreamingWriter( this.closeWithoutReporting(); return; } + // success means that we send all the data inside current_payload const written = this.current_payload.size(); this.current_payload.reset(); diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts index 38c68893c2..5425ac5026 100644 --- a/src/js/builtins/ProcessObjectInternals.ts +++ b/src/js/builtins/ProcessObjectInternals.ts @@ -364,6 +364,10 @@ export function windowsEnv(internalEnv: InternalEnvMap, envMapList: Array { + return { ...internalEnv }; + }; + return new Proxy(internalEnv, { get(_, p) { return typeof p === "string" ? internalEnv[p.toUpperCase()] : undefined; diff --git a/src/js/node/child_process.js b/src/js/node/child_process.js index cf88291026..f97ca55839 100644 --- a/src/js/node/child_process.js +++ b/src/js/node/child_process.js @@ -1217,7 +1217,6 @@ class ChildProcess extends EventEmitter { // TODO: better ipc support const ipc = $isArray(stdio) && stdio[3] === "ipc"; - var env = options.envPairs || undefined; const detachedOption = options.detached; this.#encoding = options.encoding || undefined; @@ -1595,7 +1594,7 @@ const validateObject = (value, name, options = null) => { const nullable = options?.nullable ?? false; if ( (!nullable && value === null) || - (!allowArray && ArrayIsArray.$call(value)) || + (!allowArray && $isJSArray(value)) || (typeof value !== "object" && (!allowFunction || typeof value !== "function")) ) { throw new ERR_INVALID_ARG_TYPE(name, "object", value); diff --git a/test/bundler/__snapshots__/bun-build-api.test.ts.snap b/test/bundler/__snapshots__/bun-build-api.test.ts.snap index 08a1b40f3d..30746b67d6 100644 --- a/test/bundler/__snapshots__/bun-build-api.test.ts.snap +++ b/test/bundler/__snapshots__/bun-build-api.test.ts.snap @@ -1,117 +1,117 @@ -// Bun Snapshot v1, https://goo.gl/fbAQLP - -exports[`Bun.build BuildArtifact properties: hash 1`] = `"e4885a8bc2de343a"`; - -exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"cb8abf3391c2971f"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"e4885a8bc2de343a"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; - -exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; - -exports[`Bun.build outdir + reading out blobs works 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; - -exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; +// Bun Snapshot v1, https://goo.gl/fbAQLP + +exports[`Bun.build BuildArtifact properties: hash 1`] = `"e4885a8bc2de343a"`; + +exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"cb8abf3391c2971f"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"e4885a8bc2de343a"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; + +exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; + +exports[`Bun.build outdir + reading out blobs works 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; + +exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; diff --git a/test/js/node/child_process/child-process-stdio.test.js b/test/js/node/child_process/child-process-stdio.test.js index 40a9fa0efc..424fddb815 100644 --- a/test/js/node/child_process/child-process-stdio.test.js +++ b/test/js/node/child_process/child-process-stdio.test.js @@ -78,14 +78,14 @@ describe("process.stdin", () => { child.stdin.end(input); }); - it("should allow us to read > 65kb from stdin", done => { + it.only("should allow us to read > 65kb from stdin", done => { const numReps = Math.ceil((1024 * 1024) / 5); const input = Buffer.alloc("hello".length * numReps) .fill("hello") .toString(); // Child should read from stdin and write it back const child = spawn(bunExe(), [CHILD_PROCESS_FILE, "STDIN", "FLOWING"], { - env: { ...bunEnv, BUN_DEBUG_QUIET_LOGS: "0", BUN_DEBUG: "/tmp/out.log" }, + env: { ...bunEnv, BUN_DEBUG_QUIET_LOGS: "1" }, stdio: ["pipe", "pipe", "inherit"], }); let data = ""; diff --git a/test/js/node/child_process/fixtures/child-process-echo-options.js b/test/js/node/child_process/fixtures/child-process-echo-options.js index 7d6298bd02..0f5be894af 100644 --- a/test/js/node/child_process/fixtures/child-process-echo-options.js +++ b/test/js/node/child_process/fixtures/child-process-echo-options.js @@ -1,2 +1,3 @@ // TODO - bun has no `send` method in the process -process?.send({ env: process.env }); +const out = { env: { ...process.env } }; +process?.send(out); diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 428ef3cf8d..7553485223 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -1481,7 +1481,7 @@ describe("rmdirSync", () => { }); }); -describe.skipIf(isWindows)("createReadStream", () => { +describe("createReadStream", () => { it("works (1 chunk)", async () => { return await new Promise((resolve, reject) => { var stream = createReadStream(import.meta.dir + "/readFileSync.txt", {}); diff --git a/test/js/node/process/process-stdin-echo.js b/test/js/node/process/process-stdin-echo.js index 0475586258..77dabcb545 100644 --- a/test/js/node/process/process-stdin-echo.js +++ b/test/js/node/process/process-stdin-echo.js @@ -2,10 +2,10 @@ process.stdin.setEncoding("utf8"); process.stdin.on("data", data => { process.stdout.write(data); }); -process.stdin.once(process.argv[2] == "close-event" ? "close" : "end", () => { - process.stdout.write(process.argv[2] == "close-event" ? "ENDED-CLOSE" : "ENDED"); +process.stdin.once(process.argv[2] === "close-event" ? "close" : "end", () => { + process.stdout.write(process.argv[2] === "close-event" ? "ENDED-CLOSE" : "ENDED"); }); -if (process.argv[2] == "resume") { +if (process.argv[2] === "resume") { process.stdout.write("RESUMED"); process.stdin.resume(); } diff --git a/test/js/third_party/es-module-lexer/es-module-lexer.test.ts b/test/js/third_party/es-module-lexer/es-module-lexer.test.ts index 2202a61a67..e9f7ebbbd6 100644 --- a/test/js/third_party/es-module-lexer/es-module-lexer.test.ts +++ b/test/js/third_party/es-module-lexer/es-module-lexer.test.ts @@ -1,5 +1,5 @@ import { test, expect } from "bun:test"; -import { spawnSync } from "bun"; +import { spawn } from "bun"; import { bunEnv, bunExe } from "../../../harness"; import { join } from "path"; @@ -11,13 +11,13 @@ import { join } from "path"; // // At the time of writing, this includes WebAssembly compilation and Atomics // It excludes FinalizationRegistry since that doesn't need to keep the process alive. -test("es-module-lexer consistently loads", () => { +test("es-module-lexer consistently loads", async () => { for (let i = 0; i < 10; i++) { - const { stdout, exitCode } = spawnSync({ + const { stdout, exited } = spawn({ cmd: [bunExe(), join(import.meta.dir, "index.ts")], env: bunEnv, }); - expect(JSON.parse(stdout?.toString())).toEqual({ + expect(await new Response(stdout).json()).toEqual({ imports: [ { n: "b", @@ -40,6 +40,6 @@ test("es-module-lexer consistently loads", () => { }, ], }); - expect(exitCode).toBe(42); + expect(await exited).toBe(42); } });