jonschlinkert / extend-shallow

Extend object A with the properties of object B. node.js/javascript util.
https://github.com/jonschlinkert
MIT License
33 stars 12 forks source link

Do you wanna PR for ES2015 modules? #3

Open tunnckoCore opened 7 years ago

tunnckoCore commented 7 years ago

It is very much used everywhere and by me too. So I can PR to create it both CJS and ES2015 compatible. So later when some modern bundlers like Webpack and Rollup can resolve es2015 module.

The simplest thing is just pass jsnext:main: path/to/file.with.es2015.exports.js and the current main will remain the same.

Rollup and Webpack2 understands jsnext:main and module fields, so when they do bundling they will resolve that files, not the CJS main.

Specifically, Rollup has plugin to convert CJS to ES2015 modules, but it won't do the tree-shaking magic, so it will be possible to duplicate exact that extend-shallow code multiple times if found multiple times.

tunnckoCore commented 7 years ago

It would be just

import isObject from 'is-extendable';

export default function extend(o/*, objects*/) {
  if (!isObject(o)) { o = {}; }

  // ... code
};

also converting is-extendable to es2015 would be good too.

edit: haha, i jumped to that train a bit and it's very inspiring and funny :laughing: :rocket:

jonschlinkert commented 7 years ago

Why? There is no advantage in doing this. It would only make it less compatible and slower.

tunnckoCore commented 7 years ago

Less compatible with what? Slower? Why?

The current code won't be even touched. We just need one more file with just ES2015 modules definitions and one more field in package.json which will help ES2015 aware bundlers to do their job better.

The advantage is lower duplication of code (in the bundle) and smaller install times for the user. And all that without any costs (except that npm package will have one more file in it).

jonschlinkert commented 7 years ago

The current code won't be even touched. We just need one more file with just ES2015 modules definitions and one more field in package.json which will help ES2015 aware bundlers to do their job better.

this is what you should start the issue with next time lol. sure, that's fine with me

tunnckoCore commented 7 years ago

haha

I thought that will be enough:

So I can PR to create it both CJS and ES2015 compatible.

But yea.. I'm bot. :dagger:

Okey, i'll send a pr this night

jonschlinkert commented 7 years ago

sorry, lol. Sometimes I have to skim issues and I missed the important part of your comments.