-
Notifications
You must be signed in to change notification settings - Fork 974
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
[v0.36] fix(babel-hooks): Import babel hooks correctly for console, exec and dm up commands #3231
[v0.36] fix(babel-hooks): Import babel hooks correctly for console, exec and dm up commands #3231
Conversation
['@babel/plugin-transform-typescript', undefined, 'rwjs-babel-typescript'], | ||
[ | ||
require('@redwoodjs/core/dist/babelPlugins/babel-plugin-redwood-src-alias') | ||
.default, |
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.
Notice I had to add .default
because I think.... with the datamigrate hook was doing the transform for us (accidentally)
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.
Did you manage to fix this by making it inline? Super weird behaviour, it should be ignore node_modules.
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.
Not sure what you mean by inline - as in require them before the plugin block?
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.
You mentioned that you changed something in datamigrate when you registered the hook, is this still a problem?
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 think it was the opposite actually - because the cli was registering the hooks, we didn't need to do the .default
. It is very strange to me as well...
@peterp any thoughts on how to add more tests for these? |
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.
Looking good ⚡
if (fs.existsSync(p)) { | ||
return p | ||
} else { | ||
return undefined |
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.
There's a difference between returning false
and undefined
. In the false
case it doesn't search for any additional configuration - essentially turning it off, in the undefined
case it invokes the traditional methods where it searches for the babel config.
We actually don't want it to search for .babelrc.js
because of the way it extends the base configuration. (It would mean duplicate plugins in a lot of cases) and it would be difficult to track down.
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 yes... sorry I should change this to false. I had it as undefined because I was using extends.
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 read the docs, it might not actually be searching for .babelrc.js
, but I would still prefer it to be turned off completely.
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.
Peter, so using false is different from using undefined. Using false just makes it fail... my suspicion babel register behaves differently to babel transform.
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.
What I'm not loving about this PR is that it feels like it's introducing more uncertainty in a process that I would love to be solid. This is the outcome I'm trying to achieve:
So this is what I want:
- I want people to delete
api/.babelrc.js
, or to convert it toapi/babel.config.js
and remove the "extends" part. - I want this to be a breaking change if you have custom babel transformations. The reason I want it to be a breaking change is because I want to discourage people from adding their own babel transformations because I would like to move our own transformations to a faster toolchain and would not like babel to make that process difficult.
Can we work around making that a realistic goal in this PR instead of muddying the water? And is it something that we can have tests for?
- Test that
<side>/.babelrc.js
is not imported - Test that
<side>/babel.config.json
can be imported if it's available.
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.
^^ @thedavidprice Does this reasoning sound solid to you?
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.
@peterp The items 1 and 2 above regarding your plan to deprecate and why we should deprecate are SuperImportant™. I'm 100% in agreement with 2 and moving forward with implementation on 1. (But not in this PR, see "next steps" below.)
Instead of this information being buried here, however, what would be really helpful is having this plan communicated in an Issue for visibility and alignment. I'm very interested in the move to a "faster toolchain" (tell me more!), I just don't know what that means, when it would happen, what it will require, etc.
I think I understand what you mean by "introducing more uncertainty". In this PR, we are deprecating bablerc, but because it won't throw an app error anymore you are concerned it will be confusing, correct? I could go either way. Regardless, I think we can resolve this with 1) good Release Note communication and 2) a two-step process to full deprecation (e.g. move forward with v0.36 and throw if present in v0.37).
Next Steps
We've been 2 weeks on this bug as a critical-path blocker to releasing v0.36. The code here is an improvement and, most importantly, resolves the release-blocking bugs.
- I'll approve and merge, then cut the v0.36 release branch
- I'll open an Issue with these next steps for v0.37
- PP, I'll leave next steps regarding communicating a plan for item 2 above (babel + faster toolchain) if applicable
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.
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.
And the current Release Notes draft is very clear about the Breaking change + Code Mods regarding I want people to delete api/.babelrc.js, or to convert it to api/babel.config.js and remove the "extends" part.
— says this explicitly.
Sound good?
['@babel/plugin-transform-typescript', undefined, 'rwjs-babel-typescript'], | ||
[ | ||
require('@redwoodjs/core/dist/babelPlugins/babel-plugin-redwood-src-alias') | ||
.default, |
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.
Did you manage to fix this by making it inline? Super weird behaviour, it should be ignore node_modules.
'babel-plugin-module-resolver', | ||
{ | ||
alias: { | ||
src: rwWebPaths.src, | ||
}, | ||
root: [getPaths().web.base], | ||
// needed for respecting users' custom aliases in web/.babelrc | ||
// See https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#cwd | ||
cwd: 'babelrc', | ||
loglevel: 'silent', // to silence the unnecessary warnings | ||
}, |
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.
Does the rw alias plugin I wrote not work in this case?
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 suggest we don't use that here for now - because there's a chance people may have custom aliases setup (like Burnsy).
My suggestions: keep as is, and in a later PR - we add support for specifying your own aliases, and ask users to migrate to this new system.
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.
Maybe we can be clever, and just read their tsconfig/jsconfig instead of them having to specify it somewhere else.
And get rid of the module-resolver plugin all together ☠️
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.
Using ours would not invalidate them using theirs.
packages/cli/src/commands/exec.js
Outdated
[ | ||
'babel-plugin-module-resolver', | ||
{ | ||
alias: { | ||
$api: getPaths().api.base, | ||
}, | ||
}, | ||
'exec-$api-module-resolver', | ||
], | ||
], |
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 would kick this babel plugin out and try to use the one I wrote.
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.
Mind pointng me to the plugin please? Didn't realise you added 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.
Here you go! I really struggled with the other one:
redwood/packages/internal/src/build/api.ts
Lines 88 to 94 in 8e3f9c6
[ | |
require('@redwoodjs/core/dist/babelPlugins/babel-plugin-redwood-src-alias'), | |
{ | |
srcAbsPath: rwjsPaths.api.src, | |
}, | |
'rwjs-babel-src-alias', | |
], |
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.
It does not support multiple alias, just "srcAbsPath", but it makes the files relative in the resulting ast.
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.
Oh, I guess in this case it WOULD not work. Sorry, super tired, but for pre-render it would work
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.... I think we should leave this as is for now in that case. Because one of the changes I made a while ago was to support user defined aliases (like in Burnsy's project).
What do you think of leaving this for now (to make it non-breaking) - and switch everything over (including babel-preset) and remove babel-plugin-module-resolver once we get to pre-transpiling web?
…ed-babel-location-require-hook * 'main' of github.com:redwoodjs/redwood: [v0.36] Adds ability to test api functions (#3207)
All comments addressed! |
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.
Approved. Moved next steps here for v0.37 "Full deprecation of .babelrc.js" #3245
Critical fix for v36 release - to be able to run
rw console
,rw exec
andrw dm
commands.The issue was the removal of
.babel.rc.js
from the api side here: #3187 so these commands could not regsiter the babel hookWhat does this do?
@redwoodjs/internal
, so they all work consistentlyWhat this PR won't do
Outstanding