From 2e26cc6e620e4e229d6000c6ba7d88445e0b5988 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sat, 9 Jul 2022 01:03:12 -0700 Subject: [PATCH 1/2] 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 7a0d9ee8473e..8c92889056aa 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 (existsSync(pluginName)) { + pluginName = path.basename(plugin, '.wasm') + } events.push({ eventName: EVENT_SWC_PLUGIN_PRESENT, payload: { - pluginName: plugin, + pluginName: pluginName, pluginVersion: version, }, }) From dc5224939c689ffe84c50e8888e29f804fa8d103 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 13 Jul 2022 13:03:08 -0700 Subject: [PATCH 2/2] refactor(next/telemetry): replace file check utility --- packages/next/telemetry/events/swc-plugins.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/next/telemetry/events/swc-plugins.ts b/packages/next/telemetry/events/swc-plugins.ts index 8c92889056aa..157799041ce8 100644 --- a/packages/next/telemetry/events/swc-plugins.ts +++ b/packages/next/telemetry/events/swc-plugins.ts @@ -1,6 +1,6 @@ -import { existsSync } from 'fs' import findUp from 'next/dist/compiled/find-up' import path from 'path' +import { fileExists } from '../../lib/file-exists' import type { NextConfig } from '../../server/config-shared' const EVENT_SWC_PLUGIN_PRESENT = 'NEXT_SWC_PLUGIN_DETECTED' @@ -28,26 +28,23 @@ export async function eventSwcPlugins( const swcPluginPackages = config.experimental?.swcPlugins?.map(([name, _]) => name) ?? [] - return swcPluginPackages.reduce( - (events: SwcPluginsEvent[], plugin: string): SwcPluginsEvent[] => { + return Promise.all( + swcPluginPackages.map(async (plugin) => { // swc plugins can be non-npm pkgs with absolute path doesn't have version const version = deps[plugin] ?? undefined let pluginName = plugin - if (existsSync(pluginName)) { + if (await fileExists(pluginName)) { pluginName = path.basename(plugin, '.wasm') } - events.push({ + return { eventName: EVENT_SWC_PLUGIN_PRESENT, payload: { pluginName: pluginName, pluginVersion: version, }, - }) - - return events - }, - [] + } + }) ) } catch (_) { return []