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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] Build step for compiling to CommonJS modules #417

Merged
merged 15 commits into from
Jun 16, 2017

Conversation

fuller
Copy link
Contributor

@fuller fuller commented Jun 16, 2017

Ran into an issue today while trying to update to version 2.0 with errors throwing because of the the static property on the class. Would like to avoid running babel against anything in node_modules, so ideally we'd have a transpiled main field and a module field that points to an ES module build.

The following changes are based on the build steps from Redux repo: https://github.com/reactjs/redux/blob/master/package.json

Changes proposed:

  • Move all main source code under src so that lib and es can be used for the built files
  • Entry index.js is now an ES export
  • Move create-react-class to dev dependency as it appears to be no longer necessary in the main library Now removed entirely

I've tested this locally with npm link and everything seems to be working as expected.

Note that there are more build changes that we could make as well, but this solves the initial issue I was seeing 馃樃

Upgrade Path (for changed or removed APIs):

Acceptance Checklist:

  • All commits have been squashed to one.
  • The commit message follows the guidelines in CONTRIBUTING.md.
  • Documentation (README.md) and examples have been updated as needed.
  • If this is a code change, a spec testing the functionality has been added.
  • If the commit message has [changed] or [removed], there is an upgrade path above.

.babelrc Outdated
"presets": ["react"],
"env": {
"commonjs": {
"plugins": [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Supposedly the env and non-env configs should merge, but I was seeing the below issue when I tried to consolidate. Any help is appreciated.

Tried this:

{
  "presets": ["react"],
  "plugins": [
      "transform-class-properties", 
      "transform-object-rest-spread"
  ],
  "env": {
    "commonjs": {
      "presets": ["env"]
    },
    "es": {
      "presets": [
        ["env", { "modules": false }]
      ]
    }
  }
}

Got this:
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can use the old .babelrc to fix v2.0.0. I think we need to use latest instead of stage-2.

Copy link
Collaborator

@diasbruno diasbruno Jun 16, 2017

Choose a reason for hiding this comment

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

latest isn't enough for this. 'stage-2` should work.

Copy link
Collaborator

@diasbruno diasbruno Jun 16, 2017

Choose a reason for hiding this comment

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

Actually after some tests, .babelrc is working as expected, but the main in package.json is pointing to the non-compiled version. Your change to compile from src to lib should fix without to much change (I believe).

@coveralls
Copy link

coveralls commented Jun 16, 2017

Coverage Status

Coverage decreased (-13.2%) to 71.429% when pulling 965a2c3 on ajfuller:master into ec6b8e5 on reactjs:master.

@fuller
Copy link
Contributor Author

fuller commented Jun 16, 2017

Will wait to squash commits until I address any review comments

@diasbruno
Copy link
Collaborator

diasbruno commented Jun 16, 2017

Awesome, @ajfuller. This seems close to the commit I forgot to port from the old master (9cb8441).
You can use it as reference.

.babelrc Outdated
"presets": ["react"],
"env": {
"commonjs": {
"plugins": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can use the old .babelrc to fix v2.0.0. I think we need to use latest instead of stage-2.

@diasbruno
Copy link
Collaborator

diasbruno commented Jun 16, 2017

yarn.lock can be removed as the build pipeline will add it when making the release commit. I'll update the documentation explaining the build and publish pipeline later.

.babelrc Outdated
"presets": ["react"],
"env": {
"commonjs": {
"plugins": [
Copy link
Collaborator

@diasbruno diasbruno Jun 16, 2017

Choose a reason for hiding this comment

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

Actually after some tests, .babelrc is working as expected, but the main in package.json is pointing to the non-compiled version. Your change to compile from src to lib should fix without to much change (I believe).

package.json Outdated
@@ -55,14 +56,13 @@
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"rf-release": "0.4.0",
"rimraf": "^2.5.4",
"rimraf": "^2.6.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

rimraf dependency can be removed.

.gitignore Outdated

## Built folders
es
lib
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think lib can't be ignored. You can remove es.

@coveralls
Copy link

coveralls commented Jun 16, 2017

Coverage Status

Coverage increased (+0.2%) to 84.821% when pulling a3e0332 on ajfuller:master into ec6b8e5 on reactjs:master.

@fuller
Copy link
Contributor Author

fuller commented Jun 16, 2017

@diasbruno I can remove, but wouldn't you want the yarn.lock to be up-to-date for development as well? I'll wait for the documentation updates 馃槃

@fuller fuller changed the title [added] Create separate build step for ES and CommonJS modules [added] Build step for compiling to CommonJS modules Jun 16, 2017
@coveralls
Copy link

coveralls commented Jun 16, 2017

Coverage Status

Coverage increased (+0.2%) to 84.821% when pulling d13e966 on ajfuller:master into ec6b8e5 on reactjs:master.

@diasbruno
Copy link
Collaborator

The new pipeline will guarantee that what has been changed on package.json will get on the new release.

@fuller
Copy link
Contributor Author

fuller commented Jun 16, 2017

@diasbruno I've merged your PR with mine and addressed the outstanding comments 馃憤

@coveralls
Copy link

coveralls commented Jun 16, 2017

Coverage Status

Coverage increased (+0.2%) to 84.821% when pulling 846e65b on ajfuller:master into ec6b8e5 on reactjs:master.

@fuller
Copy link
Contributor Author

fuller commented Jun 16, 2017

@diasbruno everything is passing CI now 馃憤

@diasbruno
Copy link
Collaborator

I think we are ready to ship! Thank you so much @ajfuller.

@diasbruno diasbruno merged commit 435ab91 into reactjs:master Jun 16, 2017
@diasbruno
Copy link
Collaborator

Released v2.0.1.

davidrunger referenced this pull request in hired/react-modal Oct 16, 2017
This repeats [the work][0] done on [@JonAbrams 's fork][1] of
[reactjs/react-modal][2]. However, it replays the work on top of the
latest `master` of `reactjs/react-modal`, so it should stop the
PropTypes warnings that it has been generating for quite a while now:
```
Warning: Accessing PropTypes via the main React package is deprecated,
and will be removed in  React v16.0. Use the latest available v15.*
prop-types package from npm instead. For info on usage, compatibility,
migration and more, see https://fb.me/prop-types-docs
```

This also brings the fork under the Hired GitHub organization, rather
than on a former employee's personal GitHub, so that should be good,
too.

[0]: JonAbrams@53139fa
[1]: https://github.com/JonAbrams/react-modal
[2]: https://github.com/reactjs/react-modal
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.

None yet

3 participants