diff options
author | 2021-08-14 23:04:29 -0700 | |
---|---|---|
committer | 2021-08-14 23:04:29 -0700 | |
commit | bfac22d951fb3ca2e1cf849a2af0cc60c372b1ed (patch) | |
tree | 3ca7f1213edc4ef290edfeae8a367a92904bd4dc /src/javascript/jsc | |
parent | d95ffe63023c09ea792d4f0379374f7c6c7975e6 (diff) | |
download | bun-bfac22d951fb3ca2e1cf849a2af0cc60c372b1ed.tar.gz bun-bfac22d951fb3ca2e1cf849a2af0cc60c372b1ed.tar.zst bun-bfac22d951fb3ca2e1cf849a2af0cc60c372b1ed.zip |
fix defines
Former-commit-id: 12db22bc3f5875ee0c43d25f8247983967451c3f
Diffstat (limited to 'src/javascript/jsc')
-rw-r--r-- | src/javascript/jsc/config.zig | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/javascript/jsc/config.zig b/src/javascript/jsc/config.zig index edc6f342d..affb1df68 100644 --- a/src/javascript/jsc/config.zig +++ b/src/javascript/jsc/config.zig @@ -37,89 +37,5 @@ pub fn configureTransformOptionsForSpeedyVM(allocator: *std.mem.Allocator, _args pub fn configureTransformOptionsForSpeedy(allocator: *std.mem.Allocator, _args: Api.TransformOptions) !Api.TransformOptions { var args = _args; args.platform = Api.Platform.speedy; - // We inline process.env.* at bundle time but process.env is a proxy object which will otherwise return undefined. - - var env_map = try getNodeEnvMap(allocator); - var env_count = env_map.count(); - - if (args.define) |def| { - for (def.keys) |key| { - env_count += @boolToInt((env_map.get(key) == null)); - } - } - var needs_node_env = env_map.get("NODE_ENV") == null; - var needs_window_undefined = true; - - var needs_regenerate = args.define == null and env_count > 0; - if (args.define) |def| { - if (def.keys.len != env_count) { - needs_regenerate = true; - } - for (def.keys) |key| { - if (strings.eql(key, "process.env.NODE_ENV")) { - needs_node_env = false; - } else if (strings.eql(key, "window")) { - needs_window_undefined = false; - } - } - } - - var extras_count = @intCast(usize, @boolToInt(needs_node_env)) + @intCast(usize, @boolToInt(needs_window_undefined)); - - if (needs_regenerate) { - var new_list = try allocator.alloc([]const u8, env_count * 2 + extras_count * 2); - var keys = new_list[0 .. new_list.len / 2]; - var values = new_list[keys.len..]; - var new_map = Api.StringMap{ - .keys = keys, - .values = values, - }; - var iter = env_map.iterator(); - - var last: usize = 0; - while (iter.next()) |entry| { - keys[last] = entry.key_ptr.*; - var value = entry.value_ptr.*; - - if (value.len == 0 or value[0] != '"' or value[value.len - 1] != '"') { - value = try std.fmt.allocPrint(allocator, "\"{s}\"", .{value}); - } - values[last] = value; - last += 1; - } - - if (args.define) |def| { - var from_env = keys[0..last]; - - for (def.keys) |pre, i| { - if (env_map.get(pre) != null) { - for (from_env) |key, j| { - if (strings.eql(key, pre)) { - values[j] = def.values[i]; - } - } - } else { - keys[last] = pre; - values[last] = def.values[i]; - last += 1; - } - } - } - - if (needs_node_env) { - keys[last] = options.DefaultUserDefines.NodeEnv.Key; - values[last] = options.DefaultUserDefines.NodeEnv.Value; - last += 1; - } - - if (needs_window_undefined) { - keys[last] = DefaultSpeedyDefines.Keys.window; - values[last] = DefaultSpeedyDefines.Values.window; - last += 1; - } - - args.define = new_map; - } - return args; } |