Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gatsby-core-utils

gatsbyjs2.3mMIT4.15.0TypeScript support: included

A collection of gatsby utils used in different gatsby packages

gatsby, gatsby-core-utils

readme

gatsby-core-utils

Utilities used in multiple Gatsby packages.

Usage

npm install gatsby-core-utils

createContentDigest

Encrypts an input using md5 hash of hexadecimal digest.

const { createContentDigest } = require("gatsby-core-utils")

const options = {
  key: "value",
  foo: "bar",
}

const digest = createContentDigest(options)
// ...

cpuCoreCount

Calculate the number of CPU cores on the current machine

This function can be controlled by an env variable GATSBY_CPU_COUNT setting the first argument to true.

value description
| Counts amount of real cores by running a shell command
logical_cores require("os").cpus() to count all virtual cores
any number Sets cpu count to that specific number
const { cpuCoreCount } = require("gatsby-core-utils")

const coreCount = cpuCoreCount(false)
// ...
const { cpuCoreCount } = require("gatsby-core-utils")
process.env.GATSBY_CPU_COUNT = "logical_cores"

const coreCount = cpuCoreCount()
// ...

joinPath

A utility that joins paths with a / on windows and unix-type platforms. This can also be used for URL concatenation.

const { joinPath } = require("gatsby-core-utils")

const BASEPATH = "/mybase/"
const pathname = "./gatsby/is/awesome"
const url = joinPath(BASEPATH, pathname)
// ...

isCI

A utility that enhances isCI from 'ci-info` with support for Vercel and Heroku detection

const { isCI } = require("gatsby-core-utils")

if (isCI()) {
  // execute CI-specific code
}
// ...

getCIName

A utility that returns the name of the current CI environment if available, null otherwise

const { getCIName } = require("gatsby-core-utils")

const CI_NAME = getCIName()
console.log({ CI_NAME })
// {CI_NAME: null}, or
// {CI_NAME: "Vercel"}
// ...

createRequireFromPath

A cross-version polyfill for Node's Module.createRequire.

const { createRequireFromPath } = require("gatsby-core-utils")

const requireUtil = createRequireFromPath("../src/utils/")

// Require `../src/utils/some-tool`
requireUtil("./some-tool")
// ...

Mutex

When working inside workers or async operations you want some kind of concurrency control that a specific work load can only concurrent one at a time. This is what a Mutex does.

By implementing the following code, the code is only executed one at a time and the other threads/async workloads are awaited until the current one is done. This is handy when writing to the same file to disk.

const { createMutex } = require("gatsby-core-utils/mutex")

const mutex = createMutex("my-custom-mutex-key")
await mutex.acquire()

await fs.writeFile("pathToFile", "my custom content")

await mutex.release()

Hashing

Parts of hash-wasm are re-exported from gatsby-core-utils or used in custom functions. When working on hashing where you'd normally use crypto from Node.js, you can use these functions instead. They especially show their advantage on large inputs so don't feel obliged to always use them. Refer to hash-wasm's documentation for more details on usage for the re-exported functions.

const { md5File, md5, createMD5, sha256, sha1 } = require("gatsby-core-utils")

// For md5, createMD5, sha256, sha1 refer to hash-wasm
await md5(`some-string`)

// md5File gives you the MD5 hex hash for a given filepath
await md5File(`package.json`)

changelog

Changelog: gatsby-core-utils

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

4.14.0 (2024-11-06)

🧾 Release notes

Bug Fixes

  • update dependency hash-wasm to ^4.11.0 for gatsby-core-utils #38678 (f8ce66e)
  • update dependency fs-extra to ^11.2.0 #38727 (cb33fe5)

4.13.1 (2024-01-23)

Note: Version bump only for package gatsby-core-utils

4.13.0 (2023-12-18)

🧾 Release notes

Bug Fixes

  • respect 'force' and 'conditions' properties on redirects #38657 (48d311e)

4.12.1 (2023-10-26)

Bug Fixes

4.12.0 (2023-08-24)

🧾 Release notes

Bug Fixes

Chores

  • update dependency msw to ^1.2.2 for gatsby-core-utils #38283 (ada5fef)

4.11.0 (2023-06-15)

🧾 Release notes

Bug Fixes

Chores

4.10.0 (2023-05-16)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

4.9.0 (2023-04-18)

🧾 Release notes

Bug Fixes

Chores

4.8.0 (2023-03-21)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

4.7.0 (2023-02-21)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

4.6.0 (2023-02-07)

🧾 Release notes

Bug Fixes

Chores

4.5.0 (2023-01-24)

🧾 Release notes

Features

Chores

4.4.0 (2023-01-10)

🧾 Release notes

Chores

Other Changes

4.3.1 (2022-12-14)

Other Changes

4.3.0 (2022-12-13)

🧾 Release notes

Bug Fixes

Chores

4.2.0 (2022-11-25)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

4.1.0 (2022-11-22)

🧾 Release notes

Bug Fixes

4.0.0 (2022-11-08)

🧾 Release notes

Bug Fixes

Chores

3.24.0 (2022-09-27)

🧾 Release notes

Bug Fixes

3.23.0 (2022-09-13)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

3.22.0 (2022-08-30)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

3.21.0 (2022-08-16)

🧾 Release notes

Chores

  • update dependency del-cli to v5 for gatsby-core-utils #36286 (a4f92b4)

Other Changes

3.20.0 (2022-08-02)

🧾 Release notes

Chores

3.19.0 (2022-07-19)

🧾 Release notes

Bug Fixes

3.18.1 (2022-07-12)

Bug Fixes

3.18.0 (2022-07-05)

🧾 Release notes

Bug Fixes

  • update dependency got to ^11.8.5 for gatsby-core-utils #35804 (2cd167f)

3.17.0 (2022-06-21)

🧾 Release notes

Chores

3.16.0 (2022-06-07)

🧾 Release notes

Features

Chores

3.15.0 (2022-05-24)

🧾 Release notes

Chores

3.14.0 (2022-05-10)

🧾 Release notes

Bug Fixes

Chores

3.13.0 (2022-04-26)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

3.12.1 (2022-04-13)

Note: Version bump only for package gatsby-core-utils

3.12.0 (2022-04-12)

🧾 Release notes

Bug Fixes

3.11.1 (2022-03-31)

Bug Fixes

3.11.0 (2022-03-29)

🧾 Release notes

Bug Fixes

3.10.1 (2022-03-23)

Bug Fixes

3.10.0 (2022-03-16)

🧾 Release notes

Features

Bug Fixes

  • update dependency lmdb to ^2.2.4 for gatsby-core-utils #34977 (495f71f)
  • multiple requests with different outputdir #35039 (2f361cc)

3.9.1 (2022-03-09)

Bug Fixes

3.9.0 (2022-03-01)

🧾 Release notes

Bug Fixes

Chores

3.8.2 (2022-03-01)

Bug Fixes

3.8.1 (2022-02-25)

Bug Fixes

3.8.0 (2022-02-22)

🧾 Release notes

Features

Bug Fixes

3.7.0 (2022-02-08)

🧾 Release notes

Bug Fixes

  • ensure remote file downloads are queued in all cases #34414 (6ac1ed6)

Chores

3.6.0 (2022-01-25)

🧾 Release notes

Bug Fixes

3.5.2 (2022-01-17)

Bug Fixes

3.5.1 (2022-01-12)

Bug Fixes

3.5.0 (2022-01-11)

🧾 Release notes

Features

Bug Fixes

Chores

3.4.0 (2021-12-14)

🧾 Release notes

Bug Fixes

  • update dependency got to ^11.8.3 for gatsby-core-utils #34129 (3700b21)
  • update dependency got to ^11.8.3 for gatsby-plugin-sharp #34130 (80ef329)

Chores

3.3.0 (2021-12-01)

🧾 Release notes

Bug Fixes

3.2.0 (2021-11-16)

🧾 Release notes

Features

  • Add retry on HTTP status codes to fetchRemoteFile #33461 (00dc589)

Bug Fixes

  • handle 304 correctly between builds #33975 #33981 (ab857d7)
  • fix fetchRemoteFile when called in main process after being called in worker fix #33932 (189dea6)
  • update dependency node-object-hash to ^2.3.10 for gatsby-core-utils #33364 (cecd522)

Chores

3.1.3 (2021-11-15)

Bug Fixes

3.1.2 (2021-11-11)

Bug Fixes

  • fix fetchRemoteFile when called in main process after being called in worker fix #33932 fix #33942 (26c7a3d)

3.1.1 (2021-11-10)

Features

3.1.0 (2021-11-02)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

3.0.0 (2021-10-21)

🧾 Release notes

Features

Bug Fixes

Chores

2.14.0 (2021-09-18)

🧾 Release notes

Bug Fixes

  • update dependency node-object-hash to ^2.3.9 for gatsby-core-utils #32990 (03a4dd0)

Chores

2.13.0 (2021-09-01)

🧾 Release notes

Features

  • IPC events for routes, redirects, rewrites, and headers #32847 (ba4b08c)
  • Move page-data & HTML utils to package #32861 (114e3d3)

Bug Fixes

  • Switch auth option from got to username/password #32665 (d6326df)

Chores

2.12.0 (2021-08-18)

🧾 Release notes

Bug Fixes

Chores

2.11.0 (2021-08-04)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.10.0 (2021-07-20)

🧾 Release notes

Bug Fixes

Chores

2.9.0 (2021-07-07)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.8.0 (2021-06-23)

🧾 Release notes

Chores

2.7.1 (2021-06-10)

Chores

2.7.0 (2021-06-09)

🧾 Release notes

Chores

2.6.0 (2021-05-25)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.5.0 (2021-05-12)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.4.0 (2021-04-28)

🧾 Release notes

Features

  • add support for dynamic routes for API functions #30904 (e44d6a7)

Bug Fixes

  • fetch-remote-file download failure when missing content-length header #30810 (1164a93)

Other Changes

2.3.0 (2021-04-14)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.2.0 (2021-03-30)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.1.0 (2021-03-16)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

2.0.0 (2021-03-02)

🧾 Release notes

Features

Chores

1.10.1 (2021-02-24)

Chores

1.10.0 (2021-02-02)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

1.9.0 (2021-01-20)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

1.8.0 (2021-01-06)

🧾 Release notes

Other Changes

  • chore(telemetry) improve github action and circle detection #28732 (3af7182)

1.7.1 (2020-12-23)

Other Changes

1.7.0 (2020-12-15)

🧾 Release notes

Chores

1.6.0 (2020-12-02)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

1.5.0 (2020-11-20)

🧾 Release notes

Chores

1.4.0 (2020-11-12)

🧾 Release notes

Note: Version bump only for package gatsby-core-utils

1.3.23 (2020-10-06)

Note: Version bump only for package gatsby-core-utils

1.3.22 (2020-10-01)

Note: Version bump only for package gatsby-core-utils

1.3.21 (2020-09-28)

Note: Version bump only for package gatsby-core-utils

1.3.20 (2020-09-15)

Note: Version bump only for package gatsby-core-utils

1.3.19 (2020-09-07)

Note: Version bump only for package gatsby-core-utils

1.3.18 (2020-08-28)

Note: Version bump only for package gatsby-core-utils

1.3.17 (2020-08-26)

Note: Version bump only for package gatsby-core-utils

1.3.16 (2020-08-24)

Features

  • gatsby-core-utils: Add node.js export, and move site-metadata into its own function (#26237) (b164147)

1.3.15 (2020-08-05)

Features

1.3.14 (2020-07-24)

Note: Version bump only for package gatsby-core-utils

1.3.13 (2020-07-21)

Note: Version bump only for package gatsby-core-utils

1.3.12 (2020-07-09)

Features

1.3.11 (2020-07-02)

Note: Version bump only for package gatsby-core-utils

1.3.10 (2020-07-01)

Note: Version bump only for package gatsby-core-utils

1.3.9 (2020-07-01)

Note: Version bump only for package gatsby-core-utils

1.3.8 (2020-06-24)

Note: Version bump only for package gatsby-core-utils

1.3.7 (2020-06-22)

Note: Version bump only for package gatsby-core-utils

1.3.6 (2020-06-19)

Bug Fixes

1.3.5 (2020-06-09)

Note: Version bump only for package gatsby-core-utils

1.3.4 (2020-06-02)

Note: Version bump only for package gatsby-core-utils

1.3.3 (2020-05-22)

Note: Version bump only for package gatsby-core-utils

1.3.2 (2020-05-20)

Note: Version bump only for package gatsby-core-utils

1.3.1 (2020-05-20)

Bug Fixes

  • gatsby-core-utils: create lock per service, rather than per site (#24252) (718deb3)

1.3.0 (2020-05-19)

Features

  • gatsby: Prompt users to restart process on gatsby-config & gatsby-node changes (#22759) (d4ec5e5)

1.2.3 (2020-05-18)

Bug Fixes

  • docs: changes(ZEIT to Vercel) in core-utils and recipes (#24120) (aeb6c03)

1.2.2 (2020-05-13)

Note: Version bump only for package gatsby-core-utils

1.2.1 (2020-05-05)

Note: Version bump only for package gatsby-core-utils

1.2.0 (2020-04-27)

Note: Version bump only for package gatsby-core-utils

1.1.4 (2020-04-24)

Note: Version bump only for package gatsby-core-utils

1.1.3 (2020-04-17)

Bug Fixes

1.1.2 (2020-04-16)

Note: Version bump only for package gatsby-core-utils

1.1.1 (2020-03-23)

Note: Version bump only for package gatsby-core-utils

1.1.0 (2020-03-20)

Note: Version bump only for package gatsby-core-utils

1.0.34 (2020-03-16)

Note: Version bump only for package gatsby-core-utils

1.0.33 (2020-03-11)

Note: Version bump only for package gatsby-core-utils

1.0.32 (2020-03-10)

Note: Version bump only for package gatsby-core-utils

1.0.31 (2020-03-09)

Note: Version bump only for package gatsby-core-utils

1.0.30 (2020-03-06)

Bug Fixes

  • gatsby-core-utils: Add configstore as a dependency (#22019) (ab71779)

1.0.29 (2020-03-06)

Note: Version bump only for package gatsby-core-utils

1.0.28 (2020-02-01)

Note: Version bump only for package gatsby-core-utils

1.0.27 (2020-01-29)

Bug Fixes

1.0.26 (2020-01-09)

Note: Version bump only for package gatsby-core-utils

1.0.25 (2019-12-20)

Note: Version bump only for package gatsby-core-utils

1.0.24 (2019-12-10)

Note: Version bump only for package gatsby-core-utils

1.0.23 (2019-12-10)

Note: Version bump only for package gatsby-core-utils

1.0.22 (2019-12-02)

Bug Fixes

  • gatsby-core-utils: make createContentDigest deterministic (#19832) (cb6d0e2)

1.0.21 (2019-11-26)

Note: Version bump only for package gatsby-core-utils

1.0.20 (2019-11-18)

Bug Fixes

  • gatsby: Handle special characters in windows paths (#19600) (9929cf0)

1.0.19 (2019-11-15)

Note: Version bump only for package gatsby-core-utils

1.0.18 (2019-11-10)

Note: Version bump only for package gatsby-core-utils

1.0.17 (2019-10-28)

Features

1.0.16 (2019-10-28)

Note: Version bump only for package gatsby-core-utils

1.0.15 (2019-10-14)

Note: Version bump only for package gatsby-core-utils

1.0.14 (2019-10-14)

Note: Version bump only for package gatsby-core-utils

1.0.13 (2019-10-09)

Note: Version bump only for package gatsby-core-utils

1.0.12 (2019-09-26)

Note: Version bump only for package gatsby-core-utils

1.0.11 (2019-09-26)

Note: Version bump only for package gatsby-core-utils

1.0.10 (2019-09-20)

Note: Version bump only for package gatsby-core-utils

1.0.9 (2019-09-18)

Note: Version bump only for package gatsby-core-utils

1.0.8 (2019-09-09)

Note: Version bump only for package gatsby-core-utils

1.0.7 (2019-09-01)

Bug Fixes

  • update minor updates in packages except react, babel and eslint (#17254) (252d867)

1.0.6 (2019-08-23)

Note: Version bump only for package gatsby-core-utils

1.0.5 (2019-08-20)

Note: Version bump only for package gatsby-core-utils

1.0.4 (2019-08-06)

Bug Fixes

1.0.3 (2019-07-12)

Note: Version bump only for package gatsby-core-utils

1.0.2 (2019-07-12)

Note: Version bump only for package gatsby-core-utils

1.0.1 (2019-07-11)

Note: Version bump only for package gatsby-core-utils

1.0.0 (2019-07-08)

Features

  • gatsby-utils: create new package gatsby-core-utils (#15451) (0c890a6)