Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions packages/plugins/build-report/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,10 +67,7 @@ export const cleanReport = <T = string>(
// 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()!
Expand All @@ -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);
Expand All @@ -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()!
Expand Down
8 changes: 5 additions & 3 deletions packages/plugins/build-report/src/xpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
(
Expand Down Expand Up @@ -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)
Expand All @@ -276,15 +278,15 @@ export const getXpackPlugin =
name: cleanExternalName(moduleName),
dependencies: new Set(),
dependents: new Set(),
filepath: moduleIdentifier,
filepath: cleanIdentifier(moduleIdentifier),
type: 'external',
}
: {
size: module.size() || 0,
name: moduleName,
dependencies: new Set(),
dependents: new Set(),
filepath: moduleIdentifier,
filepath: cleanIdentifier(moduleIdentifier),
type: getType(moduleIdentifier),
};

Expand Down
Loading