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

Use ES6 modules, use rollup for module bundling #198

Merged
merged 9 commits into from
Feb 27, 2017

Conversation

simon04
Copy link

@simon04 simon04 commented Feb 4, 2017

  • modularize the code using ES6 modules
  • use rollup for bundling (replaces browserify)
  • separate holiday file per country in holidays/
  • run make opening_hours.js to get the bundled file w/o embedded dependencies

@ypid
Copy link
Member

ypid commented Feb 5, 2017

Thanks very much for the PR! I guess I should do a release before I review and merge this 😉

@pke
Copy link

pke commented Feb 13, 2017

Looks interesting. I was planing a code split myself, but using webpack. Basically I think this library should be componentized in a way that the base file just uses the holidays and translations already loaded. Meaning when someone wants to include the script one has to include the required holidays and translations before the core script file. The holiday and language files will register themselves globally under opening_hours.holidays etc.

In SPA based the holidays and languages could then be imported first and opening_hours last:

import "opening_hours/holidays/de"
import oh from "opening_hours/core"

// -- or import all holidays
import "opening_hours/holidays"
import oh from "opening_hours/core"

// -- or import all at once
import oh from "opening_hours"

What u think?

The library is just too huge at the moment with ~350kb. I guess the majority of this is coming from holidays (strings).

@ypid ypid added this to the v3.6.0 milestone Feb 17, 2017
@ypid
Copy link
Member

ypid commented Feb 17, 2017

I finally enabled Travis CI testing for this project and made a release.

Can you try to get the build passing? And don’t worry about the merge conflict.

@@ -0,0 +1,19 @@
export {default as at} from './at.js';
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to have the holidays as simple JSON files for interoperability reasons. Seems like rollup-plugin-json could come in handy for this. Does this make sense and can you try it?

Copy link
Member

Choose a reason for hiding this comment

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

I just found that there is also a YAML plugin ❤️ So I would prefer YAML. But I can also convert that later.

rollup.config.js Outdated
format: 'cjs',
plugins: dependencies ? [
nodeResolve(),
common()
Copy link
Member

Choose a reason for hiding this comment

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

Can you end all list items with a comma please? This makes moving items around really easy and I hate that JSON does not allow this.

Copy link

Choose a reason for hiding this comment

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

@ypid so can be enforced on ci by running eslint with the associated eslintrc & dev requirement packages

Copy link
Member

@ypid ypid left a comment

Choose a reason for hiding this comment

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

Thanks very much. Looks good. Can you check the review comments?

Do you have an idea how to deal with the different formats now. The opening_hours.js is now only cjs, before it was also amd and iife at the same time. I guess I will just build those files on release and include them in the npm package?

rollup.config.js Outdated
export default {
banner: banner,
entry: './index',
format: 'cjs',
Copy link
Member

Choose a reason for hiding this comment

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

I guess you could also add: moduleName: 'opening_hours', so that --format iife works directly.

@simon04 simon04 force-pushed the rollup branch 2 times, most recently from 9af005f to 63d36f9 Compare February 20, 2017 21:00
@simon04
Copy link
Author

simon04 commented Feb 20, 2017

@ypid, thank you for the review. I hopefully addressed all comments plus performed the (cumbersome) extra tasks converting the holiday definitions to YAML.

@pke, let's address this in a separate issue/PR in order to not end up with one monster PR which is impossible to review.

@ypid
Copy link
Member

ypid commented Feb 20, 2017

@simon04 Thanks so much for you work, also with updating the holiday definitions! I have been working on a Python script to update YAML format over the last few days to solve #192 so this is coming together nicely.

But the older NodeJS versions, I guess https://babeljs.io/ can be used for that? Or maybe drop the const in rollup.config.js?

@ypid
Copy link
Member

ypid commented Feb 20, 2017

Could you make a changelog entry now that you rebased on latest master? 😉

@ypid
Copy link
Member

ypid commented Feb 20, 2017

You can drop support for legacy versions if you want to. According to the LTS schedule they are EOL anyway. I just supported them because interestingly when I tried with the latest NodeJS release, basically nothing broke.

@simon04 simon04 force-pushed the rollup branch 2 times, most recently from 28111dd to 8847cf1 Compare February 20, 2017 22:00
@simon04
Copy link
Author

simon04 commented Feb 20, 2017

Node.js: 0.12 compatibility is back. Had to amend my commit for CHANGELOG a few times to get the syntax for links right.

@simon04
Copy link
Author

simon04 commented Feb 20, 2017

Jay, all tests pass 😄

@ypid
Copy link
Member

ypid commented Feb 20, 2017

Awesome! I will be working on getting this merged the next days.

Used json2yaml plus manual copying of comments
@simon04
Copy link
Author

simon04 commented Feb 21, 2017

I rebased again and introduced an initial renaming commit 378b226 to retain the Git history for index.js. Additionally, I converted the locales/ strings to YAML format in 880b032.

Copy link

@shouze shouze left a comment

Choose a reason for hiding this comment

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

LGTM

@shouze
Copy link

shouze commented Feb 24, 2017

@ypid let's go for a merge?

@ypid
Copy link
Member

ypid commented Feb 24, 2017

Sure, working on it.

ypid added a commit to ypid/opening_hours.js that referenced this pull request Feb 26, 2017
ypid added a commit to ypid/opening_hours.js that referenced this pull request Feb 26, 2017
Copy link
Member

@ypid ypid left a comment

Choose a reason for hiding this comment

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

@simon04 Thanks very much, awesome work!

@ypid ypid merged commit 880b032 into opening-hours:master Feb 27, 2017
ypid added a commit that referenced this pull request Feb 27, 2017
@pke
Copy link

pke commented Mar 11, 2017

@simon04 now that this is merged, how can we make use of it in es6 to only include what one needs. Namely don't include all the holidays.

Also maybe u have a clue why the peer dependency of momentjs is still installed underneath this modules node folder even if my app already provided a newer momentjs library.

@ypid what for is moment js used here? For date calculation or merely to display dates and times? If the latter then maybe we could split that out in a new bundle.
If moment js is used for parsing dates or times then there are smaller es6 friendly Libs available . I'll open a new issue for that.

@ypid
Copy link
Member

ypid commented Mar 11, 2017

now that this is merged, how can we make use of it in es6 to only include what one needs.

What you are asking for is already tracked here #143 which should be used for discussion/constructive input (to which I pointed you already). This PR is not the right place.

what for is moment js used here?

The source is your friend. Currently only to get the list of weekdays in the configured language. But it is optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants