From caaf7a555bb42043044f05743eec0ac1ad372cc4 Mon Sep 17 00:00:00 2001 From: Hritwik Som <51828849+Apprentice76@users.noreply.github.com> Date: Wed, 1 Jun 2022 13:47:18 +0530 Subject: [PATCH] fix(gatsby-source-filesystem): Update `createRemoteFileNode` args (#35422) * fixes issue #35363 and CreateFileNodeFromBufferArgs * modified tests for remote-file-node and file-node-from-buffer * updated function calls in dependencies * removed unused typescript imports Co-authored-by: Ward Peeters Co-authored-by: Michal Piechowiak --- .../gatsby-source-remote-images/gatsby-node.js | 1 - benchmarks/source-agilitycms/gatsby-node.js | 1 - .../gatsby-source-remote-images/gatsby-node.js | 2 -- examples/using-gatsby-source-graphql/gatsby-node.js | 2 -- .../src/node-apis/image-processing.ts | 4 ---- .../src/node-apis/preprocess-source.ts | 1 - .../src/download-contentful-assets.js | 2 -- packages/gatsby-source-drupal/src/normalize.js | 2 -- packages/gatsby-source-filesystem/index.d.ts | 13 +++++-------- .../src/__tests__/create-file-node-from-buffer.js | 9 --------- .../src/__tests__/create-remote-file-node.js | 4 ---- .../src/create-remote-file-node.js | 6 ------ packages/gatsby-source-shopify/src/helpers.ts | 10 +--------- .../create-nodes/create-local-file-node.js | 3 +-- .../src/gatsby-node.js | 2 -- 15 files changed, 7 insertions(+), 55 deletions(-) diff --git a/benchmarks/image-processing/plugins/gatsby-source-remote-images/gatsby-node.js b/benchmarks/image-processing/plugins/gatsby-source-remote-images/gatsby-node.js index 970d07329dd22..d1884b5a68775 100644 --- a/benchmarks/image-processing/plugins/gatsby-source-remote-images/gatsby-node.js +++ b/benchmarks/image-processing/plugins/gatsby-source-remote-images/gatsby-node.js @@ -16,7 +16,6 @@ exports.sourceNodes = ({ actions, createNodeId, store, cache }) => fileNode = await createRemoteFileNode({ url: url, parentNodeId: nodeId, - store, cache, createNode: actions.createNode, createNodeId, diff --git a/benchmarks/source-agilitycms/gatsby-node.js b/benchmarks/source-agilitycms/gatsby-node.js index 86648f9fb6261..12698196dee09 100644 --- a/benchmarks/source-agilitycms/gatsby-node.js +++ b/benchmarks/source-agilitycms/gatsby-node.js @@ -46,7 +46,6 @@ exports.onCreateNode = async ({ createNode, // helper function in gatsby-node to generate the node createNodeId, // helper function in gatsby-node to generate the node id cache, // Gatsby's cache - store, // Gatsby's redux store }) // if the file was created, attach the new node to the parent node if (fileNode) { diff --git a/examples/using-gatsby-image/plugins/gatsby-source-remote-images/gatsby-node.js b/examples/using-gatsby-image/plugins/gatsby-source-remote-images/gatsby-node.js index 183f957c9ec3c..00a7dbc2e03fb 100644 --- a/examples/using-gatsby-image/plugins/gatsby-source-remote-images/gatsby-node.js +++ b/examples/using-gatsby-image/plugins/gatsby-source-remote-images/gatsby-node.js @@ -14,11 +14,9 @@ exports.onCreateNode = async ( if (filter(node)) { const fileNode = await createRemoteFileNode({ url: node.url, - store, cache, createNode, createNodeId: createContentDigest, - reporter, }) if (fileNode) { diff --git a/examples/using-gatsby-source-graphql/gatsby-node.js b/examples/using-gatsby-source-graphql/gatsby-node.js index 1e899b90e5968..07b350ffc5aa6 100644 --- a/examples/using-gatsby-source-graphql/gatsby-node.js +++ b/examples/using-gatsby-source-graphql/gatsby-node.js @@ -59,11 +59,9 @@ exports.createResolvers = ({ resolve(source, args, context, info) { return createRemoteFileNode({ url: source.url, - store, cache, createNode, createNodeId, - reporter, }) }, }, diff --git a/packages/gatsby-plugin-image/src/node-apis/image-processing.ts b/packages/gatsby-plugin-image/src/node-apis/image-processing.ts index c89e01717f25d..d02d73312420e 100644 --- a/packages/gatsby-plugin-image/src/node-apis/image-processing.ts +++ b/packages/gatsby-plugin-image/src/node-apis/image-processing.ts @@ -69,7 +69,6 @@ export async function writeImages({ sourceDir, createNodeId, createNode, - store, filename, }: { images: Map @@ -80,7 +79,6 @@ export async function writeImages({ sourceDir: string createNodeId: ParentSpanPluginArgs["createNodeId"] createNode: Actions["createNode"] - store: Store filename: string }): Promise { const promises = [...images.entries()].map( @@ -103,11 +101,9 @@ export async function writeImages({ try { file = await createRemoteFileNode({ url: src, - store, cache, createNode, createNodeId, - reporter, }) } catch (err) { reporter.error(`Error loading image ${src}`, err) diff --git a/packages/gatsby-plugin-image/src/node-apis/preprocess-source.ts b/packages/gatsby-plugin-image/src/node-apis/preprocess-source.ts index b2da405571d2f..f0f505e2d95ca 100644 --- a/packages/gatsby-plugin-image/src/node-apis/preprocess-source.ts +++ b/packages/gatsby-plugin-image/src/node-apis/preprocess-source.ts @@ -74,7 +74,6 @@ export async function preprocessSource({ sourceDir, createNodeId, createNode, - store, filename, }) diff --git a/packages/gatsby-source-contentful/src/download-contentful-assets.js b/packages/gatsby-source-contentful/src/download-contentful-assets.js index a6c0c28d0e653..93834e9d7b13d 100644 --- a/packages/gatsby-source-contentful/src/download-contentful-assets.js +++ b/packages/gatsby-source-contentful/src/download-contentful-assets.js @@ -78,11 +78,9 @@ export async function downloadContentfulAssets(gatsbyFunctions) { if (!fileNodeID) { const fileNode = await createRemoteFileNode({ url, - store, cache, createNode, createNodeId, - reporter, }) if (fileNode) { diff --git a/packages/gatsby-source-drupal/src/normalize.js b/packages/gatsby-source-drupal/src/normalize.js index 05ffdddbcf10a..eff3539134ca1 100644 --- a/packages/gatsby-source-drupal/src/normalize.js +++ b/packages/gatsby-source-drupal/src/normalize.js @@ -263,14 +263,12 @@ exports.downloadFile = async ( const fileNode = await createRemoteFileNode({ url: url.href, name: path.parse(decodeURIComponent(url.pathname)).name, - store, cache, createNode, createNodeId, getCache, parentNodeId: node.id, auth, - reporter, }) if (fileNode) { node.localFile___NODE = fileNode.id diff --git a/packages/gatsby-source-filesystem/index.d.ts b/packages/gatsby-source-filesystem/index.d.ts index 2d578b9e1a3da..63bb687a6e7d0 100644 --- a/packages/gatsby-source-filesystem/index.d.ts +++ b/packages/gatsby-source-filesystem/index.d.ts @@ -1,4 +1,4 @@ -import { Node, Store, NodePluginArgs } from "gatsby" +import { Node, GatsbyCache } from "gatsby" /** * @see https://www.gatsbyjs.com/plugins/gatsby-source-filesystem/?=files#createfilepath @@ -28,9 +28,8 @@ export interface CreateFilePathArgs { export interface CreateRemoteFileNodeArgs { url: string - store: Store - // TODO: use GatsbyCache type (requires gatsby@2.22.13) - cache: NodePluginArgs["cache"] + cache?: GatsbyCache + getCache?: Function createNode: Function createNodeId: Function parentNodeId?: string @@ -41,14 +40,12 @@ export interface CreateRemoteFileNodeArgs { httpHeaders?: object ext?: string name?: string - reporter: object } export interface CreateFileNodeFromBufferArgs { buffer: Buffer - store: Store - // TODO: use GatsbyCache type (requires gatsby@2.22.13) - cache: NodePluginArgs["cache"] + cache?: GatsbyCache + getCache?: Function createNode: Function createNodeId: Function parentNodeId?: string diff --git a/packages/gatsby-source-filesystem/src/__tests__/create-file-node-from-buffer.js b/packages/gatsby-source-filesystem/src/__tests__/create-file-node-from-buffer.js index 44961e9bbf77a..54fef1c650fb4 100644 --- a/packages/gatsby-source-filesystem/src/__tests__/create-file-node-from-buffer.js +++ b/packages/gatsby-source-filesystem/src/__tests__/create-file-node-from-buffer.js @@ -40,15 +40,6 @@ const bufferEq = (b1, b2) => Buffer.compare(b1, b2) === 0 describe(`create-file-node-from-buffer`, () => { const defaultArgs = { - store: { - getState: jest.fn(() => { - return { - program: { - directory: `__whatever__`, - }, - } - }), - }, createNode: jest.fn(), createNodeId: jest.fn(), } diff --git a/packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js b/packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js index ac8973319efa0..95207faabbd5d 100644 --- a/packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js +++ b/packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js @@ -1,7 +1,5 @@ import { fetchRemoteFile } from "gatsby-core-utils/fetch-remote-file" -const reporter = {} - const createRemoteFileNode = require(`../create-remote-file-node`) jest.mock(`gatsby-core-utils/fetch-remote-file`, () => { @@ -33,11 +31,9 @@ describe(`create-remote-file-node`, () => { const defaultArgs = { url: `https://external.com/dog.jpg`, - store: {}, getCache: () => cache, createNode: jest.fn(), createNodeId: jest.fn(() => String(uuid++)), - reporter, ext: `.jpg`, name: `dog-thumbnail`, } diff --git a/packages/gatsby-source-filesystem/src/create-remote-file-node.js b/packages/gatsby-source-filesystem/src/create-remote-file-node.js index 4b0645cba3166..fcdd38918a8e3 100644 --- a/packages/gatsby-source-filesystem/src/create-remote-file-node.js +++ b/packages/gatsby-source-filesystem/src/create-remote-file-node.js @@ -11,11 +11,6 @@ const { createFileNode } = require(`./create-file-node`) * @see gatsby/packages/gatsby/utils/cache.js */ -/** - * @typedef {Reporter} - * @see gatsby/packages/gatsby-cli/lib/reporter.js - */ - /** * @typedef {Auth} * @type {Object} @@ -33,7 +28,6 @@ const { createFileNode } = require(`./create-file-node`) * @param {Function} options.createNode * @param {Function} options.getCache * @param {Auth} [options.auth] - * @param {Reporter} [options.reporter] */ /****************** diff --git a/packages/gatsby-source-shopify/src/helpers.ts b/packages/gatsby-source-shopify/src/helpers.ts index d9873be209ccf..8e30ac29eb1a2 100644 --- a/packages/gatsby-source-shopify/src/helpers.ts +++ b/packages/gatsby-source-shopify/src/helpers.ts @@ -95,13 +95,7 @@ export function decorateBulkObject(input: unknown): unknown { } export async function processShopifyImages( - { - actions: { createNode }, - createNodeId, - cache, - store, - reporter, - }: SourceNodesArgs, + { actions: { createNode }, createNodeId, cache }: SourceNodesArgs, node: IShopifyNode ): Promise { const type = parseShopifyId(node.shopifyId)[1] @@ -122,8 +116,6 @@ export async function processShopifyImages( createNode, createNodeId, parentNodeId: node.id, - store, - reporter, }) image.localFile___NODE = fileNode.id diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/create-local-file-node.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/create-local-file-node.js index 0b5d80997a27e..99fcf7255a1eb 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/create-local-file-node.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/create-local-file-node.js @@ -265,11 +265,9 @@ export const createLocalFileNode = async ({ const createFileNodeRequirements = { parentNodeId: mediaItemNode.id, - store: gatsbyStore, cache, createNode, createNodeId, - reporter, } let remoteFileNode @@ -322,6 +320,7 @@ export const createLocalFileNode = async ({ url: mediaItemUrl, auth, ...createFileNodeRequirements, + reporter, pluginOptions, }) diff --git a/packages/gatsby-transformer-screenshot/src/gatsby-node.js b/packages/gatsby-transformer-screenshot/src/gatsby-node.js index 7e0c9971bd02f..b894a0d62b3bb 100644 --- a/packages/gatsby-transformer-screenshot/src/gatsby-node.js +++ b/packages/gatsby-transformer-screenshot/src/gatsby-node.js @@ -152,13 +152,11 @@ const createScreenshotNode = async ({ fileNode = await createRemoteFileNode({ url: screenshotResponse.data.url, - store, cache, createNode, createNodeId, getCache, parentNodeId, - reporter, }) expires = screenshotResponse.data.expires