Skip to content

Commit

Permalink
chore: implement babel-preset-gatsby into packages that need it (#9323)
Browse files Browse the repository at this point in the history
* Revert "chore: revert extra package changes to publish babel-preset-gatsby first (#9322)"

This reverts commit a392fb4.

* chore: implement little fix and add to gtag

* chore: add babel-preset-gatsby-package dep where it's needed

* chore: bump versionin gatsby

* chore: update plop file

* chore: remove src/ for babel-preset-gatsby-package

* test: get tests running for packages without src/ directories

* chore: add babel-preset-gatsby-package for correctness @pieh

* chore: add missing comma
  • Loading branch information
DSchau authored Oct 29, 2018
1 parent 850acf7 commit 2788f93
Show file tree
Hide file tree
Showing 193 changed files with 217 additions and 362 deletions.
50 changes: 0 additions & 50 deletions .babel-preset.js

This file was deleted.

4 changes: 1 addition & 3 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ if (process.env.NODE_ENV !== `test`) {
ignore.push(`**/__tests__`)
}

const presetAbsPath = require(`path`).join(__dirname, '.babel-preset.js')

module.exports = {
sourceMaps: true,
presets: [presetAbsPath],
presets: ["babel-preset-gatsby-package"],
ignore,
}
39 changes: 8 additions & 31 deletions docs/docs/babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,25 @@ browsers.
## How to use a custom .babelrc file

Gatsby ships with a default .babelrc setup that should work for most sites. If you'd like
to add custom Babel presets or plugins, we recommend copying our default .babelrc below
to the root of your site and modifying it per your needs.
to add custom Babel presets or plugins, you can create your own `.babelrc` at the root of your site, import [`babel-preset-gatsby`](https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-preset-gatsby), and overwrite the `target` option.

```bash
npm install --save babel-preset-gatsby
```

```json5:title=.babelrc
{
presets: [
[
"@babel/preset-env",
"babel-preset-gatsby",
{
loose: true,
modules: false,
useBuiltIns: "usage",
shippedProposals: true,
targets: {
browsers: [">0.25%", "not dead"],
},
},
],
[
"@babel/preset-react",
{
useBuiltIns: true,
pragma: "React.createElement",
},
],
],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
"@babel/plugin-syntax-dynamic-import",
"babel-plugin-macros",
[
"@babel/plugin-transform-runtime",
{
helpers: true,
regenerator: true,
},
],
],
}
```

For more advanced configurations, you can also copy the defaults from [`babel-preset-gatsby`](https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-preset-gatsby) and customize them to suit your needs.
8 changes: 3 additions & 5 deletions docs/docs/testing-css-in-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ If you followed along with the [Unit testing guide](/docs/unit-testing) you'll h

```diff:title=jest-preprocess.js
const babelOptions = {
presets: ["@babel/react", "@babel/env"],
plugins: [
presets: ["babel-preset-gatsby"],
+ plugins: [
+ "emotion",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
+ ],
}

module.exports = require("babel-jest").createTransformer(babelOptions)
Expand Down
8 changes: 2 additions & 6 deletions docs/docs/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ First you need to install Jest and some more required packages. You need to
install Babel 7 as it's required by Jest.

```sh
npm install --save-dev jest babel-jest react-test-renderer identity-obj-proxy 'babel-core@^7.0.0-0' @babel/core @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties @babel/plugin-proposal-optional-chaining
npm install --save-dev jest babel-jest react-test-renderer identity-obj-proxy 'babel-core@^7.0.0-0' @babel/core babel-preset-gatsby
```

Because Gatsby handles its own Babel configuration, you will need to manually
Expand Down Expand Up @@ -61,11 +61,7 @@ with a minimal config.

```js:title=jest-preprocess.js
const babelOptions = {
presets: ["@babel/react", "@babel/env"],
plugins: [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
presets: ["babel-preset-gatsby"],
}

module.exports = require("babel-jest").createTransformer(babelOptions)
Expand Down
3 changes: 1 addition & 2 deletions jest-transformer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
const presetAbsPath = require(`path`).join(__dirname, `.babel-preset.js`)
const babelPreset = require(presetAbsPath)()
const babelPreset = require(`babel-preset-gatsby-package`)()
module.exports = require(`babel-jest`).createTransformer(babelPreset)
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const path = require(`path`)
const glob = require(`glob`)
const fs = require("fs")

const pkgs = glob.sync(`./packages/*`).map(p => p.replace(/^\./, `<rootDir>`))

const reGatsby = /gatsby$/
const gatsbyDir = pkgs.find(p => reGatsby.exec(p))
const gatsbyBuildDirs = [`dist`].map(dir => path.join(gatsbyDir, dir))
const builtTestsDirs = pkgs.map(p => path.join(p, `__tests__`))
const builtTestsDirs = pkgs
.filter(p => fs.existsSync(path.join(p, `src`)))
.map(p => path.join(p, `__tests__`))
const distDirs = pkgs.map(p => path.join(p, `dist`))
const ignoreDirs = [].concat(gatsbyBuildDirs, builtTestsDirs, distDirs)
const coverageDirs = pkgs.map(p => path.join(p, `src/**/*.js`))
Expand All @@ -24,7 +27,7 @@ module.exports = {
`/node_modules/`,
`__tests__/fixtures`,
],
transform: { '^.+\\.js$': `<rootDir>/jest-transformer.js` },
transform: { "^.+\\.js$": `<rootDir>/jest-transformer.js` },
moduleNameMapper: {
"^highlight.js$": `<rootDir>/node_modules/highlight.js/lib/index.js`,
},
Expand Down
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "8.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-remove-graphql-queries/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
3 changes: 2 additions & 1 deletion packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"author": "Jason Quense <monastic.panic@gmail.com>",
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0"
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1"
},
"license": "MIT",
"main": "index.js",
Expand Down
1 change: 0 additions & 1 deletion packages/babel-preset-gatsby-package/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/*.js
yarn.lock
3 changes: 3 additions & 0 deletions packages/babel-preset-gatsby-package/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ flow-typed
coverage
decls
examples

# tests
__tests__
2 changes: 1 addition & 1 deletion packages/babel-preset-gatsby-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"@babel/preset-react": "^7.0.0"
},
"license": "MIT",
"main": "src/index.js"
"main": "index.js"
}
3 changes: 3 additions & 0 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"devDependencies": {
"babel-preset-gatsby-package": "^0.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-codemods/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.0.5",
"jscodeshift": "^0.5.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-dev-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-dev-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.0.5"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-dev-cli#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-image/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js", { "browser": true }]
["babel-preset-gatsby-package", { "browser": true }]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4",
"react-testing-library": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-link/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["../../.babel-preset.js", { "browser": true }]
["babel-preset-gatsby-package", { "browser": true }]
]
}

1 change: 1 addition & 0 deletions packages/gatsby-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4",
"react-testing-library": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-canonical-urls/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["../../.babel-preset.js", { "browser": true }]
["babel-preset-gatsby-package", { "browser": true }]
]
}

1 change: 1 addition & 0 deletions packages/gatsby-plugin-canonical-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-canonical-urls#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-catch-links/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["../../.babel-preset.js", { "browser": true }]
["babel-preset-gatsby-package", { "browser": true }]
]
}

1 change: 1 addition & 0 deletions packages/gatsby-plugin-catch-links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-catch-links#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-coffeescript/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-plugin-coffeescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-coffeescript#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-create-client-paths/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["../../.babel-preset.js"]
["babel-preset-gatsby-package"]
]
}
1 change: 1 addition & 0 deletions packages/gatsby-plugin-create-client-paths/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-create-client-paths#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-emotion/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["../../.babel-preset.js", { "browser": true }]
["babel-preset-gatsby-package", { "browser": true }]
]
}

1 change: 1 addition & 0 deletions packages/gatsby-plugin-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.1",
"cross-env": "^5.1.4"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-emotion#readme",
Expand Down
Loading

0 comments on commit 2788f93

Please sign in to comment.