Unverified Commit 102cef0f authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

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



Minor changes to SWC plugin telemetry payload. SWC's plugin can be either resolvable npm pkg, or absolute path. If it's an absolute path, try to grab actual plugin name only as we do not need any paths.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 53bc5b3d
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'
......@@ -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 []
......
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