Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GranularChunks conformance check #11710

Merged
merged 89 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
0d24bde
Adding native-url package
janicklas-ralph Sep 23, 2019
252ff9b
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Oct 22, 2019
ec54da8
Bumping native-url version
janicklas-ralph Oct 22, 2019
bc22678
Upgrading native-url
janicklas-ralph Oct 25, 2019
22fbeb7
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Oct 25, 2019
c74137b
Logging stats object for debugging
janicklas-ralph Oct 25, 2019
a816aff
Logging stats object for debugging
janicklas-ralph Oct 25, 2019
465fe2d
Merge branch 'canary' into native-url
timneutkens Oct 25, 2019
aa99ed0
Merge branch 'canary' into native-url
ijjk Oct 26, 2019
50c2e7c
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Oct 28, 2019
5bbf585
Adding try catch to the error lines
janicklas-ralph Oct 28, 2019
49fdf55
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Oct 28, 2019
044dae3
Experimenting with regex
janicklas-ralph Oct 28, 2019
e45be11
Experimenting with regex
janicklas-ralph Oct 28, 2019
5458c70
Experimenting with regex
janicklas-ralph Oct 28, 2019
bf44461
Testing regex changes
janicklas-ralph Oct 28, 2019
0e0f422
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Oct 29, 2019
e976414
Fixing defer-script test case to not include polyfill.js
janicklas-ralph Oct 29, 2019
31c709d
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Oct 30, 2019
e77df8b
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 5, 2019
96e4456
Meging changes with existing polyfill work
janicklas-ralph Nov 5, 2019
6134036
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 19, 2019
587783a
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 25, 2019
8431e0a
Bumping version
janicklas-ralph Nov 25, 2019
62c15ac
adjust webpack config
Timer Nov 25, 2019
98f5742
Reduce size in size test
Timer Nov 25, 2019
9183fa2
Merge branch 'canary' into native-url
Timer Nov 25, 2019
ba8e6da
Remove 1kb from legacy
Timer Nov 25, 2019
57df7e3
Merge branch 'canary' into native-url
Timer Nov 25, 2019
0ee9952
Merge branch 'canary' into native-url
Timer Nov 25, 2019
3af4325
Bumping native-url version, includes fix for IE11
janicklas-ralph Nov 26, 2019
ae4ed5a
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Nov 26, 2019
ad7b0a7
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 26, 2019
d9b07f2
Update lock file
Timer Nov 26, 2019
e81dc2f
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 26, 2019
1321a6c
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Nov 27, 2019
1cb4e98
Updating native-url, fixes issue on IE11
janicklas-ralph Nov 27, 2019
6952517
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Nov 27, 2019
80b3d56
Fix sourcemap being added in document
janicklas-ralph Dec 4, 2019
d70af64
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Dec 4, 2019
a24cc59
Merge branch 'canary' into native-url
janicklas-ralph Dec 4, 2019
65d0646
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Dec 4, 2019
054c9eb
Merge branch 'canary' into native-url
Timer Dec 5, 2019
024fa44
Merge branch 'canary' into native-url
Timer Dec 5, 2019
ed0d65a
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Dec 5, 2019
1c3a145
Adding Router as an app level dep. Fixes Router not being added as a …
janicklas-ralph Dec 9, 2019
9cf2881
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Dec 9, 2019
86e0940
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Dec 9, 2019
356edee
Fix typescript error
janicklas-ralph Dec 9, 2019
9661e19
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Dec 12, 2019
9272b59
Fix modern + granularChunks hydration failing
janicklas-ralph Dec 12, 2019
a575d5b
Fix TS error
janicklas-ralph Dec 12, 2019
d72eb98
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Dec 16, 2019
d9c593e
Update native-url version
janicklas-ralph Dec 16, 2019
51be1b0
Merge branch 'canary' into native-url
Timer Jan 14, 2020
a93355e
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Feb 14, 2020
72b7243
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Feb 14, 2020
a323b44
Adding native-url with safari fix
janicklas-ralph Feb 14, 2020
84d8b6d
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Feb 14, 2020
dd1f2f2
Merge branch 'canary' into native-url
Timer Feb 21, 2020
a160364
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Feb 28, 2020
2485d0a
Update url-polyfill in polyfill-nomodule package
janicklas-ralph Feb 28, 2020
6242b95
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Feb 28, 2020
51c5790
Remove url-polyfill from next package.json
janicklas-ralph Feb 28, 2020
03da713
Merge branch 'canary' into native-url
Timer Feb 28, 2020
344567a
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Mar 2, 2020
bdbd67a
Merge branch 'native-url' of github.com:janicklas-ralph/next.js into …
janicklas-ralph Mar 2, 2020
4697e83
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Mar 24, 2020
57eb6b4
Adding granularChunks conformance check
janicklas-ralph Mar 26, 2020
486bdd9
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Mar 26, 2020
c8c0740
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Mar 27, 2020
3a3dca3
Fixed error
janicklas-ralph Mar 27, 2020
e6e9167
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 1, 2020
f8b3edc
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 4, 2020
1f91d4b
Updating native-url version
janicklas-ralph Apr 4, 2020
2191728
Revert "Updating native-url version"
janicklas-ralph Apr 4, 2020
d307103
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 6, 2020
a8431e6
Fix review comment
janicklas-ralph Apr 6, 2020
85c45d2
Fix TS error
janicklas-ralph Apr 6, 2020
a96a5e0
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 6, 2020
8b6c255
Fix TS error
janicklas-ralph Apr 6, 2020
ecacb0b
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 15, 2020
a5e3072
Merge branch 'canary' of github.com:zeit/next.js into native-url
janicklas-ralph Apr 15, 2020
2f55404
Merge branch 'canary' into native-url
Timer May 20, 2020
fb85cff
apply lint
Timer May 20, 2020
33691f0
remove unused
Timer May 20, 2020
367baed
Merge branch 'canary' into native-url
kodiakhq[bot] May 20, 2020
4287a48
Merge branch 'canary' into native-url
Timer May 20, 2020
bd2d0eb
Merge branch 'canary' into native-url
kodiakhq[bot] May 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import WebpackConformancePlugin, {
DuplicatePolyfillsConformanceCheck,
MinificationConformanceCheck,
ReactSyncScriptsConformanceCheck,
GranularChunksConformanceCheck,
} from './webpack/plugins/webpack-conformance-plugin'
import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin'
import { codeFrameColumns } from '@babel/code-frame'
Expand Down Expand Up @@ -490,6 +491,9 @@ export default async function getBaseWebpackConfig(
?.BlockedAPIToBePolyfilled || []
),
},
GranularChunksConformanceCheck: {
enabled: true,
},
},
config.conformance
)
Expand Down Expand Up @@ -1019,6 +1023,12 @@ export default async function getBaseWebpackConfig(
conformanceConfig.DuplicatePolyfillsConformanceCheck
.BlockedAPIToBePolyfilled,
}),
!isServer &&
config.experimental.granularChunks &&
conformanceConfig.GranularChunksConformanceCheck.enabled &&
new GranularChunksConformanceCheck(
splitChunksConfigs.prodGranular
),
].filter(Boolean),
}),
new WellKnownErrorsPlugin(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import chalk from 'chalk'
import {
IWebpackConformanceTest,
IConformanceTestResult,
IConformanceTestStatus,
} from '../TestInterface'
import {
CONFORMANCE_ERROR_PREFIX,
CONFORMANCE_WARNING_PREFIX,
} from '../constants'
import { deepEqual } from '../utils/utils'

export interface GranularChunksConformanceCheck
extends IWebpackConformanceTest {
granularChunksConfig: any
}

function getWarningMessage(modifiedProp: string) {
return (
`${CONFORMANCE_WARNING_PREFIX}: The splitChunks config as part of the granularChunks flag has ` +
`been carefully crafted to optimize build size and build times. Modifying - ${chalk.bold(
modifiedProp
)} could result in slower builds and increased code duplication`
)
}

function getErrorMessage(message: string) {
return (
`${CONFORMANCE_ERROR_PREFIX}: The splitChunks config as part of the granularChunks flag has ` +
`been carefully crafted to optimize build size and build times. Please avoid changes to ${chalk.bold(
message
)}`
)
}

export class GranularChunksConformanceCheck {
constructor(granularChunksConfig: any) {
this.granularChunksConfig = granularChunksConfig
}

public buildStared(options: any): IConformanceTestResult {
const userSplitChunks = options.optimization.splitChunks
const warnings = []
const errors = []

if (
userSplitChunks.maxInitialRequests !==
this.granularChunksConfig.maxInitialRequests
) {
warnings.push('splitChunks.maxInitialRequests')
}

if (userSplitChunks.minSize !== this.granularChunksConfig.minSize) {
warnings.push('splitChunks.minSize')
}

const userCacheGroup = userSplitChunks.cacheGroups
const originalCacheGroup = this.granularChunksConfig.cacheGroups

if (userCacheGroup.vendors !== false) {
errors.push('splitChunks.cacheGroups.vendors')
}

if (!deepEqual(userCacheGroup.framework, originalCacheGroup.framework)) {
errors.push('splitChunks.cacheGroups.framework')
}

if (!deepEqual(userCacheGroup.lib, originalCacheGroup.lib)) {
errors.push('splitChunks.cacheGroups.lib')
}

if (!deepEqual(userCacheGroup.commons, originalCacheGroup.commons)) {
errors.push('splitChunks.cacheGroups.commons')
}

if (!deepEqual(userCacheGroup.shared, originalCacheGroup.shared)) {
errors.push('splitChunks.cacheGroups.shared')
}

if (!warnings.length && !errors.length) {
return {
result: IConformanceTestStatus.SUCCESS,
}
}

const failedResult: IConformanceTestResult = {
result: IConformanceTestStatus.FAILED,
}

if (warnings.length) {
failedResult.warnings = warnings.map((warning) => ({
message: getWarningMessage(warning),
}))
}

if (errors.length) {
failedResult.warnings = errors.map((error) => ({
message: getErrorMessage(error),
}))
}

return failedResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { visit } from 'next/dist/compiled/recast'
export { MinificationConformanceCheck } from './checks/minification-conformance-check'
export { ReactSyncScriptsConformanceCheck } from './checks/react-sync-scripts-conformance-check'
export { DuplicatePolyfillsConformanceCheck } from './checks/duplicate-polyfills-conformance-check'
export { GranularChunksConformanceCheck } from './checks/granular-chunks-conformance'

export interface IWebpackConformancePluginOptions {
tests: IWebpackConformanceTest[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const assert = require('assert').strict

export function deepEqual(a: any, b: any) {
try {
assert.deepStrictEqual(a, b)
return true
} catch (_) {
return false
}
}
12 changes: 12 additions & 0 deletions test/integration/conformance/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ module.exports = {
experimental: {
conformance: true,
},
webpack(cfg, { dev, isServer }) {
if (!dev && !isServer) {
cfg.optimization.splitChunks.cacheGroups.vendors = {
chunks: 'initial',
name: 'vendor',
test: 'vendor',
enforce: true,
}
}

return cfg
},
}
13 changes: 12 additions & 1 deletion test/integration/conformance/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-env jest */

import { join } from 'path'
import chalk from 'chalk'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'

const appDir = join(__dirname, '../')
jest.setTimeout(1000 * 60 * 2)
Expand All @@ -28,4 +29,14 @@ describe('Conformance system', () => {
'[BUILD CONFORMANCE WARNING]: Found polyfill.io loading polyfill for fetch.'
)
})

it('Should warn about changes to granularChunks config', async () => {
const { stderr } = build
expect(stderr).toContain(
'[BUILD CONFORMANCE ERROR]: The splitChunks config as part of the granularChunks flag has ' +
`been carefully crafted to optimize build size and build times. Please avoid changes to ${chalk.bold(
'splitChunks.cacheGroups.vendors'
)}`
)
})
})