Unverified Commit 319a338a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Use resource to detect feature usage in telemetry (#75917)

This is required for when we start using layers in Pages Router.
parent 6800e1ec
......@@ -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.
*/
......@@ -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
......@@ -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) {
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment