Détail du package

gatsby-plugin-utils

gatsbyjs1.3mMIT4.15.0

Gatsby utils that help creating plugins

gatsby

readme

gatsby-plugin-utils

Usage

npm install gatsby-plugin-utils

validateOptionsSchema

The validateOptionsSchema function verifies that the proper data types of options were passed into a plugin from the gatsby-config.js file. It is called internally by Gatsby to validate each plugin's options when a site is started.

Example

import { validateOptionsSchema } from "gatsby-plugin-utils"

await validateOptionsSchema(pluginName, pluginSchema, pluginOptions)

testPluginOptionsSchema

Utility to validate and test plugin options schemas. An example of a plugin options schema implementation can be found in the gatsby-node.js file of gatsby-plugin-google-analytics.

Example

// This is an example using Jest (https://jestjs.io/)
import { testPluginOptionsSchema } from "gatsby-plugin-utils"

it(`should partially validate one value of a schema`, async () => {
  const pluginSchema = ({ Joi }) =>
    Joi.object({
      someOtherValue: Joi.string(),
      toVerify: Joi.boolean(),
    })
  const expectedErrors = [`"toVerify" must be a boolean`]

  // Only the "toVerify" key of the schema will be verified in this test
  const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, {
    toVerify: `abcd`,
  })

  expect(isValid).toBe(false)
  expect(errors).toEqual(expectedErrors)
})

isGatsbyNodeLifecycleSupported

Utility to be used by plugins to do runtime check against gatsby core package checking wether particular gatsby-node lifecycle API is supported. Useful for plugins to be able to support multiple gatsby core versions.

Example

const { isGatsbyNodeLifecycleSupported } = require(`gatsby-plugin-utils`)

// only use createSchemaCustomization lifecycle only when it's available.
if (isGatsbyNodeLifecycleSupported(`createSchemaCustomization`)) {
  exports.createSchemaCustomization = function createSchemaCustomization({
    actions,
  }) {
    // customize schema
  }
}

hasFeature

Feature detection is now part of Gatsby. As a plugin author you don't know what version of Gatsby a user is using. hasFeature allows you to check if the current version of Gatsby has a certain feature.

Here's a list of features: // TODO

Example

const { hasFeature } = require(`gatsby-plugin-utils`)

if (!hasFeature(`image-cdn`)) {
  // You can polyfill image-cdn here so older versions have support as well
}

Add ImageCDN support

Our new ImageCDN allows source plugins to lazily download and process images. if you're a plugin author please use this polyfill to add support for all Gatsby V4 versions.

For more information (see here)[https://gatsby.dev/img]

Example

const {
  addRemoteFilePolyfillInterface,
  polyfillImageServiceDevRoutes,
} = require(`gatsby-plugin-utils/pollyfill-remote-file`)

exports.createSchemaCustomization ({ actions, schema, store }) => {
  actions.createTypes([
    addRemoteFilePolyfillInterface(
      schema.buildObjectType({
        name: `PrefixAsset`,
        fields: {
          // your fields
        },
        interfaces: [`Node`, 'RemoteFile'],
      }),
      {
        schema,
        actions,
        store
      }
    )
  ]);
}

/** @type {import('gatsby').onCreateDevServer} */
exports.onCreateDevServer = ({ app, store }) => {
  polyfillImageServiceDevRoutes(app, store)
}

changelog

Changelog: gatsby-plugin-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 minor and patch dependencies for gatsby-plugin-utils #38513 (a2b2afd)
  • update dependency fs-extra to ^11.2.0 #38727 (cb33fe5)

4.13.1 (2024-01-23)

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

4.13.0 (2023-12-18)

🧾 Release notes

Features

Bug Fixes

  • support multiple instances of same variable in gatsbyImage placeholderUrl #38626 (b177db9)

4.12.3 (2023-10-26)

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

4.12.2 (2023-10-20)

Bug Fixes

  • support multiple instances of same variable in gatsbyImage placeholderUrl #38626 #38647 (02e925a)

4.12.1 (2023-10-09)

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

4.12.0 (2023-08-24)

🧾 Release notes

Bug Fixes

Chores

  • update dependency msw to ^1.2.2 for gatsby-plugin-utils #38285 (13fc00f)

4.11.0 (2023-06-15)

🧾 Release notes

Bug Fixes

Chores

  • update dependency rimraf to ^5.0.1 for gatsby-plugin-utils #38144 (10b2ef7)

4.10.0 (2023-05-16)

🧾 Release notes

Bug Fixes

  • update dependency joi to ^17.9.2 for gatsby-plugin-utils #38002 (db45fa0)

Chores

  • update dependency rimraf to v5 for gatsby-plugin-utils #38040 (94099a9)

4.9.0 (2023-04-18)

🧾 Release notes

Features

Bug Fixes

Chores

4.8.0 (2023-03-21)

🧾 Release notes

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

4.7.0 (2023-02-21)

🧾 Release notes

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

4.6.0 (2023-02-07)

🧾 Release notes

Bug Fixes

Chores

4.5.0 (2023-01-24)

🧾 Release notes

Chores

4.4.0 (2023-01-10)

🧾 Release notes

Chores

4.3.1 (2022-12-14)

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

4.3.0 (2022-12-13)

🧾 Release notes

Features

Bug Fixes

  • update minor and patch dependencies for gatsby-plugin-utils #37155 (8a874ed)

Chores

  • update dependency typescript to ^4.9.3 #37192 (204ed0e)
  • update dependency msw to ^0.49.1 for gatsby-plugin-utils #37188 (2ec7a92)

4.2.0 (2022-11-25)

🧾 Release notes

Chores

Other Changes

4.1.0 (2022-11-22)

🧾 Release notes

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

4.0.0 (2022-11-08)

🧾 Release notes

Chores

3.18.0 (2022-09-27)

🧾 Release notes

Features

  • Encrypt image cdn image/file urls when env vars are present #36585 (a341115)

Bug Fixes

3.17.1 (2022-09-22)

Features

3.17.0 (2022-09-13)

🧾 Release notes

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

3.16.0 (2022-08-30)

🧾 Release notes

Bug Fixes

Chores

3.15.0 (2022-08-16)

🧾 Release notes

Bug Fixes

Chores

Other Changes

3.14.0 (2022-08-02)

🧾 Release notes

Bug Fixes

Chores

3.13.0 (2022-07-19)

🧾 Release notes

Chores

  • update dependency msw to ^0.42.3 for gatsby-plugin-utils #36028 (2263c8c)

3.12.1 (2022-07-12)

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

3.12.0 (2022-07-05)

🧾 Release notes

Chores

  • update dependency msw to ^0.42.0 for gatsby-plugin-utils #35807 (ecff91d)

3.11.0 (2022-06-21)

🧾 Release notes

Features

3.10.0 (2022-06-07)

🧾 Release notes

Features

Bug Fixes

Chores

3.9.1 (2022-06-01)

Bug Fixes

3.9.0 (2022-05-24)

🧾 Release notes

Bug Fixes

  • Throw Typegen errors & add IGatsbyImageData to output #35683 (e7fc88b)

3.8.0 (2022-05-10)

🧾 Release notes

Bug Fixes

Chores

3.7.0 (2022-04-26)

🧾 Release notes

Features

3.6.1 (2022-04-13)

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

3.6.0 (2022-04-12)

🧾 Release notes

Bug Fixes

  • path pieces too long and url safe base64 encoding #35160 (3f12544)

Chores

  • update dependency msw to ^0.39.2 for gatsby-plugin-utils #35300 (aa0f61a)

3.5.1 (2022-03-31)

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

3.5.0 (2022-03-29)

🧾 Release notes

Features

Bug Fixes

3.4.2 (2022-03-23)

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

3.4.1 (2022-03-18)

Bug Fixes

3.4.0 (2022-03-16)

🧾 Release notes

Features

Bug Fixes

3.3.0 (2022-03-01)

🧾 Release notes

Chores

3.2.0 (2022-02-22)

🧾 Release notes

Features

3.1.0 (2022-02-08)

🧾 Release notes

Chores

3.0.0 (2022-01-25)

🧾 Release notes

Bug Fixes

  • don't throw on warnings in pluginOptionsSchema #34182 (252f50d)

2.5.0 (2022-01-11)

🧾 Release notes

Chores

2.4.0 (2021-12-14)

🧾 Release notes

Chores

2.3.0 (2021-12-01)

🧾 Release notes

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

2.2.0 (2021-11-16)

🧾 Release notes

Bug Fixes

Chores

2.1.1 (2021-11-09)

Bug Fixes

2.1.0 (2021-11-02)

🧾 Release notes

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

2.0.0 (2021-10-21)

🧾 Release notes

Bug Fixes

Chores

Other Changes

1.14.0 (2021-09-18)

🧾 Release notes

Features

Bug Fixes

  • update dependency joi to ^17.4.2 for gatsby-plugin-utils #32585 (ed8301e)

Chores

1.13.0 (2021-09-01)

🧾 Release notes

Chores

1.12.0 (2021-08-18)

🧾 Release notes

Chores

1.11.0 (2021-08-04)

🧾 Release notes

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

1.10.0 (2021-07-20)

🧾 Release notes

Bug Fixes

Chores

1.9.0 (2021-07-07)

🧾 Release notes

Features

  • add unstable_onPluginInit that would execute once in all processes #31901 (2bf8c0d)

1.8.0 (2021-06-23)

🧾 Release notes

Chores

1.7.1 (2021-06-10)

Chores

1.7.0 (2021-06-09)

🧾 Release notes

Chores

1.6.0 (2021-05-25)

🧾 Release notes

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

1.5.0 (2021-05-12)

🧾 Release notes

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

1.4.0 (2021-04-28)

🧾 Release notes

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

1.3.0 (2021-04-14)

🧾 Release notes

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

1.2.0 (2021-03-30)

🧾 Release notes

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

1.1.0 (2021-03-16)

🧾 Release notes

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

1.0.0 (2021-03-02)

🧾 Release notes

Chores

0.9.0 (2021-02-02)

🧾 Release notes

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

0.8.0 (2021-01-20)

🧾 Release notes

Chores

Other Changes

  • add file extension, fix code block, fix link, fix code fix #28905 (6736a6d)

0.7.0 (2021-01-06)

🧾 Release notes

Chores

0.6.0 (2020-12-15)

🧾 Release notes

Chores

0.5.0 (2020-12-02)

🧾 Release notes

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

0.4.0 (2020-11-20)

🧾 Release notes

Chores

0.3.0 (2020-11-12)

🧾 Release notes

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

0.2.40 (2020-10-28)

Bug Fixes

0.2.39 (2020-10-22)

Bug Fixes

  • gatsby-plugin-utils: skip libcheck during typegen (#27588) (0fdd3e9)

0.2.38 (2020-10-21)

Bug Fixes

  • duplicate types to solve circular dependency (#27578) (029ec48)
  • Update plugin schema testing util and associated tests (#27574) (6d81283)

0.2.37 (2020-10-20)

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

0.2.36 (2020-10-19)

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

0.2.35 (2020-10-19)

Features

  • gatsby-plugin-utils: save validation resulting value to plugin options (#27381) (0073fb1)

0.2.34 (2020-10-16)

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

0.2.33 (2020-10-16)

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

0.2.32 (2020-10-15)

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

0.2.31 (2020-10-14)

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

0.2.30 (2020-10-13)

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

0.2.29 (2020-10-13)

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

0.2.28 (2020-10-12)

Bug Fixes

Features

  • gatsby-plugin-utils: add testPluginOptionsSchema to verify plugin schema options (#27334) (6f842fb)

0.2.27 (2020-10-07)

Features

0.2.26 (2020-10-06)

Features

  • gatsby-plugin-utils: add package and methods to validate plugin options (#27164) (49e6669)