3692a5ecdb
Follow-up to https://github.com/vercel/next.js/pull/36527 this adds falling back to the wasm swc build when loading the native bindings fails so that we don't block the build on the native dependency being available. This continues off of https://github.com/vercel/next.js/pull/33496 but does not add a postinstall script yet and only downloads the fallback when the native dependency fails to load.
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { traceGlobals } from '../../trace/shared'
|
|
import { Telemetry } from '../storage'
|
|
// @ts-ignore JSON
|
|
import { version as nextVersion, optionalDependencies } from 'next/package.json'
|
|
|
|
const EVENT_PLUGIN_PRESENT = 'NEXT_SWC_LOAD_FAILURE'
|
|
export type EventSwcLoadFailure = {
|
|
eventName: string
|
|
payload: {
|
|
platform: string
|
|
arch: string
|
|
nodeVersion: string
|
|
nextVersion: string
|
|
wasm?: 'enabled' | 'fallback' | 'failed'
|
|
glibcVersion?: string
|
|
installedSwcPackages?: string
|
|
}
|
|
}
|
|
|
|
export async function eventSwcLoadFailure(
|
|
event?: EventSwcLoadFailure['payload']
|
|
): Promise<void> {
|
|
const telemetry: Telemetry = traceGlobals.get('telemetry')
|
|
// can't continue if telemetry isn't set
|
|
if (!telemetry) return
|
|
|
|
let glibcVersion
|
|
let installedSwcPackages
|
|
|
|
try {
|
|
// @ts-ignore
|
|
glibcVersion = process.report?.getReport().header.glibcVersionRuntime
|
|
} catch (_) {}
|
|
|
|
try {
|
|
const pkgNames = Object.keys(optionalDependencies || {}).filter((pkg) =>
|
|
pkg.startsWith('@next/swc')
|
|
)
|
|
const installedPkgs = []
|
|
|
|
for (const pkg of pkgNames) {
|
|
try {
|
|
const { version } = require(`${pkg}/package.json`)
|
|
installedPkgs.push(`${pkg}@${version}`)
|
|
} catch (_) {}
|
|
}
|
|
|
|
if (installedPkgs.length > 0) {
|
|
installedSwcPackages = installedPkgs.sort().join(',')
|
|
}
|
|
} catch (_) {}
|
|
|
|
telemetry.record({
|
|
eventName: EVENT_PLUGIN_PRESENT,
|
|
payload: {
|
|
nextVersion,
|
|
glibcVersion,
|
|
installedSwcPackages,
|
|
arch: process.arch,
|
|
platform: process.platform,
|
|
nodeVersion: process.versions.node,
|
|
wasm: event?.wasm,
|
|
},
|
|
})
|
|
// ensure this event is flushed before process exits
|
|
await telemetry.flush()
|
|
}
|