forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webpack): webpackCompilationHash loaded in app-data file
The webpackCompilationHash is loaded in a new app-data.json file to reduce the blast radius of src changes on generated files gatsbyjs#15872
- Loading branch information
Showing
8 changed files
with
75 additions
and
79 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
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,18 @@ | ||
const fs = require(`fs-extra`) | ||
const path = require(`path`) | ||
|
||
const APP_DATA_JSON = `app-data.json` | ||
|
||
const write = (publicDir, hash) => { | ||
fs.writeJson(path.join(publicDir, APP_DATA_JSON), { | ||
appHash: hash, | ||
}) | ||
} | ||
|
||
const exists = publicDir => | ||
fs.pathExistsSync(path.join(publicDir, APP_DATA_JSON)) | ||
|
||
module.exports = { | ||
write, | ||
exists, | ||
} |
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 |
---|---|---|
@@ -1,32 +1,10 @@ | ||
const fs = require(`fs-extra`) | ||
const path = require(`path`) | ||
const Promise = require(`bluebird`) | ||
|
||
const getFilePath = ({ publicDir }, pagePath) => { | ||
const fixedPagePath = pagePath === `/` ? `index` : pagePath | ||
return path.join(publicDir, `page-data`, fixedPagePath, `page-data.json`) | ||
} | ||
|
||
const updateJsonFileField = async (filename, fieldname, value) => { | ||
const object = JSON.parse(await fs.readFile(filename, `utf-8`)) | ||
object[fieldname] = value | ||
await fs.outputFile(filename, JSON.stringify(object), `utf-8`) | ||
} | ||
|
||
const updateCompilationHashes = ( | ||
{ publicDir }, | ||
pagePaths, | ||
webpackCompilationHash | ||
) => | ||
Promise.map(pagePaths, pagePath => | ||
updateJsonFileField( | ||
getFilePath({ publicDir }, pagePath), | ||
`webpackCompilationHash`, | ||
webpackCompilationHash | ||
) | ||
) | ||
|
||
module.exports = { | ||
getFilePath, | ||
updateCompilationHashes, | ||
} |