Skip to content

Commit 95e7b49

Browse files
authored
fix(bundling): postcss-cli-resources should handle relative urls #32582 (#32658)
## Current Behavior Relative urls are not being handled correctly in the `postcss-cli-resources` Plugins for Webpack and Rspack after switching to use WHATWG URL in favour of the deprecated `url.parse()` method. ## Expected Behavior Ensure relatives are handled appropriately by resolving them based on the context of the current resource being loaded. ## Related Issue(s) Fixes #32582
1 parent 5011ecd commit 95e7b49

3 files changed

Lines changed: 3 additions & 6 deletions

File tree

packages/angular-rspack/src/lib/utils/postcss-cli-resources.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import { interpolateName } from 'loader-utils';
1010
import * as path from 'node:path';
11-
import * as url from 'node:url';
1211
import type { Declaration, Plugin } from 'postcss';
1312
import { assertIsError } from './misc-helpers';
1413

@@ -96,7 +95,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
9695
inputUrl = inputUrl.slice(1);
9796
}
9897

99-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
98+
const normalizedUrl = path.resolve(context, inputUrl.replace(/\\/g, '/'));
10099
const parsedUrl = new URL(normalizedUrl, 'file:///');
101100
const { pathname, hash, search } = parsedUrl;
102101
const resolver = (file: string, base: string) =>

packages/rspack/src/plugins/utils/plugins/postcss-cli-resources.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { interpolateName } from 'loader-utils';
22
import * as path from 'path';
33
import type { Declaration } from 'postcss';
4-
import * as url from 'node:url';
54
import type { LoaderContext } from '@rspack/core';
65

76
function wrapUrl(url: string): string {
@@ -94,7 +93,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
9493
resourceCache.set(cacheKey, outputUrl);
9594
return outputUrl;
9695
}
97-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
96+
const normalizedUrl = path.resolve(context, inputUrl.replace(/\\/g, '/'));
9897
const parsedUrl = new URL(normalizedUrl, 'file:///');
9998
const { pathname, hash, search } = parsedUrl;
10099
const resolver = (file: string, base: string) =>

packages/webpack/src/utils/webpack/plugins/postcss-cli-resources.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { interpolateName } from 'loader-utils';
22
import * as path from 'path';
33
import type { Declaration } from 'postcss';
4-
import * as url from 'node:url';
54
import { LoaderContext } from 'webpack';
65

76
function wrapUrl(url: string): string {
@@ -94,7 +93,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
9493
resourceCache.set(cacheKey, outputUrl);
9594
return outputUrl;
9695
}
97-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
96+
const normalizedUrl = path.resolve(context, inputUrl.replace(/\\/g, '/'));
9897
const parsedUrl = new URL(normalizedUrl, 'file:///');
9998
const { pathname, hash, search } = parsedUrl;
10099
const resolver = (file: string, base: string) =>

0 commit comments

Comments
 (0)