├── demo ├── .nvmrc ├── .npmrc ├── .env.production ├── plugins │ └── gatsby-plugin-image-cdn-test │ │ ├── package.json │ │ └── gatsby-node.js ├── tsconfig.json ├── src │ ├── api │ │ ├── dir │ │ │ ├── [...].js │ │ │ └── function.js │ │ ├── i-am-json.js │ │ ├── env-variables.js │ │ ├── top-level.js │ │ ├── hello-ts.ts │ │ ├── hello-world.js │ │ ├── users │ │ │ └── [userId] │ │ │ │ └── [super].js │ │ ├── a-directory │ │ │ ├── function.js │ │ │ └── index.js │ │ ├── error-send-function-twice.js │ │ ├── some-אודות.js │ │ ├── status.js │ │ ├── I-Am-Capitalized.js │ │ ├── some whitespace.js │ │ ├── some-àè-french.js │ │ ├── with-äöü-umlaut.js │ │ ├── redirect-me.ts │ │ ├── cookie-me.ts │ │ ├── i-am-typescript.ts │ │ ├── cors.js │ │ └── parser.js │ ├── template │ │ ├── post.module.css │ │ └── post.js │ ├── images │ │ └── icon.png │ ├── layout │ │ ├── default.module.css │ │ └── default.js │ └── pages │ │ ├── bad-dog.js │ │ ├── index.module.css │ │ ├── 500.js │ │ ├── dog.js │ │ ├── 404.js │ │ ├── blog.js │ │ └── image-cdn.js ├── .env.development ├── content │ └── posts │ │ ├── hello-world │ │ ├── salty_egg.jpg │ │ └── index.md │ │ └── my-second-post │ │ └── index.md ├── .gitignore ├── netlify.toml ├── gatsby-config.js ├── package.json ├── gatsby-node.js └── README.md ├── demo-v5 ├── .nvmrc ├── .npmrc ├── .env.production ├── plugins │ └── gatsby-plugin-image-cdn-test │ │ ├── package.json │ │ └── gatsby-node.js ├── tsconfig.json ├── src │ ├── template │ │ ├── post.module.css │ │ └── post.js │ ├── api │ │ ├── dir │ │ │ ├── [...].js │ │ │ └── function.js │ │ ├── i-am-json.js │ │ ├── env-variables.js │ │ ├── top-level.js │ │ ├── hello-ts.ts │ │ ├── users │ │ │ └── [userId] │ │ │ │ └── [super].js │ │ ├── hello-world.js │ │ ├── a-directory │ │ │ ├── function.js │ │ │ └── index.js │ │ ├── error-send-function-twice.js │ │ ├── some-אודות.js │ │ ├── status.js │ │ ├── I-Am-Capitalized.js │ │ ├── some whitespace.js │ │ ├── some-àè-french.js │ │ ├── with-äöü-umlaut.js │ │ ├── cookie-me.ts │ │ ├── redirect-me.ts │ │ ├── i-am-typescript.ts │ │ ├── cors.js │ │ └── parser.js │ ├── images │ │ └── icon.png │ ├── layout │ │ ├── default.module.css │ │ └── default.js │ └── pages │ │ ├── bad-dog.js │ │ ├── index.module.css │ │ ├── 500.js │ │ ├── dog.js │ │ ├── 404.js │ │ ├── blog.js │ │ └── image-cdn.js ├── .env.development ├── content │ └── posts │ │ ├── hello-world │ │ └── salty_egg.jpg │ │ └── my-second-post │ │ └── index.md ├── .gitignore ├── netlify.toml ├── gatsby-config.js ├── package.json ├── gatsby-node.js └── README.md ├── .gitattributes ├── plugin ├── .npmrc ├── .gitignore ├── test │ ├── fixtures │ │ ├── v5 │ │ │ ├── with-adapters │ │ │ │ ├── .nvmrc │ │ │ │ ├── e2e-tests │ │ │ │ │ ├── fixtures │ │ │ │ │ │ └── test.txt │ │ │ │ │ ├── functions.test.js │ │ │ │ │ ├── __snapshots__ │ │ │ │ │ │ └── functions.test.js.snap │ │ │ │ │ └── build.test.js │ │ │ │ ├── .env.production │ │ │ │ ├── src │ │ │ │ │ ├── api │ │ │ │ │ │ ├── i-am-false.js │ │ │ │ │ │ ├── i-am-status.js │ │ │ │ │ │ ├── dir │ │ │ │ │ │ │ ├── [...].js │ │ │ │ │ │ │ └── function.js │ │ │ │ │ │ ├── i-am-text.js │ │ │ │ │ │ ├── i-am-json.js │ │ │ │ │ │ ├── env-variables.js │ │ │ │ │ │ ├── i-am-json-too.js │ │ │ │ │ │ ├── top-level.js │ │ │ │ │ │ ├── hello-ts.ts │ │ │ │ │ │ ├── users │ │ │ │ │ │ │ └── [userId] │ │ │ │ │ │ │ │ └── [super].js │ │ │ │ │ │ ├── hello-world.js │ │ │ │ │ │ ├── a-directory │ │ │ │ │ │ │ ├── function.js │ │ │ │ │ │ │ └── index.js │ │ │ │ │ │ ├── error-send-function-twice.js │ │ │ │ │ │ ├── some-אודות.js │ │ │ │ │ │ ├── status.js │ │ │ │ │ │ ├── I-Am-Capitalized.js │ │ │ │ │ │ ├── some whitespace.js │ │ │ │ │ │ ├── some-àè-french.js │ │ │ │ │ │ ├── with-äöü-umlaut.js │ │ │ │ │ │ ├── cookie-me.ts │ │ │ │ │ │ ├── redirect-me.ts │ │ │ │ │ │ ├── i-am-typescript.ts │ │ │ │ │ │ ├── cors.js │ │ │ │ │ │ └── parser.js │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── netlify.toml │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ └── package.json │ │ │ ├── functions-without-gatsby-plugin │ │ │ │ ├── .nvmrc │ │ │ │ ├── .env.production │ │ │ │ ├── e2e-tests │ │ │ │ │ ├── fixtures │ │ │ │ │ │ └── test.txt │ │ │ │ │ ├── functions.test.js │ │ │ │ │ └── __snapshots__ │ │ │ │ │ │ └── functions.test.js.snap │ │ │ │ ├── src │ │ │ │ │ ├── api │ │ │ │ │ │ ├── i-am-status.js │ │ │ │ │ │ ├── dir │ │ │ │ │ │ │ ├── [...].js │ │ │ │ │ │ │ └── function.js │ │ │ │ │ │ ├── i-am-false.js │ │ │ │ │ │ ├── i-am-text.js │ │ │ │ │ │ ├── i-am-json.js │ │ │ │ │ │ ├── env-variables.js │ │ │ │ │ │ ├── i-am-json-too.js │ │ │ │ │ │ ├── top-level.js │ │ │ │ │ │ ├── hello-ts.ts │ │ │ │ │ │ ├── users │ │ │ │ │ │ │ └── [userId] │ │ │ │ │ │ │ │ └── [super].js │ │ │ │ │ │ ├── hello-world.js │ │ │ │ │ │ ├── a-directory │ │ │ │ │ │ │ ├── function.js │ │ │ │ │ │ │ └── index.js │ │ │ │ │ │ ├── error-send-function-twice.js │ │ │ │ │ │ ├── some-אודות.js │ │ │ │ │ │ ├── status.js │ │ │ │ │ │ ├── some whitespace.js │ │ │ │ │ │ ├── some-àè-french.js │ │ │ │ │ │ ├── with-äöü-umlaut.js │ │ │ │ │ │ ├── I-Am-Capitalized.js │ │ │ │ │ │ ├── redirect-me.ts │ │ │ │ │ │ ├── cookie-me.ts │ │ │ │ │ │ ├── i-am-typescript.ts │ │ │ │ │ │ ├── cors.js │ │ │ │ │ │ └── parser.js │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── netlify.toml │ │ │ │ ├── .env.development │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ └── package.json │ │ │ ├── with-no-plugins │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── package.json │ │ │ │ ├── LICENSE │ │ │ │ └── src │ │ │ │ │ └── pages │ │ │ │ │ └── 404.js │ │ │ ├── no-functions │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── package.json │ │ │ │ └── LICENSE │ │ │ ├── with-old-netlify-plugin │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ └── package.json │ │ │ ├── with-old-gatsby-plugin │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ └── package.json │ │ │ └── with-no-gatsby-config │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ └── pages │ │ │ │ └── 404.js │ │ ├── v4 │ │ │ ├── functions-without-gatsby-plugin │ │ │ │ ├── .nvmrc │ │ │ │ ├── .env.production │ │ │ │ ├── e2e-tests │ │ │ │ │ ├── fixtures │ │ │ │ │ │ └── test.txt │ │ │ │ │ ├── functions.test.js │ │ │ │ │ └── __snapshots__ │ │ │ │ │ │ └── functions.test.js.snap │ │ │ │ ├── src │ │ │ │ │ ├── api │ │ │ │ │ │ ├── i-am-status.js │ │ │ │ │ │ ├── dir │ │ │ │ │ │ │ ├── [...].js │ │ │ │ │ │ │ └── function.js │ │ │ │ │ │ ├── i-am-false.js │ │ │ │ │ │ ├── i-am-text.js │ │ │ │ │ │ ├── i-am-json.js │ │ │ │ │ │ ├── env-variables.js │ │ │ │ │ │ ├── i-am-json-too.js │ │ │ │ │ │ ├── top-level.js │ │ │ │ │ │ ├── hello-ts.ts │ │ │ │ │ │ ├── users │ │ │ │ │ │ │ └── [userId] │ │ │ │ │ │ │ │ └── [super].js │ │ │ │ │ │ ├── hello-world.js │ │ │ │ │ │ ├── a-directory │ │ │ │ │ │ │ ├── function.js │ │ │ │ │ │ │ └── index.js │ │ │ │ │ │ ├── error-send-function-twice.js │ │ │ │ │ │ ├── some-אודות.js │ │ │ │ │ │ ├── status.js │ │ │ │ │ │ ├── some whitespace.js │ │ │ │ │ │ ├── some-àè-french.js │ │ │ │ │ │ ├── with-äöü-umlaut.js │ │ │ │ │ │ ├── I-Am-Capitalized.js │ │ │ │ │ │ ├── redirect-me.ts │ │ │ │ │ │ ├── cookie-me.ts │ │ │ │ │ │ ├── i-am-typescript.ts │ │ │ │ │ │ ├── cors.js │ │ │ │ │ │ └── parser.js │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── netlify.toml │ │ │ │ ├── .env.development │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ └── package.json │ │ │ ├── with-no-plugins │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── package.json │ │ │ │ ├── LICENSE │ │ │ │ └── src │ │ │ │ │ └── pages │ │ │ │ │ └── 404.js │ │ │ ├── no-functions │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── package.json │ │ │ │ └── LICENSE │ │ │ ├── with-old-netlify-plugin │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── .gitignore │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── icon.png │ │ │ │ │ └── pages │ │ │ │ │ │ └── 404.js │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ └── package.json │ │ │ ├── with-old-gatsby-plugin │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── gatsby-config.js │ │ │ │ ├── e2e-tests │ │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ └── package.json │ │ │ └── with-no-gatsby-config │ │ │ │ ├── .gitignore │ │ │ │ ├── netlify.toml │ │ │ │ ├── e2e-tests │ │ │ │ └── build.test.js │ │ │ │ ├── LICENSE │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ └── pages │ │ │ │ └── 404.js │ │ └── v3 │ │ │ └── esm-gatsby-config │ │ │ ├── actual-gatsby-config.js │ │ │ ├── .gitignore │ │ │ ├── gatsby-config.js │ │ │ ├── netlify.toml │ │ │ ├── e2e-tests │ │ │ └── build.test.js │ │ │ ├── LICENSE │ │ │ ├── package.json │ │ │ └── src │ │ │ └── pages │ │ │ └── 404.js │ ├── v3-e2e-test.sh │ ├── v4-e2e-test.sh │ ├── v5-e2e-test.sh │ ├── helpers.js │ └── unit │ │ └── helpers │ │ └── functions.spec.ts ├── manifest.yml ├── src │ ├── helpers │ │ ├── cache.ts │ │ └── verification.ts │ └── templates │ │ ├── image.ts │ │ └── api │ │ └── gatsbyFunction.ts └── package.json ├── .github ├── CODEOWNERS ├── .kodiak.toml ├── workflows │ ├── add-to-project.yml │ ├── add-zenhub-label.yml │ ├── labeler.yml │ ├── fossa.yml │ ├── release-please.yml │ ├── pre-release.yml │ └── test.yml ├── pull_request_template.md └── ISSUE_TEMPLATE │ └── feature_request.md ├── .release-please-manifest.json ├── commitlint.config.js ├── netlify.toml ├── netlify-gatsby-plugin.png ├── .prettierrc.yml ├── release-please-config.json ├── jest.config.js ├── .editorconfig ├── .gitignore ├── .eslintignore ├── .prettierignore ├── renovate.json5 ├── LICENSE.md ├── CONTRIBUTING.md ├── .eslintrc.js ├── docs └── image-cdn.md ├── package.json ├── CODE_OF_CONDUCT.md └── README.md /demo/.nvmrc: -------------------------------------------------------------------------------- 1 | lts/fermium 2 | -------------------------------------------------------------------------------- /demo-v5/.nvmrc: -------------------------------------------------------------------------------- 1 | lts/hydrogen 2 | -------------------------------------------------------------------------------- /demo/.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /demo-v5/.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true -------------------------------------------------------------------------------- /demo/.env.production: -------------------------------------------------------------------------------- 1 | pickle=word 2 | -------------------------------------------------------------------------------- /plugin/.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true -------------------------------------------------------------------------------- /demo-v5/.env.production: -------------------------------------------------------------------------------- 1 | pickle=word 2 | -------------------------------------------------------------------------------- /plugin/.gitignore: -------------------------------------------------------------------------------- 1 | README.md 2 | lib 3 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @netlify/ecosystem-pod-frameworks 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/.nvmrc: -------------------------------------------------------------------------------- 1 | v14.17.0 2 | -------------------------------------------------------------------------------- /demo/plugins/gatsby-plugin-image-cdn-test/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugin": "3.8.4" 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/plugins/gatsby-plugin-image-cdn-test/package.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/e2e-tests/fixtures/test.txt: -------------------------------------------------------------------------------- 1 | hi -------------------------------------------------------------------------------- /demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../plugin/tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/.env.production: -------------------------------------------------------------------------------- 1 | pickle=word 2 | -------------------------------------------------------------------------------- /demo-v5/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../plugin/tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/.nvmrc: -------------------------------------------------------------------------------- 1 | v14.17.0 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/.nvmrc: -------------------------------------------------------------------------------- 1 | v14.17.0 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = {} 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = {} 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/actual-gatsby-config.js: -------------------------------------------------------------------------------- 1 | export default {} 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/.env.production: -------------------------------------------------------------------------------- 1 | pickle=word 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/e2e-tests/fixtures/test.txt: -------------------------------------------------------------------------------- 1 | hi -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/.env.production: -------------------------------------------------------------------------------- 1 | pickle=word 2 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/e2e-tests/fixtures/test.txt: -------------------------------------------------------------------------------- 1 | hi -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ['@commitlint/config-conventional'] } 2 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | base="demo/" 3 | 4 | [build.environment] 5 | NODE_VERSION = "14.17.0" 6 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [], 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [], 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/template/post.module.css: -------------------------------------------------------------------------------- 1 | .containerCss { 2 | max-width: 800px; 3 | margin: 0 auto; 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/dir/[...].js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/template/post.module.css: -------------------------------------------------------------------------------- 1 | .containerCss { 2 | max-width: 800px; 3 | margin: 0 auto; 4 | } 5 | -------------------------------------------------------------------------------- /demo-v5/src/api/dir/[...].js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/demo/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [], 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [], 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/api/i-am-json.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/i-am-json.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /netlify-gatsby-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/netlify-gatsby-plugin.png -------------------------------------------------------------------------------- /demo-v5/src/api/env-variables.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(process.env.pickle) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/api/top-level.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at the top-level`) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/demo-v5/src/images/icon.png -------------------------------------------------------------------------------- /demo/src/api/env-variables.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(process.env.pickle) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/top-level.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at the top-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /demo-v5/src/api/hello-ts.ts: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/api/users/[userId]/[super].js: -------------------------------------------------------------------------------- 1 | export default function userIdHandler(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/hello-ts.ts: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/hello-world.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/users/[userId]/[super].js: -------------------------------------------------------------------------------- 1 | export default function userIdHandler(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /demo-v5/src/api/hello-world.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify 5 | package-lock.json -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | semi: false 2 | singleQuote: true 3 | printWidth: 80 4 | endOfLine: lf 5 | proseWrap: always 6 | trailingComma: all 7 | -------------------------------------------------------------------------------- /demo-v5/src/api/a-directory/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at a secondary-level`) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/a-directory/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at a secondary-level`) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/dir/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am another sub-directory function`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-false.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(false) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(200) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/api/dir/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am another sub-directory function`) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/a-directory/index.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am an index.js in a sub-directory!`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/dir/[...].js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-text.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send('I am text') 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/src/api/a-directory/index.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am an index.js in a sub-directory!`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify/cache 5 | .netlify/functions 6 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify/cache 5 | .netlify/functions 6 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-json.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/.env.development: -------------------------------------------------------------------------------- 1 | pickle=word 2 | # @netlify/plugin-gatsby start 3 | GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS=true 4 | # @netlify/plugin-gatsby end 5 | -------------------------------------------------------------------------------- /demo/.env.development: -------------------------------------------------------------------------------- 1 | pickle=word 2 | # @netlify/plugin-gatsby start 3 | GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS=true 4 | # @netlify/plugin-gatsby end 5 | -------------------------------------------------------------------------------- /demo/content/posts/hello-world/salty_egg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/demo/content/posts/hello-world/salty_egg.jpg -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify/cache 5 | .netlify/functions 6 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(200) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(200) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/env-variables.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(process.env.pickle) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-json-too.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/top-level.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at the top-level`) 3 | } 4 | -------------------------------------------------------------------------------- /demo/src/api/error-send-function-twice.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.send(`hi`) 3 | res.json({ willCauseError: true }) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/gatsby-config.js: -------------------------------------------------------------------------------- 1 | import ActualConfig from './actual-gatsby-config.js' 2 | 3 | module.exports = ActualConfig 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/dir/[...].js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-false.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(false) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify/cache 5 | .netlify/functions 6 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/dir/[...].js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-false.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(false) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/hello-ts.ts: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/users/[userId]/[super].js: -------------------------------------------------------------------------------- 1 | export default function userIdHandler(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | .netlify/cache 5 | .netlify/functions 6 | package-lock.json -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap-sha": "c6ea2e2b6938a06776904f433f4e0a15f0dd826b", 3 | "packages": { 4 | "plugin": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /demo-v5/content/posts/hello-world/salty_egg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/demo-v5/content/posts/hello-world/salty_egg.jpg -------------------------------------------------------------------------------- /demo-v5/src/api/error-send-function-twice.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.send(`hi`) 3 | res.json({ willCauseError: true }) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-text.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send('I am text') 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-text.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send('I am text') 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/hello-world.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-json.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-json.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.json({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/a-directory/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at a secondary-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/env-variables.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(process.env.pickle) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-json-too.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/top-level.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at the top-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/env-variables.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(process.env.pickle) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-json-too.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send({ amIJSON: true }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/top-level.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at the top-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/dir/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am another sub-directory function`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/hello-ts.ts: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/users/[userId]/[super].js: -------------------------------------------------------------------------------- 1 | export default function userIdHandler(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v4/no-functions/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/hello-ts.ts: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/users/[userId]/[super].js: -------------------------------------------------------------------------------- 1 | export default function userIdHandler(req, res) { 2 | res.json(req.params) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v5/no-functions/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/a-directory/index.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am an index.js in a sub-directory!`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/hello-world.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/hello-world.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.status(200).json({ hello: `world` }) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v5/with-adapters/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/a-directory/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at a secondary-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/dir/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am another sub-directory function`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/a-directory/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am at a secondary-level`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/dir/function.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am another sub-directory function`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | siteMetadata: { 3 | title: 'Function test', 4 | }, 5 | plugins: [`gatsby-plugin-netlify`], 6 | } 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /demo/src/api/some-אודות.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | const status = req.query.code ? req.query.code : 200 3 | res.status(status).send(`I am at the top-level`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/error-send-function-twice.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.send(`hi`) 3 | res.json({ willCauseError: true }) 4 | } 5 | -------------------------------------------------------------------------------- /.github/.kodiak.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [merge.automerge_dependencies] 4 | versions = ["minor", "patch"] 5 | usernames = ["renovate"] 6 | 7 | [approve] 8 | auto_approve_usernames = ["renovate"] -------------------------------------------------------------------------------- /demo-v5/src/api/some-אודות.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo-v5/src/api/status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | const status = req.query.code ? req.query.code : 200 3 | res.status(status).send(`I am at the top-level`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/I-Am-Capitalized.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/some whitespace.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/some-àè-french.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/with-äöü-umlaut.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/a-directory/index.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am an index.js in a sub-directory!`) 3 | } 4 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/a-directory/index.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | res.send(`I am an index.js in a sub-directory!`) 3 | } 4 | -------------------------------------------------------------------------------- /demo-v5/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | 5 | # Local Netlify folder 6 | .netlify/cache 7 | .netlify/functions 8 | 9 | netlify/functions/gatsby/functions 10 | deployment.json -------------------------------------------------------------------------------- /demo-v5/src/api/I-Am-Capitalized.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo-v5/src/api/some whitespace.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo-v5/src/api/some-àè-french.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo-v5/src/api/with-äöü-umlaut.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | 5 | # Local Netlify folder 6 | .netlify/cache 7 | .netlify/functions 8 | 9 | netlify/functions/gatsby/functions 10 | deployment.json -------------------------------------------------------------------------------- /plugin/manifest.yml: -------------------------------------------------------------------------------- 1 | name: '@netlify/plugin-gatsby' 2 | inputs: [] 3 | # Example inputs: 4 | # - name: example 5 | # description: Example description 6 | # default: 5 7 | # required: false 8 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/.env.development: -------------------------------------------------------------------------------- 1 | pickle=word 2 | # @netlify/plugin-gatsby start 3 | GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS=true 4 | # @netlify/plugin-gatsby end 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v4/with-old-netlify-plugin/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/.env.development: -------------------------------------------------------------------------------- 1 | pickle=word 2 | # @netlify/plugin-gatsby start 3 | GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS=true 4 | # @netlify/plugin-gatsby end 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v5/with-old-netlify-plugin/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/error-send-function-twice.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.send(`hi`) 3 | res.json({ willCauseError: true }) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/error-send-function-twice.js: -------------------------------------------------------------------------------- 1 | export default function handler(req, res) { 2 | res.send(`hi`) 3 | res.json({ willCauseError: true }) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/images/icon.png -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netlify/netlify-plugin-gatsby/HEAD/plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/images/icon.png -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | verbose: true, 5 | testMatch: ['/plugin/test/unit/**/*.spec.ts'], 6 | } 7 | -------------------------------------------------------------------------------- /demo-v5/src/layout/default.module.css: -------------------------------------------------------------------------------- 1 | .headerCss { 2 | background: #efefef; 3 | border-bottom: 2px solid #000; 4 | padding: 50px 0; 5 | text-align: center; 6 | } 7 | 8 | .titleCss { 9 | margin: 0; 10 | } 11 | -------------------------------------------------------------------------------- /demo/src/layout/default.module.css: -------------------------------------------------------------------------------- 1 | .headerCss { 2 | background: #efefef; 3 | border-bottom: 2px solid #000; 4 | padding: 50px 0; 5 | text-align: center; 6 | } 7 | 8 | .titleCss { 9 | margin: 0; 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/some-אודות.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | const status = req.query.code ? req.query.code : 200 3 | res.status(status).send(`I am at the top-level`) 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | max_line_length = 80 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/I-Am-Capitalized.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/some whitespace.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/some-àè-french.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/with-äöü-umlaut.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | flags: { 3 | FUNCTIONS: true, 4 | }, 5 | siteMetadata: { 6 | title: 'Function test', 7 | }, 8 | plugins: [], 9 | } 10 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/some-אודות.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | const status = req.query.code ? req.query.code : 200 3 | res.status(status).send(`I am at the top-level`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | flags: { 3 | FUNCTIONS: true, 4 | }, 5 | siteMetadata: { 6 | title: 'Function test', 7 | }, 8 | plugins: [], 9 | } 10 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/some-אודות.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/status.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | const status = req.query.code ? req.query.code : 200 3 | res.status(status).send(`I am at the top-level`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/some whitespace.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/some-àè-french.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/with-äöü-umlaut.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/some whitespace.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/some-àè-french.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/with-äöü-umlaut.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/api/redirect-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.redirect(`/`) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/I-Am-Capitalized.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/I-Am-Capitalized.js: -------------------------------------------------------------------------------- 1 | const path = require(`path`) 2 | export default function topLevel(req, res) { 3 | res.send(`${path.parse(__filename).name}${path.parse(__filename).ext}`) 4 | } 5 | -------------------------------------------------------------------------------- /plugin/test/v3-e2e-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | for dir in fixtures/v3/*; do 5 | echo Running tests in "$dir" 6 | cd "$dir" 7 | npm i --no-package-lock --legacy-peer-deps 8 | npm run test 9 | cd - 10 | done 11 | -------------------------------------------------------------------------------- /plugin/test/v4-e2e-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | for dir in fixtures/v4/*; do 5 | echo Running tests in "$dir" 6 | cd "$dir" 7 | npm i --no-package-lock --legacy-peer-deps 8 | npm run test 9 | cd - 10 | done 11 | -------------------------------------------------------------------------------- /plugin/test/v5-e2e-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | for dir in fixtures/v5/*; do 5 | echo Running tests in "$dir" 6 | cd "$dir" 7 | npm i --no-package-lock --legacy-peer-deps 8 | npm run test 9 | cd - 10 | done 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | npm-debug.log 4 | node_modules 5 | /core 6 | .eslintcache 7 | .yarn-error.log 8 | .nyc_output 9 | !.github/ 10 | /coverage 11 | /build 12 | .netlify 13 | /yarn.lock 14 | .cache 15 | public 16 | .DS_Store 17 | .parcel-cache -------------------------------------------------------------------------------- /demo-v5/src/api/cookie-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.json(req.cookies) 8 | } 9 | -------------------------------------------------------------------------------- /demo-v5/src/api/redirect-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.redirect(`/`) 8 | } 9 | -------------------------------------------------------------------------------- /demo/src/api/cookie-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.json(req.cookies) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | 8 | [[plugins]] 9 | package = 'netlify-plugin-gatsby-cache' 10 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | 5 | [[plugins]] 6 | package = "../../../../src/index.ts" 7 | 8 | [[plugins]] 9 | package = 'netlify-plugin-gatsby-cache' 10 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | { 4 | resolve: 'gatsby-plugin-netlify-cache', 5 | options: { 6 | cachePublic: true, 7 | }, 8 | }, 9 | ], 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | { 4 | resolve: 'gatsby-plugin-netlify-cache', 5 | options: { 6 | cachePublic: true, 7 | }, 8 | }, 9 | ], 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/cookie-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.json(req.cookies) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/redirect-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.redirect(`/`) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/redirect-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.redirect(`/`) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/redirect-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.redirect(`/`) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/cookie-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.json(req.cookies) 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/cookie-me.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | res.json(req.cookies) 8 | } 9 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | plugin/lib 2 | .netlify 3 | fixtures/ 4 | demo 5 | 6 | *~ 7 | *.swp 8 | npm-debug.log 9 | node_modules 10 | /core 11 | .eslintcache 12 | .yarn-error.log 13 | .nyc_output 14 | !.github/ 15 | /coverage 16 | /build 17 | .netlify 18 | /yarn.lock 19 | .cache 20 | public 21 | .DS_Store 22 | .parcel-cache -------------------------------------------------------------------------------- /demo/src/api/i-am-typescript.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | if (req.method === `GET`) { 8 | res.send(`I am typescript`) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo-v5/src/api/i-am-typescript.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | if (req.method === `GET`) { 8 | res.send(`I am typescript`) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/e2e-tests/functions.test.js: -------------------------------------------------------------------------------- 1 | const { runTests } = require('./test-helpers') 2 | 3 | if (process.env.TEST_ENV === 'netlify') { 4 | const { deploy_url } = require('../deployment.json') 5 | runTests('Netlify', deploy_url) 6 | } else { 7 | runTests('Local', 'http://localhost:8888') 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | 5 | # Local Netlify folder 6 | .netlify 7 | netlify/functions/gatsby/functions 8 | deployment.json 9 | 10 | # @netlify/plugin-gatsby ignores start 11 | netlify/functions/gatsby 12 | # @netlify/plugin-gatsby ignores end 13 | 14 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/e2e-tests/functions.test.js: -------------------------------------------------------------------------------- 1 | const { runTests } = require('./test-helpers') 2 | 3 | if (process.env.TEST_ENV === 'netlify') { 4 | const { deploy_url } = require('../deployment.json') 5 | runTests('Netlify', deploy_url) 6 | } else { 7 | runTests('Local', 'http://localhost:8888') 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/e2e-tests/functions.test.js: -------------------------------------------------------------------------------- 1 | const { runTests } = require('./test-helpers') 2 | 3 | if (process.env.TEST_ENV === 'netlify') { 4 | const { deploy_url } = require('../deployment.json') 5 | runTests('Netlify', deploy_url) 6 | } else { 7 | runTests('Local', 'http://localhost:8888') 8 | } 9 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/i-am-typescript.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | if (req.method === `GET`) { 8 | res.send(`I am typescript`) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | plugin/lib 2 | plugin/CHANGELOG.md 3 | .netlify 4 | *~ 5 | *.swp 6 | npm-debug.log 7 | node_modules 8 | /core 9 | .eslintcache 10 | .yarn-error.log 11 | .nyc_output 12 | !.github/ 13 | /coverage 14 | /build 15 | .netlify 16 | /yarn.lock 17 | .cache 18 | public 19 | .DS_Store 20 | .parcel-cache 21 | package-lock.json 22 | plugin/README.md -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | 5 | # Local Netlify folder 6 | .netlify 7 | netlify/functions/gatsby/functions 8 | deployment.json 9 | 10 | # @netlify/plugin-gatsby ignores start 11 | netlify/functions/gatsby 12 | # @netlify/plugin-gatsby ignores end 13 | 14 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .cache/ 3 | public 4 | 5 | # Local Netlify folder 6 | .netlify 7 | netlify/functions/gatsby/functions 8 | deployment.json 9 | 10 | # @netlify/plugin-gatsby ignores start 11 | netlify/functions/gatsby 12 | # @netlify/plugin-gatsby ignores end 13 | 14 | package-lock.json -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/i-am-typescript.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | if (req.method === `GET`) { 8 | res.send(`I am typescript`) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/i-am-typescript.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyFunctionResponse, GatsbyFunctionRequest } from 'gatsby' 2 | 3 | export default function topLevel( 4 | req: GatsbyFunctionRequest, 5 | res: GatsbyFunctionResponse, 6 | ) { 7 | if (req.method === `GET`) { 8 | res.send(`I am typescript`) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no functions', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no plugins', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no functions', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no plugins', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /demo/src/pages/bad-dog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Layout } from '../layout/default' 3 | 4 | const BadPage = ({ serverData }) => ( 5 | 6 |

SSR Page with a random dog

7 | Happy dog 8 |
9 | ) 10 | 11 | export default BadPage 12 | 13 | export async function getServerData() { 14 | throw new Error('Bad dog') 15 | } 16 | -------------------------------------------------------------------------------- /demo-v5/src/pages/bad-dog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Layout } from '../layout/default' 3 | 4 | const BadPage = ({ serverData }) => ( 5 | 6 |

SSR Page with a random dog

7 | Happy dog 8 |
9 | ) 10 | 11 | export default BadPage 12 | 13 | export async function getServerData() { 14 | throw new Error('Bad dog') 15 | } 16 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no Gatsby config', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with no Gatsby config', () => { 6 | it('successfully builds', async () => { 7 | const { success } = await buildSite() 8 | expect(success).toBeTruthy() 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /demo-v5/src/layout/default.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Link } from 'gatsby' 3 | import { headerCss, titleCss } from './default.module.css' 4 | 5 | export function Layout({ children }) { 6 | return ( 7 | <> 8 |
9 |

10 | SSR Demo 11 |

12 |
13 |
{children}
14 | 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /demo/src/layout/default.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Link } from 'gatsby' 3 | import { headerCss, titleCss } from './default.module.css' 4 | 5 | export function Layout({ children }) { 6 | return ( 7 | <> 8 |
9 |

10 | SSR Demo 11 |

12 |
13 |
{children}
14 | 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /demo/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | environment = { NETLIFY_IMAGE_CDN = "true" } 5 | ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;" 6 | 7 | [[plugins]] 8 | package = "../plugin/src/index.ts" 9 | 10 | [[plugins]] 11 | package = "@netlify/plugin-local-install-core" 12 | 13 | [images] 14 | remote_images = ['https://images.unsplash.com/*'] -------------------------------------------------------------------------------- /demo/src/api/cors.js: -------------------------------------------------------------------------------- 1 | import Cors from 'cors' 2 | 3 | const cors = Cors() 4 | 5 | export default async function corsHandler(req, res) { 6 | // Run Cors middleware and handle errors. 7 | await new Promise((resolve, reject) => { 8 | cors(req, res, (result) => { 9 | if (result instanceof Error) { 10 | reject(result) 11 | } 12 | 13 | resolve(result) 14 | }) 15 | }) 16 | 17 | res.json(`Hi from Gatsby Functions`) 18 | } 19 | -------------------------------------------------------------------------------- /demo/src/api/parser.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | if (req.query && Object.keys(req.query).length !== 0) { 3 | res.json(req.query) 4 | } else if (req.files && req.files.length !== 0) { 5 | res.json({ files: req.files, body: req.body }) 6 | } else if (req.body) { 7 | res.json(req.body) 8 | } else { 9 | res.json({ 10 | message: `No body was sent. Try a POST request or query string`, 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /demo-v5/src/api/cors.js: -------------------------------------------------------------------------------- 1 | import Cors from 'cors' 2 | 3 | const cors = Cors() 4 | 5 | export default async function corsHandler(req, res) { 6 | // Run Cors middleware and handle errors. 7 | await new Promise((resolve, reject) => { 8 | cors(req, res, (result) => { 9 | if (result instanceof Error) { 10 | reject(result) 11 | } 12 | 13 | resolve(result) 14 | }) 15 | }) 16 | 17 | res.json(`Hi from Gatsby Functions`) 18 | } 19 | -------------------------------------------------------------------------------- /demo-v5/src/api/parser.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | if (req.query && Object.keys(req.query).length !== 0) { 3 | res.json(req.query) 4 | } else if (req.files && req.files.length !== 0) { 5 | res.json({ files: req.files, body: req.body }) 6 | } else if (req.body) { 7 | res.json(req.body) 8 | } else { 9 | res.json({ 10 | message: `No body was sent. Try a POST request or query string`, 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /demo-v5/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "public/" 4 | environment = { NETLIFY_IMAGE_CDN = "true" } 5 | ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;" 6 | 7 | [[plugins]] 8 | package = "../plugin/src/index.ts" 9 | 10 | [[plugins]] 11 | package = "@netlify/plugin-local-install-core" 12 | 13 | [images] 14 | remote_images = ['https://images.unsplash.com/*'] 15 | -------------------------------------------------------------------------------- /demo/content/posts/my-second-post/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: My Second Post! 3 | date: '2015-05-06T23:46:37.121Z' 4 | --- 5 | 6 | Wow! I love blogging so much already. 7 | 8 | Did you know that "despite its name, salted duck eggs can also be made from 9 | chicken eggs, though the taste and texture will be somewhat different, and the 10 | egg yolk will be less rich."? 11 | ([Wikipedia Link](https://en.wikipedia.org/wiki/Salted_duck_egg)) 12 | 13 | Yeah, I didn't either. 14 | -------------------------------------------------------------------------------- /demo-v5/content/posts/my-second-post/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: My Second Post! 3 | date: '2015-05-06T23:46:37.121Z' 4 | --- 5 | 6 | Wow! I love blogging so much already. 7 | 8 | Did you know that "despite its name, salted duck eggs can also be made from 9 | chicken eggs, though the taste and texture will be somewhat different, and the 10 | egg yolk will be less rich."? 11 | ([Wikipedia Link](https://en.wikipedia.org/wiki/Salted_duck_egg)) 12 | 13 | Yeah, I didn't either. 14 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/cors.js: -------------------------------------------------------------------------------- 1 | import Cors from 'cors' 2 | 3 | const cors = Cors() 4 | 5 | export default async function corsHandler(req, res) { 6 | // Run Cors middleware and handle errors. 7 | await new Promise((resolve, reject) => { 8 | cors(req, res, (result) => { 9 | if (result instanceof Error) { 10 | reject(result) 11 | } 12 | 13 | resolve(result) 14 | }) 15 | }) 16 | 17 | res.json(`Hi from Gatsby Functions`) 18 | } 19 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/api/parser.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | if (req.query && Object.keys(req.query).length !== 0) { 3 | res.json(req.query) 4 | } else if (req.files && req.files.length !== 0) { 5 | res.json({ files: req.files, body: req.body }) 6 | } else if (req.body) { 7 | res.json(req.body) 8 | } else { 9 | res.json({ 10 | message: `No body was sent. Try a POST request or query string`, 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/cors.js: -------------------------------------------------------------------------------- 1 | import Cors from 'cors' 2 | 3 | const cors = Cors() 4 | 5 | export default async function corsHandler(req, res) { 6 | // Run Cors middleware and handle errors. 7 | await new Promise((resolve, reject) => { 8 | cors(req, res, (result) => { 9 | if (result instanceof Error) { 10 | reject(result) 11 | } 12 | 13 | resolve(result) 14 | }) 15 | }) 16 | 17 | res.json(`Hi from Gatsby Functions`) 18 | } 19 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/api/parser.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | if (req.query && Object.keys(req.query).length !== 0) { 3 | res.json(req.query) 4 | } else if (req.files && req.files.length !== 0) { 5 | res.json({ files: req.files, body: req.body }) 6 | } else if (req.body) { 7 | res.json(req.body) 8 | } else { 9 | res.json({ 10 | message: `No body was sent. Try a POST request or query string`, 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/cors.js: -------------------------------------------------------------------------------- 1 | import Cors from 'cors' 2 | 3 | const cors = Cors() 4 | 5 | export default async function corsHandler(req, res) { 6 | // Run Cors middleware and handle errors. 7 | await new Promise((resolve, reject) => { 8 | cors(req, res, (result) => { 9 | if (result instanceof Error) { 10 | reject(result) 11 | } 12 | 13 | resolve(result) 14 | }) 15 | }) 16 | 17 | res.json(`Hi from Gatsby Functions`) 18 | } 19 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/api/parser.js: -------------------------------------------------------------------------------- 1 | export default function topLevel(req, res) { 2 | if (req.query && Object.keys(req.query).length !== 0) { 3 | res.json(req.query) 4 | } else if (req.files && req.files.length !== 0) { 5 | res.json({ files: req.files, body: req.body }) 6 | } else if (req.body) { 7 | res.json(req.body) 8 | } else { 9 | res.json({ 10 | message: `No body was sent. Try a POST request or query string`, 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | extends: ["github>netlify/renovate-config:default"], 3 | ignorePresets: [":prHourlyLimit2"], 4 | semanticCommits: "enabled", 5 | dependencyDashboard: true, 6 | automerge: true, 7 | packageRules: [ 8 | { 9 | major: { 10 | enabled: false, 11 | }, 12 | matchPackageNames: ["@sindresorhus/{/,}**"], 13 | }, 14 | { 15 | matchPackageNames: ["strip-ansi"], 16 | major: { 17 | enabled: false, 18 | }, 19 | }, 20 | ], 21 | } 22 | -------------------------------------------------------------------------------- /demo/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | siteMetadata: { 3 | title: 'Function test', 4 | }, 5 | plugins: [ 6 | { 7 | resolve: `gatsby-source-filesystem`, 8 | options: { 9 | path: `${__dirname}/content/posts`, 10 | name: `blog`, 11 | }, 12 | }, 13 | { 14 | resolve: `gatsby-transformer-remark`, 15 | options: { 16 | plugins: [], 17 | }, 18 | }, 19 | 'gatsby-plugin-netlify', 20 | `gatsby-plugin-image`, 21 | `gatsby-plugin-sharp`, 22 | 'gatsby-plugin-image-cdn-test', 23 | ], 24 | } 25 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | 6 | describe('A site using gatsby-plugin-netlify-cache', () => { 7 | it('bails when running a build', async () => { 8 | const { logs, success } = await buildSite() 9 | expect(success).toBeFalsy() 10 | expect(logs.stderr).toMatch( 11 | "The plugin 'gatsby-plugin-netlify-cache' is not compatible with the Gatsby build plugin", 12 | ) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | 6 | describe('A site using netlify-plugin-gatsby-cache', () => { 7 | it('warns when running a build', async () => { 8 | const { logs, success } = await buildSite() 9 | expect(success).toBeTruthy() 10 | expect(logs.stderr).toMatch( 11 | "The plugin 'netlify-plugin-gatsby-cache' is no longer required and should be removed.", 12 | ) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | 6 | describe('A site using gatsby-plugin-netlify-cache', () => { 7 | it('bails when running a build', async () => { 8 | const { logs, success } = await buildSite() 9 | expect(success).toBeFalsy() 10 | expect(logs.stderr).toMatch( 11 | "The plugin 'gatsby-plugin-netlify-cache' is not compatible with the Gatsby build plugin", 12 | ) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | 6 | describe('A site using netlify-plugin-gatsby-cache', () => { 7 | it('warns when running a build', async () => { 8 | const { logs, success } = await buildSite() 9 | expect(success).toBeTruthy() 10 | expect(logs.stderr).toMatch( 11 | "The plugin 'netlify-plugin-gatsby-cache' is no longer required and should be removed.", 12 | ) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /demo/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | .postsListCss { 2 | list-style: none; 3 | padding-left: 0; 4 | margin: 0; 5 | } 6 | 7 | .postListItemCss { 8 | border-bottom: 2px solid #000; 9 | margin: 25px 0; 10 | } 11 | .postListItemCss:first-child { 12 | margin-top: 0; 13 | } 14 | 15 | .postTeaserCss { 16 | padding: 0 25px; 17 | } 18 | .postTeaserTitleCss a { 19 | font-size: 24px; 20 | font-weight: bold; 21 | text-decoration: underline; 22 | } 23 | .postTeaserDescriptionCss { 24 | margin: 15px 0; 25 | } 26 | .postTeaserLinkCss { 27 | color: inherit; 28 | text-decoration: inherit; 29 | } 30 | -------------------------------------------------------------------------------- /demo-v5/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | .postsListCss { 2 | list-style: none; 3 | padding-left: 0; 4 | margin: 0; 5 | } 6 | 7 | .postListItemCss { 8 | border-bottom: 2px solid #000; 9 | margin: 25px 0; 10 | } 11 | .postListItemCss:first-child { 12 | margin-top: 0; 13 | } 14 | 15 | .postTeaserCss { 16 | padding: 0 25px; 17 | } 18 | .postTeaserTitleCss a { 19 | font-size: 24px; 20 | font-weight: bold; 21 | text-decoration: underline; 22 | } 23 | .postTeaserDescriptionCss { 24 | margin: 15px 0; 25 | } 26 | .postTeaserLinkCss { 27 | color: inherit; 28 | text-decoration: inherit; 29 | } 30 | -------------------------------------------------------------------------------- /demo-v5/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingSlash: 'always', 3 | siteMetadata: { 4 | title: 'Function test', 5 | }, 6 | plugins: [ 7 | { 8 | resolve: `gatsby-source-filesystem`, 9 | options: { 10 | path: `${__dirname}/content/posts`, 11 | name: `blog`, 12 | }, 13 | }, 14 | { 15 | resolve: `gatsby-transformer-remark`, 16 | options: { 17 | plugins: [], 18 | }, 19 | }, 20 | 'gatsby-plugin-netlify', 21 | `gatsby-plugin-image`, 22 | `gatsby-plugin-sharp`, 23 | 'gatsby-plugin-image-cdn-test', 24 | ], 25 | } 26 | -------------------------------------------------------------------------------- /plugin/test/helpers.js: -------------------------------------------------------------------------------- 1 | const Chance = require('chance') 2 | const execa = require('execa') 3 | 4 | const chance = new Chance() 5 | 6 | module.exports.buildSite = async () => { 7 | const { exitCode, stdout, stderr } = await execa( 8 | 'netlify', 9 | ['build', '--offline', '--cwd', '.'], 10 | { reject: false }, 11 | ) 12 | return { 13 | logs: { stdout, stderr }, 14 | success: exitCode === 0, 15 | severityCode: exitCode, 16 | } 17 | } 18 | 19 | module.exports.enableGatsbyExcludeDatastoreFromBundle = () => { 20 | process.env.GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE = 'true' 21 | process.env.DEPLOY_PRIME_URL = chance.url() 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/add-to-project.yml: -------------------------------------------------------------------------------- 1 | name: Add new issue to project 2 | on: 3 | issues: 4 | types: 5 | - opened 6 | jobs: 7 | track_pr: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Generate token 11 | id: generate_token 12 | uses: tibdex/github-app-token@v1.9.0 13 | with: 14 | app_id: ${{ secrets.TOKENS_APP_ID }} 15 | private_key: ${{ secrets.TOKENS_PRIVATE_KEY }} 16 | - name: Add issue to Project 17 | uses: actions/add-to-project@v0.6.1 18 | with: 19 | project-url: https://github.com/orgs/netlify/projects/199 20 | github-token: ${{ steps.generate_token.outputs.token }} 21 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | 4 | jest.setTimeout(120_000) 5 | describe('A site with "--require esm" and gatsby-config.js authored in ESM', () => { 6 | it('successfully builds and warns that is unable to validate gatsby-config', async () => { 7 | const { success, logs } = await buildSite() 8 | expect(success).toBeTruthy() 9 | expect(logs.stderr) 10 | .toMatch(`Could not load gatsby-config.js: Cannot use import statement outside a module 11 | 12 | Unable to validate if 'gatsby-plugin-netlify' is setup correctly.`) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "^4.9.0", 21 | "react": "^17.0.1", 22 | "react-dom": "^17.0.1" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-plugins", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "^4.9.0", 21 | "react": "^17.0.1", 22 | "react-dom": "^17.0.1" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "5.11.0", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-plugins", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "5.11.0", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Summary 4 | 5 | 6 | 7 | ### Test plan 8 | 9 | 1. Visit the Deploy Preview ([insert link to specific page]()) ... 10 | 11 | ### Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal 12 | 13 | ### Standard checks: 14 | 15 | 16 | 17 | - [ ] Check the Deploy Preview's Demo site for your PR's functionality 18 | - [ ] Add docs when necessary 19 | 20 | --- 21 | 22 | 🧪 Once merged, make sure to update the version if needed and that it was 23 | published correctly. 24 | -------------------------------------------------------------------------------- /demo-v5/plugins/gatsby-plugin-image-cdn-test/gatsby-node.js: -------------------------------------------------------------------------------- 1 | exports.createSchemaCustomization = function createSchemaCustomization({ 2 | actions, 3 | }) { 4 | actions.createTypes(` 5 | type UnsplashImage implements Node & RemoteFile { 6 | id: ID! 7 | } 8 | `) 9 | } 10 | 11 | exports.sourceNodes = function sourceNodes({ actions }) { 12 | const imageURL = `https://images.unsplash.com/photo-1672823841196-3ec078a2befd` 13 | actions.createNode({ 14 | id: 'unsplash-image-1', 15 | internal: { 16 | type: 'UnsplashImage', 17 | contentDigest: `1`, 18 | }, 19 | url: imageURL, 20 | filename: imageURL, 21 | mimeType: `image/jpeg`, 22 | width: 1940, 23 | height: 3118, 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /demo/plugins/gatsby-plugin-image-cdn-test/gatsby-node.js: -------------------------------------------------------------------------------- 1 | exports.createSchemaCustomization = function createSchemaCustomization({ 2 | actions, 3 | }) { 4 | actions.createTypes(` 5 | type UnsplashImage implements Node & RemoteFile { 6 | id: ID! 7 | } 8 | `) 9 | } 10 | 11 | exports.sourceNodes = function sourceNodes({ actions }) { 12 | const imageURL = `https://images.unsplash.com/photo-1672823841196-3ec078a2befd` 13 | actions.createNode({ 14 | id: 'unsplash-image-1', 15 | internal: { 16 | type: 'UnsplashImage', 17 | contentDigest: `1`, 18 | }, 19 | url: imageURL, 20 | filename: imageURL, 21 | mimeType: `image/jpeg`, 22 | width: 1940, 23 | height: 3118, 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /.github/workflows/add-zenhub-label.yml: -------------------------------------------------------------------------------- 1 | # Ensure we add the correct ZenHub label for all new issues 2 | # Avoids problem where checklist issues are not added to the correct ZenHub pipeline 3 | 4 | name: Add ZenHub label to issues 5 | on: 6 | issues: 7 | types: 8 | - reopened 9 | - opened 10 | jobs: 11 | label_issues: 12 | runs-on: ubuntu-latest 13 | permissions: 14 | issues: write 15 | steps: 16 | - uses: actions/github-script@v6 17 | with: 18 | script: | 19 | github.rest.issues.addLabels({ 20 | issue_number: context.issue.number, 21 | owner: context.repo.owner, 22 | repo: context.repo.repo, 23 | labels: ["Ecosystem: Frameworks"] 24 | }) 25 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-plugins", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "^4.9.0", 21 | "react": "^17.0.1", 22 | "react-dom": "^17.0.1" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | }, 27 | "peerDependencies": { 28 | "execa": "^5.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-plugins", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "5.11.0", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0" 23 | }, 24 | "devDependencies": { 25 | "jest": "^27.0.4" 26 | }, 27 | "peerDependencies": { 28 | "execa": "^5.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | The BSD Zero Clause License (0BSD) 2 | 3 | Copyright (c) 2020 Gatsby Inc. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /demo-v5/src/pages/500.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | 3 | // styles 4 | const pageStyles = { 5 | color: '#232129', 6 | padding: '96px', 7 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 8 | } 9 | const headingStyles = { 10 | marginTop: 0, 11 | marginBottom: 64, 12 | maxWidth: 320, 13 | } 14 | 15 | const paragraphStyles = { 16 | marginBottom: 48, 17 | } 18 | 19 | const ErrorPage = () => { 20 | return ( 21 |
22 | Internal Server Error 23 |

Internal Server Error

24 |

25 | Sorry{' '} 26 | 27 | 😔 28 | {' '} 29 | there was an error. 30 |

31 |
32 | ) 33 | } 34 | 35 | export default ErrorPage 36 | -------------------------------------------------------------------------------- /demo/src/pages/500.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | 3 | // styles 4 | const pageStyles = { 5 | color: '#232129', 6 | padding: '96px', 7 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 8 | } 9 | const headingStyles = { 10 | marginTop: 0, 11 | marginBottom: 64, 12 | maxWidth: 320, 13 | } 14 | 15 | const paragraphStyles = { 16 | marginBottom: 48, 17 | } 18 | 19 | const ErrorPage = () => { 20 | return ( 21 |
22 | Internal Server Error 23 |

Internal Server Error

24 |

25 | Sorry{' '} 26 | 27 | 😔 28 | {' '} 29 | there was an error. 30 |

31 |
32 | ) 33 | } 34 | 35 | export default ErrorPage 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: 'Please replace with a clear and descriptive title' 5 | labels: enhancement 6 | assignees: '' 7 | --- 8 | 9 | Thanks for suggesting a new feature! 10 | 11 | Please fill in the sections below. 12 | 13 | **Which problem is this feature request solving?** 14 | 15 | Example: I'm always frustrated when [...] 16 | 17 | **Describe the solution you'd like** 18 | 19 | Example: This could be fixed by [...] 20 | 21 | **Describe alternatives you've considered** 22 | 23 | Example: Another solution would be [...] 24 | 25 | **Can you submit a pull request?** 26 | 27 | Yes/No. 28 | 29 | Pull requests are welcome! If you would like to help us add this feature, please 30 | check our [contributions guidelines](../blob/master/CONTRIBUTING.md). 31 | -------------------------------------------------------------------------------- /demo/src/pages/dog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Layout } from '../layout/default' 3 | import fetch from 'node-fetch' 4 | 5 | const SSRPage = ({ serverData }) => ( 6 | 7 |

SSR Page with a random dog

8 | Happy dog 9 |
10 | ) 11 | 12 | export default SSRPage 13 | 14 | export async function getServerData() { 15 | try { 16 | const res = await fetch(`https://dog.ceo/api/breeds/image/random`) 17 | 18 | if (!res.ok) { 19 | throw new Error(`Response failed`) 20 | } 21 | 22 | return { 23 | props: await res.json(), 24 | headers: { 25 | 'x-dog': 'good', 26 | }, 27 | } 28 | } catch (error) { 29 | return { 30 | headers: { 31 | status: 500, 32 | }, 33 | props: {}, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demo-v5/src/pages/dog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Layout } from '../layout/default' 3 | import fetch from 'node-fetch' 4 | 5 | const SSRPage = ({ serverData }) => ( 6 | 7 |

SSR Page with a random dog

8 | Happy dog 9 |
10 | ) 11 | 12 | export default SSRPage 13 | 14 | export async function getServerData() { 15 | try { 16 | const res = await fetch(`https://dog.ceo/api/breeds/image/random`) 17 | 18 | if (!res.ok) { 19 | throw new Error(`Response failed`) 20 | } 21 | 22 | return { 23 | props: await res.json(), 24 | headers: { 25 | 'x-dog': 'good', 26 | }, 27 | } 28 | } catch (error) { 29 | return { 30 | headers: { 31 | status: 500, 32 | }, 33 | props: {}, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-gatsby-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "^4.9.0", 21 | "gatsby-plugin-netlify-cache": "^1.2.0", 22 | "react": "^17.0.1", 23 | "react-dom": "^17.0.1" 24 | }, 25 | "devDependencies": { 26 | "@netlify/build": "latest", 27 | "jest": "^27.0.4" 28 | }, 29 | "peerDependencies": { 30 | "execa": "^5.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "^4.9.0", 21 | "react": "^17.0.1", 22 | "react-dom": "^17.0.1" 23 | }, 24 | "devDependencies": { 25 | "@netlify/build": "latest", 26 | "jest": "^27.0.4", 27 | "netlify-plugin-gatsby-cache": "^0.3.2" 28 | }, 29 | "peerDependencies": { 30 | "execa": "^5.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-gatsby-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "5.11.0", 21 | "gatsby-plugin-netlify-cache": "^1.2.0", 22 | "react": "^18.2.0", 23 | "react-dom": "^18.2.0" 24 | }, 25 | "devDependencies": { 26 | "@netlify/build": "latest", 27 | "jest": "^27.0.4" 28 | }, 29 | "peerDependencies": { 30 | "execa": "^5.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "no-functions", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "gatsby develop", 12 | "start": "gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "test": "npm run build && jest" 17 | }, 18 | "license": "0BSD", 19 | "dependencies": { 20 | "gatsby": "5.11.0", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0" 23 | }, 24 | "devDependencies": { 25 | "@netlify/build": "latest", 26 | "jest": "^27.0.4", 27 | "netlify-plugin-gatsby-cache": "^0.3.2" 28 | }, 29 | "peerDependencies": { 30 | "execa": "^5.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esm-gatsby-config", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My Gatsby site", 6 | "author": "Michal Piechowiak", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "cross-env NODE_OPTIONS=\"-r esm\" gatsby develop", 12 | "start": "cross-env NODE_OPTIONS=\"-r esm\" gatsby develop", 13 | "build": "cross-env NODE_OPTIONS=\"-r esm\" gatsby build", 14 | "serve": "cross-env NODE_OPTIONS=\"-r esm\" gatsby serve", 15 | "clean": "gatsby clean", 16 | "jest": "jest", 17 | "test": "npm run build && jest" 18 | }, 19 | "license": "0BSD", 20 | "dependencies": { 21 | "cross-env": "^7.0.3", 22 | "esm": "^3.2.25", 23 | "gatsby": "^3.15.0", 24 | "react": "^17.0.1", 25 | "react-dom": "^17.0.1" 26 | }, 27 | "devDependencies": { 28 | "jest": "^27.0.4" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: Label PR 2 | on: 3 | pull_request: 4 | types: [opened, edited] 5 | 6 | jobs: 7 | label-pr: 8 | if: 9 | github.event_name == 'pull_request' && 10 | github.event.pull_request.head.repo.fork == false 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | pr: 15 | [ 16 | { prefix: 'fix', type: 'bug' }, 17 | { prefix: 'chore', type: 'chore' }, 18 | { prefix: 'test', type: 'chore' }, 19 | { prefix: 'ci', type: 'chore' }, 20 | { prefix: 'feat', type: 'feature' }, 21 | { prefix: 'security', type: 'security' }, 22 | ] 23 | steps: 24 | - uses: netlify/pr-labeler-action@v1.1.0 25 | if: startsWith(github.event.pull_request.title, matrix.pr.prefix) 26 | with: 27 | token: '${{ secrets.GITHUB_TOKEN }}' 28 | label: 'type: ${{ matrix.pr.type }}' 29 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/e2e-tests/__snapshots__/functions.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Local functions can parse different ways of sending data file in multipart/form 1`] = ` 4 | Object { 5 | "body": Object { 6 | "something": "here", 7 | }, 8 | "files": Array [ 9 | Object { 10 | "buffer": Object { 11 | "data": Array [ 12 | 104, 13 | 105, 14 | ], 15 | "type": "Buffer", 16 | }, 17 | "encoding": "7bit", 18 | "fieldname": "file", 19 | "mimetype": "text/plain", 20 | "originalname": "test.txt", 21 | "size": 2, 22 | }, 23 | ], 24 | } 25 | `; 26 | 27 | exports[`Local routing dynamic routes 1`] = ` 28 | Object { 29 | "super": "additional", 30 | "userId": "23", 31 | } 32 | `; 33 | 34 | exports[`Local routing dynamic routes 2`] = ` 35 | Object { 36 | "*": "super", 37 | "0": "super", 38 | } 39 | `; 40 | 41 | exports[`Local routing routes with special characters 1`] = `"I-Am-Capitalized.js"`; 42 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Luke Oliff 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "function-test", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "Function test", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "HOST=0.0.0.0 gatsby develop", 12 | "start": "HOST=0.0.0.0 gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "build:netlify": "netlify build --offline --cwd .", 17 | "preview": "netlify dev --offline --cwd .", 18 | "test": "run-s build:netlify test:e2e", 19 | "test:e2e": "start-server-and-test preview 8888 test:jest", 20 | "test:jest": "jest" 21 | }, 22 | "dependencies": { 23 | "gatsby": "^4.9.0", 24 | "react": "^17.0.1", 25 | "react-dom": "^17.0.1" 26 | }, 27 | "devDependencies": { 28 | "form-data": "^4.0.0", 29 | "jest": "^26.6.3", 30 | "node-fetch": "^2.6.1", 31 | "npm-run-all": "^4.1.5", 32 | "start-server-and-test": "^1.12.2" 33 | }, 34 | "license": "MIT", 35 | "engines": { 36 | "node": ">=14.17.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "function-test", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "Function test", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "HOST=0.0.0.0 gatsby develop", 12 | "start": "HOST=0.0.0.0 gatsby develop", 13 | "build": "gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "build:netlify": "netlify build --offline --cwd .", 17 | "preview": "netlify dev --offline --cwd .", 18 | "test": "run-s build:netlify test:e2e", 19 | "test:e2e": "start-server-and-test preview 8888 test:jest", 20 | "test:jest": "jest" 21 | }, 22 | "dependencies": { 23 | "gatsby": "5.11.0", 24 | "react": "^18.2.0", 25 | "react-dom": "^18.2.0" 26 | }, 27 | "devDependencies": { 28 | "form-data": "^4.0.0", 29 | "jest": "^26.6.3", 30 | "node-fetch": "^2.6.1", 31 | "npm-run-all": "^4.1.5", 32 | "start-server-and-test": "^1.12.2" 33 | }, 34 | "license": "MIT", 35 | "engines": { 36 | "node": ">=14.17.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.github/workflows/fossa.yml: -------------------------------------------------------------------------------- 1 | name: Dependency License Scanning 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - chore/fossa-workflow 8 | 9 | defaults: 10 | run: 11 | shell: bash 12 | 13 | jobs: 14 | fossa: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | - name: Download fossa cli 20 | run: |- 21 | mkdir -p $HOME/.local/bin 22 | curl https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash -s -- -b $HOME/.local/bin 23 | echo "$HOME/.local/bin" >> $GITHUB_PATH 24 | 25 | - name: Fossa init 26 | run: fossa init 27 | - name: Set env 28 | run: 29 | echo "line_number=$(grep -n "project" .fossa.yml | cut -f1 -d:)" >> 30 | $GITHUB_ENV 31 | - name: Configuration 32 | run: |- 33 | sed -i "${line_number}s|.*| project: git@github.com:${GITHUB_REPOSITORY}.git|" .fossa.yml 34 | cat .fossa.yml 35 | - name: Upload dependencies 36 | run: fossa analyze --debug 37 | env: 38 | FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }} 39 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-adapters", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "Function and adapters test", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "HOST=0.0.0.0 gatsby develop", 12 | "start": "HOST=0.0.0.0 gatsby develop", 13 | "build": "gatsby --version && gatsby build", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean", 16 | "build:netlify": "jest build.test.js", 17 | "preview": "netlify serve --cwd .", 18 | "test": "run-s build:netlify test:e2e", 19 | "test:e2e": "start-server-and-test preview 8888 test:jest", 20 | "test:jest": "jest functions.test.js" 21 | }, 22 | "dependencies": { 23 | "gatsby": "5.14.1", 24 | "gatsby-plugin-netlify": "5.1.0", 25 | "react": "^18.2.0", 26 | "react-dom": "^18.2.0" 27 | }, 28 | "devDependencies": { 29 | "form-data": "^4.0.0", 30 | "jest": "^26.6.3", 31 | "node-fetch": "^2.6.1", 32 | "npm-run-all": "^4.1.5", 33 | "start-server-and-test": "^1.12.2" 34 | }, 35 | "license": "MIT", 36 | "engines": { 37 | "node": ">=14.17.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/no-functions/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/no-functions/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v3/esm-gatsby-config/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-plugins/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-plugins/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-no-gatsby-config/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/with-old-netlify-plugin/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-no-gatsby-config/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-old-netlify-plugin/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby' 2 | import * as React from 'react' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => ( 29 |
30 | Not found 31 |

Page not found

32 |

33 | Sorry{' '} 34 | 35 | 😔 36 | {' '} 37 | we couldn’t find what you were looking for. 38 |
39 | {process.env.NODE_ENV === 'development' ? ( 40 | <> 41 |
42 | Try creating a page in src/pages/. 43 |
44 | 45 | ) : null} 46 |
47 | Go home. 48 |

49 |
50 | ) 51 | 52 | export default NotFoundPage 53 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/with-adapters/e2e-tests/build.test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line node/no-unpublished-require 2 | const { buildSite } = require('../../../../helpers') 3 | const { readFileSync } = require('fs') 4 | 5 | jest.setTimeout(240_000) 6 | describe('A site using gatsby version with adapters', () => { 7 | it('successfully builds and disables @netlify/plugin-gatsby and gatsby-plugin-netlify', async () => { 8 | const { 9 | success, 10 | logs: { stdout, stderr }, 11 | } = await buildSite() 12 | 13 | // in CI warnings are outputted to stderr (yikes) 14 | const fullOutput = stdout + stderr 15 | 16 | if (!success) { 17 | console.error(fullOutput) 18 | } 19 | 20 | expect(success).toBeTruthy() 21 | 22 | expect(fullOutput).toContain( 23 | 'Skipping @netlify/plugin-gatsby work, because used Gatsby version supports adapters.', 24 | ) 25 | expect(fullOutput).toContain('Disabling plugin "gatsby-plugin-netlify"') 26 | 27 | const _redirectsContent = readFileSync('public/_redirects', 'utf8') 28 | 29 | expect(_redirectsContent).not.toContain( 30 | '# @netlify/plugin-gatsby redirects start', 31 | ) 32 | expect(_redirectsContent).not.toContain( 33 | '## Created with gatsby-plugin-netlify', 34 | ) 35 | expect(_redirectsContent).toContain('# gatsby-adapter-netlify start') 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /demo/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Link } from 'gatsby' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => { 29 | return ( 30 |
31 | Not found 32 |

Page not found

33 |

34 | Sorry{' '} 35 | 36 | 😔 37 | {' '} 38 | we couldn’t find what you were looking for. 39 |
40 | {process.env.NODE_ENV === 'development' ? ( 41 | <> 42 |
43 | Try creating a page in src/pages/. 44 |
45 | 46 | ) : null} 47 |
48 | Go home. 49 |

50 |
51 | ) 52 | } 53 | 54 | export default NotFoundPage 55 | -------------------------------------------------------------------------------- /demo-v5/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { Link } from 'gatsby' 3 | 4 | // styles 5 | const pageStyles = { 6 | color: '#232129', 7 | padding: '96px', 8 | fontFamily: '-apple-system, Roboto, sans-serif, serif', 9 | } 10 | const headingStyles = { 11 | marginTop: 0, 12 | marginBottom: 64, 13 | maxWidth: 320, 14 | } 15 | 16 | const paragraphStyles = { 17 | marginBottom: 48, 18 | } 19 | const codeStyles = { 20 | color: '#8A6534', 21 | padding: 4, 22 | backgroundColor: '#FFF4DB', 23 | fontSize: '1.25rem', 24 | borderRadius: 4, 25 | } 26 | 27 | // markup 28 | const NotFoundPage = () => { 29 | return ( 30 |
31 | Not found 32 |

Page not found

33 |

34 | Sorry{' '} 35 | 36 | 😔 37 | {' '} 38 | we couldn’t find what you were looking for. 39 |
40 | {process.env.NODE_ENV === 'development' ? ( 41 | <> 42 |
43 | Try creating a page in src/pages/. 44 |
45 | 46 | ) : null} 47 |
48 | Go home. 49 |

50 |
51 | ) 52 | } 53 | 54 | export default NotFoundPage 55 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v4/functions-without-gatsby-plugin/e2e-tests/__snapshots__/functions.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Local functions can parse different ways of sending data file in multipart/form 1`] = ` 4 | Object { 5 | "body": Object { 6 | "something": "here", 7 | }, 8 | "files": Array [ 9 | Object { 10 | "buffer": Object { 11 | "data": Array [ 12 | 104, 13 | 105, 14 | ], 15 | "type": "Buffer", 16 | }, 17 | "encoding": "7bit", 18 | "fieldname": "file", 19 | "mimetype": "text/plain", 20 | "originalname": "test.txt", 21 | "size": 2, 22 | }, 23 | ], 24 | } 25 | `; 26 | 27 | exports[`Local routing dynamic routes 1`] = ` 28 | Object { 29 | "super": "additional", 30 | "userId": "23", 31 | } 32 | `; 33 | 34 | exports[`Local routing dynamic routes 2`] = ` 35 | Object { 36 | "*": "super", 37 | "0": "super", 38 | } 39 | `; 40 | 41 | exports[`Local routing routes with special characters 1`] = `"I-Am-Capitalized.js"`; 42 | 43 | exports[`Local routing routes with special characters 2`] = `"some whitespace.js"`; 44 | 45 | exports[`Local routing routes with special characters 3`] = `"with-äöü-umlaut.js"`; 46 | 47 | exports[`Local routing routes with special characters 4`] = `"some-àè-french.js"`; 48 | 49 | exports[`Local routing routes with special characters 5`] = `"some-אודות.js"`; 50 | -------------------------------------------------------------------------------- /plugin/test/fixtures/v5/functions-without-gatsby-plugin/e2e-tests/__snapshots__/functions.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Local functions can parse different ways of sending data file in multipart/form 1`] = ` 4 | Object { 5 | "body": Object { 6 | "something": "here", 7 | }, 8 | "files": Array [ 9 | Object { 10 | "buffer": Object { 11 | "data": Array [ 12 | 104, 13 | 105, 14 | ], 15 | "type": "Buffer", 16 | }, 17 | "encoding": "7bit", 18 | "fieldname": "file", 19 | "mimetype": "text/plain", 20 | "originalname": "test.txt", 21 | "size": 2, 22 | }, 23 | ], 24 | } 25 | `; 26 | 27 | exports[`Local routing dynamic routes 1`] = ` 28 | Object { 29 | "super": "additional", 30 | "userId": "23", 31 | } 32 | `; 33 | 34 | exports[`Local routing dynamic routes 2`] = ` 35 | Object { 36 | "*": "super", 37 | "0": "super", 38 | } 39 | `; 40 | 41 | exports[`Local routing routes with special characters 1`] = `"I-Am-Capitalized.js"`; 42 | 43 | exports[`Local routing routes with special characters 2`] = `"some whitespace.js"`; 44 | 45 | exports[`Local routing routes with special characters 3`] = `"with-äöü-umlaut.js"`; 46 | 47 | exports[`Local routing routes with special characters 4`] = `"some-àè-french.js"`; 48 | 49 | exports[`Local routing routes with special characters 5`] = `"some-אודות.js"`; 50 | -------------------------------------------------------------------------------- /demo/src/template/post.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql } from 'gatsby' 3 | import { Layout } from '../layout/default' 4 | import { containerCss } from './post.module.css' 5 | 6 | export default function BlogPostTemplate({ data }) { 7 | const post = data.markdownRemark 8 | 9 | return ( 10 | 11 |
16 |
17 |

{post.frontmatter.title}

18 |

{post.frontmatter.date}

19 |
20 |
24 |
25 |
26 |
27 | ) 28 | } 29 | 30 | /** 31 | * Example of DSG per path using fs Routes 32 | */ 33 | // export function config({ params }) { 34 | // return { 35 | // defer: params.slug !== 'hello-world', 36 | // } 37 | // } 38 | 39 | /** 40 | * Example of DSG for all routes 41 | */ 42 | // export const config = { 43 | // defer: true, 44 | // } 45 | 46 | export const query = graphql` 47 | query ($id: String) { 48 | allMarkdownRemark { 49 | nodes { 50 | id 51 | } 52 | } 53 | markdownRemark(id: { eq: $id }) { 54 | id 55 | html 56 | frontmatter { 57 | title 58 | date(formatString: "MMMM DD, YYYY") 59 | description 60 | } 61 | # slug 62 | } 63 | } 64 | ` 65 | -------------------------------------------------------------------------------- /demo-v5/src/template/post.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql } from 'gatsby' 3 | import { Layout } from '../layout/default' 4 | import { containerCss } from './post.module.css' 5 | 6 | export default function BlogPostTemplate({ data }) { 7 | const post = data.markdownRemark 8 | 9 | return ( 10 | 11 |
16 |
17 |

{post.frontmatter.title}

18 |

{post.frontmatter.date}

19 |
20 |
24 |
25 |
26 |
27 | ) 28 | } 29 | 30 | /** 31 | * Example of DSG per path using fs Routes 32 | */ 33 | // export function config({ params }) { 34 | // return { 35 | // defer: params.slug !== 'hello-world', 36 | // } 37 | // } 38 | 39 | /** 40 | * Example of DSG for all routes 41 | */ 42 | // export const config = { 43 | // defer: true, 44 | // } 45 | 46 | export const query = graphql` 47 | query ($id: String) { 48 | allMarkdownRemark { 49 | nodes { 50 | id 51 | } 52 | } 53 | markdownRemark(id: { eq: $id }) { 54 | id 55 | html 56 | frontmatter { 57 | title 58 | date(formatString: "MMMM DD, YYYY") 59 | description 60 | } 61 | # slug 62 | } 63 | } 64 | ` 65 | -------------------------------------------------------------------------------- /plugin/src/helpers/cache.ts: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import process from 'process' 3 | 4 | import type { NetlifyPluginOptions } from '@netlify/build' 5 | 6 | import { getGatsbyRoot } from './config' 7 | 8 | export function getCacheDirs(publish) { 9 | return [publish, normalizedCacheDir(publish)] 10 | } 11 | 12 | export async function saveCache({ 13 | publish, 14 | utils, 15 | }: { 16 | publish: string 17 | utils: NetlifyPluginOptions['utils'] 18 | }): Promise { 19 | if (process.env.NETLIFY_LOCAL) { 20 | return 21 | } 22 | 23 | const cacheDirs = getCacheDirs(publish) 24 | 25 | if (await utils.cache.save(cacheDirs, { move: true })) { 26 | utils.status.show({ 27 | title: 'Essential Gatsby Build Plugin ran successfully', 28 | summary: 'Stored the Gatsby cache to speed up future builds. 🔥', 29 | }) 30 | } else { 31 | console.log('No Gatsby build found.') 32 | } 33 | } 34 | 35 | export async function restoreCache({ 36 | publish, 37 | utils, 38 | }: { 39 | publish: string 40 | utils: NetlifyPluginOptions['utils'] 41 | }): Promise { 42 | if (process.env.NETLIFY_LOCAL) { 43 | return 44 | } 45 | 46 | const cacheDirs = getCacheDirs(publish) 47 | 48 | if (await utils.cache.restore(cacheDirs, { move: true })) { 49 | console.log('Found a Gatsby cache. We’re about to go FAST. ⚡️') 50 | } else { 51 | console.log('No Gatsby cache found. Building fresh.') 52 | } 53 | } 54 | 55 | export function normalizedCacheDir(publish: string): string { 56 | return path.join(getGatsbyRoot(publish), `.cache`) 57 | } 58 | -------------------------------------------------------------------------------- /.github/workflows/release-please.yml: -------------------------------------------------------------------------------- 1 | name: release-please 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | release-please: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: navikt/github-app-token-generator@757386febfca7206eca81593f81558cd99bcee12 11 | id: get-token 12 | with: 13 | private-key: ${{ secrets.TOKENS_PRIVATE_KEY }} 14 | app-id: ${{ secrets.TOKENS_APP_ID }} 15 | - uses: GoogleCloudPlatform/release-please-action@v3 16 | id: release 17 | with: 18 | token: ${{ steps.get-token.outputs.token }} 19 | command: manifest 20 | - uses: actions/checkout@v4 21 | if: ${{ steps.release.outputs.releases_created }} 22 | - uses: actions/setup-node@v4 23 | with: 24 | node-version: '*' 25 | cache: 'npm' 26 | check-latest: true 27 | registry-url: 'https://registry.npmjs.org' 28 | if: ${{ steps.release.outputs.releases_created }} 29 | - name: Install dependencies 30 | run: npm ci 31 | working-directory: plugin 32 | if: ${{ steps.release.outputs.releases_created }} 33 | - run: npm publish 34 | working-directory: plugin 35 | if: ${{ steps.release.outputs.releases_created }} 36 | env: 37 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 38 | - uses: netlify/submit-build-plugin-action@v1 39 | if: ${{ steps.release.outputs.releases_created }} 40 | with: 41 | github-token: ${{ steps.get-token.outputs.token }} 42 | package-json-dir: plugin 43 | -------------------------------------------------------------------------------- /demo-v5/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netlify-gatsby-v5-demo", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "Function test", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "HOST=0.0.0.0 gatsby develop", 12 | "start": "HOST=0.0.0.0 gatsby develop", 13 | "build": "gatsby -v && gatsby build && ls -l .cache public", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean && rm -rf .netlify/cache .netlify/functions*", 16 | "build:netlify": "netlify build --offline --cwd .", 17 | "preview": "netlify dev --offline --cwd .", 18 | "test": "run-s build:netlify test:e2e", 19 | "test:e2e": "start-server-and-test preview 8888 test:jest", 20 | "test:jest": "jest" 21 | }, 22 | "dependencies": { 23 | "@sindresorhus/slugify": "^1.1.2", 24 | "gatsby": "5.15.0", 25 | "gatsby-plugin-image": "next", 26 | "gatsby-plugin-sharp": "next", 27 | "gatsby-source-filesystem": "next", 28 | "gatsby-transformer-remark": "next", 29 | "react": "^18.0.0", 30 | "react-dom": "^18.0.0" 31 | }, 32 | "devDependencies": { 33 | "@netlify/functions": "latest", 34 | "@netlify/ipx": "latest", 35 | "co-body": "^6.1.0", 36 | "cookie": "^0.7.0", 37 | "form-data": "^4.0.0", 38 | "fs-extra": "^10.0.0", 39 | "gatsby-plugin-netlify": "^5.1.0", 40 | "jest": "^29.0.0", 41 | "linkfs": "^2.1.0", 42 | "multer": "^2.0.0", 43 | "node-fetch": "^2.6.1", 44 | "npm-run-all2": "^5.0.0", 45 | "path-to-regexp": "^6.0.0", 46 | "start-server-and-test": "^2.0.0" 47 | }, 48 | "license": "MIT", 49 | "engines": { 50 | "node": ">=18.0.0" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netlify-gatsby-v4-demo", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "Function test", 6 | "author": "Matt Kane", 7 | "keywords": [ 8 | "gatsby" 9 | ], 10 | "scripts": { 11 | "develop": "HOST=0.0.0.0 gatsby develop", 12 | "start": "HOST=0.0.0.0 gatsby develop", 13 | "build": "gatsby -v && gatsby build && ls -l .cache public", 14 | "serve": "gatsby serve", 15 | "clean": "gatsby clean && rm -rf .netlify/cache .netlify/functions*", 16 | "build:netlify": "netlify build --offline --cwd .", 17 | "preview": "netlify dev --offline --cwd .", 18 | "test": "run-s build:netlify test:e2e", 19 | "test:e2e": "start-server-and-test preview 8888 test:jest", 20 | "test:jest": "jest" 21 | }, 22 | "dependencies": { 23 | "@sindresorhus/slugify": "^1.1.2", 24 | "gatsby": "^4.24.8", 25 | "gatsby-plugin-image": "^2.25.0", 26 | "gatsby-plugin-sharp": "^4.25.0", 27 | "gatsby-source-filesystem": "^4.24.0", 28 | "gatsby-transformer-remark": "^5.24.0", 29 | "react": "^18.0.0", 30 | "react-dom": "^18.0.0" 31 | }, 32 | "devDependencies": { 33 | "@netlify/functions": "latest", 34 | "@netlify/ipx": "latest", 35 | "co-body": "^6.1.0", 36 | "cookie": "^0.7.0", 37 | "form-data": "^4.0.0", 38 | "fs-extra": "^10.0.0", 39 | "gatsby-plugin-netlify": "^5.0.0", 40 | "jest": "^29.0.0", 41 | "linkfs": "^2.1.0", 42 | "multer": "^2.0.0", 43 | "node-fetch": "^2.6.1", 44 | "npm-run-all2": "^5.0.0", 45 | "path-to-regexp": "^6.0.0", 46 | "start-server-and-test": "^2.0.0" 47 | }, 48 | "license": "MIT", 49 | "engines": { 50 | "node": ">=14.17.0" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.github/workflows/pre-release.yml: -------------------------------------------------------------------------------- 1 | name: prerelease 2 | on: 3 | push: 4 | branches: 5 | # releases// 6 | - releases/*/* 7 | jobs: 8 | prerelease: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: '*' 15 | cache: 'npm' 16 | check-latest: true 17 | registry-url: 'https://registry.npmjs.org' 18 | - name: Install core dependencies 19 | run: npm ci --no-audit 20 | - name: Extract tag and version 21 | id: extract 22 | run: |- 23 | ref=${{ github.ref }} 24 | branch=${ref:11} 25 | tag_version=${branch:9} 26 | tag=${tag_version%/*} 27 | version=${tag_version##*/} 28 | echo "tag=${tag}" >> $GITHUB_OUTPUT 29 | echo "version=${version}" >> $GITHUB_OUTPUT 30 | - name: Log versions 31 | run: |- 32 | echo tag=${{ steps.extract.outputs.tag }} 33 | echo version=${{ steps.extract.outputs.version }} 34 | - name: Setup git user 35 | run: git config --global user.name github-actions 36 | - name: Setup git email 37 | run: git config --global user.email github-actions@github.com 38 | - name: Run npm version 39 | run: 40 | npm version ${{ steps.extract.outputs.version }}-${{ 41 | steps.extract.outputs.tag }} --allow-same-version 42 | - name: Push changes 43 | run: git push --follow-tags 44 | - name: Run npm publish 45 | run: npm publish --tag=${{ steps.extract.outputs.tag }} 46 | env: 47 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 48 | -------------------------------------------------------------------------------- /demo-v5/gatsby-node.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | const slugify = require('@sindresorhus/slugify') 4 | 5 | exports.createSchemaCustomization = function createSchemaCustomization({ 6 | actions, 7 | schema, 8 | }) { 9 | const { createTypes } = actions 10 | const typeDefs = [ 11 | ` 12 | type Frontmatter @dontInfer { 13 | title: String! 14 | date: Date! @dateformat 15 | description: String 16 | } 17 | `, 18 | schema.buildObjectType({ 19 | name: 'MarkdownRemark', 20 | fields: { 21 | frontmatter: 'Frontmatter!', 22 | slug: { 23 | type: 'String!', 24 | resolve(parent) { 25 | return slugify(parent.frontmatter.title) 26 | }, 27 | }, 28 | }, 29 | interfaces: ['Node'], 30 | extensions: { 31 | infer: true, 32 | }, 33 | }), 34 | ] 35 | 36 | createTypes(typeDefs) 37 | } 38 | 39 | /** 40 | * Example of DPR using createPages 41 | */ 42 | exports.createPages = async function createPages({ 43 | graphql, 44 | actions, 45 | reporter, 46 | }) { 47 | const { data, errors } = await graphql(` 48 | { 49 | allMarkdownRemark { 50 | nodes { 51 | id 52 | slug 53 | } 54 | } 55 | } 56 | `) 57 | 58 | if (errors) { 59 | for (const error of errors) { 60 | reporter.panic(error.message) 61 | } 62 | } 63 | 64 | for (const node of data.allMarkdownRemark.nodes) { 65 | console.log('nodeid', node.id) 66 | actions.createPage({ 67 | path: `/blog/${node.slug}/`, 68 | component: path.resolve(`./src/template/post.js`), 69 | ownerNodeId: node.id, 70 | context: { 71 | id: node.id, 72 | slug: node.slug, 73 | }, 74 | defer: node.slug !== 'hello-world', 75 | }) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /demo/gatsby-node.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | const slugify = require('@sindresorhus/slugify') 4 | 5 | exports.createSchemaCustomization = function createSchemaCustomization({ 6 | actions, 7 | schema, 8 | }) { 9 | const { createTypes } = actions 10 | const typeDefs = [ 11 | ` 12 | type Frontmatter @dontInfer { 13 | title: String! 14 | date: Date! @dateformat 15 | description: String 16 | } 17 | `, 18 | schema.buildObjectType({ 19 | name: 'MarkdownRemark', 20 | fields: { 21 | frontmatter: 'Frontmatter!', 22 | slug: { 23 | type: 'String!', 24 | resolve(parent) { 25 | return slugify(parent.frontmatter.title) 26 | }, 27 | }, 28 | }, 29 | interfaces: ['Node'], 30 | extensions: { 31 | infer: true, 32 | }, 33 | }), 34 | ] 35 | 36 | createTypes(typeDefs) 37 | } 38 | 39 | /** 40 | * Example of DPR using createPages 41 | */ 42 | exports.createPages = async function createPages({ 43 | graphql, 44 | actions, 45 | reporter, 46 | }) { 47 | const { data, errors } = await graphql(` 48 | { 49 | allMarkdownRemark { 50 | nodes { 51 | id 52 | slug 53 | } 54 | } 55 | } 56 | `) 57 | 58 | if (errors) { 59 | for (const error of errors) { 60 | reporter.panic(error.message) 61 | } 62 | } 63 | 64 | for (const node of data.allMarkdownRemark.nodes) { 65 | console.log('nodeid', node.id) 66 | actions.createPage({ 67 | path: `/blog/${node.slug}/`, 68 | component: path.resolve(`./src/template/post.js`), 69 | ownerNodeId: node.id, 70 | context: { 71 | id: node.id, 72 | slug: node.slug, 73 | }, 74 | defer: node.slug !== 'hello-world', 75 | }) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributions 2 | 3 | 🎉 Thanks for considering contributing to this project! 🎉 4 | 5 | These guidelines will help you send a pull request. 6 | 7 | If you're submitting an issue instead, please skip this document. 8 | 9 | If your pull request is related to a typo or the documentation being unclear, 10 | please click on the relevant page's `Edit` button (pencil icon) and directly 11 | suggest a correction instead. 12 | 13 | This project was made with ❤️. The simplest way to give back is by starring and 14 | sharing it online. 15 | 16 | Everyone is welcome regardless of personal background. We enforce a 17 | [Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and 18 | inclusive environment. 19 | 20 | # Development process 21 | 22 | First fork and clone the repository. If you're not sure how to do this, please 23 | watch 24 | [these videos](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github). 25 | 26 | Run: 27 | 28 | ```bash 29 | npm install 30 | ``` 31 | 32 | Make sure everything is correctly setup with: 33 | 34 | ```bash 35 | npm test 36 | ``` 37 | 38 | # Development tasks 39 | 40 | The following development tasks are available. Please check the 41 | [`package.json`](/package.json) `scripts` property for more information. 42 | 43 | ```bash 44 | npm run build 45 | ``` 46 | 47 | Runs a Netlify Build locally with the current plugin. This can be used for 48 | debugging and manual tests. 49 | 50 | The local Build configuration file is [`netlify.toml`](/netlify.toml) and can be 51 | modified. 52 | 53 | ```bash 54 | npm run ava 55 | ``` 56 | 57 | Runs [unit tests](/test/index.js). 58 | 59 | ```bash 60 | npm run lint 61 | ``` 62 | 63 | Lints and prettifies source files. 64 | 65 | ```bash 66 | npm test 67 | ``` 68 | 69 | Runs both unit tests and linting. 70 | 71 | ```bash 72 | npm run release 73 | ``` 74 | 75 | Publishes this plugin to `npm`. 76 | -------------------------------------------------------------------------------- /demo/src/pages/blog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql, Link } from 'gatsby' 3 | import { Layout } from '../layout/default' 4 | import { 5 | postsListCss, 6 | postListItemCss, 7 | postTeaserCss, 8 | postTeaserTitleCss, 9 | postTeaserDescriptionCss, 10 | postTeaserLinkCss, 11 | } from './index.module.css' 12 | 13 | export default function Home({ data }) { 14 | return ( 15 | 16 |
    17 | {data.allMarkdownRemark.nodes.map((node) => { 18 | return ( 19 |
  • 20 |
    21 |

    22 | 26 | {node.frontmatter.title} 27 | 28 |

    29 |

    30 | 34 | {node.frontmatter.description} 35 | 36 |

    37 |
    38 |
  • 39 | ) 40 | })} 41 | 42 | {/*
  • 43 |
    44 |

    45 | 46 | GraphiQL 47 | 48 |

    49 |
    50 |
  • */} 51 |
52 |
53 | ) 54 | } 55 | 56 | export const query = graphql` 57 | { 58 | allMarkdownRemark { 59 | nodes { 60 | frontmatter { 61 | title 62 | description 63 | } 64 | slug 65 | } 66 | } 67 | } 68 | ` 69 | -------------------------------------------------------------------------------- /demo-v5/src/pages/blog.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql, Link } from 'gatsby' 3 | import { Layout } from '../layout/default' 4 | import { 5 | postsListCss, 6 | postListItemCss, 7 | postTeaserCss, 8 | postTeaserTitleCss, 9 | postTeaserDescriptionCss, 10 | postTeaserLinkCss, 11 | } from './index.module.css' 12 | 13 | export default function Home({ data }) { 14 | return ( 15 | 16 |
    17 | {data.allMarkdownRemark.nodes.map((node) => { 18 | return ( 19 |
  • 20 |
    21 |

    22 | 26 | {node.frontmatter.title} 27 | 28 |

    29 |

    30 | 34 | {node.frontmatter.description} 35 | 36 |

    37 |
    38 |
  • 39 | ) 40 | })} 41 | 42 | {/*
  • 43 |
    44 |

    45 | 46 | GraphiQL 47 | 48 |

    49 |
    50 |
  • */} 51 |
52 |
53 | ) 54 | } 55 | 56 | export const query = graphql` 57 | { 58 | allMarkdownRemark { 59 | nodes { 60 | frontmatter { 61 | title 62 | description 63 | } 64 | slug 65 | } 66 | } 67 | } 68 | ` 69 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Plugin Tests 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | schedule: 8 | - cron: '0 0 * * *' 9 | 10 | jobs: 11 | build-ubuntu: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v4 16 | with: 17 | node-version: '18' 18 | - name: Global Node packages cache 19 | uses: actions/cache@v4 20 | with: 21 | path: ~/.npm 22 | key: 23 | ubuntu--build-${{ env.cache-name }}-${{ 24 | hashFiles('**/package-lock.json') }} 25 | - name: Test fixture dependency cache 26 | uses: actions/cache@v4 27 | with: 28 | path: plugin/test/fixtures/**/node_modules 29 | key: 30 | ubuntu-build-${{ env.cache-name }}-${{ 31 | hashFiles('plugin/test/fixtures/**/package.json') }}-node-modules 32 | - run: npm install -g netlify-cli 33 | - run: npm ci 34 | - run: cd plugin && npm ci && npm run build 35 | - run: npm test 36 | 37 | build-mac: 38 | runs-on: macos-latest 39 | if: github.ref_name == 'main' 40 | steps: 41 | - uses: actions/checkout@v4 42 | - uses: actions/setup-node@v4 43 | with: 44 | node-version: '*' 45 | - name: Global Node packages cache 46 | uses: actions/cache@v4 47 | with: 48 | path: ~/.npm 49 | key: 50 | macOS-build-${{ env.cache-name }}-${{ 51 | hashFiles('**/package-lock.json') }} 52 | - name: Test fixture dependency cache 53 | uses: actions/cache@v4 54 | with: 55 | path: plugin/test/fixtures/**/node_modules 56 | key: 57 | macOS-build-${{ env.cache-name }}-${{ 58 | hashFiles('plugin/test/fixtures/**/package.json') }}-node-modules 59 | - run: npm install -g netlify-cli 60 | - run: npm ci 61 | - run: cd plugin && npm ci && npm run build 62 | - run: npm test 63 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | const { overrides } = require('@netlify/eslint-config-node') 2 | 3 | module.exports = { 4 | extends: ['@netlify/eslint-config-node'], 5 | rules: { 6 | // For now 7 | 'func-style': 'off', 8 | // This is compiled, so we can use modern syntax 9 | 'node/no-unsupported-features/es-syntax': 'off', 10 | // This is a duplicate of `import/no-duplicates` but can handle "import type" 11 | 'no-duplicate-imports': 'off', 12 | 'max-depth': ['error', 4], 13 | 'n/no-missing-import': 'off', 14 | }, 15 | env: { 16 | jest: true, 17 | }, 18 | parserOptions: { 19 | sourceType: 'module', 20 | }, 21 | overrides: [ 22 | ...overrides, 23 | { 24 | // Tests use lots of nested callbacks 25 | files: ['*-test.js', '*.spec.js', '**/e2e-tests/*.js'], 26 | rules: { 27 | 'max-nested-callbacks': 'off', 28 | }, 29 | }, 30 | { 31 | // Templates import files from the site itself and needs lots of dynamic requires 32 | files: ['plugin/src/templates/**/*'], 33 | rules: { 34 | 'n/no-unpublished-import': 'off', 35 | '@typescript-eslint/no-var-requires': 'off', 36 | 'n/global-require': 'off', 37 | 'import/no-dynamic-require': 'off', 38 | 'import/no-unresolved': 'off', 39 | 'n/no-unpublished-require': 'off', 40 | 'n/no-missing-require': 'off', 41 | 'n/no-missing-import': 'off', 42 | 'max-lines': 'off', 43 | complexity: 'off', 44 | 'max-statements': 'off', 45 | 'n/prefer-global/process': 'off', 46 | 'unicorn/filename-case': 'off', 47 | }, 48 | }, 49 | { 50 | files: ['plugin/test/**/*'], 51 | rules: { 52 | 'n/no-unpublished-import': 'off', 53 | 'max-lines': 'off', 54 | 'n/no-unpublished-require': 'off', 55 | 'n/no-missing-require': 'off', 56 | 'n/no-missing-import': 'off', 57 | '@typescript-eslint/no-var-requires': 'off', 58 | 'n/global-require': 'off', 59 | 'n/prefer-global/process': 'off', 60 | }, 61 | }, 62 | ], 63 | } 64 | -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Gatsby 4 | 5 |

6 |

7 | Gatsby minimal starter 8 |

9 | 10 | ## 🚀 Quick start 11 | 12 | 1. **Create a Gatsby site.** 13 | 14 | Use the Gatsby CLI to create a new site, specifying the minimal starter. 15 | 16 | ```shell 17 | # create a new Gatsby site using the minimal starter 18 | npm init gatsby 19 | ``` 20 | 21 | 2. **Start developing.** 22 | 23 | Navigate into your new site’s directory and start it up. 24 | 25 | ```shell 26 | cd my-gatsby-site/ 27 | npm run develop 28 | ``` 29 | 30 | 3. **Open the code and start customizing!** 31 | 32 | Your site is now running at http://localhost:8000! 33 | 34 | Edit `src/pages/index.js` to see your site update in real-time! 35 | 36 | 4. **Learn more** 37 | 38 | - [Documentation](https://www.gatsbyjs.com/docs/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 39 | 40 | - [Tutorials](https://www.gatsbyjs.com/tutorial/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 41 | 42 | - [Guides](https://www.gatsbyjs.com/tutorial/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 43 | 44 | - [API Reference](https://www.gatsbyjs.com/docs/api-reference/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 45 | 46 | - [Plugin Library](https://www.gatsbyjs.com/plugins?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 47 | 48 | - [Cheat Sheet](https://www.gatsbyjs.com/docs/cheat-sheet/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 49 | 50 | ## 🚀 Quick start (Gatsby Cloud) 51 | 52 | Deploy this starter with one click on 53 | [Gatsby Cloud](https://www.gatsbyjs.com/cloud/): 54 | 55 | [Deploy to Gatsby Cloud](https://www.gatsbyjs.com/dashboard/deploynow?url=https://github.com/gatsbyjs/gatsby-starter-minimal) 56 | -------------------------------------------------------------------------------- /demo-v5/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Gatsby 4 | 5 |

6 |

7 | Gatsby minimal starter 8 |

9 | 10 | ## 🚀 Quick start 11 | 12 | 1. **Create a Gatsby site.** 13 | 14 | Use the Gatsby CLI to create a new site, specifying the minimal starter. 15 | 16 | ```shell 17 | # create a new Gatsby site using the minimal starter 18 | npm init gatsby 19 | ``` 20 | 21 | 2. **Start developing.** 22 | 23 | Navigate into your new site’s directory and start it up. 24 | 25 | ```shell 26 | cd my-gatsby-site/ 27 | npm run develop 28 | ``` 29 | 30 | 3. **Open the code and start customizing!** 31 | 32 | Your site is now running at http://localhost:8000! 33 | 34 | Edit `src/pages/index.js` to see your site update in real-time! 35 | 36 | 4. **Learn more** 37 | 38 | - [Documentation](https://www.gatsbyjs.com/docs/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 39 | 40 | - [Tutorials](https://www.gatsbyjs.com/tutorial/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 41 | 42 | - [Guides](https://www.gatsbyjs.com/tutorial/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 43 | 44 | - [API Reference](https://www.gatsbyjs.com/docs/api-reference/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 45 | 46 | - [Plugin Library](https://www.gatsbyjs.com/plugins?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 47 | 48 | - [Cheat Sheet](https://www.gatsbyjs.com/docs/cheat-sheet/?utm_source=starter&utm_medium=readme&utm_campaign=minimal-starter) 49 | 50 | ## 🚀 Quick start (Gatsby Cloud) 51 | 52 | Deploy this starter with one click on 53 | [Gatsby Cloud](https://www.gatsbyjs.com/cloud/): 54 | 55 | [Deploy to Gatsby Cloud](https://www.gatsbyjs.com/dashboard/deploynow?url=https://github.com/gatsbyjs/gatsby-starter-minimal) 56 | -------------------------------------------------------------------------------- /plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@netlify/plugin-gatsby", 3 | "version": "3.8.4", 4 | "description": "Netlify Build plugin - Run Gatsby seamlessly on Netlify", 5 | "source": "src/index.ts", 6 | "main": "lib/index.js", 7 | "files": [ 8 | "src/templates/**", 9 | "lib/**/*", 10 | "manifest.yml" 11 | ], 12 | "keywords": [ 13 | "netlify-plugin", 14 | "netlify", 15 | "gatsby", 16 | "gatsbyjs" 17 | ], 18 | "author": "Luke Oliff ", 19 | "license": "MIT", 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/netlify/netlify-plugin-gatsby" 23 | }, 24 | "directories": { 25 | "test": "test" 26 | }, 27 | "engines": { 28 | "node": ">=14.17.0" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/netlify/netlify-plugin-gatsby/issues" 32 | }, 33 | "scripts": { 34 | "prepublishOnly": "npm-run-all -l -s clean -p copy-readme build", 35 | "copy-readme": "cp ../README.md .", 36 | "clean": "rimraf lib", 37 | "watch": "tsc --watch", 38 | "build": "tsc", 39 | "start": "npm run watch", 40 | "prepare": "npm run build" 41 | }, 42 | "dependencies": { 43 | "@netlify/functions": "^1.6.0", 44 | "@netlify/ipx": "^1.4.6", 45 | "abortcontroller-polyfill": "^1.7.3", 46 | "chalk": "^4.1.2", 47 | "co-body": "^6.1.0", 48 | "cookie": "^0.7.0", 49 | "etag": "^1.8.1", 50 | "fs-extra": "^10.0.0", 51 | "linkfs": "^2.1.0", 52 | "multer": "^2.0.0", 53 | "node-fetch": "^2.6.1", 54 | "node-stream-zip": "^1.15.0", 55 | "pathe": "^0.3.0", 56 | "pretty-bytes": "^5.6.0", 57 | "semver": "^7.3.5", 58 | "statuses": "^2.0.1", 59 | "uuid": "^9.0.0" 60 | }, 61 | "devDependencies": { 62 | "@gatsbyjs/reach-router": "^2.0.0", 63 | "@netlify/build": "^33.4.7", 64 | "@types/chance": "^1.1.3", 65 | "@types/fs-extra": "^9.0.12", 66 | "@types/multer": "^1.4.7", 67 | "@types/semver": "^7.3.9", 68 | "chance": "^1.1.8", 69 | "execa": "^5.0.0", 70 | "gatsby": "^5.2.0", 71 | "npm-run-all2": "^5.0.0", 72 | "react": "^18.2.0", 73 | "rimraf": "^5.0.0", 74 | "tmp-promise": "^3.0.3", 75 | "typescript": "^5.0.0" 76 | }, 77 | "peerDependencies": { 78 | "@gatsbyjs/reach-router": "*", 79 | "common-tags": "^1.8.2" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /docs/image-cdn.md: -------------------------------------------------------------------------------- 1 | # Gatsby Image CDN on Netlify 2 | 3 | Gatsby Image CDN is a feature available since Gatsby v4.10.0. Instead of 4 | downloading and processing images at build time, it defers processing until 5 | request time. This can greatly improve build times for sites with remote images, 6 | such as those that use a CMS. Netlify includes full support for Image CDN, on 7 | all plans. 8 | 9 | ## Enabling the Image CDN 10 | 11 | To enable the Image CDN, you should set the environment variable 12 | `NETLIFY_IMAGE_CDN` to `true`. You will also need to declare allowed remote 13 | image regular expression patterns in `netlify.toml`: 14 | 15 | ```toml 16 | [build.environment] 17 | NETLIFY_IMAGE_CDN = "true" 18 | 19 | [images] 20 | remote_images = [ 21 | 'https://example1.com/.*', 22 | 'https://example2.com/.*' 23 | ] 24 | ``` 25 | 26 | Exact remote image pattern to use will depend on CMS you use and possibly your 27 | configuration of it. 28 | 29 | - `gatsby-source-contentful`: 30 | 31 | ```toml 32 | [images] 33 | remote_images = [ 34 | # is specified in the `spaceId` option for the 35 | # gatsby-source-contentful plugin in your gatsby-config file. 36 | "https://images.ctfassets.net//.*" 37 | ] 38 | ``` 39 | 40 | - `gatsby-source-drupal`: 41 | 42 | ```toml 43 | [images] 44 | remote_images = [ 45 | # is speciafied in the `baseUrl` option for the 46 | # gatsby-source-drupal plugin in your gatsby-config file. 47 | "/.*" 48 | ] 49 | ``` 50 | 51 | - `gatsby-source-wordpress`: 52 | 53 | ```toml 54 | [images] 55 | remote_images = [ 56 | # is specified in the `url` option for the 57 | # gatsby-source-wordpress plugin in your gatsby-config file. 58 | # There is no need to include `/graphql in the path here` 59 | "/.*" 60 | ] 61 | ``` 62 | 63 | Above examples are the most likely ones to be needed. However if you configure 64 | your CMS to host assets on different domain or path, you might need to adjust 65 | the patterns accordingly. 66 | 67 | ## How it works 68 | 69 | When using the Image CDN, Gatsby generates URLs of the form 70 | `/_gatsby/image/...`. On Netlify, these are served by a function that translates 71 | Gatsby Image CDN URLs into Netlify Image CDN compatible URL of the form 72 | `/.netlify/images/...`. For more information about Netlify Image CDN, 73 | documentation can be found [here](https://docs.netlify.com/image-cdn/overview). 74 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netlify-plugin-gatsby", 3 | "version": "2.0.0", 4 | "description": "Netlify Build plugin gatsby - Run Gatsby seamlessly on Netlify.", 5 | "directories": { 6 | "test": "test" 7 | }, 8 | "scripts": { 9 | "build:demo": "cd demo && GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE=true npm run build:netlify", 10 | "install:demo": "cd demo && npm install", 11 | "prepare": "husky install node_modules/@netlify/eslint-config-node/.husky/", 12 | "test": "run-s format install:demo build:demo test:unit test:e2e", 13 | "test:unit": "jest", 14 | "test:e2e": "run-s test:e2e:*", 15 | "test:e2e:v3": "cd plugin/test && ./v3-e2e-test.sh", 16 | "test:e2e:v4": "cd plugin/test && ./v4-e2e-test.sh", 17 | "test:e2e:v5": "cd plugin/test && ./v5-e2e-test.sh", 18 | "format": "run-s format:check-fix:*", 19 | "format:ci": "run-s format:check:*", 20 | "format:check-fix:lint": "run-e format:check:lint format:fix:lint", 21 | "format:check:lint": "cross-env-shell eslint $npm_package_config_eslint", 22 | "format:fix:lint": "cross-env-shell eslint --fix $npm_package_config_eslint", 23 | "format:check-fix:prettier": "run-e format:check:prettier format:fix:prettier", 24 | "format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier", 25 | "format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier", 26 | "ava": "cross-env FORCE_COLOR=1 ava --verbose" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/netlify/netlify-plugin-gatsby.git" 31 | }, 32 | "author": "", 33 | "license": "ISC", 34 | "bugs": { 35 | "url": "https://github.com/netlify/netlify-plugin-gatsby/issues" 36 | }, 37 | "homepage": "https://github.com/netlify/netlify-plugin-gatsby#readme", 38 | "config": { 39 | "eslint": "--cache --format=codeframe --max-warnings=0 \"{plugin,demo,.github}/**/*.{ts,js,md,html}\" \"*.{ts,js,md,html}\" \".*.{ts,js,md,html}\"", 40 | "prettier": "--loglevel=warn \"{plugin,demo,.github}/**/*.{ts,js,md,yml,json,html}\" \"*.{ts,js,yml,json,html}\" \".*.{ts,js,yml,json,html}\" \"!package-lock.json\"" 41 | }, 42 | "devDependencies": { 43 | "@netlify/build": "^33.4.7", 44 | "@netlify/eslint-config-node": "7.0.1", 45 | "@types/jest": "^29.0.0", 46 | "ava": "^5.0.0", 47 | "cross-env": "^7.0.2", 48 | "husky": "^8.0.0", 49 | "jest": "^29.0.0", 50 | "ts-jest": "^29.0.0" 51 | }, 52 | "peerDependencies": { 53 | "execa": "^5.0.0" 54 | }, 55 | "private": true 56 | } 57 | -------------------------------------------------------------------------------- /plugin/src/helpers/verification.ts: -------------------------------------------------------------------------------- 1 | import process from 'process' 2 | 3 | import { yellowBright, blueBright } from 'chalk' 4 | import { stripIndent } from 'common-tags' 5 | import { existsSync, promises } from 'fs-extra' 6 | import { async as StreamZip } from 'node-stream-zip' 7 | import { relative } from 'pathe' 8 | import prettyBytes from 'pretty-bytes' 9 | 10 | // 50MB, which is the warning max 11 | // eslint-disable-next-line no-magic-numbers 12 | export const LAMBDA_WARNING_SIZE = 1024 * 1024 * 50 13 | 14 | // 250MB, which is the hard max 15 | // eslint-disable-next-line no-magic-numbers 16 | export const LAMBDA_MAX_SIZE = 1024 * 1024 * 250 17 | 18 | // eslint-disable-next-line max-statements 19 | export const checkZipSize = async ( 20 | file: string, 21 | warningSize: number = LAMBDA_WARNING_SIZE, 22 | maxSize: number = LAMBDA_MAX_SIZE, 23 | ): Promise => { 24 | if (!existsSync(file)) { 25 | console.warn(`Could not check zip size because ${file} does not exist`) 26 | return 27 | } 28 | const fileSize = await promises.stat(file).then(({ size }) => size) 29 | if (fileSize < warningSize) { 30 | return 31 | } 32 | // We don't fail the build, because the actual hard max size is larger so it might still succeed 33 | console.log( 34 | yellowBright(stripIndent` 35 | The function zip ${blueBright( 36 | relative(process.cwd(), file), 37 | )} size is ${prettyBytes( 38 | fileSize, 39 | )}, which is larger than the recommended maximum size of ${prettyBytes( 40 | warningSize, 41 | )}. This will fail the build if the unzipped size is bigger than the maximum size of ${prettyBytes( 42 | maxSize, 43 | )} 44 | There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files". 45 | `), 46 | ) 47 | const zip = new StreamZip({ file }) 48 | console.log(`Contains ${await zip.entriesCount} files`) 49 | const sortedFiles = Object.values(await zip.entries()).sort( 50 | (entryA, entryB) => entryB.size - entryA.size, 51 | ) 52 | 53 | const largest = {} 54 | const MAX_ROWS = 10 55 | for (let idx = 0; idx < MAX_ROWS && idx < sortedFiles.length; idx++) { 56 | largest[`${idx + 1}`] = { 57 | File: sortedFiles[idx].name, 58 | 'Compressed Size': prettyBytes(sortedFiles[idx].compressedSize), 59 | 'Uncompressed Size': prettyBytes(sortedFiles[idx].size), 60 | } 61 | } 62 | await zip.close() 63 | console.log(yellowBright`\n\nThese are the largest files in the zip:`) 64 | console.table(largest) 65 | } 66 | -------------------------------------------------------------------------------- /plugin/src/templates/image.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from 'buffer' 2 | 3 | import { Handler } from '@netlify/functions' 4 | 5 | type Event = Parameters[0] 6 | 7 | function generateURLFromQueryParamsPath(uParam, cdParam, argsParam) { 8 | try { 9 | const newURL = new URL('.netlify/images', 'https://example.com') 10 | newURL.searchParams.set('url', uParam) 11 | newURL.searchParams.set('cd', cdParam) 12 | 13 | const aParams = new URLSearchParams(argsParam) 14 | aParams.forEach((value, key) => { 15 | newURL.searchParams.set(key, value) 16 | }) 17 | 18 | return newURL.pathname + newURL.search 19 | } catch (error) { 20 | console.error('Error constructing URL:', error) 21 | return null 22 | } 23 | } 24 | 25 | function generateURLFromBase64EncodedPath(path) { 26 | const [, , , encodedUrl, encodedArgs] = path.split('/') 27 | 28 | const decodedUrl = Buffer.from(encodedUrl, 'base64').toString('utf8') 29 | const decodedArgs = Buffer.from(encodedArgs, 'base64').toString('utf8') 30 | 31 | let sourceURL 32 | try { 33 | sourceURL = new URL(decodedUrl) 34 | } catch (error) { 35 | console.error('Decoded string is not a valid URL:', error) 36 | return 37 | } 38 | 39 | const newURL = new URL('.netlify/images', 'https://example.com') 40 | newURL.searchParams.set('url', sourceURL.href) 41 | 42 | const aParams = new URLSearchParams(decodedArgs) 43 | aParams.forEach((value, key) => { 44 | newURL.searchParams.set(key, value) 45 | }) 46 | 47 | return newURL.pathname + newURL.search 48 | } 49 | 50 | // eslint-disable-next-line require-await 51 | export const handler: Handler = async (event: Event) => { 52 | const QUERY_PARAM_PATTERN = 53 | /^\/\.netlify\/functions\/__image\/image_query_compat\/?$/i 54 | 55 | const { pathname } = new URL(event.rawUrl) 56 | const match = pathname.match(QUERY_PARAM_PATTERN) 57 | 58 | let newURL 59 | 60 | if (match) { 61 | // Extract the query parameters 62 | const { 63 | url: uParam, 64 | cd: cdParam, 65 | args: argsParam, 66 | } = event.queryStringParameters 67 | 68 | newURL = generateURLFromQueryParamsPath(uParam, cdParam, argsParam) 69 | } else { 70 | newURL = generateURLFromBase64EncodedPath(pathname) 71 | } 72 | 73 | const cachingHeaders = { 74 | 'Cache-Control': 'public,max-age=31536000,immutable', 75 | 'Netlify-CDN-Cache-Control': 'public,max-age=31536000,immutable', 76 | 'Netlify-Vary': 'query', 77 | } 78 | 79 | return newURL 80 | ? { 81 | statusCode: 301, 82 | headers: { 83 | Location: newURL, 84 | ...cachingHeaders, 85 | }, 86 | } 87 | : { statusCode: 400, body: 'Invalid request', headers: cachingHeaders } 88 | } 89 | -------------------------------------------------------------------------------- /demo/src/pages/image-cdn.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql } from 'gatsby' 3 | import { GatsbyImage } from 'gatsby-plugin-image' 4 | import { Layout } from '../layout/default' 5 | 6 | const ImageCDNPage = ({ data }) => ( 7 | 8 |

Image CDN

9 |
    10 | {data.allUnsplashImage.nodes.map((node) => ( 11 | <> 12 |
  • 13 |
    14 | 15 |
    400px wide image
    16 |
    17 |
  • 18 |
  • 19 |
    20 | 21 |
    200px wide image
    22 |
    23 |
  • 24 |
  • 25 |
    26 | Public URL 27 |
    Public URL
    28 |
    29 |
  • 30 | 31 | ))} 32 |
33 |

Old url structure

34 |
35 | Gatsby Image 39 |
40 | /_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==.avif 41 |
42 |
43 |
44 | Gatsby File 48 |
49 | /_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif 50 |
51 |
52 |
53 | ) 54 | 55 | export default ImageCDNPage 56 | 57 | export const query = graphql` 58 | { 59 | allUnsplashImage { 60 | nodes { 61 | id 62 | gatsbyImage200: gatsbyImage(width: 200) 63 | gatsbyImage400: gatsbyImage(width: 400) 64 | publicUrl 65 | } 66 | } 67 | } 68 | ` 69 | -------------------------------------------------------------------------------- /demo-v5/src/pages/image-cdn.js: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import { graphql } from 'gatsby' 3 | import { GatsbyImage } from 'gatsby-plugin-image' 4 | import { Layout } from '../layout/default' 5 | 6 | const ImageCDNPage = ({ data }) => ( 7 | 8 |

Image CDN

9 |
    10 | {data.allUnsplashImage.nodes.map((node) => ( 11 | <> 12 |
  • 13 |
    14 | 15 |
    400px wide image
    16 |
    17 |
  • 18 |
  • 19 |
    20 | 21 |
    200px wide image
    22 |
    23 |
  • 24 |
  • 25 |
    26 | Public URL 27 |
    Public URL
    28 |
    29 |
  • 30 | 31 | ))} 32 |
33 |

Old url structure

34 |
35 | Gatsby Image 39 |
40 | /_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==.avif 41 |
42 |
43 |
44 | Gatsby File 48 |
49 | /_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif 50 |
51 |
52 |
53 | ) 54 | 55 | export default ImageCDNPage 56 | 57 | export const query = graphql` 58 | { 59 | allUnsplashImage { 60 | nodes { 61 | id 62 | gatsbyImage200: gatsbyImage(width: 200) 63 | gatsbyImage400: gatsbyImage(width: 400) 64 | publicUrl 65 | } 66 | } 67 | } 68 | ` 69 | -------------------------------------------------------------------------------- /plugin/test/unit/helpers/functions.spec.ts: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import process from 'process' 3 | 4 | import type { NetlifyConfig, NetlifyPluginOptions } from '@netlify/build' 5 | import Chance from 'chance' 6 | import { copy, existsSync } from 'fs-extra' 7 | import { dir as getTmpDir } from 'tmp-promise' 8 | 9 | import { writeFunctions } from '../../../src/helpers/functions' 10 | 11 | const SAMPLE_PROJECT_DIR = `${__dirname}/../../../../demo` 12 | const TEST_TIMEOUT = 60_000 13 | 14 | const changeCwd = (cwd) => { 15 | const originalCwd = process.cwd() 16 | process.chdir(cwd) 17 | return () => { 18 | process.chdir(originalCwd) 19 | } 20 | } 21 | 22 | // Move gatsby project from sample project to current directory 23 | const moveGatsbyDir = async () => { 24 | await copy(SAMPLE_PROJECT_DIR, join(process.cwd())) 25 | } 26 | 27 | const chance = new Chance() 28 | 29 | describe('writeFunctions', () => { 30 | let cleanup 31 | let restoreCwd 32 | 33 | beforeEach(async () => { 34 | const tmpDir = await getTmpDir({ unsafeCleanup: true }) 35 | 36 | restoreCwd = changeCwd(tmpDir.path) 37 | // eslint-disable-next-line prefer-destructuring 38 | cleanup = tmpDir.cleanup 39 | }) 40 | 41 | afterEach(async () => { 42 | // Cleans up the temporary directory from `getTmpDir()` and do not make it 43 | // the current directory anymore 44 | restoreCwd() 45 | await cleanup() 46 | }, TEST_TIMEOUT) 47 | it( 48 | 'successfully creates a functions-internal directory if it does not exist', 49 | async () => { 50 | await moveGatsbyDir() 51 | const constants: NetlifyPluginOptions['constants'] = { 52 | INTERNAL_FUNCTIONS_SRC: 'demo/.netlify/functions-internal', 53 | PUBLISH_DIR: 'demo/public', 54 | FUNCTIONS_DIST: 'demo/.netlify/functions', 55 | EDGE_FUNCTIONS_DIST: 'demo/.netlify/edge-functions-dist/', 56 | IS_LOCAL: true, 57 | NETLIFY_BUILD_VERSION: '9000.0.0', 58 | SITE_ID: chance.guid(), 59 | CACHE_DIR: 'demo/.netlify/cache', 60 | } 61 | 62 | const netlifyConfig: NetlifyConfig = { 63 | build: { 64 | command: 'npm run build', 65 | publish: 'demo/public', 66 | base: '.', 67 | environment: { 68 | GATSBY_CLOUD_IMAGE_CDN: 'true', 69 | }, 70 | services: {}, 71 | processing: { 72 | css: {}, 73 | js: {}, 74 | html: {}, 75 | images: {}, 76 | }, 77 | }, 78 | functions: { '*': {} }, 79 | redirects: [], 80 | headers: [], 81 | edge_functions: [], 82 | plugins: [], 83 | images: { 84 | remote_images: [], 85 | }, 86 | } 87 | 88 | await writeFunctions({ 89 | constants, 90 | netlifyConfig, 91 | neededFunctions: [], 92 | }) 93 | 94 | const doesDirectoryExist = existsSync( 95 | join(process.cwd(), 'demo', '.netlify', 'functions-internal'), 96 | ) 97 | 98 | expect(doesDirectoryExist).toEqual(true) 99 | // Longer timeout for the test is necessary due to the copying of the demo project into the tmp dir 100 | }, 101 | TEST_TIMEOUT, 102 | ) 103 | }) 104 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This text is available in 4 | [many other languages](https://www.contributor-covenant.org/translations). 5 | 6 | ## Our Pledge 7 | 8 | In the interest of fostering an open and welcoming environment, we as 9 | contributors and maintainers pledge to making participation in our project and 10 | our community a harassment-free experience for everyone, regardless of age, body 11 | size, disability, ethnicity, sex characteristics, gender identity and 12 | expression, level of experience, education, socio-economic status, nationality, 13 | personal appearance, race, religion, or sexual identity and orientation. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | - Using welcoming and inclusive language 21 | - Being respectful of differing viewpoints and experiences 22 | - Gracefully accepting constructive criticism 23 | - Focusing on what is best for the community 24 | - Showing empathy towards other community members 25 | 26 | Examples of unacceptable behavior by participants include: 27 | 28 | - The use of sexualized language or imagery and unwelcome sexual attention or 29 | advances 30 | - Trolling, insulting/derogatory comments, and personal or political attacks 31 | - Public or private harassment 32 | - Publishing others' private information, such as a physical or electronic 33 | address, without explicit permission 34 | - Other conduct which could reasonably be considered inappropriate in a 35 | professional setting 36 | 37 | ## Our Responsibilities 38 | 39 | Project maintainers are responsible for clarifying the standards of acceptable 40 | behavior and are expected to take appropriate and fair corrective action in 41 | response to any instances of unacceptable behavior. 42 | 43 | Project maintainers have the right and responsibility to remove, edit, or reject 44 | comments, commits, code, wiki edits, issues, and other contributions that are 45 | not aligned to this Code of Conduct, or to ban temporarily or permanently any 46 | contributor for other behaviors that they deem inappropriate, threatening, 47 | offensive, or harmful. 48 | 49 | ## Scope 50 | 51 | This Code of Conduct applies both within project spaces and in public spaces 52 | when an individual is representing the project or its community. Examples of 53 | representing a project or community include using an official project e-mail 54 | address, posting via an official social media account, or acting as an appointed 55 | representative at an online or offline event. Representation of a project may be 56 | further defined and clarified by project maintainers. 57 | 58 | ## Enforcement 59 | 60 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 61 | reported by contacting the project team at luke@lukeoliff.com. 62 | 63 | All complaints will be reviewed and investigated and will result in a response 64 | that is deemed necessary and appropriate to the circumstances. The project team 65 | is obligated to maintain confidentiality with regard to the reporter of an 66 | incident. Further details of specific enforcement policies may be posted 67 | separately. 68 | 69 | Project maintainers who do not follow or enforce the Code of Conduct in good 70 | faith may face temporary or permanent repercussions as determined by other 71 | members of the project's leadership. 72 | 73 | ## Attribution 74 | 75 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 76 | version 1.4, available at 77 | https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 78 | 79 | [homepage]: https://www.contributor-covenant.org 80 | 81 | For answers to common questions about this code of conduct, see 82 | https://www.contributor-covenant.org/faq 83 | -------------------------------------------------------------------------------- /plugin/src/templates/api/gatsbyFunction.ts: -------------------------------------------------------------------------------- 1 | import { existsSync } from 'fs' 2 | import path from 'path' 3 | import process from 'process' 4 | 5 | import { 6 | match as reachRouterMatch, 7 | matchPath as reachRouterMatchPath, 8 | } from '@gatsbyjs/reach-router' 9 | import { HandlerEvent } from '@netlify/functions' 10 | import bodyParser from 'co-body' 11 | import multer from 'multer' 12 | 13 | import { 14 | proxyRequest, 15 | AugmentedGatsbyFunctionResponse, 16 | AugmentedGatsbyFunctionRequest, 17 | } from './utils' 18 | 19 | /** 20 | * Depending on the version of '@gatsbyjs/reach-router' installed, the 'match' method may not be defined. 21 | * This check ensures that this continues to work as expected between v1 and v2 of the package. 22 | */ 23 | const reachMatch = reachRouterMatch || reachRouterMatchPath 24 | const parseForm = multer().any() 25 | type MulterReq = Parameters[0] 26 | type MulterRes = Parameters[1] 27 | /** 28 | * Execute a Gatsby function 29 | */ 30 | export async function gatsbyFunction( 31 | req: AugmentedGatsbyFunctionRequest, 32 | res: AugmentedGatsbyFunctionResponse, 33 | event: HandlerEvent, 34 | appDir: string, 35 | ) { 36 | const functionsDir = path.join(appDir, '.cache', 'functions') 37 | 38 | // Multipart form data middleware. because co-body can't handle it 39 | await new Promise((resolve) => { 40 | // As we're using a fake Express handler we need to ignore the type to keep multer happy 41 | parseForm(req as unknown as MulterReq, res as unknown as MulterRes, resolve) 42 | }) 43 | try { 44 | // If req.body is populated then it was multipart data 45 | if ( 46 | !req.files && 47 | !req.body && 48 | req.method !== 'GET' && 49 | req.method !== 'HEAD' 50 | ) { 51 | req.body = await bodyParser(req as unknown as Request) 52 | } 53 | } catch (error) { 54 | console.log('Error parsing body', error, req) 55 | } 56 | 57 | const pathFragment = decodeURIComponent(req.url).replace('/api/', '') 58 | 59 | let functions 60 | try { 61 | functions = require(path.join(functionsDir, 'manifest.json')) 62 | } catch { 63 | return { 64 | statusCode: 404, 65 | body: 'Could not load function manifest', 66 | } 67 | } 68 | 69 | // Begin copied from Gatsby serve command 70 | // Check first for exact matches. 71 | let functionObj = functions.find( 72 | ({ functionRoute }) => functionRoute === pathFragment, 73 | ) 74 | 75 | if (!functionObj) { 76 | // Check if there's any matchPaths that match. 77 | // We loop until we find the first match. 78 | functions.some((func) => { 79 | if (func.matchPath) { 80 | const matchResult = reachMatch(func.matchPath, pathFragment) 81 | if (matchResult) { 82 | req.params = matchResult.params 83 | 84 | if (req.params[`*`]) { 85 | // Backwards compatability for v3 86 | // TODO remove in v5 87 | req.params[`0`] = req.params[`*`] 88 | } 89 | functionObj = func 90 | 91 | return true 92 | } 93 | } 94 | 95 | return false 96 | }) 97 | } 98 | // end copied from Gatsby serve command 99 | if (functionObj) { 100 | console.log(`Running ${functionObj.functionRoute}`) 101 | const start = Date.now() 102 | // During develop, the absolute path is correct, otherwise we need to use a relative path, as we're in a lambda 103 | const pathToFunction = process.env.NETLIFY_DEV 104 | ? functionObj.absoluteCompiledFilePath 105 | : path.join(functionsDir, functionObj.relativeCompiledFilePath) 106 | 107 | if (process.env.NETLIFY_DEV && !existsSync(pathToFunction)) { 108 | // Functions are sometimes lazily-compiled, so we check and proxy the request if needed 109 | console.log( 110 | 'No compiled function found. Proxying to gatsby develop server', 111 | ) 112 | return proxyRequest(event, res) 113 | } 114 | 115 | try { 116 | if (process.env.NETLIFY_LOCAL) { 117 | // Make sure it's hot and fresh from the filesystem 118 | delete require.cache[require.resolve(pathToFunction)] 119 | } 120 | 121 | const fn = require(pathToFunction) 122 | 123 | const fnToExecute = (fn && fn.default) || fn 124 | 125 | await Promise.resolve(fnToExecute(req, res)) 126 | } catch (error) { 127 | console.error(error) 128 | // Don't send the error if that would cause another error. 129 | if (!res.headersSent) { 130 | res 131 | .status(500) 132 | .send( 133 | `Error when executing function "${functionObj.originalRelativeFilePath}": "${error.message}"`, 134 | ) 135 | } 136 | } 137 | 138 | const end = Date.now() 139 | console.log( 140 | `Executed function "/api/${functionObj.functionRoute}" in ${ 141 | end - start 142 | }ms`, 143 | ) 144 | } else { 145 | res.status(404).send('Not found') 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Netlify Build plugin Gatsby – Run Gatsby seamlessly on Netlify](netlify-gatsby-plugin.png) 2 | 3 | # Essential Gatsby Plugin 4 | 5 | The Essential Gatsby build plugin enables caching of builds, SSR and DSG 6 | [render modes](https://v4.gatsbyjs.com/docs/conceptual/rendering-options/), 7 | image CDN and Gatsby Functions. It is installed automatically for all new Gatsby 8 | sites. 9 | 10 | > **Note:** 11 | > 12 | > - Essential Gatsby includes functionality from the 13 | > [Gatsby Cache build plugin](https://github.com/jlengstorf/netlify-plugin-gatsby-cache). 14 | > If you already have the Gatsby Cache plugin installed on your Netlify site, 15 | > you should 16 | > [remove it](https://docs.netlify.com/configure-builds/build-plugins/#remove-a-plugin) 17 | > before installing this plugin. 18 | > - Essential Gatsby is not compatible with the Gatsby community plugin 19 | > [gatsby-plugin-netlify-cache](https://www.gatsbyjs.com/plugins/gatsby-plugin-netlify-cache/). 20 | 21 | ## Installation 22 | 23 | Gatsby sites need two plugins to support all features. 24 | 25 | 1. The Netlify build plugin, called "Essential Gatsby" or 26 | `@netlify/plugin-gatsby`. This is installed automatically for all Gatsby 27 | sites deployed to Netlify. 28 | 2. The Gatsby plugin `gatsby-plugin-netlify`. This needs to be manually 29 | installed. 30 | 31 | ### Installing the Netlify build plugin 32 | 33 | New Gatsby sites on Netlify automatically install the Essential Gatsby build 34 | plugin. You can confirm this in the build logs. If you need to install it 35 | manually, you have two options: 36 | 37 | - [The Netlify UI](https://docs.netlify.com/configure-builds/build-plugins/#ui-installation). 38 | Here, you can search for "Essential Gatsby" and install the plugin. 39 | 40 | - [File-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#file-based-installation). 41 | You can install the plugin as `@netlify/plugin-gatsby` in your `netlify.toml` 42 | file. 43 | 44 | ### Install the Gatsby Plugin 45 | 46 | You should also install the Gatsby plugin 47 | [gatsby-plugin-netlify](https://www.gatsbyjs.org/plugins/gatsby-plugin-netlify/). 48 | This is required for SSR and DSG pages, and adds support for Gatsby redirects and asset 49 | caching rules: 50 | 51 | 1. Add the package as a dependency: 52 | 53 | ```shell 54 | npm install -D gatsby-plugin-netlify 55 | ``` 56 | 57 | 2. Then add the following to your `gatsby-config.js` file: 58 | 59 | ```js 60 | module.exports = { 61 | plugins: ['gatsby-plugin-netlify'], 62 | } 63 | ``` 64 | 65 | See 66 | [the gatsby-plugin-netlify docs](https://github.com/netlify/gatsby-plugin-netlify/) 67 | for more information, including optional plugin configuration. 68 | 69 | ### Disabling Netlify functions 70 | 71 | In order to support Gatsby Functions and DSG and SSR render modes, this plugin 72 | generates four Netlify Functions called `__api`, `__ssr`, `__dsg` and `_ipx`. If 73 | you are not using any of these modes, then you can disable the creation of these 74 | functions. If you are using the latest version of `gatsby-plugin-netlify` then 75 | this will be handled automatically, disabling functions if the site has no 76 | Gatsby Functions, or DSG/SSR pages. Otherwise, you can do this manually by 77 | setting the environment variable `NETLIFY_SKIP_GATSBY_FUNCTIONS` to `true`. Be 78 | aware that if you do this, any DSG or SSR pages will not work, and nor will any 79 | Gatsby Functions or the remote image CDN. 80 | 81 | ### Gatsby Image CDN 82 | 83 | Gatsby includes beta support for deferred image resizing using a CDN. Netlify 84 | includes full support for Image CDN on all plans. For details on how to enable 85 | it, see 86 | [the image CDN docs](https://github.com/netlify/netlify-plugin-gatsby/blob/main/docs/image-cdn.md). 87 | 88 | ### Caveats 89 | 90 | Currently you cannot use `StaticImage` or `gatsby-transformer-sharp` in SSR or 91 | DSG pages. Support for Gatsby Image CDN is coming soon. The best workaround is 92 | to use an image CDN such as 93 | [Cloudinary](https://www.gatsbyjs.com/docs/how-to/images-and-media/using-cloudinary-image-service/) 94 | or [imgix](https://github.com/imgix/gatsby) to host your images. This will give 95 | you faster builds and rendering too. 96 | 97 | ### Local development 98 | 99 | When developing Gatsby Functions it is usually easier to use the built-in 100 | `gatsby develop` functions server. However if you want to try the Netlify 101 | functions wrapper it will run via `netlify dev`. You should be sure to run 102 | `netlify build` first, so that the wrappers are generated and the functions 103 | copied across. 104 | 105 | ## Netlify Background and Scheduled Functions 106 | 107 | In order to use [Netlify Background](https://docs.netlify.com/functions/background-functions/) or [Netlify Scheduled](https://docs.netlify.com/netlify-labs/experimental-features/scheduled-functions/) Functions in your Gatsby project, you will need to create a `netlify/functions` directory at the root of the project, and put the Functions in there. 108 | 109 | Once that's completed, the Background or Scheduled Function can be invoked like an ordinary Gatsby function. 110 | -------------------------------------------------------------------------------- /demo/content/posts/hello-world/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hello World 3 | date: '2015-05-01T22:12:03.284Z' 4 | description: 'Hello World' 5 | --- 6 | 7 | This is my first post on my new fake blog! How exciting! 8 | 9 | I'm sure I'll write a lot more interesting things in the future. 10 | 11 | Oh, and here's a great quote from this Wikipedia on 12 | [salted duck eggs](https://en.wikipedia.org/wiki/Salted_duck_egg). 13 | 14 | > A salted duck egg is a Chinese preserved food product made by soaking duck 15 | > eggs in brine, or packing each egg in damp, salted charcoal. In Asian 16 | > supermarkets, these eggs are sometimes sold covered in a thick layer of salted 17 | > charcoal paste. The eggs may also be sold with the salted paste removed, 18 | > wrapped in plastic, and vacuum packed. From the salt curing process, the 19 | > salted duck eggs have a briny aroma, a gelatin-like egg white and a 20 | > firm-textured, round yolk that is bright orange-red in color. 21 | 22 | ![Chinese Salty Egg](./salty_egg.jpg) 23 | 24 | You can also write code blocks here! 25 | 26 | ```js 27 | const saltyDuckEgg = 'chinese preserved food product' 28 | ``` 29 | 30 | | Number | Title | Year | 31 | | :----- | :--------------------------------------- | ---: | 32 | | 1 | Harry Potter and the Philosopher’s Stone | 2001 | 33 | | 2 | Harry Potter and the Chamber of Secrets | 2002 | 34 | | 3 | Harry Potter and the Prisoner of Azkaban | 2004 | 35 | 36 | [View raw (TEST.md)](https://raw.github.com/adamschwartz/github-markdown-kitchen-sink/master/README.md) 37 | 38 | This is a paragraph. 39 | 40 | This is a paragraph. 41 | 42 | # Header 1 43 | 44 | ## Header 2 45 | 46 | Header 1 47 | ======== 48 | 49 | Header 2 50 | -------- 51 | 52 | # Header 1 53 | 54 | ## Header 2 55 | 56 | ### Header 3 57 | 58 | #### Header 4 59 | 60 | ##### Header 5 61 | 62 | ###### Header 6 63 | 64 | # Header 1 65 | ## Header 2 66 | ### Header 3 67 | #### Header 4 68 | ##### Header 5 69 | ###### Header 6 70 | 71 | # Header 1 72 | 73 | ## Header 2 74 | 75 | ### Header 3 76 | 77 | #### Header 4 78 | 79 | ##### Header 5 80 | 81 | ###### Header 6 82 | 83 | # Header 1 # 84 | ## Header 2 ## 85 | ### Header 3 ### 86 | #### Header 4 #### 87 | ##### Header 5 ##### 88 | ###### Header 6 ###### 89 | 90 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi 91 | > posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet 92 | > vitae, risus. 93 | 94 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 95 | 96 | > ## This is a header. 97 | > 98 | > 1. This is the first list item. 99 | > 2. This is the second list item. 100 | > 101 | > Here's some example code: 102 | > 103 | > Markdown.generate(); 104 | 105 | > ## This is a header. 106 | > 1. This is the first list item. 107 | > 2. This is the second list item. 108 | > 109 | > Here's some example code: 110 | > 111 | > Markdown.generate(); 112 | 113 | - Red 114 | - Green 115 | - Blue 116 | 117 | * Red 118 | * Green 119 | * Blue 120 | 121 | - Red 122 | - Green 123 | - Blue 124 | 125 | ```markdown 126 | - Red 127 | - Green 128 | - Blue 129 | 130 | * Red 131 | * Green 132 | * Blue 133 | 134 | - Red 135 | - Green 136 | - Blue 137 | ``` 138 | 139 | - `code goes` here in this line 140 | - **bold** goes here 141 | 142 | ```markdown 143 | - `code goes` here in this line 144 | - **bold** goes here 145 | ``` 146 | 147 | 1. Buy flour and salt 148 | 1. Mix together with water 149 | 1. Bake 150 | 151 | ```markdown 152 | 1. Buy flour and salt 153 | 1. Mix together with water 154 | 1. Bake 155 | ``` 156 | 157 | 1. `code goes` here in this line 158 | 1. **bold** goes here 159 | 160 | ```markdown 161 | 1. `code goes` here in this line 162 | 1. **bold** goes here 163 | ``` 164 | 165 | Paragraph: 166 | 167 | Code 168 | 169 | 170 | 171 | Paragraph: 172 | 173 | Code 174 | 175 | --- 176 | 177 | --- 178 | 179 | --- 180 | 181 | --- 182 | 183 | --- 184 | 185 | * * * 186 | 187 | *** 188 | 189 | ***** 190 | 191 | - - - 192 | 193 | --------------------------------------- 194 | 195 | This is [an example](http://example.com 'Example') link. 196 | 197 | [This link](http://example.com) has no title attr. 198 | 199 | This is [an example][id] reference-style link. 200 | 201 | [id]: http://example.com 'Optional Title' 202 | 203 | This is [an example](http://example.com "Example") link. 204 | 205 | [This link](http://example.com) has no title attr. 206 | 207 | This is [an example] [id] reference-style link. 208 | 209 | [id]: http://example.com "Optional Title" 210 | 211 | _single asterisks_ 212 | 213 | _single underscores_ 214 | 215 | **double asterisks** 216 | 217 | **double underscores** 218 | 219 | *single asterisks* 220 | 221 | _single underscores_ 222 | 223 | **double asterisks** 224 | 225 | __double underscores__ 226 | 227 | This paragraph has some `code` in it. 228 | 229 | This paragraph has some `code` in it. 230 | 231 | ![Alt Text](https://placehold.it/200x50 'Image Title') 232 | 233 | ![Alt Text](https://placehold.it/200x50 "Image Title") 234 | --------------------------------------------------------------------------------