-
Notifications
You must be signed in to change notification settings - Fork 2
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
Babel v7 compatibility #3
Conversation
- Updated dependencies. - Plugin options now an object instead of a string (Babel v7 requirement). - Options default to use `object-assign`. - Replaced `lodash.assign` in examples with `object-assign`. - Updated tests and fixtures. - Updated readme.
Package lock files are for apps, not packages; npm blacklists them from ever being published.
Please don't merge until I have a chance to integrate @babel/helper-module-imports, to fix #1. |
Fixes newoga#1. Also improves the fixuture expected outputs.
@jaydenseric This looks great. And looks like you wrapped up integrating @babel/helper-module-imports as well. Let me know if you're wrapped up.
That's interesting. If you're willing, I think this use case would great to add to the Thanks for your contribution! 👍 |
FYI I'm wondering what the best plan should be for releasing. Since this is a breaking change, we should consider a major bump (even though the previous version technically never was released at v1). Since babel v7 is still in beta, I'm wondering whether or not we should publish this in |
I think this PR is ready, but won't be sure until I can test it locally on my real project using As for documenting the React optimization use case, I would like to streamline a recipe for it for a while first because the const { engines: { node } } = require('./package.json')
module.exports = {
comments: false,
presets: [
{ plugins: ['babel-plugin-transform-replace-object-assign'] },
[
'@babel/env',
{
targets: { node: node.substring(2) }, // Strip `>=`
modules: process.env.MODULE ? false : 'commonjs',
loose: true
}
],
['@babel/preset-react', { useBuiltIns: true }]
],
plugins: [
[
'@babel/plugin-proposal-object-rest-spread',
{ loose: true, useBuiltIns: true }
],
['@babel/proposal-class-properties', { loose: true }]
]
} For the release plan, maybe |
Okay, sounds good. Let me know what you find. I haven't moved to babel 7 in my projects yet so I don't have anything real to test this on. That being said, I did pull this and ran the tests, which all looked good. But I do have some questions regarding the new fixtures. I will leave comments on the changes.
Makes sense to me, once we iron out the kinks I'm fine going straight to beta unless we think API could 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.
I think the big question I have is with the test fixtures and making sure the expected.js
files reflect what we're trying to test. It seems like the expected result is properly importing the configured Object.assign
replacement but is not using it. Let me know what you think.
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
(0, _simpleAssign2.default)({ a: 1 }, { b: 2 }); | ||
(0, _simpleAssign2.default)({ c: 3 }, { d: 4 }); | ||
_objectAssign({ |
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.
@jaydenseric Should this be _simpleAssign
if this is working correctly?
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 super confused. How come the tests used to pass with _simpleAssign
expected, when the UID was hardcoded to objectAssign
all along?
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.
Yeah, me too. It's be a while since I have looked at this (and babel plugin development in general). But it's possibly that in babel v6, babel always generated the UID for an import based on the package here. The generateUidIdentifier('objectAssign')
may have been unnecessary/unused. Can't confirm that at the moment.
Finding issues when testing it on my project (although I worked out the regenerator runtime issue was something unrelated). I was seeing I don't know why the tests here don't exhibit the issue, but addDefault(
file.path,
moduleSpecifier,
{nameHint: file.get(OBJECT_ASSIGN).name} // <-- This
) Since doing that though, now I always get Note that all along, the instances in code are correctly |
That's interesting. Yeah, the tests also confuse me. The tests seem to indicate the plugin isn't working.
In your project, out of curiosity, are all the |
No, with |
And sorry if I'm misunderstanding, but you're saying that it is correct behavior for the calls to use |
@jaydenseric I'm sorry I can't be more helpful regarding the babel Is there any other documentation that says otherwise? That being said, I'm still puzzled why It's past 1am in my timezone. I can investigate this more in the morning. Let me know what you find! Thanks again @jaydenseric. 😄 |
This is a good reference: https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-runtime/src/index.js#L154 |
Using prettier. Sorry, I could not live without it.
- Only destructure out the config when it is needed. - No need to set an import name hint.
@newoga I think it's ready! Tested it out in the project, and it seems to work ok. Please take a look over the assertions, as I have updated them again; they now look more similar to what you originally had. |
You can see it in action here: https://github.com/jaydenseric/graphql-react/blob/master/.babelrc.js#L6 |
Just pulled the latest, looks great! 👍And surprised to see the apollo I have a few nit-picky things I'd like to add. If you have the time to tackle these I'd really appreciate it, otherwise, I can do them later this evening.
I think we can do a release today as well. I'm half-tempted to release a new version of this plugin that supports babel v6 with the |
Also, forgot to mention, that new implementation of the plugin is super simple and clean. 👍 👍 |
This commit is based on the new API proposed by @jaydenseric in his PR #3. His PR primarily adds support for babel 7. The PR also introduces some necessary breaking changes to the plugin configuration. This commit takes his new API and backports it to the babel 6 supported version of this plugin to ease migrations. The API changes are: 1. Configuration is now optional. If no config is provided, `object-assign` is used. 2. String based configuration is no longer supported. It must be an object with a `moduleSpecifier` key. Documentation was updated and a new test fixture was addded to test the new default configuration behavior.
But first pretty everything, with semicons.
@jaydenseric I'm going to cut a |
@jaydenseric I'm all wrapped up. Let's rebase this (might be a bit messy, sorry! 🙏) and merge! Edit: Essentially for the merge, you can keep your version of all the changes, the only really nasty file might be the |
# Conflicts: # README.md # src/index.js # test/index.js Also, fixed tests and prettied code.
# Conflicts: # lib/index.js
@jaydenseric All wrapped up? I pulled the latest and everything looks good to me. We just need to add a note in the I'm ready to merge when you are though 👍 |
It's ready! |
Thanks again @jaydenseric. This landed as |
With this update, the package should be compatible with both Babel v6 and v7.
simple-assign
dependency.moduleSpecifier
:object-assign
:babel-plugin-transform-replace-object-assign
is to optimize React projects by configuring all plugins to output theObject.assign
builtin (instead of helpers), then instead of polyfilling, replace all occurrences with the sameobject-assign
dependency used by React.declar
todeclare
variable name typo fix.sourceType
ismodule
orscript
.lodash.assign
in readme examples withobject-assign
. It looks more intuitive and demos the defaults.