Skip to content

Commit

Permalink
chore(gatsby): Convert utils/create-node-id to TypeScript (#22096)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Kasten <[email protected]>
  • Loading branch information
Pittan and blainekasten authored Mar 10, 2020
1 parent 955d357 commit 5f02fd0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/load-plugins/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const glob = require(`glob`)
const { warnOnIncompatiblePeerDependency } = require(`./validate`)
const { store } = require(`../../redux`)
const existsSync = require(`fs-exists-cached`).sync
const createNodeId = require(`../../utils/create-node-id`)
import { createNodeId } from "../../utils/create-node-id"
const { createRequireFromPath } = require(`gatsby-core-utils`)

function createFileContentHash(root, globPattern) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const stackTrace = require(`stack-trace`)
const { codeFrameColumns } = require(`@babel/code-frame`)
const fs = require(`fs-extra`)
const { getCache } = require(`./get-cache`)
const createNodeId = require(`./create-node-id`)
import { createNodeId } from "./create-node-id"
const { createContentDigest } = require(`gatsby-core-utils`)
const {
buildObjectType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const uuidv5 = require(`uuid/v5`)
const report = require(`gatsby-cli/lib/reporter`)
import uuidv5 from "uuid/v5"
import report from "gatsby-cli/lib/reporter"

const seedConstant = `638f7a53-c567-4eca-8fc1-b23efb1cfb2b`

/**
* createNodeId() Generate UUID
*
* @param {String} id - A string of arbitrary length
* @param {String | Number} id - A string of arbitrary length
* @param {String} namespace - Namespace to use for UUID
*
* @return {String} - UUID
*/
function createNodeId(id, namespace) {
export function createNodeId(id: string | number, namespace: string): string {
if (typeof id === `number`) {
id = id.toString()
} else if (typeof id !== `string`) {
Expand All @@ -22,5 +22,3 @@ function createNodeId(id, namespace) {

return uuidv5(id, uuidv5(namespace, seedConstant))
}

module.exports = createNodeId

0 comments on commit 5f02fd0

Please sign in to comment.