Ensure Deterministic Builds (#845)
* add klaw-sync dep, add postbuild script * specify exact klaw-sync version
This commit is contained in:
parent
d9c7e33bc1
commit
446cc96de1
|
@ -89,6 +89,7 @@
|
|||
"husky": "0.14.3",
|
||||
"image-webpack-loader": "3.4.2",
|
||||
"jest": "22.1.1",
|
||||
"klaw-sync": "3.0.2",
|
||||
"less": "2.7.3",
|
||||
"less-loader": "4.0.5",
|
||||
"lint-staged": "6.0.0",
|
||||
|
@ -130,6 +131,7 @@
|
|||
"db": "nodemon ./db",
|
||||
"build": "rimraf dist && webpack --config webpack_config/webpack.prod.js",
|
||||
"prebuild": "check-node-version --package",
|
||||
"postbuild": "node ./utils/postBuild.js",
|
||||
"build:downloadable": "BUILD_DOWNLOADABLE=true rimraf dist && webpack --config webpack_config/webpack.prod.js",
|
||||
"prebuild:demo": "check-node-version --package",
|
||||
"test:coverage": "jest --config=jest_config/jest.config.json --coverage",
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
/**
|
||||
* (1) Parses the '.cache' file in the 'dist/icons' folder
|
||||
* (2) Sorts the 'cache.result.files' property
|
||||
* (3) Rewrites the file to ensure a deterministic build
|
||||
*/
|
||||
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const klawSync = require('klaw-sync')
|
||||
|
||||
const DIST_PATH = path.resolve('./dist/')
|
||||
const CACHE_FILE_REGEX = /.*icons-[a-z0-9]*\/\.cache$/
|
||||
|
||||
const findCacheFile = item => CACHE_FILE_REGEX.test(item.path)
|
||||
|
||||
console.log('postBuild start')
|
||||
|
||||
try {
|
||||
const cacheFilePaths = klawSync(DIST_PATH, { filter: findCacheFile })
|
||||
|
||||
if (!cacheFilePaths.length) {
|
||||
throw new Error('Could not find .cache file')
|
||||
}
|
||||
|
||||
if (cacheFilePaths.length > 1) {
|
||||
throw new Error('More than one possible .cache file detected')
|
||||
}
|
||||
|
||||
const cacheFilePath = cacheFilePaths[0].path
|
||||
const rawCacheFile = fs.readFileSync(cacheFilePath, 'utf8')
|
||||
const cache = JSON.parse(rawCacheFile)
|
||||
|
||||
cache.result.files = cache.result.files.sort()
|
||||
|
||||
fs.writeFileSync(cacheFilePath, JSON.stringify(cache), 'utf8')
|
||||
|
||||
} catch(err) {
|
||||
console.log('postBuild fail', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('postBuild finish')
|
||||
|
||||
|
Loading…
Reference in New Issue