Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(next/telemetry): use basename for the absolute plugin path #38473

Merged
merged 3 commits into from Jul 13, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/next/telemetry/events/swc-plugins.ts
@@ -1,4 +1,6 @@
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'
Expand Down Expand Up @@ -26,22 +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 (await fileExists(pluginName)) {
pluginName = path.basename(plugin, '.wasm')
}

events.push({
return {
eventName: EVENT_SWC_PLUGIN_PRESENT,
payload: {
pluginName: plugin,
pluginName: pluginName,
pluginVersion: version,
},
})

return events
},
[]
}
})
)
} catch (_) {
return []
Expand Down