Skip to content

Commit

Permalink
Pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
padmaia committed Feb 8, 2022
1 parent bf267b4 commit a6118ef
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/advanced-features/compiler.md
Expand Up @@ -154,7 +154,7 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
```js
{
"compilerOptions": {
"jsxImportSource": true
"jsxImportSource": 'preact'
}
}
```
Expand Down
14 changes: 10 additions & 4 deletions packages/next/build/webpack-config.ts
Expand Up @@ -1519,10 +1519,16 @@ export default async function getBaseWebpackConfig(
['swcMinify', config.swcMinify],
['swcRelay', !!config.compiler?.relay],
['swcStyledComponents', !!config.compiler?.styledComponents],
['swcReactRemoveProperties', !!config.reactRemoveProperties],
['swcExperimentalDecorators', !!config.experimentalDecorators],
['swcRemoveConsole', !!config.removeConsole],
['swcImportSource', !!config.importSource],
[
'swcReactRemoveProperties',
!!config.compiler?.reactRemoveProperties,
],
[
'swcExperimentalDecorators',
!!jsConfig?.compilerOptions?.experimentalDecorators,
],
['swcRemoveConsole', !!config.compiler?.removeConsole],
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
])
),
].filter(Boolean as any as ExcludesFalse),
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/webpack/plugins/telemetry-plugin.ts
Expand Up @@ -44,6 +44,7 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
const BUILD_FEATURES: Array<Feature> = [
'swcLoader',
'swcMinify',
'swcRelay',
'swcStyledComponents',
'swcReactRemoveProperties',
'swcExperimentalDecorators',
Expand All @@ -62,6 +63,7 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance {
// Build feature usage is on/off and is known before the build starts
constructor(buildFeaturesMap: Map<Feature, boolean>) {
for (const featureName of BUILD_FEATURES) {
console.error('FEATURES MAP', buildFeaturesMap)
this.usageTracker.set(featureName, {
featureName,
invocationCount: buildFeaturesMap.get(featureName) ? 1 : 0,
Expand Down
12 changes: 10 additions & 2 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -621,6 +621,12 @@ describe('Telemetry CLI', () => {
expect(optimizeFonts).toContain(`"invocationCount": 1`)
regex.exec(stderr).pop() // swcLoader
regex.exec(stderr).pop() // swcMinify
regex.exec(stderr).pop() // swcRelay
regex.exec(stderr).pop() // swcStyledComponents
regex.exec(stderr).pop() // swcExperimentalDecorators
regex.exec(stderr).pop() // swcReactRemoveProperties
regex.exec(stderr).pop() // swcRemoveConsole
regex.exec(stderr).pop() // swcImportSource
const image = regex.exec(stderr).pop()
expect(image).toContain(`"featureName": "next/image"`)
expect(image).toContain(`"invocationCount": 1`)
Expand All @@ -647,6 +653,8 @@ describe('Telemetry CLI', () => {
path.join(appDir, 'jsconfig.json')
)

console.log('STDERR', stderr)

const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // optimizeCss
regex.exec(stderr).pop() // build-lint
Expand All @@ -656,7 +664,7 @@ describe('Telemetry CLI', () => {
expect(swcLoader).toContain(`"invocationCount": 1`)
const swcMinify = regex.exec(stderr).pop()
expect(swcMinify).toContain(`"featureName": "swcMinify"`)
//expect(swcMinify).toContain(`"invocationCount": 1`)
expect(swcMinify).toContain(`"invocationCount": 1`)
const swcRelay = regex.exec(stderr).pop()
expect(swcRelay).toContain(`"featureName": "swcRelay"`)
expect(swcRelay).toContain(`"invocationCount": 1`)
Expand All @@ -680,7 +688,7 @@ describe('Telemetry CLI', () => {
expect(swcRemoveConsole).toContain(`"invocationCount": 1`)
const swcImportSource = regex.exec(stderr).pop()
expect(swcImportSource).toContain(`"featureName": "swcImportSource"`)
expect(swcImportSource).toContain(`"invocationCount": 1`)
expect(swcImportSource).toContain(`"invocationCount": 0`)
})

it('emits telemetry for usage of `optimizeCss`', async () => {
Expand Down

0 comments on commit a6118ef

Please sign in to comment.