Skip to content

Commit

Permalink
Use resource to detect feature usage in telemetry
Browse files Browse the repository at this point in the history
This is required for when we start using layers in Pages Router.
It's also required to fix telemetry of certain features in App Router which makes extensive usage of layers.
That isn't working just yet though a test was kept in place.
  • Loading branch information
eps1lon committed Feb 12, 2025
1 parent a90f0c9 commit 554d372
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ interface FeatureUsage {
invocationCount: number
}

/**
* A vertex in the module graph.
*/
interface Module {
type: string
identifier(): string
}

/**
* An edge in the module graph.
*/
Expand Down Expand Up @@ -127,16 +119,17 @@ const useCacheTracker = createUseCacheTracker()
/**
* Determine if there is a feature of interest in the specified 'module'.
*/
function findFeatureInModule(module: Module): Feature | undefined {
function findFeatureInModule(module: webpack.Module): Feature | undefined {
if (module.type !== 'javascript/auto') {
return
}
const normalizedIdentifier = module.identifier().replace(/\\/g, '/')

for (const [feature, path] of FEATURE_MODULE_MAP) {
if (normalizedIdentifier.endsWith(path)) {
if ((module as webpack.NormalModule).resource.endsWith(path)) {
return feature
}
}
const normalizedIdentifier = module.identifier().replace(/\\/g, '/')
for (const [feature, regexp] of FEATURE_MODULE_REGEXP_MAP) {
if (regexp.test(normalizedIdentifier)) {
return feature
Expand All @@ -151,7 +144,7 @@ function findFeatureInModule(module: Module): Feature | undefined {
*/
function findUniqueOriginModulesInConnections(
connections: Connection[],
originModule: Module
originModule: webpack.Module
): Set<unknown> {
const originModules = new Set()
for (const connection of connections) {
Expand Down Expand Up @@ -206,7 +199,7 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance {
async (compilation: webpack.Compilation, callback: () => void) => {
compilation.hooks.finishModules.tapAsync(
TelemetryPlugin.name,
async (modules: Iterable<Module>, modulesFinish: () => void) => {
async (modules, modulesFinish) => {
for (const module of modules) {
const feature = findFeatureInModule(module)
if (!feature) {
Expand Down

0 comments on commit 554d372

Please sign in to comment.