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): use correct hash when using createFileNodeFromBuffer #35243

Merged
merged 3 commits into from Mar 30, 2022
Merged

fix(gatsby-source-filesystem): use correct hash when using createFileNodeFromBuffer #35243

merged 3 commits into from Mar 30, 2022

Conversation

g00glen00b
Copy link
Contributor

Description

This pull request fixes the inconsistency within createFileNodeFromBuffer() function of gatsby-source-filesystem if a hash is calculated and not provided.

The name argument of this function has a default value of hash. However, the hash parameter is optional. if not given, it is calculated within the same function. In this case, name remains undefined, which throws an error when createFilePath() is called.

In previous versions of Gatsby, the behaviour was also consistent, but didn't throw an error. In stead, the filename would have been undefined.

This pull request fixes that inconsistency by setting the name default after calculating the hash.

I also added two tests:

  1. A test to verify the behavior if hash is given but name isn't
  2. A test to verify the behavior if neither hash nor name is given (which would fail without this fix)

Documentation

This behavior was undocumented. I added a note about it to the README.md of gatsby-source-filesystem.

Related Issues

Addresses #35242

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 29, 2022
@wardpeet wardpeet changed the title Fix/create file node from buffer name default fix(gatsby-source-filesystem): create file node from buffer name default Mar 30, 2022
@wardpeet wardpeet changed the title fix(gatsby-source-filesystem): create file node from buffer name default fix(gatsby-source-filesystem): always use hash when using createFileNodeFromBuffer Mar 30, 2022
@wardpeet wardpeet changed the title fix(gatsby-source-filesystem): always use hash when using createFileNodeFromBuffer fix(gatsby-source-filesystem): use correct hash when using createFileNodeFromBuffer Mar 30, 2022
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing and adding these tests. This made the review extra easy!

@wardpeet wardpeet merged commit 54f643b into gatsbyjs:master Mar 30, 2022
@wardpeet wardpeet added topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 30, 2022
mwfrost pushed a commit to mwfrost/gatsby that referenced this pull request Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants