Skip to content

Commit

Permalink
V2 - Switch Sources and Transformers to use createNodeId for ids (gat…
Browse files Browse the repository at this point in the history
…sbyjs#3807)

* Switch Sources and Transformers to use createNodeId for ids

* Only use createNodeId if an id isn't passed in

* Remove unused imports
  • Loading branch information
danielfarrell authored and KyleAMathews committed Feb 10, 2018
1 parent 18fc8d9 commit e519a5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/__tests__/create-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const { createFileNode } = require(`../create-file-node`)
// FIXME: This test needs to not use snapshots because of file differences
// and locations across users and CI systems
describe(`create-file-node`, () => {
it(`creates a file node`, () =>
createFileNode(path.resolve(`${__dirname}/fixtures/file.json`), {}))
it(`creates a file node`, () => {
const createNodeId = jest.fn()
createNodeId.mockReturnValue(`uuid-from-gatsby`)
return createFileNode(path.resolve(`${__dirname}/fixtures/file.json`), createNodeId, {})
})
})
4 changes: 2 additions & 2 deletions src/create-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const createId = path => {

exports.createId = createId

exports.createFileNode = async (pathToFile, pluginOptions = {}) => {
exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}) => {
const slashed = slash(pathToFile)
const parsedSlashed = path.parse(slashed)
const slashedFile = {
Expand Down Expand Up @@ -56,7 +56,7 @@ exports.createFileNode = async (pathToFile, pluginOptions = {}) => {
// Don't actually make the File id the absolute path as otherwise
// people will use the id for that and ids shouldn't be treated as
// useful information.
id: createId(pathToFile),
id: createNodeId(pathToFile),
children: [],
parent: `___SOURCE___`,
internal,
Expand Down
4 changes: 2 additions & 2 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require(`fs`)
const { createId, createFileNode } = require(`./create-file-node`)

exports.sourceNodes = (
{ actions, getNode, hasNodeChanged, reporter },
{ actions, getNode, createNodeId, hasNodeChanged, reporter },
pluginOptions
) => {
const { createNode, deleteNode } = actions
Expand Down Expand Up @@ -36,7 +36,7 @@ Please pick a path to an existing directory.
})

const createAndProcessNode = path =>
createFileNode(path, pluginOptions).then(createNode)
createFileNode(path, createNodeId, pluginOptions).then(createNode)

// For every path that is reported before the 'ready' event, we throw them
// into a queue and then flush the queue when 'ready' event arrives.
Expand Down

0 comments on commit e519a5b

Please sign in to comment.