diff --git a/package.json b/package.json index 0f64bd6e866aadedb2e7dba9cdb59b7666b473c3..af94fb5f66b0d5611d2fd287e0c3aff286bf2cd5 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ }, "pre-commit": "lint-staged", "lint-staged": { - "*.js": "standard --fix", - "*.ts": "standard --parser typescript-eslint-parser --plugin typescript --fix", - "packages/**/bin/*": "standard" + "*.js": ["standard --fix", "git add"], + "*.ts": ["standard --parser typescript-eslint-parser --plugin typescript --fix", "git add"], + "packages/**/bin/*": ["standard --fix", "git add"] }, "standard": { "parser": "babel-eslint", diff --git a/packages/next/README.md b/packages/next/README.md index dc8bff327eb63b09e4c5bf72fc037424c9404839..64c2b9f36175479f09a10e0f961756674937c8d5 100644 --- a/packages/next/README.md +++ b/packages/next/README.md @@ -1206,8 +1206,6 @@ Or use a function: ```js module.exports = (phase, {defaultConfig}) => { - // - // https://github.com/zeit/ return { /* config options here */ } @@ -1296,6 +1294,21 @@ module.exports = { } ``` +To fall back to the default of generating a unique id return `null` from the function: + +```js +module.exports = { + generateBuildId: async () => { + // When process.env.YOUR_BUILD_ID is undefined we fall back to the default + if(process.env.YOUR_BUILD_ID) { + return process.env.YOUR_BUILD_ID + } + + return null + } +} +``` + ### Customizing webpack config
diff --git a/test/integration/production-config/next.config.js b/test/integration/production-config/next.config.js index 3b08c56e12840b251832759b1e7b5d7affdb1649..4d8a001d1d99133cff8172669e7c4dfa38f2b026 100644 --- a/test/integration/production-config/next.config.js +++ b/test/integration/production-config/next.config.js @@ -19,5 +19,8 @@ module.exports = withCSS(withSass({ } return config + }, + async generateBuildId () { + return 'custom-buildid' } })) diff --git a/test/integration/production-config/test/index.test.js b/test/integration/production-config/test/index.test.js index 4b93863a4c6886c28cbb5905e2d5786e7282a18e..ff787be6b50abdf8baab8275c68357d47a4d818a 100644 --- a/test/integration/production-config/test/index.test.js +++ b/test/integration/production-config/test/index.test.js @@ -11,6 +11,7 @@ import webdriver from 'next-webdriver' jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 +let appPort let server describe('Production Config Usage', () => { @@ -23,6 +24,7 @@ describe('Production Config Usage', () => { quiet: true }) server = await startApp(app) + appPort = server.address().port }) afterAll(() => stopApp(server)) @@ -34,10 +36,22 @@ describe('Production Config Usage', () => { await testBrowser() }) }) + + describe('with generateBuildId', () => { + it('should add the custom buildid', async () => { + const browser = await webdriver(appPort, '/') + const text = await browser.elementByCss('#mounted').text() + expect(text).toMatch(/ComponentDidMount executed on client\./) + + const html = await browser.elementByCss('html').getAttribute('innerHTML') + expect(html).toMatch('custom-buildid') + return browser.close() + }) + }) }) async function testBrowser () { - const browser = await webdriver(server.address().port, '/') + const browser = await webdriver(appPort, '/') const element = await browser.elementByCss('#mounted') const text = await element.text() expect(text).toMatch(/ComponentDidMount executed on client\./)