diff options
author | 2021-09-23 00:17:06 -0700 | |
---|---|---|
committer | 2021-09-23 00:17:06 -0700 | |
commit | 57ed3c89a253a6dfe775e1bfad1f25dcc814468b (patch) | |
tree | 196f3eec433bfb4f03bd227eb1a8a73e4699e7e7 /src/resolver/package_json.zig | |
parent | 1a284a1c94f0468634e35246f58a8381a2085616 (diff) | |
download | bun-57ed3c89a253a6dfe775e1bfad1f25dcc814468b.tar.gz bun-57ed3c89a253a6dfe775e1bfad1f25dcc814468b.tar.zst bun-57ed3c89a253a6dfe775e1bfad1f25dcc814468b.zip |
Add `"bun": { "alwaysBundle": ["packageName"] },` to package.json
This is for monorepos that symlink directories into node_modules. For example, if you have a design system in your monorepo, you probably want to always bundle that.
Diffstat (limited to 'src/resolver/package_json.zig')
-rw-r--r-- | src/resolver/package_json.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index fa8603569..bff445bf2 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -55,6 +55,8 @@ pub const PackageJSON = struct { version: string = "", hash: u32 = 0xDEADBEEF, + always_bundle: []string = &.{}, + // Present if the "browser" field is present. This field is intended to be // used by bundlers and lets you redirect the paths of certain 3rd-party // modules that don't work in the browser to other modules that shim that @@ -527,6 +529,27 @@ pub const PackageJSON = struct { } } + if (json.asProperty("bun")) |bun_json| { + if (bun_json.expr.asProperty("alwaysBundle")) |bundle_| { + if (bundle_.expr.data == .e_array) { + var always_bundle_count: u16 = 0; + const array = bundle_.expr.data.e_array.items; + for (array) |item| { + always_bundle_count += @intCast(u16, @boolToInt(item.data == .e_string and item.data.e_string.utf8.len > 0)); + } + package_json.always_bundle = r.allocator.alloc(string, always_bundle_count) catch unreachable; + + var i: u16 = 0; + for (array) |item| { + if (!(item.data == .e_string and item.data.e_string.utf8.len > 0)) continue; + package_json.always_bundle[i] = item.asString(r.allocator).?; + i += 1; + } + // for (var i = 0; i < bundle_.expr.data.e_array.len; i++) { + } + } + } + // Read the "main" fields for (r.opts.main_fields) |main| { if (json.asProperty(main)) |main_json| { |