Skip to content

Commit

Permalink
fix(gatsby-source-filesystem): Update createRemoteFileNode args (#3…
Browse files Browse the repository at this point in the history
…5422)

* 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 <ward@coding-tech.com>
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
3 people committed Jun 1, 2022
1 parent 4c180eb commit caaf7a5
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 55 deletions.
Expand Up @@ -16,7 +16,6 @@ exports.sourceNodes = ({ actions, createNodeId, store, cache }) =>
fileNode = await createRemoteFileNode({
url: url,
parentNodeId: nodeId,
store,
cache,
createNode: actions.createNode,
createNodeId,
Expand Down
1 change: 0 additions & 1 deletion benchmarks/source-agilitycms/gatsby-node.js
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions examples/using-gatsby-source-graphql/gatsby-node.js
Expand Up @@ -59,11 +59,9 @@ exports.createResolvers = ({
resolve(source, args, context, info) {
return createRemoteFileNode({
url: source.url,
store,
cache,
createNode,
createNodeId,
reporter,
})
},
},
Expand Down
Expand Up @@ -69,7 +69,6 @@ export async function writeImages({
sourceDir,
createNodeId,
createNode,
store,
filename,
}: {
images: Map<string, IStaticImageProps>
Expand All @@ -80,7 +79,6 @@ export async function writeImages({
sourceDir: string
createNodeId: ParentSpanPluginArgs["createNodeId"]
createNode: Actions["createNode"]
store: Store
filename: string
}): Promise<void> {
const promises = [...images.entries()].map(
Expand All @@ -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)
Expand Down
Expand Up @@ -74,7 +74,6 @@ export async function preprocessSource({
sourceDir,
createNodeId,
createNode,
store,
filename,
})

Expand Down
Expand Up @@ -78,11 +78,9 @@ export async function downloadContentfulAssets(gatsbyFunctions) {
if (!fileNodeID) {
const fileNode = await createRemoteFileNode({
url,
store,
cache,
createNode,
createNodeId,
reporter,
})

if (fileNode) {
Expand Down
2 changes: 0 additions & 2 deletions packages/gatsby-source-drupal/src/normalize.js
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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(),
}
Expand Down
@@ -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`, () => {
Expand Down Expand Up @@ -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`,
}
Expand Down
Expand Up @@ -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}
Expand All @@ -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]
*/

/******************
Expand Down
10 changes: 1 addition & 9 deletions packages/gatsby-source-shopify/src/helpers.ts
Expand Up @@ -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<void> {
const type = parseShopifyId(node.shopifyId)[1]
Expand All @@ -122,8 +116,6 @@ export async function processShopifyImages(
createNode,
createNodeId,
parentNodeId: node.id,
store,
reporter,
})

image.localFile___NODE = fileNode.id
Expand Down
Expand Up @@ -265,11 +265,9 @@ export const createLocalFileNode = async ({

const createFileNodeRequirements = {
parentNodeId: mediaItemNode.id,
store: gatsbyStore,
cache,
createNode,
createNodeId,
reporter,
}

let remoteFileNode
Expand Down Expand Up @@ -322,6 +320,7 @@ export const createLocalFileNode = async ({
url: mediaItemUrl,
auth,
...createFileNodeRequirements,
reporter,
pluginOptions,
})

Expand Down
2 changes: 0 additions & 2 deletions packages/gatsby-transformer-screenshot/src/gatsby-node.js
Expand Up @@ -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

Expand Down

0 comments on commit caaf7a5

Please sign in to comment.