Skip to content

Commit

Permalink
fix: webpack compilations fail when using filesystem cache, #458
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Dec 16, 2024
1 parent 8eb07f8 commit b6fbf39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ async function loader(content) {
}

let isAbsolute = isAbsoluteURL(this.resourcePath);
const isData = this.resourcePath.startsWith("DATA:");
const shouldMakeRelative = !isData && isAbsolute;

const filename = isAbsolute
? this.resourcePath
: path.relative(this.rootContext, this.resourcePath);
const filename = shouldMakeRelative
? path.relative(this.rootContext, this.resourcePath)
: this.resourcePath;

const minifyOptions =
/** @type {import("./index").InternalWorkerOptions<T>} */ ({
Expand Down
6 changes: 3 additions & 3 deletions test/ImageminPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ describe("imagemin plugin", () => {
const stringStats = stats.toString({ relatedAssets: true });

expect(stringStats).toMatch(
/asset loader-test.webp.+\[from: .+loader-test.png\] \[generated\]/,
/asset loader-test.webp.+\[from: .*loader-test.png\] \[generated\]/,
);
});

Expand Down Expand Up @@ -1386,7 +1386,7 @@ describe("imagemin plugin", () => {
expect(warnings).toHaveLength(0);
expect(errors).toHaveLength(1);
expect(errors[0].message).toMatch(
/Multiple values for the 'encodeOptions' option is not supported for '.+loader-test.png', specify only one codec for the generator/,
/Multiple values for the 'encodeOptions' option is not supported for '.*loader-test.png', specify only one codec for the generator/,
);
});

Expand Down Expand Up @@ -1771,7 +1771,7 @@ describe("imagemin plugin", () => {
expect(warnings).toHaveLength(0);
expect(errors).toHaveLength(1);
expect(errors[0].message).toMatch(
/Error with '.+loader-test.txt': Input file has an unsupported format/g,
/Error with '.*loader-test.txt': Input file has an unsupported format/g,
);
});

Expand Down

0 comments on commit b6fbf39

Please sign in to comment.