Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gatsbyjs/gatsby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: gatsby@4.5.2
Choose a base ref
...
head repository: gatsbyjs/gatsby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: gatsby@4.5.3
Choose a head ref
  • 5 commits
  • 56 files changed
  • 5 contributors

Commits on Jan 17, 2022

  1. fix(gatsby): Fix issue with env variables not being passed to getServ…

    …erData (#34447) (#34508)
    
    Co-authored-by: marvinjude <marvinjudehk@gmail.com>
    Co-authored-by: LekoArts <lekoarts@gmail.com>
    Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
    (cherry picked from commit 64ff3c6)
    
    Co-authored-by: Jude Agboola <marvinjudehk@gmail.com>
    gatsbybot and marvinjude authored Jan 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2fb74de View commit details
  2. fix(gatsby): handle loaded page being potentially undefined (#34488) (#…

    …34509)
    
    (cherry picked from commit 59cd704)
    
    Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
    gatsbybot and pieh authored Jan 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0d29e95 View commit details
  3. fix(gatsby-cli): Re-Add plugin-add functionality (#34482) (#34510)

    (cherry picked from commit 618b32b)
    
    Co-authored-by: Lennart <lekoarts@gmail.com>
    gatsbybot and LekoArts authored Jan 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0f5f7e4 View commit details
  4. fix(create-gatsby): Respect telemetry disable (#34495) (#34511)

    (cherry picked from commit 44b2ef5)
    
    Co-authored-by: Ty Hopp <tyhopp@users.noreply.github.com>
    gatsbybot and tyhopp authored Jan 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9f9cabf View commit details
  5. chore(release): Publish

     - babel-plugin-remove-graphql-queries@4.5.2
     - babel-preset-gatsby@2.5.2
     - create-gatsby@2.5.1
     - gatsby-cli@4.5.2
     - gatsby-core-utils@3.5.2
     - gatsby-page-utils@2.5.2
     - gatsby-plugin-benchmark-reporting@2.5.2
     - gatsby-plugin-gatsby-cloud@4.5.2
     - gatsby-plugin-image@2.5.2
     - gatsby-plugin-manifest@4.5.2
     - gatsby-plugin-mdx@3.5.2
     - gatsby-plugin-offline@5.5.2
     - gatsby-plugin-page-creator@4.5.2
     - gatsby-plugin-preload-fonts@3.5.2
     - gatsby-plugin-sharp@4.5.2
     - gatsby-plugin-typescript@4.5.2
     - gatsby-remark-images@6.5.2
     - gatsby-source-contentful@7.3.2
     - gatsby-source-drupal@5.5.2
     - gatsby-source-filesystem@4.5.2
     - gatsby-source-graphql@4.5.2
     - gatsby-source-shopify@6.5.2
     - gatsby-source-wordpress@6.5.2
     - gatsby-telemetry@3.5.2
     - gatsby-transformer-remark@5.5.2
     - gatsby-transformer-sqip@4.5.2
     - gatsby@4.5.3
    marvinjude committed Jan 17, 2022
    Copy the full SHA
    c493ee7 View commit details
Showing with 984 additions and 566 deletions.
  1. +7 −5 e2e-tests/production-runtime/__tests__/env-vars.js
  2. +45 −0 e2e-tests/production-runtime/cypress/integration/env-vars.js
  3. +2 −2 e2e-tests/production-runtime/package.json
  4. +1 −1 e2e-tests/production-runtime/src/pages/ssr/error-path.js
  5. +1 −1 e2e-tests/production-runtime/src/pages/ssr/param-path/[param].js
  6. +1 −1 e2e-tests/production-runtime/src/pages/ssr/path-ranking/[...].js
  7. +1 −1 e2e-tests/production-runtime/src/pages/ssr/path-ranking/[p1]/[p2].js
  8. +1 −1 e2e-tests/production-runtime/src/pages/ssr/path-ranking/[p1]/page.js
  9. +63 −3 e2e-tests/production-runtime/src/pages/ssr/static-path.js
  10. +1 −1 e2e-tests/production-runtime/src/pages/ssr/wildcard-path/[...wildcard].js
  11. +2 −2 packages/babel-plugin-remove-graphql-queries/package.json
  12. +2 −2 packages/babel-preset-gatsby/package.json
  13. +1 −1 packages/create-gatsby/README.md
  14. +1 −1 packages/create-gatsby/package.json
  15. +61 −0 packages/create-gatsby/src/__tests__/tracking.ts
  16. +23 −0 packages/create-gatsby/src/is-truthy.ts
  17. +32 −0 packages/create-gatsby/src/tracking.ts
  18. +9 −5 packages/gatsby-cli/package.json
  19. +193 −0 packages/gatsby-cli/src/handlers/plugin-add-utils.ts
  20. +86 −0 packages/gatsby-cli/src/handlers/plugin-add.ts
  21. +319 −0 packages/gatsby-cli/src/handlers/plugin-babel-utils.ts
  22. +1 −1 packages/gatsby-core-utils/package.json
  23. +2 −0 packages/gatsby-core-utils/src/index.ts
  24. +2 −2 packages/gatsby-page-utils/package.json
  25. +2 −2 packages/gatsby-plugin-benchmark-reporting/package.json
  26. +3 −3 packages/gatsby-plugin-gatsby-cloud/package.json
  27. +3 −3 packages/gatsby-plugin-image/package.json
  28. +2 −2 packages/gatsby-plugin-manifest/package.json
  29. +2 −2 packages/gatsby-plugin-mdx/package.json
  30. +2 −2 packages/gatsby-plugin-offline/package.json
  31. +4 −4 packages/gatsby-plugin-page-creator/package.json
  32. +2 −2 packages/gatsby-plugin-preload-fonts/package.json
  33. +4 −4 packages/gatsby-plugin-sharp/package.json
  34. +2 −2 packages/gatsby-plugin-typescript/package.json
  35. +2 −2 packages/gatsby-remark-images/package.json
  36. +3 −3 packages/gatsby-source-contentful/package.json
  37. +2 −2 packages/gatsby-source-drupal/package.json
  38. +2 −2 packages/gatsby-source-filesystem/package.json
  39. +2 −2 packages/gatsby-source-graphql/package.json
  40. +4 −4 packages/gatsby-source-shopify/package.json
  41. +5 −5 packages/gatsby-source-wordpress/package.json
  42. +2 −2 packages/gatsby-telemetry/package.json
  43. +2 −2 packages/gatsby-transformer-remark/package.json
  44. +2 −2 packages/gatsby-transformer-sqip/package.json
  45. +4 −1 packages/gatsby/cache-dir/production-app.js
  46. +8 −8 packages/gatsby/package.json
  47. +0 −19 packages/gatsby/src/utils/babel-loader-helpers.js
  48. +0 −27 packages/gatsby/src/utils/babel/__tests__/fixtures/env-vars/arrow-fn/input.mjs
  49. +0 −22 packages/gatsby/src/utils/babel/__tests__/fixtures/env-vars/arrow-fn/output.mjs
  50. +0 −27 packages/gatsby/src/utils/babel/__tests__/fixtures/env-vars/function/input.mjs
  51. +0 −22 packages/gatsby/src/utils/babel/__tests__/fixtures/env-vars/function/output.mjs
  52. +0 −15 packages/gatsby/src/utils/babel/__tests__/fixtures/env-vars/options.json
  53. +0 −80 packages/gatsby/src/utils/babel/babel-plugin-env-vars.ts
  54. +4 −1 packages/gatsby/src/utils/webpack.config.js
  55. +2 −262 renovate.json5
  56. +57 −0 yarn.lock
12 changes: 7 additions & 5 deletions e2e-tests/production-runtime/__tests__/env-vars.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { exec } = require(`child_process`)

const grepJSFilesFor = str =>
const grepJSFilesFor = (str, pathToGrep) =>
new Promise(resolve => {
const grep = exec(`grep -r "${str}" ./public/*.js`)
const grep = exec(`grep -r "${str}" ${pathToGrep}`)

grep.stdout.on(`data`, () => {
grep.stdout.on(`data`, data => {
resolve(true)
return
})
@@ -17,8 +17,10 @@ const grepJSFilesFor = str =>

const checkLeakedEnvVar = async () => {
const isLeaked =
(await grepJSFilesFor(`VERY_SECRET_VAR`)) ||
(await grepJSFilesFor(`it's a secret`))
// we want to make sure unused VERY_SECRET_VAR doesn't end up in js bundles
(await grepJSFilesFor(`VERY_SECRET_VAR`, `./public/*.js`)) ||
// additionally we want to verify that its value don't end up anywhere in public dir
(await grepJSFilesFor(`it's a secret`, `./public`))

if (isLeaked) {
console.error(`Error: VERY_SECRET_VAR found in bundle`)
45 changes: 45 additions & 0 deletions e2e-tests/production-runtime/cypress/integration/env-vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
describe(`Uses env vars correctly`, () => {
it(`SSG page gets right env vars`, () => {
cy.visit(`/env-vars`).waitForRouteChange()

cy.getTestElement(`process.env`).contains(`{}`)
cy.getTestElement(`process.env.EXISTING_VAR`).contains(`"foo bar"`)
cy.getTestElement(`process.env.NOT_EXISTING_VAR`).should(`be.empty`)
})

it(`SSR page gets right env vars`, () => {
cy.visit(`/ssr/static-path`).waitForRouteChange()

cy.getTestElement(`process.env`).contains(`{}`)

// EXISTING_VAR is provided by `.env.production`
// so despite not being prefixed with `GATSBY_` it is
// available to use in react template as well as in getServerData
cy.getTestElement(`process.env.EXISTING_VAR`).contains(`"foo bar"`)
cy.getTestElement(`serverData.envVars.EXISTING_VAR`).contains(`"foo bar"`)

// VERY_SECRET_VAR is not used by browser bundle, but it's used by getServerData
// we want to verify that it's available to getServerData and at the same time check
// if it doesn't leak to browser bundle (we do so by running `test-env-vars` script)
// We do use alias "VERY_SECRET_ALIAS_VAR" so that "VERY_SECRET_VAR" doesn't end up
// in public dir and mess with our test scanning public directory
cy.getTestElement(`serverData.envVars.VERY_SECRET_ALIAS_VAR`).contains(
`"it's a secret"`
)

// NOT_EXISTING_VAR is not defined at all so we expect it to be blank
// both in react template and in getServerData
cy.getTestElement(`process.env.NOT_EXISTING_VAR`).should(`be.empty`)
cy.getTestElement(`serverData.envVars.NOT_EXISTING_VAR`).should(`be.empty`)

// FROM_COMMAND_LINE is just in `process.env.`, but it's not prefixed with
// `GATSBY_` so it's not available for react template (process.env.FROM_COMMAND_LINE)
// but it is available to getServerData
cy.getTestElement(`process.env.FROM_COMMAND_LINE`).should(`be.empty`)
cy.getTestElement(`serverData.envVars.FROM_COMMAND_LINE`).contains(`"YES"`)

//prefix env should be available in `process.env` and getServerData
cy.getTestElement(`process.env.GATSBY_PREFIXED_FROM_COMMAND_LINE`).contains(`"YES"`)
cy.getTestElement(`serverData.envVars.GATSBY_PREFIXED_FROM_COMMAND_LINE`).contains(`"YES"`)
})
})
4 changes: 2 additions & 2 deletions e2e-tests/production-runtime/package.json
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@
],
"license": "MIT",
"scripts": {
"build": "cross-env CYPRESS_SUPPORT=y gatsby build",
"build:offline": "cross-env TEST_PLUGIN_OFFLINE=y CYPRESS_SUPPORT=y gatsby build",
"build": "cross-env GATSBY_PREFIXED_FROM_COMMAND_LINE=YES FROM_COMMAND_LINE=YES CYPRESS_SUPPORT=y gatsby build",
"build:offline": "cross-env GATSBY_PREFIXED_FROM_COMMAND_LINE=YES FROM_COMMAND_LINE=YES TEST_PLUGIN_OFFLINE=y CYPRESS_SUPPORT=y gatsby build",
"develop": "cross-env CYPRESS_SUPPORT=y gatsby develop",
"format": "prettier --write '**/*.js' --ignore-path .gitignore",
"serve": "gatsby serve",
2 changes: 1 addition & 1 deletion e2e-tests/production-runtime/src/pages/ssr/error-path.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,6 @@ export default function ErrorPath({ serverData }) {
)
}

export function getServerData() {
export async function getServerData() {
throw new Error(`Some runtime error`)
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default function Params({ serverData }) {
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
return {
props: {
arg,
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default function StaticPath({ serverData }) {
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
return {
props: {
arg,
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default function StaticPath({ serverData }) {
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
return {
props: {
arg,
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default function StaticPath({ serverData }) {
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
return {
props: {
arg,
66 changes: 63 additions & 3 deletions e2e-tests/production-runtime/src/pages/ssr/static-path.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,82 @@
import React from "react"

const UseEnv = ({ heading, envVar }) => (
<React.Fragment>
<h3>{heading}</h3>
<pre>
<code data-testid={heading}>{JSON.stringify(envVar)}</code>
</pre>
</React.Fragment>
)

export default function StaticPath({ serverData }) {
return (
<div>
<h2>Query</h2>
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre>
<h2>Params</h2>
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre>
<h2>Debug</h2>
<pre>{JSON.stringify({ serverData }, null, 2)}</pre>
<h2>Using env vars (react template)</h2>
<UseEnv heading="process.env" envVar={process.env} />
<UseEnv
heading="process.env.EXISTING_VAR"
envVar={process.env.EXISTING_VAR}
/>
<UseEnv
heading="process.env.NOT_EXISTING_VAR"
envVar={process.env.NOT_EXISTING_VAR}
/>
<UseEnv
heading="process.env.FROM_COMMAND_LINE"
envVar={process.env.FROM_COMMAND_LINE}
/>
<UseEnv
heading="process.env.GATSBY_PREFIXED_FROM_COMMAND_LINE"
envVar={process.env.GATSBY_PREFIXED_FROM_COMMAND_LINE}
/>

<h2>Using env vars (getServerData)</h2>
<UseEnv
heading="serverData.envVars.VERY_SECRET_ALIAS_VAR"
envVar={serverData?.envVars?.VERY_SECRET_ALIAS_VAR}
/>
<UseEnv
heading="serverData.envVars.EXISTING_VAR"
envVar={serverData?.envVars?.EXISTING_VAR}
/>
<UseEnv
heading="serverData.envVars.NOT_EXISTING_VAR"
envVar={serverData?.envVars?.NOT_EXISTING_VAR}
/>
<UseEnv
heading="serverData.envVars.FROM_COMMAND_LINE"
envVar={serverData?.envVars.FROM_COMMAND_LINE}
/>

<UseEnv
heading="serverData.envVars.GATSBY_PREFIXED_FROM_COMMAND_LINE"
envVar={serverData?.envVars.GATSBY_PREFIXED_FROM_COMMAND_LINE}
/>

</div>
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
const VERY_SECRET_ALIAS_VAR = process.env.VERY_SECRET_VAR
const EXISTING_VAR = process.env.EXISTING_VAR
const FROM_COMMAND_LINE = process.env.FROM_COMMAND_LINE
const GATSBY_PREFIXED_FROM_COMMAND_LINE = process.env.GATSBY_PREFIXED_FROM_COMMAND_LINE

return {
props: {
arg,
envVars: {
VERY_SECRET_ALIAS_VAR,
EXISTING_VAR,
FROM_COMMAND_LINE,
GATSBY_PREFIXED_FROM_COMMAND_LINE
},
},
}
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default function Wildcard({ serverData }) {
)
}

export function getServerData(arg) {
export async function getServerData(arg) {
return {
props: {
arg,
4 changes: 2 additions & 2 deletions packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-remove-graphql-queries",
"version": "4.5.1",
"version": "4.5.2",
"author": "Jason Quense <monastic.panic@gmail.com>",
"repository": {
"type": "git",
@@ -10,7 +10,7 @@
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-plugin-remove-graphql-queries#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"gatsby-core-utils": "^3.5.1"
"gatsby-core-utils": "^3.5.2"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
4 changes: 2 additions & 2 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-gatsby",
"version": "2.5.1",
"version": "2.5.2",
"author": "Philipp Spiess <hello@philippspiess.com>",
"repository": {
"type": "git",
@@ -22,7 +22,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-macros": "^2.8.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"gatsby-core-utils": "^3.5.1",
"gatsby-core-utils": "^3.5.2",
"gatsby-legacy-polyfills": "^2.5.0"
},
"peerDependencies": {
2 changes: 1 addition & 1 deletion packages/create-gatsby/README.md
Original file line number Diff line number Diff line change
@@ -62,5 +62,5 @@ Open another terminal window and go to a folder where you can easily delete the
cd <path-to-playground>
# Run the create-gatsby script
node <some-path/packages/create-gatsby/cli.js
node <some-path>/packages/create-gatsby/cli.js
```
2 changes: 1 addition & 1 deletion packages/create-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gatsby",
"version": "2.5.0",
"version": "2.5.1",
"main": "lib/index.js",
"bin": "cli.js",
"license": "MIT",
61 changes: 61 additions & 0 deletions packages/create-gatsby/src/__tests__/tracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
let isTrackingEnabled: () => boolean

const get = jest.fn()
const set = jest.fn()

jest.doMock(`../get-config-store`, () => {
return {
getConfigStore: (): unknown => {
return {
get,
set,
}
},
}
})

describe(`isTrackingEnabled`, () => {
beforeEach(() => {
jest.resetModules()
isTrackingEnabled = require(`../tracking`).isTrackingEnabled
})

it(`is enabled by default`, () => {
const enabled = isTrackingEnabled()
expect(enabled).toBeTrue()
})

it(`respects the setting of the config store`, () => {
get.mockImplementationOnce(key => {
if (key === `telemetry.enabled`) {
return false
} else {
return true
}
})

const enabled = isTrackingEnabled()
expect(enabled).toBeFalse()

const cachedEnabled = isTrackingEnabled()
expect(cachedEnabled).toBeFalse()
})

describe(`process.env.GATSBY_TELEMETRY_DISABLED`, () => {
beforeAll(() => {
process.env.GATSBY_TELEMETRY_DISABLED = `true`
})

it(`respects the setting of the environment variable`, () => {
const enabled = isTrackingEnabled()
expect(enabled).toBeFalse()

const cachedEnabled = isTrackingEnabled()
expect(cachedEnabled).toBeFalse()
})

afterAll(() => {
process.env.GATSBY_TELEMETRY_DISABLED = undefined
})
})
})
23 changes: 23 additions & 0 deletions packages/create-gatsby/src/is-truthy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copied from gatsby-core-utils to avoid depending on it, similar to get-config-store
//
// Returns true for `true`, true, positive numbers
// Returns false for `false`, false, 0, negative integers and anything else
export function isTruthy(value: any): boolean {
// Return if Boolean
if (typeof value === `boolean`) return value

// Return false if null or undefined
if (value === undefined || value === null) return false

// If the String is true or false
if (value.toLowerCase() === `true`) return true
if (value.toLowerCase() === `false`) return false

// Now check if it's a number
const number = parseInt(value, 10)
if (isNaN(number)) return false
if (number > 0) return true

// Default to false
return false
}
Loading