-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use next-build-id as module within Next 6 generateBuildId funct…
…ion (#6) BREAKING CHANGE: The next-build-id CLI has not changed, but module usage will no longer manually overwrite a BUILD_ID file unless a `write: true` option is given, so that the module can be used within generateBuildId from next.config.js to just lookup the current git commit hash.
- Loading branch information
Showing
9 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const nextBuildId = require('../../index') | ||
|
||
module.exports = (phase, nextConfig) => { | ||
if (process.env.NBI_TEST_CALL_DEFAULT_GENERATEBUILDID) console.log(nextConfig.defaultConfig.generateBuildId()) | ||
return { | ||
generateBuildId: () => nextBuildId({ dir: __dirname }).then(result => result.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "fixture", | ||
"version": "1.0.0", | ||
"description": "Fixture to test against Next.js 6", | ||
"private": true, | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "next build" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"next": "^6.0.3", | ||
"react": "^16.4.0", | ||
"react-dom": "^16.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => <div>Welcome to next.js!</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const path = require('path') | ||
|
||
const tap = require('tap') | ||
const rimraf = require('rimraf') | ||
|
||
const utils = require('./utils') | ||
|
||
const exec = utils.exec | ||
const mockedGitEnv = utils.mockedGitEnv | ||
const fixturePath = path.resolve(__dirname, 'fixture-next6') | ||
|
||
let npmi = false | ||
tap.beforeEach(() => { | ||
if (npmi) return Promise.resolve() | ||
npmi = true | ||
return exec('npm', 'i', fixturePath) | ||
}) | ||
|
||
tap.afterEach(() => { | ||
return Promise.all(['.next'].map(dir => { | ||
return new Promise((resolve, reject) => { | ||
rimraf(path.resolve(fixturePath, dir), err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
})) | ||
}) | ||
|
||
tap.test('with next.config.js that uses a generateBuildId function', t => { | ||
return exec('npm', 'run build', fixturePath, mockedGitEnv()) | ||
.then(io => { | ||
t.notOk(io.err) | ||
t.notOk(io.stderr) | ||
return utils.readTextFile(path.resolve(fixturePath, '.next', 'BUILD_ID')) | ||
}) | ||
.then(buildId => { | ||
t.equal(buildId, '0123456789abcdef0123456789abcdef01234567') | ||
}) | ||
}) | ||
|
||
tap.test('call stupid default generateBuildId for code coverage', t => { | ||
return exec('npm', 'run build', fixturePath, mockedGitEnv()) | ||
.then(() => { | ||
return exec(path.resolve(__dirname, '..', 'cli.js'), '', fixturePath, Object.assign(mockedGitEnv(), { NBI_TEST_CALL_DEFAULT_GENERATEBUILDID: true })) | ||
}) | ||
.then(io => { | ||
t.notOk(io.err) | ||
t.notOk(io.stderr) | ||
t.match(io.stdout, /9f2a37be-4545-445e-91bd/) | ||
t.match(io.stdout, /Build ID: 0123456789abcdef0123456789abcdef01234567/) | ||
t.match(io.stdout, /Updated:.*BUILD_ID/) | ||
return utils.readTextFile(path.resolve(fixturePath, '.next', 'BUILD_ID')) | ||
}) | ||
.then(buildId => { | ||
t.equal(buildId, '0123456789abcdef0123456789abcdef01234567') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters