aboutsummaryrefslogtreecommitdiff
path: root/src/resolver
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-04 00:20:22 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-04 00:20:22 -0800
commit51fbbea1d3dc2b610fe5fe525229e56b581e5c8a (patch)
treec75e063c4eb7c99737fbf7a5a2014f9546e2e218 /src/resolver
parent696710fd7aedee6054947aab002aaa853e9ee731 (diff)
downloadbun-jarred/upgrade-zig-2.tar.gz
bun-jarred/upgrade-zig-2.tar.zst
bun-jarred/upgrade-zig-2.zip
Diffstat (limited to '')
-rw-r--r--src/resolver/data_url.zig3
-rw-r--r--src/resolver/resolver.zig18
-rw-r--r--src/resolver/tsconfig_json.zig3
3 files changed, 14 insertions, 10 deletions
diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig
index 486f60608..46638d10b 100644
--- a/src/resolver/data_url.zig
+++ b/src/resolver/data_url.zig
@@ -13,6 +13,7 @@ const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
const Allocator = mem.Allocator;
+const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap;
// https://github.com/Vexu/zuri/blob/master/src/zuri.zig#L61-L127
pub const PercentEncoding = struct {
@@ -83,7 +84,7 @@ pub const MimeType = enum {
TextJavaScript,
ApplicationJSON,
- pub const Map = std.ComptimeStringMap(MimeType, .{
+ pub const Map = ComptimeStringMap(MimeType, .{
.{ "text/css", MimeType.TextCSS },
.{ "text/javascript", MimeType.TextJavaScript },
.{ "application/json", MimeType.ApplicationJSON },
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index d3d8856cb..cd907ea2c 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -575,7 +575,7 @@ pub const Resolver = struct {
defer {
if (FeatureFlags.tracing) {
- if (timer) |time| {
+ if (timer) |*time| {
// technically, this should be an atomic op
r.elapsed += time.read();
}
@@ -672,6 +672,13 @@ pub const Resolver = struct {
return result;
}
+ const ModuleTypeMap = _global.ComptimeStringMap(options.ModuleType, .{
+ .{ ".mjs", options.ModuleType.esm },
+ .{ ".mts", options.ModuleType.esm },
+ .{ ".cjs", options.ModuleType.cjs },
+ .{ ".cts", options.ModuleType.cjs },
+ });
+
pub fn finalizeResult(r: *ThisResolver, result: *Result, kind: ast.ImportKind) !void {
if (result.is_external) return;
@@ -693,12 +700,7 @@ pub const Resolver = struct {
// If you use cjs or cts, then you're using cjs
// This should win out over the module type from package.json
if (!kind.isFromCSS() and module_type == .unknown and path.name.ext.len == 4) {
- const FourLetterMatcher = strings.ExactSizeMatcher(4);
- module_type = switch (FourLetterMatcher.match(path.name.ext)) {
- FourLetterMatcher.case(".mjs"), FourLetterMatcher.case(".mts") => .esm,
- FourLetterMatcher.case(".cjs"), FourLetterMatcher.case(".cts") => .cjs,
- else => .unknown,
- };
+ module_type = ModuleTypeMap.getWithLength(path.name.ext, 4) orelse .unknown;
}
if (dir.getEntries()) |entries| {
@@ -720,7 +722,7 @@ pub const Resolver = struct {
if (query.entry.cache.fd == 0) {
buf[out.len] = 0;
const span = buf[0..out.len :0];
- var file = try std.fs.openFileAbsoluteZ(span, .{ .read = true });
+ var file = try std.fs.openFileAbsoluteZ(span, .{ .mode = .read_only });
if (comptime !FeatureFlags.store_file_descriptors) {
out = try std.os.getFdPath(query.entry.cache.fd, &buf);
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig
index 82b658d69..cbf0b5b67 100644
--- a/src/resolver/tsconfig_json.zig
+++ b/src/resolver/tsconfig_json.zig
@@ -14,6 +14,7 @@ const logger = @import("../logger.zig");
const cache = @import("../cache.zig");
const js_ast = @import("../js_ast.zig");
const js_lexer = @import("../js_lexer.zig");
+const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap;
// Heuristic: you probably don't have 100 of these
// Probably like 5-10
@@ -60,7 +61,7 @@ pub const TSConfigJSON = struct {
remove,
invalid,
- pub const List = std.ComptimeStringMap(ImportsNotUsedAsValue, .{
+ pub const List = ComptimeStringMap(ImportsNotUsedAsValue, .{
.{ "preserve", ImportsNotUsedAsValue.preserve },
.{ "error", ImportsNotUsedAsValue.err },
.{ "remove", ImportsNotUsedAsValue.remove },