Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(packages): make unstable_shouldOnCreateNode stable #36516

Merged
merged 6 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/gabe-csv-markdown/gatsby-node.js
Expand Up @@ -42,7 +42,7 @@ exports.createPages = async ({ graphql, actions }) => {
})
}

exports.unstable_shouldOnCreateNode = ({ node }) =>
exports.shouldOnCreateNode = ({ node }) =>
node.internal.type === `GendataCsv`

// Not sure if there is a better way than to create a proxy node for markdown to pick up
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gabe-fs-text/gatsby-node.js
Expand Up @@ -40,7 +40,7 @@ exports.createPages = async ({ graphql, actions }) => {
})
}

exports.unstable_shouldOnCreateNode = ({ node }) =>
exports.shouldOnCreateNode = ({ node }) =>
node.internal.type === "File"

exports.onCreateNode = ({ node, actions, createNodeId }) => {
Expand Down
12 changes: 7 additions & 5 deletions packages/gatsby-plugin-mdx/src/gatsby-node.ts
Expand Up @@ -282,11 +282,13 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"]
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const unstable_shouldOnCreateNode: GatsbyNode["unstable_shouldOnCreateNode"] =
({ node }: { node: FileSystemNode }, pluginOptions) => {
const { extensions } = defaultOptions(pluginOptions)
return node.internal.type === `File` && extensions.includes(node.ext)
}
export const shouldOnCreateNode: GatsbyNode["shouldOnCreateNode"] = (
{ node }: { node: FileSystemNode },
pluginOptions
) => {
const { extensions } = defaultOptions(pluginOptions)
return node.internal.type === `File` && extensions.includes(node.ext)
}

/**
* Create Mdx nodes from MDX files.
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-asciidoc/src/gatsby-node.js
@@ -1,7 +1,7 @@
const asciidoc = require(`asciidoctor`)()
const _ = require(`lodash`)

function unstable_shouldOnCreateNode({ node }, pluginOptions = {}) {
function shouldOnCreateNode({ node }, pluginOptions = {}) {
const extensionsConfig = pluginOptions.fileExtensions

// make extensions configurable and use adoc and asciidoc as default
Expand All @@ -23,7 +23,7 @@ async function onCreateNode(
},
pluginOptions
) {
if (!unstable_shouldOnCreateNode({ node }, pluginOptions)) {
if (!shouldOnCreateNode({ node }, pluginOptions)) {
return
}
LekoArts marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -140,5 +140,5 @@ const extractPageAttributes = allAttributes =>
return pageAttributes
}, {})

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-csv/src/gatsby-node.js
Expand Up @@ -8,7 +8,7 @@ const convertToJson = (data, options) =>
.fromString(data)
.then(jsonData => jsonData, new Error(`CSV to JSON conversion failed!`))

function unstable_shouldOnCreateNode({ node }, pluginOptions = {}) {
function shouldOnCreateNode({ node }, pluginOptions = {}) {
const { extension } = node
const { extensions } = pluginOptions

Expand All @@ -19,7 +19,7 @@ async function onCreateNode(
{ node, actions, loadNodeContent, createNodeId, createContentDigest },
pluginOptions
) {
if (!unstable_shouldOnCreateNode({ node }, pluginOptions)) {
if (!shouldOnCreateNode({ node }, pluginOptions)) {
return
}

Expand Down Expand Up @@ -84,5 +84,5 @@ async function onCreateNode(
return
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
Expand Up @@ -185,7 +185,7 @@ exports.createResolvers = ({ createResolvers }) => {
})
}

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
return (
node.internal.type === `File` &&
(node.internal.mediaType === `application/javascript` ||
Expand All @@ -195,14 +195,14 @@ function unstable_shouldOnCreateNode({ node }) {
)
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode

/**
* Implement the onCreateNode API to create documentation.js nodes
* @param {Object} super this is a super param
*/
exports.onCreateNode = async ({ node, actions, ...helpers }) => {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return null
}

Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-excel/src/gatsby-node.js
Expand Up @@ -28,15 +28,15 @@ const extensions = [
`numbers`,
]

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
return extensions.includes((node.extension || ``).toLowerCase())
}

async function onCreateNode(
{ node, actions, loadNodeContent, createNodeId, createContentDigest },
options = {}
) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down Expand Up @@ -108,5 +108,5 @@ async function onCreateNode(
return
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-hjson/src/gatsby-node.js
Expand Up @@ -2,7 +2,7 @@ const _ = require(`lodash`)
const path = require(`path`)
const HJSON = require(`hjson`)

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
// We only care about HJSON content.
// NOTE the mime package does not recognize HJSON yet
// See RFC https://hjson.org/rfc.html#rfc.section.1.3
Expand All @@ -19,7 +19,7 @@ async function onCreateNode({
createNodeId,
createContentDigest,
}) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down Expand Up @@ -63,5 +63,5 @@ async function onCreateNode({
}
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
Expand Up @@ -4,7 +4,7 @@ const traverse = require(`@babel/traverse`).default

const fileExtsToProcess = [`js`, `jsx`, `ts`, `tsx`]

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
// This only processes JavaScript and TypeScript files.
return fileExtsToProcess.includes(node.extension)
}
Expand All @@ -15,7 +15,7 @@ async function onCreateNode({
loadNodeContent,
createContentDigest,
}) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down Expand Up @@ -142,5 +142,5 @@ async function onCreateNode({
}
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
Expand Up @@ -2,7 +2,7 @@ const _ = require(`lodash`)
const babylon = require(`@babel/parser`)
const traverse = require(`@babel/traverse`).default

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
// This only processes JavaScript files.
return node.internal.mediaType === `application/javascript`
}
Expand All @@ -15,7 +15,7 @@ async function onCreateNode({
createNodeId,
createContentDigest,
}) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down Expand Up @@ -155,5 +155,5 @@ async function onCreateNode({
}
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-json/src/gatsby-node.js
@@ -1,7 +1,7 @@
const _ = require(`lodash`)
const path = require(`path`)

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
// We only care about JSON content.
return node.internal.mediaType === `application/json`
}
Expand All @@ -10,7 +10,7 @@ async function onCreateNode(
{ node, actions, loadNodeContent, createNodeId, createContentDigest },
pluginOptions
) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down Expand Up @@ -78,5 +78,5 @@ async function onCreateNode(
}
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-pdf/src/gatsby-node.js
Expand Up @@ -2,7 +2,7 @@
const Promise = require(`bluebird`)
const PDFParser = require(`pdf2json`)

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
// Filter out non-pdf content
return node.extension === `pdf`
}
Expand All @@ -27,7 +27,7 @@ async function onCreateNode({
createNodeId,
createContentDigest,
}) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand All @@ -51,5 +51,5 @@ async function onCreateNode({
createParentChildLink({ parent: node, child: pdfNode })
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
7 changes: 2 additions & 5 deletions packages/gatsby-transformer-react-docgen/src/gatsby-node.js
@@ -1,7 +1,4 @@
const {
onCreateNode,
unstable_shouldOnCreateNode,
} = require(`./on-node-create`)
exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
const { onCreateNode, shouldOnCreateNode } = require(`./on-node-create`)
exports.shouldOnCreateNode = shouldOnCreateNode
exports.onCreateNode = onCreateNode
exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`).default
Expand Up @@ -88,7 +88,7 @@ function createPropNodes(
return node
}

export function unstable_shouldOnCreateNode({ node }) {
export function shouldOnCreateNode({ node }) {
return canParse(node)
}

Expand Down
7 changes: 2 additions & 5 deletions packages/gatsby-transformer-remark/src/gatsby-node.js
@@ -1,9 +1,6 @@
const {
onCreateNode,
unstable_shouldOnCreateNode,
} = require(`./on-node-create`)
const { onCreateNode, shouldOnCreateNode } = require(`./on-node-create`)
exports.onCreateNode = onCreateNode
exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.createSchemaCustomization = require(`./create-schema-customization`)
exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`)

Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-remark/src/on-node-create.js
@@ -1,7 +1,7 @@
const grayMatter = require(`gray-matter`)
const _ = require(`lodash`)

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
return (
node.internal.mediaType === `text/markdown` ||
node.internal.mediaType === `text/x-markdown`
Expand All @@ -20,7 +20,7 @@ module.exports.onCreateNode = async function onCreateNode(
pluginOptions
) {
// We only care about markdown content.
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return {}
}

Expand Down Expand Up @@ -81,4 +81,4 @@ module.exports.onCreateNode = async function onCreateNode(
}
}

module.exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
module.exports.shouldOnCreateNode = shouldOnCreateNode
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-screenshot/src/gatsby-node.js
Expand Up @@ -82,7 +82,7 @@ exports.onPreBootstrap = (
})
}

function unstable_shouldOnCreateNode({ node }, pluginOptions) {
function shouldOnCreateNode({ node }, pluginOptions) {
/*
* Check if node is of a type we care about, and has a url field
* (originally only checked sites.yml, hence including by default)
Expand All @@ -91,13 +91,13 @@ function unstable_shouldOnCreateNode({ node }, pluginOptions) {
return validNodeTypes.includes(node.internal.type) && node.url
}

exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode

exports.onCreateNode = async (
{ node, actions, store, cache, createNodeId, createContentDigest, getCache },
pluginOptions
) => {
if (!unstable_shouldOnCreateNode({ node }, pluginOptions)) {
if (!shouldOnCreateNode({ node }, pluginOptions)) {
return
}

Expand Down
7 changes: 2 additions & 5 deletions packages/gatsby-transformer-sharp/src/gatsby-node.js
@@ -1,7 +1,4 @@
const {
onCreateNode,
unstable_shouldOnCreateNode,
} = require(`./on-node-create`)
const { onCreateNode, shouldOnCreateNode } = require(`./on-node-create`)
const { ERROR_MAP } = require(`./error-utils`)

exports.onPreInit = ({ reporter }) => {
Expand All @@ -10,6 +7,6 @@ exports.onPreInit = ({ reporter }) => {
}
}
exports.onCreateNode = onCreateNode
exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
exports.shouldOnCreateNode = shouldOnCreateNode
exports.createSchemaCustomization = require(`./customize-schema`)
exports.createResolvers = require(`./create-resolvers`)
6 changes: 3 additions & 3 deletions packages/gatsby-transformer-sharp/src/on-node-create.js
@@ -1,17 +1,17 @@
const { supportedExtensions } = require(`./supported-extensions`)

function unstable_shouldOnCreateNode({ node }) {
function shouldOnCreateNode({ node }) {
return node.internal.type === `File` && !!supportedExtensions[node.extension]
}

module.exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
module.exports.shouldOnCreateNode = shouldOnCreateNode

module.exports.onCreateNode = async function onCreateNode({
node,
actions,
createNodeId,
}) {
if (!unstable_shouldOnCreateNode({ node })) {
if (!shouldOnCreateNode({ node })) {
return
}

Expand Down