Skip to content

Commit 0f00d1d

Browse files
committed
Revert "feat(webpack): migrate from deprecated url.parse() to WHATWG … (#32397)
…URL API" This reverts commit f768886. <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Accidentally pushed this without review ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Reverting it so it can be reviewed ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 6abfbc8)
1 parent 70fb618 commit 0f00d1d

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
9696
inputUrl = inputUrl.slice(1);
9797
}
9898

99-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
100-
const parsedUrl = new URL(normalizedUrl, 'file:///');
101-
const { pathname, hash, search } = parsedUrl;
99+
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
102100
const resolver = (file: string, base: string) =>
103101
new Promise<string>((resolve, reject) => {
104102
loader.resolve(base, decodeURI(file), (err, result) => {
@@ -146,11 +144,11 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
146144

147145
let outputUrl = outputPath.replace(/\\/g, '/');
148146
if (hash || search) {
149-
outputUrl = outputUrl + (search || '') + (hash || '');
147+
outputUrl = url.format({ pathname: outputUrl, hash, search });
150148
}
151149

152150
if (deployUrl && !extracted) {
153-
outputUrl = new URL(outputUrl, deployUrl).href;
151+
outputUrl = url.resolve(deployUrl, outputUrl);
154152
}
155153

156154
resourceCache.set(cacheKey, outputUrl);

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
9494
resourceCache.set(cacheKey, outputUrl);
9595
return outputUrl;
9696
}
97-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
98-
const parsedUrl = new URL(normalizedUrl, 'file:///');
99-
const { pathname, hash, search } = parsedUrl;
97+
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
10098
const resolver = (file: string, base: string) =>
10199
new Promise<boolean | string>((resolve, reject) => {
102100
loader.resolve(base, decodeURI(file), (err, result) => {
@@ -127,11 +125,11 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
127125
loader.emitFile(outputPath, content, undefined);
128126
let outputUrl = outputPath.replace(/\\/g, '/');
129127
if (hash || search) {
130-
outputUrl = outputUrl + (search || '') + (hash || '');
128+
outputUrl = url.format({ pathname: outputUrl, hash, search });
131129
}
132130
const loaderOptions: any = loader.loaders[loader.loaderIndex].options;
133131
if (deployUrl && loaderOptions.ident !== 'extracted') {
134-
outputUrl = new URL(outputUrl, deployUrl).href;
132+
outputUrl = url.resolve(deployUrl, outputUrl);
135133
}
136134
resourceCache.set(cacheKey, outputUrl);
137135
resolve(outputUrl);

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
9494
resourceCache.set(cacheKey, outputUrl);
9595
return outputUrl;
9696
}
97-
const normalizedUrl = inputUrl.replace(/\\/g, '/');
98-
const parsedUrl = new URL(normalizedUrl, 'file:///');
99-
const { pathname, hash, search } = parsedUrl;
97+
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
10098
const resolver = (file: string, base: string) =>
10199
new Promise<boolean | string>((resolve, reject) => {
102100
loader.resolve(base, decodeURI(file), (err, result) => {
@@ -127,11 +125,11 @@ export function PostcssCliResources(options: PostcssCliResourcesOptions) {
127125
loader.emitFile(outputPath, content, undefined);
128126
let outputUrl = outputPath.replace(/\\/g, '/');
129127
if (hash || search) {
130-
outputUrl = outputUrl + (search || '') + (hash || '');
128+
outputUrl = url.format({ pathname: outputUrl, hash, search });
131129
}
132130
const loaderOptions: any = loader.loaders[loader.loaderIndex].options;
133131
if (deployUrl && loaderOptions.ident !== 'extracted') {
134-
outputUrl = new URL(outputUrl, deployUrl).href;
132+
outputUrl = url.resolve(deployUrl, outputUrl);
135133
}
136134
resourceCache.set(cacheKey, outputUrl);
137135
resolve(outputUrl);

0 commit comments

Comments
 (0)