From 769d7a168017c5f4a397aff25763b620b428be9b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 9 Apr 2024 17:02:23 -0400 Subject: [PATCH 01/13] fix: null is not an object at readableStreamCancel (#10091) * fix: null is not an object at readableStreamCancel * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/js/builtins/ReadableStreamInternals.ts | 16 +++++++--------- test/js/web/fetch/response.test.ts | 4 ++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/js/builtins/ReadableStreamInternals.ts b/src/js/builtins/ReadableStreamInternals.ts index 1cdcb1bc7b3b6..44651b98aa958 100644 --- a/src/js/builtins/ReadableStreamInternals.ts +++ b/src/js/builtins/ReadableStreamInternals.ts @@ -1354,16 +1354,14 @@ export function readableStreamCancel(stream, reason) { if (state === $streamErrored) return Promise.$reject($getByIdDirectPrivate(stream, "storedError")); $readableStreamClose(stream); - var controller = $getByIdDirectPrivate(stream, "readableStreamController"); - var cancel = controller.$cancel; - if (cancel) { - return cancel(controller, reason).$then(function () {}); - } + const controller = $getByIdDirectPrivate(stream, "readableStreamController"); + if (controller === null) return Promise.$resolve(); - var close = controller.close; - if (close) { - return Promise.$resolve(controller.close(reason)); - } + const cancel = controller.$cancel; + if (cancel) return cancel(controller, reason).$then(function () {}); + + const close = controller.close; + if (close) return Promise.$resolve(controller.close(reason)); $throwTypeError("ReadableStreamController has no cancel or close method"); } diff --git a/test/js/web/fetch/response.test.ts b/test/js/web/fetch/response.test.ts index 7a692f0453e75..2577e34053703 100644 --- a/test/js/web/fetch/response.test.ts +++ b/test/js/web/fetch/response.test.ts @@ -6,6 +6,10 @@ test("zero args returns an otherwise empty 200 response", () => { expect(response.statusText).toBe(""); }); +test("calling cancel() on response body doesn't throw", () => { + expect(() => new Response("").body?.cancel()).not.toThrow(); +}); + test("undefined args don't throw", () => { const response = new Response("", { status: undefined, From 81d021794ebb1eb0a7c293feff3066b35ba096ae Mon Sep 17 00:00:00 2001 From: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:42:23 -0400 Subject: [PATCH 02/13] stdout and sterr are in err (#10130) --- docs/runtime/shell.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/runtime/shell.md b/docs/runtime/shell.md index 0d13c56a11250..7379dc703a168 100644 --- a/docs/runtime/shell.md +++ b/docs/runtime/shell.md @@ -74,8 +74,8 @@ try { console.log(output); } catch (err) { console.log(`Failed with code ${err.exitCode}`); - console.log(output.stdout.toString()); - console.log(output.stderr.toString()); + console.log(err.stdout.toString()); + console.log(err.stderr.toString()); } ``` From baf0d7c40f2818d854cb06879a227809b1d4d8b7 Mon Sep 17 00:00:00 2001 From: Zack Radisic <56137411+zackradisic@users.noreply.github.com> Date: Wed, 10 Apr 2024 02:25:10 +0200 Subject: [PATCH 03/13] shell: Fix escaped newlines and add more tests (#10122) * Fix multiline args and add more tests * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/shell/interpreter.zig | 14 +++ src/shell/shell.zig | 13 +++ test/js/bun/shell/bunshell.test.ts | 170 +++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 774c5c98f10e5..1e894fd1edfe2 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -1065,6 +1065,20 @@ pub const Interpreter = struct { return shell.ParseError.Lex; } + if (comptime bun.Environment.allow_assert) { + const print = bun.Output.scoped(.ShellTokens, true); + var test_tokens = std.ArrayList(shell.Test.TestToken).initCapacity(arena.allocator(), lex_result.tokens.len) catch @panic("OOPS"); + defer test_tokens.deinit(); + for (lex_result.tokens) |tok| { + const test_tok = shell.Test.TestToken.from_real(tok, lex_result.strpool); + test_tokens.append(test_tok) catch @panic("OOPS"); + } + + const str = std.json.stringifyAlloc(bun.default_allocator, test_tokens.items[0..], .{}) catch @panic("OOPS"); + defer bun.default_allocator.free(str); + print("Tokens: {s}", .{str}); + } + out_parser.* = try bun.shell.Parser.new(arena.allocator(), lex_result, jsobjs); const script_ast = try out_parser.*.?.parse(); diff --git a/src/shell/shell.zig b/src/shell/shell.zig index 8665f26275efb..edd603f03a7f7 100644 --- a/src/shell/shell.zig +++ b/src/shell/shell.zig @@ -2629,6 +2629,16 @@ pub fn NewLexer(comptime encoding: StringEncoding) type { } continue; } + // Treat newline preceded by backslash as whitespace + else if (char == '\n') { + if (comptime bun.Environment.allow_assert) { + std.debug.assert(input.escaped); + } + if (self.chars.state != .Double) { + try self.break_word_impl(true, true, false); + } + continue; + } try self.appendCharToStrPool(char); } @@ -2979,9 +2989,11 @@ pub fn NewLexer(comptime encoding: StringEncoding) type { }, .normal => try self.tokens.append(.OpenParen), } + const prev_quote_state = self.chars.state; var sublexer = self.make_sublexer(kind); try sublexer.lex(); self.continue_from_sublexer(&sublexer); + self.chars.state = prev_quote_state; } fn appendStringToStrPool(self: *@This(), bunstr: bun.String) !void { @@ -3440,6 +3452,7 @@ pub fn ShellCharIter(comptime encoding: StringEncoding) type { else => return .{ .char = char, .escaped = false }, } }, + // We checked `self.state == .Single` above so this is impossible .Single => unreachable, } diff --git a/test/js/bun/shell/bunshell.test.ts b/test/js/bun/shell/bunshell.test.ts index 403cbfb408d2c..b69fa71006b80 100644 --- a/test/js/bun/shell/bunshell.test.ts +++ b/test/js/bun/shell/bunshell.test.ts @@ -351,6 +351,176 @@ describe("bunshell", () => { expect(stdout.toString()).toEqual(`noice\n`); }); + // Ported from GNU bash "quote.tests" + // https://github.com/bminor/bash/blob/f3b6bd19457e260b65d11f2712ec3da56cef463f/tests/quote.tests#L1 + // Some backtick tests are skipped, because of insane behavior: + // For some reason, even though $(...) and `...` are suppoed to be equivalent, + // doing: + // echo "`echo 'foo\ + // bar'`" + // + // gives: + // foobar + // + // While doing the same, but with $(...): + // echo "$(echo 'foo\ + // bar')" + // + // gives: + // foo\ + // bar + // + // I'm not sure why, this isn't documented behavior, so I'm choosing to ignore it. + describe("gnu_quote", () => { + // An unfortunate consequence of our use of String.raw and tagged template + // functions for the shell make it so that we have to use { raw: string } to do + // backtick command substitution + const BACKTICK = { raw: "`" }; + + // Single Quote + TestBuilder.command` +echo 'foo +bar' +echo 'foo +bar' +echo 'foo\ +bar' +` + .stdout("foo\nbar\nfoo\nbar\nfoo\\\nbar\n") + .runAsTest("Single Quote"); + + TestBuilder.command` +echo "foo +bar" +echo "foo +bar" +echo "foo\ +bar" +` + .stdout("foo\nbar\nfoo\nbar\nfoobar\n") + .runAsTest("Double Quote"); + + TestBuilder.command` +echo ${BACKTICK}echo 'foo +bar'${BACKTICK} +echo ${BACKTICK}echo 'foo +bar'${BACKTICK} +echo ${BACKTICK}echo 'foo\ +bar'${BACKTICK} +` + .stdout( + `foo bar +foo bar +foobar\n`, + ) + .todo("insane backtick behavior") + .runAsTest("Backslash Single Quote"); + + TestBuilder.command` +echo "${BACKTICK}echo 'foo +bar'${BACKTICK}" +echo "${BACKTICK}echo 'foo +bar'${BACKTICK}" +echo "${BACKTICK}echo 'foo\ +bar'${BACKTICK}" +` + .stdout( + `foo +bar +foo +bar +foobar\n`, + ) + .todo("insane backtick behavior") + .runAsTest("Double Quote Backslash Single Quote"); + + TestBuilder.command` +echo $(echo 'foo +bar') +echo $(echo 'foo +bar') +echo $(echo 'foo\ +bar') +` + .stdout( + `foo bar +foo bar +foo\\ bar\n`, + ) + .runAsTest("Dollar Paren Single Quote"); + + TestBuilder.command` +echo "$(echo 'foo +bar')" +echo "$(echo 'foo +bar')" +echo "$(echo 'foo\ +bar')" +` + .stdout( + `foo +bar +foo +bar +foo\\ +bar\n`, + ) + .runAsTest("Dollar Paren Double Quote"); + + TestBuilder.command` +echo "$(echo 'foo +bar')" +echo "$(echo 'foo +bar')" +echo "$(echo 'foo\ +bar')" +` + .stdout( + `foo +bar +foo +bar +foo\\ +bar\n`, + ) + .runAsTest("Double Quote Dollar Paren Single Quote"); + }); + + describe("escaped_newline", () => { + const printArgs = /* ts */ `console.log(JSON.stringify(process.argv))`; + + TestBuilder.command/* sh */ `${BUN} run ./code.ts hi hello \ + on a newline! + ` + .ensureTempDir() + .file("code.ts", printArgs) + .stdout(out => expect(JSON.parse(out).slice(2)).toEqual(["hi", "hello", "on", "a", "newline!"])) + .runAsTest("single"); + + TestBuilder.command/* sh */ `${BUN} run ./code.ts hi hello \ + on a newline! \ + and \ + a few \ + others! + ` + .ensureTempDir() + .file("code.ts", printArgs) + .stdout(out => + expect(JSON.parse(out).slice(2)).toEqual(["hi", "hello", "on", "a", "newline!", "and", "a", "few", "others!"]), + ) + .runAsTest("many"); + + TestBuilder.command/* sh */ `${BUN} run ./code.ts hi hello \ + on a newline! \ + ooga" +booga" + ` + .ensureTempDir() + .file("code.ts", printArgs) + .stdout(out => expect(JSON.parse(out).slice(2)).toEqual(["hi", "hello", "on", "a", "newline!", "ooga\nbooga"])) + .runAsTest("quotes"); + }); + describe("glob expansion", () => { // Issue #8403: https://github.com/oven-sh/bun/issues/8403 TestBuilder.command`ls *.sdfljsfsdf` From 698d0f7c8782c5ebb68fa3c87f50ca3e7245312c Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 9 Apr 2024 20:42:42 -0700 Subject: [PATCH 04/13] fix vscode json handling in prettier (#10133) --- .prettierrc | 9 + .vscode/c_cpp_properties.json | 24 +-- .vscode/extensions.json | 4 +- .vscode/launch.json | 392 +++++++++++++++++----------------- .vscode/settings.json | 40 ++-- .vscode/tasks.json | 18 +- 6 files changed, 248 insertions(+), 239 deletions(-) diff --git a/.prettierrc b/.prettierrc index b62f9dff183f0..c9da1bd439c65 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,6 +5,15 @@ "useTabs": false, "quoteProps": "preserve", "overrides": [ + { + "files": [".vscode/*.json"], + "options": { + "parser": "jsonc", + "quoteProps": "preserve", + "singleQuote": false, + "trailingComma": "all" + } + }, { "files": ["*.md"], "options": { diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fda3a058d8a01..3bd648a1ffd99 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -17,7 +17,7 @@ "${workspaceFolder}/src/deps", "${workspaceFolder}/src/napi/*", "${workspaceFolder}/packages/bun-usockets/src", - "${workspaceFolder}/packages/" + "${workspaceFolder}/packages/", ], "browse": { "path": [ @@ -30,10 +30,10 @@ "${workspaceFolder}/src/deps/boringssl/include/*", "${workspaceFolder}/packages/bun-usockets/*", "${workspaceFolder}/packages/bun-uws/*", - "${workspaceFolder}/src/napi/*" + "${workspaceFolder}/src/napi/*", ], "limitSymbolsToIncludedHeaders": true, - "databaseFilename": ".vscode/cppdb" + "databaseFilename": ".vscode/cppdb", }, "defines": [ "STATICALLY_LINKED_WITH_JavaScriptCore=1", @@ -44,12 +44,12 @@ "BUILDING_JSCONLY__", "USE_FOUNDATION=1", "ASSERT_ENABLED=1", - "DU_DISABLE_RENAMING=1" + "DU_DISABLE_RENAMING=1", ], "macFrameworkPath": [], "compilerPath": "${workspaceFolder}/.vscode/clang++", "cStandard": "c17", - "cppStandard": "c++20" + "cppStandard": "c++20", }, { "name": "BunWithJSCDebug", @@ -72,7 +72,7 @@ "${workspaceFolder}/src/deps", "${workspaceFolder}/src/napi/*", "${workspaceFolder}/packages/bun-usockets/src", - "${workspaceFolder}/packages/" + "${workspaceFolder}/packages/", ], "browse": { "path": [ @@ -94,10 +94,10 @@ "${workspaceFolder}/src/deps/boringssl/include/", "${workspaceFolder}/packages/bun-usockets/", "${workspaceFolder}/packages/bun-uws/", - "${workspaceFolder}/src/napi" + "${workspaceFolder}/src/napi", ], "limitSymbolsToIncludedHeaders": true, - "databaseFilename": ".vscode/cppdb_debug" + "databaseFilename": ".vscode/cppdb_debug", }, "defines": [ "STATICALLY_LINKED_WITH_JavaScriptCore=1", @@ -108,13 +108,13 @@ "BUILDING_JSCONLY__", "USE_FOUNDATION=1", "ASSERT_ENABLED=1", - "DU_DISABLE_RENAMING=1" + "DU_DISABLE_RENAMING=1", ], "macFrameworkPath": [], "compilerPath": "${workspaceFolder}/.vscode/clang++", "cStandard": "c17", - "cppStandard": "c++20" - } + "cppStandard": "c++20", + }, ], - "version": 4 + "version": 4, } diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0f78c35d22701..29d8dbad5a931 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -28,6 +28,6 @@ "tamasfe.even-better-toml", // Other - "bierner.comment-tagged-templates" - ] + "bierner.comment-tagged-templates", + ], } diff --git a/.vscode/launch.json b/.vscode/launch.json index 470c19c916884..619197fac0429 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,9 +18,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -33,9 +33,9 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "1", - "BUN_DEBUG_FileReader": "1" + "BUN_DEBUG_FileReader": "1", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -47,9 +47,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "0" + "BUN_GARBAGE_COLLECTOR_LEVEL": "0", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -61,9 +61,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "0", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -75,9 +75,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -89,9 +89,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -104,14 +104,14 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?wait=1" + "BUN_INSPECT": "ws://localhost:0/?wait=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "lldb", @@ -124,14 +124,14 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?break=1" + "BUN_INSPECT": "ws://localhost:0/?break=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // bun run [file] { @@ -144,9 +144,9 @@ "env": { "FORCE_COLOR": "0", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -158,9 +158,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "0" + "BUN_GARBAGE_COLLECTOR_LEVEL": "0", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -172,9 +172,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "0", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -186,9 +186,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -200,9 +200,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -215,14 +215,14 @@ "FORCE_COLOR": "0", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?wait=1" + "BUN_INSPECT": "ws://localhost:0/?wait=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "lldb", @@ -235,14 +235,14 @@ "FORCE_COLOR": "0", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?break=1" + "BUN_INSPECT": "ws://localhost:0/?break=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // bun test [...] { @@ -255,9 +255,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -269,9 +269,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "0" + "BUN_GARBAGE_COLLECTOR_LEVEL": "0", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -283,9 +283,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "0", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -297,9 +297,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -311,9 +311,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -326,14 +326,14 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?wait=1" + "BUN_INSPECT": "ws://localhost:0/?wait=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "lldb", @@ -346,14 +346,14 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/?break=1" + "BUN_INSPECT": "ws://localhost:0/?break=1", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // bun exec [...] { @@ -366,9 +366,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, // bun test [*] { @@ -381,9 +381,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -395,9 +395,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "0" + "BUN_GARBAGE_COLLECTOR_LEVEL": "0", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -410,14 +410,14 @@ "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", "BUN_GARBAGE_COLLECTOR_LEVEL": "2", - "BUN_INSPECT": "ws://localhost:0/" + "BUN_INSPECT": "ws://localhost:0/", }, "console": "internalConsole", "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "lldb", @@ -429,9 +429,9 @@ "env": { "FORCE_COLOR": "1", "BUN_DEBUG_QUIET_LOGS": "1", - "BUN_GARBAGE_COLLECTOR_LEVEL": "2" + "BUN_GARBAGE_COLLECTOR_LEVEL": "2", }, - "console": "internalConsole" + "console": "internalConsole", }, { "type": "lldb", @@ -440,7 +440,7 @@ "program": "node", "args": ["src/runner.node.mjs"], "cwd": "${workspaceFolder}/packages/bun-internal-test", - "console": "internalConsole" + "console": "internalConsole", }, // Windows: bun test [file] { @@ -453,22 +453,22 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_jest", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "1" - } - ] + "value": "1", + }, + ], }, { "type": "cppvsdbg", @@ -480,33 +480,33 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_EventLoop", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_uv", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_SYS", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_PipeWriter", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -518,17 +518,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "0" - } - ] + "value": "0", + }, + ], }, { "type": "cppvsdbg", @@ -540,17 +540,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "0" + "value": "0", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -562,26 +562,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?wait=1" - } + "value": "ws://localhost:0/?wait=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "cppvsdbg", @@ -593,26 +593,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?break=1" - } + "value": "ws://localhost:0/?break=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // Windows: bun run [file] { @@ -625,17 +625,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -647,14 +647,14 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "0" - } - ] + "value": "0", + }, + ], }, { "type": "cppvsdbg", @@ -666,17 +666,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "0" + "value": "0", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -688,26 +688,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?wait=1" - } + "value": "ws://localhost:0/?wait=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "cppvsdbg", @@ -719,26 +719,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?break=1" - } + "value": "ws://localhost:0/?break=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // Windows: bun test [...] { @@ -751,17 +751,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -773,17 +773,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "0" - } - ] + "value": "0", + }, + ], }, { "type": "cppvsdbg", @@ -795,17 +795,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "0" + "value": "0", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -817,17 +817,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -839,17 +839,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -861,26 +861,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?wait=1" - } + "value": "ws://localhost:0/?wait=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "cppvsdbg", @@ -892,26 +892,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/?break=1" - } + "value": "ws://localhost:0/?break=1", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, // Windows: bun exec [...] { @@ -924,17 +924,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, // Windows: bun test [*] { @@ -947,17 +947,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" - } - ] + "value": "2", + }, + ], }, { "type": "cppvsdbg", @@ -969,17 +969,17 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "1" + "value": "1", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "0" - } - ] + "value": "0", + }, + ], }, { "type": "cppvsdbg", @@ -991,26 +991,26 @@ "environment": [ { "name": "FORCE_COLOR", - "value": "1" + "value": "1", }, { "name": "BUN_DEBUG_QUIET_LOGS", - "value": "0" + "value": "0", }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "2", }, { "name": "BUN_INSPECT", - "value": "ws://localhost:0/" - } + "value": "ws://localhost:0/", + }, ], "serverReadyAction": { "pattern": "https://debug.bun.sh/#localhost:([0-9]+)/", "uriFormat": "https://debug.bun.sh/#ws://localhost:%s/", - "action": "openExternally" - } + "action": "openExternally", + }, }, { "type": "cppvsdbg", @@ -1019,19 +1019,19 @@ "program": "node", "args": ["src/runner.node.mjs"], "cwd": "${workspaceFolder}/packages/bun-internal-test", - "console": "internalConsole" - } + "console": "internalConsole", + }, ], "inputs": [ { "id": "commandLine", "type": "promptString", - "description": "Usage: bun [...]" + "description": "Usage: bun [...]", }, { "id": "testName", "type": "promptString", - "description": "Usage: bun test [...]" - } - ] + "description": "Usage: bun test [...]", + }, + ], } diff --git a/.vscode/settings.json b/.vscode/settings.json index e0d404062f814..4961329465ad7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,7 @@ "node_modules": true, ".git": true, "src/bun.js/WebKit": true, - "src/deps/*/**": true + "src/deps/*/**": true, }, "search.followSymlinks": false, "search.useIgnoreFiles": true, @@ -34,7 +34,7 @@ "[zig]": { "editor.tabSize": 4, "editor.useTabStops": false, - "editor.defaultFormatter": "ziglang.vscode-zig" + "editor.defaultFormatter": "ziglang.vscode-zig", }, // C++ @@ -42,41 +42,41 @@ "cmake.configureOnOpen": false, "C_Cpp.errorSquiggles": "enabled", "[cpp]": { - "editor.defaultFormatter": "xaver.clang-format" + "editor.defaultFormatter": "xaver.clang-format", }, "[c]": { - "editor.defaultFormatter": "xaver.clang-format" + "editor.defaultFormatter": "xaver.clang-format", }, "[h]": { - "editor.defaultFormatter": "xaver.clang-format" + "editor.defaultFormatter": "xaver.clang-format", }, // JavaScript "prettier.enable": true, - "prettier.configPath": "${workspaceFolder}/.prettierrc", + "prettier.configPath": ".prettierrc", "eslint.workingDirectories": ["${workspaceFolder}/packages/bun-types"], "[javascript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, "[javascriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, // TypeScript "typescript.tsdk": "${workspaceFolder}/node_modules/typescript/lib", "[typescript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, "[typescriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, // JSON "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, "[jsonc]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, // Markdown @@ -89,23 +89,23 @@ "editor.quickSuggestions": { "comments": "off", "strings": "off", - "other": "off" - } + "other": "off", + }, }, // TOML "[toml]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, // YAML "[yaml]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", }, // Docker "[dockerfile]": { - "editor.formatOnSave": false + "editor.formatOnSave": false, }, // Files @@ -122,7 +122,7 @@ "**/*.i": true, }, "files.associations": { - "*.idl": "cpp" + "*.idl": "cpp", }, "C_Cpp.files.exclude": { "**/.vscode": true, @@ -140,6 +140,6 @@ "WebKit/WebCore": true, "WebKit/WebDriver": true, "WebKit/WebKitBuild": true, - "WebKit/WebInspectorUI": true - } + "WebKit/WebInspectorUI": true, + }, } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cec77199e526b..faf1dc0d22400 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,13 +6,13 @@ "label": "Install Dependencies", "command": "scripts/all-dependencies.sh", "windows": { - "command": "scripts/all-dependencies.ps1" + "command": "scripts/all-dependencies.ps1", }, "icon": { - "id": "arrow-down" + "id": "arrow-down", }, "options": { - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", }, }, { @@ -21,13 +21,13 @@ "dependsOn": ["Install Dependencies"], "command": "scripts/setup.sh", "windows": { - "command": "scripts/setup.ps1" + "command": "scripts/setup.ps1", }, "icon": { - "id": "check" + "id": "check", }, "options": { - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", }, }, { @@ -37,10 +37,10 @@ "command": "bun", "args": ["run", "build"], "icon": { - "id": "gear" + "id": "gear", }, "options": { - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", }, "isBuildCommand": true, "runOptions": { @@ -48,5 +48,5 @@ "reevaluateOnRerun": true, }, }, - ] + ], } From e209ae81ddb34f9298f9e2b84ae9019b1a9c78f0 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 9 Apr 2024 22:41:07 -0700 Subject: [PATCH 05/13] meta: ensure there's a single 'bun' import per file in zig (#10137) * meta: ensure there's a single 'bun' import per file in zig * undo this change in codegen --- build.zig | 2 - misctools/fetch.zig | 6 +- misctools/http_bench.zig | 2 +- misctools/machbench.zig | 6 +- src/__global.zig | 8 +-- src/allocators.zig | 2 +- src/analytics/analytics_thread.zig | 4 +- src/bench/string-handling.zig | 2 +- src/bun.js/api/BunObject.zig | 60 ++++++++--------- src/bun.js/api/JSTranspiler.zig | 4 +- src/bun.js/api/bun/dns_resolver.zig | 12 ++-- src/bun.js/api/bun/socket.zig | 10 +-- src/bun.js/api/bun/spawn.zig | 2 +- src/bun.js/api/bun/spawn/stdio.zig | 6 +- src/bun.js/api/bun/subprocess.zig | 10 +-- src/bun.js/api/bun/x509.zig | 2 +- src/bun.js/api/ffi.zig | 54 ++++++++-------- src/bun.js/api/filesystem_router.zig | 16 ++--- src/bun.js/api/html_rewriter.zig | 4 +- src/bun.js/api/server.zig | 64 +++++++++---------- src/bun.js/base.zig | 6 +- src/bun.js/bindings/bindings-generator.zig | 4 +- src/bun.js/bindings/bindings.zig | 4 +- src/bun.js/bindings/bun-simdutf.zig | 3 +- src/bun.js/bindings/codegen.zig | 3 +- src/bun.js/bindings/exports.zig | 4 +- .../bindings/generated_classes_list.zig | 3 +- src/bun.js/bindings/headers-replacements.zig | 4 +- src/bun.js/bindings/headers.zig | 7 +- src/bun.js/config.zig | 2 +- src/bun.js/event_loop.zig | 4 +- src/bun.js/ipc.zig | 6 +- src/bun.js/javascript.zig | 50 +++++++-------- src/bun.js/javascript_core_c_api.zig | 8 +-- src/bun.js/module_loader.zig | 48 +++++++------- src/bun.js/node/dir_iterator.zig | 4 +- src/bun.js/node/node_fs.zig | 2 +- src/bun.js/node/node_fs_binding.zig | 2 +- src/bun.js/node/node_fs_stat_watcher.zig | 2 +- src/bun.js/node/node_fs_watcher.zig | 2 +- src/bun.js/node/node_os.zig | 2 +- src/bun.js/node/os/constants.zig | 2 +- src/bun.js/node/util/parse_args_utils.zig | 5 +- src/bun.js/node/util/validators.zig | 2 +- src/bun.js/rare_data.zig | 10 +-- src/bun.js/script_execution_context.zig | 2 +- src/bun.js/test/jest.zig | 18 +++--- src/bun.js/webcore.zig | 4 +- src/bun.js/webcore/blob.zig | 22 +++---- src/bun.js/webcore/body.zig | 20 +++--- src/bun.js/webcore/encoding.zig | 18 +++--- src/bun.js/webcore/request.zig | 20 +++--- src/bun.js/webcore/response.zig | 20 +++--- src/bun.js/webcore/streams.zig | 18 +++--- src/bun_js.zig | 6 +- src/bundler.zig | 4 +- src/bundler/bundle_v2.zig | 8 +-- src/bundler/entry_points.zig | 2 +- src/bunfig.zig | 2 +- src/cache.zig | 2 +- src/cli.zig | 4 +- src/cli/build_command.zig | 2 +- src/cli/create_command.zig | 10 +-- src/cli/init_command.zig | 2 +- src/cli/install_completions_command.zig | 6 +- src/cli/test_command.zig | 8 +-- src/cli/upgrade_command.zig | 8 +-- src/comptime_string_map.zig | 13 ++-- src/copy_file.zig | 2 +- src/crash_reporter.zig | 10 +-- src/css_scanner.zig | 2 +- src/defines.zig | 2 +- src/deps/boringssl.translated.zig | 7 +- src/deps/c_ares.zig | 14 ++-- src/deps/lol-html.zig | 2 +- src/deps/picohttp.zig | 9 +-- src/deps/uws.zig | 2 +- src/env_loader.zig | 2 +- src/feature_flags.zig | 6 +- src/http/header_builder.zig | 3 +- src/http/websocket_http_client.zig | 6 +- src/http/zlib.zig | 2 +- src/import_record.zig | 4 +- src/install/bin.zig | 4 +- src/install/install.zig | 2 +- src/install/npm.zig | 14 ++-- src/install/resolvers/folder_resolver.zig | 4 +- src/io/io_linux.zig | 2 +- src/io/pipes.zig | 2 +- src/js_ast.zig | 6 +- src/js_lexer.zig | 2 +- src/js_lexer_tables.zig | 5 +- src/js_parser.zig | 4 +- src/js_printer.zig | 2 +- src/json_parser.zig | 2 +- src/libarchive/libarchive.zig | 2 +- src/linker.zig | 4 +- src/logger.zig | 4 +- src/main_wasm.zig | 6 +- src/meta.zig | 3 +- src/napi/napi.zig | 4 +- src/node_fallbacks.zig | 2 +- src/options.zig | 4 +- src/output.zig | 18 +++--- src/panic_handler.zig | 2 +- src/renamer.zig | 6 +- src/report.zig | 6 +- src/resolver/package_json.zig | 2 +- src/resolver/resolver.zig | 2 +- src/resolver/tsconfig_json.zig | 2 +- src/router.zig | 2 +- src/sha.zig | 5 +- src/shell/subproc.zig | 12 ++-- src/shell/util.zig | 6 +- src/sourcemap/sourcemap.zig | 2 +- src/string_immutable.zig | 2 +- src/string_types.zig | 2 +- src/thread_pool.zig | 2 +- src/toml/toml_lexer.zig | 2 +- src/toml/toml_parser.zig | 2 +- src/work_pool.zig | 3 +- 121 files changed, 461 insertions(+), 452 deletions(-) diff --git a/build.zig b/build.zig index 6b18ae9ed25fa..5a3eb7868ad86 100644 --- a/build.zig +++ b/build.zig @@ -629,5 +629,3 @@ pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, obj_step: * obj.link_function_sections = true; } } - -// ! \ No newline at end of file diff --git a/misctools/fetch.zig b/misctools/fetch.zig index 5e8701eb9c82d..b027a65f8120b 100644 --- a/misctools/fetch.zig +++ b/misctools/fetch.zig @@ -14,13 +14,13 @@ pub usingnamespace @import("root").bun; const clap = bun.clap; const URL = @import("../src/url.zig").URL; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; const HeadersTuple = ColonListType(string, noop_resolver); const path_handler = @import("../src/resolver/resolve_path.zig"); -const HTTPThread = @import("root").bun.http.HTTPThread; -const HTTP = @import("root").bun.http; +const HTTPThread = bun.http.HTTPThread; +const HTTP = bun.http; fn noop_resolver(in: string) !string { return in; } diff --git a/misctools/http_bench.zig b/misctools/http_bench.zig index 27546881c4d44..1df8256323743 100644 --- a/misctools/http_bench.zig +++ b/misctools/http_bench.zig @@ -177,7 +177,7 @@ pub const Arguments = struct { } }; -const HTTP = @import("root").bun.http; +const HTTP = bun.http; const NetworkThread = HTTP.NetworkThread; var stdout_: std.fs.File = undefined; diff --git a/misctools/machbench.zig b/misctools/machbench.zig index e4a929e814ba4..0c2419fb11c8a 100644 --- a/misctools/machbench.zig +++ b/misctools/machbench.zig @@ -13,13 +13,13 @@ const C = bun.C; const clap = @import("../src/deps/zig-clap/clap.zig"); const URL = @import("../src/url.zig").URL; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const Method = @import("../src/http/method.zig").Method; const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType; const HeadersTuple = ColonListType(string, noop_resolver); const path_handler = @import("../src/resolver/resolve_path.zig"); -const NetworkThread = @import("root").bun.http.NetworkThread; -const HTTP = @import("root").bun.http; +const NetworkThread = bun.http.NetworkThread; +const HTTP = bun.http; fn noop_resolver(in: string) !string { return in; } diff --git a/src/__global.zig b/src/__global.zig index c4c4bcadbcbfa..4bad953bbabc6 100644 --- a/src/__global.zig +++ b/src/__global.zig @@ -2,9 +2,9 @@ const std = @import("std"); const Environment = @import("./env.zig"); const Output = @import("output.zig"); -const use_mimalloc = @import("root").bun.use_mimalloc; +const use_mimalloc = bun.use_mimalloc; const StringTypes = @import("./string_types.zig"); -const Mimalloc = @import("root").bun.Mimalloc; +const Mimalloc = bun.Mimalloc; const bun = @import("root").bun; const version_string = Environment.version_string; @@ -61,7 +61,7 @@ else pub inline fn getStartTime() i128 { if (Environment.isTest) return 0; - return @import("root").bun.start_time; + return bun.start_time; } pub fn setThreadName(name: StringTypes.stringZ) void { @@ -194,7 +194,7 @@ pub fn crash() noreturn { } const Global = @This(); -const string = @import("root").bun.string; +const string = bun.string; pub const BunInfo = struct { bun_version: string, diff --git a/src/allocators.zig b/src/allocators.zig index 5af6c1014cbe7..06caa08ac0d20 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -80,7 +80,7 @@ fn OverflowGroup(comptime Block: type) type { // ...right? const max = 4095; const UsedSize = std.math.IntFittingRange(0, max + 1); - const default_allocator = @import("root").bun.default_allocator; + const default_allocator = bun.default_allocator; used: UsedSize = 0, allocated: UsedSize = 0, ptrs: [max]*Block = undefined, diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig index c4ecd60897d31..95f0d197187b5 100644 --- a/src/analytics/analytics_thread.zig +++ b/src/analytics/analytics_thread.zig @@ -12,13 +12,13 @@ const C = bun.C; const sync = @import("../sync.zig"); const std = @import("std"); -const HTTP = @import("root").bun.http; +const HTTP = bun.http; const URL = @import("../url.zig").URL; const Fs = @import("../fs.zig"); const Analytics = @import("./analytics_schema.zig").analytics; const Writer = @import("./analytics_schema.zig").Writer; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const Futex = @import("../futex.zig"); const Semver = @import("../install/semver.zig"); diff --git a/src/bench/string-handling.zig b/src/bench/string-handling.zig index 23f558eb8a363..8d778e35646f2 100644 --- a/src/bench/string-handling.zig +++ b/src/bench/string-handling.zig @@ -1,4 +1,4 @@ -const strings = @import("root").bun.strings; +const strings = bun.strings; const std = @import("std"); pub fn main() anyerror!void { diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 5bf82aeecb0ef..954fde690717b 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -155,7 +155,7 @@ pub const BunObject = struct { }; const Bun = @This(); -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const uv = bun.windows.libuv; const Environment = bun.Environment; @@ -163,8 +163,8 @@ const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; const IdentityContext = @import("../../identity_context.zig").IdentityContext; @@ -173,7 +173,7 @@ const Resolver = @import("../../resolver/resolver.zig"); const ast = @import("../../import_record.zig"); const MacroEntryPoint = bun.bundler.MacroEntryPoint; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../../api/schema.zig").Api; const options = @import("../../options.zig"); const Bundler = bun.Bundler; @@ -184,7 +184,7 @@ const js_ast = bun.JSAst; const NodeFallbackModules = @import("../../node_fallbacks.zig"); const ImportKind = ast.ImportKind; const Analytics = @import("../../analytics/analytics_thread.zig"); -const ZigString = @import("root").bun.JSC.ZigString; +const ZigString = bun.JSC.ZigString; const Runtime = @import("../../runtime.zig"); const Router = @import("./filesystem_router.zig"); const ImportRecord = ast.ImportRecord; @@ -192,37 +192,37 @@ const DotEnv = @import("../../env_loader.zig"); const ParseResult = bun.bundler.ParseResult; const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../../resolver/package_json.zig").MacroMap; -const WebCore = @import("root").bun.JSC.WebCore; +const WebCore = bun.JSC.WebCore; const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; -const js = @import("root").bun.JSC.C; -const JSC = @import("root").bun.JSC; +const js = bun.JSC.C; +const JSC = bun.JSC; const JSError = @import("../base.zig").JSError; const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer; const getAllocator = @import("../base.zig").getAllocator; -const JSValue = @import("root").bun.JSC.JSValue; - -const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject; -const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef; -const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr; -const ConsoleObject = @import("root").bun.JSC.ConsoleObject; -const Node = @import("root").bun.JSC.Node; -const ZigException = @import("root").bun.JSC.ZigException; -const ZigStackTrace = @import("root").bun.JSC.ZigStackTrace; -const ErrorableResolvedSource = @import("root").bun.JSC.ErrorableResolvedSource; -const ResolvedSource = @import("root").bun.JSC.ResolvedSource; -const JSPromise = @import("root").bun.JSC.JSPromise; -const JSInternalPromise = @import("root").bun.JSC.JSInternalPromise; -const JSModuleLoader = @import("root").bun.JSC.JSModuleLoader; -const JSPromiseRejectionOperation = @import("root").bun.JSC.JSPromiseRejectionOperation; -const Exception = @import("root").bun.JSC.Exception; -const ErrorableZigString = @import("root").bun.JSC.ErrorableZigString; -const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; -const VM = @import("root").bun.JSC.VM; -const JSFunction = @import("root").bun.JSC.JSFunction; +const JSValue = bun.JSC.JSValue; + +const JSGlobalObject = bun.JSC.JSGlobalObject; +const ExceptionValueRef = bun.JSC.ExceptionValueRef; +const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; +const ConsoleObject = bun.JSC.ConsoleObject; +const Node = bun.JSC.Node; +const ZigException = bun.JSC.ZigException; +const ZigStackTrace = bun.JSC.ZigStackTrace; +const ErrorableResolvedSource = bun.JSC.ErrorableResolvedSource; +const ResolvedSource = bun.JSC.ResolvedSource; +const JSPromise = bun.JSC.JSPromise; +const JSInternalPromise = bun.JSC.JSInternalPromise; +const JSModuleLoader = bun.JSC.JSModuleLoader; +const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation; +const Exception = bun.JSC.Exception; +const ErrorableZigString = bun.JSC.ErrorableZigString; +const ZigGlobalObject = bun.JSC.ZigGlobalObject; +const VM = bun.JSC.VM; +const JSFunction = bun.JSC.JSFunction; const Config = @import("../config.zig"); const URL = @import("../../url.zig").URL; const Transpiler = bun.JSC.API.JSTranspiler; @@ -3410,7 +3410,7 @@ const TOMLObject = struct { globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { - var arena = @import("root").bun.ArenaAllocator.init(globalThis.allocator()); + var arena = bun.ArenaAllocator.init(globalThis.allocator()); const allocator = arena.allocator(); defer arena.deinit(); var log = logger.Log.init(default_allocator); @@ -3481,7 +3481,7 @@ pub const Timer = struct { return VirtualMachine.get().timer.last_id; } - const uws = @import("root").bun.uws; + const uws = bun.uws; // TODO: reference count to avoid multiple Strong references to the same // object in setInterval diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index e5c1d53874f6a..60e8cf4125464 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -45,7 +45,7 @@ const Expr = JSAst.Expr; pub usingnamespace JSC.Codegen.JSTranspiler; bundler: Bundler.Bundler, -arena: @import("root").bun.ArenaAllocator, +arena: bun.ArenaAllocator, transpiler_options: TranspilerOptions, scan_pass_result: ScanPassResult, buffer_writer: ?JSPrinter.BufferWriter = null, @@ -744,7 +744,7 @@ pub fn constructor( globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame, ) callconv(.C) ?*Transpiler { - var temp = @import("root").bun.ArenaAllocator.init(getAllocator(globalThis)); + var temp = bun.ArenaAllocator.init(getAllocator(globalThis)); const arguments = callframe.arguments(3); var args = JSC.Node.ArgumentsSlice.init( globalThis.bunVM(), diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index aa5fd018d5b22..125571df52d89 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -1,16 +1,16 @@ const Bun = @This(); -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const c_ares = bun.c_ares; @@ -330,7 +330,7 @@ pub fn addrInfoToJSArray( globalThis: *JSC.JSGlobalObject, ) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); const array = JSC.JSValue.createEmptyArray( globalThis, addrInfoCount(addr_info), @@ -642,7 +642,7 @@ pub const GetAddrInfo = struct { .addrinfo => |addrinfo| addrInfoToJSArray(globalThis.allocator(), addrinfo orelse return null, globalThis), .list => |list| brk: { var stack = std.heap.stackFallback(2048, globalThis.allocator()); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); const array = JSC.JSValue.createEmptyArray(globalThis, @as(u32, @truncate(list.items.len))); var i: u32 = 0; const items: []const Result = list.items; diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index b6320c44f139c..f28f07cf6ac99 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -1,19 +1,19 @@ -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const Which = @import("../../../which.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const ZigString = JSC.ZigString; const BoringSSL = bun.BoringSSL; const X509 = @import("./x509.zig"); diff --git a/src/bun.js/api/bun/spawn.zig b/src/bun.js/api/bun/spawn.zig index caba172bf7a64..15ee0a9f2a68f 100644 --- a/src/bun.js/api/bun/spawn.zig +++ b/src/bun.js/api/bun/spawn.zig @@ -1,4 +1,4 @@ -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const bun = @import("root").bun; const string = bun.string; const std = @import("std"); diff --git a/src/bun.js/api/bun/spawn/stdio.zig b/src/bun.js/api/bun/spawn/stdio.zig index de3d25f085907..edcc07fc4e026 100644 --- a/src/bun.js/api/bun/spawn/stdio.zig +++ b/src/bun.js/api/bun/spawn/stdio.zig @@ -1,14 +1,14 @@ const Allocator = std.mem.Allocator; const uws = bun.uws; const std = @import("std"); -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Async = bun.Async; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; -const Output = @import("root").bun.Output; +const Output = bun.Output; const os = std.os; const uv = bun.windows.libuv; pub const Stdio = union(enum) { diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 8198edbf0d888..df57bce7d35f1 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1,15 +1,15 @@ -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const Which = @import("../../../which.zig"); @@ -1555,7 +1555,7 @@ pub const Subprocess = struct { secondaryArgsValue: ?JSValue, comptime is_sync: bool, ) JSValue { - var arena = @import("root").bun.ArenaAllocator.init(bun.default_allocator); + var arena = bun.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); var allocator = arena.allocator(); diff --git a/src/bun.js/api/bun/x509.zig b/src/bun.js/api/bun/x509.zig index b1ff707890da2..48d8bb87916ea 100644 --- a/src/bun.js/api/bun/x509.zig +++ b/src/bun.js/api/bun/x509.zig @@ -2,7 +2,7 @@ const BoringSSL = bun.BoringSSL; const bun = @import("root").bun; const ZigString = JSC.ZigString; const std = @import("std"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index aa7d3efc3ac93..a910238d7c000 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -7,8 +7,8 @@ const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; const IdentityContext = @import("../../identity_context.zig").IdentityContext; @@ -17,7 +17,7 @@ const Resolver = @import("../../resolver/resolver.zig"); const ast = @import("../../import_record.zig"); const MacroEntryPoint = bun.bundler.MacroEntryPoint; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../../api/schema.zig").Api; const options = @import("../../options.zig"); const Bundler = bun.Bundler; @@ -28,45 +28,45 @@ const js_ast = bun.JSAst; const NodeFallbackModules = @import("../../node_fallbacks.zig"); const ImportKind = ast.ImportKind; const Analytics = @import("../../analytics/analytics_thread.zig"); -const ZigString = @import("root").bun.JSC.ZigString; +const ZigString = bun.JSC.ZigString; const Runtime = @import("../../runtime.zig"); const ImportRecord = ast.ImportRecord; const DotEnv = @import("../../env_loader.zig"); const ParseResult = bun.bundler.ParseResult; const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../../resolver/package_json.zig").MacroMap; -const WebCore = @import("root").bun.JSC.WebCore; +const WebCore = bun.JSC.WebCore; const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; const FetchEvent = WebCore.FetchEvent; -const js = @import("root").bun.JSC.C; -const JSC = @import("root").bun.JSC; +const js = bun.JSC.C; +const JSC = bun.JSC; const JSError = @import("../base.zig").JSError; const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer; const getAllocator = @import("../base.zig").getAllocator; -const JSValue = @import("root").bun.JSC.JSValue; - -const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject; -const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef; -const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr; -const ConsoleObject = @import("root").bun.JSC.ConsoleObject; -const Node = @import("root").bun.JSC.Node; -const ZigException = @import("root").bun.JSC.ZigException; -const ZigStackTrace = @import("root").bun.JSC.ZigStackTrace; -const ErrorableResolvedSource = @import("root").bun.JSC.ErrorableResolvedSource; -const ResolvedSource = @import("root").bun.JSC.ResolvedSource; -const JSPromise = @import("root").bun.JSC.JSPromise; -const JSInternalPromise = @import("root").bun.JSC.JSInternalPromise; -const JSModuleLoader = @import("root").bun.JSC.JSModuleLoader; -const JSPromiseRejectionOperation = @import("root").bun.JSC.JSPromiseRejectionOperation; -const Exception = @import("root").bun.JSC.Exception; -const ErrorableZigString = @import("root").bun.JSC.ErrorableZigString; -const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; -const VM = @import("root").bun.JSC.VM; -const JSFunction = @import("root").bun.JSC.JSFunction; +const JSValue = bun.JSC.JSValue; + +const JSGlobalObject = bun.JSC.JSGlobalObject; +const ExceptionValueRef = bun.JSC.ExceptionValueRef; +const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; +const ConsoleObject = bun.JSC.ConsoleObject; +const Node = bun.JSC.Node; +const ZigException = bun.JSC.ZigException; +const ZigStackTrace = bun.JSC.ZigStackTrace; +const ErrorableResolvedSource = bun.JSC.ErrorableResolvedSource; +const ResolvedSource = bun.JSC.ResolvedSource; +const JSPromise = bun.JSC.JSPromise; +const JSInternalPromise = bun.JSC.JSInternalPromise; +const JSModuleLoader = bun.JSC.JSModuleLoader; +const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation; +const Exception = bun.JSC.Exception; +const ErrorableZigString = bun.JSC.ErrorableZigString; +const ZigGlobalObject = bun.JSC.ZigGlobalObject; +const VM = bun.JSC.VM; +const JSFunction = bun.JSC.JSFunction; const Config = @import("../config.zig"); const URL = @import("../../url.zig").URL; const VirtualMachine = JSC.VirtualMachine; diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index d2827ffb6e481..d1b69863228e3 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -5,7 +5,7 @@ const QueryStringMap = @import("../../url.zig").QueryStringMap; const CombinedScanner = @import("../../url.zig").CombinedScanner; const bun = @import("root").bun; const string = bun.string; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const js = JSC.C; const WebCore = JSC.WebCore; const Bundler = bun.bundler; @@ -19,14 +19,14 @@ const JSObject = JSC.JSObject; const JSError = Base.JSError; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; -const strings = @import("root").bun.strings; +const strings = bun.strings; const To = Base.To; const Request = WebCore.Request; const URLPath = @import("../../http/url_path.zig"); const URL = @import("../../url.zig").URL; -const Log = @import("root").bun.logger; +const Log = bun.logger; const Resolver = @import("../../resolver/resolver.zig").Resolver; const Router = @import("../../router.zig"); @@ -43,7 +43,7 @@ pub const FileSystemRouter = struct { origin: ?*JSC.RefString = null, base_dir: ?*JSC.RefString = null, router: Router, - arena: *@import("root").bun.ArenaAllocator = undefined, + arena: *bun.ArenaAllocator = undefined, allocator: std.mem.Allocator = undefined, asset_prefix: ?*JSC.RefString = null, @@ -100,8 +100,8 @@ pub const FileSystemRouter = struct { globalThis.throwInvalidArguments("Expected dir to be a string", .{}); return null; } - var arena = globalThis.allocator().create(@import("root").bun.ArenaAllocator) catch unreachable; - arena.* = @import("root").bun.ArenaAllocator.init(globalThis.allocator()); + var arena = globalThis.allocator().create(bun.ArenaAllocator) catch unreachable; + arena.* = bun.ArenaAllocator.init(globalThis.allocator()); const allocator = arena.allocator(); var extensions = std.ArrayList(string).init(allocator); if (argument.get(globalThis, "fileExtensions")) |file_extensions| { @@ -214,8 +214,8 @@ pub const FileSystemRouter = struct { pub fn reload(this: *FileSystemRouter, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue { const this_value = callframe.this(); - var arena = globalThis.allocator().create(@import("root").bun.ArenaAllocator) catch unreachable; - arena.* = @import("root").bun.ArenaAllocator.init(globalThis.allocator()); + var arena = globalThis.allocator().create(bun.ArenaAllocator) catch unreachable; + arena.* = bun.ArenaAllocator.init(globalThis.allocator()); var allocator = arena.allocator(); var vm = globalThis.bunVM(); diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index b0cb87ecfa623..47a26afc6be65 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -1,7 +1,7 @@ const std = @import("std"); const bun = @import("root").bun; const string = bun.string; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const WebCore = @import("../webcore/response.zig"); const ZigString = JSC.ZigString; const Base = @import("../base.zig"); @@ -9,7 +9,7 @@ const getAllocator = Base.getAllocator; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const Response = WebCore.Response; -const LOLHTML = @import("root").bun.LOLHTML; +const LOLHTML = bun.LOLHTML; const SelectorMap = std.ArrayListUnmanaged(*LOLHTML.HTMLSelector); pub const LOLHTMLContext = struct { diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 65ff45264e149..724b91703cff6 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -1,13 +1,13 @@ const Bun = @This(); -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; const IdentityContext = @import("../../identity_context.zig").IdentityContext; @@ -17,7 +17,7 @@ const ast = @import("../../import_record.zig"); const Sys = @import("../../sys.zig"); const MacroEntryPoint = bun.bundler.MacroEntryPoint; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../../api/schema.zig").Api; const options = @import("../../options.zig"); const Bundler = bun.Bundler; @@ -28,55 +28,55 @@ const js_ast = bun.JSAst; const NodeFallbackModules = @import("../../node_fallbacks.zig"); const ImportKind = ast.ImportKind; const Analytics = @import("../../analytics/analytics_thread.zig"); -const ZigString = @import("root").bun.JSC.ZigString; +const ZigString = bun.JSC.ZigString; const Runtime = @import("../../runtime.zig"); const ImportRecord = ast.ImportRecord; const DotEnv = @import("../../env_loader.zig"); const ParseResult = bun.bundler.ParseResult; const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../../resolver/package_json.zig").MacroMap; -const WebCore = @import("root").bun.JSC.WebCore; +const WebCore = bun.JSC.WebCore; const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; -const HTTP = @import("root").bun.http; +const HTTP = bun.http; const FetchEvent = WebCore.FetchEvent; -const js = @import("root").bun.JSC.C; -const JSC = @import("root").bun.JSC; +const js = bun.JSC.C; +const JSC = bun.JSC; const JSError = @import("../base.zig").JSError; const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer; const getAllocator = @import("../base.zig").getAllocator; -const JSValue = @import("root").bun.JSC.JSValue; - -const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject; -const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef; -const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr; -const ConsoleObject = @import("root").bun.JSC.ConsoleObject; -const Node = @import("root").bun.JSC.Node; -const ZigException = @import("root").bun.JSC.ZigException; -const ZigStackTrace = @import("root").bun.JSC.ZigStackTrace; -const ErrorableResolvedSource = @import("root").bun.JSC.ErrorableResolvedSource; -const ResolvedSource = @import("root").bun.JSC.ResolvedSource; -const JSPromise = @import("root").bun.JSC.JSPromise; -const JSInternalPromise = @import("root").bun.JSC.JSInternalPromise; -const JSModuleLoader = @import("root").bun.JSC.JSModuleLoader; -const JSPromiseRejectionOperation = @import("root").bun.JSC.JSPromiseRejectionOperation; -const Exception = @import("root").bun.JSC.Exception; -const ErrorableZigString = @import("root").bun.JSC.ErrorableZigString; -const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; -const VM = @import("root").bun.JSC.VM; -const JSFunction = @import("root").bun.JSC.JSFunction; +const JSValue = bun.JSC.JSValue; + +const JSGlobalObject = bun.JSC.JSGlobalObject; +const ExceptionValueRef = bun.JSC.ExceptionValueRef; +const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; +const ConsoleObject = bun.JSC.ConsoleObject; +const Node = bun.JSC.Node; +const ZigException = bun.JSC.ZigException; +const ZigStackTrace = bun.JSC.ZigStackTrace; +const ErrorableResolvedSource = bun.JSC.ErrorableResolvedSource; +const ResolvedSource = bun.JSC.ResolvedSource; +const JSPromise = bun.JSC.JSPromise; +const JSInternalPromise = bun.JSC.JSInternalPromise; +const JSModuleLoader = bun.JSC.JSModuleLoader; +const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation; +const Exception = bun.JSC.Exception; +const ErrorableZigString = bun.JSC.ErrorableZigString; +const ZigGlobalObject = bun.JSC.ZigGlobalObject; +const VM = bun.JSC.VM; +const JSFunction = bun.JSC.JSFunction; const Config = @import("../config.zig"); const URL = @import("../../url.zig").URL; const VirtualMachine = JSC.VirtualMachine; const IOTask = JSC.IOTask; const is_bindgen = JSC.is_bindgen; -const uws = @import("root").bun.uws; +const uws = bun.uws; const Fallback = Runtime.Fallback; const MimeType = HTTP.MimeType; const Blob = JSC.WebCore.Blob; -const BoringSSL = @import("root").bun.BoringSSL; +const BoringSSL = bun.BoringSSL; const Arena = @import("../../mimalloc_arena.zig").Arena; const SendfileContext = struct { fd: bun.FileDescriptor, @@ -319,7 +319,7 @@ pub const ServerConfig = struct { pub fn inJS(global: *JSC.JSGlobalObject, obj: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SSLConfig { var result = zero; - var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator); + var arena: bun.ArenaAllocator = bun.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); if (!obj.isObject()) { diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index 0aa698a34709c..18b98c253d4a8 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -1,4 +1,4 @@ -pub const js = @import("root").bun.JSC.C; +pub const js = bun.JSC.C; const std = @import("std"); const bun = @import("root").bun; const string = bun.string; @@ -11,7 +11,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const JavaScript = @import("./javascript.zig"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const WebCore = @import("./webcore.zig"); const Test = @import("./test/jest.zig"); const Fetch = WebCore.Fetch; @@ -19,7 +19,7 @@ const Response = WebCore.Response; const Request = WebCore.Request; const Router = @import("./api/filesystem_router.zig"); const IdentityContext = @import("../identity_context.zig").IdentityContext; -const uws = @import("root").bun.uws; +const uws = bun.uws; const Body = WebCore.Body; const TaggedPointerTypes = @import("../tagged_pointer.zig"); const TaggedPointerUnion = TaggedPointerTypes.TaggedPointerUnion; diff --git a/src/bun.js/bindings/bindings-generator.zig b/src/bun.js/bindings/bindings-generator.zig index f2c084ba55435..a215a979268b2 100644 --- a/src/bun.js/bindings/bindings-generator.zig +++ b/src/bun.js/bindings/bindings-generator.zig @@ -15,14 +15,14 @@ const Allocator = std.mem.Allocator; pub const bindgen = true; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Classes = JSC.GlobalClasses; pub fn main() anyerror!void { var allocator = std.heap.c_allocator; const src: std.builtin.SourceLocation = @src(); - const src_path = comptime @import("root").bun.Environment.base_path ++ std.fs.path.dirname(src.file).?; + const src_path = comptime bun.Environment.base_path ++ std.fs.path.dirname(src.file).?; { const paths = [_][]const u8{ src_path, "headers.h" }; const paths2 = [_][]const u8{ src_path, "headers-cpp.h" }; diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 0215b7ab6f664..55348dc834cae 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2,7 +2,7 @@ const std = @import("std"); const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; -const C_API = @import("root").bun.JSC.C; +const C_API = bun.JSC.C; const StringPointer = @import("../../api/schema.zig").Api.StringPointer; const Exports = @import("./exports.zig"); const strings = bun.strings; @@ -12,7 +12,7 @@ const ZigException = Exports.ZigException; const ZigStackTrace = Exports.ZigStackTrace; const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false; const ArrayBuffer = @import("../base.zig").ArrayBuffer; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Shimmer = JSC.Shimmer; const ConsoleObject = JSC.ConsoleObject; const FFI = @import("./FFI.zig"); diff --git a/src/bun.js/bindings/bun-simdutf.zig b/src/bun.js/bindings/bun-simdutf.zig index a8b5b6653a991..0ff7a07d07a79 100644 --- a/src/bun.js/bindings/bun-simdutf.zig +++ b/src/bun.js/bindings/bun-simdutf.zig @@ -1,4 +1,5 @@ -const JSC = @import("root").bun.JSC; +const bun = @import("root").bun; +const JSC = bun.JSC; pub const SIMDUTFResult = extern struct { status: Status, diff --git a/src/bun.js/bindings/codegen.zig b/src/bun.js/bindings/codegen.zig index eaa3f4e6442e8..bf67bb491cf5d 100644 --- a/src/bun.js/bindings/codegen.zig +++ b/src/bun.js/bindings/codegen.zig @@ -1,5 +1,6 @@ -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const std = @import("std"); +const bun = @import("root").bun; pub const CallbackGetterFn = fn (JSC.JSValue) callconv(.C) JSC.JSValue; pub const CallbackSetterFn = fn (JSC.JSValue, JSC.JSValue) callconv(.C) void; diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 99ee9ce599529..a70c1173f4f0a 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -1,4 +1,4 @@ -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Fs = @import("../../fs.zig"); const CAPI = JSC.C; const JS = @import("../javascript.zig"); @@ -8,7 +8,7 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const std = @import("std"); const Shimmer = @import("./shimmer.zig").Shimmer; -const strings = @import("root").bun.strings; +const strings = bun.strings; const default_allocator = bun.default_allocator; const NewGlobalObject = JSC.NewGlobalObject; const JSGlobalObject = JSC.JSGlobalObject; diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig index 0a7b52c1535b8..2c28e25c1b3e5 100644 --- a/src/bun.js/bindings/generated_classes_list.zig +++ b/src/bun.js/bindings/generated_classes_list.zig @@ -1,4 +1,5 @@ -const JSC = @import("root").bun.JSC; +const bun = @import("root").bun; +const JSC = bun.JSC; pub const Classes = struct { pub const Blob = JSC.WebCore.Blob; diff --git a/src/bun.js/bindings/headers-replacements.zig b/src/bun.js/bindings/headers-replacements.zig index 39730a52f1c15..2c9173e774b21 100644 --- a/src/bun.js/bindings/headers-replacements.zig +++ b/src/bun.js/bindings/headers-replacements.zig @@ -1,4 +1,4 @@ -const bindings = @import("root").bun.JSC; +const bindings = bun.JSC; pub const struct_JSC__CallFrame = bindings.CallFrame; pub const struct_JSC__StringPrototype = bindings.StringPrototype; pub const struct_JSC__SetIteratorPrototype = bindings.SetIteratorPrototype; @@ -68,4 +68,4 @@ pub const WebSocketHTTPClient = bindings.WebSocketHTTPClient; pub const WebSocketHTTPSClient = bindings.WebSocketHTTPSClient; pub const WebSocketClient = bindings.WebSocketClient; pub const WebSocketClientTLS = bindings.WebSocketClientTLS; -pub const BunString = @import("root").bun.String; +pub const BunString = bun.String; diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig index 810d0d076c4a2..91015dab3dc2b 100644 --- a/src/bun.js/bindings/headers.zig +++ b/src/bun.js/bindings/headers.zig @@ -1,6 +1,5 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -const bindings = @import("root").bun.JSC; +const bun = @import("root").bun; +const bindings = bun.JSC; pub const struct_JSC__CallFrame = bindings.CallFrame; pub const struct_JSC__StringPrototype = bindings.StringPrototype; pub const struct_JSC__SetIteratorPrototype = bindings.SetIteratorPrototype; @@ -71,7 +70,7 @@ pub const WebSocketHTTPClient = bindings.WebSocketHTTPClient; pub const WebSocketHTTPSClient = bindings.WebSocketHTTPSClient; pub const WebSocketClient = bindings.WebSocketClient; pub const WebSocketClientTLS = bindings.WebSocketClientTLS; -pub const BunString = @import("root").bun.String; +pub const BunString = bun.String; pub const JSC__JSString = bJSC__JSString; pub const JSC__JSPromise = bJSC__JSPromise; pub const JSC__VM = bJSC__VM; diff --git a/src/bun.js/config.zig b/src/bun.js/config.zig index 079c0b8f64256..1018a6226d018 100644 --- a/src/bun.js/config.zig +++ b/src/bun.js/config.zig @@ -13,7 +13,7 @@ const std = @import("std"); const Fs = @import("../fs.zig"); const resolver = @import("../resolver/resolver.zig"); const ast = @import("../import_record.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../api/schema.zig").Api; const options = @import("../options.zig"); const Bundler = bun.bundler.ServeBundler; diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 0f230fe5cd291..24fd49265eab1 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSGlobalObject = JSC.JSGlobalObject; const VirtualMachine = JSC.VirtualMachine; const Allocator = std.mem.Allocator; @@ -25,7 +25,7 @@ const Waker = bun.Async.Waker; pub const WorkPool = @import("../work_pool.zig").WorkPool; pub const WorkPoolTask = @import("../work_pool.zig").Task; -const uws = @import("root").bun.uws; +const uws = bun.uws; const Async = bun.Async; pub fn ConcurrentPromiseTask(comptime Context: type) type { diff --git a/src/bun.js/ipc.zig b/src/bun.js/ipc.zig index bc8cd134cb436..7a4590ef77fa9 100644 --- a/src/bun.js/ipc.zig +++ b/src/bun.js/ipc.zig @@ -4,11 +4,11 @@ const Environment = bun.Environment; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 9a9c28a38e034..25ce1c407b924 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -22,7 +22,7 @@ const Resolver = @import("../resolver/resolver.zig"); const ast = @import("../import_record.zig"); const MacroEntryPoint = bun.bundler.MacroEntryPoint; const ParseResult = bun.bundler.ParseResult; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../api/schema.zig").Api; const options = @import("../options.zig"); const Bundler = bun.Bundler; @@ -34,47 +34,47 @@ const js_ast = bun.JSAst; const NodeFallbackModules = @import("../node_fallbacks.zig"); const ImportKind = ast.ImportKind; const Analytics = @import("../analytics/analytics_thread.zig"); -const ZigString = @import("root").bun.JSC.ZigString; +const ZigString = bun.JSC.ZigString; const Runtime = @import("../runtime.zig"); const Router = @import("./api/filesystem_router.zig"); const ImportRecord = ast.ImportRecord; const DotEnv = @import("../env_loader.zig"); const PackageJSON = @import("../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../resolver/package_json.zig").MacroMap; -const WebCore = @import("root").bun.JSC.WebCore; +const WebCore = bun.JSC.WebCore; const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const String = bun.String; const Fetch = WebCore.Fetch; const FetchEvent = WebCore.FetchEvent; -const js = @import("root").bun.JSC.C; -const JSC = @import("root").bun.JSC; +const js = bun.JSC.C; +const JSC = bun.JSC; const JSError = @import("./base.zig").JSError; const d = @import("./base.zig").d; const MarkedArrayBuffer = @import("./base.zig").MarkedArrayBuffer; const getAllocator = @import("./base.zig").getAllocator; -const JSValue = @import("root").bun.JSC.JSValue; +const JSValue = bun.JSC.JSValue; const NewClass = @import("./base.zig").NewClass; -const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject; -const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef; -const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr; -const ConsoleObject = @import("root").bun.JSC.ConsoleObject; -const Node = @import("root").bun.JSC.Node; -const ZigException = @import("root").bun.JSC.ZigException; -const ZigStackTrace = @import("root").bun.JSC.ZigStackTrace; -const ErrorableResolvedSource = @import("root").bun.JSC.ErrorableResolvedSource; -const ResolvedSource = @import("root").bun.JSC.ResolvedSource; -const JSPromise = @import("root").bun.JSC.JSPromise; -const JSInternalPromise = @import("root").bun.JSC.JSInternalPromise; -const JSModuleLoader = @import("root").bun.JSC.JSModuleLoader; -const JSPromiseRejectionOperation = @import("root").bun.JSC.JSPromiseRejectionOperation; -const Exception = @import("root").bun.JSC.Exception; -const ErrorableZigString = @import("root").bun.JSC.ErrorableZigString; -const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; -const VM = @import("root").bun.JSC.VM; -const JSFunction = @import("root").bun.JSC.JSFunction; +const JSGlobalObject = bun.JSC.JSGlobalObject; +const ExceptionValueRef = bun.JSC.ExceptionValueRef; +const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; +const ConsoleObject = bun.JSC.ConsoleObject; +const Node = bun.JSC.Node; +const ZigException = bun.JSC.ZigException; +const ZigStackTrace = bun.JSC.ZigStackTrace; +const ErrorableResolvedSource = bun.JSC.ErrorableResolvedSource; +const ResolvedSource = bun.JSC.ResolvedSource; +const JSPromise = bun.JSC.JSPromise; +const JSInternalPromise = bun.JSC.JSInternalPromise; +const JSModuleLoader = bun.JSC.JSModuleLoader; +const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation; +const Exception = bun.JSC.Exception; +const ErrorableZigString = bun.JSC.ErrorableZigString; +const ZigGlobalObject = bun.JSC.ZigGlobalObject; +const VM = bun.JSC.VM; +const JSFunction = bun.JSC.JSFunction; const Config = @import("./config.zig"); const URL = @import("../url.zig").URL; const Bun = JSC.API.Bun; @@ -263,7 +263,7 @@ pub const SavedSourceMap = struct { return SourceMap.Mapping.find(parsed_mappings.mappings, line, column); } }; -const uws = @import("root").bun.uws; +const uws = bun.uws; pub export fn Bun__getDefaultGlobal() *JSGlobalObject { return JSC.VirtualMachine.get().global; diff --git a/src/bun.js/javascript_core_c_api.zig b/src/bun.js/javascript_core_c_api.zig index 87e06a3149976..00a7be2ded6cb 100644 --- a/src/bun.js/javascript_core_c_api.zig +++ b/src/bun.js/javascript_core_c_api.zig @@ -12,7 +12,7 @@ const generic = opaque { return @as(cpp.JSValue, @enumFromInt(@as(cpp.JSValue.Type, @bitCast(@intFromPtr(this))))); } - pub inline fn bunVM(this: *@This()) *@import("root").bun.JSC.VirtualMachine { + pub inline fn bunVM(this: *@This()) *bun.JSC.VirtualMachine { return this.ptr().bunVM(); } }; @@ -180,13 +180,13 @@ pub extern fn JSValueToNumber(ctx: JSContextRef, value: JSValueRef, exception: E pub extern fn JSValueToStringCopy(ctx: JSContextRef, value: JSValueRef, exception: ExceptionRef) JSStringRef; pub extern fn JSValueToObject(ctx: JSContextRef, value: JSValueRef, exception: ExceptionRef) JSObjectRef; -const log_protection = @import("root").bun.Environment.allow_assert and false; +const log_protection = bun.Environment.allow_assert and false; pub inline fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void { const Wrapped = struct { pub extern fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef) void; }; if (comptime log_protection) { - const Output = @import("root").bun.Output; + const Output = bun.Output; Output.debug("[unprotect] {d}\n", .{@intFromPtr(value)}); } // wrapper exists to make it easier to set a breakpoint @@ -198,7 +198,7 @@ pub inline fn JSValueProtect(ctx: JSContextRef, value: JSValueRef) void { pub extern fn JSValueProtect(ctx: JSContextRef, value: JSValueRef) void; }; if (comptime log_protection) { - const Output = @import("root").bun.Output; + const Output = bun.Output; Output.debug("[protect] {d}\n", .{@intFromPtr(value)}); } // wrapper exists to make it easier to set a breakpoint diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 98970fa02d5a8..4552d46f27a5b 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -21,7 +21,7 @@ const Resolver = @import("../resolver/resolver.zig"); const ast = @import("../import_record.zig"); const MacroEntryPoint = bun.bundler.MacroEntryPoint; const ParseResult = bun.bundler.ParseResult; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Api = @import("../api/schema.zig").Api; const options = @import("../options.zig"); const Bundler = bun.Bundler; @@ -33,46 +33,46 @@ const js_ast = bun.JSAst; const NodeFallbackModules = @import("../node_fallbacks.zig"); const ImportKind = ast.ImportKind; const Analytics = @import("../analytics/analytics_thread.zig"); -const ZigString = @import("root").bun.JSC.ZigString; +const ZigString = bun.JSC.ZigString; const Runtime = @import("../runtime.zig"); const Router = @import("./api/filesystem_router.zig"); const ImportRecord = ast.ImportRecord; const DotEnv = @import("../env_loader.zig"); const PackageJSON = @import("../resolver/package_json.zig").PackageJSON; const MacroRemap = @import("../resolver/package_json.zig").MacroMap; -const WebCore = @import("root").bun.JSC.WebCore; +const WebCore = bun.JSC.WebCore; const Request = WebCore.Request; const Response = WebCore.Response; const Headers = WebCore.Headers; const Fetch = WebCore.Fetch; const FetchEvent = WebCore.FetchEvent; -const js = @import("root").bun.JSC.C; -const JSC = @import("root").bun.JSC; +const js = bun.JSC.C; +const JSC = bun.JSC; const JSError = @import("./base.zig").JSError; const d = @import("./base.zig").d; const MarkedArrayBuffer = @import("./base.zig").MarkedArrayBuffer; const getAllocator = @import("./base.zig").getAllocator; -const JSValue = @import("root").bun.JSC.JSValue; +const JSValue = bun.JSC.JSValue; const NewClass = @import("./base.zig").NewClass; -const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject; -const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef; -const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr; -const ConsoleObject = @import("root").bun.JSC.ConsoleObject; -const Node = @import("root").bun.JSC.Node; -const ZigException = @import("root").bun.JSC.ZigException; -const ZigStackTrace = @import("root").bun.JSC.ZigStackTrace; -const ErrorableResolvedSource = @import("root").bun.JSC.ErrorableResolvedSource; -const ResolvedSource = @import("root").bun.JSC.ResolvedSource; -const JSPromise = @import("root").bun.JSC.JSPromise; -const JSInternalPromise = @import("root").bun.JSC.JSInternalPromise; -const JSModuleLoader = @import("root").bun.JSC.JSModuleLoader; -const JSPromiseRejectionOperation = @import("root").bun.JSC.JSPromiseRejectionOperation; -const Exception = @import("root").bun.JSC.Exception; -const ErrorableZigString = @import("root").bun.JSC.ErrorableZigString; -const ZigGlobalObject = @import("root").bun.JSC.ZigGlobalObject; -const VM = @import("root").bun.JSC.VM; -const JSFunction = @import("root").bun.JSC.JSFunction; +const JSGlobalObject = bun.JSC.JSGlobalObject; +const ExceptionValueRef = bun.JSC.ExceptionValueRef; +const JSPrivateDataPtr = bun.JSC.JSPrivateDataPtr; +const ConsoleObject = bun.JSC.ConsoleObject; +const Node = bun.JSC.Node; +const ZigException = bun.JSC.ZigException; +const ZigStackTrace = bun.JSC.ZigStackTrace; +const ErrorableResolvedSource = bun.JSC.ErrorableResolvedSource; +const ResolvedSource = bun.JSC.ResolvedSource; +const JSPromise = bun.JSC.JSPromise; +const JSInternalPromise = bun.JSC.JSInternalPromise; +const JSModuleLoader = bun.JSC.JSModuleLoader; +const JSPromiseRejectionOperation = bun.JSC.JSPromiseRejectionOperation; +const Exception = bun.JSC.Exception; +const ErrorableZigString = bun.JSC.ErrorableZigString; +const ZigGlobalObject = bun.JSC.ZigGlobalObject; +const VM = bun.JSC.VM; +const JSFunction = bun.JSC.JSFunction; const Config = @import("./config.zig"); const URL = @import("../url.zig").URL; const Bun = JSC.API.Bun; diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig index 74a4bf92ea183..9a5bfe4c84b1d 100644 --- a/src/bun.js/node/dir_iterator.zig +++ b/src/bun.js/node/dir_iterator.zig @@ -10,13 +10,13 @@ const std = @import("std"); const os = std.os; const Dir = std.fs.Dir; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const PathString = JSC.PathString; const bun = @import("root").bun; const IteratorError = error{ AccessDenied, SystemResources } || os.UnexpectedError; const mem = std.mem; -const strings = @import("root").bun.strings; +const strings = bun.strings; const Maybe = JSC.Maybe; const File = std.fs.File; diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index e5f7aa8ba6a7e..6d72269796848 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -6,7 +6,7 @@ const bun = @import("root").bun; const strings = bun.strings; const windows = bun.windows; const string = bun.string; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const PathString = JSC.PathString; const Environment = bun.Environment; const C = bun.C; diff --git a/src/bun.js/node/node_fs_binding.zig b/src/bun.js/node/node_fs_binding.zig index 5b6b399219a88..a5613f0d0ac14 100644 --- a/src/bun.js/node/node_fs_binding.zig +++ b/src/bun.js/node/node_fs_binding.zig @@ -6,7 +6,7 @@ const ArgumentsSlice = JSC.Node.ArgumentsSlice; const system = std.os.system; const Maybe = JSC.Maybe; const Encoding = JSC.Node.Encoding; -const FeatureFlags = @import("root").bun.FeatureFlags; +const FeatureFlags = bun.FeatureFlags; const Args = JSC.Node.NodeFS.Arguments; const d = JSC.d; diff --git a/src/bun.js/node/node_fs_stat_watcher.zig b/src/bun.js/node/node_fs_stat_watcher.zig index 8514dcc071ae3..d546143e88247 100644 --- a/src/bun.js/node/node_fs_stat_watcher.zig +++ b/src/bun.js/node/node_fs_stat_watcher.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const bun = @import("root").bun; const Fs = @import("../../fs.zig"); const Path = @import("../../resolver/resolve_path.zig"); diff --git a/src/bun.js/node/node_fs_watcher.zig b/src/bun.js/node/node_fs_watcher.zig index 0ca350a3db129..b3a13a8915ab5 100644 --- a/src/bun.js/node/node_fs_watcher.zig +++ b/src/bun.js/node/node_fs_watcher.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const bun = @import("root").bun; const Fs = @import("../../fs.zig"); const Path = @import("../../resolver/resolve_path.zig"); diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index 95c5992c4d330..d48f99c9d76d2 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -4,7 +4,7 @@ const bun = @import("root").bun; const C = bun.C; const string = bun.string; const strings = bun.strings; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Environment = bun.Environment; const Global = bun.Global; const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false; diff --git a/src/bun.js/node/os/constants.zig b/src/bun.js/node/os/constants.zig index 9cf754e032a62..858f3f2f01f55 100644 --- a/src/bun.js/node/os/constants.zig +++ b/src/bun.js/node/os/constants.zig @@ -2,7 +2,7 @@ const std = @import("std"); const bun = @import("root").bun; const string = bun.string; const Environment = bun.Environment; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const ConstantType = enum { ERRNO, ERRNO_WIN, SIG, DLOPEN, OTHER }; diff --git a/src/bun.js/node/util/parse_args_utils.zig b/src/bun.js/node/util/parse_args_utils.zig index 1555ba47524f0..e94d91bb3b1f4 100644 --- a/src/bun.js/node/util/parse_args_utils.zig +++ b/src/bun.js/node/util/parse_args_utils.zig @@ -1,7 +1,8 @@ const std = @import("std"); +const bun = @import("root").bun; const testing = std.testing; -const String = if (@import("builtin").is_test) TestString else @import("root").bun.String; -const JSValue = if (@import("builtin").is_test) usize else @import("root").bun.JSC.JSValue; +const String = if (@import("builtin").is_test) TestString else bun.String; +const JSValue = if (@import("builtin").is_test) usize else bun.JSC.JSValue; pub const OptionValueType = enum { boolean, string }; diff --git a/src/bun.js/node/util/validators.zig b/src/bun.js/node/util/validators.zig index 93de1f8f4df60..6ea243b67c0cd 100644 --- a/src/bun.js/node/util/validators.zig +++ b/src/bun.js/node/util/validators.zig @@ -1,7 +1,7 @@ const std = @import("std"); const bun = @import("root").bun; const string = bun.string; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const ZigString = JSC.ZigString; diff --git a/src/bun.js/rare_data.zig b/src/bun.js/rare_data.zig index 8b2920a4b6419..1f6b6f8ede82a 100644 --- a/src/bun.js/rare_data.zig +++ b/src/bun.js/rare_data.zig @@ -1,12 +1,12 @@ const EditorContext = @import("../open.zig").EditorContext; const Blob = JSC.WebCore.Blob; -const default_allocator = @import("root").bun.default_allocator; -const Output = @import("root").bun.Output; +const default_allocator = bun.default_allocator; +const Output = bun.Output; const RareData = @This(); const Syscall = bun.sys; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const std = @import("std"); -const BoringSSL = @import("root").bun.BoringSSL; +const BoringSSL = bun.BoringSSL; const bun = @import("root").bun; const FDImpl = bun.FDImpl; const Environment = bun.Environment; @@ -15,7 +15,7 @@ const UUID = @import("./uuid.zig"); const Async = bun.Async; const StatWatcherScheduler = @import("./node/node_fs_stat_watcher.zig").StatWatcherScheduler; const IPC = @import("./ipc.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; boring_ssl_engine: ?*BoringSSL.ENGINE = null, editor_context: EditorContext = EditorContext{}, diff --git a/src/bun.js/script_execution_context.zig b/src/bun.js/script_execution_context.zig index 50f531689d0a7..3753952363e2d 100644 --- a/src/bun.js/script_execution_context.zig +++ b/src/bun.js/script_execution_context.zig @@ -1,4 +1,4 @@ -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; pub const ScriptExecutionContext = extern struct { main_file_path: JSC.ZigString, diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 95bad40e406ce..8aad1acdbdcde 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -5,7 +5,7 @@ const js_ast = bun.JSAst; const Api = @import("../../api/schema.zig").Api; const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; -const HTTPClient = @import("root").bun.http; +const HTTPClient = bun.http; const Environment = bun.Environment; const Snapshots = @import("./snapshot.zig").Snapshots; @@ -15,20 +15,20 @@ const Expect = expect.Expect; const DiffFormatter = @import("./diff_format.zig").DiffFormatter; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const js = JSC.C; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Method = @import("../../http/method.zig").Method; const ObjectPool = @import("../../pool.zig").ObjectPool; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; const getAllocator = @import("../base.zig").getAllocator; diff --git a/src/bun.js/webcore.zig b/src/bun.js/webcore.zig index 7e170988fc0af..0bfc83753d3aa 100644 --- a/src/bun.js/webcore.zig +++ b/src/bun.js/webcore.zig @@ -5,7 +5,7 @@ pub usingnamespace @import("./webcore/blob.zig"); pub usingnamespace @import("./webcore/request.zig"); pub usingnamespace @import("./webcore/body.zig"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const std = @import("std"); const bun = @import("root").bun; const string = bun.string; @@ -342,7 +342,7 @@ pub const Prompt = struct { pub const Crypto = struct { garbage: i32 = 0, - const BoringSSL = @import("root").bun.BoringSSL; + const BoringSSL = bun.BoringSSL; pub const doScryptSync = JSC.wrapInstanceMethod(Crypto, "scryptSync", false); diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 26123df5bdd77..3537cd9f994af 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -3,20 +3,20 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = http.MimeType; const ZigURL = @import("../../url.zig").URL; -const http = @import("root").bun.http; -const JSC = @import("root").bun.JSC; +const http = bun.http; +const JSC = bun.JSC; const js = JSC.C; const io = bun.io; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; const ObjectPool = @import("../../pool.zig").ObjectPool; const SystemError = JSC.SystemError; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; @@ -34,9 +34,9 @@ const NullableAllocator = @import("../../nullable_allocator.zig").NullableAlloca const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; const StringJoiner = @import("../../string_joiner.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const invalid_fd = bun.invalid_fd; const Response = JSC.WebCore.Response; @@ -518,7 +518,7 @@ pub const Blob = struct { allocator: std.mem.Allocator, form_data: *JSC.DOMFormData, ) Blob { - var arena = @import("root").bun.ArenaAllocator.init(allocator); + var arena = bun.ArenaAllocator.init(allocator); defer arena.deinit(); var stack_allocator = std.heap.stackFallback(1024, arena.allocator()); const stack_mem_all = stack_allocator.get(); diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index a6b28afc0cbcf..3ece0a37ed76b 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -3,20 +3,20 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; -const HTTPClient = @import("root").bun.http; -const JSC = @import("root").bun.JSC; +const HTTPClient = bun.http; +const JSC = bun.JSC; const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; const ObjectPool = @import("../../pool.zig").ObjectPool; const SystemError = JSC.SystemError; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; @@ -36,9 +36,9 @@ const NullableAllocator = @import("../../nullable_allocator.zig").NullableAlloca const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; const StringJoiner = @import("../../string_joiner.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const Blob = JSC.WebCore.Blob; // const InlineBlob = JSC.WebCore.InlineBlob; diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index c47454687c51b..690be5a8553ef 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -2,21 +2,21 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; -const HTTPClient = @import("root").bun.http; +const HTTPClient = bun.http; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const js = JSC.C; const Method = @import("../../http/method.zig").Method; const ObjectPool = @import("../../pool.zig").ObjectPool; const bun = @import("root").bun; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; @@ -35,7 +35,7 @@ const JSGlobalObject = JSC.JSGlobalObject; const VirtualMachine = JSC.VirtualMachine; const Task = @import("../javascript.zig").Task; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; pub const TextEncoder = struct { filler: u32 = 0, diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig index 2099bd354cdd3..2817348045224 100644 --- a/src/bun.js/webcore/request.zig +++ b/src/bun.js/webcore/request.zig @@ -3,8 +3,8 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; -const HTTPClient = @import("root").bun.http; -const JSC = @import("root").bun.JSC; +const HTTPClient = bun.http; +const JSC = bun.JSC; const js = JSC.C; const Method = @import("../../http/method.zig").Method; @@ -12,12 +12,12 @@ const FetchHeaders = JSC.FetchHeaders; const AbortSignal = JSC.WebCore.AbortSignal; const ObjectPool = @import("../../pool.zig").ObjectPool; const SystemError = JSC.SystemError; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; @@ -37,9 +37,9 @@ const NullableAllocator = @import("../../nullable_allocator.zig").NullableAlloca const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; const StringJoiner = @import("../../string_joiner.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const InlineBlob = JSC.WebCore.InlineBlob; const AnyBlob = JSC.WebCore.AnyBlob; diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index d301b82c5362e..3531f11d3fd96 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -3,21 +3,21 @@ const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; const MimeType = bun.http.MimeType; const ZigURL = @import("../../url.zig").URL; -const http = @import("root").bun.http; +const http = bun.http; const FetchRedirect = http.FetchRedirect; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; const ObjectPool = @import("../../pool.zig").ObjectPool; const SystemError = JSC.SystemError; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; @@ -38,9 +38,9 @@ const DataURL = @import("../../resolver/data_url.zig").DataURL; const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; const StringJoiner = @import("../../string_joiner.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const Mutex = @import("../../lock.zig").Lock; const InlineBlob = JSC.WebCore.InlineBlob; diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 7703efa216bac..01df75471c52f 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -4,19 +4,19 @@ const bun = @import("root").bun; const MimeType = HTTPClient.MimeType; const ZigURL = @import("../../url.zig").URL; const HTTPClient = bun.http; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const js = JSC.C; const Method = @import("../../http/method.zig").Method; const FetchHeaders = JSC.FetchHeaders; const ObjectPool = @import("../../pool.zig").ObjectPool; const SystemError = JSC.SystemError; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; -const strings = @import("root").bun.strings; -const string = @import("root").bun.string; -const default_allocator = @import("root").bun.default_allocator; -const FeatureFlags = @import("root").bun.FeatureFlags; +const Output = bun.Output; +const MutableString = bun.MutableString; +const strings = bun.strings; +const string = bun.string; +const default_allocator = bun.default_allocator; +const FeatureFlags = bun.FeatureFlags; const ArrayBuffer = @import("../base.zig").ArrayBuffer; const Properties = @import("../base.zig").Properties; const Async = bun.Async; @@ -36,9 +36,9 @@ const E = bun.C.E; const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; const StringJoiner = @import("../../string_joiner.zig"); -const uws = @import("root").bun.uws; +const uws = bun.uws; const Blob = JSC.WebCore.Blob; const Response = JSC.WebCore.Response; const Request = JSC.WebCore.Request; diff --git a/src/bun_js.zig b/src/bun_js.zig index ec76be444d220..73ce474679bb5 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -11,7 +11,7 @@ const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("options.zig"); const js_parser = bun.js_parser; const json_parser = bun.JSON; @@ -27,8 +27,8 @@ const Command = @import("cli.zig").Command; const bundler = bun.bundler; const DotEnv = @import("env_loader.zig"); const which = @import("which.zig").which; -const JSC = @import("root").bun.JSC; -const AsyncHTTP = @import("root").bun.http.AsyncHTTP; +const JSC = bun.JSC; +const AsyncHTTP = bun.http.AsyncHTTP; const Arena = @import("./mimalloc_arena.zig").Arena; const OpaqueWrap = JSC.OpaqueWrap; diff --git a/src/bundler.zig b/src/bundler.zig index 77f8a0e91f674..138b5777cf38c 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -12,7 +12,7 @@ const FeatureFlags = bun.FeatureFlags; const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("options.zig"); const js_parser = bun.js_parser; const json_parser = bun.JSON; @@ -50,7 +50,7 @@ const Report = @import("./report.zig"); const Linker = linker.Linker; const Resolver = _resolver.Resolver; const TOML = @import("./toml/toml_parser.zig").TOML; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const PackageManager = @import("./install/install.zig").PackageManager; pub fn MacroJSValueType_() type { diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index cbfc0e9aea8d3..9967311bfa11a 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -217,7 +217,7 @@ pub const ThreadPool = struct { deinit_task: ThreadPoolLib.Task = .{ .callback = deinitCallback }, - temporary_arena: @import("root").bun.ArenaAllocator = undefined, + temporary_arena: bun.ArenaAllocator = undefined, stmt_list: LinkerContext.StmtList = undefined, pub fn deinitCallback(task: *ThreadPoolLib.Task) void { @@ -301,7 +301,7 @@ pub const ThreadPool = struct { this.data.bundler.linker.resolver = &this.data.bundler.resolver; this.data.bundler.macro_context = js_ast.Macro.MacroContext.init(&this.data.bundler); this.data.macro_context = this.data.bundler.macro_context.?; - this.temporary_arena = @import("root").bun.ArenaAllocator.init(this.allocator); + this.temporary_arena = bun.ArenaAllocator.init(this.allocator); this.stmt_list = LinkerContext.StmtList.init(this.allocator); const CacheSet = @import("../cache.zig"); @@ -4070,7 +4070,7 @@ const LinkerContext = struct { var stack_fallback = std.heap.stackFallback(4096, this.allocator); const stack_all = stack_fallback.get(); - var arena = @import("root").bun.ArenaAllocator.init(stack_all); + var arena = bun.ArenaAllocator.init(stack_all); defer arena.deinit(); var temp_allocator = arena.allocator(); @@ -6684,7 +6684,7 @@ const LinkerContext = struct { defer chunk.renamer.deinit(bun.default_allocator); - var arena = @import("root").bun.ArenaAllocator.init(worker.allocator); + var arena = bun.ArenaAllocator.init(worker.allocator); defer arena.deinit(); // Also generate the cross-chunk binding code diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig index 16dcdd3257c8c..654a7926fb6e6 100644 --- a/src/bundler/entry_points.zig +++ b/src/bundler/entry_points.zig @@ -1,4 +1,4 @@ -const logger = @import("root").bun.logger; +const logger = bun.logger; const std = @import("std"); const bun = @import("root").bun; const string = bun.string; diff --git a/src/bunfig.zig b/src/bunfig.zig index c55361b33e189..755b33eef09c2 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -11,7 +11,7 @@ const default_allocator = bun.default_allocator; const URL = @import("./url.zig").URL; const C = bun.C; const options = @import("./options.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_ast = bun.JSAst; const js_lexer = bun.js_lexer; const Defines = @import("./defines.zig"); diff --git a/src/cache.zig b/src/cache.zig index 08b94e3f77f6d..43273e9bb5f3f 100644 --- a/src/cache.zig +++ b/src/cache.zig @@ -12,7 +12,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const js_ast = bun.JSAst; -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_parser = bun.js_parser; const json_parser = bun.JSON; const options = @import("./options.zig"); diff --git a/src/cli.zig b/src/cli.zig index c62ea916d6a84..2d30e64852a77 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -12,7 +12,7 @@ const C = bun.C; const root = @import("root"); const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("options.zig"); const js_parser = bun.js_parser; const json_parser = bun.JSON; @@ -27,7 +27,7 @@ const sync = @import("./sync.zig"); const Api = @import("api/schema.zig").Api; const resolve_path = @import("./resolver/resolve_path.zig"); const configureTransformOptionsForBun = @import("./bun.js/config.zig").configureTransformOptionsForBun; -const clap = @import("root").bun.clap; +const clap = bun.clap; const BunJS = @import("./bun_js.zig"); const Install = @import("./install/install.zig"); const bundler = bun.bundler; diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index f8af12d66bb3c..751f8df13f165 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -12,7 +12,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("../options.zig"); const js_parser = bun.js_parser; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index 40d0cada3af16..07ad50341987b 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -11,7 +11,7 @@ const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("../options.zig"); const js_parser = bun.js_parser; @@ -28,7 +28,7 @@ const bundler = bun.bundler; const fs = @import("../fs.zig"); const URL = @import("../url.zig").URL; -const HTTP = @import("root").bun.http; +const HTTP = bun.http; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; const Archive = @import("../libarchive/libarchive.zig").Archive; @@ -37,9 +37,9 @@ const JSPrinter = bun.js_printer; const DotEnv = @import("../env_loader.zig"); const NPMClient = @import("../which_npm_client.zig").NPMClient; const which = @import("../which.zig").which; -const clap = @import("root").bun.clap; +const clap = bun.clap; const Lock = @import("../lock.zig").Lock; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const CopyFile = @import("../copy_file.zig"); var bun_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; const Futex = @import("../futex.zig"); @@ -1693,7 +1693,7 @@ const Commands = .{ &[_]string{""}, &[_]string{""}, }; -const picohttp = @import("root").bun.picohttp; +const picohttp = bun.picohttp; pub const DownloadedExample = struct { tarball_bytes: MutableString, diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index 43be7a6404629..c878e28e78458 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -19,7 +19,7 @@ const linker = @import("../linker.zig"); const options = @import("../options.zig"); const initializeStore = @import("./create_command.zig").initializeStore; const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const JSPrinter = bun.js_printer; fn exists(path: anytype) bool { diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index 3611ad32a21dd..6d5a923d925ef 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -11,7 +11,7 @@ const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("../options.zig"); const js_parser = bun.js_parser; @@ -35,9 +35,9 @@ const JSPrinter = bun.js_printer; const DotEnv = @import("../env_loader.zig"); const NPMClient = @import("../which_npm_client.zig").NPMClient; const which = @import("../which.zig").which; -const clap = @import("root").bun.clap; +const clap = bun.clap; const Lock = @import("../lock.zig").Lock; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const CopyFile = @import("../copy_file.zig"); const ShellCompletions = @import("./shell_completions.zig"); diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 9021d66482793..034bf47d458d0 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -11,7 +11,7 @@ const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const FileSystem = @import("../fs.zig").FileSystem; const PathName = @import("../fs.zig").PathName; @@ -35,15 +35,15 @@ var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; const PathString = bun.PathString; const is_bindgen = std.meta.globalOption("bindgen", bool) orelse false; -const HTTPThread = @import("root").bun.http.HTTPThread; +const HTTPThread = bun.http.HTTPThread; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const jest = JSC.Jest; const TestRunner = JSC.Jest.TestRunner; const Snapshots = JSC.Snapshot.Snapshots; const Test = TestRunner.Test; -const uws = @import("root").bun.uws; +const uws = bun.uws; fn fmtStatusTextLine(comptime status: @Type(.EnumLiteral), comptime emoji_or_color: bool) []const u8 { comptime { diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index f1f0b838c4bd0..0dfaa30848527 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -11,7 +11,7 @@ const C = bun.C; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("../options.zig"); const js_parser = bun.js_parser; @@ -28,16 +28,16 @@ const bundler = bun.bundler; const fs = @import("../fs.zig"); const URL = @import("../url.zig").URL; -const HTTP = @import("root").bun.http; +const HTTP = bun.http; const ParseJSON = @import("../json_parser.zig").ParseJSONUTF8; const Archive = @import("../libarchive/libarchive.zig").Archive; const Zlib = @import("../zlib.zig"); const JSPrinter = bun.js_printer; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; -const clap = @import("root").bun.clap; +const clap = bun.clap; const Lock = @import("../lock.zig").Lock; -const Headers = @import("root").bun.http.Headers; +const Headers = bun.http.Headers; const CopyFile = @import("../copy_file.zig"); pub var initialized_store = false; diff --git a/src/comptime_string_map.zig b/src/comptime_string_map.zig index f747a72152ab3..037569143e99c 100644 --- a/src/comptime_string_map.zig +++ b/src/comptime_string_map.zig @@ -1,5 +1,6 @@ -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const std = @import("std"); +const bun = @import("root").bun; const mem = std.mem; const strings = @import("./string_immutable.zig"); @@ -165,26 +166,26 @@ pub fn ComptimeStringMapWithKeyType(comptime KeyType: type, comptime V: type, co /// Caller must ensure that the input is a string. pub fn fromJS(globalThis: *JSC.JSGlobalObject, input: JSC.JSValue) ?V { - if (comptime @import("root").bun.Environment.allow_assert) { + if (comptime bun.Environment.allow_assert) { if (!input.isString()) { @panic("ComptimeStringMap.fromJS: input is not a string"); } } - const str = @import("root").bun.String.tryFromJS(input, globalThis) orelse return null; + const str = bun.String.tryFromJS(input, globalThis) orelse return null; defer str.deref(); - return getWithEql(str, @import("root").bun.String.eqlComptime); + return getWithEql(str, bun.String.eqlComptime); } /// Caller must ensure that the input is a string. pub fn fromJSCaseInsensitive(globalThis: *JSC.JSGlobalObject, input: JSC.JSValue) ?V { - if (comptime @import("root").bun.Environment.allow_assert) { + if (comptime bun.Environment.allow_assert) { if (!input.isString()) { @panic("ComptimeStringMap.fromJS: input is not a string"); } } - const str = @import("root").bun.String.tryFromJS(input, globalThis) orelse return null; + const str = bun.String.tryFromJS(input, globalThis) orelse return null; defer str.deref(); return str.inMapCaseInsensitive(@This()); } diff --git a/src/copy_file.zig b/src/copy_file.zig index 80c6d519d92a0..6acf4946ff49b 100644 --- a/src/copy_file.zig +++ b/src/copy_file.zig @@ -148,7 +148,7 @@ pub fn copyFile(in: InputType, out: InputType) CopyFileError!void { var state: CopyFileState = .{}; return copyFileWithState(in, out, &state); } -const Platform = @import("root").bun.analytics.GenerateHeader.GeneratePlatform; +const Platform = bun.analytics.GenerateHeader.GeneratePlatform; var can_use_copy_file_range = std.atomic.Value(i32).init(0); pub inline fn disableCopyFileRangeSyscall() void { diff --git a/src/crash_reporter.zig b/src/crash_reporter.zig index f31ed81b650e4..735ec74bdbc88 100644 --- a/src/crash_reporter.zig +++ b/src/crash_reporter.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const bun = @import("root").bun; fn setup_sigactions(act: ?*const os.Sigaction) !void { try os.sigaction(os.SIG.ABRT, act, null); @@ -28,13 +29,12 @@ noinline fn sigaction_handler(sig: i32, info: *const std.os.siginfo_t, _: ?*cons } noinline fn sigpipe_handler(_: i32, _: *const std.os.siginfo_t, _: ?*const anyopaque) callconv(.C) void { - const bun = @import("root").bun; bun.Output.debug("SIGPIPE received\n", .{}); } pub fn reloadHandlers() !void { - if (comptime @import("root").bun.Environment.isWindows) { - return @import("root").bun.todo(@src(), {}); + if (comptime bun.Environment.isWindows) { + return bun.todo(@src(), {}); } try os.sigaction(os.SIG.PIPE, null, null); try setup_sigactions(null); @@ -46,7 +46,7 @@ pub fn reloadHandlers() !void { }; try setup_sigactions(&act); - @import("root").bun.spawn.WaiterThread.reloadHandlers(); + bun.spawn.WaiterThread.reloadHandlers(); bun_ignore_sigpipe(); } const os = std.os; @@ -59,7 +59,7 @@ pub fn start() !void { try setup_sigactions(&act); bun_ignore_sigpipe(); - @import("root").bun.spawn.WaiterThread.reloadHandlers(); + bun.spawn.WaiterThread.reloadHandlers(); } extern fn bun_ignore_sigpipe() void; diff --git a/src/css_scanner.zig b/src/css_scanner.zig index ebf849947b70f..d0424aef4829f 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -15,7 +15,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const options = @import("./options.zig"); const import_record = @import("import_record.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const Options = options; const resolver = @import("./resolver/resolver.zig"); const _linker = @import("./linker.zig"); diff --git a/src/defines.zig b/src/defines.zig index 204361be776cd..4c1071f5481ba 100644 --- a/src/defines.zig +++ b/src/defines.zig @@ -1,6 +1,6 @@ const std = @import("std"); const js_ast = bun.JSAst; -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_lexer = bun.js_lexer; const json_parser = bun.JSON; const fs = @import("fs.zig"); diff --git a/src/deps/boringssl.translated.zig b/src/deps/boringssl.translated.zig index 4bb62e5aea23e..069676b37815a 100644 --- a/src/deps/boringssl.translated.zig +++ b/src/deps/boringssl.translated.zig @@ -1,6 +1,7 @@ const std = @import("std"); +const bun = @import("root").bun; const C = @import("std").zig.c_builtins; -const pthread_rwlock_t = if (@import("root").bun.Environment.isPosix) @import("../sync.zig").RwLock.pthread_rwlock_t else *anyopaque; +const pthread_rwlock_t = if (bun.Environment.isPosix) @import("../sync.zig").RwLock.pthread_rwlock_t else *anyopaque; const time_t = C.time_t; const va_list = C.va_list; const struct_timeval = C.struct_timeval; @@ -19068,8 +19069,8 @@ pub const SSL = opaque { }; } - const Output = @import("root").bun.Output; - const Environment = @import("root").bun.Environment; + const Output = bun.Output; + const Environment = bun.Environment; pub fn read(this: *SSL, buf: []u8) Error!usize { const rc = SSL_read(this, buf.ptr, @as(c_int, @intCast(buf.len))); diff --git a/src/deps/c_ares.zig b/src/deps/c_ares.zig index 6798193e75ad9..3a10195ea40f6 100644 --- a/src/deps/c_ares.zig +++ b/src/deps/c_ares.zig @@ -373,7 +373,7 @@ pub const AddrInfo = extern struct { globalThis: *JSC.JSGlobalObject, ) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); var node = addr_info.node.?; const array = JSC.JSValue.createEmptyArray( globalThis, @@ -736,7 +736,7 @@ pub const struct_ares_caa_reply = extern struct { pub fn toJSResponse(this: *struct_ares_caa_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); @@ -814,7 +814,7 @@ pub const struct_ares_srv_reply = extern struct { pub fn toJSResponse(this: *struct_ares_srv_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); @@ -897,7 +897,7 @@ pub const struct_ares_mx_reply = extern struct { pub fn toJSResponse(this: *struct_ares_mx_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); @@ -971,7 +971,7 @@ pub const struct_ares_txt_reply = extern struct { pub fn toJSResponse(this: *struct_ares_txt_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); @@ -1051,7 +1051,7 @@ pub const struct_ares_naptr_reply = extern struct { pub fn toJSResponse(this: *struct_ares_naptr_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); @@ -1143,7 +1143,7 @@ pub const struct_ares_soa_reply = extern struct { pub fn toJSResponse(this: *struct_ares_soa_reply, parent_allocator: std.mem.Allocator, globalThis: *JSC.JSGlobalObject, comptime _: []const u8) JSC.JSValue { var stack = std.heap.stackFallback(2048, parent_allocator); - var arena = @import("root").bun.ArenaAllocator.init(stack.get()); + var arena = bun.ArenaAllocator.init(stack.get()); defer arena.deinit(); const allocator = arena.allocator(); diff --git a/src/deps/lol-html.zig b/src/deps/lol-html.zig index 8ad1a727f27fe..d5e747c773011 100644 --- a/src/deps/lol-html.zig +++ b/src/deps/lol-html.zig @@ -7,7 +7,7 @@ pub const MemorySettings = extern struct { }; inline fn auto_disable() void { - if (comptime @import("root").bun.FeatureFlags.disable_lolhtml) + if (comptime bun.FeatureFlags.disable_lolhtml) unreachable; } diff --git a/src/deps/picohttp.zig b/src/deps/picohttp.zig index 4155678c12861..2153abf23f6f4 100644 --- a/src/deps/picohttp.zig +++ b/src/deps/picohttp.zig @@ -1,10 +1,11 @@ const std = @import("std"); +const bun = @import("root").bun; const c = @import("picohttpparser.zig"); -const ExactSizeMatcher = @import("root").bun.ExactSizeMatcher; +const ExactSizeMatcher = bun.ExactSizeMatcher; const Match = ExactSizeMatcher(2); -const Output = @import("root").bun.Output; -const Environment = @import("root").bun.Environment; -const StringBuilder = @import("root").bun.StringBuilder; +const Output = bun.Output; +const Environment = bun.Environment; +const StringBuilder = bun.StringBuilder; const fmt = std.fmt; diff --git a/src/deps/uws.zig b/src/deps/uws.zig index fc2cbfd465739..f38d9ee11e2fa 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -13,7 +13,7 @@ pub const Socket = opaque {}; const debug = bun.Output.scoped(.uws, false); const uws = @This(); -const BoringSSL = @import("root").bun.BoringSSL; +const BoringSSL = bun.BoringSSL; fn NativeSocketHandleType(comptime ssl: bool) type { if (ssl) { return BoringSSL.SSL; diff --git a/src/env_loader.zig b/src/env_loader.zig index 31ae661f4a2f7..ac3d7049211d7 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; diff --git a/src/feature_flags.zig b/src/feature_flags.zig index b996e5df3808a..9a847aad00bff 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -1,4 +1,6 @@ const env = @import("env.zig"); +const bun = @import("root").bun; + pub const strong_etags_for_built_files = true; pub const keep_alive = false; @@ -95,7 +97,7 @@ pub const hardcode_localhost_to_127_0_0_1 = false; /// so we just disable it pub const support_jsxs_in_jsx_transform = false; -pub const use_simdutf = @import("root").bun.Environment.isNative and !@import("root").bun.JSC.is_bindgen; +pub const use_simdutf = bun.Environment.isNative and !bun.JSC.is_bindgen; pub const inline_properties_in_transpiler = true; @@ -103,7 +105,7 @@ pub const same_target_becomes_destructuring = true; pub const react_server_components = true; -pub const help_catch_memory_issues = @import("root").bun.Environment.allow_assert; +pub const help_catch_memory_issues = bun.Environment.allow_assert; /// This performs similar transforms as https://github.com/rollup/plugins/tree/master/packages/commonjs /// diff --git a/src/http/header_builder.zig b/src/http/header_builder.zig index 882ea7e0f1161..94744fc3263e5 100644 --- a/src/http/header_builder.zig +++ b/src/http/header_builder.zig @@ -1,10 +1,11 @@ const HeaderBuilder = @This(); const StringBuilder = @import("../string_builder.zig"); const Headers = @import("./headers.zig"); -const string = @import("root").bun.string; +const string = bun.string; const HTTPClient = @import("../http.zig"); const Api = @import("../api/schema.zig").Api; const std = @import("std"); +const bun = @import("root").bun; content: StringBuilder = StringBuilder{}, header_count: u64 = 0, diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig index 3ad9cfdeb599b..3e6ecddb03e08 100644 --- a/src/http/websocket_http_client.zig +++ b/src/http/websocket_http_client.zig @@ -13,9 +13,9 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const BoringSSL = bun.BoringSSL; -const uws = @import("root").bun.uws; -const JSC = @import("root").bun.JSC; -const PicoHTTP = @import("root").bun.picohttp; +const uws = bun.uws; +const JSC = bun.JSC; +const PicoHTTP = bun.picohttp; const ObjectPool = @import("../pool.zig").ObjectPool; const WebsocketHeader = @import("./websocket.zig").WebsocketHeader; const WebsocketDataFrame = @import("./websocket.zig").WebsocketDataFrame; diff --git a/src/http/zlib.zig b/src/http/zlib.zig index c69a7b48f7e73..3357720e61e42 100644 --- a/src/http/zlib.zig +++ b/src/http/zlib.zig @@ -1,6 +1,6 @@ const Lock = @import("../lock.zig").Lock; const std = @import("std"); -const MutableString = @import("root").bun.MutableString; +const MutableString = bun.MutableString; const getAllocator = @import("../http.zig").getAllocator; const ZlibPool = @This(); const Zlib = @import("../zlib.zig"); diff --git a/src/import_record.zig b/src/import_record.zig index c21019b693726..560d0f6a1650d 100644 --- a/src/import_record.zig +++ b/src/import_record.zig @@ -1,6 +1,6 @@ -const fs = @import("root").bun.fs; +const fs = bun.fs; const bun = @import("root").bun; -const logger = @import("root").bun.logger; +const logger = bun.logger; const std = @import("std"); const Ref = @import("ast/base.zig").Ref; const Index = @import("ast/base.zig").Index; diff --git a/src/install/bin.zig b/src/install/bin.zig index 0e53e20b30795..47433c8324ed6 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -5,12 +5,12 @@ const String = Semver.String; const Output = bun.Output; const Global = bun.Global; const std = @import("std"); -const strings = @import("root").bun.strings; +const strings = bun.strings; const Environment = @import("../env.zig"); const Path = @import("../resolver/resolve_path.zig"); const C = @import("../c.zig"); const Fs = @import("../fs.zig"); -const stringZ = @import("root").bun.stringZ; +const stringZ = bun.stringZ; const Resolution = @import("./resolution.zig").Resolution; const bun = @import("root").bun; const string = bun.string; diff --git a/src/install/install.zig b/src/install/install.zig index 1d8ebcfaf23ec..a5a957b6706e2 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -3358,7 +3358,7 @@ pub const PackageManager = struct { return null; } - var arena = @import("root").bun.ArenaAllocator.init(this.allocator); + var arena = bun.ArenaAllocator.init(this.allocator); defer arena.deinit(); const arena_alloc = arena.allocator(); var stack_fallback = std.heap.stackFallback(4096, arena_alloc); diff --git a/src/install/npm.zig b/src/install/npm.zig index da6a0c732a6e2..91147553805e7 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -12,15 +12,15 @@ const ExternalStringMap = @import("./install.zig").ExternalStringMap; const ExternalStringList = @import("./install.zig").ExternalStringList; const ExternalSlice = @import("./install.zig").ExternalSlice; const initializeStore = @import("./install.zig").initializeMiniStore; -const logger = @import("root").bun.logger; -const Output = @import("root").bun.Output; +const logger = bun.logger; +const Output = bun.Output; const Integrity = @import("./integrity.zig").Integrity; const Bin = @import("./bin.zig").Bin; -const Environment = @import("root").bun.Environment; +const Environment = bun.Environment; const Aligner = @import("./install.zig").Aligner; -const HTTPClient = @import("root").bun.http; +const HTTPClient = bun.http; const json_parser = bun.JSON; -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const IdentityContext = @import("../identity_context.zig").IdentityContext; const ArrayIdentityContext = @import("../identity_context.zig").ArrayIdentityContext; const SlicedString = Semver.SlicedString; @@ -216,7 +216,7 @@ pub const Registry = struct { not_found: void, }; - const Pico = @import("root").bun.picohttp; + const Pico = bun.picohttp; pub fn getPackageMetadata( allocator: std.mem.Allocator, response: Pico.Response, @@ -892,7 +892,7 @@ pub const PackageManifest = struct { const source = logger.Source.initPathString(expected_name, json_buffer); initializeStore(); defer bun.JSAst.Stmt.Data.Store.memory_allocator.?.pop(); - var arena = @import("root").bun.ArenaAllocator.init(allocator); + var arena = bun.ArenaAllocator.init(allocator); defer arena.deinit(); const json = json_parser.ParseJSONUTF8( &source, diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig index c7f89c8d12891..a0cb160d0c449 100644 --- a/src/install/resolvers/folder_resolver.zig +++ b/src/install/resolvers/folder_resolver.zig @@ -5,14 +5,14 @@ const initializeStore = @import("../install.zig").initializeStore; const json_parser = bun.JSON; const PackageManager = @import("../install.zig").PackageManager; const Npm = @import("../npm.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const FileSystem = @import("../../fs.zig").FileSystem; const JSAst = bun.JSAst; const string = bun.string; const stringZ = bun.stringZ; const Features = @import("../install.zig").Features; const IdentityContext = @import("../../identity_context.zig").IdentityContext; -const strings = @import("root").bun.strings; +const strings = bun.strings; const Resolution = @import("../resolution.zig").Resolution; const String = @import("../semver.zig").String; const Semver = @import("../semver.zig"); diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig index 795b88c2bf98f..d786b7fbc07b5 100644 --- a/src/io/io_linux.zig +++ b/src/io/io_linux.zig @@ -1,6 +1,6 @@ const std = @import("std"); const assert = std.debug.assert; -const Platform = @import("root").bun.analytics.GenerateHeader.GeneratePlatform; +const Platform = bun.analytics.GenerateHeader.GeneratePlatform; const os = struct { pub usingnamespace std.os; pub const EPERM = 1; diff --git a/src/io/pipes.zig b/src/io/pipes.zig index 71f0191896cff..f6fb46053af88 100644 --- a/src/io/pipes.zig +++ b/src/io/pipes.zig @@ -1,4 +1,4 @@ -const Async = @import("root").bun.Async; +const Async = bun.Async; const bun = @import("root").bun; const Environment = bun.Environment; diff --git a/src/js_ast.zig b/src/js_ast.zig index e710f7c02e7fd..763964933c0ec 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const JSXRuntime = @import("options.zig").JSX.Runtime; const Runtime = @import("runtime.zig").Runtime; const bun = @import("root").bun; @@ -18,7 +18,7 @@ const RefHashCtx = @import("ast/base.zig").RefHashCtx; const ObjectPool = @import("./pool.zig").ObjectPool; const ImportRecord = @import("import_record.zig").ImportRecord; const allocators = @import("allocators.zig"); -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const RefCtx = @import("./ast/base.zig").RefCtx; const JSONParser = bun.JSON; const is_bindgen = std.meta.globalOption("bindgen", bool) orelse false; @@ -6805,7 +6805,7 @@ pub fn printmem(comptime format: string, args: anytype) void { } pub const Macro = struct { - const JavaScript = @import("root").bun.JSC; + const JavaScript = bun.JSC; const JSCBase = @import("./bun.js/base.zig"); const Resolver = @import("./resolver/resolver.zig").Resolver; const isPackagePath = @import("./resolver/resolver.zig").isPackagePath; diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 69dafc97cbe96..2b193a5f96083 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const tables = @import("js_lexer_tables.zig"); const build_options = @import("build_options"); const js_ast = bun.JSAst; diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig index 60a705c301284..8f8fe0420658c 100644 --- a/src/js_lexer_tables.zig +++ b/src/js_lexer_tables.zig @@ -1,9 +1,10 @@ const std = @import("std"); +const bun = @import("root").bun; const expectString = std.testing.expectEqualStrings; const expect = std.testing.expect; -const logger = @import("root").bun.logger; +const logger = bun.logger; const unicode = std.unicode; -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const string = @import("string_types.zig").string; const CodePoint = @import("string_types.zig").CodePoint; const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap; diff --git a/src/js_parser.zig b/src/js_parser.zig index 1449d04ff8863..9baf96527358d 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -3,7 +3,7 @@ /// ** you must also increment the `expected_version` in RuntimeTranspilerCache.zig ** /// ** IMPORTANT ** pub const std = @import("std"); -pub const logger = @import("root").bun.logger; +pub const logger = bun.logger; pub const js_lexer = bun.js_lexer; pub const importRecord = @import("./import_record.zig"); pub const js_ast = bun.JSAst; @@ -43,7 +43,7 @@ pub const StmtNodeList = js_ast.StmtNodeList; pub const BindingNodeList = js_ast.BindingNodeList; const DeclaredSymbol = js_ast.DeclaredSymbol; const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Index = @import("./ast/base.zig").Index; fn _disabledAssert(_: bool) void { diff --git a/src/js_printer.zig b/src/js_printer.zig index beddb1c388483..663abe811e7f4 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_lexer = bun.js_lexer; const importRecord = @import("import_record.zig"); const js_ast = bun.JSAst; diff --git a/src/json_parser.zig b/src/json_parser.zig index 4ce9a12aaf5bd..a077132af2e9b 100644 --- a/src/json_parser.zig +++ b/src/json_parser.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_lexer = bun.js_lexer; const importRecord = @import("import_record.zig"); const js_ast = bun.JSAst; diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig index a941038c94f6b..c6ddb0c738bce 100644 --- a/src/libarchive/libarchive.zig +++ b/src/libarchive/libarchive.zig @@ -14,7 +14,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const std = @import("std"); const struct_archive = lib.struct_archive; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; pub const Seek = enum(c_int) { set = std.os.SEEK_SET, current = std.os.SEEK_CUR, diff --git a/src/linker.zig b/src/linker.zig index d84b5788203f5..4b07c71de7b82 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -15,7 +15,7 @@ const Ref = @import("./ast/base.zig").Ref; const std = @import("std"); const lex = bun.js_lexer; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Options = @import("options.zig"); const js_parser = bun.js_parser; const json_parser = bun.JSON; @@ -39,7 +39,7 @@ const ResolverType = Resolver.Resolver; const ESModule = @import("./resolver/package_json.zig").ESModule; const Runtime = @import("./runtime.zig").Runtime; const URL = @import("url.zig").URL; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const PluginRunner = bun.bundler.PluginRunner; pub const CSSResolveError = error{ResolveMessage}; diff --git a/src/logger.zig b/src/logger.zig index 604ebfa83f567..be31238bc8445 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -1,6 +1,6 @@ const std = @import("std"); const Api = @import("./api/schema.zig").Api; -const js = @import("root").bun.JSC; +const js = bun.JSC; const ImportKind = @import("./import_record.zig").ImportKind; const bun = @import("root").bun; const string = bun.string; @@ -12,7 +12,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const fs = @import("fs.zig"); const unicode = std.unicode; const Ref = @import("./ast/base.zig").Ref; diff --git a/src/main_wasm.zig b/src/main_wasm.zig index 6d3ba24665ff5..adf57dee438b4 100644 --- a/src/main_wasm.zig +++ b/src/main_wasm.zig @@ -3,7 +3,7 @@ const JSParser = bun.js_parser; const JSPrinter = bun.js_printer; const JSAst = bun.JSAst; const Api = @import("./api/schema.zig").Api; -const Logger = @import("root").bun.logger; +const Logger = bun.logger; const global = @import("root").bun; const default_allocator = global.default_allocator; const std = @import("std"); @@ -502,7 +502,7 @@ export fn getTests(opts_array: u64) u64 { } export fn transform(opts_array: u64) u64 { - // var arena = @import("root").bun.ArenaAllocator.init(default_allocator); + // var arena = bun.ArenaAllocator.init(default_allocator); var arena = Arena.init() catch unreachable; var allocator = arena.allocator(); defer arena.deinit(); @@ -572,7 +572,7 @@ export fn transform(opts_array: u64) u64 { } export fn scan(opts_array: u64) u64 { - // var arena = @import("root").bun.ArenaAllocator.init(default_allocator); + // var arena = bun.ArenaAllocator.init(default_allocator); var arena = Arena.init() catch unreachable; var allocator = arena.allocator(); defer arena.deinit(); diff --git a/src/meta.zig b/src/meta.zig index 37281e85b2832..cf49553771fa5 100644 --- a/src/meta.zig +++ b/src/meta.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const bun = @import("root").bun; pub usingnamespace std.meta; @@ -36,7 +37,7 @@ pub fn enumFieldNames(comptime Type: type) []const []const u8 { for (names) |name| { // zig seems to include "_" or an empty string in the list of enum field names // it makes sense, but humans don't want that - if (@import("root").bun.strings.eqlAnyComptime(name, &.{ "_none", "", "_" })) { + if (bun.strings.eqlAnyComptime(name, &.{ "_none", "", "_" })) { continue; } names[i] = name; diff --git a/src/napi/napi.zig b/src/napi/napi.zig index 658d4489a2112..0fcf760d6b2ee 100644 --- a/src/napi/napi.zig +++ b/src/napi/napi.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const JSC = @import("root").bun.JSC; -const strings = @import("root").bun.strings; +const JSC = bun.JSC; +const strings = bun.strings; const bun = @import("root").bun; const Lock = @import("../lock.zig").Lock; const JSValue = JSC.JSValue; diff --git a/src/node_fallbacks.zig b/src/node_fallbacks.zig index 00af758850b2d..b3f95ac836b89 100644 --- a/src/node_fallbacks.zig +++ b/src/node_fallbacks.zig @@ -1,7 +1,7 @@ const std = @import("std"); const string = @import("./string_types.zig").string; const PackageJSON = @import("./resolver/package_json.zig").PackageJSON; -const logger = @import("root").bun.logger; +const logger = bun.logger; const Fs = @import("./fs.zig"); const bun = @import("root").bun; const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap; diff --git a/src/options.zig b/src/options.zig index 0097ae9d74134..e0415a5c0381e 100644 --- a/src/options.zig +++ b/src/options.zig @@ -1,7 +1,7 @@ /// This file is mostly the API schema but with all the options normalized. /// Normalization is necessary because most fields in the API schema are optional const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const Fs = @import("fs.zig"); const resolver = @import("./resolver/resolver.zig"); @@ -23,7 +23,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; const StoredFileDescriptorType = bun.StoredFileDescriptorType; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const Runtime = @import("./runtime.zig").Runtime; const Analytics = @import("./analytics/analytics_thread.zig"); const MacroRemap = @import("./resolver/package_json.zig").MacroMap; diff --git a/src/output.zig b/src/output.zig index d89abdc2008f6..0949df1ac8427 100644 --- a/src/output.zig +++ b/src/output.zig @@ -2,13 +2,13 @@ const Output = @This(); const bun = @import("root").bun; const std = @import("std"); const Environment = @import("./env.zig"); -const string = @import("root").bun.string; +const string = bun.string; const root = @import("root"); -const strings = @import("root").bun.strings; -const StringTypes = @import("root").bun.StringTypes; -const Global = @import("root").bun.Global; -const ComptimeStringMap = @import("root").bun.ComptimeStringMap; -const use_mimalloc = @import("root").bun.use_mimalloc; +const strings = bun.strings; +const StringTypes = bun.StringTypes; +const Global = bun.Global; +const ComptimeStringMap = bun.ComptimeStringMap; +const use_mimalloc = bun.use_mimalloc; const writeStream = std.json.writeStream; const WriteStream = std.json.WriteStream; @@ -663,7 +663,7 @@ pub const color_map = ComptimeStringMap(string, .{ }); const RESET: string = "\x1b[0m"; pub fn prettyFmt(comptime fmt: string, comptime is_enabled: bool) string { - if (comptime @import("root").bun.fast_debug_build_mode) + if (comptime bun.fast_debug_build_mode) return fmt; comptime var new_fmt: [fmt.len * 4]u8 = undefined; @@ -752,7 +752,7 @@ pub noinline fn prettyWithPrinter(comptime fmt: string, args: anytype, comptime } pub noinline fn prettyWithPrinterFn(comptime fmt: string, args: anytype, comptime printFn: anytype, ctx: anytype) void { - if (comptime @import("root").bun.fast_debug_build_mode) + if (comptime bun.fast_debug_build_mode) return printFn(ctx, comptime prettyFmt(fmt, false), args); if (enable_ansi_colors) { @@ -810,7 +810,7 @@ pub noinline fn printError(comptime fmt: string, args: anytype) void { } pub const DebugTimer = struct { - timer: @import("root").bun.DebugOnly(std.time.Timer) = undefined, + timer: bun.DebugOnly(std.time.Timer) = undefined, pub fn start() DebugTimer { if (comptime Environment.isDebug) { diff --git a/src/panic_handler.zig b/src/panic_handler.zig index ce80d92ebf500..e5d0167fe93cc 100644 --- a/src/panic_handler.zig +++ b/src/panic_handler.zig @@ -11,7 +11,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const CLI = @import("./cli.zig").Cli; const Features = @import("./analytics/analytics_thread.zig").Features; -const HTTP = @import("root").bun.http.AsyncHTTP; +const HTTP = bun.http.AsyncHTTP; const Report = @import("./report.zig"); pub fn NewPanicHandler(comptime panic_func: fn ([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn) type { diff --git a/src/renamer.zig b/src/renamer.zig index f3461a6a7f550..ea3196a802ad5 100644 --- a/src/renamer.zig +++ b/src/renamer.zig @@ -12,7 +12,7 @@ const C = bun.C; const std = @import("std"); const Ref = @import("./ast/base.zig").Ref; const RefCtx = @import("./ast/base.zig").RefCtx; -const logger = @import("root").bun.logger; +const logger = bun.logger; const JSLexer = @import("./js_lexer.zig"); pub const NoOpRenamer = struct { @@ -470,7 +470,7 @@ pub const NumberRenamer = struct { allocator: std.mem.Allocator, temp_allocator: std.mem.Allocator, number_scope_pool: bun.HiveArray(NumberScope, 128).Fallback, - arena: @import("root").bun.ArenaAllocator, + arena: bun.ArenaAllocator, root: NumberScope = .{}, name_stack_fallback: std.heap.StackFallbackAllocator(512) = undefined, name_temp_allocator: std.mem.Allocator = undefined, @@ -538,7 +538,7 @@ pub const NumberRenamer = struct { .temp_allocator = temp_allocator, .names = try allocator.alloc(bun.BabyList(string), symbols.symbols_for_source.len), .number_scope_pool = undefined, - .arena = @import("root").bun.ArenaAllocator.init(temp_allocator), + .arena = bun.ArenaAllocator.init(temp_allocator), }; renamer.name_stack_fallback = .{ .buffer = undefined, diff --git a/src/report.zig b/src/report.zig index 70e80702da7ed..84d729653cbdd 100644 --- a/src/report.zig +++ b/src/report.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const bun = @import("root").bun; const string = bun.string; const Output = bun.Output; @@ -13,7 +13,7 @@ const C = bun.C; const CLI = @import("./cli.zig").Cli; const Features = @import("./analytics/analytics_thread.zig").Features; const Platform = @import("./analytics/analytics_thread.zig").GenerateHeader.GeneratePlatform; -const HTTP = @import("root").bun.http.AsyncHTTP; +const HTTP = bun.http.AsyncHTTP; const CrashReporter = @import("./crash_reporter.zig"); const Report = @This(); @@ -308,7 +308,7 @@ pub noinline fn handleCrash(signal: i32, addr: usize) void { } if (!Environment.isWindows) { - if (comptime !@import("root").bun.JSC.is_bindgen) { + if (comptime !bun.JSC.is_bindgen) { std.mem.doNotOptimizeAway(&Bun__crashReportWrite); Bun__crashReportDumpStackTrace(&crash_report_writer); } diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 10546363aae4f..ac13ca954e11a 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -13,7 +13,7 @@ const Api = @import("../api/schema.zig").Api; const std = @import("std"); const options = @import("../options.zig"); const cache = @import("../cache.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_ast = bun.JSAst; const fs = @import("../fs.zig"); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 25758cf1af3b3..d14542b152c29 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -12,7 +12,7 @@ const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const C = bun.C; const ast = @import("../import_record.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const options = @import("../options.zig"); const Fs = @import("../fs.zig"); const std = @import("std"); diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig index d63b3bf5d5e57..a7f4fe9db90b6 100644 --- a/src/resolver/tsconfig_json.zig +++ b/src/resolver/tsconfig_json.zig @@ -10,7 +10,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const std = @import("std"); const options = @import("../options.zig"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const cache = @import("../cache.zig"); const js_ast = bun.JSAst; const js_lexer = bun.js_lexer; diff --git a/src/router.zig b/src/router.zig index de6494591a61f..2a11f738d5085 100644 --- a/src/router.zig +++ b/src/router.zig @@ -967,7 +967,7 @@ const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const expectEqualStrings = std.testing.expectEqualStrings; const expectStr = std.testing.expectEqualStrings; -const Logger = @import("root").bun.logger; +const Logger = bun.logger; pub const Test = struct { pub fn makeRoutes(comptime testName: string, data: anytype) !Routes { diff --git a/src/sha.zig b/src/sha.zig index c8a1a095eae53..9c6e3854a7f6d 100644 --- a/src/sha.zig +++ b/src/sha.zig @@ -1,7 +1,6 @@ -const BoringSSL = @import("root").bun.BoringSSL; +const BoringSSL = bun.BoringSSL; const std = @import("std"); - -pub const bun = if (@import("build_options").project.len == 0) @import("./bun.zig") else @import("root").bun; +pub const bun = @import("root").bun; fn NewHasher(comptime digest_size: comptime_int, comptime ContextType: type, comptime Full: anytype, comptime Init: anytype, comptime Update: anytype, comptime Final: anytype) type { return struct { diff --git a/src/shell/subproc.zig b/src/shell/subproc.zig index a3b9e3f547ede..cdec642d97b36 100644 --- a/src/shell/subproc.zig +++ b/src/shell/subproc.zig @@ -1,15 +1,15 @@ -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; -const NetworkThread = @import("root").bun.http.NetworkThread; +const NetworkThread = bun.http.NetworkThread; const Global = bun.Global; const strings = bun.strings; const string = bun.string; -const Output = @import("root").bun.Output; -const MutableString = @import("root").bun.MutableString; +const Output = bun.Output; +const MutableString = bun.MutableString; const std = @import("std"); const Allocator = std.mem.Allocator; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const Which = @import("../which.zig"); @@ -755,7 +755,7 @@ pub const ShellSubprocess = struct { spawn_args_: SpawnArgs, out: **@This(), ) bun.shell.Result(void) { - var arena = @import("root").bun.ArenaAllocator.init(bun.default_allocator); + var arena = bun.ArenaAllocator.init(bun.default_allocator); defer arena.deinit(); var spawn_args = spawn_args_; diff --git a/src/shell/util.zig b/src/shell/util.zig index 1b448c818c764..a474fafcf7802 100644 --- a/src/shell/util.zig +++ b/src/shell/util.zig @@ -2,15 +2,15 @@ const IPC = @import("../bun.js/ipc.zig"); const Allocator = std.mem.Allocator; const uws = bun.uws; const std = @import("std"); -const default_allocator = @import("root").bun.default_allocator; +const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; const Async = bun.Async; -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const Which = @import("../which.zig"); -const Output = @import("root").bun.Output; +const Output = bun.Output; const PosixSpawn = @import("../bun.js/api/bun/spawn.zig").PosixSpawn; const os = std.os; diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index d366e8af90573..10e25ad2d6e52 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -8,7 +8,7 @@ const bun = @import("root").bun; const string = bun.string; const JSAst = bun.JSAst; const BabyList = JSAst.BabyList; -const Logger = @import("root").bun.logger; +const Logger = bun.logger; const strings = bun.strings; const MutableString = bun.MutableString; const Joiner = @import("../string_joiner.zig"); diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 1dda0e6de3850..8769058d50587 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -2441,7 +2441,7 @@ pub fn elementLengthLatin1IntoUTF8(comptime Type: type, latin1_: Type) usize { return input_len + total_non_ascii_count; } -const JSC = @import("root").bun.JSC; +const JSC = bun.JSC; pub fn copyLatin1IntoUTF16(comptime Buffer: type, buf_: Buffer, comptime Type: type, latin1_: Type) EncodeIntoResult { var buf = buf_; diff --git a/src/string_types.zig b/src/string_types.zig index 456c7f186ef87..1858cae1e40ab 100644 --- a/src/string_types.zig +++ b/src/string_types.zig @@ -16,7 +16,7 @@ pub const PathString = packed struct { ptr: PointerIntType = 0, len: PathInt = 0, - const JSC = @import("root").bun.JSC; + const JSC = bun.JSC; pub fn estimatedSize(this: *const PathString) usize { return @as(usize, this.len); diff --git a/src/thread_pool.zig b/src/thread_pool.zig index 369adacd699f4..0bfa281f04348 100644 --- a/src/thread_pool.zig +++ b/src/thread_pool.zig @@ -670,7 +670,7 @@ fn join(self: *ThreadPool) void { thread.join_event.notify(); } -const Output = @import("root").bun.Output; +const Output = bun.Output; pub const Thread = struct { next: ?*Thread = null, diff --git a/src/toml/toml_lexer.zig b/src/toml/toml_lexer.zig index a8010f8644eab..b9d93991a5523 100644 --- a/src/toml/toml_lexer.zig +++ b/src/toml/toml_lexer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const js_ast = bun.JSAst; const bun = @import("root").bun; diff --git a/src/toml/toml_parser.zig b/src/toml/toml_parser.zig index c1baa68ee0a4b..c31c70dcff535 100644 --- a/src/toml/toml_parser.zig +++ b/src/toml/toml_parser.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const logger = @import("root").bun.logger; +const logger = bun.logger; const toml_lexer = @import("./toml_lexer.zig"); const Lexer = toml_lexer.Lexer; const importRecord = @import("../import_record.zig"); diff --git a/src/work_pool.zig b/src/work_pool.zig index c0c5649d44582..495bfdb292f77 100644 --- a/src/work_pool.zig +++ b/src/work_pool.zig @@ -1,5 +1,6 @@ -const ThreadPool = @import("root").bun.ThreadPool; +const ThreadPool = bun.ThreadPool; const std = @import("std"); +const bun = @import("root").bun; pub const Batch = ThreadPool.Batch; pub const Task = ThreadPool.Task; From 21fc1f7295b10f8e8384592d584793f33e89ca52 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 9 Apr 2024 22:51:22 -0700 Subject: [PATCH 06/13] Add test for #10132 (#10136) * Add test for #10132 * Update 010132.test.ts * Update 010132.test.ts --- src/cli/run_command.zig | 2 +- test/regression/issue/010132.test.ts | 83 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test/regression/issue/010132.test.ts diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 6d0b302909b79..eb9a87ea55cb4 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -942,7 +942,7 @@ pub const RunCommand = struct { if (root_dir_info.enclosing_package_json) |package_json| { if (root_dir_info.package_json == null) { // no trailing slash - package_json_dir = std.mem.trimRight(u8, package_json.source.path.name.dir, "/"); + package_json_dir = strings.withoutTrailingSlash(package_json.source.path.name.dir); } } diff --git a/test/regression/issue/010132.test.ts b/test/regression/issue/010132.test.ts new file mode 100644 index 0000000000000..25fbcbf7beb36 --- /dev/null +++ b/test/regression/issue/010132.test.ts @@ -0,0 +1,83 @@ +import { test, expect, beforeAll } from "bun:test"; +import { join } from "path"; +import { $ } from "bun"; +import { bunExe, isPosix, tempDirWithFiles } from "harness"; +import { chmodSync } from "fs"; + +let dir = ""; +beforeAll(() => { + dir = tempDirWithFiles("issue-10132", { + "subdir/one/two/three/hello.txt": "hello", + "node_modules/.bin/bun-hello": `#!/usr/bin/env bash +echo "My name is bun-hello" + `, + "node_modules/.bin/bun-hello.cmd": `@echo off +echo My name is bun-hello + `, + "subdir/one/two/package.json": JSON.stringify( + { + name: "issue-10132", + version: "0.0.0", + scripts: { + "other-script": "echo hi", + }, + }, + null, + 2, + ), + "subdir/one/two/node_modules/.bin/bun-hello2": `#!/usr/bin/env bash +echo "My name is bun-hello2" + `, + "subdir/one/two/node_modules/.bin/bun-hello2.cmd": `@echo off +echo My name is bun-hello2 + `, + "package.json": JSON.stringify( + { + name: "issue-10132", + version: "0.0.0", + scripts: { + "get-pwd": "pwd", + }, + }, + null, + 2, + ), + }); + + if (isPosix) { + chmodSync(join(dir, "node_modules/.bin/bun-hello"), 0o755); + chmodSync(join(dir, "subdir/one/two/node_modules/.bin/bun-hello2"), 0o755); + } +}); + +test("issue #10132, bun run sets cwd", async () => { + $.cwd(dir); + const currentPwd = (await $`${bunExe()} run get-pwd`.text()).trim(); + expect(currentPwd).toBe(dir); + + const currentPwd2 = join(currentPwd, "subdir", "one"); + $.cwd(currentPwd2); + expect((await $`${bunExe()} run get-pwd`.text()).trim()).toBe(currentPwd2); + + $.cwd(process.cwd()); +}); + +test("issue #10132, bun run sets PATH", async () => { + async function run(dir: string) { + $.cwd(dir); + const [first, second] = await Promise.all([$`${bunExe()} bun-hello`.quiet(), $`${bunExe()} run bun-hello`.quiet()]); + + expect(first.text().trim()).toBe("My name is bun-hello"); + expect(second.text().trim()).toBe("My name is bun-hello"); + } + + await Promise.all( + [ + dir, + join(dir, "subdir"), + join(dir, "subdir", "one"), + join(dir, "subdir", "one", "two"), + join(dir, "subdir", "one", "two", "three"), + ].map(run), + ); +}); From cd52f421486cb5da80221f1ccc5e65801d68b9d9 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 9 Apr 2024 22:57:10 -0700 Subject: [PATCH 07/13] windows: fs/promises: fix when writing to file opened in append mode (#10134) * windows: fs/promises: fix when writing to file opened in append mode * add default values since we're using one now * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/bun.js/node/node_fs.zig | 4 ++++ src/js/node/fs.promises.ts | 34 +++++++++++++++++++++++++------- test/js/node/fs/promises.test.js | 16 +++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 6d72269796848..13fac010b8913 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -5458,6 +5458,10 @@ pub const NodeFS = struct { } if (Environment.isWindows) { + if (args.flag == .a) { + return Maybe(Return.WriteFile).success; + } + const rc = std.os.windows.kernel32.SetEndOfFile(fd.cast()); if (rc == 0) { return .{ diff --git a/src/js/node/fs.promises.ts b/src/js/node/fs.promises.ts index c0a9b00259b29..7ba217144243f 100644 --- a/src/js/node/fs.promises.ts +++ b/src/js/node/fs.promises.ts @@ -19,6 +19,7 @@ const kTransfer = Symbol("kTransfer"); const kTransferList = Symbol("kTransferList"); const kDeserialize = Symbol("kDeserialize"); const kEmptyObject = ObjectFreeze({ __proto__: null }); +const kFlag = Symbol("kFlag"); function watch( filename: string | Buffer | URL, @@ -174,8 +175,8 @@ const exports = { lstat: fs.lstat.bind(fs), mkdir: fs.mkdir.bind(fs), mkdtemp: fs.mkdtemp.bind(fs), - open: async (path, flags, mode) => { - return new FileHandle(await fs.open(path, flags, mode)); + open: async (path, flags = "r", mode = 0o666) => { + return new FileHandle(await fs.open(path, flags, mode), flags); }, read: fs.read.bind(fs), write: fs.write.bind(fs), @@ -240,11 +241,12 @@ export default exports; // These functions await the result so that errors propagate correctly with // async stack traces and so that the ref counting is correct. var FileHandle = (private_symbols.FileHandle = class FileHandle extends EventEmitter { - constructor(fd) { + constructor(fd, flag) { super(); this[kFd] = fd ? fd : -1; this[kRefs] = 1; this[kClosePromise] = null; + this[kFlag] = flag; } getAsyncId() { @@ -255,13 +257,23 @@ export default exports; return this[kFd]; } - async appendFile(data, options) { + async appendFile(data, options: object | string | undefined) { const fd = this[kFd]; throwEBADFIfNecessary(writeFile, fd); + let encoding = "utf8"; + let flush = false; + + if (options == null || typeof options === "function") { + } else if (typeof options === "string") { + encoding = options; + } else { + encoding = options?.encoding ?? encoding; + flush = options?.flush ?? flush; + } try { this[kRef](); - return await writeFile(fd, data, options); + return await writeFile(fd, data, { encoding, flush, flag: this[kFlag] }); } finally { this[kUnref](); } @@ -415,13 +427,21 @@ export default exports; } } - async writeFile(data, options) { + async writeFile(data: string, options: object | string | undefined = "utf8") { const fd = this[kFd]; throwEBADFIfNecessary(writeFile, fd); + let encoding: string = "utf8"; + + if (options == null || typeof options === "function") { + } else if (typeof options === "string") { + encoding = options; + } else { + encoding = options?.encoding ?? encoding; + } try { this[kRef](); - return await writeFile(fd, data, options); + return await writeFile(fd, data, { encoding, flag: this[kFlag] }); } finally { this[kUnref](); } diff --git a/test/js/node/fs/promises.test.js b/test/js/node/fs/promises.test.js index e97127827c516..24309e6aba14a 100644 --- a/test/js/node/fs/promises.test.js +++ b/test/js/node/fs/promises.test.js @@ -9,6 +9,7 @@ const open = fsPromises.open; const copyFile = fsPromises.copyFile; const statfs = fsPromises.statfs; const unlink = fsPromises.unlink; +const readFile = fsPromises.readFile; // // @@ -186,3 +187,18 @@ describe("more", () => { }); }); }); + +test("writing to file in append mode works", async () => { + const tempFile = os.tmpdir() + "/" + Date.now() + ".txt"; + + const f = await open(tempFile, "a"); + + await f.writeFile("test\n"); + await f.appendFile("test\n"); + await f.write("test\n"); + await f.datasync(); + + await f.close(); + + expect((await readFile(tempFile)).toString()).toEqual("test\ntest\ntest\n"); +}); From 1e20f618c9300e9774b8c1b5e72dce873992cb57 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 9 Apr 2024 23:18:09 -0700 Subject: [PATCH 08/13] [bundler] Do not generate sourceContents for non-javascript assets (#10140) --- src/bundler/bundle_v2.zig | 12 +++++ src/sourcemap/sourcemap.zig | 11 +++++ test/bundler/expectBundled.ts | 2 +- test/bundler/large_asset_regression.test.ts | 54 +++++++++++++++++++++ test/harness.ts | 7 ++- 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 test/bundler/large_asset_regression.test.ts diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 9967311bfa11a..d1b621d4dfa11 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -3870,6 +3870,13 @@ const LinkerContext = struct { const line_offset_table: *bun.sourcemap.LineOffsetTable.List = &this.graph.files.items(.line_offset_table)[source_index]; const source: *const Logger.Source = &this.parse_graph.input_files.items(.source)[source_index]; + const loader: options.Loader = this.parse_graph.input_files.items(.loader)[source_index]; + + if (!loader.canHaveSourceMap()) { + // This is not a file which we support generating source maps for + line_offset_table.* = .{}; + return; + } const approximate_line_count = this.graph.ast.items(.approximate_newline_count)[source_index]; @@ -3884,7 +3891,12 @@ const LinkerContext = struct { pub fn computeQuotedSourceContents(this: *LinkerContext, allocator: std.mem.Allocator, source_index: Index.Int) void { debug("Computing Quoted Source Contents: {d}", .{source_index}); + const loader: options.Loader = this.parse_graph.input_files.items(.loader)[source_index]; const quoted_source_contents: *string = &this.graph.files.items(.quoted_source_contents)[source_index]; + if (!loader.canHaveSourceMap()) { + quoted_source_contents.* = ""; + return; + } const source: *const Logger.Source = &this.parse_graph.input_files.items(.source)[source_index]; const mutable = MutableString.initEmpty(allocator); diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 10e25ad2d6e52..a486378f7acc3 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -1399,6 +1399,17 @@ pub const Chunk = struct { b.prev_loc = loc; const list = b.line_offset_tables; + + // We have no sourcemappings. + // This happens for example when importing an asset which does not support sourcemaps + // like a png or a jpg + // + // import foo from "./foo.png"; + // + if (list.len == 0) { + return; + } + const original_line = LineOffsetTable.findLine(b.line_offset_table_byte_offset_list, loc); const line = list.get(@as(usize, @intCast(@max(original_line, 0)))); diff --git a/test/bundler/expectBundled.ts b/test/bundler/expectBundled.ts index 8d26e4b83627f..4d4dd85faad86 100644 --- a/test/bundler/expectBundled.ts +++ b/test/bundler/expectBundled.ts @@ -121,7 +121,7 @@ export interface BundlerTestInput { todo?: boolean; // file options - files: Record; + files: Record; /** Files to be written only after the bundle is done. */ runtimeFiles?: Record; /** Defaults to the first item in `files` */ diff --git a/test/bundler/large_asset_regression.test.ts b/test/bundler/large_asset_regression.test.ts new file mode 100644 index 0000000000000..d3a662fa6a378 --- /dev/null +++ b/test/bundler/large_asset_regression.test.ts @@ -0,0 +1,54 @@ +import { test, expect, beforeAll, describe, afterAll } from "bun:test"; +import { bunExe, tempDirWithFiles } from "harness"; +import path from "path"; +import { rm } from "fs/promises"; +import { $ } from "bun"; +import { readdirSync, statSync } from "fs"; + +// https://github.com/oven-sh/bun/issues/10139 +describe("https://github.com/oven-sh/bun/issues/10139", async () => { + let temp = ""; + beforeAll(async () => { + temp = tempDirWithFiles("issue-10132", { + "huge-asset.js": ` + import huge from './1.png'; + if (!huge.startsWith("https://example.com/huge")) { + throw new Error("Unexpected public path: " + huge); + } + `, + "1.png": new Buffer(1024 * 1024 * 1024), + }); + }); + + afterAll(async () => { + rm(temp, { recursive: true, force: true }); + }); + + test("Bun.build", async () => { + const results = await Bun.build({ + entrypoints: [path.join(temp, "huge-asset.js")], + outdir: path.join(temp, "out"), + sourcemap: "external", + }); + var sourceMapCount = 0; + for (const output of results.outputs) { + const size = output?.sourcemap?.size || 0; + expect(size).toBeLessThan(1024); + sourceMapCount += Number(Number(size) > 0); + } + await rm(path.join(temp, "out"), { force: true, recursive: true }); + expect(sourceMapCount).toBe(1); + }); + + test("CLI", async () => { + $.cwd(temp); + await $`${bunExe()} build ./huge-asset.js --outdir=out --sourcemap=external --minify`; + readdirSync(path.join(temp, "out")).forEach(file => { + const size = statSync(path.join(temp, "out", file)).size; + if (file.includes(".map")) { + expect(size).toBeLessThan(1024); + } + }); + await rm(path.join(temp, "out"), { recursive: true, force: true }); + }); +}); diff --git a/test/harness.ts b/test/harness.ts index b4c00c3426fd0..1f8b7c18a8c0b 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -110,14 +110,17 @@ export function hideFromStackTrace(block: CallableFunction) { }); } -export function tempDirWithFiles(basename: string, files: Record>): string { +export function tempDirWithFiles( + basename: string, + files: Record>, +): string { var fs = require("fs"); var path = require("path"); var { tmpdir } = require("os"); const dir = fs.mkdtempSync(path.join(fs.realpathSync(tmpdir()), basename + "_")); for (const [name, contents] of Object.entries(files)) { - if (typeof contents === "object") { + if (typeof contents === "object" && contents && !Buffer.isBuffer(contents)) { const entries = Object.entries(contents); if (entries.length == 0) { fs.mkdirSync(path.join(dir, name), { recursive: true }); From f5c8914c8a23eacbfbb91d497a51474f2d54939f Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 9 Apr 2024 23:21:11 -0700 Subject: [PATCH 09/13] Re-sync `URL` from WebKit + set `ERR_MISSING_ARGS` (#10129) * Update URL from WebKit * Set `ERR_MISSING_ARGS` code on all Error objects from C++ * Fix the `code` * [autofix.ci] apply automated fixes * Micro optimize URL * [autofix.ci] apply automated fixes * Update url.mjs * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- bench/snippets/url.mjs | 19 ++ src/bun.js/bindings/DOMURL.cpp | 109 +++--- src/bun.js/bindings/DOMURL.h | 19 +- src/bun.js/bindings/URLSearchParams.cpp | 2 +- src/bun.js/bindings/bindings.zig | 2 +- .../bindings/webcore/JSDOMOperation.cpp | 22 ++ src/bun.js/bindings/webcore/JSDOMOperation.h | 12 +- src/bun.js/bindings/webcore/JSDOMURL.cpp | 309 ++++++++---------- test/js/node/url/url.test.ts | 13 + 9 files changed, 291 insertions(+), 216 deletions(-) create mode 100644 bench/snippets/url.mjs create mode 100644 src/bun.js/bindings/webcore/JSDOMOperation.cpp diff --git a/bench/snippets/url.mjs b/bench/snippets/url.mjs new file mode 100644 index 0000000000000..1cb6e7a8f1ea5 --- /dev/null +++ b/bench/snippets/url.mjs @@ -0,0 +1,19 @@ +import { bench, run } from "./runner.mjs"; + +bench(`new URL('https://example.com/')`, () => { + const url = new URL("https://example.com/"); +}); + +bench(`new URL('https://example.com')`, () => { + const url = new URL("https://example.com"); +}); + +bench(`new URL('https://www.example.com')`, () => { + const url = new URL("https://www.example.com"); +}); + +bench(`new URL('https://www.example.com/')`, () => { + const url = new URL("https://www.example.com/"); +}); + +await run(); diff --git a/src/bun.js/bindings/DOMURL.cpp b/src/bun.js/bindings/DOMURL.cpp index 9818fc6cb99a0..638111df9dc00 100644 --- a/src/bun.js/bindings/DOMURL.cpp +++ b/src/bun.js/bindings/DOMURL.cpp @@ -23,42 +23,50 @@ * Boston, MA 02110-1301, USA. */ +#include "config.h" #include "DOMURL.h" -// #include "ActiveDOMObject.h" +#include "ActiveDOMObject.h" // #include "Blob.h" // #include "BlobURL.h" // #include "MemoryCache.h" // #include "PublicURLManager.h" // #include "ResourceRequest.h" +#include "ScriptExecutionContext.h" +// #include "SecurityOrigin.h" #include "URLSearchParams.h" -// #include +#include + +class URLRegistrable { +public: +}; + +class Blob { +public: +}; namespace WebCore { static inline String redact(const String& input) { - if (input.contains("@"_s)) + if (input.contains('@')) return ""_s; return makeString('"', input, '"'); } -inline DOMURL::DOMURL(URL&& completeURL, const URL& baseURL) - : m_baseURL(baseURL) - , m_url(WTFMove(completeURL)) +inline DOMURL::DOMURL(URL&& completeURL) + : m_url(WTFMove(completeURL)) { + ASSERT(m_url.isValid()); } -DOMURL::~DOMURL() = default; - -bool DOMURL::canParse(const String& url, const String& base) +ExceptionOr> DOMURL::create(const String& url) { - URL baseURL { base }; - if (!base.isNull() && !baseURL.isValid()) - return false; - URL completeURL { baseURL, url }; - return completeURL.isValid(); + URL completeURL { url }; + if (!completeURL.isValid()) + return Exception { TypeError, makeString(redact(url), " cannot be parsed as a URL.") }; + return adoptRef(*new DOMURL(WTFMove(completeURL))); } ExceptionOr> DOMURL::create(const String& url, const URL& base) @@ -67,7 +75,7 @@ ExceptionOr> DOMURL::create(const String& url, const URL& base) URL completeURL { base, url }; if (!completeURL.isValid()) return Exception { TypeError, makeString(redact(url), " cannot be parsed as a URL.") }; - return adoptRef(*new DOMURL(WTFMove(completeURL), base)); + return adoptRef(*new DOMURL(WTFMove(completeURL))); } ExceptionOr> DOMURL::create(const String& url, const String& base) @@ -78,9 +86,27 @@ ExceptionOr> DOMURL::create(const String& url, const String& base) return create(url, baseURL); } -ExceptionOr> DOMURL::create(const String& url, const DOMURL& base) +DOMURL::~DOMURL() = default; + +static URL parseInternal(const String& url, const String& base) +{ + URL baseURL { base }; + if (!base.isNull() && !baseURL.isValid()) + return {}; + return { baseURL, url }; +} + +RefPtr DOMURL::parse(const String& url, const String& base) { - return create(url, base.href()); + auto completeURL = parseInternal(url, base); + if (!completeURL.isValid()) + return {}; + return adoptRef(*new DOMURL(WTFMove(completeURL))); +} + +bool DOMURL::canParse(const String& url, const String& base) +{ + return parseInternal(url, base).isValid(); } ExceptionOr DOMURL::setHref(const String& url) @@ -96,26 +122,27 @@ ExceptionOr DOMURL::setHref(const String& url) return {}; } -void DOMURL::setQuery(const String& query) +String DOMURL::createObjectURL(ScriptExecutionContext& scriptExecutionContext, Blob& blob) { - m_url.setQuery(query); + UNUSED_PARAM(blob); + UNUSED_PARAM(scriptExecutionContext); + return String(); + // return createPublicURL(scriptExecutionContext, blob); } -// String DOMURL::createObjectURL(Blob& blob) -// { -// return createPublicURL(scriptExecutionContext, blob); -// } - -// String DOMURL::createPublicURL(URLRegistrable& registrable) -// { -// URL publicURL = BlobURL::createPublicURL(scriptExecutionContext.securityOrigin()); -// if (publicURL.isEmpty()) -// return String(); +String DOMURL::createPublicURL(ScriptExecutionContext& scriptExecutionContext, URLRegistrable& registrable) +{ + // URL publicURL = BlobURL::createPublicURL(scriptExecutionContext.securityOrigin()); + // if (publicURL.isEmpty()) + // return String(); -// scriptExecutionContext.publicURLManager().registerURL(publicURL, registrable); + // scriptExecutionContext.publicURLManager().registerURL(publicURL, registrable); -// return publicURL.string(); -// } + // return publicURL.string(); + UNUSED_PARAM(scriptExecutionContext); + UNUSED_PARAM(registrable); + return String(); +} URLSearchParams& DOMURL::searchParams() { @@ -124,15 +151,17 @@ URLSearchParams& DOMURL::searchParams() return *m_searchParams; } -// void DOMURL::revokeObjectURL(const String& urlString) -// { -// // URL url(URL(), urlString); -// // ResourceRequest request(url); -// // request.setDomainForCachePartition(scriptExecutionContext.domainForCachePartition()); +void DOMURL::revokeObjectURL(ScriptExecutionContext& scriptExecutionContext, const String& urlString) +{ + // URL url { urlString }; + // ResourceRequest request(url); + // request.setDomainForCachePartition(scriptExecutionContext.domainForCachePartition()); -// // MemoryCache::removeRequestFromSessionCaches(scriptExecutionContext, request); + // MemoryCache::removeRequestFromSessionCaches(scriptExecutionContext, request); -// // scriptExecutionContext.publicURLManager().revoke(url); -// } + // scriptExecutionContext.publicURLManager().revoke(url); + UNUSED_PARAM(scriptExecutionContext); + UNUSED_PARAM(urlString); +} } // namespace WebCore diff --git a/src/bun.js/bindings/DOMURL.h b/src/bun.js/bindings/DOMURL.h index 7e8c40015e2d9..e0aff84cbc9d4 100644 --- a/src/bun.js/bindings/DOMURL.h +++ b/src/bun.js/bindings/DOMURL.h @@ -35,36 +35,39 @@ namespace WebCore { +class Blob; +class ScriptExecutionContext; +class URLRegistrable; class URLSearchParams; class DOMURL final : public RefCounted, public CanMakeWeakPtr, public URLDecomposition { public: static ExceptionOr> create(const String& url, const String& base); - static ExceptionOr> create(const String& url, const DOMURL& base); - ~DOMURL(); + static ExceptionOr> create(const String& url); + WEBCORE_EXPORT ~DOMURL(); + static RefPtr parse(const String& url, const String& base); static bool canParse(const String& url, const String& base); + const URL& href() const { return m_url; } ExceptionOr setHref(const String&); - void setQuery(const String&); URLSearchParams& searchParams(); const String& toJSON() const { return m_url.string(); } - // static String createObjectURL(ScriptExecutionContext&, Blob&); - // static void revokeObjectURL(ScriptExecutionContext&, const String&); + static String createObjectURL(ScriptExecutionContext&, Blob&); + static void revokeObjectURL(ScriptExecutionContext&, const String&); - // static String createPublicURL(ScriptExecutionContext&, URLRegistrable&); + static String createPublicURL(ScriptExecutionContext&, URLRegistrable&); private: static ExceptionOr> create(const String& url, const URL& base); - DOMURL(URL&& completeURL, const URL& baseURL); + DOMURL(URL&& completeURL); URL fullURL() const final { return m_url; } void setFullURL(const URL& fullURL) final { setHref(fullURL.string()); } - URL m_baseURL; URL m_url; RefPtr m_searchParams; }; diff --git a/src/bun.js/bindings/URLSearchParams.cpp b/src/bun.js/bindings/URLSearchParams.cpp index dd86cab765b38..fc0b543842d30 100644 --- a/src/bun.js/bindings/URLSearchParams.cpp +++ b/src/bun.js/bindings/URLSearchParams.cpp @@ -165,7 +165,7 @@ String URLSearchParams::toString() const void URLSearchParams::updateURL() { if (m_associatedURL) - m_associatedURL->setQuery(WTF::URLParser::serialize(m_pairs)); + m_associatedURL->setSearch(WTF::URLParser::serialize(m_pairs)); } void URLSearchParams::updateFromAssociatedURL() diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 55348dc834cae..d5e81f726f2aa 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -2709,7 +2709,7 @@ pub const JSGlobalObject = extern struct { got: usize, ) JSC.JSValue { return JSC.toTypeErrorWithCode( - "NOT_ENOUGH_ARGUMENTS", + @tagName(JSC.Node.ErrorCode.ERR_MISSING_ARGS), "Not enough arguments to '" ++ name_ ++ "'. Expected {d}, got {d}.", .{ expected, got }, this, diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.cpp b/src/bun.js/bindings/webcore/JSDOMOperation.cpp new file mode 100644 index 0000000000000..0e824fe29b6a7 --- /dev/null +++ b/src/bun.js/bindings/webcore/JSDOMOperation.cpp @@ -0,0 +1,22 @@ +#include "root.h" + +#include "BunClientData.h" +#include "JSDOMOperation.h" +#include "BunBuiltinNames.h" + +#undef createNotEnoughArgumentsError + +namespace WebCore { + +JSC::JSObject* createNotEnoughArgumentsErrorBun(JSC::JSGlobalObject* globalObject) +{ + JSC::JSObject* error = JSC::createNotEnoughArgumentsError(globalObject); + if (LIKELY(error)) { + auto& vm = globalObject->vm(); + const auto& names = WebCore::builtinNames(vm); + error->putDirect(vm, names.codePublicName(), JSC::jsString(vm, WTF::String("ERR_MISSING_ARGS"_s)), 0); + } + + return error; +} +} \ No newline at end of file diff --git a/src/bun.js/bindings/webcore/JSDOMOperation.h b/src/bun.js/bindings/webcore/JSDOMOperation.h index c3f6d0451cddf..afae4b89865af 100644 --- a/src/bun.js/bindings/webcore/JSDOMOperation.h +++ b/src/bun.js/bindings/webcore/JSDOMOperation.h @@ -49,7 +49,7 @@ class IDLOperation { static JSC::EncodedJSValue call(JSC::JSGlobalObject& lexicalGlobalObject, JSC::CallFrame& callFrame, const char* operationName) { auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); - + auto* thisObject = cast(lexicalGlobalObject, callFrame); if constexpr (shouldThrow != CastedThisErrorBehavior::Assert) { if (UNLIKELY(!thisObject)) @@ -58,7 +58,7 @@ class IDLOperation { ASSERT(thisObject); ASSERT_GC_OBJECT_INHERITS(thisObject, JSClass::info()); - + // FIXME: We should refactor the binding generated code to use references for lexicalGlobalObject and thisObject. RELEASE_AND_RETURN(throwScope, (operation(&lexicalGlobalObject, &callFrame, thisObject))); } @@ -71,4 +71,12 @@ class IDLOperation { } }; +// Rewrite all usages of JSC::createNotEnoughArgumentsError to use our own version. +// Our version adds the "code" property from Node.js. +JSC::JSObject* createNotEnoughArgumentsErrorBun(JSGlobalObject* globalObject); + +#ifndef createNotEnoughArgumentsError +#define createNotEnoughArgumentsError WebCore::createNotEnoughArgumentsErrorBun +#endif + } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/JSDOMURL.cpp b/src/bun.js/bindings/webcore/JSDOMURL.cpp index 87994d289a1e0..ff0ecf8ae2736 100755 --- a/src/bun.js/bindings/webcore/JSDOMURL.cpp +++ b/src/bun.js/bindings/webcore/JSDOMURL.cpp @@ -18,19 +18,20 @@ Boston, MA 02110-1301, USA. */ -#include "root.h" +#include "config.h" #include "JSDOMURL.h" #include "ActiveDOMObject.h" #include "ExtendedDOMClientIsoSubspaces.h" #include "ExtendedDOMIsoSubspaces.h" #include "IDLTypes.h" -// #include "JSBlob.h" #include "JSDOMAttribute.h" #include "JSDOMBinding.h" #include "JSDOMConstructor.h" #include "JSDOMConvertBase.h" +#include "JSDOMConvertBoolean.h" #include "JSDOMConvertInterface.h" +#include "JSDOMConvertNullable.h" #include "JSDOMConvertStrings.h" #include "JSDOMExceptionHandling.h" #include "JSDOMGlobalObject.h" @@ -43,7 +44,7 @@ #include "WebCoreJSClientData.h" #include #include - +#include #include #include #include @@ -61,10 +62,11 @@ using namespace JSC; // Functions +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_parse); +static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toJSON); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL); -static JSC_DECLARE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse); static JSC_DECLARE_HOST_FUNCTION(jsDOMURLPrototypeFunction_toString); // Attributes @@ -130,48 +132,27 @@ using JSDOMURLDOMConstructor = JSDOMConstructor; /* Hash table for constructor */ static const HashTableValue JSDOMURLConstructorTableValues[] = { + { "parse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_parse, 1 } }, + { "canParse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_canParse, 1 } }, { "createObjectURL"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_createObjectURL, 1 } }, { "revokeObjectURL"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_revokeObjectURL, 1 } }, - { "canParse"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLConstructorFunction_canParse, 1 } }, }; -static inline JSC::EncodedJSValue constructJSDOMURL1(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) +template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) { - VM& vm = lexicalGlobalObject->vm(); + auto& vm = lexicalGlobalObject->vm(); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* castedThis = jsCast(callFrame->jsCallee()); ASSERT(castedThis); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); auto url = convert(*lexicalGlobalObject, argument0.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); EnsureStillAliveScope argument1 = callFrame->argument(1); auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - auto object = DOMURL::create(WTFMove(url), WTFMove(base)); - if constexpr (IsExceptionOr) - RETURN_IF_EXCEPTION(throwScope, {}); - static_assert(TypeOrExceptionOrUnderlyingType::isRef); - auto jsValue = toJSNewlyCreated>(*lexicalGlobalObject, *castedThis->globalObject(), throwScope, WTFMove(object)); - if constexpr (IsExceptionOr) - RETURN_IF_EXCEPTION(throwScope, {}); - setSubclassStructureIfNeeded(lexicalGlobalObject, callFrame, asObject(jsValue)); - RETURN_IF_EXCEPTION(throwScope, {}); - return JSValue::encode(jsValue); -} - -static inline JSC::EncodedJSValue constructJSDOMURL2(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - auto* castedThis = jsCast(callFrame->jsCallee()); - ASSERT(castedThis); - EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - auto url = convert(*lexicalGlobalObject, argument0.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1); - auto base = convert>(*lexicalGlobalObject, argument1.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 1, "base", "URL", nullptr, "DOMURL"); }); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - auto object = DOMURL::create(WTFMove(url), *base); + auto object = base.isEmpty() ? DOMURL::create(WTFMove(url)) : DOMURL::create(WTFMove(url), WTFMove(base)); if constexpr (IsExceptionOr) RETURN_IF_EXCEPTION(throwScope, {}); static_assert(TypeOrExceptionOrUnderlyingType::isRef); @@ -182,27 +163,7 @@ static inline JSC::EncodedJSValue constructJSDOMURL2(JSGlobalObject* lexicalGlob RETURN_IF_EXCEPTION(throwScope, {}); return JSValue::encode(jsValue); } - -template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::construct(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame) -{ - VM& vm = lexicalGlobalObject->vm(); - auto throwScope = DECLARE_THROW_SCOPE(vm); - UNUSED_PARAM(throwScope); - size_t argsCount = std::min(2, callFrame->argumentCount()); - if (argsCount == 1) { - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - } - if (argsCount == 2) { - JSValue distinguishingArg = callFrame->uncheckedArgument(1); - if (distinguishingArg.isUndefined()) - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL2(lexicalGlobalObject, callFrame))); - RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); - } - return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); -} -JSC_ANNOTATE_HOST_FUNCTION(JSDOMURLConstructorConstruct, JSDOMURLDOMConstructor::construct); +JSC_ANNOTATE_HOST_FUNCTION(JSDOMURLDOMConstructorConstruct, JSDOMURLDOMConstructor::construct); template<> const ClassInfo JSDOMURLDOMConstructor::s_info = { "URL"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMURLDOMConstructor) }; @@ -220,24 +181,36 @@ template<> void JSDOMURLDOMConstructor::initializeProperties(VM& vm, JSDOMGlobal putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); putDirect(vm, vm.propertyNames->prototype, JSDOMURL::prototype(vm, globalObject), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); reifyStaticProperties(vm, JSDOMURL::info(), JSDOMURLConstructorTableValues, *this); + // if (!((&globalObject)->inherits() || (&globalObject)->inherits() || (&globalObject)->inherits())) { + // auto propertyName = Identifier::fromString(vm, "createObjectURL"_s); + // VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); + // DeletePropertySlot slot; + // JSObject::deleteProperty(this, &globalObject, propertyName, slot); + // } + // if (!((&globalObject)->inherits() || (&globalObject)->inherits() || (&globalObject)->inherits())) { + // auto propertyName = Identifier::fromString(vm, "revokeObjectURL"_s); + // VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); + // DeletePropertySlot slot; + // JSObject::deleteProperty(this, &globalObject, propertyName, slot); + // } } /* Hash table for prototype */ static const HashTableValue JSDOMURLPrototypeTableValues[] = { - { "constructor"_s, static_cast(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURLConstructor, 0 } }, - { "href"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_href, setJSDOMURL_href } }, - { "origin"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_origin, 0 } }, - { "protocol"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_protocol, setJSDOMURL_protocol } }, - { "username"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_username, setJSDOMURL_username } }, - { "password"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_password, setJSDOMURL_password } }, - { "host"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_host, setJSDOMURL_host } }, - { "hostname"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hostname, setJSDOMURL_hostname } }, - { "port"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_port, setJSDOMURL_port } }, - { "pathname"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_pathname, setJSDOMURL_pathname } }, - { "hash"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hash, setJSDOMURL_hash } }, - { "search"_s, static_cast(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_search, setJSDOMURL_search } }, - { "searchParams"_s, static_cast(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_searchParams, 0 } }, + { "constructor"_s, static_cast(PropertyAttribute::DontEnum), NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURLConstructor, 0 } }, + { "href"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_href, setJSDOMURL_href } }, + { "origin"_s, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_origin, 0 } }, + { "protocol"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_protocol, setJSDOMURL_protocol } }, + { "username"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_username, setJSDOMURL_username } }, + { "password"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_password, setJSDOMURL_password } }, + { "host"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_host, setJSDOMURL_host } }, + { "hostname"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hostname, setJSDOMURL_hostname } }, + { "port"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_port, setJSDOMURL_port } }, + { "pathname"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_pathname, setJSDOMURL_pathname } }, + { "hash"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_hash, setJSDOMURL_hash } }, + { "search"_s, JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_search, setJSDOMURL_search } }, + { "searchParams"_s, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute, NoIntrinsic, { HashTableValue::GetterSetterType, jsDOMURL_searchParams, 0 } }, { "toJSON"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLPrototypeFunction_toJSON, 0 } }, { "toString"_s, static_cast(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsDOMURLPrototypeFunction_toString, 0 } }, }; @@ -258,13 +231,7 @@ JSDOMURL::JSDOMURL(Structure* structure, JSDOMGlobalObject& globalObject, Ref::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); -} +// static_assert(!std::is_base_of::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject."); JSObject* JSDOMURL::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) { @@ -289,14 +256,14 @@ void JSDOMURL::destroy(JSC::JSCell* cell) thisObject->JSDOMURL::~JSDOMURL(); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName)) { - VM& vm = JSC::getVM(lexicalGlobalObject); + auto& vm = JSC::getVM(lexicalGlobalObject); auto throwScope = DECLARE_THROW_SCOPE(vm); auto* prototype = jsDynamicCast(JSValue::decode(thisValue)); if (UNLIKELY(!prototype)) return throwVMTypeError(lexicalGlobalObject, throwScope); - return JSValue::encode(JSDOMURL::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); + return JSValue::encode(JSDOMURL::getConstructor(vm, prototype->globalObject())); } static inline JSValue jsDOMURL_hrefGetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject) @@ -307,7 +274,7 @@ static inline JSValue jsDOMURL_hrefGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.href()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -315,6 +282,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_href, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hrefSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -325,7 +293,7 @@ static inline bool setJSDOMURL_hrefSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_href, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_href, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -338,7 +306,7 @@ static inline JSValue jsDOMURL_originGetter(JSGlobalObject& lexicalGlobalObject, RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.origin()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_origin, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_origin, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -351,7 +319,7 @@ static inline JSValue jsDOMURL_protocolGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.protocol()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -359,6 +327,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_protocol, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_protocolSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -369,7 +338,7 @@ static inline bool setJSDOMURL_protocolSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_protocol, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -382,7 +351,7 @@ static inline JSValue jsDOMURL_usernameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.username()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -390,6 +359,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_username, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_usernameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -400,7 +370,7 @@ static inline bool setJSDOMURL_usernameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_username, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_username, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -413,7 +383,7 @@ static inline JSValue jsDOMURL_passwordGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.password()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -421,6 +391,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_password, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_passwordSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -431,7 +402,7 @@ static inline bool setJSDOMURL_passwordSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_password, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_password, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -444,7 +415,7 @@ static inline JSValue jsDOMURL_hostGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.host()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -452,6 +423,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_host, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hostSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -462,7 +434,7 @@ static inline bool setJSDOMURL_hostSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_host, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_host, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -475,7 +447,7 @@ static inline JSValue jsDOMURL_hostnameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hostname()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -483,6 +455,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hostname, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_hostnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -493,7 +466,7 @@ static inline bool setJSDOMURL_hostnameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hostname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -506,7 +479,7 @@ static inline JSValue jsDOMURL_portGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.port()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -514,6 +487,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_port, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_portSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -524,7 +498,7 @@ static inline bool setJSDOMURL_portSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_port, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_port, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -537,7 +511,7 @@ static inline JSValue jsDOMURL_pathnameGetter(JSGlobalObject& lexicalGlobalObjec RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.pathname()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -545,6 +519,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_pathname, (JSGlobalObject * lexicalGlobalObjec static inline bool setJSDOMURL_pathnameSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -555,7 +530,7 @@ static inline bool setJSDOMURL_pathnameSetter(JSGlobalObject& lexicalGlobalObjec return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_pathname, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -568,7 +543,7 @@ static inline JSValue jsDOMURL_hashGetter(JSGlobalObject& lexicalGlobalObject, J RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.hash()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -576,6 +551,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, J static inline bool setJSDOMURL_hashSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -586,7 +562,7 @@ static inline bool setJSDOMURL_hashSetter(JSGlobalObject& lexicalGlobalObject, J return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_hash, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -599,7 +575,7 @@ static inline JSValue jsDOMURL_searchGetter(JSGlobalObject& lexicalGlobalObject, RELEASE_AND_RETURN(throwScope, (toJS(lexicalGlobalObject, throwScope, impl.search()))); } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } @@ -607,6 +583,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_search, (JSGlobalObject * lexicalGlobalObject, static inline bool setJSDOMURL_searchSetter(JSGlobalObject& lexicalGlobalObject, JSDOMURL& thisObject, JSValue value) { auto& vm = JSC::getVM(&lexicalGlobalObject); + UNUSED_PARAM(vm); auto throwScope = DECLARE_THROW_SCOPE(vm); auto& impl = thisObject.wrapped(); auto nativeValue = convert(lexicalGlobalObject, value); @@ -617,7 +594,7 @@ static inline bool setJSDOMURL_searchSetter(JSGlobalObject& lexicalGlobalObject, return true; } -JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_search, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_SETTER(setJSDOMURL_search, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName)) { return IDLAttribute::set(*lexicalGlobalObject, thisValue, encodedValue, attributeName); } @@ -635,11 +612,55 @@ static inline JSValue jsDOMURL_searchParamsGetter(JSGlobalObject& lexicalGlobalO return result; } -JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_searchParams, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName attributeName)) +JSC_DEFINE_CUSTOM_GETTER(jsDOMURL_searchParams, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { return IDLAttribute::get(*lexicalGlobalObject, thisValue, attributeName); } +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_parseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS>>(*lexicalGlobalObject, *jsCast(lexicalGlobalObject), throwScope, DOMURL::parse(WTFMove(url), WTFMove(base))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_parse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "parse"); +} + +static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_canParseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); + UNUSED_PARAM(callFrame); + if (UNLIKELY(callFrame->argumentCount() < 1)) + return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); + EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); + auto url = convert(*lexicalGlobalObject, argument0.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + EnsureStillAliveScope argument1 = callFrame->argument(1); + auto base = argument1.value().isUndefined() ? String() : convert(*lexicalGlobalObject, argument1.value()); + RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, DOMURL::canParse(WTFMove(url), WTFMove(base))))); +} + +JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "canParse"); +} + static inline JSC::EncodedJSValue jsDOMURLPrototypeFunction_toJSONBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation::ClassParameter castedThis) { auto& vm = JSC::getVM(lexicalGlobalObject); @@ -659,8 +680,8 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL1Bo { // auto& vm = JSC::getVM(lexicalGlobalObject); // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); + UNUSED_PARAM(lexicalGlobalObject); + UNUSED_PARAM(callFrame); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); // if (UNLIKELY(!context)) return JSValue::encode(jsUndefined()); @@ -674,8 +695,8 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_revokeObjectURLBod { // auto& vm = JSC::getVM(lexicalGlobalObject); // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); + UNUSED_PARAM(lexicalGlobalObject); + UNUSED_PARAM(callFrame); // if (UNLIKELY(callFrame->argumentCount() < 1)) // return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); @@ -692,70 +713,31 @@ JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_revokeObjectURL, (JSGlobalO return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "revokeObjectURL"); } -static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_canParseBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) +void JSDOMURL::finishCreation(JSC::VM& vm) { - auto& vm = JSC::getVM(lexicalGlobalObject); - auto throwScope = DECLARE_THROW_SCOPE(vm); - - if (UNLIKELY(callFrame->argumentCount() < 1)) - return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)); - - EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - auto url = convert(*lexicalGlobalObject, argument0.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - - EnsureStillAliveScope argument1 = callFrame->argument(1); - String base; - if (!argument1.value().isUndefinedOrNull()) { - base = convert(*lexicalGlobalObject, argument1.value()); - RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - } - - return JSValue::encode(jsBoolean(DOMURL::canParse(url, base))); -} - -JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_canParse, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) -{ - return IDLOperation::callStatic(*lexicalGlobalObject, *callFrame, "canParse"); -} - -#if ENABLE(MEDIA_SOURCE) -static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURL2Body(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) -{ - // auto& vm = JSC::getVM(lexicalGlobalObject); - // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); - // UNUSED_PARAM(callFrame); - // auto* context = jsCast(lexicalGlobalObject)->scriptExecutionContext(); - // if (UNLIKELY(!context)) - return JSValue::encode(jsUndefined()); - // EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - // auto source = convert>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "source", "URL", "createObjectURL", "MediaSource"); }); - // RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); - // RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, WebCore::DOMURLMediaSource::createObjectURL(*context, *source)))); + Base::finishCreation(vm); + ASSERT(inherits(info())); } -#endif - static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURLOverloadDispatcher(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame) { - return JSValue::encode(jsUndefined()); - - // auto& vm = JSC::getVM(lexicalGlobalObject); - // auto throwScope = DECLARE_THROW_SCOPE(vm); - // UNUSED_PARAM(throwScope); + auto& vm = JSC::getVM(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + UNUSED_PARAM(throwScope); UNUSED_PARAM(callFrame); - // size_t argsCount = std::min(1, callFrame->argumentCount()); - // if (argsCount == 1) { - // JSValue distinguishingArg = callFrame->uncheckedArgument(0); - // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame))); - // #if ENABLE(MEDIA_SOURCE) - // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) - // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame))); - // #endif - // } - // return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); + size_t argsCount = std::min(1, callFrame->argumentCount()); + if (argsCount == 1) { + JSValue distinguishingArg = callFrame->uncheckedArgument(0); + if (distinguishingArg.isObject()) { + return JSValue::encode(jsUndefined()); + } + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame))); + // #if ENABLE(MEDIA_SOURCE) + // if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits()) + // RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame))); + } + return argsCount < 1 ? throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject)) : throwVMTypeError(lexicalGlobalObject, throwScope); } JSC_DEFINE_HOST_FUNCTION(jsDOMURLConstructorFunction_createObjectURL, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) @@ -803,8 +785,8 @@ void JSDOMURL::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer) { auto* thisObject = jsCast(cell); analyzer.setWrappedObjectForCell(cell, &thisObject->wrapped()); - // if (thisObject->scriptExecutionContext()) - // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); + if (thisObject->scriptExecutionContext()) + analyzer.setLabelForCell(cell, "url "_s + thisObject->scriptExecutionContext()->url().string()); Base::analyzeHeap(cell, analyzer); } @@ -867,11 +849,10 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g return wrap(lexicalGlobalObject, globalObject, impl); } -DOMURL* JSDOMURL::toWrapped(JSC::VM& vm, JSC::JSValue value) +DOMURL* JSDOMURL::toWrapped(JSC::VM&, JSC::JSValue value) { if (auto* wrapper = jsDynamicCast(value)) return &wrapper->wrapped(); return nullptr; } - } diff --git a/test/js/node/url/url.test.ts b/test/js/node/url/url.test.ts index f01484136dd76..004fb499914e8 100644 --- a/test/js/node/url/url.test.ts +++ b/test/js/node/url/url.test.ts @@ -66,3 +66,16 @@ describe("Url.prototype.parse", () => { }); }); }); + +it("URL constructor throws ERR_MISSING_ARGS", () => { + var err; + try { + // @ts-expect-error + new URL(); + } catch (e) { + err = e; + } + + // @ts-expect-error + expect(err?.code).toEqual("ERR_MISSING_ARGS"); +}); From 459bcdc5ac6b1b588a5ea2370614a1d02541f16b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 10 Apr 2024 05:09:14 -0700 Subject: [PATCH 10/13] Concurrent uninstalls (#10111) * Concurrent uninstalls * Try disabling concurrency * Get `rm` tests to pass on Windows * Fix more things * Undisable concurrency * handle error * Deflake * [autofix.ci] apply automated fixes * Undo --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../bun-internal-test/src/runner.node.mjs | 6 +- src/bun.js/bindings/c-bindings.cpp | 4 + src/bun.js/module_loader.zig | 2 +- src/bun.js/node/types.zig | 4 +- src/install/extract_tarball.zig | 2 +- src/install/install.zig | 121 +++++++++++++++--- src/output.zig | 16 ++- src/shell/interpreter.zig | 67 ++-------- src/sys.zig | 52 +++++--- src/windows.zig | 114 ++++++++++++++++- src/windows_c.zig | 9 +- .../registry/bun-install-registry.test.ts | 6 +- 12 files changed, 286 insertions(+), 117 deletions(-) diff --git a/packages/bun-internal-test/src/runner.node.mjs b/packages/bun-internal-test/src/runner.node.mjs index 3530f60a889c9..194771eec05e3 100644 --- a/packages/bun-internal-test/src/runner.node.mjs +++ b/packages/bun-internal-test/src/runner.node.mjs @@ -361,9 +361,9 @@ Starting "${name}" } console.log( - `\x1b[2m${formatTime(duration).padStart(6, " ")}\x1b[0m ${ - passed ? "\x1b[32m✔" : "\x1b[31m✖" - } ${name}\x1b[0m${reason ? ` (${reason})` : ""}`, + `\x1b[2m${formatTime(duration).padStart(6, " ")}\x1b[0m ${passed ? "\x1b[32m✔" : "\x1b[31m✖"} ${name}\x1b[0m${ + reason ? ` (${reason})` : "" + }`, ); finished++; diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index 72799419a6f30..db4ad1e467ec2 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -423,6 +423,8 @@ extern "C" void Bun__setCTRLHandler(BOOL add) } #endif +extern "C" int32_t bun_is_stdio_null[3] = { 0, 0, 0 }; + extern "C" void bun_initialize_process() { // Disable printf() buffering. We buffer it ourselves. @@ -443,6 +445,7 @@ extern "C" void bun_initialize_process() bool anyTTYs = false; const auto setDevNullFd = [&](int target_fd) -> void { + bun_is_stdio_null[target_fd] = 1; if (devNullFd_ == -1) { do { devNullFd_ = open("/dev/null", O_RDWR | O_CLOEXEC, 0); @@ -510,6 +513,7 @@ extern "C" void bun_initialize_process() // Ignore _close result. If it fails or not depends on used Windows // version. We will just check _open result. _close(fd); + bun_is_stdio_null[fd] = 1; if (fd != _open("nul", O_RDWR)) { RELEASE_ASSERT_NOT_REACHED(); } else { diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 4552d46f27a5b..78ba52108a5c2 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -948,7 +948,7 @@ pub const ModuleLoader = struct { pub fn pollModules(this: *Queue) void { var pm = this.vm().packageManager(); - if (pm.pending_tasks > 0) return; + if (pm.pending_tasks.load(.Monotonic) > 0) return; var modules: []AsyncModule = this.map.items; var i: usize = 0; diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 4dd667ed9e73f..8752a92a966c3 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -220,7 +220,9 @@ pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type { pub inline fn errnoSys(rc: anytype, syscall: Syscall.Tag) ?@This() { if (comptime Environment.isWindows) { - if (rc != 0) return null; + if (comptime @TypeOf(rc) == std.os.windows.NTSTATUS) {} else { + if (rc != 0) return null; + } } return switch (Syscall.getErrno(rc)) { .SUCCESS => null, diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig index 796381d6c5141..6c06083fbe711 100644 --- a/src/install/extract_tarball.zig +++ b/src/install/extract_tarball.zig @@ -326,7 +326,7 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !Install.ExtractD .err => |err| { if (!did_retry) { switch (err.getErrno()) { - .PERM, .BUSY, .EXIST => { + .NOTEMPTY, .PERM, .BUSY, .EXIST => { // before we attempt to delete the destination, let's close the source dir. _ = bun.sys.close(dir_to_move); diff --git a/src/install/install.zig b/src/install/install.zig index a5a957b6706e2..3c91ed7748379 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -886,6 +886,7 @@ pub const PackageInstall = struct { package_name: string, package_version: string, file_count: u32 = 0, + node_modules: *const NodeModulesFolder, const debug = Output.scoped(.install, true); @@ -1913,7 +1914,80 @@ pub const PackageInstall = struct { // if it fails, that means the directory doesn't exist or was inaccessible }, .result => { - this.destination_dir.deleteTree(temp_path) catch {}; + // Uninstall can sometimes take awhile in a large directory + // tree. Since we're renaming the directory to a randomly + // generated name, we can delete it in another thread without + // worrying about race conditions or blocking the main thread. + // + // This should be a slight improvement to CI environments. + // + // on macOS ARM64 in a project with Gatsby, @mui/icons-material, and Next.js: + // + // ❯ hyperfine "bun install --ignore-scripts" "bun-1.1.2 install --ignore-scripts" --prepare="rm -rf node_modules/**/package.json" --warmup=2 + // Benchmark 1: bun install --ignore-scripts + // Time (mean ± σ): 2.281 s ± 0.027 s [User: 0.041 s, System: 6.851 s] + // Range (min … max): 2.231 s … 2.312 s 10 runs + // + // Benchmark 2: bun-1.1.2 install --ignore-scripts + // Time (mean ± σ): 3.315 s ± 0.033 s [User: 0.029 s, System: 2.237 s] + // Range (min … max): 3.279 s … 3.356 s 10 runs + // + // Summary + // bun install --ignore-scripts ran + // 1.45 ± 0.02 times faster than bun-1.1.2 install --ignore-scripts + // + + const UninstallTask = struct { + absolute_path: []const u8, + task: JSC.WorkPoolTask = .{ .callback = &run }, + pub fn run(task: *JSC.WorkPoolTask) void { + var unintall_task = @fieldParentPtr(@This(), "task", task); + var debug_timer = bun.Output.DebugTimer.start(); + defer { + _ = PackageManager.instance.pending_tasks.fetchSub(1, .Monotonic); + PackageManager.instance.wake(); + } + + defer unintall_task.deinit(); + const dirname = std.fs.path.dirname(unintall_task.absolute_path) orelse { + Output.debugWarn("Unexpectedly failed to get dirname of {s}", .{unintall_task.absolute_path}); + return; + }; + const basename = std.fs.path.basename(unintall_task.absolute_path); + + var dir = bun.openDirA(std.fs.cwd(), dirname) catch |err| { + if (comptime Environment.isDebug) { + Output.debugWarn("Failed to delete {s}: {s}", .{ unintall_task.absolute_path, @errorName(err) }); + } + return; + }; + defer _ = bun.sys.close(bun.toFD(dir.fd)); + + dir.deleteTree(basename) catch |err| { + if (comptime Environment.isDebug) { + Output.debugWarn("Failed to delete {s} in {s}: {s}", .{ basename, dirname, @errorName(err) }); + } + }; + + if (Environment.isDebug) { + _ = &debug_timer; + debug("deleteTree({s}, {s}) = {}", .{ basename, dirname, debug_timer }); + } + } + + pub fn deinit(uninstall_task: *@This()) void { + bun.default_allocator.free(uninstall_task.absolute_path); + uninstall_task.destroy(); + } + + pub usingnamespace bun.New(@This()); + }; + var task = UninstallTask.new(.{ + .absolute_path = bun.default_allocator.dupeZ(u8, bun.path.joinAbsString(FileSystem.instance.top_level_dir, &.{ this.node_modules.path.items, temp_path }, .auto)) catch bun.outOfMemory(), + }); + PackageManager.instance.thread_pool.schedule(bun.ThreadPool.Batch.from(&task.task)); + _ = PackageManager.instance.pending_tasks.fetchAdd(1, .Monotonic); + PackageManager.instance.total_tasks += 1; }, } } @@ -2334,7 +2408,7 @@ pub const PackageManager = struct { network_tarball_batch: ThreadPool.Batch = .{}, network_resolve_batch: ThreadPool.Batch = .{}, network_task_fifo: NetworkQueue = undefined, - pending_tasks: u32 = 0, + pending_tasks: std.atomic.Value(u32) = std.atomic.Value(u32).init(0), total_tasks: u32 = 0, preallocated_network_tasks: PreallocatedNetworkTasks = PreallocatedNetworkTasks.init(bun.default_allocator), preallocated_resolve_tasks: PreallocatedTaskStore = PreallocatedTaskStore.init(bun.default_allocator), @@ -2651,7 +2725,7 @@ pub const PackageManager = struct { manager: *PackageManager, pub fn isDone(closure: *@This()) bool { var manager = closure.manager; - if (manager.pending_tasks > 0) { + if (manager.pendingTaskCount() > 0) { manager.runTasks( void, {}, @@ -2668,12 +2742,12 @@ pub const PackageManager = struct { return true; }; - if (PackageManager.verbose_install and manager.pending_tasks > 0) { - if (PackageManager.hasEnoughTimePassedBetweenWaitingMessages()) Output.prettyErrorln("[PackageManager] waiting for {d} tasks\n", .{PackageManager.instance.pending_tasks}); + if (PackageManager.verbose_install and manager.pendingTaskCount() > 0) { + if (PackageManager.hasEnoughTimePassedBetweenWaitingMessages()) Output.prettyErrorln("[PackageManager] waiting for {d} tasks\n", .{PackageManager.instance.pendingTaskCount()}); } } - return manager.pending_tasks == 0; + return manager.pendingTaskCount() == 0; } }; } @@ -4728,7 +4802,7 @@ pub const PackageManager = struct { pub fn scheduleTasks(manager: *PackageManager) usize { const count = manager.task_batch.len + manager.network_resolve_batch.len + manager.network_tarball_batch.len; - manager.pending_tasks += @as(u32, @truncate(count)); + _ = manager.pending_tasks.fetchAdd(@truncate(count), .Monotonic); manager.total_tasks += @as(u32, @truncate(count)); manager.thread_pool.schedule(manager.task_batch); manager.network_resolve_batch.push(manager.network_tarball_batch); @@ -5124,8 +5198,8 @@ pub const PackageManager = struct { var network_tasks_batch = manager.async_network_task_queue.popBatch(); var network_tasks_iter = network_tasks_batch.iterator(); while (network_tasks_iter.next()) |task| { - if (comptime Environment.allow_assert) std.debug.assert(manager.pending_tasks > 0); - manager.pending_tasks -|= 1; + if (comptime Environment.allow_assert) std.debug.assert(manager.pendingTaskCount() > 0); + _ = manager.pending_tasks.fetchSub(1, .Monotonic); // We cannot free the network task at the end of this scope. // It may continue to be referenced in a future task. @@ -5449,9 +5523,9 @@ pub const PackageManager = struct { var resolve_tasks_batch = manager.resolve_tasks.popBatch(); var resolve_tasks_iter = resolve_tasks_batch.iterator(); while (resolve_tasks_iter.next()) |task| { - if (comptime Environment.allow_assert) std.debug.assert(manager.pending_tasks > 0); + if (comptime Environment.allow_assert) std.debug.assert(manager.pendingTaskCount() > 0); defer manager.preallocated_resolve_tasks.put(task); - manager.pending_tasks -|= 1; + _ = manager.pending_tasks.fetchSub(1, .Monotonic); if (task.log.msgs.items.len > 0) { switch (Output.enable_ansi_colors) { @@ -5762,7 +5836,7 @@ pub const PackageManager = struct { if (comptime log_level.showProgress()) { if (@hasField(@TypeOf(callbacks), "progress_bar") and callbacks.progress_bar == true) { - const completed_items = manager.total_tasks - manager.pending_tasks; + const completed_items = manager.total_tasks - manager.pendingTaskCount(); if (completed_items != manager.downloads_node.?.unprotected_completed_items or has_updated_this_run) { manager.downloads_node.?.setCompletedItems(completed_items); manager.downloads_node.?.setEstimatedTotalItems(manager.total_tasks); @@ -8989,6 +9063,7 @@ pub const PackageManager = struct { .allocator = this.lockfile.allocator, .package_name = name, .package_version = resolution_label, + .node_modules = &this.node_modules, // .install_order = this.tree_iterator.order, }; debug("Installing {s}@{s}", .{ name, resolution_label }); @@ -9888,7 +9963,7 @@ pub const PackageManager = struct { // We want to minimize how often we call this function // That's part of why we unroll this loop - if (this.pending_tasks > 0) { + if (this.pendingTaskCount() > 0) { try this.runTasks( *PackageInstaller, &installer, @@ -9928,7 +10003,7 @@ pub const PackageManager = struct { this.tickLifecycleScripts(); } - while (this.pending_tasks > 0 and installer.options.do.install_packages) { + while (this.pendingTaskCount() > 0 and installer.options.do.install_packages) { const Closure = struct { installer: *PackageInstaller, err: ?anyerror = null, @@ -9954,11 +10029,11 @@ pub const PackageManager = struct { return true; } - if (PackageManager.verbose_install and PackageManager.instance.pending_tasks > 0) { - if (PackageManager.hasEnoughTimePassedBetweenWaitingMessages()) Output.prettyErrorln("[PackageManager] waiting for {d} tasks\n", .{PackageManager.instance.pending_tasks}); + if (PackageManager.verbose_install and PackageManager.instance.pendingTaskCount() > 0) { + if (PackageManager.hasEnoughTimePassedBetweenWaitingMessages()) Output.prettyErrorln("[PackageManager] waiting for {d} tasks\n", .{PackageManager.instance.pendingTaskCount()}); } - return closure.manager.pending_tasks == 0 and closure.manager.hasNoMorePendingLifecycleScripts(); + return closure.manager.pendingTaskCount() == 0 and closure.manager.hasNoMorePendingLifecycleScripts(); } }; @@ -10006,6 +10081,10 @@ pub const PackageManager = struct { return summary; } + pub inline fn pendingTaskCount(manager: *const PackageManager) u32 { + return manager.pending_tasks.load(.Monotonic); + } + pub fn setupGlobalDir(manager: *PackageManager, ctx: *const Command.Context) !void { manager.options.global_bin_dir = try Options.openGlobalBinDir(ctx.install); var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; @@ -10025,7 +10104,7 @@ pub const PackageManager = struct { manager.progress.supports_ansi_escape_codes = Output.enable_ansi_colors_stderr; manager.setNodeName(manager.downloads_node.?, ProgressStrings.download_no_emoji_, ProgressStrings.download_emoji, true); manager.downloads_node.?.setEstimatedTotalItems(manager.total_tasks + manager.extracted_count); - manager.downloads_node.?.setCompletedItems(manager.total_tasks - manager.pending_tasks); + manager.downloads_node.?.setCompletedItems(manager.total_tasks - manager.pendingTaskCount()); manager.downloads_node.?.activate(); manager.progress.refresh(); } @@ -10345,7 +10424,7 @@ pub const PackageManager = struct { manager.drainDependencyList(); } - if (manager.pending_tasks > 0 or manager.peer_dependencies.readableLength() > 0) { + if (manager.pendingTaskCount() > 0 or manager.peer_dependencies.readableLength() > 0) { if (root.dependencies.len > 0) { _ = manager.getCacheDirectory(); _ = manager.getTemporaryDirectory(); @@ -10396,7 +10475,7 @@ pub const PackageManager = struct { } } - const pending_tasks = this.pending_tasks; + const pending_tasks = this.pendingTaskCount(); if (PackageManager.verbose_install and pending_tasks > 0) { if (PackageManager.hasEnoughTimePassedBetweenWaitingMessages()) Output.prettyErrorln("[PackageManager] waiting for {d} tasks\n", .{pending_tasks}); @@ -10423,7 +10502,7 @@ pub const PackageManager = struct { const waitForEverythingExceptPeers = runAndWaitFn(false); const waitForPeers = runAndWaitFn(true); - if (manager.pending_tasks > 0) { + if (manager.pendingTaskCount() > 0) { try waitForEverythingExceptPeers(manager); } diff --git a/src/output.zig b/src/output.zig index 0949df1ac8427..aeb45dd61e8ca 100644 --- a/src/output.zig +++ b/src/output.zig @@ -214,6 +214,20 @@ pub const Source = struct { }; pub const Stdio = struct { + extern "C" var bun_is_stdio_null: [3]i32; + + pub fn isStderrNull() bool { + return bun_is_stdio_null[2] == 1; + } + + pub fn isStdoutNull() bool { + return bun_is_stdio_null[1] == 1; + } + + pub fn isStdinNull() bool { + return bun_is_stdio_null[0] == 1; + } + pub fn init() void { bun.C.bun_initialize_process(); @@ -812,7 +826,7 @@ pub noinline fn printError(comptime fmt: string, args: anytype) void { pub const DebugTimer = struct { timer: bun.DebugOnly(std.time.Timer) = undefined, - pub fn start() DebugTimer { + pub inline fn start() DebugTimer { if (comptime Environment.isDebug) { return DebugTimer{ .timer = std.time.Timer.start() catch unreachable, diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 1e894fd1edfe2..ebc73ddf530e4 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -1143,7 +1143,7 @@ pub const Interpreter = struct { } log("Duping stdin", .{}); - const stdin_fd = switch (ShellSyscall.dup(shell.STDIN_FD)) { + const stdin_fd = switch (if (bun.Output.Source.Stdio.isStdinNull()) bun.sys.openNullDevice() else ShellSyscall.dup(shell.STDIN_FD)) { .result => |fd| fd, .err => |err| return .{ .err = .{ .sys = err.toSystemError() } }, }; @@ -1329,13 +1329,13 @@ pub const Interpreter = struct { const event_loop = this.event_loop; log("Duping stdout", .{}); - const stdout_fd = switch (ShellSyscall.dup(shell.STDOUT_FD)) { + const stdout_fd = switch (if (bun.Output.Source.Stdio.isStdoutNull()) bun.sys.openNullDevice() else ShellSyscall.dup(bun.STDOUT_FD)) { .result => |fd| fd, .err => |err| return .{ .err = err }, }; log("Duping stderr", .{}); - const stderr_fd = switch (ShellSyscall.dup(shell.STDERR_FD)) { + const stderr_fd = switch (if (bun.Output.Source.Stdio.isStderrNull()) bun.sys.openNullDevice() else ShellSyscall.dup(bun.STDERR_FD)) { .result => |fd| fd, .err => |err| return .{ .err = err }, }; @@ -9218,8 +9218,8 @@ pub const Interpreter = struct { JSC.WorkPool.schedule(&subtask.task); } - pub fn getcwd(this: *ShellRmTask) if (bun.Environment.isWindows) CwdPath else bun.FileDescriptor { - return if (bun.Environment.isWindows) this.cwd_path.? else bun.toFD(this.cwd); + pub fn getcwd(this: *ShellRmTask) bun.FileDescriptor { + return this.cwd; } pub fn verboseDeleted(this: *@This(), dir_task: *DirTask, path: [:0]const u8) Maybe(void) { @@ -9554,8 +9554,7 @@ pub const Interpreter = struct { } }; const dirfd = bun.toFD(this.cwd); - _ = dirfd; // autofix - switch (ShellSyscall.unlinkatWithFlags(this.getcwd(), path, 0)) { + switch (ShellSyscall.unlinkatWithFlags(dirfd, path, 0)) { .result => return this.verboseDeleted(parent_dir_task, path), .err => |e| { print("unlinkatWithFlags({s}) = {s}", .{ path, @tagName(e.getErrno()) }); @@ -11180,6 +11179,8 @@ pub const IOWriterChildPtr = struct { /// - Sometimes windows doesn't have `*at()` functions like `rmdirat` so we have to join the directory path with the target path /// - Converts Posix absolute paths to Windows absolute paths on Windows const ShellSyscall = struct { + pub const unlinkatWithFlags = Syscall.unlinkatWithFlags; + pub const rmdirat = Syscall.rmdirat; fn getPath(dirfd: anytype, to: [:0]const u8, buf: *[bun.MAX_PATH_BYTES]u8) Maybe([:0]const u8) { if (bun.Environment.isPosix) @compileError("Don't use this"); if (bun.strings.eqlComptime(to[0..to.len], "/dev/null")) { @@ -11293,58 +11294,6 @@ const ShellSyscall = struct { } return Syscall.dup(fd); } - - pub fn unlinkatWithFlags(dirfd: anytype, to: [:0]const u8, flags: c_uint) Maybe(void) { - if (bun.Environment.isWindows) { - if (flags & std.os.AT.REMOVEDIR != 0) return ShellSyscall.rmdirat(dirfd, to); - - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; - const path = brk: { - switch (ShellSyscall.getPath(dirfd, to, &buf)) { - .err => |e| return .{ .err = e }, - .result => |p| break :brk p, - } - }; - - return switch (Syscall.unlink(path)) { - .result => return Maybe(void).success, - .err => |e| { - log("unlinkatWithFlags({s}) = {s}", .{ path, @tagName(e.getErrno()) }); - return .{ .err = e.withPath(bun.default_allocator.dupe(u8, path) catch bun.outOfMemory()) }; - }, - }; - } - if (@TypeOf(dirfd) != bun.FileDescriptor) { - @compileError("Bad type: " ++ @typeName(@TypeOf(dirfd))); - } - return Syscall.unlinkatWithFlags(dirfd, to, flags); - } - - pub fn rmdirat(dirfd: anytype, to: [:0]const u8) Maybe(void) { - if (bun.Environment.isWindows) { - var buf: [bun.MAX_PATH_BYTES]u8 = undefined; - const path: []const u8 = brk: { - switch (getPath(dirfd, to, &buf)) { - .result => |p| break :brk p, - .err => |e| return .{ .err = e }, - } - }; - var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined; - const wpath = bun.strings.toWPath(&wide_buf, path); - while (true) { - if (windows.RemoveDirectoryW(wpath) == 0) { - const errno = Syscall.getErrno(420); - if (errno == .INTR) continue; - log("rmdirat({s}) = {d}: {s}", .{ path, @intFromEnum(errno), @tagName(errno) }); - return .{ .err = Syscall.Error.fromCode(errno, .rmdir) }; - } - log("rmdirat({s}) = {d}", .{ path, 0 }); - return Maybe(void).success; - } - } - - return Syscall.rmdirat(dirfd, to); - } }; /// A task that can write to stdout and/or stderr diff --git a/src/sys.zig b/src/sys.zig index 1f9ed5019953e..b04c31e5a36cd 100644 --- a/src/sys.zig +++ b/src/sys.zig @@ -593,6 +593,10 @@ pub fn fcntl(fd: bun.FileDescriptor, cmd: i32, arg: usize) Maybe(usize) { pub fn getErrno(rc: anytype) bun.C.E { if (comptime Environment.isWindows) { + if (comptime @TypeOf(rc) == bun.windows.NTSTATUS) { + return bun.windows.translateNTStatusToErrno(rc); + } + if (bun.windows.Win32Error.get().toSystemErrno()) |e| { return e.toE(); } @@ -815,14 +819,14 @@ pub fn openFileAtWindowsNtPath( disposition: w.ULONG, options: w.ULONG, ) Maybe(bun.FileDescriptor) { - var result: windows.HANDLE = undefined; - // Another problem re: normalization is that you can use relative paths, but no leading '.\' or './'' // this path is probably already backslash normalized so we're only going to check for '.\' // const path = if (bun.strings.hasPrefixComptimeUTF16(path_maybe_leading_dot, ".\\")) path_maybe_leading_dot[2..] else path_maybe_leading_dot; // std.debug.assert(!bun.strings.hasPrefixComptimeUTF16(path_maybe_leading_dot, "./")); assertIsValidWindowsPath(u16, path); + var result: windows.HANDLE = undefined; + const path_len_bytes = std.math.cast(u16, path.len * 2) orelse return .{ .err = .{ .errno = @intFromEnum(bun.C.E.NOMEM), @@ -1029,11 +1033,11 @@ pub fn openatWindowsT(comptime T: type, dir: bun.FileDescriptor, path: []const T } pub fn openatWindows( - dir: bun.FileDescriptor, + dir: anytype, path: []const u16, flags: bun.Mode, ) Maybe(bun.FileDescriptor) { - return openatWindowsT(u16, dir, path, flags); + return openatWindowsT(u16, bun.toFD(dir), path, flags); } pub fn openatWindowsA( @@ -1666,14 +1670,16 @@ pub fn renameat(from_dir: bun.FileDescriptor, from: [:0]const u8, to_dir: bun.Fi var w_buf_from: bun.WPathBuffer = undefined; var w_buf_to: bun.WPathBuffer = undefined; - return bun.C.renameAtW( + const rc = bun.C.renameAtW( from_dir, - bun.strings.toWPathNormalized(&w_buf_from, from), + bun.strings.toNTPath(&w_buf_from, from), to_dir, - bun.strings.toWPathNormalized(&w_buf_to, to), + bun.strings.toNTPath(&w_buf_to, to), // @paperdave why waas this set to false? true, ); + + return rc; } while (true) { if (Maybe(void).errnoSys(sys.renameat(from_dir.cast(), from, to_dir.cast(), to), .rename)) |err| { @@ -1855,22 +1861,22 @@ pub fn unlink(from: [:0]const u8) Maybe(void) { } pub fn rmdirat(dirfd: bun.FileDescriptor, to: anytype) Maybe(void) { - if (Environment.isWindows) { - return Maybe(void).todo(); - } - while (true) { - if (Maybe(void).errnoSys(sys.unlinkat(dirfd.cast(), to, std.os.AT.REMOVEDIR), .rmdir)) |err| { - if (err.getErrno() == .INTR) continue; - return err; - } - return Maybe(void).success; - } + return unlinkatWithFlags(dirfd, to, std.os.AT.REMOVEDIR); } pub fn unlinkatWithFlags(dirfd: bun.FileDescriptor, to: anytype, flags: c_uint) Maybe(void) { if (Environment.isWindows) { - return Maybe(void).todo(); + if (comptime std.meta.Elem(@TypeOf(to)) == u8) { + var w_buf: bun.WPathBuffer = undefined; + return unlinkatWithFlags(dirfd, bun.strings.toNTPath(&w_buf, bun.span(to)), flags); + } + + return bun.windows.DeleteFileBun(to, .{ + .dir = if (dirfd != bun.invalid_fd) dirfd.cast() else null, + .remove_dir = flags & std.os.AT.REMOVEDIR != 0, + }); } + while (true) { if (Maybe(void).errnoSys(sys.unlinkat(dirfd.cast(), to, flags), .unlink)) |err| { if (err.getErrno() == .INTR) continue; @@ -1887,7 +1893,7 @@ pub fn unlinkatWithFlags(dirfd: bun.FileDescriptor, to: anytype, flags: c_uint) pub fn unlinkat(dirfd: bun.FileDescriptor, to: anytype) Maybe(void) { if (Environment.isWindows) { - return Maybe(void).todo(); + return unlinkatWithFlags(dirfd, to, 0); } while (true) { if (Maybe(void).errnoSys(sys.unlinkat(dirfd.cast(), to, 0), .unlink)) |err| { @@ -2270,6 +2276,14 @@ pub fn pipe() Maybe([2]bun.FileDescriptor) { return .{ .result = .{ bun.toFD(fds[0]), bun.toFD(fds[1]) } }; } +pub fn openNullDevice() Maybe(bun.FileDescriptor) { + if (comptime Environment.isWindows) { + return sys_uv.open("nul", 0, 0); + } + + return open("/dev/null", os.O.RDWR, 0); +} + pub fn dupWithFlags(fd: bun.FileDescriptor, flags: i32) Maybe(bun.FileDescriptor) { if (comptime Environment.isWindows) { var target: windows.HANDLE = undefined; diff --git a/src/windows.zig b/src/windows.zig index ed169bcfe9c95..14685ecaec74c 100644 --- a/src/windows.zig +++ b/src/windows.zig @@ -3044,7 +3044,7 @@ pub fn translateNTStatusToErrno(err: win32.NTSTATUS) bun.C.E { .OBJECT_NAME_NOT_FOUND => .NOENT, .NOT_A_DIRECTORY => .NOTDIR, .RETRY => .AGAIN, - .DIRECTORY_NOT_EMPTY => .EXIST, + .DIRECTORY_NOT_EMPTY => .NOTEMPTY, .FILE_TOO_LARGE => .@"2BIG", .SHARING_VIOLATION => if (comptime Environment.isDebug) brk: { bun.Output.debugWarn("Received SHARING_VIOLATION, indicates file handle should've been opened with FILE_SHARE_DELETE", .{}); @@ -3052,6 +3052,7 @@ pub fn translateNTStatusToErrno(err: win32.NTSTATUS) bun.C.E { } else .BUSY, .OBJECT_NAME_INVALID => if (comptime Environment.isDebug) brk: { bun.Output.debugWarn("Received OBJECT_NAME_INVALID, indicates a file path conversion issue.", .{}); + std.debug.dumpCurrentStackTrace(null); break :brk .INVAL; } else .INVAL, @@ -3375,3 +3376,114 @@ pub extern fn SetConsoleMode(console_handle: *anyopaque, mode: u32) u32; pub extern fn SetStdHandle(nStdHandle: u32, hHandle: *anyopaque) u32; pub extern fn GetConsoleOutputCP() u32; pub extern "kernel32" fn SetConsoleCP(wCodePageID: std.os.windows.UINT) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; + +pub const DeleteFileOptions = struct { + dir: ?HANDLE, + remove_dir: bool = false, +}; + +const FILE_DISPOSITION_DELETE: ULONG = 0x00000001; +const FILE_DISPOSITION_POSIX_SEMANTICS: ULONG = 0x00000002; +const FILE_DISPOSITION_FORCE_IMAGE_SECTION_CHECK: ULONG = 0x00000004; +const FILE_DISPOSITION_ON_CLOSE: ULONG = 0x00000008; +const FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE: ULONG = 0x00000010; + +// Copy-paste of the standard library function except without unreachable. +pub fn DeleteFileBun(sub_path_w: []const u16, options: DeleteFileOptions) bun.JSC.Maybe(void) { + const create_options_flags: ULONG = if (options.remove_dir) + FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT + else + windows.FILE_NON_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT; // would we ever want to delete the target instead? + + const path_len_bytes = @as(u16, @intCast(sub_path_w.len * 2)); + var nt_name = UNICODE_STRING{ + .Length = path_len_bytes, + .MaximumLength = path_len_bytes, + // The Windows API makes this mutable, but it will not mutate here. + .Buffer = @constCast(sub_path_w.ptr), + }; + + if (sub_path_w[0] == '.' and sub_path_w[1] == 0) { + // Windows does not recognize this, but it does work with empty string. + nt_name.Length = 0; + } + + var attr = OBJECT_ATTRIBUTES{ + .Length = @sizeOf(OBJECT_ATTRIBUTES), + .RootDirectory = if (std.fs.path.isAbsoluteWindowsWTF16(sub_path_w)) null else options.dir, + .Attributes = 0, // Note we do not use OBJ_CASE_INSENSITIVE here. + .ObjectName = &nt_name, + .SecurityDescriptor = null, + .SecurityQualityOfService = null, + }; + var io: IO_STATUS_BLOCK = undefined; + var tmp_handle: HANDLE = undefined; + var rc = ntdll.NtCreateFile( + &tmp_handle, + windows.SYNCHRONIZE | windows.DELETE, + &attr, + &io, + null, + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + windows.FILE_OPEN, + create_options_flags, + null, + 0, + ); + bun.sys.syslog("NtCreateFile({}, DELETE) = {}", .{ bun.fmt.fmtPath(u16, sub_path_w, .{}), rc }); + if (bun.JSC.Maybe(void).errnoSys(rc, .open)) |err| { + return err; + } + defer _ = bun.windows.CloseHandle(tmp_handle); + + // FileDispositionInformationEx (and therefore FILE_DISPOSITION_POSIX_SEMANTICS and FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE) + // are only supported on NTFS filesystems, so the version check on its own is only a partial solution. To support non-NTFS filesystems + // like FAT32, we need to fallback to FileDispositionInformation if the usage of FileDispositionInformationEx gives + // us INVALID_PARAMETER. + // The same reasoning for win10_rs5 as in os.renameatW() applies (FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE requires >= win10_rs5). + var need_fallback = true; + // Deletion with posix semantics if the filesystem supports it. + var info = windows.FILE_DISPOSITION_INFORMATION_EX{ + .Flags = FILE_DISPOSITION_DELETE | + FILE_DISPOSITION_POSIX_SEMANTICS | + FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE, + }; + + rc = ntdll.NtSetInformationFile( + tmp_handle, + &io, + &info, + @sizeOf(windows.FILE_DISPOSITION_INFORMATION_EX), + .FileDispositionInformationEx, + ); + bun.sys.syslog("NtSetInformationFile({}, DELETE) = {}", .{ bun.fmt.fmtPath(u16, sub_path_w, .{}), rc }); + switch (rc) { + .SUCCESS => return .{ .result = {} }, + // INVALID_PARAMETER here means that the filesystem does not support FileDispositionInformationEx + .INVALID_PARAMETER => {}, + // For all other statuses, fall down to the switch below to handle them. + else => need_fallback = false, + } + if (need_fallback) { + // Deletion with file pending semantics, which requires waiting or moving + // files to get them removed (from here). + var file_dispo = windows.FILE_DISPOSITION_INFORMATION{ + .DeleteFile = TRUE, + }; + + rc = ntdll.NtSetInformationFile( + tmp_handle, + &io, + &file_dispo, + @sizeOf(windows.FILE_DISPOSITION_INFORMATION), + .FileDispositionInformation, + ); + bun.sys.syslog("NtSetInformationFile({}, DELETE) = {}", .{ bun.fmt.fmtPath(u16, sub_path_w, .{}), rc }); + } + if (bun.JSC.Maybe(void).errnoSys(rc, .NtSetInformationFile)) |err| { + return err; + } + + return .{ .result = {} }; +} diff --git a/src/windows_c.zig b/src/windows_c.zig index 0d17838b1e03f..64a710358a705 100644 --- a/src/windows_c.zig +++ b/src/windows_c.zig @@ -1269,13 +1269,6 @@ pub fn renameAtW( new_path_w: []const u16, replace_if_exists: bool, ) Maybe(void) { - if (comptime bun.Environment.allow_assert) { - // if the directories are the same and the destination path is absolute, the old path name is kept - if (old_dir_fd == new_dir_fd) { - std.debug.assert(!std.fs.path.isAbsoluteWindowsWTF16(new_path_w)); - } - } - const src_fd = brk: { switch (bun.sys.openFileAtWindows( old_dir_fd, @@ -1305,7 +1298,7 @@ pub fn renameAtW( return moveOpenedFileAt(src_fd, new_dir_fd, new_path_w, replace_if_exists); } -const log = bun.Output.scoped(.SYS, true); +const log = bun.sys.syslog; /// With an open file source_fd, move it into the directory new_dir_fd with the name new_path_w. /// Does not close the file descriptor. diff --git a/test/cli/install/registry/bun-install-registry.test.ts b/test/cli/install/registry/bun-install-registry.test.ts index 2b50119cbea49..b3d10a3be05c7 100644 --- a/test/cli/install/registry/bun-install-registry.test.ts +++ b/test/cli/install/registry/bun-install-registry.test.ts @@ -1,5 +1,5 @@ import { file, spawn } from "bun"; -import { bunExe, bunEnv as env, toBeValidBin, toHaveBins, writeShebangScript } from "harness"; +import { bunExe, bunEnv as env, isLinux, toBeValidBin, toHaveBins, writeShebangScript } from "harness"; import { join, sep } from "path"; import { mkdtempSync, realpathSync } from "fs"; import { rm, writeFile, mkdir, exists, cp } from "fs/promises"; @@ -42,6 +42,7 @@ afterAll(() => { beforeEach(async () => { packageDir = mkdtempSync(join(realpathSync(tmpdir()), "bun-install-registry-" + testCounter++ + "-")); env.BUN_INSTALL_CACHE_DIR = join(packageDir, ".bun-cache"); + env.BUN_TMPDIR = env.TMPDIR = env.TEMP = join(packageDir, ".bun-tmp"); await writeFile( join(packageDir, "bunfig.toml"), ` @@ -2348,7 +2349,8 @@ test("missing package on reinstall, some with binaries", async () => { ).toBe(join(packageDir, "node_modules", "uses-what-bin", "node_modules", ".bin", bin)); }); -for (const forceWaiterThread of [false, true]) { +// waiter thread is only a thing on Linux. +for (const forceWaiterThread of isLinux ? [false, true] : [false]) { const testEnv = forceWaiterThread ? { ...env, BUN_FEATURE_FLAG_FORCE_WAITER_THREAD: "1" } : env; describe("lifecycle scripts" + (forceWaiterThread ? " (waiter thread)" : ""), async () => { test("root package with all lifecycle scripts", async () => { From 257f4c1b3ec62bdd7eb5b5e2bb601994f8a18bfb Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 10 Apr 2024 05:21:05 -0700 Subject: [PATCH 11/13] Bump zig std lib --- src/deps/zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deps/zig b/src/deps/zig index 7fe33d94eaeb1..0da041f84ea01 160000 --- a/src/deps/zig +++ b/src/deps/zig @@ -1 +1 @@ -Subproject commit 7fe33d94eaeb1af7705e9c5f43a3b243aa895436 +Subproject commit 0da041f84ea019cbdde7a3bc4af69f0d3258f50c From 5b4b6931c4f2d15fc390a57233eca8deff860168 Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Wed, 10 Apr 2024 05:25:27 -0700 Subject: [PATCH 12/13] docs: add guide for neon serverless postgres driver (#10126) --- .../ecosystem/neon-serverless-postgres.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 docs/guides/ecosystem/neon-serverless-postgres.md diff --git a/docs/guides/ecosystem/neon-serverless-postgres.md b/docs/guides/ecosystem/neon-serverless-postgres.md new file mode 100644 index 0000000000000..a51eb46d12e28 --- /dev/null +++ b/docs/guides/ecosystem/neon-serverless-postgres.md @@ -0,0 +1,55 @@ +--- +name: Use Neon's Serverless Postgres with Bun +--- + +[Neon](https://neon.tech/) is a fully managed serverless Postgres. Neon separates compute and storage to offer modern developer features such as autoscaling, branching, bottomless storage, and more. + +--- + +Get started by creating a project directory, initializing the directory using `bun init`, and adding the [Neon serverless driver](https://github.com/neondatabase/serverless/) as a project dependency. + +```sh +$ mkdir bun-neon-postgres +$ cd bun-neon-postgres +$ bun init -y +$ bun add @neondatabase/serverless +``` + +--- + +Create a `.env.local` file and add your [Neon Postgres connection string](https://neon.tech/docs/connect/connect-from-any-app) to it. + +```sh +DATBASE_URL=postgresql://username:password@ep-adj-noun-guid.us-east-1.aws.neon.tech/neondb?sslmode=require +``` + +--- + +Paste the following code into your project's `index.ts` file. + +```ts +import { neon } from "@neondatabase/serverless"; + +// Bun automatically loads the DATABASE_URL from .env.local +// Refer to: https://bun.sh/docs/runtime/env for more information +const sql = neon(process.env.DATABASE_URL); + +const rows = await sql`SELECT version()`; + +console.log(rows[0].version); +``` + +--- + +Start the program using `bun run`. The Postgres version should be printed to the console. + +```sh +$ bun run index.ts +PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit +``` + +--- + +This example used the Neon serverless driver's SQL-over-HTTP functionality. Neon's serverless driver also exposes `Client` and `Pool` constructors to enable sessions, interactive transactions, and node-postgres compatibility. + +Refer to [Neon's documentation](https://neon.tech/docs/serverless/serverless-driver) for a complete overview of the serverless driver. From 57208cb02e867244af4a599ae88700c6939e0636 Mon Sep 17 00:00:00 2001 From: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:32:47 -0400 Subject: [PATCH 13/13] fix typos (#10131) --- docs/runtime/shell.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/runtime/shell.md b/docs/runtime/shell.md index 7379dc703a168..3a85e35877557 100644 --- a/docs/runtime/shell.md +++ b/docs/runtime/shell.md @@ -191,7 +191,7 @@ import { $ } from "bun"; await $`bun run index.ts 2> errors.txt`; ``` -### Example: Redirect stdout -> stderr +### Example: Redirect stderr -> stdout ```js import { $ } from "bun"; @@ -201,7 +201,7 @@ import { $ } from "bun"; await $`bun run ./index.ts 2>&1`; ``` -### Example: Redirect stderr -> stdout +### Example: Redirect stdout -> stderr ```js import { $ } from "bun";