From 4c7d16fa6fda1bf9ba772c1f43ce439cd24c9265 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sat, 9 Jul 2022 01:03:12 -0700 Subject: [PATCH] refactor(next/telemetry): use basename for the absolute plugin path --- packages/next/telemetry/events/swc-plugins.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/next/telemetry/events/swc-plugins.ts b/packages/next/telemetry/events/swc-plugins.ts index 329337d1af5b..6329a7ce21c8 100644 --- a/packages/next/telemetry/events/swc-plugins.ts +++ b/packages/next/telemetry/events/swc-plugins.ts @@ -1,4 +1,6 @@ +import { existsSync } from 'fs' import findUp from 'next/dist/compiled/find-up' +import path from 'path' import type { NextConfig } from '../../server/config-shared' const EVENT_SWC_PLUGIN_PRESENT = 'NEXT_SWC_PLUGIN_DETECTED' @@ -30,11 +32,15 @@ export async function eventSwcPlugins( (events: SwcPluginsEvent[], plugin: string): SwcPluginsEvent[] => { // swc plugins can be non-npm pkgs with absolute path doesn't have version const version = deps[plugin] ?? undefined + let pluginName = plugin + if (!version && existsSync(pluginName)) { + pluginName = path.basename(plugin, '.wasm') + } events.push({ eventName: EVENT_SWC_PLUGIN_PRESENT, payload: { - packageName: plugin, + packageName: pluginName, packageVersion: version, }, })