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 { ...@@ -54,14 +54,6 @@ interface FeatureUsage {
invocationCount: number invocationCount: number
} }
/**
* A vertex in the module graph.
*/
interface Module {
type: string
identifier(): string
}
/** /**
* An edge in the module graph. * An edge in the module graph.
*/ */
...@@ -127,16 +119,17 @@ const useCacheTracker = createUseCacheTracker() ...@@ -127,16 +119,17 @@ const useCacheTracker = createUseCacheTracker()
/** /**
* Determine if there is a feature of interest in the specified 'module'. * 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') { if (module.type !== 'javascript/auto') {
return return
} }
const normalizedIdentifier = module.identifier().replace(/\\/g, '/')
for (const [feature, path] of FEATURE_MODULE_MAP) { for (const [feature, path] of FEATURE_MODULE_MAP) {
if (normalizedIdentifier.endsWith(path)) { if ((module as webpack.NormalModule).resource.endsWith(path)) {
return feature return feature
} }
} }
const normalizedIdentifier = module.identifier().replace(/\\/g, '/')
for (const [feature, regexp] of FEATURE_MODULE_REGEXP_MAP) { for (const [feature, regexp] of FEATURE_MODULE_REGEXP_MAP) {
if (regexp.test(normalizedIdentifier)) { if (regexp.test(normalizedIdentifier)) {
return feature return feature
...@@ -151,7 +144,7 @@ function findFeatureInModule(module: Module): Feature | undefined { ...@@ -151,7 +144,7 @@ function findFeatureInModule(module: Module): Feature | undefined {
*/ */
function findUniqueOriginModulesInConnections( function findUniqueOriginModulesInConnections(
connections: Connection[], connections: Connection[],
originModule: Module originModule: webpack.Module
): Set<unknown> { ): Set<unknown> {
const originModules = new Set() const originModules = new Set()
for (const connection of connections) { for (const connection of connections) {
...@@ -206,7 +199,7 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance { ...@@ -206,7 +199,7 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance {
async (compilation: webpack.Compilation, callback: () => void) => { async (compilation: webpack.Compilation, callback: () => void) => {
compilation.hooks.finishModules.tapAsync( compilation.hooks.finishModules.tapAsync(
TelemetryPlugin.name, TelemetryPlugin.name,
async (modules: Iterable<Module>, modulesFinish: () => void) => { async (modules, modulesFinish) => {
for (const module of modules) { for (const module of modules) {
const feature = findFeatureInModule(module) const feature = findFeatureInModule(module)
if (!feature) { 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