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
0ab8c7ad
Unverified
Commit
0ab8c7ad
authored
Oct 26, 2021
by
Maia Teegarden
Committed by
GitHub
Oct 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track usage of swc features (#30297)
Co-authored-by:
Tim Neutkens
<
timneutkens@me.com
>
parent
9eceb955
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
3 deletions
+34
-3
webpack-config.ts
packages/next/build/webpack-config.ts
+8
-1
telemetry-plugin.ts
packages/next/build/webpack/plugins/telemetry-plugin.ts
+18
-2
build.ts
packages/next/telemetry/events/build.ts
+2
-0
index.test.js
test/integration/telemetry/test/index.test.js
+6
-0
No files found.
packages/next/build/webpack-config.ts
View file @
0ab8c7ad
...
...
@@ -1307,7 +1307,14 @@ export default async function getBaseWebpackConfig(
minimized
:
true
,
},
}),
!
dev
&&
!
isServer
&&
new
TelemetryPlugin
(),
!
dev
&&
!
isServer
&&
new
TelemetryPlugin
(
new
Map
([
[
'swcLoader'
,
useSWCLoader
],
[
'swcMinify'
,
config
.
swcMinify
],
])
),
].
filter
(
Boolean
as
any
as
ExcludesFalse
),
}
...
...
packages/next/build/webpack/plugins/telemetry-plugin.ts
View file @
0ab8c7ad
import
type
{
webpack5
as
webpack
}
from
'next/dist/compiled/webpack/webpack'
type
Feature
=
'next/image'
|
'next/script'
|
'next/dynamic'
type
Feature
=
|
'next/image'
|
'next/script'
|
'next/dynamic'
|
'swcLoader'
|
'swcMinify'
interface
FeatureUsage
{
featureName
:
Feature
...
...
@@ -29,6 +34,9 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
[
'next/dynamic'
,
'/next/dynamic.js'
],
])
// List of build features used in webpack configuration
const
BUILD_FEATURES
:
Array
<
Feature
>
=
[
'swcLoader'
,
'swcMinify'
]
/**
* Plugin that queries the ModuleGraph to look for modules that correspond to
* certain features (e.g. next/image and next/script) and record how many times
...
...
@@ -37,7 +45,15 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
export
class
TelemetryPlugin
implements
webpack
.
WebpackPluginInstance
{
private
usageTracker
=
new
Map
<
Feature
,
FeatureUsage
>
()
constructor
()
{
// Build feature usage is on/off and is known before the build starts
constructor
(
buildFeaturesMap
:
Map
<
Feature
,
boolean
>
)
{
for
(
const
featureName
of
BUILD_FEATURES
)
{
this
.
usageTracker
.
set
(
featureName
,
{
featureName
,
invocationCount
:
buildFeaturesMap
.
get
(
featureName
)
?
1
:
0
,
})
}
for
(
const
featureName
of
FEATURE_MODULE_MAP
.
keys
())
{
this
.
usageTracker
.
set
(
featureName
,
{
featureName
,
...
...
packages/next/telemetry/events/build.ts
View file @
0ab8c7ad
...
...
@@ -128,6 +128,8 @@ export type EventBuildFeatureUsage = {
|
'next/script'
|
'next/dynamic'
|
'experimental/optimizeCss'
|
'swcLoader'
|
'swcMinify'
invocationCount
:
number
}
export
function
eventBuildFeatureUsage
(
...
...
test/integration/telemetry/test/index.test.js
View file @
0ab8c7ad
...
...
@@ -569,6 +569,12 @@ describe('Telemetry CLI', () => {
})
const
regex
=
/NEXT_BUILD_FEATURE_USAGE
[\s\S]
+
?
{
([\s\S]
+
?)
}/g
regex
.
exec
(
stderr
).
pop
()
// optimizeCss
const
swcLoader
=
regex
.
exec
(
stderr
).
pop
()
expect
(
swcLoader
).
toContain
(
`"featureName": "swcLoader"`
)
expect
(
swcLoader
).
toContain
(
`"invocationCount": 1`
)
const
swcMinify
=
regex
.
exec
(
stderr
).
pop
()
expect
(
swcMinify
).
toContain
(
`"featureName": "swcMinify"`
)
expect
(
swcMinify
).
toContain
(
`"invocationCount": 0`
)
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