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

Remove lodash as a dependency #35

Merged
merged 10 commits into from
Sep 15, 2018
Merged

Conversation

jonpitch
Copy link
Contributor

Fixes #34 by removing lodash and replacing with Ember's merge polyfill. I played it safe here instead of just using Object.assign, but feel free to modify depending on how many browsers you need to support.

package.json Outdated
@@ -32,24 +31,24 @@
"broccoli-asset-rev": "2.6.0",
"ember-ajax": "3.0.0",
"ember-bootstrap": "1.2.0",
"ember-cli": "~3.0.0-beta.2",
"ember-cli": "^3.1.4",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont use ^ in packages.

@@ -34,7 +34,7 @@ export default Service.extend({
}).readOnly(),

rollbarClient(customConfig = {}) {
let config = deepMerge({}, this.get('config'), customConfig);
let config = merge({}, this.get('config'), customConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a big difference between merge and deepMerge :/ We definitely need the second one.

package.json Outdated
@@ -23,7 +23,6 @@
},
"dependencies": {
"ember-cli-babel": "6.11.0",
"ember-lodash": "4.18.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just use lodash.merge package and shim it.

package.json Outdated
"ember-cli-dependency-checker": "2.1.0",
"ember-cli-eslint": "4.2.3",
"ember-cli-fastboot": "1.1.3",
"ember-cli-favicon": "1.0.0-beta.4",
"ember-cli-favicon": "^1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no upgrades please in this PR

@jonpitch
Copy link
Contributor Author

@Exelord moving ember-lodash to a devDependency had the effect I was going for and the addon still seems to work as expected in my app. I came across this issue where it looks like I had an older version of broccoli-concat-analyser, so my initial report in #34 was off. The actual savings in my app is ~65k.

In regards to the deep merge, if that's needed for merging Rollbar configs, maybe some test coverage there would be good? I can add that; I just couldn't think of the use case.

@Exelord
Copy link
Member

Exelord commented Jul 1, 2018

Can we move it to devDependencies? We are using it in production code, to it has to be compiled using this packages.

Yes we need that. If you'll look here https://github.com/Exelord/ember-rollbar-client/blob/master/config/environment.js
you'll see there is nested object. As we are allowing on overwriting we have to use deepMerge.
Otherwise having a config like:

{
  payload: {
    test: true,
  }
}

and passing in rollbar service:

{
  payload: {
    test2: true,
  }
}

will result:

{
  payload: {
    test2: true,
  }
}

which will overwrite the object and remove the test key

@jonpitch
Copy link
Contributor Author

jonpitch commented Jul 1, 2018

Thanks for the explanation @Exelord that was really helpful. I missed the part of the readme that specified users could create a new Rollbar instance, thus requiring the deep merge.

I added a test for that and brought in just lodash.merge. I also brought in ember-auto-import to make things a little easier. This is failing in CI; so I'm open to using a vendor-shim or something, but I'm less familiar with how that would work here.

We could always add our own implementation of a deep merge, something like this is probably sufficient and passes the test.

@st-h
Copy link

st-h commented Jul 1, 2018

We could always add our own implementation of a deep merge, something like this is probably sufficient and passes the test.

haha, I was gonna write a merge function tonight, as that should be doable in just a few lines of code - given that we very likely do not need very complex logic to just merge the configs. Great you already found something that works.

Totally in favour of removing lodash though. I was wondering where that dependency comes from in our app a few days ago, but did not have the time to look further into it so far. Needless to say that it was significantly increasing the size of our app.

@jonpitch
Copy link
Contributor Author

@Exelord is there anything preventing this from being merged?

I also added a small change here to resolve the rollbar path a little differently. The way it was broke a mono-repo that I was using this dependency in. This should work in both cases, per this discussion.

package.json Outdated
@@ -55,7 +54,7 @@
"ember-maybe-import-regenerator": "^0.1.6",
"ember-resolver": "4.5.0",
"ember-scroll-to": "0.6.4",
"ember-source": "~3.0.0-beta.6",
"ember-source": "~2.12.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we downgraded?

@@ -29,6 +30,27 @@ test('currentUser', function(assert) {
assert.equal(service.get('notifier.options.payload.person.name'), 'User');
});

test('new rollbar client - deep merge config', function(assert) {

This comment was marked as outdated.

@@ -0,0 +1,52 @@
// from https://github.com/tchak/ember-fetch-adapter/blob/master/addon/-private/merge.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an util under addon/utils/deep-merge.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why we dont use here a lodash one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway we need full pack of tests for it

@@ -0,0 +1,52 @@
// from https://github.com/tchak/ember-fetch-adapter/blob/master/addon/-private/merge.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why we dont use here a lodash one?

@@ -0,0 +1,52 @@
// from https://github.com/tchak/ember-fetch-adapter/blob/master/addon/-private/merge.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway we need full pack of tests for it

@jonpitch
Copy link
Contributor Author

@Exelord pr feedback addressed. Per your feedback, I reverted the deepMerge function in favor of using lodash.merge. To bring that module in, I opted for ember-cli-cjs-transform over ember-auto-import which adds 17kb to the vendor build. This does mean that consumers will get the cjs transform included though.

If you know of a better way to shim that in, let me know. I also left the deep merge config test, since you don't have tests anywhere else for that. If you'd like me to move it or add coverage, please help me by identifying some use cases of merging rollbar configs.

@Exelord
Copy link
Member

Exelord commented Aug 26, 2018

Thank you! All looks good! There is just one thing. There is a difference between ember-cli-cjs-transform and ember-auto-import. Once is for transforming cjs modules to es6 and the second one allows you import dynamically node modules. Thats why in that case I would prefer to go with auto-import as cjs-transform is not needed here as this package already export es6 module.

@jonpitch
Copy link
Contributor Author

jonpitch commented Aug 26, 2018

@Exelord understood, i was hesitant to use ember-auto-import because it does add 17Kb to the build, which seems excessive to invoke a function. Is there any other way that you would be ok with?

@Exelord
Copy link
Member

Exelord commented Aug 27, 2018

Well it depends if we want to still support ember 2.12. What do you think?

@jonpitch
Copy link
Contributor Author

I think that's up to you, but I don't believe ember-auto-import supports back to 2.12.

@Exelord
Copy link
Member

Exelord commented Aug 29, 2018

Ok I have a solution. Lets manually push it to vendor folder and import from there. The same as we do with rollbar. check index.js for more info :)

@PoslinskiNet
Copy link
Contributor

I would vote for dropping 2.12 support. It's about time to do so (almost 3.4 is here).

@Exelord
Copy link
Member

Exelord commented Aug 29, 2018

I think we should drop it when Ember-cli will do it, so that we can keep compatibility with everything supported by ember officially. It should be deprecated September 10th 2018 then we may drop it :)

@PoslinskiNet
Copy link
Contributor

Agree. So few more days left and Lodash is completely gone :) ?

@Exelord
Copy link
Member

Exelord commented Aug 29, 2018

Probably :) ... well Lodash will be still with us ;) ... but just one module

package.json Outdated
"git-repo-version": "1.0.2",
"lodash.merge": "^4.6.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change ^ to ~?

package.json Outdated
@@ -24,8 +24,9 @@
"dependencies": {
"broccoli-funnel": "^2.0.1",
"ember-cli-babel": "6.11.0",
"ember-lodash": "4.18.0",
"ember-cli-cjs-transform": "^1.3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change ^ to ~?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Exelord are we sticking with ember-cli-cjs-transform or going the vendor route? I pushed your recent feedback here, but if you want to go the vendor route, I'll need some more guidance there.

I'm not as familiar with broccoli trees; I follow bringing in the dependency through the vendor tree, but it's unclear how to import it in the service.

@@ -2,7 +2,7 @@ import { getOwner } from '@ember/application';
import { computed } from '@ember/object';
import Service from '@ember/service';
import Rollbar from 'rollbar';
import deepMerge from 'lodash/merge';
import merge from 'lodash.merge';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename it to deepMerge? it's more meaningful to what it does.

@Exelord
Copy link
Member

Exelord commented Sep 1, 2018

Perfect :) Lets wait then for Ember 2.12 deprecation

@Exelord
Copy link
Member

Exelord commented Sep 6, 2018

I see in ember-cli 3.4 there is still support for 2.12 :/

@st-h
Copy link

st-h commented Sep 7, 2018

can we please remove that lodash thing one way or the other? That dependency is large enough to make us switch to another rollbar client (or publish just another one :trollface: )
I don't think dropping support for 2.12 will be a major issue. If one needs to use this addon within ember 2.12 the previous versions including lodash still are available. However, we could still use a custom implementation to merge the config if supporting 2.12 is crucial.

@Exelord
Copy link
Member

Exelord commented Sep 7, 2018

Conflicts

@jonpitch
Copy link
Contributor Author

jonpitch commented Sep 7, 2018

@Exelord any ideas on the CI failures?

@Exelord
Copy link
Member

Exelord commented Sep 7, 2018

Try to remove this thing: importTransforms: require('ember-cli-cjs-transform').importTransforms, :/

@jonpitch
Copy link
Contributor Author

jonpitch commented Sep 8, 2018

@Exelord I think that's needed so we don't break consuming applications. There's an open issue about it here

All of the ember-try scenarios pass for me locally. Maybe you could clear the Travis cache and re-run the build?

@Exelord
Copy link
Member

Exelord commented Sep 8, 2018

It looks like this issue is on travis or sth. I see its everywhere without any change on multiple projects
https://travis-ci.org/minutebase/ember-can/jobs/426134012

@kimek
Copy link

kimek commented Sep 14, 2018

Any updates from travis ? I've check logs, configs, code and couldn't find any problems with it. Did you try run this again @Exelord ? Great job with this pull request btw !

@Exelord
Copy link
Member

Exelord commented Sep 14, 2018

Restarted one more time. (clean cache)

@Exelord
Copy link
Member

Exelord commented Sep 15, 2018

Eh... ok merging that. Tests are not related

@Exelord Exelord merged commit 544b19b into EmberExperts:master Sep 15, 2018
@kimek
Copy link

kimek commented Sep 25, 2018

is there a chance to make a release for it ?

@Exelord
Copy link
Member

Exelord commented Sep 25, 2018

#40 This one should fix the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants