Skip to content

Commit

Permalink
Rename src/bundler.zig to src/transpiler.zig (#15921)
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Conway <[email protected]>
  • Loading branch information
Jarred-Sumner and dylan-conway authored Dec 21, 2024
1 parent 3c37b7f commit d6b9c44
Show file tree
Hide file tree
Showing 49 changed files with 1,186 additions and 1,200 deletions.
12 changes: 6 additions & 6 deletions src/bake/DevServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ bundles_since_last_error: usize = 0,
framework: bake.Framework,
bundler_options: bake.SplitBundlerOptions,
// Each logical graph gets its own bundler configuration
server_bundler: Bundler,
client_bundler: Bundler,
ssr_bundler: Bundler,
server_bundler: Transpiler,
client_bundler: Transpiler,
ssr_bundler: Transpiler,
/// The log used by all `server_bundler`, `client_bundler` and `ssr_bundler`.
/// Note that it is rarely correct to write messages into it. Instead, associate
/// messages with the IncrementalGraph file or Route using `SerializedFailure`
Expand Down Expand Up @@ -837,7 +837,7 @@ pub fn onSrcRequest(dev: *DevServer, req: *uws.Request, resp: *App.Response) voi
}

const ctx = &dev.vm.rareData().editor_context;
ctx.autoDetectEditor(JSC.VirtualMachine.get().bundler.env);
ctx.autoDetectEditor(JSC.VirtualMachine.get().transpiler.env);
const line: ?[]const u8 = req.header("editor-line");
const column: ?[]const u8 = req.header("editor-column");

Expand Down Expand Up @@ -3431,7 +3431,7 @@ pub const SerializedFailure = struct {
// TODO: syntax highlighted line text + give more context lines
try writeString32(loc.line_text orelse "", w);

// The file is not specified here. Since the bundler runs every file
// The file is not specified here. Since the transpiler runs every file
// in isolation, it would be impossible to reference any other file
// in this Log. Thus, it is not serialized.
} else {
Expand Down Expand Up @@ -4463,7 +4463,7 @@ const OpaqueFileId = FrameworkRouter.OpaqueFileId;
const Log = bun.logger.Log;
const Output = bun.Output;

const Bundler = bun.bundler.Bundler;
const Transpiler = bun.transpiler.Transpiler;
const BundleV2 = bun.bundle_v2.BundleV2;

const Define = bun.options.Define;
Expand Down
2 changes: 1 addition & 1 deletion src/bake/FrameworkRouter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ pub const JSFrameworkRouter = struct {
try jsfr.router.scan(
bun.default_allocator,
Type.Index.init(0),
&global.bunVM().bundler.resolver,
&global.bunVM().transpiler.resolver,
InsertionContext.wrap(JSFrameworkRouter, jsfr),
);
if (jsfr.stored_parse_errors.items.len > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ pub const Framework = struct {
log: *bun.logger.Log,
mode: Mode,
comptime renderer: Graph,
out: *bun.bundler.Bundler,
out: *bun.transpiler.Transpiler,
) !void {
out.* = try bun.Bundler.init(
out.* = try bun.Transpiler.init(
allocator, // TODO: this is likely a memory leak
log,
std.mem.zeroes(bun.Schema.Api.TransformOptions),
Expand Down
24 changes: 12 additions & 12 deletions src/bake/production.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn buildCommand(ctx: bun.CLI.Command.Context) !void {
vm.regular_event_loop.global = vm.global;
vm.jsc = vm.global.vm();
vm.event_loop.ensureWaker();
const b = &vm.bundler;
const b = &vm.transpiler;
vm.preload = ctx.preloads;
vm.argv = ctx.passthrough;
vm.arena = &arena;
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn buildCommand(ctx: bun.CLI.Command.Context) !void {
pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMachine) !void {
// Load and evaluate the configuration module
const global = vm.global;
const b = &vm.bundler;
const b = &vm.transpiler;
const allocator = bun.default_allocator;

Output.prettyErrorln("Loading configuration", .{});
Expand Down Expand Up @@ -171,23 +171,23 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
try loader.map.put("NODE_ENV", "production");
bun.DotEnv.instance = loader;

var client_bundler: bun.bundler.Bundler = undefined;
var server_bundler: bun.bundler.Bundler = undefined;
var ssr_bundler: bun.bundler.Bundler = undefined;
var client_bundler: bun.transpiler.Transpiler = undefined;
var server_bundler: bun.transpiler.Transpiler = undefined;
var ssr_bundler: bun.transpiler.Transpiler = undefined;
try framework.initBundler(allocator, vm.log, .production_static, .server, &server_bundler);
try framework.initBundler(allocator, vm.log, .production_static, .client, &client_bundler);
if (separate_ssr_graph) {
try framework.initBundler(allocator, vm.log, .production_static, .ssr, &ssr_bundler);
}

if (ctx.bundler_options.bake_debug_disable_minify) {
for ([_]*bun.bundler.Bundler{ &client_bundler, &server_bundler, &ssr_bundler }) |bundler| {
bundler.options.minify_syntax = false;
bundler.options.minify_identifiers = false;
bundler.options.minify_whitespace = false;
bundler.resolver.opts.entry_naming = "_bun/[dir]/[name].[hash].[ext]";
bundler.resolver.opts.chunk_naming = "_bun/[dir]/[name].[hash].chunk.[ext]";
bundler.resolver.opts.asset_naming = "_bun/[dir]/[name].[hash].asset.[ext]";
for ([_]*bun.transpiler.Transpiler{ &client_bundler, &server_bundler, &ssr_bundler }) |transpiler| {
transpiler.options.minify_syntax = false;
transpiler.options.minify_identifiers = false;
transpiler.options.minify_whitespace = false;
transpiler.resolver.opts.entry_naming = "_bun/[dir]/[name].[hash].[ext]";
transpiler.resolver.opts.chunk_naming = "_bun/[dir]/[name].[hash].chunk.[ext]";
transpiler.resolver.opts.asset_naming = "_bun/[dir]/[name].[hash].asset.[ext]";
}
}

Expand Down
31 changes: 15 additions & 16 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,11 @@ const Fs = @import("../../fs.zig");
const Resolver = @import("../../resolver/resolver.zig");
const ast = @import("../../import_record.zig");

const MacroEntryPoint = bun.bundler.MacroEntryPoint;
const MacroEntryPoint = bun.transpiler.MacroEntryPoint;
const logger = bun.logger;
const Api = @import("../../api/schema.zig").Api;
const options = @import("../../options.zig");
const Bundler = bun.Bundler;
const ServerEntryPoint = bun.bundler.ServerEntryPoint;
const ServerEntryPoint = bun.transpiler.ServerEntryPoint;
const js_printer = bun.js_printer;
const js_parser = bun.js_parser;
const js_ast = bun.JSAst;
Expand All @@ -203,7 +202,7 @@ const Runtime = @import("../../runtime.zig");
const Router = @import("./filesystem_router.zig");
const ImportRecord = ast.ImportRecord;
const DotEnv = @import("../../env_loader.zig");
const ParseResult = bun.bundler.ParseResult;
const ParseResult = bun.transpiler.ParseResult;
const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON;
const MacroRemap = @import("../../resolver/package_json.zig").MacroMap;
const WebCore = bun.JSC.WebCore;
Expand Down Expand Up @@ -379,10 +378,10 @@ pub fn which(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSE
}

path_str = ZigString.Slice.fromUTF8NeverFree(
globalThis.bunVM().bundler.env.get("PATH") orelse "",
globalThis.bunVM().transpiler.env.get("PATH") orelse "",
);
cwd_str = ZigString.Slice.fromUTF8NeverFree(
globalThis.bunVM().bundler.fs.top_level_dir,
globalThis.bunVM().transpiler.fs.top_level_dir,
);

if (arguments.nextEat()) |arg| {
Expand Down Expand Up @@ -572,7 +571,7 @@ pub fn registerMacro(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFram
}

pub fn getCWD(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue {
return ZigString.init(VirtualMachine.get().bundler.fs.top_level_dir).toJS(globalThis);
return ZigString.init(VirtualMachine.get().transpiler.fs.top_level_dir).toJS(globalThis);
}

pub fn getOrigin(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue {
Expand Down Expand Up @@ -696,7 +695,7 @@ pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.
if (!strings.eqlLong(prev_name, sliced.slice(), true)) {
const prev = edit.*;
edit.name = sliced.slice();
edit.detectEditor(VirtualMachine.get().bundler.env);
edit.detectEditor(VirtualMachine.get().transpiler.env);
editor_choice = edit.editor;
if (editor_choice == null) {
edit.* = prev;
Expand All @@ -719,7 +718,7 @@ pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.
}

const editor = editor_choice orelse edit.editor orelse brk: {
edit.autoDetectEditor(VirtualMachine.get().bundler.env);
edit.autoDetectEditor(VirtualMachine.get().transpiler.env);
if (edit.editor == null) {
return globalThis.throw("Failed to auto-detect editor", .{});
}
Expand All @@ -741,7 +740,7 @@ pub fn openInEditor(globalThis: js.JSContextRef, callframe: *JSC.CallFrame) bun.
pub fn getPublicPath(to: string, origin: URL, comptime Writer: type, writer: Writer) void {
return getPublicPathWithAssetPrefix(
to,
VirtualMachine.get().bundler.fs.top_level_dir,
VirtualMachine.get().transpiler.fs.top_level_dir,
origin,
"",
comptime Writer,
Expand All @@ -762,15 +761,15 @@ pub fn getPublicPathWithAssetPrefix(
const relative_path = if (strings.hasPrefix(to, dir))
strings.withoutTrailingSlash(to[dir.len..])
else
VirtualMachine.get().bundler.fs.relativePlatform(dir, to, platform);
VirtualMachine.get().transpiler.fs.relativePlatform(dir, to, platform);
if (origin.isAbsolute()) {
if (strings.hasPrefix(relative_path, "..") or strings.hasPrefix(relative_path, "./")) {
writer.writeAll(origin.origin) catch return;
writer.writeAll("/abs:") catch return;
if (std.fs.path.isAbsolute(to)) {
writer.writeAll(to) catch return;
} else {
writer.writeAll(VirtualMachine.get().bundler.fs.abs(&[_]string{to})) catch return;
writer.writeAll(VirtualMachine.get().transpiler.fs.abs(&[_]string{to})) catch return;
}
} else {
origin.joinWrite(
Expand Down Expand Up @@ -4193,8 +4192,8 @@ pub fn stringWidth(str: bun.String, opts: gen.StringWidthOptions) usize {
pub const EnvironmentVariables = struct {
pub export fn Bun__getEnvCount(globalObject: *JSC.JSGlobalObject, ptr: *[*][]const u8) usize {
const bunVM = globalObject.bunVM();
ptr.* = bunVM.bundler.env.map.map.keys().ptr;
return bunVM.bundler.env.map.map.unmanaged.entries.len;
ptr.* = bunVM.transpiler.env.map.map.keys().ptr;
return bunVM.transpiler.env.map.map.unmanaged.entries.len;
}

pub export fn Bun__getEnvKey(ptr: [*][]const u8, i: usize, data_ptr: *[*]const u8) usize {
Expand All @@ -4214,7 +4213,7 @@ pub const EnvironmentVariables = struct {

pub fn getEnvNames(globalObject: *JSC.JSGlobalObject, names: []ZigString) usize {
var vm = globalObject.bunVM();
const keys = vm.bundler.env.map.map.keys();
const keys = vm.transpiler.env.map.map.keys();
const len = @min(names.len, keys.len);
for (keys[0..len], names[0..len]) |key, *name| {
name.* = ZigString.initUTF8(key);
Expand All @@ -4226,7 +4225,7 @@ pub const EnvironmentVariables = struct {
var vm = globalObject.bunVM();
var sliced = name.toSlice(vm.allocator);
defer sliced.deinit();
const value = vm.bundler.env.get(sliced.slice()) orelse return null;
const value = vm.transpiler.env.get(sliced.slice()) orelse return null;
return ZigString.initUTF8(value);
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const string = bun.string;
const JSC = bun.JSC;
const js = JSC.C;
const WebCore = @import("../webcore/response.zig");
const Bundler = bun.bundler;
const Transpiler = bun.transpiler;
const options = @import("../../options.zig");
const resolve_path = @import("../../resolver/resolve_path.zig");
const VirtualMachine = JavaScript.VirtualMachine;
Expand Down Expand Up @@ -44,7 +44,7 @@ const JSLexer = bun.js_lexer;
const Expr = JSAst.Expr;
const Index = @import("../../ast/base.zig").Index;

const debug = bun.Output.scoped(.Bundler, false);
const debug = bun.Output.scoped(.Transpiler, false);

pub const JSBundler = struct {
const OwnedString = bun.MutableString;
Expand Down Expand Up @@ -389,7 +389,7 @@ pub const JSBundler = struct {
// defer slice.deinit();
// this.appendSliceExact(slice.slice()) catch unreachable;
// } else {
// this.appendSliceExact(globalThis.bunVM().bundler.fs.top_level_dir) catch unreachable;
// this.appendSliceExact(globalThis.bunVM().transpiler.fs.top_level_dir) catch unreachable;
// }

if (try config.getOptional(globalThis, "publicPath", ZigString.Slice)) |slice| {
Expand Down Expand Up @@ -748,7 +748,7 @@ pub const JSBundler = struct {
.bv2 = bv2,
.parse_task = parse,
.source_index = parse.source_index,
.default_loader = parse.path.loader(&bv2.bundler.options.loaders) orelse .js,
.default_loader = parse.path.loader(&bv2.transpiler.options.loaders) orelse .js,
.value = .pending,
.path = parse.path.text,
.namespace = parse.path.namespace,
Expand Down
Loading

0 comments on commit d6b9c44

Please sign in to comment.