Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c2619247
Unverified
Commit
c2619247
authored
Mar 22, 2022
by
OJ Kwon
Committed by
GitHub
Mar 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(telemetry): report swc target triple to telemetry (#35420)
parent
af95b0cb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
20 deletions
+94
-20
index.js
packages/next/build/swc/index.js
+13
-2
webpack-config.ts
packages/next/build/webpack-config.ts
+33
-17
telemetry-plugin.ts
packages/next/build/webpack/plugins/telemetry-plugin.ts
+33
-1
build.ts
packages/next/telemetry/events/build.ts
+2
-0
index.test.js
test/integration/telemetry/test/index.test.js
+13
-0
No files found.
packages/next/build/swc/index.js
View file @
c2619247
...
...
@@ -76,6 +76,9 @@ async function loadWasm() {
parse
(
src
,
options
)
{
return
Promise
.
resolve
(
bindings
.
parse
(
src
.
toString
(),
options
))
},
getTargetTriple
()
{
return
undefined
},
}
return
wasmBindings
}
catch
(
e
)
{
...
...
@@ -187,6 +190,8 @@ function loadNative() {
parse(src, options) {
return bindings.parse(src, toBuffer(options ?? {}))
},
getTargetTriple: bindings.getTargetTriple,
}
return nativeBindings
}
...
...
@@ -235,8 +240,14 @@ export async function parse(src, options) {
}
export function getBinaryMetadata() {
let bindings = loadBindingsSync()
let bindings
try {
bindings = loadNative()
} catch (e) {
// Suppress exceptions, this fn allows to fail to load native bindings
}
return {
target: bindings
.getTargetTriple
(),
target: bindings
?.getTargetTriple?.
(),
}
}
packages/next/build/webpack-config.ts
View file @
c2619247
...
...
@@ -43,7 +43,11 @@ import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin
import
{
regexLikeCss
}
from
'./webpack/config/blocks/css'
import
{
CopyFilePlugin
}
from
'./webpack/plugins/copy-file-plugin'
import
{
FlightManifestPlugin
}
from
'./webpack/plugins/flight-manifest-plugin'
import
{
TelemetryPlugin
}
from
'./webpack/plugins/telemetry-plugin'
import
{
Feature
,
SWC_TARGET_TRIPLE
,
TelemetryPlugin
,
}
from
'./webpack/plugins/telemetry-plugin'
import
type
{
Span
}
from
'../trace'
import
{
getRawPageExtensions
}
from
'./utils'
import
browserslist
from
'next/dist/compiled/browserslist'
...
...
@@ -406,6 +410,15 @@ export default async function getBaseWebpackConfig(
const
distDir
=
path
.
join
(
dir
,
config
.
distDir
)
let
useSWCLoader
=
!
babelConfigFile
let
SWCBinaryTarget
:
[
Feature
,
boolean
]
|
undefined
=
undefined
if
(
useSWCLoader
)
{
// TODO: we do not collect wasm target yet
const
binaryTarget
=
require
(
'./swc'
)?.
getBinaryMetadata
?.()
?.
target
as
SWC_TARGET_TRIPLE
SWCBinaryTarget
=
binaryTarget
?
[
`swc/target/
${
binaryTarget
}
`
as
const
,
true
]
:
undefined
}
if
(
!
loggedSwcDisabled
&&
!
useSWCLoader
&&
babelConfigFile
)
{
Log
.
info
(
...
...
@@ -1492,23 +1505,26 @@ export default async function getBaseWebpackConfig(
!
dev
&&
!
isServer
&&
new
TelemetryPlugin
(
new
Map
([
[
'swcLoader'
,
useSWCLoader
],
[
'swcMinify'
,
config
.
swcMinify
],
[
'swcRelay'
,
!!
config
.
compiler
?.
relay
],
[
'swcStyledComponents'
,
!!
config
.
compiler
?.
styledComponents
],
[
'swcReactRemoveProperties'
,
!!
config
.
compiler
?.
reactRemoveProperties
,
],
new
Map
(
[
'swcExperimentalDecorators'
,
!!
jsConfig
?.
compilerOptions
?.
experimentalDecorators
,
],
[
'swcRemoveConsole'
,
!!
config
.
compiler
?.
removeConsole
],
[
'swcImportSource'
,
!!
jsConfig
?.
compilerOptions
?.
jsxImportSource
],
[
'swcEmotion'
,
!!
config
.
experimental
.
emotion
],
])
[
'swcLoader'
,
useSWCLoader
],
[
'swcMinify'
,
config
.
swcMinify
],
[
'swcRelay'
,
!!
config
.
compiler
?.
relay
],
[
'swcStyledComponents'
,
!!
config
.
compiler
?.
styledComponents
],
[
'swcReactRemoveProperties'
,
!!
config
.
compiler
?.
reactRemoveProperties
,
],
[
'swcExperimentalDecorators'
,
!!
jsConfig
?.
compilerOptions
?.
experimentalDecorators
,
],
[
'swcRemoveConsole'
,
!!
config
.
compiler
?.
removeConsole
],
[
'swcImportSource'
,
!!
jsConfig
?.
compilerOptions
?.
jsxImportSource
],
[
'swcEmotion'
,
!!
config
.
experimental
.
emotion
],
SWCBinaryTarget
,
].
filter
<
[
Feature
,
boolean
]
>
(
Boolean
as
any
)
)
),
].
filter
(
Boolean
as
any
as
ExcludesFalse
),
}
...
...
packages/next/build/webpack/plugins/telemetry-plugin.ts
View file @
c2619247
import
type
{
webpack5
as
webpack
}
from
'next/dist/compiled/webpack/webpack'
type
Feature
=
/**
* List of target triples next-swc native binary supports.
*/
export
type
SWC_TARGET_TRIPLE
=
|
'x86_64-apple-darwin'
|
'x86_64-unknown-linux-gnu'
|
'x86_64-pc-windows-msvc'
|
'i686-pc-windows-msvc'
|
'aarch64-unknown-linux-gnu'
|
'armv7-unknown-linux-gnueabihf'
|
'aarch64-apple-darwin'
|
'aarch64-linux-android'
|
'arm-linux-androideabi'
|
'x86_64-unknown-freebsd'
|
'x86_64-unknown-linux-musl'
|
'aarch64-unknown-linux-musl'
|
'aarch64-pc-windows-msvc'
export
type
Feature
=
|
'next/image'
|
'next/script'
|
'next/dynamic'
...
...
@@ -13,6 +31,7 @@ type Feature =
|
'swcRemoveConsole'
|
'swcImportSource'
|
'swcEmotion'
|
`swc/target/
${
SWC_TARGET_TRIPLE
}
`
interface
FeatureUsage
{
featureName
:
Feature
...
...
@@ -52,6 +71,19 @@ const BUILD_FEATURES: Array<Feature> = [
'swcRemoveConsole'
,
'swcImportSource'
,
'swcEmotion'
,
'swc/target/x86_64-apple-darwin'
,
'swc/target/x86_64-unknown-linux-gnu'
,
'swc/target/x86_64-pc-windows-msvc'
,
'swc/target/i686-pc-windows-msvc'
,
'swc/target/aarch64-unknown-linux-gnu'
,
'swc/target/armv7-unknown-linux-gnueabihf'
,
'swc/target/aarch64-apple-darwin'
,
'swc/target/aarch64-linux-android'
,
'swc/target/arm-linux-androideabi'
,
'swc/target/x86_64-unknown-freebsd'
,
'swc/target/x86_64-unknown-linux-musl'
,
'swc/target/aarch64-unknown-linux-musl'
,
'swc/target/aarch64-pc-windows-msvc'
,
]
/**
...
...
packages/next/telemetry/events/build.ts
View file @
c2619247
import
{
TelemetryPlugin
}
from
'../../build/webpack/plugins/telemetry-plugin'
import
type
{
SWC_TARGET_TRIPLE
}
from
'../../build/webpack/plugins/telemetry-plugin'
const
REGEXP_DIRECTORY_DUNDER
=
/
[\\/]
__
[^\\/]
+
(?<
!
[\\/]
__
(?:
tests|mocks
))
__
[\\/]
/i
...
...
@@ -144,6 +145,7 @@ export type EventBuildFeatureUsage = {
|
'swcRemoveConsole'
|
'swcImportSource'
|
'swcEmotion'
|
`swc/target/
${
SWC_TARGET_TRIPLE
}
`
|
'build-lint'
invocationCount
:
number
}
...
...
test/integration/telemetry/test/index.test.js
View file @
c2619247
...
...
@@ -632,6 +632,19 @@ describe('Telemetry CLI', () => {
regex
.
exec
(
stderr
).
pop
()
// swcRemoveConsole
regex
.
exec
(
stderr
).
pop
()
// swcImportSource
regex
.
exec
(
stderr
).
pop
()
// swcEmotion
regex
.
exec
(
stderr
).
pop
()
// swc/targets/*
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
regex
.
exec
(
stderr
).
pop
()
const
image
=
regex
.
exec
(
stderr
).
pop
()
expect
(
image
).
toContain
(
`"featureName": "next/image"`
)
expect
(
image
).
toContain
(
`"invocationCount": 1`
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment