-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unstable_onPluginInit that would execute once in all proces…
…ses (#31901) * feat: add unstable_onPluginInit that would execute once in all processes * update tests * add basic unit test for isGatsbyNodeLifecycleSupported * add readme section about added lifecycle existance check * don't mix ESM and CJS in readme * add example to node api docs * set version to 3.9 * try/catch lifecycle check, just to make sure we never crash because of it * uncoditionally set actions and plugins in onPreBootstrap, it doesn't hurt to do so
- Loading branch information
Showing
11 changed files
with
108 additions
and
26 deletions.
There are no files selected for viewing
23 changes: 11 additions & 12 deletions
23
examples/using-redux-w-interaction-code-splitting/static/background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 11 additions & 12 deletions
23
examples/using-redux-w-page-code-splitting/static/background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/gatsby-plugin-utils/src/__tests__/node-api-is-supported.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isGatsbyNodeLifecycleSupported } from "../node-api-is-supported" | ||
|
||
describe(`isGatsbyNodeLifecycleSupported`, () => { | ||
it(`returns true for supported API (createSchemaCustomization)`, () => { | ||
expect(isGatsbyNodeLifecycleSupported(`createSchemaCustomization`)).toEqual( | ||
true | ||
) | ||
}) | ||
|
||
it(`returns false for unsupported API (thisIsNotSupported)`, () => { | ||
expect(isGatsbyNodeLifecycleSupported(`thisIsNotSupported`)).toEqual(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./validate" | ||
export * from "./test-plugin-options-schema" | ||
export * from "./joi" | ||
export * from "./node-api-is-supported" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function isGatsbyNodeLifecycleSupported(apiName: string): boolean { | ||
let availableAPIs | ||
try { | ||
availableAPIs = require(`gatsby/apis.json`) | ||
} catch (e) { | ||
throw new Error( | ||
`Couldn't check available APIs. Make sure you are on gatsby version >=2.13.41` | ||
) | ||
} | ||
|
||
return !!availableAPIs?.node?.[apiName] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters