Skip to content

Commit 5f66cb1

Browse files
GatsbyJS Botsidharthachatterjee
GatsbyJS Bot
andauthored
feat(gatsby): Turn on Functions experiment for everybody (#31807) (#31826)
* Ship functions for everyone * Set FUNCTIONS to LOCKED_IN * Add mock for panicOnBuild * Fix test * Update packages/gatsby/src/bootstrap/load-plugins/load.ts Co-authored-by: Vladimir Razuvaev <[email protected]> Co-authored-by: Vladimir Razuvaev <[email protected]> (cherry picked from commit a485415) Co-authored-by: Sidhartha Chatterjee <[email protected]>
1 parent 850826c commit 5f66cb1

File tree

6 files changed

+126
-44
lines changed

6 files changed

+126
-44
lines changed

packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.ts.snap

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ Array [
8686
"ssrAPIs": Array [],
8787
"version": "1.0.0",
8888
},
89+
Object {
90+
"browserAPIs": Array [],
91+
"id": "",
92+
"name": "functions",
93+
"nodeAPIs": Array [
94+
"onPreBootstrap",
95+
"onCreateDevServer",
96+
],
97+
"pluginOptions": Object {
98+
"plugins": Array [],
99+
},
100+
"resolve": "",
101+
"ssrAPIs": Array [],
102+
"version": "1.0.0",
103+
},
89104
Object {
90105
"browserAPIs": Array [],
91106
"id": "",
@@ -194,6 +209,24 @@ Array [
194209
"ssrAPIs": Array [],
195210
"version": "1.0.0",
196211
},
212+
Object {
213+
"browserAPIs": Array [],
214+
"id": "",
215+
"name": "gatsby-plugin-page-creator",
216+
"nodeAPIs": Array [
217+
"createPagesStatefully",
218+
"setFieldsOnGraphQLNodeType",
219+
"onPreInit",
220+
],
221+
"pluginOptions": Object {
222+
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
223+
"pathCheck": false,
224+
"plugins": Array [],
225+
},
226+
"resolve": "",
227+
"ssrAPIs": Array [],
228+
"version": "1.0.0",
229+
},
197230
Object {
198231
"browserAPIs": Array [],
199232
"id": "",
@@ -333,6 +366,21 @@ Array [
333366
"ssrAPIs": Array [],
334367
"version": "1.0.0",
335368
},
369+
Object {
370+
"browserAPIs": Array [],
371+
"id": "",
372+
"name": "functions",
373+
"nodeAPIs": Array [
374+
"onPreBootstrap",
375+
"onCreateDevServer",
376+
],
377+
"pluginOptions": Object {
378+
"plugins": Array [],
379+
},
380+
"resolve": "",
381+
"ssrAPIs": Array [],
382+
"version": "1.0.0",
383+
},
336384
Object {
337385
"browserAPIs": Array [],
338386
"id": "",
@@ -453,6 +501,24 @@ Array [
453501
"ssrAPIs": Array [],
454502
"version": "1.0.0",
455503
},
504+
Object {
505+
"browserAPIs": Array [],
506+
"id": "",
507+
"name": "gatsby-plugin-page-creator",
508+
"nodeAPIs": Array [
509+
"createPagesStatefully",
510+
"setFieldsOnGraphQLNodeType",
511+
"onPreInit",
512+
],
513+
"pluginOptions": Object {
514+
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
515+
"pathCheck": false,
516+
"plugins": Array [],
517+
},
518+
"resolve": "",
519+
"ssrAPIs": Array [],
520+
"version": "1.0.0",
521+
},
456522
Object {
457523
"browserAPIs": Array [],
458524
"id": "",
@@ -610,6 +676,21 @@ Array [
610676
"ssrAPIs": Array [],
611677
"version": "1.0.0",
612678
},
679+
Object {
680+
"browserAPIs": Array [],
681+
"id": "",
682+
"name": "functions",
683+
"nodeAPIs": Array [
684+
"onPreBootstrap",
685+
"onCreateDevServer",
686+
],
687+
"pluginOptions": Object {
688+
"plugins": Array [],
689+
},
690+
"resolve": "",
691+
"ssrAPIs": Array [],
692+
"version": "1.0.0",
693+
},
613694
Object {
614695
"browserAPIs": Array [],
615696
"id": "",
@@ -738,6 +819,24 @@ Array [
738819
"ssrAPIs": Array [],
739820
"version": "1.0.0",
740821
},
822+
Object {
823+
"browserAPIs": Array [],
824+
"id": "",
825+
"name": "gatsby-plugin-page-creator",
826+
"nodeAPIs": Array [
827+
"createPagesStatefully",
828+
"setFieldsOnGraphQLNodeType",
829+
"onPreInit",
830+
],
831+
"pluginOptions": Object {
832+
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
833+
"pathCheck": false,
834+
"plugins": Array [],
835+
},
836+
"resolve": "",
837+
"ssrAPIs": Array [],
838+
"version": "1.0.0",
839+
},
741840
Object {
742841
"browserAPIs": Array [],
743842
"id": "",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
88
return {
99
error: jest.fn(),
1010
panic: jest.fn(),
11+
panicOnBuild: jest.fn(),
1112
log: jest.fn(),
1213
warn: jest.fn(),
1314
success: jest.fn(),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ export function loadPlugins(
243243
`../../internal-plugins/prod-404`,
244244
`../../internal-plugins/webpack-theme-component-shadowing`,
245245
`../../internal-plugins/bundle-optimisations`,
246-
process.env.GATSBY_EXPERIMENTAL_FUNCTIONS &&
247-
`../../internal-plugins/functions`,
246+
`../../internal-plugins/functions`,
248247
].filter(Boolean) as Array<string>
249248
internalPlugins.forEach(relPath => {
250249
const absPath = path.join(__dirname, relPath)

packages/gatsby/src/internal-plugins/functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "functions",
33
"version": "1.0.0",
44
"description": "An internal Gatsby plugin which lets one write serverless functions",
5-
"main": "index.js",
5+
"main": "index.ts",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},

packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -119,46 +119,8 @@ exports.sourceNodes = ({
119119
watchConfig(pathToGatsbyConfig, createGatsbyConfigNode)
120120

121121
// Create nodes for functions
122-
if (process.env.GATSBY_EXPERIMENTAL_FUNCTIONS) {
123-
const { functions } = store.getState()
124-
const createFunctionNode = config => {
125-
createNode({
126-
id: `gatsby-function-${config.absoluteCompiledFilePath}`,
127-
...config,
128-
parent: null,
129-
children: [],
130-
internal: {
131-
contentDigest: createContentDigest(config),
132-
type: `SiteFunction`,
133-
},
134-
})
135-
}
136-
functions.forEach(config => {
137-
createFunctionNode(config)
138-
})
139-
140-
// Listen for updates to functions to update the nodes.
141-
emitter.on(`SET_SITE_FUNCTIONS`, action => {
142-
// Identify any now deleted functions and remove their nodes.
143-
const existingNodes = getNodesByType(`SiteFunction`)
144-
const newFunctionsSet = new Set()
145-
action.payload.forEach(config =>
146-
newFunctionsSet.add(
147-
`gatsby-function-${config.absoluteCompiledFilePath}`
148-
)
149-
)
150-
const toBeDeleted = existingNodes.filter(
151-
node => !newFunctionsSet.has(node.id)
152-
)
153-
toBeDeleted.forEach(node => deleteNode(node))
154-
155-
action.payload.forEach(config => {
156-
createFunctionNode(config)
157-
})
158-
})
159-
} else {
160-
// If not enabled, create a dummy node so we can ignore it in the dev 404 page
161-
const config = { functionRoute: `FAKE`, absoluteCompiledFilePath: `FAKE` }
122+
const { functions } = store.getState()
123+
const createFunctionNode = config => {
162124
createNode({
163125
id: `gatsby-function-${config.absoluteCompiledFilePath}`,
164126
...config,
@@ -170,6 +132,27 @@ exports.sourceNodes = ({
170132
},
171133
})
172134
}
135+
functions.forEach(config => {
136+
createFunctionNode(config)
137+
})
138+
139+
// Listen for updates to functions to update the nodes.
140+
emitter.on(`SET_SITE_FUNCTIONS`, action => {
141+
// Identify any now deleted functions and remove their nodes.
142+
const existingNodes = getNodesByType(`SiteFunction`)
143+
const newFunctionsSet = new Set()
144+
action.payload.forEach(config =>
145+
newFunctionsSet.add(`gatsby-function-${config.absoluteCompiledFilePath}`)
146+
)
147+
const toBeDeleted = existingNodes.filter(
148+
node => !newFunctionsSet.has(node.id)
149+
)
150+
toBeDeleted.forEach(node => deleteNode(node))
151+
152+
action.payload.forEach(config => {
153+
createFunctionNode(config)
154+
})
155+
})
173156
}
174157

175158
function watchConfig(pathToGatsbyConfig, createGatsbyConfigNode) {

packages/gatsby/src/utils/flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const activeFlags: Array<IFlag> = [
180180
experimental: false,
181181
description: `Compile Serverless functions in your Gatsby project and write them to disk, ready to deploy to Gatsby Cloud`,
182182
umbrellaIssue: `https://gatsby.dev/functions-feedback`,
183-
testFitness: (): fitnessEnum => true,
183+
testFitness: (): fitnessEnum => `LOCKED_IN`,
184184
},
185185
{
186186
name: `CONCURRENT_FEATURES`,

0 commit comments

Comments
 (0)