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

feat: update default npm export to ES5 js files #3245

Merged
merged 23 commits into from
Sep 28, 2018

Conversation

moog16
Copy link
Contributor

@moog16 moog16 commented Jul 26, 2018

Currently npm is setup to export /index.js by default. The index.js file is ES6 and less universally accepted by other developers. This PR is to support those developers that are on other versions of EcmaScript, by exporting by default the dist js file.

Refs #929

See also material-components/material-components-web-react#107

BREAKING CHANGE: Anyone intending to build MDC Web's ES2015+ sources must directly import @material/foo/index. @material/foo will now resolve to UMD modules.

@@ -9,7 +9,6 @@
"material design",
"tab"
],
"main": "index.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this because this isn't a package. Developer should be installing mdc-tabs

Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect. mdc-tab is part of the new tabs work being done in the feat/tabs/tabs branch. Users will be installing this as well as mdc-tab-bar, mdc-tab-scroller, and mdc-tab-indicator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah gotcha...I saw the export {MDCTabFoundation, MDCTab} from './tab'; line in mdc-tabs, and thought it to be this mdc-tab package. Just missing a . to become ../tab

Copy link
Contributor

Choose a reason for hiding this comment

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

This was never updated after my comment. Also, mdc-tab-bar, mdc-tab-scroller, and mdc-tab-indicator were added since this.

@mdc-web-bot
Copy link
Collaborator

All 128 screenshot tests passed for commit b55f5cc vs. master! 💯🎉

@codecov-io
Copy link

codecov-io commented Jul 26, 2018

Codecov Report

Merging #3245 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3245   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files         120      120           
  Lines        5212     5212           
  Branches      654      654           
=======================================
  Hits         5132     5132           
  Misses         80       80

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5978499...3cbdb21. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 128 screenshot tests passed for commit e43c556 vs. master! 💯🎉

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

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

I would rather hold off on merging this until we can try and test a few things...

For instance, does this actually break every README we have which states import {MDCFoo} from '@material/foo'; because main no longer points to the main ES6 module?

@moog16
Copy link
Contributor Author

moog16 commented Jul 31, 2018

I think we'll also need to do a similar change as this PR: material-components/material-components-web-react#198

@kfranqueiro
Copy link
Contributor

That's precisely the kind of thing I'm concerned about. I think that corroborates my concern about needing to update any ES2015 examples in our READMEs, because they would need to explicitly point to /index now.

Incidentally, our modules themselves should already be referencing /index where necessary, since #2111 was a thing. Otherwise we'd potentially have problems even in the module code itself.

@moog16
Copy link
Contributor Author

moog16 commented Jul 31, 2018

Would we want to point to the /index or the /dist/mdc.foo.js files? I believe we would want to point to /dist/mdc.foo, since pointing to /index wouldn't fix the issue.

Currently our readmes don't point to /index now, so why would they need to now? I think what #1991 is referring to is that Webpack/node will default to whatever the package.json main's prop is set to.

@kfranqueiro
Copy link
Contributor

kfranqueiro commented Jul 31, 2018

Would we want to point to the /index or the /dist/mdc.foo.js files? I believe we would want to point to /dist/mdc.foo, since pointing to /index wouldn't fix the issue.

Currently our readmes don't point to /index now, so why would they need to now? I think what #1991 is referring to is that Webpack/node will default to whatever the package.json main's prop is set to.

Do transpilers honor package.json's main property when resolving imports the way that node itself does? If they do, then all of our documented ES2015 usages would break, because they're all simply referencing the directory, not a specific file, and what they reference would change when we change main. This would also presumably break a large percentage of any end-user code that consumes our ES2015 modules.

@moog16
Copy link
Contributor Author

moog16 commented Aug 16, 2018

I wrote up a blog post of my learnings of the benefits of having npm packages export ES5 instead of ES6.

https://medium.com/@moog16/rules-of-npm-packaging-16a40c5d7e30

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

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

This is out of date with master and it looks like there are potentially some merge conflicts that are going to happen, based on what github is saying.

Also note that we've added more packages since this was opened (e.g. the new mdc-tab* packages, mdc-switch JS, and mdc-menu-surface).

Also, I don't know why this wasn't reported in CI, but I see a lot of test failures when I run unit tests locally. I also see incorrect coverage reports (and coverage well below the required 95% mark). Some of the coverage reports are now pointing to dist. I assume this is due to needing tests to explicitly reference mdc-foo/index after these changes, similar to material-components/material-components-web-react#198. (It concerns me that apparently the MDC React repo went over an entire month without correct coverage... we can't do that with MDC Web.)

I'm also still wanting to understand how our documented ES6 syntax still happens to work even when the entry point references the UMD files. I'd also like to know whether our getting started guide is impacted by this change at all.

@@ -9,7 +9,6 @@
"material design",
"tab"
],
"main": "index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

This was never updated after my comment. Also, mdc-tab-bar, mdc-tab-scroller, and mdc-tab-indicator were added since this.

@@ -3,6 +3,7 @@
"version": "0.37.1",
"description": "The Material Components for the web top app bar component",
"license": "Apache-2.0",
"main": "mdc.topAppBar.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing dist?

@mdc-web-bot
Copy link
Collaborator

All 353 screenshot tests passed for commit 21955dd vs. master! 💯🎉

@@ -8,7 +8,7 @@
"material design",
"form"
],
"main": "index.js",
"main": "mdc.formField.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing dist

@@ -3,6 +3,7 @@
"description": "The Material Components for the web linear progress indicator component",
"version": "0.38.0",
"license": "MIT",
"main": "dist/linearProgress.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing mdc.

@mdc-web-bot
Copy link
Collaborator

All 353 screenshot tests passed for commit cc1ee56 vs. master! 💯🎉

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

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

Since we're pointing all packages to compiled version, can we have module property which points to ES6 for ES6 aware tool like webpack?

Reference: Rollup.js - Publishing ES6 modules

@mdc-web-bot
Copy link
Collaborator

All 353 screenshot tests passed for commit 39f9f31 vs. master! 💯🎉

@moog16
Copy link
Contributor Author

moog16 commented Aug 22, 2018

Pushed changes and performed following:

Linux:
npm run test:unit (passes)
npm run start (chrome)
npm run dev (chrome)

Windows:
npm run test:unit (passes)
npm run start (ie11 & edge)
npm run dev (ie11 & edge)

npm run start is not working on this branch or master branch on Windows 10 - I don't think it is an issue, since there are some PWD and $ in the start script. So all is good (regarding this PR)

@mdc-web-bot
Copy link
Collaborator

All 353 screenshot tests passed for commit 2e58cd5 vs. master! 💯🎉

@kfranqueiro kfranqueiro added this to the R20 milestone Sep 27, 2018
@kfranqueiro kfranqueiro changed the title chore(infrastructure): update default npm export to ES5 js files feat: update default npm export to ES5 js files Sep 27, 2018
@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit 853f2d5 vs. master! 💯🎉

```

Note that in this case, you must ensure your build toolchain is configured to process and transpile MDC Web's modules
as well as your own. You will also need to include babel's `transform-object-assign` plugin for IE 11 support.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I had intended to look into the right place to add that to getting-started, thanks for reminding me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've fixed that in #3665, since that PR was already touching the lines around that point in the file. That way hopefully it'll merge cleanly the next time we sync this PR.

@@ -0,0 +1,66 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome script! Tested it and works nicely

@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit ecacefc vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit b1c6e83 vs. master! 💯🎉

@kfranqueiro
Copy link
Contributor

Matt performed some tests with various build tools (e.g. browserify and webpack), and I tested this against our catalog and getting started guide. Between that and getting positive feedback from James on RMWC and Dominic on angular-mdc-web, I think we can merge this.

@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit 44dde56 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit 7fcf8f1 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 581 screenshot tests passed for commit 3cbdb21 vs. master! 💯🎉

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

Successfully merging this pull request may close these issues.

6 participants