From 75f63f40ebd6528012ac34471f5ad6d7528c1204 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 27 Mar 2020 22:13:29 -0500 Subject: [PATCH 01/10] Add optimize-hook-destructing package --- .../.babelrc | 5 ++ .../.gitignore | 1 + .../.npmignore | 34 ++++++++++ .../CHANGELOG.md | 6 ++ .../package.json | 32 +++++++++ .../src/__tests__/index.js | 42 ++++++++++++ .../src/index.ts | 67 +++++++++++++++++++ .../tsconfig.json | 3 + 8 files changed, 190 insertions(+) create mode 100644 packages/babel-plugin-optimize-hook-destructuring/.babelrc create mode 100644 packages/babel-plugin-optimize-hook-destructuring/.gitignore create mode 100644 packages/babel-plugin-optimize-hook-destructuring/.npmignore create mode 100644 packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md create mode 100644 packages/babel-plugin-optimize-hook-destructuring/package.json create mode 100644 packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js create mode 100644 packages/babel-plugin-optimize-hook-destructuring/src/index.ts create mode 100644 packages/babel-plugin-optimize-hook-destructuring/tsconfig.json diff --git a/packages/babel-plugin-optimize-hook-destructuring/.babelrc b/packages/babel-plugin-optimize-hook-destructuring/.babelrc new file mode 100644 index 0000000000000..9f5de61e0d79e --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + ["babel-preset-gatsby-package"] + ] +} diff --git a/packages/babel-plugin-optimize-hook-destructuring/.gitignore b/packages/babel-plugin-optimize-hook-destructuring/.gitignore new file mode 100644 index 0000000000000..8ee01d321b721 --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/.gitignore @@ -0,0 +1 @@ +yarn.lock diff --git a/packages/babel-plugin-optimize-hook-destructuring/.npmignore b/packages/babel-plugin-optimize-hook-destructuring/.npmignore new file mode 100644 index 0000000000000..e771d2c9fa299 --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/.npmignore @@ -0,0 +1,34 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules +*.un~ +yarn.lock +src +flow-typed +coverage +decls +examples diff --git a/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md b/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md new file mode 100644 index 0000000000000..c22c8ce2e774a --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md @@ -0,0 +1,6 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +**Note:** Version bump only for package babel-plugin-optimize-hook-destructuring diff --git a/packages/babel-plugin-optimize-hook-destructuring/package.json b/packages/babel-plugin-optimize-hook-destructuring/package.json new file mode 100644 index 0000000000000..33de7cf1afac1 --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/package.json @@ -0,0 +1,32 @@ +{ + "name": "babel-plugin-optimize-hook-destructuring", + "version": "1.0.0", + "author": [ + "Blaine Kasten ", + "Jason Miller <>" + ], + "repository": { + "type": "git", + "url": "https://github.com/gatsbyjs/gatsby.git", + "directory": "packages/babel-plugin-optimize-hook-destructuring" + }, + "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-plugin-optimize-hook-destructuring", + "devDependencies": { + "@babel/core": "^7.8.7", + "babel-preset-gatsby-package": "^0.3.1" + }, + "license": "MIT", + "main": "dist/index.js", + "peerDependencies": { + "gatsby": "^2.0.0", + "graphql": "^14.1.1" + }, + "scripts": { + "build": "babel src --out-dir dist --ignore **/__tests__", + "prepare": "cross-env NODE_ENV=production npm run build", + "watch": "babel -w src --out-dir dist --ignore **/__tests__" + }, + "engines": { + "node": ">=10.13.0" + } +} diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js new file mode 100644 index 0000000000000..3dc3797b3acde --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js @@ -0,0 +1,42 @@ +import { transform } from "@babel/core" +import preset from "babel-preset-gatsby-package" + +const trim = s => + s + .join(`\n`) + .trim() + .replace(/^\s+/gm, ``) + +const babel = (code, esm = false) => + transform(code, { + filename: `noop.js`, + presets: [preset], + babelrc: false, + configFile: false, + sourceType: `module`, + compact: true, + caller: { + name: `tests`, + supportsStaticESM: esm, + }, + }).code + +describe(`optimize-hook-destructuring`, () => { + it(`should transform Array-destructured hook return values use object destructuring`, () => { + const output = babel( + trim` + import { useState } from 'react'; + const [count, setCount] = useState(0); + `, + true + ) + + expect(output).toMatch(trim` + var _useState=useState(0),count=_useState[0],setCount=_useState[1]; + `) + + expect(output).toMatchInlineSnapshot( + `"import{useState}from'react';var _useState=useState(0),count=_useState[0],setCount=_useState[1];"` + ) + }) +}) diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/index.ts b/packages/babel-plugin-optimize-hook-destructuring/src/index.ts new file mode 100644 index 0000000000000..13359a8dbefdc --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/src/index.ts @@ -0,0 +1,67 @@ +import { PluginObj } from "@babel/core" +import { NodePath } from "@babel/traverse" +import * as BabelTypes from "@babel/types" + +// matches any hook-like (the default) +const isHook = /^use[A-Z]/ + +// matches only built-in hooks provided by React et al +const isBuiltInHook = /^use(Callback|Context|DebugValue|Effect|ImperativeHandle|LayoutEffect|Memo|Reducer|Ref|State)$/ + +export default function({ + types: t, +}: { + types: typeof BabelTypes +}): PluginObj { + const visitor = { + CallExpression(path: NodePath, state: any) { + const onlyBuiltIns = state.opts.onlyBuiltIns + + // if specified, options.lib is a list of libraries that provide hook functions + const libs = + state.opts.lib && + (state.opts.lib === true + ? ["react", "preact/hooks"] + : [].concat(state.opts.lib)) + + // skip function calls that are not the init of a variable declaration: + if (!t.isVariableDeclarator(path.parent)) return + + // skip function calls where the return value is not Array-destructured: + if (!t.isArrayPattern(path.parent.id)) return + + // name of the (hook) function being called: + const hookName = (path.node.callee as BabelTypes.Identifier).name + + if (libs) { + const binding = path.scope.getBinding(hookName) + // not an import + if (!binding || binding.kind !== "module") return + + const specifier = (binding.path.parent as BabelTypes.ImportDeclaration) + .source.value + // not a match + if (!libs.some(lib => lib === specifier)) return + } + + // only match function calls with names that look like a hook + if (!(onlyBuiltIns ? isBuiltInHook : isHook).test(hookName)) return + + path.parent.id = t.objectPattern( + path.parent.id.elements.map((element, i) => + t.objectProperty(t.numericLiteral(i), element) + ) + ) + }, + } + + return { + name: "optimize-hook-destructuring", + visitor: { + // this is a workaround to run before preset-env destroys destructured assignments + Program(path, state) { + path.traverse(visitor, state) + }, + }, + } +} diff --git a/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json b/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json new file mode 100644 index 0000000000000..4082f16a5d91c --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} From 50d312ecffcb4d7ed43404d7a3f03ee479bc221e Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 27 Mar 2020 22:30:36 -0500 Subject: [PATCH 02/10] feat(gatsby): Optimize hook destructuring to improve performance --- .../README.md | 15 +++++++++++++++ .../src/__tests__/index.js | 6 ++++-- packages/babel-preset-gatsby/README.md | 1 + packages/babel-preset-gatsby/src/index.js | 1 + packages/gatsby-dev-cli/src/__tests__/watch.js | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-optimize-hook-destructuring/README.md diff --git a/packages/babel-plugin-optimize-hook-destructuring/README.md b/packages/babel-plugin-optimize-hook-destructuring/README.md new file mode 100644 index 0000000000000..3c7e431269d44 --- /dev/null +++ b/packages/babel-plugin-optimize-hook-destructuring/README.md @@ -0,0 +1,15 @@ +# babel-plugin-optimize-hook-destructuring + +Thanks to the wonderful [Jason Miller](@developit) for sharing with us the V8 teams research into array destructuring and for writing this code for the next.js project. + +This plugin does the following: + +```js +// in +const [state, setState] = useState() + +// out +const { 0: state, 1: setState } = useState() +``` + +The V8 team found that this destructure operation is faster for browser engines. diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js index 3dc3797b3acde..286e0425ba83b 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js +++ b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js @@ -1,5 +1,6 @@ import { transform } from "@babel/core" import preset from "babel-preset-gatsby-package" +import plugin from "../" const trim = s => s @@ -11,6 +12,7 @@ const babel = (code, esm = false) => transform(code, { filename: `noop.js`, presets: [preset], + plugins: [plugin], babelrc: false, configFile: false, sourceType: `module`, @@ -32,11 +34,11 @@ describe(`optimize-hook-destructuring`, () => { ) expect(output).toMatch(trim` - var _useState=useState(0),count=_useState[0],setCount=_useState[1]; + \"use strict\";var _react=require(\"react\");const{0:count,1:setCount}=(0,_react.useState)(0); `) expect(output).toMatchInlineSnapshot( - `"import{useState}from'react';var _useState=useState(0),count=_useState[0],setCount=_useState[1];"` + `"\\"use strict\\";var _react=require(\\"react\\");const{0:count,1:setCount}=(0,_react.useState)(0);"` ) }) }) diff --git a/packages/babel-preset-gatsby/README.md b/packages/babel-preset-gatsby/README.md index 7de679dfb9f64..e5f47e8d417c2 100644 --- a/packages/babel-preset-gatsby/README.md +++ b/packages/babel-preset-gatsby/README.md @@ -15,6 +15,7 @@ For more information on how to customize the Babel configuration of your Gatsby - [`babel-plugin-transform-react-remove-prop-types`](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) - [`@babel/plugin-proposal-nullish-coalescing-operator`](https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator) - [`@babel/plugin-proposal-optional-chaining`](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining) +- [`babel-plugin-optimize-hook-destructuring`](https://www.github.com/gatsbyjs/gatsby/packages/babel-plugin-optimize-hook-destructring) ## Usage diff --git a/packages/babel-preset-gatsby/src/index.js b/packages/babel-preset-gatsby/src/index.js index 578a8b7847ac6..a2f7d9c305351 100644 --- a/packages/babel-preset-gatsby/src/index.js +++ b/packages/babel-preset-gatsby/src/index.js @@ -70,6 +70,7 @@ module.exports = function preset(_, options = {}) { ], ], plugins: [ + resolve(`babel-plugin-optimize-hook-destructuring`), [ resolve(`@babel/plugin-proposal-class-properties`), { diff --git a/packages/gatsby-dev-cli/src/__tests__/watch.js b/packages/gatsby-dev-cli/src/__tests__/watch.js index 68326929526c1..f991be64add81 100644 --- a/packages/gatsby-dev-cli/src/__tests__/watch.js +++ b/packages/gatsby-dev-cli/src/__tests__/watch.js @@ -183,6 +183,7 @@ describe(`watching`, () => { }) const monoRepoPackages = [ + `babel-plugin-optimize-hook-destructuring`, `babel-plugin-remove-graphql-queries`, `babel-preset-gatsby`, `babel-preset-gatsby-package`, From eadc916d96001b245a3d4e9bec5eb9a1056e3f71 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Sat, 28 Mar 2020 21:29:47 -0500 Subject: [PATCH 03/10] fix lint --- .../src/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/index.ts b/packages/babel-plugin-optimize-hook-destructuring/src/index.ts index 13359a8dbefdc..feb492bb51fa1 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/src/index.ts +++ b/packages/babel-plugin-optimize-hook-destructuring/src/index.ts @@ -14,14 +14,17 @@ export default function({ types: typeof BabelTypes }): PluginObj { const visitor = { - CallExpression(path: NodePath, state: any) { + CallExpression( + path: NodePath, + state: any + ): void { const onlyBuiltIns = state.opts.onlyBuiltIns // if specified, options.lib is a list of libraries that provide hook functions const libs = state.opts.lib && (state.opts.lib === true - ? ["react", "preact/hooks"] + ? [`react`, `preact/hooks`] : [].concat(state.opts.lib)) // skip function calls that are not the init of a variable declaration: @@ -36,7 +39,7 @@ export default function({ if (libs) { const binding = path.scope.getBinding(hookName) // not an import - if (!binding || binding.kind !== "module") return + if (!binding || binding.kind !== `module`) return const specifier = (binding.path.parent as BabelTypes.ImportDeclaration) .source.value @@ -56,10 +59,10 @@ export default function({ } return { - name: "optimize-hook-destructuring", + name: `optimize-hook-destructuring`, visitor: { // this is a workaround to run before preset-env destroys destructured assignments - Program(path, state) { + Program(path: NodePath, state: any): void { path.traverse(visitor, state) }, }, From bd77192596ac6cdb410d5d7451aeb0f973c6fc7e Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Mon, 30 Mar 2020 10:00:36 -0500 Subject: [PATCH 04/10] fix builds and clean up tests --- .../babel-plugin-optimize-hook-destructuring/.babelrc | 8 ++++++-- .../package.json | 4 ++-- .../src/__tests__/index.js | 9 ++++----- packages/babel-preset-gatsby/package.json | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/babel-plugin-optimize-hook-destructuring/.babelrc b/packages/babel-plugin-optimize-hook-destructuring/.babelrc index 9f5de61e0d79e..997f827fa80a7 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/.babelrc +++ b/packages/babel-plugin-optimize-hook-destructuring/.babelrc @@ -1,5 +1,9 @@ { - "presets": [ - ["babel-preset-gatsby-package"] + "presets": [["babel-preset-gatsby-package"]], + "overrides": [ + { + "test": "**/*.ts", + "plugins": [["@babel/plugin-transform-typescript", { "isTSX": true }]] + } ] } diff --git a/packages/babel-plugin-optimize-hook-destructuring/package.json b/packages/babel-plugin-optimize-hook-destructuring/package.json index 33de7cf1afac1..51207e3137df1 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/package.json +++ b/packages/babel-plugin-optimize-hook-destructuring/package.json @@ -22,9 +22,9 @@ "graphql": "^14.1.1" }, "scripts": { - "build": "babel src --out-dir dist --ignore **/__tests__", + "build": "babel src --out-dir dist --ignore **/__tests__ --extensions \".ts\"", "prepare": "cross-env NODE_ENV=production npm run build", - "watch": "babel -w src --out-dir dist --ignore **/__tests__" + "watch": "babel -w src --out-dir dist --ignore **/__tests__ --extensions \".ts\"" }, "engines": { "node": ">=10.13.0" diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js index 286e0425ba83b..9cf77d6616933 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js +++ b/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js @@ -1,5 +1,5 @@ import { transform } from "@babel/core" -import preset from "babel-preset-gatsby-package" +import preset from "babel-preset-gatsby" import plugin from "../" const trim = s => @@ -8,7 +8,7 @@ const trim = s => .trim() .replace(/^\s+/gm, ``) -const babel = (code, esm = false) => +const babel = code => transform(code, { filename: `noop.js`, presets: [preset], @@ -19,7 +19,7 @@ const babel = (code, esm = false) => compact: true, caller: { name: `tests`, - supportsStaticESM: esm, + supportsStaticESM: true, }, }).code @@ -29,8 +29,7 @@ describe(`optimize-hook-destructuring`, () => { trim` import { useState } from 'react'; const [count, setCount] = useState(0); - `, - true + ` ) expect(output).toMatch(trim` diff --git a/packages/babel-preset-gatsby/package.json b/packages/babel-preset-gatsby/package.json index 95602e07017fa..46383ea0ff5dd 100644 --- a/packages/babel-preset-gatsby/package.json +++ b/packages/babel-preset-gatsby/package.json @@ -20,6 +20,7 @@ "@babel/runtime": "^7.8.7", "babel-plugin-dynamic-import-node": "^2.3.0", "babel-plugin-macros": "^2.8.0", + "babel-plugin-optimize-hook-destructuring": "^1.0.0", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", "gatsby-core-utils": "^1.1.1" }, From 4c65bbe741e6efdadf096dc099507633cd49df34 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Fri, 10 Apr 2020 08:23:58 -0500 Subject: [PATCH 05/10] Undo specific package --- .../.babelrc | 9 ----- .../.gitignore | 1 - .../.npmignore | 34 ------------------- .../CHANGELOG.md | 6 ---- .../README.md | 15 -------- .../package.json | 32 ----------------- .../tsconfig.json | 3 -- packages/babel-preset-gatsby/.babelrc | 9 +++-- packages/babel-preset-gatsby/package.json | 1 - .../__tests__/optimize-hook-destructuring.js} | 2 +- packages/babel-preset-gatsby/src/index.js | 7 +++- .../src/optimize-hook-destructuring.ts} | 0 12 files changed, 13 insertions(+), 106 deletions(-) delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/.babelrc delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/.gitignore delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/.npmignore delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/README.md delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/package.json delete mode 100644 packages/babel-plugin-optimize-hook-destructuring/tsconfig.json rename packages/{babel-plugin-optimize-hook-destructuring/src/__tests__/index.js => babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js} (95%) rename packages/{babel-plugin-optimize-hook-destructuring/src/index.ts => babel-preset-gatsby/src/optimize-hook-destructuring.ts} (100%) diff --git a/packages/babel-plugin-optimize-hook-destructuring/.babelrc b/packages/babel-plugin-optimize-hook-destructuring/.babelrc deleted file mode 100644 index 997f827fa80a7..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/.babelrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "presets": [["babel-preset-gatsby-package"]], - "overrides": [ - { - "test": "**/*.ts", - "plugins": [["@babel/plugin-transform-typescript", { "isTSX": true }]] - } - ] -} diff --git a/packages/babel-plugin-optimize-hook-destructuring/.gitignore b/packages/babel-plugin-optimize-hook-destructuring/.gitignore deleted file mode 100644 index 8ee01d321b721..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/.gitignore +++ /dev/null @@ -1 +0,0 @@ -yarn.lock diff --git a/packages/babel-plugin-optimize-hook-destructuring/.npmignore b/packages/babel-plugin-optimize-hook-destructuring/.npmignore deleted file mode 100644 index e771d2c9fa299..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/.npmignore +++ /dev/null @@ -1,34 +0,0 @@ -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules -*.un~ -yarn.lock -src -flow-typed -coverage -decls -examples diff --git a/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md b/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md deleted file mode 100644 index c22c8ce2e774a..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/CHANGELOG.md +++ /dev/null @@ -1,6 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -**Note:** Version bump only for package babel-plugin-optimize-hook-destructuring diff --git a/packages/babel-plugin-optimize-hook-destructuring/README.md b/packages/babel-plugin-optimize-hook-destructuring/README.md deleted file mode 100644 index 3c7e431269d44..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# babel-plugin-optimize-hook-destructuring - -Thanks to the wonderful [Jason Miller](@developit) for sharing with us the V8 teams research into array destructuring and for writing this code for the next.js project. - -This plugin does the following: - -```js -// in -const [state, setState] = useState() - -// out -const { 0: state, 1: setState } = useState() -``` - -The V8 team found that this destructure operation is faster for browser engines. diff --git a/packages/babel-plugin-optimize-hook-destructuring/package.json b/packages/babel-plugin-optimize-hook-destructuring/package.json deleted file mode 100644 index 51207e3137df1..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "babel-plugin-optimize-hook-destructuring", - "version": "1.0.0", - "author": [ - "Blaine Kasten ", - "Jason Miller <>" - ], - "repository": { - "type": "git", - "url": "https://github.com/gatsbyjs/gatsby.git", - "directory": "packages/babel-plugin-optimize-hook-destructuring" - }, - "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-plugin-optimize-hook-destructuring", - "devDependencies": { - "@babel/core": "^7.8.7", - "babel-preset-gatsby-package": "^0.3.1" - }, - "license": "MIT", - "main": "dist/index.js", - "peerDependencies": { - "gatsby": "^2.0.0", - "graphql": "^14.1.1" - }, - "scripts": { - "build": "babel src --out-dir dist --ignore **/__tests__ --extensions \".ts\"", - "prepare": "cross-env NODE_ENV=production npm run build", - "watch": "babel -w src --out-dir dist --ignore **/__tests__ --extensions \".ts\"" - }, - "engines": { - "node": ">=10.13.0" - } -} diff --git a/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json b/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json deleted file mode 100644 index 4082f16a5d91c..0000000000000 --- a/packages/babel-plugin-optimize-hook-destructuring/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.json" -} diff --git a/packages/babel-preset-gatsby/.babelrc b/packages/babel-preset-gatsby/.babelrc index 837b17615376b..841d89afa9a35 100644 --- a/packages/babel-preset-gatsby/.babelrc +++ b/packages/babel-preset-gatsby/.babelrc @@ -1,6 +1,9 @@ { - "presets": [ - ["babel-preset-gatsby-package"] + "presets": [["babel-preset-gatsby-package"]], + "overrides": [ + { + "test": ["**/*.ts", "**/*.tsx"], + "plugins": [["@babel/plugin-transform-typescript", { "isTSX": true }]] + } ] } - diff --git a/packages/babel-preset-gatsby/package.json b/packages/babel-preset-gatsby/package.json index 46383ea0ff5dd..95602e07017fa 100644 --- a/packages/babel-preset-gatsby/package.json +++ b/packages/babel-preset-gatsby/package.json @@ -20,7 +20,6 @@ "@babel/runtime": "^7.8.7", "babel-plugin-dynamic-import-node": "^2.3.0", "babel-plugin-macros": "^2.8.0", - "babel-plugin-optimize-hook-destructuring": "^1.0.0", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", "gatsby-core-utils": "^1.1.1" }, diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js similarity index 95% rename from packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js rename to packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js index 9cf77d6616933..45878bd5381c4 100644 --- a/packages/babel-plugin-optimize-hook-destructuring/src/__tests__/index.js +++ b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js @@ -1,6 +1,6 @@ import { transform } from "@babel/core" import preset from "babel-preset-gatsby" -import plugin from "../" +import plugin from "../optimize-hook-destructuring" const trim = s => s diff --git a/packages/babel-preset-gatsby/src/index.js b/packages/babel-preset-gatsby/src/index.js index a2f7d9c305351..fa92e82efa7e7 100644 --- a/packages/babel-preset-gatsby/src/index.js +++ b/packages/babel-preset-gatsby/src/index.js @@ -70,7 +70,12 @@ module.exports = function preset(_, options = {}) { ], ], plugins: [ - resolve(`babel-plugin-optimize-hook-destructuring`), + [ + resolve(`./optimize-hook-destructuring`), + { + lib: true, + }, + ], [ resolve(`@babel/plugin-proposal-class-properties`), { diff --git a/packages/babel-plugin-optimize-hook-destructuring/src/index.ts b/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts similarity index 100% rename from packages/babel-plugin-optimize-hook-destructuring/src/index.ts rename to packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts From d50d511849757ffed58cc875df1d17cd64b7ad33 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Wed, 15 Apr 2020 22:08:14 -0500 Subject: [PATCH 06/10] update test --- .../src/__tests__/__snapshots__/index.js.snap | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap index bf872b28d82e9..13accfb93ac9e 100644 --- a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap +++ b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap @@ -3,6 +3,12 @@ exports[`babel-preset-gatsby should specify proper presets and plugins when stage is build-html 1`] = ` Object { "plugins": Array [ + Array [ + "/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts", + Object { + "lib": true, + }, + ], Array [ "/node_modules/@babel/plugin-proposal-class-properties/lib/index.js", Object { @@ -66,6 +72,12 @@ Object { exports[`babel-preset-gatsby should specify proper presets and plugins when stage is build-javascript 1`] = ` Object { "plugins": Array [ + Array [ + "/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts", + Object { + "lib": true, + }, + ], Array [ "/node_modules/@babel/plugin-proposal-class-properties/lib/index.js", Object { @@ -133,6 +145,12 @@ Object { exports[`babel-preset-gatsby should specify proper presets and plugins when stage is build-stage 1`] = ` Object { "plugins": Array [ + Array [ + "/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts", + Object { + "lib": true, + }, + ], Array [ "/node_modules/@babel/plugin-proposal-class-properties/lib/index.js", Object { @@ -194,6 +212,12 @@ Object { exports[`babel-preset-gatsby should specify proper presets and plugins when stage is develop 1`] = ` Object { "plugins": Array [ + Array [ + "/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts", + Object { + "lib": true, + }, + ], Array [ "/node_modules/@babel/plugin-proposal-class-properties/lib/index.js", Object { From 08f14872b254ae0bcc56b9ade3c0b7ad334a00c8 Mon Sep 17 00:00:00 2001 From: Blaine Kasten Date: Wed, 15 Apr 2020 22:19:06 -0500 Subject: [PATCH 07/10] yarn lint:code --- .../src/__tests__/index.js | 2 +- .../src/index.js | 39 +- .../__tests__/optimize-hook-destructuring.js | 6 +- .../babel-preset-gatsby/src/dependencies.js | 16 +- .../src/optimize-hook-destructuring.ts | 2 +- .../src/reporter/__tests__/index.js | 12 +- .../src/transforms/global-graphql-calls.js | 21 +- .../src/utils/check-deps-changes.js | 18 +- .../gatsby-graphiql-explorer/src/app/app.js | 20 +- packages/gatsby-image/src/index.js | 44 +- .../gatsby-image/src/withIEPolyfill/index.js | 10 +- .../src/gatsby-node.js | 23 +- .../src/catch-links.js | 2 +- .../src/gatsby-node.js | 2 +- .../src/__tests__/gatsby-browser.js | 4 +- .../gatsby-plugin-fullstory/src/gatsby-ssr.js | 4 +- .../src/index.js | 10 +- .../gatsby-plugin-google-gtag/src/index.js | 6 +- .../src/__tests__/gatsby-ssr.js | 40 +- .../src/__tests__/gatsby-node.js | 96 ++-- packages/gatsby-plugin-manifest/src/common.js | 20 +- .../src/gatsby-browser.js | 2 +- .../gatsby-plugin-mdx/gatsby/source-nodes.js | 49 +- .../loaders/mdx-components.js | 2 +- .../gatsby-plugin-mdx/loaders/mdx-loader.js | 16 +- .../gatsby-plugin-mdx/loaders/mdx-scopes.js | 2 +- .../gatsby-plugin-mdx/loaders/mdx-wrappers.js | 2 +- .../babel-plugin-html-attr-to-jsx-attr.js | 16 +- packages/gatsby-plugin-mdx/utils/gen-mdx.js | 16 +- .../gatsby-plugin-mdx/utils/render-html.js | 8 +- .../src/gatsby-node.js | 80 ++-- .../gatsby-plugin-sharp/src/gatsby-worker.js | 4 +- .../src/__tests__/internals.js | 52 +-- .../gatsby-plugin-sitemap/src/internals.js | 12 +- .../src/gatsby-ssr.js | 8 +- .../src/__tests__/index.js | 55 +-- .../src/index.js | 8 +- .../src/__tests__/index.js | 16 +- .../gatsby-remark-embed-snippet/src/index.js | 2 +- .../src/index.js | 12 +- packages/gatsby-remark-images/src/index.js | 21 +- .../gatsby-remark-prismjs/src/directives.js | 11 +- packages/gatsby-remark-prismjs/src/index.js | 11 +- .../src/plugins/prism-show-invisibles.js | 8 +- .../src/__tests__/index.js | 14 +- .../src/index.js | 7 +- .../gatsby-remark-smartypants/src/index.js | 4 +- .../src/extend-node-type.js | 140 +++--- .../gatsby-source-contentful/src/normalize.js | 54 +-- .../src/plugin-options.js | 22 +- packages/gatsby-source-drupal/src/utils.js | 6 +- .../src/__tests__/gatsby-node.js | 24 +- .../src/batching/__tests__/dataloader-link.js | 22 +- .../src/batching/__tests__/merge-queries.js | 46 +- .../src/batching/dataloader-link.js | 6 +- .../src/batching/merge-queries.js | 56 +-- .../gatsby-source-graphql/src/gatsby-node.js | 24 +- .../gatsby-source-graphql/src/transforms.js | 12 +- packages/gatsby-source-mongodb/src/mapping.js | 6 +- packages/gatsby-source-wordpress/src/fetch.js | 64 +-- .../gatsby-source-wordpress/src/normalize.js | 42 +- .../src/__tests__/repository-id.js | 17 +- packages/gatsby-telemetry/src/index.js | 2 +- .../gatsby-telemetry/src/repository-id.js | 11 +- .../src/components/post-date.js | 2 +- .../src/components/post-link.js | 4 +- .../gatsby-theme-blog/src/components/post.js | 6 +- .../gatsby-theme-blog/src/components/seo.js | 26 +- .../src/gatsby-node.js | 47 +- .../src/extend-node-type.js | 97 ++-- .../cache-dir/__tests__/minimal-config.js | 8 +- packages/gatsby/cache-dir/prefetch.js | 8 +- .../cache-dir/register-service-worker.js | 4 +- .../__tests__/create-graphql-runner.js | 22 +- .../bootstrap/__tests__/requires-writer.js | 92 ++-- .../__tests__/resolve-module-exports.js | 14 +- packages/gatsby/src/bootstrap/index.js | 88 ++-- .../gatsby/src/bootstrap/load-themes/index.js | 10 +- .../gatsby/src/bootstrap/log-line-function.js | 4 +- .../gatsby/src/bootstrap/requires-writer.js | 12 +- packages/gatsby/src/db/loki/nodes.js | 9 +- .../create-page.js | 8 +- .../src/query/better-queue-custom-store.js | 20 +- packages/gatsby/src/query/file-parser.js | 103 ++--- packages/gatsby/src/redux/__tests__/index.js | 22 +- .../gatsby/src/redux/__tests__/run-sift.js | 150 +++--- packages/gatsby/src/redux/actions/public.js | 131 +++--- packages/gatsby/src/redux/reducers/index.js | 2 +- packages/gatsby/src/redux/run-sift.js | 20 +- .../gatsby/src/schema/__tests__/node-model.js | 194 ++++---- .../gatsby/src/schema/__tests__/queries.js | 432 +++++++++--------- .../gatsby/src/schema/__tests__/run-query.js | 368 +++++++-------- .../src/schema/infer/add-inferred-fields.js | 53 +-- .../schema/infer/type-conflict-reporter.js | 14 +- packages/gatsby/src/schema/node-model.js | 24 +- packages/gatsby/src/schema/resolvers.js | 24 +- ...ch-router-add-basecontext-export-loader.js | 2 +- packages/gatsby/src/utils/webpack.config.js | 92 ++-- plopfile.js | 48 +- scripts/check-ts.js | 4 +- scripts/i18n/sync.js | 28 +- 101 files changed, 1764 insertions(+), 1817 deletions(-) diff --git a/packages/babel-plugin-remove-graphql-queries/src/__tests__/index.js b/packages/babel-plugin-remove-graphql-queries/src/__tests__/index.js index 5108d5f38fdf9..8402701319dac 100644 --- a/packages/babel-plugin-remove-graphql-queries/src/__tests__/index.js +++ b/packages/babel-plugin-remove-graphql-queries/src/__tests__/index.js @@ -4,7 +4,7 @@ const plugin = require(`../`) function matchesSnapshot(query) { const { code } = babel.transform(query, { presets: [`@babel/preset-react`], - plugins: [plugin] + plugins: [plugin], }) expect(code).toMatchSnapshot() } diff --git a/packages/babel-plugin-remove-graphql-queries/src/index.js b/packages/babel-plugin-remove-graphql-queries/src/index.js index d57bdfb23750f..ab96e3516cd5a 100644 --- a/packages/babel-plugin-remove-graphql-queries/src/index.js +++ b/packages/babel-plugin-remove-graphql-queries/src/index.js @@ -159,16 +159,13 @@ function isUseStaticQuery(path) { return ( (path.node.callee.type === `MemberExpression` && path.node.callee.property.name === `useStaticQuery` && - path - .get(`callee`) - .get(`object`) - .referencesImport(`gatsby`)) || + path.get(`callee`).get(`object`).referencesImport(`gatsby`)) || (path.node.callee.name === `useStaticQuery` && path.get(`callee`).referencesImport(`gatsby`)) ) } -export default function({ types: t }) { +export default function ({ types: t }) { return { visitor: { Program(path, state) { @@ -208,7 +205,7 @@ export default function({ types: t }) { ) path.unshiftContainer(`body`, importDeclaration) } - } + }, } const nestedHookVisitor = { @@ -260,7 +257,7 @@ export default function({ types: t }) { ) path.unshiftContainer(`body`, importDeclaration) } - } + }, } const tagsToRemoveImportsFrom = new Set() @@ -296,14 +293,14 @@ export default function({ types: t }) { // modify StaticQuery elements and import data only if query is inside StaticQuery parent.traverse(nestedJSXVistor, { queryHash, - query + query, }) // modify useStaticQuery elements and import data only if query is inside useStaticQuery parent.traverse(nestedHookVisitor, { queryHash, query, - templatePath + templatePath, }) return null @@ -340,17 +337,17 @@ export default function({ types: t }) { varPath.traverse({ TaggedTemplateExpression(templatePath) { setImportForStaticQuery(templatePath) - } + }, }) } - } + }, }) } - } + }, }) - } + }, }) - } + }, }) function followVariableDeclarations(binding) { @@ -389,16 +386,16 @@ export default function({ types: t }) { if (binding) { followVariableDeclarations(binding).path.traverse({ - TaggedTemplateExpression + TaggedTemplateExpression, }) } } hookPath.traverse({ // Assume the query is inline in the component and extract that. - TaggedTemplateExpression + TaggedTemplateExpression, }) - } + }, }) // Run it again to remove non-staticquery versions @@ -420,12 +417,12 @@ export default function({ types: t }) { // Replace the query with the hash of the query. path2.replaceWith(t.StringLiteral(queryHash)) return null - } + }, }) tagsToRemoveImportsFrom.forEach(removeImport) - } - } + }, + }, } } @@ -433,5 +430,5 @@ export { getGraphQLTag, StringInterpolationNotAllowedError, EmptyGraphQLTagError, - GraphQLSyntaxError + GraphQLSyntaxError, } diff --git a/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js index 45878bd5381c4..a28360cb5bc1b 100644 --- a/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js +++ b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js @@ -2,11 +2,7 @@ import { transform } from "@babel/core" import preset from "babel-preset-gatsby" import plugin from "../optimize-hook-destructuring" -const trim = s => - s - .join(`\n`) - .trim() - .replace(/^\s+/gm, ``) +const trim = s => s.join(`\n`).trim().replace(/^\s+/gm, ``) const babel = code => transform(code, { diff --git a/packages/babel-preset-gatsby/src/dependencies.js b/packages/babel-preset-gatsby/src/dependencies.js index fafa48515709f..b819e8dc9c5e4 100644 --- a/packages/babel-preset-gatsby/src/dependencies.js +++ b/packages/babel-preset-gatsby/src/dependencies.js @@ -4,7 +4,7 @@ const path = require(`path`) const resolve = m => require.resolve(m) -module.exports = function(api, options = {}) { +module.exports = function (api, options = {}) { const absoluteRuntimePath = path.dirname( resolve(`@babel/runtime/package.json`) ) @@ -25,9 +25,9 @@ module.exports = function(api, options = {}) { corejs: 2, modules: false, // Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) - exclude: [`transform-typeof-symbol`] - } - ] + exclude: [`transform-typeof-symbol`], + }, + ], ], plugins: [ // Polyfills the runtime needed for async/await, generators, and friends @@ -45,11 +45,11 @@ module.exports = function(api, options = {}) { // Undocumented option that lets us encapsulate our runtime, ensuring // the correct version is used // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42 - absoluteRuntime: absoluteRuntimePath - } + absoluteRuntime: absoluteRuntimePath, + }, ], // Adds syntax support for import() - resolve(`@babel/plugin-syntax-dynamic-import`) - ] + resolve(`@babel/plugin-syntax-dynamic-import`), + ], } } diff --git a/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts b/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts index feb492bb51fa1..9b6fe611363da 100644 --- a/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts +++ b/packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts @@ -8,7 +8,7 @@ const isHook = /^use[A-Z]/ // matches only built-in hooks provided by React et al const isBuiltInHook = /^use(Callback|Context|DebugValue|Effect|ImperativeHandle|LayoutEffect|Memo|Reducer|Ref|State)$/ -export default function({ +export default function ({ types: t, }: { types: typeof BabelTypes diff --git a/packages/gatsby-cli/src/reporter/__tests__/index.js b/packages/gatsby-cli/src/reporter/__tests__/index.js index 02fe93c189a01..51328b4966e4a 100644 --- a/packages/gatsby-cli/src/reporter/__tests__/index.js +++ b/packages/gatsby-cli/src/reporter/__tests__/index.js @@ -35,7 +35,7 @@ describe(`report.error`, () => { const generatedError = getErrorMessages(reporterActions.createLog)[0] expect(generatedError).toMatchSnapshot({ - stack: expect.any(Array) + stack: expect.any(Array), }) }) @@ -43,7 +43,7 @@ describe(`report.error`, () => { reporter.error(new Error(`Message from new Error`)) const generatedError = getErrorMessages(reporterActions.createLog)[0] expect(generatedError).toMatchSnapshot({ - stack: expect.any(Array) + stack: expect.any(Array), }) }) @@ -51,7 +51,7 @@ describe(`report.error`, () => { reporter.error([ new Error(`Message 1 from new Error`), new Error(`Message 2 from new Error`), - new Error(`Message 3 from new Error`) + new Error(`Message 3 from new Error`), ]) const generatedErrors = getErrorMessages(reporterActions.createLog) @@ -61,7 +61,7 @@ describe(`report.error`, () => { // get final generated object const generatedError = generatedErrors[2] expect(generatedError).toMatchSnapshot({ - stack: expect.any(Array) + stack: expect.any(Array), }) }) @@ -69,8 +69,8 @@ describe(`report.error`, () => { reporter.error({ id: `95312`, context: { - ref: `navigator` - } + ref: `navigator`, + }, }) const generatedError = getErrorMessages(reporterActions.createLog)[0] expect(generatedError).toMatchSnapshot() diff --git a/packages/gatsby-codemods/src/transforms/global-graphql-calls.js b/packages/gatsby-codemods/src/transforms/global-graphql-calls.js index b71674a60090c..be5dd74bf8323 100644 --- a/packages/gatsby-codemods/src/transforms/global-graphql-calls.js +++ b/packages/gatsby-codemods/src/transforms/global-graphql-calls.js @@ -4,12 +4,12 @@ const IMPORT_NAME = `graphql` function findGatsbyRequire(root, j) { const requires = root.find(j.VariableDeclarator, { init: { - callee: { name: `require` } - } + callee: { name: `require` }, + }, }) let string = requires.find(j.VariableDeclarator, { - init: { arguments: [{ value: MODULE_NAME }] } + init: { arguments: [{ value: MODULE_NAME }] }, }) if (string.length) return string @@ -22,7 +22,7 @@ function findGatsbyRequire(root, j) { function addEsmImport(j, root, tag) { let existingImport = root.find(j.ImportDeclaration, { - source: { value: `gatsby` } + source: { value: `gatsby` }, }) if ( @@ -39,10 +39,7 @@ function addEsmImport(j, root, tag) { j.literal(MODULE_NAME) ) importStatement.comments = comments - root - .find(j.Program) - .get(`body`, 0) - .insertBefore(importStatement) + root.find(j.Program).get(`body`, 0).insertBefore(importStatement) return } @@ -78,7 +75,7 @@ function addRequire(j, root, tag) { .get(`body`, 0) .insertBefore( j.template.statement([ - `const { ${IMPORT_NAME} } = require('${MODULE_NAME}');\n` + `const { ${IMPORT_NAME} } = require('${MODULE_NAME}');\n`, ]) ) return @@ -113,7 +110,7 @@ module.exports = (file, api, options) => { const root = j(file.source) const tags = root.find(j.TaggedTemplateExpression, { - tag: { name: `graphql` } + tag: { name: `graphql` }, }) if (!tags.length) return false @@ -124,8 +121,8 @@ module.exports = (file, api, options) => { root.find(j.ImportDeclaration, { importKind: `value` }).length > 0 || root.find(j.VariableDeclarator, { init: { - callee: { name: `require` } - } + callee: { name: `require` }, + }, }).length === 0 if (useImportSyntax) { diff --git a/packages/gatsby-dev-cli/src/utils/check-deps-changes.js b/packages/gatsby-dev-cli/src/utils/check-deps-changes.js index cf3e4f531f5fd..cd7a045389556 100644 --- a/packages/gatsby-dev-cli/src/utils/check-deps-changes.js +++ b/packages/gatsby-dev-cli/src/utils/check-deps-changes.js @@ -1,13 +1,13 @@ const fs = require(`fs-extra`) const _ = require(`lodash`) const { - getMonorepoPackageJsonPath + getMonorepoPackageJsonPath, } = require(`./get-monorepo-package-json-path`) const request = require(`request`) function difference(object, base) { function changes(object, base) { - return _.transform(object, function(result, value, key) { + return _.transform(object, function (result, value, key) { if (!_.isEqual(value, base[key])) { result[key] = _.isObject(value) && _.isObject(base[key]) @@ -33,7 +33,7 @@ exports.checkDepsChanges = async ({ monoRepoPackages, root, isInitialScan, - ignoredPackageJSON + ignoredPackageJSON, }) => { let localPKGjson let packageNotInstalled = false @@ -49,7 +49,7 @@ exports.checkDepsChanges = async ({ ) return { didDepsChanged: false, - packageNotInstalled + packageNotInstalled, } } @@ -78,14 +78,14 @@ exports.checkDepsChanges = async ({ ) return { didDepsChanged: true, - packageNotInstalled + packageNotInstalled, } } } const monoRepoPackageJsonPath = getMonorepoPackageJsonPath({ packageName, - root + root, }) const monorepoPKGjsonString = fs.readFileSync( monoRepoPackageJsonPath, @@ -98,7 +98,7 @@ exports.checkDepsChanges = async ({ // so we need to not cause false positives return { didDepsChanged: false, - packageNotInstalled + packageNotInstalled, } } } @@ -178,12 +178,12 @@ exports.checkDepsChanges = async ({ } return { didDepsChanged: needPublishing, - packageNotInstalled + packageNotInstalled, } } } return { didDepsChanged: false, - packageNotInstalled + packageNotInstalled, } } diff --git a/packages/gatsby-graphiql-explorer/src/app/app.js b/packages/gatsby-graphiql-explorer/src/app/app.js index 8240e181a8f91..ce889f1873490 100644 --- a/packages/gatsby-graphiql-explorer/src/app/app.js +++ b/packages/gatsby-graphiql-explorer/src/app/app.js @@ -17,7 +17,7 @@ const parameters = {} window.location.search .substr(1) .split(`&`) - .forEach(function(entry) { + .forEach(function (entry) { var eq = entry.indexOf(`=`) if (eq >= 0) { parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent( @@ -30,7 +30,7 @@ function locationQuery(params) { return ( `?` + Object.keys(params) - .map(function(key) { + .map(function (key) { return encodeURIComponent(key) + `=` + encodeURIComponent(params[key]) }) .join(`&`) @@ -42,7 +42,7 @@ const graphqlParamNames = { query: true, variables: true, operationName: true, - explorerIsOpen: true + explorerIsOpen: true, } const otherParams = {} for (var k in parameters) { @@ -57,11 +57,11 @@ function graphQLFetcher(graphQLParams) { method: `post`, headers: { Accept: `application/json`, - "Content-Type": `application/json` + "Content-Type": `application/json`, }, body: JSON.stringify(graphQLParams), - credentials: `include` - }).then(function(response) { + credentials: `include`, + }).then(function (response) { return response.json() }) } @@ -166,12 +166,12 @@ class App extends React.Component { query: DEFAULT_QUERY, variables: DEFAULT_VARIABLES, explorerIsOpen: storedExplorerPaneState, - codeExporterIsOpen: storedCodeExporterPaneState + codeExporterIsOpen: storedCodeExporterPaneState, } componentDidMount() { graphQLFetcher({ - query: getIntrospectionQuery() + query: getIntrospectionQuery(), }).then(result => { const newState = { schema: buildClientSchema(result.data) } @@ -208,7 +208,7 @@ class App extends React.Component { const editor = this._graphiql.getQueryEditor() editor.setOption(`extraKeys`, { ...(editor.options.extraKeys || {}), - "Shift-Alt-LeftClick": this._handleInspectOperation + "Shift-Alt-LeftClick": this._handleInspectOperation, }) } @@ -225,7 +225,7 @@ class App extends React.Component { const end = { line: mousePos.line, ch: token.end } const relevantMousePos = { start: cm.indexFromPos(start), - end: cm.indexFromPos(end) + end: cm.indexFromPos(end), } const position = relevantMousePos diff --git a/packages/gatsby-image/src/index.js b/packages/gatsby-image/src/index.js index d40b0e6d524f0..8621fbfe83fb6 100644 --- a/packages/gatsby-image/src/index.js +++ b/packages/gatsby-image/src/index.js @@ -314,7 +314,7 @@ const Img = React.forwardRef((props, ref) => { height: `100%`, objectFit: `cover`, objectPosition: `center`, - ...style + ...style, }} /> ) @@ -323,7 +323,7 @@ const Img = React.forwardRef((props, ref) => { Img.propTypes = { style: PropTypes.object, onError: PropTypes.func, - onLoad: PropTypes.func + onLoad: PropTypes.func, } class Image extends React.Component { @@ -351,7 +351,7 @@ class Image extends React.Component { isVisible, imgLoaded: false, imgCached: false, - fadeIn: !this.seenBefore && props.fadeIn + fadeIn: !this.seenBefore && props.fadeIn, } this.imageRef = React.createRef() @@ -403,7 +403,7 @@ class Image extends React.Component { // TODO fix imgCached behaviour as it's now false when it's lazyloaded imgCached: !!( this.imageRef.current && this.imageRef.current.currentSrc - ) + ), }) }) }) @@ -436,7 +436,7 @@ class Image extends React.Component { Tag, itemProp, loading, - draggable + draggable, } = convertProps(this.props) const shouldReveal = this.state.fadeIn === false || this.state.imgLoaded @@ -445,21 +445,21 @@ class Image extends React.Component { const imageStyle = { opacity: shouldReveal ? 1 : 0, transition: shouldFadeIn ? `opacity ${durationFadeIn}ms` : `none`, - ...imgStyle + ...imgStyle, } const bgColor = typeof backgroundColor === `boolean` ? `lightgray` : backgroundColor const delayHideStyle = { - transitionDelay: `${durationFadeIn}ms` + transitionDelay: `${durationFadeIn}ms`, } const imagePlaceholderStyle = { opacity: this.state.imgLoaded ? 0 : 1, ...(shouldFadeIn && delayHideStyle), ...imgStyle, - ...placeholderStyle + ...placeholderStyle, } const placeholderImageProps = { @@ -467,7 +467,7 @@ class Image extends React.Component { alt: !this.state.isVisible ? alt : ``, style: imagePlaceholderStyle, className: placeholderClassName, - itemProp + itemProp, } if (fluid) { @@ -480,7 +480,7 @@ class Image extends React.Component { style={{ position: `relative`, overflow: `hidden`, - ...style + ...style, }} ref={this.handleRef} key={`fluid-${JSON.stringify(image.srcSet)}`} @@ -490,7 +490,7 @@ class Image extends React.Component { aria-hidden style={{ width: `100%`, - paddingBottom: `${100 / image.aspectRatio}%` + paddingBottom: `${100 / image.aspectRatio}%`, }} /> @@ -507,7 +507,7 @@ class Image extends React.Component { opacity: !this.state.imgLoaded ? 1 : 0, right: 0, left: 0, - ...(shouldFadeIn && delayHideStyle) + ...(shouldFadeIn && delayHideStyle), }} /> )} @@ -567,8 +567,8 @@ class Image extends React.Component { title, loading, ...image, - imageVariants - }) + imageVariants, + }), }} /> )} @@ -586,7 +586,7 @@ class Image extends React.Component { display: `inline-block`, width: image.width, height: image.height, - ...style + ...style, } if (style.display === `inherit`) { @@ -610,7 +610,7 @@ class Image extends React.Component { width: image.width, opacity: !this.state.imgLoaded ? 1 : 0, height: image.height, - ...(shouldFadeIn && delayHideStyle) + ...(shouldFadeIn && delayHideStyle), }} /> )} @@ -672,8 +672,8 @@ class Image extends React.Component { title, loading, ...image, - imageVariants - }) + imageVariants, + }), }} /> )} @@ -692,7 +692,7 @@ Image.defaultProps = { Tag: `div`, // We set it to `lazy` by default because it's best to default to a performant // setting and let the user "opt out" to `eager` - loading: `lazy` + loading: `lazy`, } const fixedObject = PropTypes.shape({ @@ -704,7 +704,7 @@ const fixedObject = PropTypes.shape({ tracedSVG: PropTypes.string, srcWebp: PropTypes.string, srcSetWebp: PropTypes.string, - media: PropTypes.string + media: PropTypes.string, }) const fluidObject = PropTypes.shape({ @@ -716,7 +716,7 @@ const fluidObject = PropTypes.shape({ tracedSVG: PropTypes.string, srcWebp: PropTypes.string, srcSetWebp: PropTypes.string, - media: PropTypes.string + media: PropTypes.string, }) // If you modify these propTypes, please don't forget to update following files as well: @@ -746,7 +746,7 @@ Image.propTypes = { Tag: PropTypes.string, itemProp: PropTypes.string, loading: PropTypes.oneOf([`auto`, `lazy`, `eager`]), - draggable: PropTypes.bool + draggable: PropTypes.bool, } export default Image diff --git a/packages/gatsby-image/src/withIEPolyfill/index.js b/packages/gatsby-image/src/withIEPolyfill/index.js index ba3d6452ac6aa..45081065faa6e 100644 --- a/packages/gatsby-image/src/withIEPolyfill/index.js +++ b/packages/gatsby-image/src/withIEPolyfill/index.js @@ -26,7 +26,7 @@ class ImageWithIEPolyfill extends Component { const polyfillStyle = { objectFit: objectFit, objectPosition: objectPosition, - fontFamily: `"object-fit: ${objectFit}; object-position: ${objectPosition}"` + fontFamily: `"object-fit: ${objectFit}; object-position: ${objectPosition}"`, } return ( @@ -36,11 +36,11 @@ class ImageWithIEPolyfill extends Component { {...props} imgStyle={{ ...props.imgStyle, - ...polyfillStyle + ...polyfillStyle, }} placeholderStyle={{ ...props.placeholderStyle, - ...polyfillStyle + ...polyfillStyle, }} /> ) @@ -53,12 +53,12 @@ class ImageWithIEPolyfill extends Component { // https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/gatsby-image.md#gatsby-image-props ImageWithIEPolyfill.propTypes = { objectFit: PropTypes.string, - objectPosition: PropTypes.string + objectPosition: PropTypes.string, } ImageWithIEPolyfill.defaultProps = { objectFit: `cover`, - objectPosition: `50% 50%` + objectPosition: `50% 50%`, } export default forwardRef((props, ref) => ( diff --git a/packages/gatsby-plugin-benchmark-reporting/src/gatsby-node.js b/packages/gatsby-plugin-benchmark-reporting/src/gatsby-node.js index 5ab16c95b8421..f40d19ba0c6e7 100644 --- a/packages/gatsby-plugin-benchmark-reporting/src/gatsby-node.js +++ b/packages/gatsby-plugin-benchmark-reporting/src/gatsby-node.js @@ -27,7 +27,7 @@ function reportError(...args) { function execToStr(cmd) { return String( execSync(cmd, { - encoding: `utf8` + encoding: `utf8`, }) ?? `` ).trim() } @@ -52,7 +52,7 @@ class BenchMeta { preBootstrap: 0, // Gatsby onPreBootstrap life cycle preBuild: 0, // Gatsby onPreBuild life cycle postBuild: 0, // Gatsby onPostBuild life cycle - benchmarkEnd: 0 // End of benchmark itself + benchmarkEnd: 0, // End of benchmark itself } this.started = false } @@ -96,7 +96,7 @@ class BenchMeta { contentSource: process.env.BENCHMARK_CONTENT_SOURCE, siteType: process.env.BENCHMARK_SITE_TYPE, repoName: process.env.BENCHMARK_REPO_NAME, - buildType: buildType + buildType: buildType, } } @@ -107,7 +107,7 @@ class BenchMeta { rss: rss ?? 0, heapTotal: heapTotal ?? 0, heapUsed: heapUsed ?? 0, - external: external ?? 0 + external: external ?? 0, } for (const key in this.timestamps) { @@ -173,18 +173,18 @@ class BenchMeta { gatsby: gatsbyVersion, gatsbyCli: gatsbyCliVersion, sharp: sharpVersion, - webpack: webpackVersion + webpack: webpackVersion, }, counts: { pages: parseInt(process.env.NUM_PAGES), jpgs: jpgCount, pngs: pngCount, gifs: gifCount, - other: otherCount + other: otherCount, }, memory, publicJsSize, - ...benchmarkMetadata + ...benchmarkMetadata, } } @@ -244,9 +244,9 @@ class BenchMeta { method: `POST`, headers: { "content-type": `application/json`, - "x-benchmark-secret": process.env.BENCHMARK_REPORTING_SECRET + "x-benchmark-secret": process.env.BENCHMARK_REPORTING_SECRET, }, - body: json + body: json, }).then(res => { lastStatus = res.status if ([401, 500].includes(lastStatus)) { @@ -291,8 +291,9 @@ async function onPreInit(api) { lastApi = api // This should be set in the gatsby-config of the site when enabling this plugin reportInfo( - `gatsby-plugin-benchmark-reporting: Will post benchmark data to: ${BENCHMARK_REPORTING_URL || - `the CLI`}` + `gatsby-plugin-benchmark-reporting: Will post benchmark data to: ${ + BENCHMARK_REPORTING_URL || `the CLI` + }` ) benchMeta.markStart() diff --git a/packages/gatsby-plugin-catch-links/src/catch-links.js b/packages/gatsby-plugin-catch-links/src/catch-links.js index 96acef9538e5f..cbdab5c69a9bc 100644 --- a/packages/gatsby-plugin-catch-links/src/catch-links.js +++ b/packages/gatsby-plugin-catch-links/src/catch-links.js @@ -167,7 +167,7 @@ export const routeThroughBrowserOrApp = ( return false } -export default function(root, pluginOptions, cb) { +export default function (root, pluginOptions, cb) { const clickHandler = routeThroughBrowserOrApp(cb, pluginOptions) root.addEventListener(`click`, clickHandler) diff --git a/packages/gatsby-plugin-catch-links/src/gatsby-node.js b/packages/gatsby-plugin-catch-links/src/gatsby-node.js index 5d85c46250697..2b33735b7e18f 100644 --- a/packages/gatsby-plugin-catch-links/src/gatsby-node.js +++ b/packages/gatsby-plugin-catch-links/src/gatsby-node.js @@ -1,5 +1,5 @@ /** @type {import('gatsby').GatsbyNode["onPreInit"]} */ -exports.onPreInit = function(args, options) { +exports.onPreInit = function (args, options) { if (options.excludeRegex && !options.excludePattern) { options.excludePattern = options.excludeRegex } diff --git a/packages/gatsby-plugin-facebook-analytics/src/__tests__/gatsby-browser.js b/packages/gatsby-plugin-facebook-analytics/src/__tests__/gatsby-browser.js index bc39cb91c2b92..07882c69f2c43 100644 --- a/packages/gatsby-plugin-facebook-analytics/src/__tests__/gatsby-browser.js +++ b/packages/gatsby-plugin-facebook-analytics/src/__tests__/gatsby-browser.js @@ -5,7 +5,7 @@ describe(`gatsby-plugin-facebook-analytics`, () => { describe(`in development mode`, () => { it(`does not log page views`, () => { const logPageView = jest.fn() - window.FB = function() {} + window.FB = function () {} window.FB.AppEvents = { logPageView } onRouteUpdate() @@ -28,7 +28,7 @@ describe(`gatsby-plugin-facebook-analytics`, () => { it(`logs page views`, () => { const logPageView = jest.fn() - window.FB = function() {} + window.FB = function () {} window.FB.AppEvents = { logPageView } onRouteUpdate() diff --git a/packages/gatsby-plugin-fullstory/src/gatsby-ssr.js b/packages/gatsby-plugin-fullstory/src/gatsby-ssr.js index 3f286b5ba9249..da3c4b444cf19 100644 --- a/packages/gatsby-plugin-fullstory/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-fullstory/src/gatsby-ssr.js @@ -28,9 +28,9 @@ window['_fs_namespace'] = 'FS'; if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)}; g._v="1.2.0"; })(window,document,window['_fs_namespace'],'script','user'); - ` + `, }} - /> + />, ]) } diff --git a/packages/gatsby-plugin-google-analytics/src/index.js b/packages/gatsby-plugin-google-analytics/src/index.js index 35688255316c1..236d76f506caf 100644 --- a/packages/gatsby-plugin-google-analytics/src/index.js +++ b/packages/gatsby-plugin-google-analytics/src/index.js @@ -43,11 +43,11 @@ function OutboundLink(props) { eventLabel: eventLabel || props.href, eventValue, transport: redirect ? `beacon` : ``, - hitCallback: function() { + hitCallback: function () { if (redirect) { document.location = props.href } - } + }, }) } else { if (redirect) { @@ -68,7 +68,7 @@ OutboundLink.propTypes = { eventAction: PropTypes.string, eventLabel: PropTypes.string, eventValue: PropTypes.number, - onClick: PropTypes.func + onClick: PropTypes.func, } /** @@ -85,7 +85,7 @@ function trackCustomEvent({ nonInteraction = true, transport, hitCallback, - callbackTimeout = 1000 + callbackTimeout = 1000, }) { if (typeof window !== `undefined` && window.ga) { const trackingEventOptions = { @@ -94,7 +94,7 @@ function trackCustomEvent({ eventLabel: label, eventValue: value, nonInteraction: nonInteraction, - transport + transport, } if (hitCallback && typeof hitCallback === `function`) { diff --git a/packages/gatsby-plugin-google-gtag/src/index.js b/packages/gatsby-plugin-google-gtag/src/index.js index 21230b94d0fdb..a029778f4e55a 100644 --- a/packages/gatsby-plugin-google-gtag/src/index.js +++ b/packages/gatsby-plugin-google-gtag/src/index.js @@ -28,11 +28,11 @@ const OutboundLink = React.forwardRef(({ children, ...props }, ref) => ( event_category: `outbound`, event_label: props.href, transport_type: redirect ? `beacon` : ``, - event_callback: function() { + event_callback: function () { if (redirect) { document.location = props.href } - } + }, }) } else { if (redirect) { @@ -50,7 +50,7 @@ const OutboundLink = React.forwardRef(({ children, ...props }, ref) => ( OutboundLink.propTypes = { href: PropTypes.string, target: PropTypes.string, - onClick: PropTypes.func + onClick: PropTypes.func, } export { OutboundLink } diff --git a/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-ssr.js b/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-ssr.js index 280604855a4e1..669e8ff1c99f5 100644 --- a/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-ssr.js +++ b/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-ssr.js @@ -5,10 +5,10 @@ describe(`gatsby-plugin-google-tagmanager`, () => { it(`should load gtm`, () => { const mocks = { setHeadComponents: jest.fn(), - setPreBodyComponents: jest.fn() + setPreBodyComponents: jest.fn(), } const pluginOptions = { - includeInDevelopment: true + includeInDevelopment: true, } onRenderBody(mocks, pluginOptions) @@ -27,11 +27,11 @@ describe(`gatsby-plugin-google-tagmanager`, () => { it(`should add no dataLayer by default`, () => { const mocks = { setHeadComponents: jest.fn(), - setPreBodyComponents: jest.fn() + setPreBodyComponents: jest.fn(), } const pluginOptions = { id: `123`, - includeInDevelopment: true + includeInDevelopment: true, } onRenderBody(mocks, pluginOptions) @@ -48,14 +48,14 @@ describe(`gatsby-plugin-google-tagmanager`, () => { it(`should add a static object as defaultDatalayer`, () => { const mocks = { setHeadComponents: jest.fn(), - setPreBodyComponents: jest.fn() + setPreBodyComponents: jest.fn(), } const pluginOptions = { includeInDevelopment: true, defaultDataLayer: { type: `object`, - value: { pageCategory: `home` } - } + value: { pageCategory: `home` }, + }, } onRenderBody(mocks, pluginOptions) @@ -69,16 +69,16 @@ describe(`gatsby-plugin-google-tagmanager`, () => { it(`should add a function as defaultDatalayer`, () => { const mocks = { setHeadComponents: jest.fn(), - setPreBodyComponents: jest.fn() + setPreBodyComponents: jest.fn(), } const pluginOptions = { includeInDevelopment: true, defaultDataLayer: { type: `function`, - value: function() { + value: function () { return { pageCategory: window.pageType } - }.toString() - } + }.toString(), + }, } const datalayerFuncAsString = oneLine`${pluginOptions.defaultDataLayer.value}` @@ -98,15 +98,15 @@ describe(`gatsby-plugin-google-tagmanager`, () => { reporter: { panic: msg => { throw new Error(msg) - } - } + }, + }, } let pluginOptions = { includeInDevelopment: true, defaultDataLayer: { type: `number`, - value: 5 - } + value: 5, + }, } expect(() => onRenderBody(mocks, pluginOptions)).toThrow() @@ -116,8 +116,8 @@ describe(`gatsby-plugin-google-tagmanager`, () => { includeInDevelopment: true, defaultDataLayer: { type: `object`, - value: new Test() - } + value: new Test(), + }, } expect(() => onRenderBody(mocks, pluginOptions)).toThrow() @@ -127,15 +127,15 @@ describe(`gatsby-plugin-google-tagmanager`, () => { const dataLayerName = `TEST_DATA_LAYER_NAME` const mocks = { setHeadComponents: jest.fn(), - setPreBodyComponents: jest.fn() + setPreBodyComponents: jest.fn(), } const pluginOptions = { includeInDevelopment: true, defaultDataLayer: { type: `object`, - value: { pageCategory: `home` } + value: { pageCategory: `home` }, }, - dataLayerName + dataLayerName, } onRenderBody(mocks, pluginOptions) diff --git a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js index b9c21450d8f04..d46a1c72db61b 100644 --- a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js @@ -4,7 +4,7 @@ jest.mock(`fs`, () => { writeFileSync: jest.fn(), mkdirSync: jest.fn(), readFileSync: jest.fn().mockImplementation(() => `someIconImage`), - statSync: jest.fn() + statSync: jest.fn(), } }) /* @@ -26,7 +26,7 @@ jest.mock(`sharp`, () => { metadata() { return { width: 128, - height: 128 + height: 128, } } })() @@ -43,7 +43,7 @@ jest.mock(`gatsby-core-utils`, () => { return { slash: originalCoreUtils.slash, cpuCoreCount: jest.fn(() => `1`), - createContentDigest: jest.fn(() => `contentDigest`) + createContentDigest: jest.fn(() => `contentDigest`), } }) @@ -51,17 +51,17 @@ const fs = require(`fs`) const path = require(`path`) const sharp = require(`sharp`) const reporter = { - activityTimer: jest.fn().mockImplementation(function() { + activityTimer: jest.fn().mockImplementation(function () { return { start: jest.fn(), - end: jest.fn() + end: jest.fn(), } - }) + }), } const { onPostBootstrap } = require(`../gatsby-node`) const apiArgs = { - reporter + reporter, } const manifestOptions = { @@ -76,14 +76,14 @@ const manifestOptions = { src: `icons/icon-48x48.png`, sizes: `48x48`, type: `image/png`, - purpose: `all` + purpose: `all`, }, { src: `icons/icon-128x128.png`, sizes: `128x128`, - type: `image/png` - } - ] + type: `image/png`, + }, + ], } describe(`Test plugin manifest options`, () => { @@ -106,7 +106,7 @@ describe(`Test plugin manifest options`, () => { start_url: `/`, background_color: `#f7f0eb`, theme_color: `#a2466c`, - display: `standalone` + display: `standalone`, }) const contents = fs.writeFileSync.mock.calls[0][1] expect(fs.writeFileSync).toHaveBeenCalledWith( @@ -127,19 +127,19 @@ describe(`Test plugin manifest options`, () => { { src: `icons/icon-48x48.png`, sizes: `${size}x${size}`, - type: `image/png` + type: `image/png`, }, { src: `other-icons/icon-48x48.png`, sizes: `${size}x${size}`, - type: `image/png` - } - ] + type: `image/png`, + }, + ], } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) const firstIconPath = path.join( @@ -167,14 +167,14 @@ describe(`Test plugin manifest options`, () => { { src: `icons/icon-48x48.png`, sizes: `${size}x${size}`, - type: `image/png` - } - ] + type: `image/png`, + }, + ], } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) expect(sharp).toHaveBeenCalledWith(icon, { density: size }) @@ -185,13 +185,13 @@ describe(`Test plugin manifest options`, () => { fs.statSync.mockReturnValueOnce({ isFile: () => false }) const pluginSpecificOptions = { - icon: `non/existing/path` + icon: `non/existing/path`, } await expect( onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) ).rejects.toThrow( `icon (non/existing/path) does not exist as defined in gatsby-config.js. Make sure the file exists relative to the root of the site.` @@ -209,11 +209,11 @@ describe(`Test plugin manifest options`, () => { cache_busting_mode: `name`, include_favicon: true, crossOrigin: `anonymous`, - icon_options: {} + icon_options: {}, } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) expect(sharp).toHaveBeenCalledTimes(0) @@ -229,11 +229,11 @@ describe(`Test plugin manifest options`, () => { const pluginSpecificOptions = { icon: `images/gatsby-logo.png`, legacy: true, - cache_busting_mode: `name` + cache_busting_mode: `name`, } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) expect(sharp).toHaveBeenCalledTimes(2) @@ -246,11 +246,11 @@ describe(`Test plugin manifest options`, () => { const pluginSpecificOptions = { icon: `images/gatsby-logo.png`, legacy: true, - cache_busting_mode: `none` + cache_busting_mode: `none`, } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) expect(sharp).toHaveBeenCalledTimes(2) @@ -266,12 +266,12 @@ describe(`Test plugin manifest options`, () => { const pluginSpecificOptions = { icon: `images/gatsby-logo.png`, icon_options: { - purpose: `maskable` - } + purpose: `maskable`, + }, } await onPostBootstrap(apiArgs, { ...manifestOptions, - ...pluginSpecificOptions + ...pluginSpecificOptions, }) expect(sharp).toHaveBeenCalledTimes(2) @@ -289,7 +289,7 @@ describe(`Test plugin manifest options`, () => { start_url: `/`, background_color: `#f7f0eb`, theme_color: `#a2466c`, - display: `standalone` + display: `standalone`, } ) const contents = fs.writeFileSync.mock.calls[0][1] @@ -309,14 +309,14 @@ describe(`Test plugin manifest options`, () => { { ...manifestOptions, start_url: `/de/`, - lang: `de` + lang: `de`, }, { ...manifestOptions, start_url: `/es/`, - lang: `es` - } - ] + lang: `es`, + }, + ], } const { localize, ...manifest } = pluginSpecificOptions const expectedResults = localize.concat(manifest).map(x => { @@ -346,14 +346,14 @@ describe(`Test plugin manifest options`, () => { { ...manifestOptions, start_url: `/de/`, - lang: `de` + lang: `de`, }, { ...manifestOptions, start_url: `/es/`, - lang: `es` - } - ] + lang: `es`, + }, + ], } const { localize, ...manifest } = pluginSpecificOptions @@ -365,9 +365,9 @@ describe(`Test plugin manifest options`, () => { icons: manifest.icons.map(icon => { return { ...icon, - src: path.posix.join(`/blog`, icon.src) + src: path.posix.join(`/blog`, icon.src), } - }) + }), } }) @@ -397,13 +397,13 @@ describe(`Test plugin manifest options`, () => { localize: [ { start_url: `/de/`, - lang: `de` + lang: `de`, }, { start_url: `/es/`, - lang: `es` - } - ] + lang: `es`, + }, + ], } const { localize, ...manifest } = pluginSpecificOptions const expectedResults = localize @@ -411,7 +411,7 @@ describe(`Test plugin manifest options`, () => { .map(({ language, manifest }) => { return { ...manifestOptions, - ...manifest + ...manifest, } }) diff --git a/packages/gatsby-plugin-manifest/src/common.js b/packages/gatsby-plugin-manifest/src/common.js index 99110bae8c5fa..7113b6a175610 100644 --- a/packages/gatsby-plugin-manifest/src/common.js +++ b/packages/gatsby-plugin-manifest/src/common.js @@ -6,43 +6,43 @@ exports.defaultIcons = [ { src: `icons/icon-48x48.png`, sizes: `48x48`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-72x72.png`, sizes: `72x72`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-96x96.png`, sizes: `96x96`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-144x144.png`, sizes: `144x144`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-192x192.png`, sizes: `192x192`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-256x256.png`, sizes: `256x256`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-384x384.png`, sizes: `384x384`, - type: `image/png` + type: `image/png`, }, { src: `icons/icon-512x512.png`, sizes: `512x512`, - type: `image/png` - } + type: `image/png`, + }, ] /** @@ -66,7 +66,7 @@ exports.doesIconExist = function doesIconExist(srcIcon) { * @param {string} path The generic path to an icon * @param {string} digest The digest of the icon provided in the plugin's options. */ -exports.addDigestToPath = function(path, digest, method) { +exports.addDigestToPath = function (path, digest, method) { if (method === `name`) { const parsedPath = sysPath.parse(path) diff --git a/packages/gatsby-plugin-manifest/src/gatsby-browser.js b/packages/gatsby-plugin-manifest/src/gatsby-browser.js index 9280241922bd8..c2b240182493d 100644 --- a/packages/gatsby-plugin-manifest/src/gatsby-browser.js +++ b/packages/gatsby-plugin-manifest/src/gatsby-browser.js @@ -6,7 +6,7 @@ import getManifestForPathname from "./get-manifest-pathname" if (__MANIFEST_PLUGIN_HAS_LOCALISATION__) { const withPrefix = withAssetPrefix || fallbackWithPrefix - exports.onRouteUpdate = function({ location }, pluginOptions) { + exports.onRouteUpdate = function ({ location }, pluginOptions) { const { localize } = pluginOptions const manifestFilename = getManifestForPathname(location.pathname, localize) diff --git a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js b/packages/gatsby-plugin-mdx/gatsby/source-nodes.js index 4550555b22062..b3030f492dacd 100644 --- a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js +++ b/packages/gatsby-plugin-mdx/gatsby/source-nodes.js @@ -28,12 +28,7 @@ async function getCounts({ mdast }) { }) await remark() - .use( - remark2retext, - unified() - .use(english) - .use(count) - ) + .use(remark2retext, unified().use(english).use(count)) .run(mdast) function count() { @@ -49,7 +44,7 @@ async function getCounts({ mdast }) { return { paragraphs: counts.ParagraphNode, sentences: counts.SentenceNode, - words: counts.WordNode + words: counts.WordNode, } } @@ -128,7 +123,7 @@ module.exports = ( reporter, actions, schema, - ...helpers + ...helpers, }) // New Code // Schema @@ -143,19 +138,19 @@ module.exports = ( async resolve(mdxNode) { const { body } = await processMDX({ node: mdxNode }) return body - } + }, }, excerpt: { type: `String!`, args: { pruneLength: { type: `Int`, - defaultValue: 140 + defaultValue: 140, }, truncate: { type: GraphQLBoolean, - defaultValue: false - } + defaultValue: false, + }, }, async resolve(mdxNode, { pruneLength, truncate }) { if (mdxNode.excerpt) { @@ -177,16 +172,16 @@ module.exports = ( return _.truncate(excerptNodes.join(` `), { length: pruneLength, - omission: `…` + omission: `…`, }) - } + }, }, headings: { type: `[MdxHeadingMdx]`, args: { depth: { - type: `HeadingsMdx` - } + type: `HeadingsMdx`, + }, }, async resolve(mdxNode, { depth }) { // TODO: change this to operate on html instead of mdast @@ -195,14 +190,14 @@ module.exports = ( visit(mdast, `heading`, heading => { headings.push({ value: toString(heading), - depth: heading.depth + depth: heading.depth, }) }) if (headingsMdx.includes(depth)) { headings = headings.filter(heading => `h${heading.depth}` === depth) } return headings - } + }, }, html: { type: `String`, @@ -227,29 +222,29 @@ ${e}` ) return undefined } - } + }, }, mdxAST: { type: `JSON`, async resolve(mdxNode) { const { mdast } = await processMDX({ node: mdxNode }) return mdast - } + }, }, tableOfContents: { type: `JSON`, args: { maxDepth: { type: `Int`, - default: 6 - } + default: 6, + }, }, async resolve(mdxNode, { maxDepth }) { const { mdast } = await processMDX({ node: mdxNode }) const toc = generateTOC(mdast, { maxDepth }) return getTableOfContents(toc.map, {}) - } + }, }, timeToRead: { type: `Int`, @@ -263,17 +258,17 @@ ${e}` timeToRead = 1 } return timeToRead - } + }, }, wordCount: { type: `MdxWordCount`, async resolve(mdxNode) { const { mdast } = await processMDX({ node: mdxNode }) return getCounts({ mdast }) - } - } + }, + }, }, - interfaces: [`Node`] + interfaces: [`Node`], }) createTypes(MdxType) } diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-components.js b/packages/gatsby-plugin-mdx/loaders/mdx-components.js index 7a6262b2236b5..46b6d27a9e403 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-components.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-components.js @@ -13,7 +13,7 @@ const loaderUtils = require(`loader-utils`) * } * ``` */ -module.exports = function() { +module.exports = function () { const options = loaderUtils.getOptions(this) const pluginRequires = !options.plugins ? `[]` diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-loader.js b/packages/gatsby-plugin-mdx/loaders/mdx-loader.js index 8ca7afbff9f39..9999829f5cd7e 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-loader.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-loader.js @@ -10,7 +10,7 @@ const { isExport, isExportDefault, BLOCKS_REGEX, - EMPTY_NEWLINE + EMPTY_NEWLINE, } = require(`@mdx-js/mdx/util`) // Some packages are required implicitly from @mdx-js/mdx (not listed in package.json). @@ -32,7 +32,7 @@ const DEFAULT_OPTIONS = { remarkPlugins: [], rehypePlugins: [], compilers: [], - blocks: [BLOCKS_REGEX] + blocks: [BLOCKS_REGEX], } /** @@ -57,7 +57,7 @@ const hasDefaultExport = (str, options) => { return eat(subvalue)({ type: isExport(subvalue) ? `export` : `import`, default: getDefaultExportBlock(subvalue), - value: subvalue + value: subvalue, }) } @@ -88,7 +88,7 @@ const hasDefaultExport = (str, options) => { return hasDefaultExportBool } -module.exports = async function(content) { +module.exports = async function (content) { const callback = this.async() const { getNode: rawGetNode, @@ -123,7 +123,7 @@ module.exports = async function(content) { mdxNode = await createMDXNode({ id: `fakeNodeIdMDXFileABugIfYouSeeThis`, node: fileNode, - content + content, }) } catch (e) { return callback(e) @@ -170,7 +170,7 @@ ${contentWithoutFrontmatter}` getNodes, reporter, cache, - pathPrefix + pathPrefix, }) try { @@ -179,8 +179,8 @@ ${contentWithoutFrontmatter}` plugins: [ requireFromMDX(`@babel/plugin-syntax-jsx`), requireFromMDX(`@babel/plugin-syntax-object-rest-spread`), - require(`../utils/babel-plugin-html-attr-to-jsx-attr`) - ] + require(`../utils/babel-plugin-html-attr-to-jsx-attr`), + ], }) debugMore(`transformed code`, result.code) return callback( diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js b/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js index 360f8581ad735..0f3fc1faf254f 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-scopes.js @@ -4,7 +4,7 @@ const { slash } = require(`gatsby-core-utils`) const loaderUtils = require(`loader-utils`) const { MDX_SCOPES_LOCATION } = require(`../constants`) -module.exports = function() { +module.exports = function () { const { cache } = loaderUtils.getOptions(this) const abs = path.join(cache.directory, MDX_SCOPES_LOCATION) const files = fs.readdirSync(abs) diff --git a/packages/gatsby-plugin-mdx/loaders/mdx-wrappers.js b/packages/gatsby-plugin-mdx/loaders/mdx-wrappers.js index 9fe59870f18b0..cf99d2831364c 100644 --- a/packages/gatsby-plugin-mdx/loaders/mdx-wrappers.js +++ b/packages/gatsby-plugin-mdx/loaders/mdx-wrappers.js @@ -14,7 +14,7 @@ const loaderUtils = require(`loader-utils`) * } * ``` */ -module.exports = function() { +module.exports = function () { const options = loaderUtils.getOptions(this) const { flattenedPlugins: plugins } = options.store.getState() const wrapperPlugins = plugins diff --git a/packages/gatsby-plugin-mdx/utils/babel-plugin-html-attr-to-jsx-attr.js b/packages/gatsby-plugin-mdx/utils/babel-plugin-html-attr-to-jsx-attr.js index 276a356307202..54fd443e8c3ff 100644 --- a/packages/gatsby-plugin-mdx/utils/babel-plugin-html-attr-to-jsx-attr.js +++ b/packages/gatsby-plugin-mdx/utils/babel-plugin-html-attr-to-jsx-attr.js @@ -488,7 +488,7 @@ var TRANSLATIONS = { y: `y`, ychannelselector: `yChannelSelector`, z: `z`, - zoomandpan: `zoomAndPan` + zoomandpan: `zoomAndPan`, } const propsKeysVisitor = { @@ -497,10 +497,10 @@ const propsKeysVisitor = { node.node.key.value = TRANSLATIONS[node.node.key.value] || node.node.key.value } - } + }, } var jsxAttributeFromHTMLAttributeVisitor = { - JSXAttribute: function(node) { + JSXAttribute: function (node) { if (node.node.name.name in TRANSLATIONS) { node.node.name.name = TRANSLATIONS[node.node.name.name] } else if (node.node.name.name === `props`) { @@ -518,7 +518,7 @@ var jsxAttributeFromHTMLAttributeVisitor = { // node.node.value.type !== "JSXExpressionContainer" ) { let styleArray = [] - styleToObject(node.node.value.extra.rawValue, function( + styleToObject(node.node.value.extra.rawValue, function ( name, value, declaration @@ -533,15 +533,15 @@ var jsxAttributeFromHTMLAttributeVisitor = { ) ) } - } + }, } module.exports = function attrs() { return { visitor: { - JSXElement: function(path) { + JSXElement: function (path) { path.traverse(jsxAttributeFromHTMLAttributeVisitor) - } - } + }, + }, } } diff --git a/packages/gatsby-plugin-mdx/utils/gen-mdx.js b/packages/gatsby-plugin-mdx/utils/gen-mdx.js index 4604ca23428d6..fc6fbd4b3ef3d 100644 --- a/packages/gatsby-plugin-mdx/utils/gen-mdx.js +++ b/packages/gatsby-plugin-mdx/utils/gen-mdx.js @@ -70,7 +70,7 @@ module.exports = async function genMDX( html: undefined, scopeImports: [], scopeIdentifiers: [], - body: undefined + body: undefined, } // TODO: a remark and a hast plugin that pull out the ast and store it in results @@ -116,7 +116,7 @@ export const _frontmatter = ${JSON.stringify(data)}` reporter, cache, pathPrefix, - ...helpers + ...helpers, } ) @@ -125,7 +125,7 @@ export const _frontmatter = ${JSON.stringify(data)}` ...options, remarkPlugins: options.remarkPlugins.concat( gatsbyRemarkPluginsAsremarkPlugins - ) + ), }) results.rawMDXOutput = `/* @jsx mdx */ @@ -141,7 +141,7 @@ ${code}` instance.plugin, objRestSpread, htmlAttrToJSXAttr, - removeExportKeywords + removeExportKeywords, ], presets: [ require(`@babel/preset-react`), @@ -150,10 +150,10 @@ ${code}` { useBuiltIns: `entry`, corejs: 2, - modules: false - } - ] - ] + modules: false, + }, + ], + ], }) const identifiers = Array.from(instance.state.identifiers) diff --git a/packages/gatsby-plugin-mdx/utils/render-html.js b/packages/gatsby-plugin-mdx/utils/render-html.js index f524fa4ecd064..1c6086a860cd7 100644 --- a/packages/gatsby-plugin-mdx/utils/render-html.js +++ b/packages/gatsby-plugin-mdx/utils/render-html.js @@ -10,7 +10,7 @@ const { cloneDeep } = require(`lodash`) const DataLoader = require(`dataloader`) const queue = new PQueue({ - concurrency: parseInt(process.env.GATSBY_MDX_CONCURRENCY) || 4 + concurrency: parseInt(process.env.GATSBY_MDX_CONCURRENCY) || 4, }) let count = 0 @@ -22,7 +22,7 @@ queue.on(`active`, () => { ) }) -var findAsset = function(src, compilation, webpackStatsJson) { +var findAsset = function (src, compilation, webpackStatsJson) { if (!src) { var chunkNames = Object.keys(webpackStatsJson.assetsByChunkName) @@ -43,7 +43,7 @@ var findAsset = function(src, compilation, webpackStatsJson) { // Webpack outputs an array for each chunk when using sourcemaps if (chunkValue instanceof Array) { // Is the main bundle always the first element? - chunkValue = chunkValue.find(function(filename) { + chunkValue = chunkValue.find(function (filename) { return /\.js$/.test(filename) }) } @@ -122,7 +122,7 @@ exports.mdxHTMLLoader = ({ cache, reporter, store }) => webpackConfig.output = { filename: `output.js`, path: path.join(cache.directory, `webpack`), - libraryTarget: `commonjs` + libraryTarget: `commonjs`, } webpackConfig.plugins = webpackConfig.plugins || [] webpackConfig.plugins.push(new MdxHtmlBuilderWebpackPlugin()) diff --git a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js index 9a0545658aea0..3019caec724fd 100644 --- a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js +++ b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js @@ -63,8 +63,8 @@ function replaceRule(value, stage) { ...rule, loader: MiniCssExtractPlugin.loader, options: { - hmr: true - } + hmr: true, + }, } } @@ -74,12 +74,12 @@ function replaceRule(value, stage) { if (value.use) { return { ...value, - use: value.use.map(replaceStyleLoader) + use: value.use.map(replaceStyleLoader), } } else if (value.loader) { return { ...value, - loader: replaceStyleLoader(value) + loader: replaceStyleLoader(value), } } } @@ -101,7 +101,7 @@ exports.onPreInit = ({ reporter }) => { exports.onCreateDevServer = ({ app, store }, { publicPath = `admin` }) => { const { program } = store.getState() const publicPathClean = trim(publicPath, `/`) - app.get(`/${publicPathClean}`, function(req, res) { + app.get(`/${publicPathClean}`, function (req, res) { res.sendFile( path.join(program.directory, `public`, publicPathClean, `index.html`), err => { @@ -123,7 +123,7 @@ exports.onCreateWebpackConfig = ( htmlTitle = `Content Manager`, htmlFavicon = ``, manualInit = false, - includeRobots = false + includeRobots = false, } ) => { if (![`develop`, `build-javascript`].includes(stage)) { @@ -139,7 +139,7 @@ exports.onCreateWebpackConfig = ( /\.s(a|c)ss$/, /\.module\.s(a|c)ss$/, /\.less$/, - /\.module\.less$/ + /\.module\.less$/, ].map(t => t.toString()) ) } @@ -153,21 +153,21 @@ exports.onCreateWebpackConfig = ( name: `react`, global: `React`, assetDir: `umd`, - assetName: `react.production.min.js` + assetName: `react.production.min.js`, }, { name: `react-dom`, global: `ReactDOM`, assetDir: `umd`, - assetName: `react-dom.production.min.js` + assetName: `react-dom.production.min.js`, }, { name: `netlify-cms-app`, global: `NetlifyCmsApp`, assetDir: `dist`, assetName: `netlify-cms-app.js`, - sourceMap: `netlify-cms-app.js.map` - } + sourceMap: `netlify-cms-app.js.map`, + }, ] if (enableIdentityWidget) { @@ -176,7 +176,7 @@ exports.onCreateWebpackConfig = ( global: `netlifyIdentity`, assetDir: `build`, assetName: `netlify-identity.js`, - sourceMap: `netlify-identity.js.map` + sourceMap: `netlify-identity.js.map`, }) } @@ -185,18 +185,18 @@ exports.onCreateWebpackConfig = ( entry: { cms: [ path.join(__dirname, `cms.js`), - enableIdentityWidget && path.join(__dirname, `cms-identity.js`) + enableIdentityWidget && path.join(__dirname, `cms-identity.js`), ] .concat(modulePath) - .filter(p => p) + .filter(p => p), }, output: { - path: path.join(program.directory, `public`, publicPathClean) + path: path.join(program.directory, `public`, publicPathClean), }, module: { rules: deepMap(gatsbyConfig.module.rules, value => replaceRule(value, stage) - ).filter(Boolean) + ).filter(Boolean), }, plugins: [ // Remove plugins that either attempt to process the core Netlify CMS @@ -219,15 +219,15 @@ exports.onCreateWebpackConfig = ( messages: [ `Netlify CMS is running at ${program.ssl ? `https` : `http`}://${ program.host - }:${program.port}/${publicPathClean}/` - ] - } + }:${program.port}/${publicPathClean}/`, + ], + }, }), // Use a simple filename with no hash so we can access from source by // path. new MiniCssExtractPlugin({ - filename: `[name].css` + filename: `[name].css`, }), // Auto generate CMS index.html page. @@ -237,8 +237,8 @@ exports.onCreateWebpackConfig = ( chunks: [`cms`], excludeAssets: [/cms.css/], meta: { - robots: includeRobots ? `all` : `none` // Control whether search engines index this page - } + robots: includeRobots ? `all` : `none`, // Control whether search engines index this page + }, }), // Exclude CSS from index.html, as any imported styles are assumed to be @@ -249,7 +249,7 @@ exports.onCreateWebpackConfig = ( // Pass in needed Gatsby config values. new webpack.DefinePlugin({ __PATH__PREFIX__: pathPrefix, - CMS_PUBLIC_PATH: JSON.stringify(publicPath) + CMS_PUBLIC_PATH: JSON.stringify(publicPath), }), new CopyPlugin( @@ -259,12 +259,12 @@ exports.onCreateWebpackConfig = ( [ { from: require.resolve(path.join(name, assetDir, assetName)), - to: assetName + to: assetName, }, sourceMap && { from: require.resolve(path.join(name, assetDir, sourceMap)), - to: sourceMap - } + to: sourceMap, + }, ].filter(item => item) ) ) @@ -272,13 +272,13 @@ exports.onCreateWebpackConfig = ( new HtmlWebpackTagsPlugin({ tags: externals.map(({ assetName }) => assetName), - append: false + append: false, }), new webpack.DefinePlugin({ CMS_MANUAL_INIT: JSON.stringify(manualInit), - PRODUCTION: JSON.stringify(stage !== `develop`) - }) + PRODUCTION: JSON.stringify(stage !== `develop`), + }), ].filter(p => p), // Remove common chunks style optimizations from Gatsby's default @@ -287,14 +287,14 @@ exports.onCreateWebpackConfig = ( optimization: { // Without this, node can get out of memory errors when building for // production. - minimizer: stage === `develop` ? [] : gatsbyConfig.optimization.minimizer + minimizer: stage === `develop` ? [] : gatsbyConfig.optimization.minimizer, }, devtool: stage === `develop` ? `cheap-module-source-map` : `source-map`, externals: externals.map(({ name, global }) => { return { - [name]: global + [name]: global, } - }) + }), } if (customizeWebpackConfig) { @@ -305,7 +305,7 @@ exports.onCreateWebpackConfig = ( getConfig, rules, loaders, - plugins + plugins, }) } @@ -321,19 +321,19 @@ exports.onCreateWebpackConfig = ( test: /[\\/]node_modules[\\/](netlify-identity-widget)[\\/]/, name: `netlify-identity-widget`, chunks: `all`, - enforce: true - } - } - } + enforce: true, + }, + }, + }, }, // ignore netlify-identity-widget when not enabled plugins: enableIdentityWidget ? [] : [ new webpack.IgnorePlugin({ - resourceRegExp: /^netlify-identity-widget$/ - }) - ] + resourceRegExp: /^netlify-identity-widget$/, + }), + ], }) return new Promise((resolve, reject) => { diff --git a/packages/gatsby-plugin-sharp/src/gatsby-worker.js b/packages/gatsby-plugin-sharp/src/gatsby-worker.js index 14acfc62dba58..c4ea6698a330d 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-worker.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-worker.js @@ -25,7 +25,7 @@ const q = queue( args.operations.map(operation => { return { outputPath: path.join(outputDir, operation.outputPath), - args: operation.args + args: operation.args, } }), args.pluginOptions @@ -40,7 +40,7 @@ const q = queue( */ exports.IMAGE_PROCESSING = ({ inputPaths, outputDir, args }) => new Promise((resolve, reject) => { - q.push({ inputPaths, outputDir, args }, function(err) { + q.push({ inputPaths, outputDir, args }, function (err) { if (err) { return reject(err) } diff --git a/packages/gatsby-plugin-sitemap/src/__tests__/internals.js b/packages/gatsby-plugin-sitemap/src/__tests__/internals.js index d752cbfbcc33b..7a8b5652f25be 100644 --- a/packages/gatsby-plugin-sitemap/src/__tests__/internals.js +++ b/packages/gatsby-plugin-sitemap/src/__tests__/internals.js @@ -1,6 +1,6 @@ const { filterQuery, - defaultOptions: { serialize } + defaultOptions: { serialize }, } = require(`../internals`) beforeEach(() => { @@ -19,24 +19,24 @@ describe(`results using default settings`, () => { data: { site: { siteMetadata: { - siteUrl: siteUrl - } + siteUrl: siteUrl, + }, }, allSitePage: { edges: [ { node: { - path: `/page-1` - } + path: `/page-1`, + }, }, { node: { - path: `/page-2` - } - } - ] - } - } + path: `/page-2`, + }, + }, + ], + }, + }, } } @@ -53,7 +53,7 @@ describe(`results using default settings`, () => { verifyUrlsExistInResults(urls, [ `http://dummy.url${pathPrefix}/page-1`, - `http://dummy.url${pathPrefix}/page-2` + `http://dummy.url${pathPrefix}/page-2`, ]) }) @@ -69,7 +69,7 @@ describe(`results using default settings`, () => { verifyUrlsExistInResults(urls, [ `http://dummy.url${pathPrefix}/page-1`, - `http://dummy.url${pathPrefix}/page-2` + `http://dummy.url${pathPrefix}/page-2`, ]) }) @@ -124,30 +124,30 @@ describe(`results using non default alternatives`, () => { data: { site: { siteMetadata: { - siteUrl: siteUrl - } + siteUrl: siteUrl, + }, }, allSitePage: { nodes: [ { - path: `/page-1` + path: `/page-1`, }, { - path: `/page-2` - } - ] + path: `/page-2`, + }, + ], }, otherData: { nodes: [ { - name: `test` + name: `test`, }, { - name: `test 2` - } - ] - } - } + name: `test 2`, + }, + ], + }, + }, } } @@ -159,7 +159,7 @@ describe(`results using non default alternatives`, () => { verifyUrlsExistInResults(urls, [ `http://dummy.url/page-1`, - `http://dummy.url/page-2` + `http://dummy.url/page-2`, ]) }) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index e432d971a3363..7b5a8356a8425 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -62,9 +62,9 @@ export function filterQuery( ? allPages : allPages.map(page => { return { node: page } - }) + }), }, - site: { siteMetadata: { siteUrl } } + site: { siteMetadata: { siteUrl } }, } } @@ -90,7 +90,7 @@ export const defaultOptions = { `/dev-404-page`, `/404`, `/404.html`, - `/offline-plugin-app-shell-fallback` + `/offline-plugin-app-shell-fallback`, ], createLinkInHead: true, serialize: ({ site, allSitePage }) => { @@ -99,11 +99,11 @@ export const defaultOptions = { return { url: `${site.siteMetadata?.siteUrl ?? ``}${page.path}`, changefreq: `daily`, - priority: 0.7 + priority: 0.7, } }) }, - resolveSiteUrl: data => data.site.siteMetadata.siteUrl + resolveSiteUrl: data => data.site.siteMetadata.siteUrl, } function getNodes(results) { @@ -114,7 +114,7 @@ function getNodes(results) { if (`edges` in results) { return { allPages: results?.edges?.map(edge => edge.node), - originalType: `edges` + originalType: `edges`, } } throw new Error( diff --git a/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js b/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js index 863bf12d2ca81..4622771662040 100644 --- a/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js +++ b/packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js @@ -3,7 +3,7 @@ import React from "react" const pluginDefaults = { className: `anchor`, icon: true, - offsetY: 0 + offsetY: 0, } exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => { @@ -75,15 +75,13 @@ exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => { - ) : ( - undefined - ) + ) : undefined return setHeadComponents([ style,