diff options
author | 2022-02-10 01:40:36 -0800 | |
---|---|---|
committer | 2022-02-10 01:40:36 -0800 | |
commit | 27501a05767f76b2f5cee785e6a761d5bb99ae34 (patch) | |
tree | d3da3fc921495602fccf8cd3efe124c5f244dc52 | |
parent | 2e2521c6381104e7697b9c44918bf8fb313ccb3e (diff) | |
download | bun-27501a05767f76b2f5cee785e6a761d5bb99ae34.tar.gz bun-27501a05767f76b2f5cee785e6a761d5bb99ae34.tar.zst bun-27501a05767f76b2f5cee785e6a761d5bb99ae34.zip |
[bun dev][css] Fix loading external assets
-rw-r--r-- | src/bundler.zig | 2 | ||||
-rw-r--r-- | src/css_scanner.zig | 5 | ||||
-rw-r--r-- | src/linker.zig | 53 |
3 files changed, 22 insertions, 38 deletions
diff --git a/src/bundler.zig b/src/bundler.zig index 0267fb014..0de0932d6 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -2280,6 +2280,7 @@ pub const Bundler = struct { WatcherType, @TypeOf(bundler.fs), true, + import_path_format, ); const CSSBundler = Css.NewBundler( @@ -2289,6 +2290,7 @@ pub const Bundler = struct { WatcherType, @TypeOf(bundler.fs), false, + import_path_format, ); return BuildResolveResultPair{ diff --git a/src/css_scanner.zig b/src/css_scanner.zig index 616a577e2..059f7f23a 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -1057,7 +1057,7 @@ pub fn NewWriter( import_record.ImportKind.url, writer.buildCtx.origin, import_path_format, - true, + false, ); try writer.writeURL(url_str, url); }, @@ -1135,6 +1135,7 @@ pub fn NewBundler( comptime Watcher: type, comptime FSType: type, comptime hot_module_reloading: bool, + comptime import_path_format: options.BundleOptions.ImportPathFormat, ) type { return struct { const CSSBundler = @This(); @@ -1184,7 +1185,7 @@ pub fn NewBundler( .allocator = allocator, .watcher = watcher, }; - const CSSWriter = NewWriter(*CSSBundler, Linker, .absolute_url, *CSSBundler); + const CSSWriter = NewWriter(*CSSBundler, Linker, import_path_format, *CSSBundler); var css = CSSWriter.init( undefined, diff --git a/src/linker.zig b/src/linker.zig index 1ddcc1eef..6f565f0fb 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -141,48 +141,29 @@ pub const Linker = struct { comptime resolve_only: bool, ) !string { const dir = path.name.dirWithTrailingSlash(); + if (strings.hasPrefix(url, "/")) { + if (comptime import_path_format == .absolute_url) { + return try origin.joinAlloc(this.allocator, "", url, "", "", url); + } - switch (kind) { - .at => { - var resolve_result = try this.resolver.resolve(dir, url, .at); - if (resolve_only or resolve_result.is_external) { - return resolve_result.path_pair.primary.text; - } - - var import_record = ImportRecord{ .range = range, .path = resolve_result.path_pair.primary, .kind = kind }; - - const loader = this.options.loaders.get(resolve_result.path_pair.primary.name.ext) orelse .file; + return url; + } - this.processImportRecord(loader, dir, &resolve_result, &import_record, origin, import_path_format) catch unreachable; - return import_record.path.text; - }, - .at_conditional => { - var resolve_result = try this.resolver.resolve(dir, url, .at_conditional); - if (resolve_only or resolve_result.is_external) { - return resolve_result.path_pair.primary.text; - } + var resolve_result = try this.resolver.resolve(dir, url, kind); - var import_record = ImportRecord{ .range = range, .path = resolve_result.path_pair.primary, .kind = kind }; - const loader = this.options.loaders.get(resolve_result.path_pair.primary.name.ext) orelse .file; + if (resolve_result.is_external) { + return url; + } - this.processImportRecord(loader, dir, &resolve_result, &import_record, origin, import_path_format) catch unreachable; - return import_record.path.text; - }, - .url => { - var resolve_result = try this.resolver.resolve(dir, url, .url); - if (resolve_only or resolve_result.is_external) { - return resolve_result.path_pair.primary.text; - } + if (resolve_only) { + return resolve_result.path_pair.primary.text; + } - var import_record = ImportRecord{ .range = range, .path = resolve_result.path_pair.primary, .kind = kind }; - const loader = this.options.loaders.get(resolve_result.path_pair.primary.name.ext) orelse .file; + var import_record = ImportRecord{ .range = range, .path = resolve_result.path_pair.primary, .kind = kind }; + const loader = this.options.loaders.get(resolve_result.path_pair.primary.name.ext) orelse .file; - this.processImportRecord(loader, dir, &resolve_result, &import_record, origin, import_path_format) catch unreachable; - return import_record.path.text; - }, - else => unreachable, - } - unreachable; + this.processImportRecord(loader, dir, &resolve_result, &import_record, origin, import_path_format) catch unreachable; + return import_record.path.text; } pub inline fn nodeModuleBundleImportPath(this: *const ThisLinker, origin: URL) string { |