Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-offline): Run app-shell.js from user cache directory for pnp compatibility #22351

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/gatsby-plugin-offline/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// use `let` to workaround https://github.com/jhnns/rewire/issues/144
let fs = require(`fs`)
let workboxBuild = require(`workbox-build`)
const { promisify } = require(`util`)
const path = require(`path`)
const { slash } = require(`gatsby-core-utils`)
const glob = require(`glob`)
const _ = require(`lodash`)

const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
let getResourcesFromHTML = require(`./get-resources-from-html`)

exports.createPages = ({ actions }) => {
exports.onPreBootstrap = async ({ cache }) => {
const appShellDir = cache.directory
const appShellSourcePath = path.join(__dirname, `app-shell.js`)
const appShellTargetPath = path.join(appShellDir, `app-shell.js`)
const appShellSource = await readFile(appShellSourcePath)

await writeFile(appShellTargetPath, appShellSource)
pieh marked this conversation as resolved.
Show resolved Hide resolved
}

exports.createPages = ({ actions, cache }) => {
const appShellPath = path.join(cache.directory, `app-shell.js`)
if (process.env.NODE_ENV === `production`) {
const { createPage } = actions
createPage({
path: `/offline-plugin-app-shell-fallback/`,
component: slash(path.resolve(`${__dirname}/app-shell.js`)),
component: slash(appShellPath),
})
}
}
Expand Down