4.13.1 • Published 3 months ago

gatsby-plugin-utils v4.13.1

Weekly downloads
369,011
License
MIT
Repository
github
Last release
3 months ago

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)
}
4.13.1

3 months ago

4.14.0-next.2

3 months ago

4.14.0-next.1

4 months ago

4.13.0

4 months ago

4.14.0-next.0

4 months ago

4.13.0-next.1

5 months ago

4.12.3

6 months ago

4.12.2

6 months ago

4.12.1

6 months ago

4.12.0

8 months ago

4.12.0-next.1

10 months ago

4.12.0-next.0

10 months ago

4.11.0-next.0

11 months ago

4.11.0-next.1

11 months ago

4.10.0

11 months ago

4.13.0-next.0

9 months ago

4.11.0

10 months ago

4.9.0

1 year ago

4.10.0-next.0

1 year ago

4.10.0-next.1

12 months ago

4.10.0-next.2

12 months ago

4.8.0

1 year ago

4.7.0

1 year ago

4.8.0-next.0

1 year ago

4.9.0-next.1

1 year ago

4.9.0-next.0

1 year ago

4.6.0-next.1

1 year ago

4.6.0-next.0

1 year ago

4.7.0-next.0

1 year ago

4.6.0

1 year ago

4.5.0-next.1

1 year ago

4.5.0

1 year ago

4.4.0

1 year ago

4.3.0-next.0

1 year ago

4.0.0

1 year ago

4.3.0-next.3

1 year ago

4.3.0-next.2

1 year ago

4.3.0-next.1

1 year ago

4.2.0-next.0

1 year ago

3.19.0

1 year ago

4.0.0-next.1

2 years ago

4.0.0-next.0

2 years ago

4.0.0-next.4

1 year ago

4.0.0-next.3

1 year ago

4.0.0-next.2

1 year ago

4.5.0-next.0

1 year ago

4.1.0-next.0

1 year ago

1.15.0

1 year ago

4.3.1

1 year ago

4.3.0

1 year ago

4.2.0

1 year ago

4.4.0-next.2

1 year ago

4.4.0-next.1

1 year ago

4.4.0-next.0

1 year ago

4.1.0

1 year ago

3.17.0-next.0

2 years ago

3.19.0-next.0

2 years ago

3.17.0

2 years ago

3.17.1

2 years ago

3.18.0-next.2

2 years ago

3.18.0

2 years ago

3.18.0-next.1

2 years ago

3.18.0-next.0

2 years ago

3.16.0

2 years ago

3.10.0-next.1

2 years ago

3.10.0-next.0

2 years ago

3.12.1

2 years ago

3.12.0

2 years ago

3.14.0

2 years ago

3.13.0-next.0

2 years ago

3.13.0-next.1

2 years ago

3.13.0

2 years ago

3.9.1

2 years ago

3.9.0

2 years ago

3.16.0-next.0

2 years ago

3.16.0-next.1

2 years ago

3.10.0

2 years ago

3.14.0-next.2

2 years ago

3.14.0-next.1

2 years ago

3.14.0-next.0

2 years ago

3.11.0-next.1

2 years ago

3.11.0-next.0

2 years ago

3.11.0

2 years ago

3.15.0-next.0

2 years ago

3.15.0-next.2

2 years ago

3.15.0-next.1

2 years ago

3.12.0-next.0

2 years ago

3.12.0-next.1

2 years ago

3.15.0

2 years ago

3.8.0-next.0

2 years ago

3.8.0-next.2

2 years ago

3.8.0-next.1

2 years ago

3.8.0-next.3

2 years ago

3.9.0-next.0

2 years ago

3.9.0-next.1

2 years ago

3.9.0-next.2

2 years ago

3.8.0

2 years ago

3.7.0

2 years ago

3.6.0-next.3

2 years ago

3.6.0-next.0

2 years ago

3.6.0-next.1

2 years ago

3.6.0-next.2

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.4.0-next.3

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

3.4.0

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.5.0-next.0

2 years ago

3.5.0-next.1

2 years ago

3.5.0-next.2

2 years ago

3.5.0-next.3

2 years ago

3.7.0-next.0

2 years ago

3.4.0-next.2

2 years ago

3.4.0-next.1

2 years ago

3.4.0-next.0

2 years ago

3.3.0

2 years ago

3.1.0-next.1

2 years ago

3.1.0-next.0

2 years ago

2.4.0

2 years ago

2.6.0-next.0

2 years ago

2.6.0-next.1

2 years ago

3.2.0

2 years ago

2.4.0-next.1

2 years ago

2.4.0-next.0

2 years ago

3.3.0-next.0

2 years ago

2.3.0

2 years ago

3.1.0

2 years ago

2.5.0-next.0

2 years ago

3.0.0-next.0

2 years ago

2.5.0-next.1

2 years ago

3.0.0

2 years ago

3.2.0-next.1

2 years ago

3.2.0-next.0

2 years ago

2.5.0

2 years ago

2.2.0

2 years ago

2.2.0-next.2

2 years ago

2.2.0-next.1

2 years ago

2.1.1

2 years ago

2.3.0-next.0

2 years ago

2.2.0-next.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

2.1.0-next.0

2 years ago

2.0.0-zz-next.3

3 years ago

2.0.0-zz-next.2

3 years ago

1.14.0

3 years ago

2.0.0-zz-next.1

3 years ago

2.0.0-zz-next.8

3 years ago

2.0.0-next.0

3 years ago

2.0.0-next.1

3 years ago

1.14.0-next.2

3 years ago

1.14.0-next.1

3 years ago

1.13.0

3 years ago

1.14.0-next.0

3 years ago

1.12.0

3 years ago

1.13.0-next.0

3 years ago

1.12.0-next.3

3 years ago

1.12.0-next.1

3 years ago

1.12.0-next.2

3 years ago

1.11.0

3 years ago

1.12.0-next.0

3 years ago

1.10.0

3 years ago

1.11.0-next.0

3 years ago

1.10.0-next.1

3 years ago

1.9.0

3 years ago

1.10.0-next.0

3 years ago

1.9.0-next.1

3 years ago

1.8.0

3 years ago

1.9.0-next.0

3 years ago

1.6.0

3 years ago

1.7.0-next.1

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.7.0-next.2

3 years ago

1.8.0-next.0

3 years ago

1.8.0-next.1

3 years ago

1.4.0

3 years ago

1.5.0-next.0

3 years ago

1.6.0-next.0

3 years ago

1.7.0-next.0

3 years ago

1.5.0

3 years ago

1.3.0

3 years ago

1.4.0-next.0

3 years ago

1.3.0-next.1

3 years ago

1.2.0

3 years ago

1.3.0-next.0

3 years ago

1.1.0

3 years ago

1.2.0-next.0

3 years ago

1.0.0

3 years ago

1.0.0-v3rc.0

3 years ago

1.1.0-next.1

3 years ago

1.1.0-next.0

3 years ago

1.0.0-next.1

3 years ago

1.0.0-next.0

3 years ago

0.9.0

3 years ago

0.10.0-next.0

3 years ago

0.8.0

3 years ago

0.9.0-next.0

3 years ago

0.8.0-next.1

3 years ago

0.7.0

3 years ago

0.8.0-next.0

3 years ago

0.7.0-next.1

3 years ago

0.6.0

3 years ago

0.7.0-next.0

3 years ago

0.5.0

3 years ago

0.6.0-next.0

3 years ago

0.4.0

3 years ago

0.5.0-next.0

3 years ago

0.3.0

3 years ago

0.4.0-next.0

3 years ago

0.3.0-next.1

3 years ago

0.3.0-next.0

3 years ago

0.2.40

3 years ago

0.2.39

3 years ago

0.2.27-qod.21

3 years ago

0.2.27-qod.20

3 years ago

0.2.38

3 years ago

0.2.27-qod.19

3 years ago

0.2.37

3 years ago

0.2.36

3 years ago

0.2.35

4 years ago

0.2.34

4 years ago

0.2.33

4 years ago

0.2.32

4 years ago

0.2.31

4 years ago

0.2.30

4 years ago

0.2.29

4 years ago

0.2.28

4 years ago

0.2.27

4 years ago

0.2.26

4 years ago