Skip to content

Commit

Permalink
fix: improve stats string for match resource with data url
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Sep 6, 2024
1 parent 3ad52de commit bc6c969
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ exports[`statsOutput statsOutput/logging-loader should print correct stats for 1
"
`;
exports[`statsOutput statsOutput/match-resource-data-url should print correct stats for 1`] = `
"runtime modules 677 bytes 3 modules
./index.js 145 bytes [built] [code generated]
./a.js!=!data:javascript,var __looooooooo.. 93 bytes [built] [code generated]"
`;
exports[`statsOutput statsOutput/minify-error should print correct stats for 1`] = `
"ERROR in × JavaScript parsing error: Expected a semicolon
╭─[1:8]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import name from "./a.js!=!data:javascript,var __looooooooooooong_variable_name__ = 1;export default __looooooooooooong_variable_name__;";
name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @type {import('@rspack/core').RspackOptions}
*/
module.exports = {
entry: "./index.js",
mode: "development",
stats: {
all: false,
modules: true,
}
};
7 changes: 6 additions & 1 deletion packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ const getResourceName = (resource: string) => {
};

const getModuleName = (name: string) => {
const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name) || [];
const matchResourceMatch = /^([^!]+)!=!/.exec(name);
const n = matchResourceMatch
? matchResourceMatch[0] +
getResourceName(name.slice(matchResourceMatch[0].length))
: name;
const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(n) || [];
return [prefix, getResourceName(resource)];
};

Expand Down

0 comments on commit bc6c969

Please sign in to comment.