Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes babel configuration from users project #3719

Merged
merged 32 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ddfff6f
WIP: playing with presets and jest babel config
dac09 Nov 9, 2021
e16384b
Only set preset env for jest
dac09 Nov 10, 2021
e2b2ba7
Remove all babelconfig from users project, including
dac09 Nov 10, 2021
56793eb
Whoops deleted the wrong rc
dac09 Nov 10, 2021
057b307
Fix apiSide register
dac09 Nov 10, 2021
908c6db
Fix prerendering
dac09 Nov 10, 2021
b2a2d73
Merge branch 'main' of github.com:redwoodjs/redwood into feat/babel-j…
dac09 Nov 12, 2021
cc2d774
Try programatically generating babel config for project
dac09 Nov 12, 2021
5bff963
Fixes for linter config
dac09 Nov 12, 2021
40de3e3
A few tweaks
dac09 Nov 12, 2021
fcf55aa
Config to configFile
dac09 Nov 12, 2021
a8e3dc5
Lint the linter config...
dac09 Nov 12, 2021
ba13b9e
Separate out fw and project eslint config
dac09 Nov 15, 2021
ea0173b
Standarise usage of babel options
dac09 Nov 15, 2021
9af65f6
Remove reminder for me
dac09 Nov 15, 2021
ba3b718
Switch ignores array to string array
dac09 Nov 15, 2021
39cf27c
Merge branch 'main' into feat/babel-jest-fun
dac09 Nov 16, 2021
6e92db7
Update internal package dependency
dac09 Nov 16, 2021
771278b
Add middleware to warn users about custom babel config
dac09 Nov 16, 2021
b455f89
Merge branch 'main' into feat/babel-jest-fun
dac09 Nov 17, 2021
df842bc
Remove scary warning, only leave helpful error if using a babelrc file
dac09 Nov 17, 2021
870d47f
Merge branch 'main' into feat/babel-jest-fun
dac09 Nov 17, 2021
48837e2
Add babelrc check to build command
dac09 Nov 18, 2021
6437507
Add comment to explain presetEnv flag
dac09 Nov 18, 2021
61ed774
Consistent test pattern for cell and routes overrides
dac09 Nov 18, 2021
6a33ba1
Undo web jest env changes
dac09 Nov 18, 2021
f5febfc
Merge branch 'main' into feat/babel-jest-fun
dac09 Nov 18, 2021
b0f4eac
Make fast-glob explicit cli dependency
dac09 Nov 18, 2021
ff0ffb6
Bump eslint config dep to 0.38.3 too
dac09 Nov 18, 2021
e8415b1
Option A: remove polyfill plugin, only have transform-runtime
dac09 Nov 18, 2021
5d069e8
move framework ESlint settings 100% to ./.eslintrc.js
thedavidprice Nov 19, 2021
9b9cdc6
Merge branch 'main' into feat/babel-jest-fun
thedavidprice Nov 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
const path = require('path')

const findUp = require('findup-sync')

// Framework Babel config is monorepo root ./babel.config.js
// `yarn lint` runs for each workspace, which needs findup for path to root
const findBabelConfig = (cwd = process.cwd()) => {
const configPath = findUp('babel.config.js', { cwd })
if (!configPath) {
throw new Error(`Eslint-parser could not find a "babel.config.js" file`)
}
return configPath
}

module.exports = {
extends: path.join(__dirname, 'packages/eslint-config/shared.js'),
parserOptions: {
babelOptions: {
configFile: findBabelConfig(),
},
},
ignorePatterns: [
'dist',
'fixtures',
Expand Down
19 changes: 19 additions & 0 deletions __fixtures__/example-todo-main/api/src/lib/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var sym = Symbol()

var promise = Promise.resolve()

var check = arr.includes('yeah!')

console.log(arr[Symbol.iterator]())

Promise.allSettled()

console.log([].includes('bazinga'))

Promise.any()


Object.hasOwn({ x: 2 }, "x")

var arr = [1, 2, 3];
arr.at(0) === 1
17 changes: 16 additions & 1 deletion __fixtures__/example-todo-main/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// This is added as a test for prebuild;
// check: packages/internal/**/build_api.test.ts
module.exports = {
presets: ['@redwoodjs/core/config/babel-preset'],
plugins: [
[
'babel-plugin-auto-import',
{
declarations: [
{
// import kitty from 'kitty-purr'
default: 'kitty',
path: 'kitty-purr',
},
],
},
],
]
}
1 change: 0 additions & 1 deletion __fixtures__/example-todo-main/web/.babelrc.js

This file was deleted.

24 changes: 12 additions & 12 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ module.exports = {
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
[
'@babel/plugin-transform-runtime',
{
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#core-js-aliasing
// Setting the version here also requires `@babel/runtime-corejs3`
corejs: { version: 3, proposals: true },
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#version
// Transform-runtime assumes that @babel/runtime@7.0.0 is installed.
// Specifying the version can result in a smaller bundle size.
version: packageJSON.devDependencies['@babel/runtime-corejs3'],
},
],
],
overrides: [
// ** WEB PACKAGES **
Expand Down Expand Up @@ -93,18 +105,6 @@ module.exports = {
],
},
],
[
'@babel/plugin-transform-runtime',
{
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#core-js-aliasing
// Setting the version here also requires `@babel/runtime-corejs3`
corejs: { version: 3, proposals: true },
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#version
// Transform-runtime assumes that @babel/runtime@7.0.0 is installed.
// Specifying the version can result in a smaller bundle size.
version: packageJSON.devDependencies['@babel/runtime-corejs3'],
},
],
// normally provided through preset-env detecting TARGET_BROWSER
// but webpack 4 has an issue with this
// see https://github.com/PaulLeCam/react-leaflet/issues/883
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"types": "./dist/index.d.ts",
"license": "MIT",
"dependencies": {
"@babel/runtime-corejs3": "7.15.4",
"@prisma/client": "3.3.0",
"core-js": "3.18.3",
"crypto-js": "4.1.1",
"jsonwebtoken": "8.5.1",
"jwks-rsa": "2.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dotenv-defaults": "3.0.0",
"envinfo": "7.8.1",
"execa": "5.1.1",
"fast-glob": "3.2.7",
"fs-extra": "10.0.0",
"humanize-string": "2.1.0",
"latest-version": "5.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { detectPrerenderRoutes } from '@redwoodjs/prerender/detection'
import { getPaths } from '../lib'
import c from '../lib/colors'
import { generatePrismaCommand } from '../lib/generatePrismaClient'
import checkForBabelConfig from '../middleware/checkForBabelConfig'

import { getTasks as getPrerenderTasks } from './prerender'

Expand Down Expand Up @@ -71,6 +72,7 @@ export const builder = (yargs) => {
default: false,
description: 'Measure build performance',
})
.middleware(checkForBabelConfig)
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getConfig, getConfigPath, shutdownPort } from '@redwoodjs/internal'
import { getPaths } from '../lib'
import c from '../lib/colors'
import { generatePrismaClient } from '../lib/generatePrismaClient'
import checkForBabelConfig from '../middleware/checkForBabelConfig'

export const command = 'dev [side..]'
export const description = 'Start development servers for api, and web'
Expand All @@ -34,6 +35,7 @@ export const builder = (yargs) => {
type: 'boolean',
description: 'Reload on changes to node_modules',
})
.middleware(checkForBabelConfig)
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const handler = async ({
collectCoverage ? '--collectCoverage' : null,
'--passWithNoTests',
...jestFilterArgs,
'--runInBand',
'--runInBand', // @TODO always run in band, even for web as we get babel errors https://github.com/redwoodjs/redwood/issues/3646
].filter((flagOrValue) => flagOrValue !== null) // Filter out nulls, not booleans because user may have passed a --something false flag

// If the user wants to watch, set the proper watch flag based on what kind of repo this is
Expand Down
43 changes: 43 additions & 0 deletions packages/cli/src/middleware/checkForBabelConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import boxen from 'boxen'
import fg from 'fast-glob'

import { getPaths } from '@redwoodjs/internal'

import c from '../lib/colors'

const isUsingBabelRc = () => {
return (
fg.sync('**/*/.babelrc(.*)?', {
cwd: getPaths().base,
ignore: 'node_modules',
}).length > 0
)
}
const BABEL_SETTINGS_LINK = c.warning('https://redwoodjs.com/docs/builds')

const checkForBabelConfig = () => {
if (isUsingBabelRc()) {
const messages = [
"Looks like you're trying to configure one of your sides with a .babelrc file.",
'These settings will be ignored, unless you use a babel.config.js file',
'',
'Your plugins and settings will be automatically merged with',
`the Redwood built-in config, more details here: ${BABEL_SETTINGS_LINK}`,
]

const errTitle = 'Incorrect project configuration'

console.log(
boxen(messages.join('\n'), {
title: errTitle,
padding: { top: 0, bottom: 0, right: 1, left: 1 },
margin: 1,
borderColor: 'red',
})
)

throw new Error(errTitle)
}
}

export default checkForBabelConfig