Skip to content

Commit 9dcc773

Browse files
marvinjudewardpeet
andauthored
chore(gatsby, gatsby-transformer-remark, gatsby-plugin-sharp): Cleanup v4 compile flag conditions (#36486)
Co-authored-by: Ward Peeters <[email protected]>
1 parent e421c10 commit 9dcc773

File tree

20 files changed

+152
-270
lines changed

20 files changed

+152
-270
lines changed

packages/gatsby-plugin-sharp/src/gatsby-node.js

+4-27
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ const { slash } = require(`gatsby-core-utils/path`)
1111
const { setPluginOptions } = require(`./plugin-options`)
1212
const path = require(`path`)
1313

14-
let coreSupportsOnPluginInit
15-
try {
16-
const { isGatsbyNodeLifecycleSupported } = require(`gatsby-plugin-utils`)
17-
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
18-
coreSupportsOnPluginInit = isGatsbyNodeLifecycleSupported(`onPluginInit`)
19-
} else {
20-
coreSupportsOnPluginInit = isGatsbyNodeLifecycleSupported(
21-
`unstable_onPluginInit`
22-
)
23-
}
24-
} catch (e) {
25-
coreSupportsOnPluginInit = false
26-
}
27-
2814
function removeCachedValue(cache, key) {
2915
if (cache?.del) {
3016
// if cache expose ".del" method directly on public interface
@@ -129,19 +115,10 @@ exports.onPostBootstrap = async ({ reporter, cache, store }) => {
129115
}
130116
}
131117

132-
if (coreSupportsOnPluginInit) {
133-
// to properly initialize plugin in worker (`onPreBootstrap` won't run in workers)
134-
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
135-
exports.onPluginInit = async ({ actions }, pluginOptions) => {
136-
setActions(actions)
137-
setPluginOptions(pluginOptions)
138-
}
139-
} else {
140-
exports.unstable_onPluginInit = async ({ actions }, pluginOptions) => {
141-
setActions(actions)
142-
setPluginOptions(pluginOptions)
143-
}
144-
}
118+
// to properly initialize plugin in worker (`onPreBootstrap` won't run in workers)
119+
exports.onPluginInit = async ({ actions }, pluginOptions) => {
120+
setActions(actions)
121+
setPluginOptions(pluginOptions)
145122
}
146123

147124
exports.onPreBootstrap = async ({ actions, emitter, cache }, pluginOptions) => {

packages/gatsby-transformer-remark/src/create-schema-customization.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ module.exports = (nodeApiArgs, pluginOptions = {}) => {
4040
// to customize the GraphQL schema. This makes it possible for subplugins to
4141
// modify types owned by `gatsby-transformer-remark`.
4242
plugins.forEach(plugin => {
43-
const resolvedPlugin =
44-
_CFLAGS_.GATSBY_MAJOR === `4` ? plugin.module : require(plugin.resolve)
43+
const resolvedPlugin = plugin.module
4544

4645
if (typeof resolvedPlugin.createSchemaCustomization === `function`) {
4746
resolvedPlugin.createSchemaCustomization(

packages/gatsby-transformer-remark/src/extend-node-type.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ module.exports = function remarkExtendNodeType(
135135
}
136136

137137
for (const plugin of pluginOptions.plugins) {
138-
const requiredPlugin =
139-
_CFLAGS_.GATSBY_MAJOR === `4` ? plugin.module : require(plugin.resolve)
138+
const requiredPlugin = plugin.module
140139
if (_.isFunction(requiredPlugin.setParserPlugins)) {
141140
for (const parserPlugin of requiredPlugin.setParserPlugins(
142141
plugin.pluginOptions
@@ -294,10 +293,8 @@ module.exports = function remarkExtendNodeType(
294293

295294
// Use a for loop to run remark plugins serially.
296295
for (const plugin of pluginOptions.plugins) {
297-
const requiredPlugin =
298-
_CFLAGS_.GATSBY_MAJOR === `4`
299-
? plugin.module
300-
: require(plugin.resolve)
296+
const requiredPlugin = plugin.module
297+
301298
// Allow both exports = function(), and exports.default = function()
302299
const defaultFunction = _.isFunction(requiredPlugin)
303300
? requiredPlugin
@@ -350,10 +347,8 @@ module.exports = function remarkExtendNodeType(
350347
//
351348
// Use for loop to run remark plugins serially.
352349
for (const plugin of pluginOptions.plugins) {
353-
const requiredPlugin =
354-
_CFLAGS_.GATSBY_MAJOR === `4`
355-
? plugin.module
356-
: require(plugin.resolve)
350+
const requiredPlugin = plugin.module
351+
357352
if (typeof requiredPlugin.mutateSource === `function`) {
358353
await requiredPlugin.mutateSource(
359354
{

packages/gatsby-transformer-remark/src/gatsby-node.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,8 @@ exports.pluginOptionsSchema = function ({ Joi }) {
1818
excerpt_separator: Joi.string().description(
1919
`If your Markdown file contains HTML, excerpt will not return a value. In that case, you can set an excerpt_separator to an HTML tag. Edit your Markdown files to include that HTML tag after the text you’d like to appear in the excerpt.`
2020
),
21-
plugins:
22-
_CFLAGS_.GATSBY_MAJOR === `4`
23-
? Joi.subPlugins().description(
24-
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
25-
)
26-
: Joi.array()
27-
.items(
28-
Joi.string(),
29-
Joi.object({
30-
resolve: Joi.string(),
31-
options: Joi.object({}).unknown(true),
32-
})
33-
)
34-
.default([])
35-
.description(
36-
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
37-
),
21+
plugins: Joi.subPlugins().description(
22+
`A list of remark plugins. See also: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-remark for examples`
23+
),
3824
})
3925
}

packages/gatsby/src/bootstrap/load-plugins/load-internal-plugins.ts

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export function loadInternalPlugins(
7676
})
7777

7878
if (
79-
_CFLAGS_.GATSBY_MAJOR === `4` &&
8079
configuredPluginNames.has(GATSBY_CLOUD_PLUGIN_NAME) &&
8180
incompatibleGatsbyCloudPlugin(plugins)
8281
) {

packages/gatsby/src/bootstrap/requires-writer.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,8 @@ const getMatchPaths = (
111111
const matchPathPages: Array<IMatchPathEntry> = []
112112

113113
pages.forEach((page: IGatsbyPage, index: number): void => {
114-
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
115-
if (page.matchPath && getPageMode(page) === `SSG`) {
116-
matchPathPages.push(createMatchPathEntry(page, index))
117-
}
118-
} else {
119-
if (page.matchPath) {
120-
matchPathPages.push(createMatchPathEntry(page, index))
121-
}
114+
if (page.matchPath && getPageMode(page) === `SSG`) {
115+
matchPathPages.push(createMatchPathEntry(page, index))
122116
}
123117
})
124118

packages/gatsby/src/commands/build-html.ts

-8
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,6 @@ export async function buildHTMLPagesAndDeleteStaleArtifacts({
546546
reporter.info(`There are no new or changed html files to build.`)
547547
}
548548

549-
if (_CFLAGS_.GATSBY_MAJOR !== `4` && !program.keepPageRenderer) {
550-
try {
551-
await deleteRenderer(pageRenderer)
552-
} catch (err) {
553-
// pass through
554-
}
555-
}
556-
557549
if (toDelete.length > 0) {
558550
const publicDir = path.join(program.directory, `public`)
559551
const deletePageDataActivityTimer = reporter.activityTimer(

packages/gatsby/src/commands/build-utils.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,7 @@ export function calcDirtyHtmlFiles(state: IGatsbyState): {
162162
// and because of that `isDeleted` might not be set ...
163163
markActionForPage(path, `delete`)
164164
} else {
165-
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
166-
if (getPageMode(page, state) === `SSG`) {
167-
if (htmlFile.dirty || state.html.unsafeBuiltinWasUsedInSSR) {
168-
markActionForPage(path, `regenerate`)
169-
} else {
170-
markActionForPage(path, `reuse`)
171-
}
172-
}
173-
} else {
165+
if (getPageMode(page, state) === `SSG`) {
174166
if (htmlFile.dirty || state.html.unsafeBuiltinWasUsedInSSR) {
175167
markActionForPage(path, `regenerate`)
176168
} else {

packages/gatsby/src/commands/build.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports = async function build(
180180
buildActivityTimer.end()
181181
}
182182

183-
if (_CFLAGS_.GATSBY_MAJOR === `4` && shouldGenerateEngines()) {
183+
if (shouldGenerateEngines()) {
184184
const state = store.getState()
185185
const buildActivityTimer = report.activityTimer(
186186
`Building Rendering Engines`,
@@ -246,7 +246,7 @@ module.exports = async function build(
246246
pageConfigActivity.end()
247247
}
248248

249-
if (_CFLAGS_.GATSBY_MAJOR === `4` && shouldGenerateEngines()) {
249+
if (shouldGenerateEngines()) {
250250
const validateEnginesActivity = report.activityTimer(
251251
`Validating Rendering Engines`,
252252
{
@@ -284,11 +284,10 @@ module.exports = async function build(
284284
const { queryIds } = await calculateDirtyQueries({ store })
285285

286286
// Only run queries with mode SSG
287-
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
288-
queryIds.pageQueryIds = queryIds.pageQueryIds.filter(
289-
query => getPageMode(query) === `SSG`
290-
)
291-
}
287+
288+
queryIds.pageQueryIds = queryIds.pageQueryIds.filter(
289+
query => getPageMode(query) === `SSG`
290+
)
292291

293292
// Start saving page.mode in the main process (while queries run in workers in parallel)
294293
const waitMaterializePageMode = materializePageMode()
@@ -405,7 +404,7 @@ module.exports = async function build(
405404
// we need to save it again to make sure our latest state has been saved
406405
await db.saveState()
407406

408-
if (_CFLAGS_.GATSBY_MAJOR === `4` && shouldGenerateEngines()) {
407+
if (shouldGenerateEngines()) {
409408
// well, tbf we should just generate this in `.cache` and avoid deleting it :shrug:
410409
program.keepPageRenderer = true
411410
}

0 commit comments

Comments
 (0)