From 085d1888481881456bbaf4a988cfb7578f28f0d9 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 2 Nov 2020 12:01:54 -0800 Subject: [PATCH] fix(gatsby-plugin-manifest): create directories recursively (#27793) * fix(gatsby-plugin-manifest): create directories recursively It's possible to have directories nested multiple layers deep or potentially that `public` isn't defined. * fix typo * fix tests --- .../gatsby-plugin-manifest/src/__tests__/gatsby-node.js | 8 ++++++-- packages/gatsby-plugin-manifest/src/gatsby-node.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js index 01417574e9a5d..2cc398f6d5213 100644 --- a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js @@ -166,8 +166,12 @@ describe(`Test plugin manifest options`, () => { // No sharp calls because this is manual mode: user provides all icon sizes // rather than the plugin generating them expect(sharp).toHaveBeenCalledTimes(0) - expect(fs.mkdirSync).toHaveBeenNthCalledWith(1, firstIconPath) - expect(fs.mkdirSync).toHaveBeenNthCalledWith(2, secondIconPath) + expect(fs.mkdirSync).toHaveBeenNthCalledWith(1, firstIconPath, { + recursive: true, + }) + expect(fs.mkdirSync).toHaveBeenNthCalledWith(2, secondIconPath, { + recursive: true, + }) }) it(`invokes sharp if icon argument specified`, async () => { diff --git a/packages/gatsby-plugin-manifest/src/gatsby-node.js b/packages/gatsby-plugin-manifest/src/gatsby-node.js index c079e42fa934c..1df0107bd3767 100644 --- a/packages/gatsby-plugin-manifest/src/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/gatsby-node.js @@ -218,7 +218,7 @@ const makeManifest = async ({ const exists = fs.existsSync(iconPath) //create destination directory if it doesn't exist if (!exists) { - fs.mkdirSync(iconPath) + fs.mkdirSync(iconPath, { recursive: true }) } paths[iconPath] = true }