diff --git a/packages/plugins/build-report/src/helpers.ts b/packages/plugins/build-report/src/helpers.ts index 005fce1a..f14a4bd4 100644 --- a/packages/plugins/build-report/src/helpers.ts +++ b/packages/plugins/build-report/src/helpers.ts @@ -9,9 +9,8 @@ import path from 'path'; // Will match any last part of a path after a dot or slash and is a word character. const EXTENSION_RX = /\.(?!.*(?:\.|\/|\\))(\w{1,})/g; -// Will match any type of query characters. -// "?" or "%3F" (url encoded "?") or "|" -const QUERY_RX = /(\?|%3F|\|)+/gi; +// Will match "?" or "%3F" (url encoded "?") +const QUERY_RX = /(\?|%3F)+/gi; const getExtension = (filepath: string) => { // Reset RX first. @@ -68,10 +67,7 @@ export const cleanReport = ( // Careful with this and webpack/rspack as loaders may add "|" before and after the filepath. export const cleanPath = (filepath: string) => { return ( - filepath - // [webpack] Only keep the loaded part of a loader query. - .split('!') - .pop()! + cleanIdentifier(filepath) // Remove query parameters. .split(QUERY_RX) .shift()! @@ -81,6 +77,17 @@ export const cleanPath = (filepath: string) => { ); }; +export const cleanIdentifier = (identifier: string) => { + return ( + identifier // [webpack] Only keep the loaded part of a loader query. + .split('!') + .pop()! + // [webpack] Remove some loader prefix. + .split('|') + .pop()! + ); +}; + // From two file paths, remove the common path prefix. export const removeCommonPrefix = (filepath1: string, filepath2: string) => { const filepath2Split = filepath2.split(path.sep); @@ -106,13 +113,7 @@ export const cleanName = (absoluteOutDir: string, filepath: string) => { } return ( - removeCommonPrefix( - filepath - // [webpack] Only keep the loaded part of a loader query. - .split('!') - .pop()!, - absoluteOutDir, - ) + removeCommonPrefix(cleanIdentifier(filepath), absoluteOutDir) // Remove node_modules path. .split('node_modules') .pop()! diff --git a/packages/plugins/build-report/src/xpack.ts b/packages/plugins/build-report/src/xpack.ts index c9d1bc32..f1edc823 100644 --- a/packages/plugins/build-report/src/xpack.ts +++ b/packages/plugins/build-report/src/xpack.ts @@ -14,7 +14,7 @@ import type { PluginOptions, } from '@dd/core/types'; -import { cleanName, cleanPath, getType } from './helpers'; +import { cleanIdentifier, cleanName, cleanPath, getType } from './helpers'; export const getXpackPlugin = ( @@ -264,10 +264,12 @@ export const getXpackPlugin = depDeps.dependents.add(moduleIdentifier); moduleDeps.dependencies.add(depIdentifier); tempDeps.set(depIdentifier, depDeps); + tempDeps.set(cleanIdentifier(depIdentifier), depDeps); } // Store the dependencies. tempDeps.set(moduleIdentifier, moduleDeps); + tempDeps.set(cleanIdentifier(moduleIdentifier), moduleDeps); // Store the inputs. const file: Input = isExternal(module) @@ -276,7 +278,7 @@ export const getXpackPlugin = name: cleanExternalName(moduleName), dependencies: new Set(), dependents: new Set(), - filepath: moduleIdentifier, + filepath: cleanIdentifier(moduleIdentifier), type: 'external', } : { @@ -284,7 +286,7 @@ export const getXpackPlugin = name: moduleName, dependencies: new Set(), dependents: new Set(), - filepath: moduleIdentifier, + filepath: cleanIdentifier(moduleIdentifier), type: getType(moduleIdentifier), };