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-source-filesystem): Update createRemoteFileNode args #35422

Merged
merged 6 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export async function preprocessSource({
sourceDir,
createNodeId,
createNode,
store,
filename,
})

Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 [email protected])
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 [email protected])
cache: NodePluginArgs["cache"]
cache?: GatsbyCache
getCache?: Function
createNode: Function
createNodeId: Function
parentNodeId?: string
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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