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

Build: move dependency transpilation config to calypso-build #38531

Merged
merged 1 commit into from
Jan 15, 2020

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Dec 19, 2019

Alternative to #33492 which still uses the special Babel config for transpiling dependencies, but moves it to the calypso-build package.

This PR, unlike #33492, doesn't attempt to transpile both app and node_modules code with the same Babel config. It keeps the separation and shouldn't cause any changes in output -- just moves code to a different location. That involves less risk in my opinion.

Also, this approach is in line with what Create React App does.

After merging this, calypso-build should start transpiling dependencies out of the box, without any configuration. Jetpack can just upgrade to the new version and be done.

How to test:
I'm not sure what's the right way to test if dependencies are still transpiled correctly. Load the calypso.live build in IE11?

@jsnajdr jsnajdr added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Build labels Dec 19, 2019
@jsnajdr jsnajdr requested a review from a team as a code owner December 19, 2019 12:11
@jsnajdr jsnajdr self-assigned this Dec 19, 2019
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

matticbot commented Dec 19, 2019

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@@ -112,6 +112,12 @@ function getWebpackConfig(
presets,
workerCount,
} ),
TranspileConfig.loader( {
cacheDirectory: true,
include: shouldTranspileDependency,
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll want to expose this to the user of calypso-build, as they may have dependencies that require transpilation that calypso does not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do users need to only expand the whitelist with new entries, or to also exclude some existing ones?

// general form is <package-name>/.
// The trailing slash makes sure we're not matching these as prefixes
// In some cases we do want prefix style matching (lodash. for lodash.assign)
'@github/webauthn-json/',
Copy link
Contributor

Choose a reason for hiding this comment

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

Would now be a good time to extend this to support semver?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is to have semver specifiers like debug@^3 in the whitelist and be able to read the package.json for a tested package and match the semver version?

That seems a big enough topic to warrant its own PR. We probably want to keep some cache of "file-path -> package-version" mappings, so that we don't do the look up for every file (every package can include a large number of contained files and webpack sees each sub-path separately).

'react-spring/',
'regenerate-unicode-properties/',
'regexpu-core/',
'striptags',
Copy link
Contributor

Choose a reason for hiding this comment

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

oop, this one should have a trailing /

Copy link
Member Author

Choose a reason for hiding this comment

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

If we go the semver route, and start exposing API for expanding the whitelist, then we should get rid of the trailing slashes and patch the matching algorithm instead.

@jsnajdr jsnajdr force-pushed the move/dependencies-transpile-to-build-package branch from c73ab27 to 96e5df3 Compare December 20, 2019 11:57
@jsnajdr jsnajdr force-pushed the move/dependencies-transpile-to-build-package branch from 96e5df3 to 136aa8a Compare January 14, 2020 11:57
@jsnajdr
Copy link
Member Author

jsnajdr commented Jan 14, 2020

I rebased this PR onto the latest master and it's still ready for review.

One open question is to whether to allow to customize the whitelist of transpiled dependencies and how.

We can also take the CRA route and start transpiling all node_modules dependencies except @babel/runtime, as they do.

@blowery @ockham @sgomes let me know if you have any concerns.

Copy link
Contributor

@sgomes sgomes left a comment

Choose a reason for hiding this comment

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

No concerns from my end. This makes sense to live in calypso-build, and I don't see an immediate need to make the transpilation list configurable, as all projects making use of calypso-build presumably need (or can benefit from) the same configuration there.

@sirreal
Copy link
Member

sirreal commented Jan 15, 2020

How to test:
I'm not sure what's the right way to test if dependencies are still transpiled correctly. Load the calypso.live build in IE11?

I'd expect the es6 fallback build linter to catch issues.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I haven't tested, but I looked it over and this makes sense. Thanks!

@sirreal
Copy link
Member

sirreal commented Jan 15, 2020

Will you add a changelog entry to calypso-build?

Alternative to #33492 which still uses the special Babel config for transpiling dependencies,
but moves it to the `calypso-build` package.

This PR, unlike #33492, doesn't attempt to transpile both app and `node_modules` code with the
same Babel config. It keeps the separation and shouldn't cause any changes in output -- just
moves code to a different location.

Also, this approach is in line with what Create React App does.

After merging this, `calypso-build` should start transpiling dependencies out of the box, without
any configuration. Jetpack can just upgrade to the new version and be done.
@jsnajdr jsnajdr force-pushed the move/dependencies-transpile-to-build-package branch from 136aa8a to d90f1ee Compare January 15, 2020 11:39
@jsnajdr
Copy link
Member Author

jsnajdr commented Jan 15, 2020

I rebased this PR to pickup the changes in CoreJS 3 upgrade (#38660) and added the changelog entry requested by @sirreal. I'll merge this after the CI checks come back green.

@jsnajdr jsnajdr merged commit e2dc23e into master Jan 15, 2020
@jsnajdr jsnajdr deleted the move/dependencies-transpile-to-build-package branch January 15, 2020 12:29
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 15, 2020
@ockham
Copy link
Contributor

ockham commented Jan 15, 2020

Thanks all!

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