Skip to content

Commit 44cc1fa

Browse files
committed
feat(telemetry): report swc target triple to telemetry
1 parent cd47984 commit 44cc1fa

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

packages/next/build/webpack-config.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin
4343
import { regexLikeCss } from './webpack/config/blocks/css'
4444
import { CopyFilePlugin } from './webpack/plugins/copy-file-plugin'
4545
import { FlightManifestPlugin } from './webpack/plugins/flight-manifest-plugin'
46-
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
46+
import {
47+
Feature,
48+
SWC_TARGET_TRIPLE,
49+
TelemetryPlugin,
50+
} from './webpack/plugins/telemetry-plugin'
4751
import type { Span } from '../trace'
4852
import { getRawPageExtensions } from './utils'
4953
import browserslist from 'next/dist/compiled/browserslist'
@@ -406,6 +410,15 @@ export default async function getBaseWebpackConfig(
406410
const distDir = path.join(dir, config.distDir)
407411

408412
let useSWCLoader = !babelConfigFile
413+
let SWCBinaryTarget: [Feature, boolean] | undefined = undefined
414+
if (useSWCLoader) {
415+
// TODO: we do not collect wasm target yet
416+
const binaryTarget = require('./swc')?.getBinaryMetadata?.()
417+
?.target as SWC_TARGET_TRIPLE
418+
SWCBinaryTarget = binaryTarget
419+
? [`swc/target/${binaryTarget}` as const, true]
420+
: undefined
421+
}
409422

410423
if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
411424
Log.info(
@@ -1492,23 +1505,26 @@ export default async function getBaseWebpackConfig(
14921505
!dev &&
14931506
!isServer &&
14941507
new TelemetryPlugin(
1495-
new Map([
1496-
['swcLoader', useSWCLoader],
1497-
['swcMinify', config.swcMinify],
1498-
['swcRelay', !!config.compiler?.relay],
1499-
['swcStyledComponents', !!config.compiler?.styledComponents],
1500-
[
1501-
'swcReactRemoveProperties',
1502-
!!config.compiler?.reactRemoveProperties,
1503-
],
1508+
new Map(
15041509
[
1505-
'swcExperimentalDecorators',
1506-
!!jsConfig?.compilerOptions?.experimentalDecorators,
1507-
],
1508-
['swcRemoveConsole', !!config.compiler?.removeConsole],
1509-
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
1510-
['swcEmotion', !!config.experimental.emotion],
1511-
])
1510+
['swcLoader', useSWCLoader],
1511+
['swcMinify', config.swcMinify],
1512+
['swcRelay', !!config.compiler?.relay],
1513+
['swcStyledComponents', !!config.compiler?.styledComponents],
1514+
[
1515+
'swcReactRemoveProperties',
1516+
!!config.compiler?.reactRemoveProperties,
1517+
],
1518+
[
1519+
'swcExperimentalDecorators',
1520+
!!jsConfig?.compilerOptions?.experimentalDecorators,
1521+
],
1522+
['swcRemoveConsole', !!config.compiler?.removeConsole],
1523+
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
1524+
['swcEmotion', !!config.experimental.emotion],
1525+
SWCBinaryTarget,
1526+
].filter<[Feature, boolean]>(Boolean as any)
1527+
)
15121528
),
15131529
].filter(Boolean as any as ExcludesFalse),
15141530
}

packages/next/build/webpack/plugins/telemetry-plugin.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'
22

3-
type Feature =
3+
/**
4+
* List of target triples next-swc native binary supports.
5+
*/
6+
export type SWC_TARGET_TRIPLE =
7+
| 'x86_64-apple-darwin'
8+
| 'x86_64-unknown-linux-gnu'
9+
| 'x86_64-pc-windows-msvc'
10+
| 'i686-pc-windows-msvc'
11+
| 'aarch64-unknown-linux-gnu'
12+
| 'armv7-unknown-linux-gnueabihf'
13+
| 'aarch64-apple-darwin'
14+
| 'aarch64-linux-android'
15+
| 'arm-linux-androideabi'
16+
| 'x86_64-unknown-freebsd'
17+
| 'x86_64-unknown-linux-musl'
18+
| 'aarch64-unknown-linux-musl'
19+
| 'aarch64-pc-windows-msvc'
20+
21+
export type Feature =
422
| 'next/image'
523
| 'next/script'
624
| 'next/dynamic'
@@ -13,6 +31,7 @@ type Feature =
1331
| 'swcRemoveConsole'
1432
| 'swcImportSource'
1533
| 'swcEmotion'
34+
| `swc/target/${SWC_TARGET_TRIPLE}`
1635

1736
interface FeatureUsage {
1837
featureName: Feature
@@ -52,6 +71,19 @@ const BUILD_FEATURES: Array<Feature> = [
5271
'swcRemoveConsole',
5372
'swcImportSource',
5473
'swcEmotion',
74+
'swc/target/x86_64-apple-darwin',
75+
'swc/target/x86_64-unknown-linux-gnu',
76+
'swc/target/x86_64-pc-windows-msvc',
77+
'swc/target/i686-pc-windows-msvc',
78+
'swc/target/aarch64-unknown-linux-gnu',
79+
'swc/target/armv7-unknown-linux-gnueabihf',
80+
'swc/target/aarch64-apple-darwin',
81+
'swc/target/aarch64-linux-android',
82+
'swc/target/arm-linux-androideabi',
83+
'swc/target/x86_64-unknown-freebsd',
84+
'swc/target/x86_64-unknown-linux-musl',
85+
'swc/target/aarch64-unknown-linux-musl',
86+
'swc/target/aarch64-pc-windows-msvc',
5587
]
5688

5789
/**

packages/next/telemetry/events/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TelemetryPlugin } from '../../build/webpack/plugins/telemetry-plugin'
2+
import type { SWC_TARGET_TRIPLE } from '../../build/webpack/plugins/telemetry-plugin'
23

34
const REGEXP_DIRECTORY_DUNDER =
45
/[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
@@ -144,6 +145,7 @@ export type EventBuildFeatureUsage = {
144145
| 'swcRemoveConsole'
145146
| 'swcImportSource'
146147
| 'swcEmotion'
148+
| `swc/target/${SWC_TARGET_TRIPLE}`
147149
| 'build-lint'
148150
invocationCount: number
149151
}

0 commit comments

Comments
 (0)