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
Conversation
Load all babel config from rwjs/interal
@peterp just wanted to confirm... if I can get the web side working too, we want to remove the root babel.config.js right? |
Resolved |
…est-fun * 'main' of github.com:redwoodjs/redwood: Throw error on missing route param. (redwoodjs#3714) Regenerate lock file(s) (redwoodjs#3722) update yarn.lock udpate yarn.lock v0.38.1 update yarn.lock Have Redwood figure out in what order tables need to be cleared during scenario teardown (redwoodjs#3716) Base64 encode smaller required images during prerender (redwoodjs#3705) Have Redwood figure out in what order tables need to be cleared during scenario teardown (redwoodjs#3716) Base64 encode smaller required images during prerender (redwoodjs#3705) Fixes syntax error Firebase Auth template initializeApp (redwoodjs#3709) Fixes UserInputError mesage display in FormError (redwoodjs#3704) dbAuth: Resolved typos and inconsistencies in templates (redwoodjs#3698) fixed styling post-setup-tailwind command (redwoodjs#3696) More router tests. (redwoodjs#3718) Fix Fastify link. Remove Codesee integration. (redwoodjs#3717) Teach named route function to handle glob routes (redwoodjs#3702)
@dac09 The indirect babel dependency in the tailwind setup command is through execa, and it’s just to format a file. We could try doing it programmatically with prettier instead like we do in some of the codemods: https://github.com/redwoodjs/redwood/blob/main/packages/codemods/src/lib/prettify.ts. When I originally wrote this I probably just copied the execa call from another part of the code base, but we should start moving away from it for sure. If the call to eslint breaks in the tailwind setup command, does |
Managed to make progress on this @jtoar - but I'm now back to getting failures (Babel related) when jest web is run with runInBand. Here's the worst part - it doesn't always fail (passes in e2e). |
Always one thing after another with these things! We only had the web side Is the web side still broken even without |
// Not sure about this one: | ||
// Do we need this? | ||
// [ | ||
// '@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: RUNTIME_CORE_JS_VERSION, | ||
// }, | ||
// ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷 I guess a test would be really helpful here to accurately describe what this does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dac09 Unless this is throwing an error, I'd really prefer we not change (in this case remove) babel config at this stage in our roadmap. We know it's an optimization step, but we don't know how/if it could have downstream affect on things like Netlify deploy, etc.
tl;dr:
unless we have a strong case to remove this, we should leave it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm of the opposite opinion - I think it's better not to include this, unless we're also including Babel/runtime as a dependency on the rwjs/api. These two things must go hand in hand - as we learnt from one our releases a while ago.
I'm pretty sure the fact that this was still in the root Babel.config was wrong - and ignored for builds anyway. So adding it here would be a change 😂, confusing I know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep as I mentioned @thedavidprice this needs @babel/runtime
dep if we use this plugin. See here: https://babeljs.io/docs/en/babel-plugin-transform-runtime
We can evaluate later on whether we should include this, but to maintain the same configuration as we've had past couple of releases, we should not include this
I've spent some time writing unit tests, to understand exactly what's happening and I finally think I understand (a little) more of whats been happening, and verified my assumptions. I'll update this, and include it, but also will include relevant dependencies on the rwjs/api package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, a lot going on here. Also, I didn't correctly understand the relationship with @babel/runtime
I'm pretty sure the fact that this was still in the root Babel.config was wrong - and ignored for builds anyway. So adding it here would be a change 😂, confusing I know!
^^ Got it. And definitely an important consideration!
Happy to discuss real-time later this morning (Pacific time)! My primary concern is keeping babel config consistent with this PR. And now I better understand why you were making this (apparent) change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK Update on this, thanks to @dthyresson for rubber ducking with me. We have 3 options here:
Option A: remove polyfill plugin, only have transform runtime
We remove the polyfill plugin babel-plugin-polyfill-corejs3
and include babel-plugin-transform-runtime
. We will also need to change our framework config to include babel-plugin-transform-runtime
, because otherwise it won't use the correct module
We then only have @babel/runtime-corejs3 as a dependency on the api package.json.
Why?
- It seems the polyfill-corejs3 doesn't cover all cases of polyfilling. e.g.
Array.at()
- polyfill plugin will add imports, where it isn't required (e.g. try doing
Promise.any
) - We want to minimise the number of these polyfill dependencies, so the framework config must match the project config
Option B: accept polyfill-corejs3 misvehaviour
- Include both plugins
- We accept that this plugin will sometimes misbehave
- We include both
corejs
and@babel/runtime-corejs3
as dependencies - Trade off is that we are adding both these dependencies at runtime (worth about 1.2MB) in the api side. The web side should be fine since we're bundling anyway
Option C: not include transform-runtime plugin
- Only have polyfill-corejs3 plugin
- Have corejs as dependency in rwjs/api
- This is effectively what we have right now
- Accept that some things won't be polyfilled e.g.
Array.at()
I don't think all of this really affects the web side all that much - since the webside uses preset-env anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly (there's a 50/50 chance), the babel-plugin-polyfill-corejs3
was added to correct for ESBuild behavior.
y/n/maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushing up option A at the moment, until we discuss. See commit with tests: 18eb8df
(#3719)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wowza @dac09, this here is a ton of great work. Thank you 🚀
Only question I have in addition to my comments is whether or not the middleware check for Babel files should also be added to the rw build
command?
// Not sure about this one: | ||
// Do we need this? | ||
// [ | ||
// '@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: RUNTIME_CORE_JS_VERSION, | ||
// }, | ||
// ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dac09 Unless this is throwing an error, I'd really prefer we not change (in this case remove) babel config at this stage in our roadmap. We know it's an optimization step, but we don't know how/if it could have downstream affect on things like Netlify deploy, etc.
tl;dr:
unless we have a strong case to remove this, we should leave it in.
getCommonPlugins, | ||
} from './common' | ||
|
||
const TARGETS_NODE = '12.16' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still the "correct" target? And/or when will we know it's time to bump?
Just for future discussion.
packages/eslint-config/framework.js
Outdated
const path = require('path') | ||
|
||
const findUp = require('findup-sync') | ||
|
||
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 | ||
} | ||
|
||
// Just configure the babel options | ||
// The framework is configured with babel.config.js | ||
// While projects are configured programatically from rwjs/internal | ||
module.exports = { | ||
extends: path.join(__dirname, 'shared.js'), | ||
parserOptions: { | ||
babelOptions: { | ||
configFile: findBabelConfig(), | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dac09 could all this code live in ./.eslintrc.js
instead of a separate file here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, because of the "findUp" dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But will you need findUp since they're both in root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I don't know, I'll try, but I wanted to minimise the changes here... I find lint configuration boring and impossible to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. When I was tracing the changes and saw the files "shared" and "framework", I assumed two things: 1) there would be a "project" and 2) there would be eslint config in framework. When I saw that this file is specifically handling associated babel config for the framework, that's what got me thinking about whether or not it could be simplified further.
So all that mostly for discussion. Maybe what all this really needs is documentation in the package README.
done, I dont know if its useful, but I suppose it doesn't hurt! |
18eb8df
to
2e8954a
Compare
Also change framework config to make sure corejs isn't imported
2e8954a
to
e8415b1
Compare
I've moved Framework ESLint config into root .eslintrc.js and confirmed it's working. It's a minor change, but it's much easier for my brain to parse where the associated settings are within one file in root. Added comments to explain as well. Waiting for CI to pass, will then merge. |
This PR tries to achieve:
a) Move all of the babel related config required for running anything within redwood to inside the framework
Why? This sets us up for being able to change things internally between versions, and also longer term move to something like SWC when its ready
b) Leaves support for bringing your own babel plugins, but only using babel.config.js per side
DX
Warn users if .babelrc is present, that it'll be ignored (exits with error)
https://user-images.githubusercontent.com/1521877/142239626-8a333aa7-8d50-4583-b538-b0e5debba2a3.mp4
Warn users if babel.config.js is present, that this will be removed and may not be supported in future versionWeb
Api
Both
Other