From 5f02fd098b6b3a8c5730dee7006a78d9aa9fc2a3 Mon Sep 17 00:00:00 2001 From: Amon Keishima Date: Tue, 10 Mar 2020 17:34:57 +0900 Subject: [PATCH] chore(gatsby): Convert utils/create-node-id to TypeScript (#22096) Co-authored-by: Blaine Kasten --- packages/gatsby/src/bootstrap/load-plugins/load.js | 2 +- packages/gatsby/src/utils/api-runner-node.js | 2 +- .../src/utils/{create-node-id.js => create-node-id.ts} | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) rename packages/gatsby/src/utils/{create-node-id.js => create-node-id.ts} (68%) diff --git a/packages/gatsby/src/bootstrap/load-plugins/load.js b/packages/gatsby/src/bootstrap/load-plugins/load.js index 9547f3c5785d9..0591cffc217f1 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/load.js +++ b/packages/gatsby/src/bootstrap/load-plugins/load.js @@ -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) { diff --git a/packages/gatsby/src/utils/api-runner-node.js b/packages/gatsby/src/utils/api-runner-node.js index 4238d3c8c9302..e9c9b5e770f45 100644 --- a/packages/gatsby/src/utils/api-runner-node.js +++ b/packages/gatsby/src/utils/api-runner-node.js @@ -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, diff --git a/packages/gatsby/src/utils/create-node-id.js b/packages/gatsby/src/utils/create-node-id.ts similarity index 68% rename from packages/gatsby/src/utils/create-node-id.js rename to packages/gatsby/src/utils/create-node-id.ts index 2c6a553a7c82a..7f69874327df6 100644 --- a/packages/gatsby/src/utils/create-node-id.js +++ b/packages/gatsby/src/utils/create-node-id.ts @@ -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`) { @@ -22,5 +22,3 @@ function createNodeId(id, namespace) { return uuidv5(id, uuidv5(namespace, seedConstant)) } - -module.exports = createNodeId