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

Allow customizing order of bify transforms/plugins #13483

Closed
wants to merge 7 commits into from

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Feb 1, 2022

We use Browserify to compile our JavaScript code into a distributable
format. You can use Browserify in a few different ways, but we use the
API, which is detailed here. The way we use it is as follows:

const bundlerOpts = {
  entries: [],
  transform: [],
  plugin: [],
  require: [],
  manualExternal: [],
  manualIgnore: [],
}
// ... change bundlerOpts in various ways ...

// then, later:
const bundler = browserify(bundlerOpts);
bundler.bundle();

Note that all transforms and all plugins are passed to browserify in
one go. This creates a problem, because transforms and plugins are
processed in the same order in which they are specified. That is,
specifying transform A, then plugin B, then transform C, is NOT the same
as specifying transform A, then transform C, then plugin B.

The way to correct this is to make use of Browserify's full API, which
provides transform and plugin methods, as well as other specific
methods to specify other options. This commit, then, updates the part of
the build system that configures Browserify to use this API.

The order dependency as it relates to transforms and plugins will come
into play when introducing TypeScript into the build system. Namely, we
will be introducing a tsify Browserify plugin, which will need to be
specified before specifying babelify, as demonstrated here. Hence
we need this commit to be in place so that this is possible.


Manual testing steps:

  • Make sure you've added the development version of the extension to your browser (sourced from dist/).
  • Run yarn start. Reload the extension if need be. You should not see a white screen. Click around in the extension for a bit. You should not encounter any error screens.
  • Run yarn start:test. Run an e2e test. It should pass.
  • Run yarn dist. Reload the extension if need be. You should not see a white screen. Click around in the extension for a bit. You should not encounter any error screens.

We use Browserify to compile our JavaScript code into a distributable
format. You can use Browserify in a few different ways, but we use the
API, which is detailed [here][1]. The way we use it is as follows:

``` javascript
const bundlerOpts = {
  entries: [],
  transform: [],
  plugin: [],
  require: [],
  manualExternal: [],
  manualIgnore: [],
}
// ... change bundlerOpts in various ways ...

// then, later:
const bundler = browserify(bundlerOpts);
bundler.bundle();
```

Note that all transforms and all plugins are passed to `browserify` in
one go. This creates a problem, because transforms and plugins are
processed in the same order in which they are specified. That is,
specifying transform A, then plugin B, then transform C, is NOT the same
as specifying transform A, then transform C, then plugin B.

The way to correct this is to make use of Browserify's full API, which
provides `transform` and `plugin` methods, as well as other specific
methods to specify other options. This commit, then, updates the part of
the build system that configures Browserify to use this API.

The order dependency as it relates to transforms and plugins will come
into play when introducing TypeScript into the build system. Namely, we
will be introducing a `tsify` Browserify plugin, which will need to be
specified before specifying `babelify`, as demonstrated [here][2]. Hence
we need this commit to be in place so that this is possible.

[1]: https://www.npmjs.com/package/browserify#browserifyfiles--opts
[2]: https://github.com/TypeStrong/tsify#es2015-formerly-known-as-es6
@mcmire mcmire requested review from kumavis and a team as code owners February 1, 2022 20:56
@mcmire mcmire requested a review from digiwand February 1, 2022 20:56
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2022

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@mcmire mcmire requested a review from Gudahtt February 1, 2022 21:05
addTransform(
createRemoveFencedCodeTransform(buildType, shouldLintFenceFiles),
);
// Transpile top-level code
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where tsify will go. According to the documentation, it needs to go before babelify.

// call the completion event to handle any post-processing
events.emit('bundleDone');
}
async function performBundle({ bundler, events }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see a real reason this was nested within bundleIt, and considering most of bundleIt is this function anyway, I pulled it out.

@metamaskbot
Copy link
Collaborator

Builds ready [0115b86]
Page Load Metrics (1106 ± 15 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint651129325400192
domContentLoaded1060120011063115
load1060120011063215
domInteractive1060120011063115

digiwand
digiwand previously approved these changes Feb 2, 2022
Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

Lovely solution! More modular, succint, and got rid of the "manual" code 👍

development/build/scripts.js Show resolved Hide resolved
development/build/scripts.js Outdated Show resolved Hide resolved
@mcmire
Copy link
Contributor Author

mcmire commented Feb 2, 2022

@digiwand Made a small change in response to your feedback. Can you take another quick look?

@metamaskbot
Copy link
Collaborator

Builds ready [94b5c58]
Page Load Metrics (1097 ± 24 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint651101284306147
domContentLoaded1027119810975124
load1032119810975124
domInteractive1027119810975124

@metamaskbot
Copy link
Collaborator

Builds ready [b8e1e9d]
Page Load Metrics (1098 ± 30 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6341714713063
domContentLoaded1007129210976330
load1007129210986330
domInteractive1007129210976330

@metamaskbot
Copy link
Collaborator

Builds ready [5ab2295]
Page Load Metrics (1155 ± 38 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint731208420397190
domContentLoaded1030135211558038
load1030135211558038
domInteractive1030135211558038

@metamaskbot
Copy link
Collaborator

Builds ready [843f9ef]
Page Load Metrics (1162 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint761159363347167
domContentLoaded1070129711616531
load1071129711626531
domInteractive1070129711616531

@metamaskbot
Copy link
Collaborator

Builds ready [d7ffcfd]
Page Load Metrics (1082 ± 28 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint651114416435209
domContentLoaded993121910815828
load993121910825828
domInteractive993121910815828

@mcmire
Copy link
Contributor Author

mcmire commented Feb 15, 2022

This PR may no longer be necessary since we're no longer adding tsify. I'll wait until #13495 is merged.

@mcmire mcmire marked this pull request as draft February 25, 2022 19:13
@mcmire
Copy link
Contributor Author

mcmire commented Mar 11, 2022

We won't need this after all so I am closing this.

@mcmire mcmire closed this Mar 11, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants