diff options
author | 2021-05-13 00:46:22 -0700 | |
---|---|---|
committer | 2021-05-13 00:46:22 -0700 | |
commit | bed0227a8f2d8b674a98803659922d08ac665bfe (patch) | |
tree | 42e6cd96757a0f9c01d103de1f42bdc7a9e958b8 /src/bundler.zig | |
parent | 9fd6f635cd5092ce82359b504f1e053d7f0387d6 (diff) | |
download | bun-bed0227a8f2d8b674a98803659922d08ac665bfe.tar.gz bun-bed0227a8f2d8b674a98803659922d08ac665bfe.tar.zst bun-bed0227a8f2d8b674a98803659922d08ac665bfe.zip |
hm
Former-commit-id: 28fce4aac174c7cf7a492ca4c5442d57a4f395a3
Diffstat (limited to 'src/bundler.zig')
-rw-r--r-- | src/bundler.zig | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/bundler.zig b/src/bundler.zig index 04a3725f9..8df23e265 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -22,7 +22,7 @@ const ThreadSafeHashMap = @import("./thread_safe_hash_map.zig"); // pub const // const BundleMap = - +const ResolveResults = ThreadSafeHashMap.ThreadSafeStringHashMap(Resolver.Resolver.Result); pub const Bundler = struct { options: options.BundleOptions, log: *logger.Log, @@ -30,7 +30,9 @@ pub const Bundler = struct { result: options.TransformResult = undefined, resolver: Resolver.Resolver, fs: *Fs.FileSystem, - thread_pool: *ThreadPool, + // thread_pool: *ThreadPool, + + resolve_results: *ResolveResults, // to_bundle: @@ -43,20 +45,24 @@ pub const Bundler = struct { ) !Bundler { var fs = try Fs.FileSystem.init1(allocator, opts.absolute_working_dir, opts.watch orelse false); const bundle_options = try options.BundleOptions.fromApi(allocator, fs, log, opts); - var pool = try allocator.create(ThreadPool); - try pool.init(ThreadPool.InitConfig{ - .allocator = allocator, - }); + // var pool = try allocator.create(ThreadPool); + // try pool.init(ThreadPool.InitConfig{ + // .allocator = allocator, + // }); return Bundler{ .options = bundle_options, .fs = fs, .allocator = allocator, .resolver = Resolver.Resolver.init1(allocator, log, fs, bundle_options), .log = log, - .thread_pool = pool, + // .thread_pool = pool, + .result = options.TransformResult{}, + .resolve_results = try ResolveResults.init(allocator), }; } + pub fn scan(bundler: *Bundler) !void {} + pub fn bundle( allocator: *std.mem.Allocator, log: *logger.Log, @@ -65,14 +71,27 @@ pub const Bundler = struct { var bundler = try Bundler.init(allocator, log, opts); var entry_points = try allocator.alloc(Resolver.Resolver.Result, bundler.options.entry_points.len); + var entry_point_i: usize = 0; for (bundler.options.entry_points) |entry| { - entry_points[entry_point_i] = bundler.resolver.resolve(bundler.fs.top_level_dir, entry, .entry_point) catch { + const result = bundler.resolver.resolve(bundler.fs.top_level_dir, entry, .entry_point) catch { continue; } orelse continue; + const key = result.path_pair.primary.text; + if (bundler.resolve_results.contains(key)) { + continue; + } + try bundler.resolve_results.put(key, result); + entry_points[entry_point_i] = result; + Output.print("Resolved {s} => {s}", .{ entry, result.path_pair.primary.text }); entry_point_i += 1; } + switch (bundler.options.resolve_mode) { + .lazy, .dev, .bundle => {}, + else => Global.panic("Unsupported resolve mode: {s}", .{@tagName(bundler.options.resolve_mode)}), + } + return bundler.result; } }; |