Skip to content

Commit

Permalink
fix: prefix manifest paths, fixes #18497
Browse files Browse the repository at this point in the history
  • Loading branch information
moonmeister committed Dec 20, 2019
1 parent 480eefc commit 9c81f3c
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function checkCache(cache, icon, srcIcon, srcIconDigest, callback) {
}

exports.onPostBootstrap = async (
{ reporter, parentSpan },
{ reporter, parentSpan, basePath },
{ localize, ...manifest }
) => {
const activity = reporter.activityTimer(`Build manifest and related icons`, {
Expand All @@ -68,7 +68,7 @@ exports.onPostBootstrap = async (

let cache = new Map()

await makeManifest(cache, reporter, manifest)
await makeManifest({ cache, reporter, pluginOptions: manifest, basePath })

if (Array.isArray(localize)) {
const locales = [...localize]
Expand All @@ -84,23 +84,44 @@ exports.onPostBootstrap = async (
cacheModeOverride = { cache_busting_mode: `name` }
}

return makeManifest(
return makeManifest({
cache,
reporter,
{
pluginOptions: {
...manifest,
...locale,
...cacheModeOverride,
},
true
)
shouldLocalize: true,
basePath,
})
})
)
}
activity.end()
}

const makeManifest = async (cache, reporter, pluginOptions, shouldLocalize) => {
/**
* The complete Triforce, or one or more components of the Triforce.
* @typedef {Object} makeManifestArgs
* @property {Object} cache - from gatsby-node api
* @property {Object} reporter - from gatsby-node api
* @property {Object} pluginOptions - from gatsby-node api/gatsby config
* @property {boolean} shouldLocalize
* @property {string} basePath - string of base path frpvided by gatsby node
*/

/**
* Build manifest
* @param {makeManifestArgs}
*/
const makeManifest = async ({
cache,
reporter,
pluginOptions,
shouldLocalize = false,
basePath = ``,
}) => {
const { icon, ...manifest } = pluginOptions
const suffix =
shouldLocalize && pluginOptions.lang ? `_${pluginOptions.lang}` : ``
Expand Down Expand Up @@ -196,6 +217,11 @@ const makeManifest = async (cache, reporter, pluginOptions, shouldLocalize) => {
}
}

//Fix #18497 by prefixing paths
manifest.icons = manifest.icons.map(icon => {
return { ...icon, src: path.join(basePath, icon.src) }
})

//Write manifest
fs.writeFileSync(
path.join(`public`, `manifest${suffix}.webmanifest`),
Expand Down

0 comments on commit 9c81f3c

Please sign in to comment.