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

RFC: Scope hoisting: support bundling browserify-built bundles #3933

Closed
wants to merge 2 commits into from

Conversation

wbinnssmith
Copy link
Contributor

@wbinnssmith wbinnssmith commented Dec 20, 2019

Closes #4634

This adds support for bundling bundles that have already been built using browserify.

The browserify prelude tests for an existing global require using typeof require === 'function', which we previously statically rewrote to 'function' === 'function', leading it to attempt to invoke a require that does not exist. Should we find a way of conditionally rewriting these, maybe only if require is only used as a function in a statically analyzable way?

Test Plan: Added a test using a browserify bundle as a fixture.

@wbinnssmith wbinnssmith force-pushed the wbinnssmith/scope-hoist-browserify-compat branch 3 times, most recently from da87fe8 to 9520b67 Compare December 20, 2019 00:15
@parcel-benchmark
Copy link

parcel-benchmark commented Dec 20, 2019

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 9.26s -178.00ms
Cached 2.39s +17.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 297.00ms +78.00ms ⚠️
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 202.00ms -39.00ms 🚀

Cached Bundles

No bundle changes detected.

React HackerNews ✅

Timings

Description Time Difference
Cold 29.66s +488.00ms
Cached 2.25s +74.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/NotFound.141e0b29.js 532.00b +0.00b 1.08s -97.00ms 🚀
dist/logo.24c8bf9e.png 274.00b +0.00b 158.00ms +52.00ms ⚠️

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.84m +543.00ms
Cached 4.86s +268.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/pdfRenderer.bc282f72.js 1.11mb +3.00b ⚠️ 56.67s +2.56s
dist/EmojiPickerComponent.88cc2f04.js 139.08kb +0.00b 13.45s +691.00ms ⚠️
dist/component.29a1022e.js 30.87kb +0.00b 3.58s +198.00ms ⚠️
dist/esm.79a76316.js 27.71kb +0.00b 13.47s +702.00ms ⚠️
dist/Modal.be4d7ece.js 3.15kb +0.00b 3.57s -1.23s 🚀
dist/16.6f170271.js 2.49kb +0.00b 4.91s +1.53s ⚠️
dist/16.7caa2097.js 1.79kb +0.00b 1.00m +3.19s ⚠️
dist/workerHasher.8ad4130a.js 1.75kb +0.00b 13.46s +699.00ms ⚠️
dist/16.e42a1bf9.js 1.45kb +0.00b 3.57s +205.00ms ⚠️
dist/16.5859a374.js 1.34kb +0.00b 3.57s +206.00ms ⚠️
dist/media-card-analytics-error-boundary.163d021e.js 1.30kb +0.00b 34.70s -19.27s 🚀
dist/16.5360f030.js 1.27kb +0.00b 3.57s +205.00ms ⚠️
dist/simpleHasher.d3ebb0a0.js 755.00b +0.00b 59.59s -37.99s 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/pdfRenderer.bc282f72.js 1.11mb +3.00b ⚠️ 1.48s +82.00ms ⚠️
dist/EmojiPickerComponent.88cc2f04.js 139.08kb +0.00b 1.46s +84.00ms ⚠️
dist/media-viewer.2cde196f.js 72.60kb +0.00b 1.48s +82.00ms ⚠️
dist/Modal.8c16e3a2.js 38.79kb +0.00b 1.24s -360.00ms 🚀
dist/component.29a1022e.js 30.87kb +0.00b 1.41s -186.00ms 🚀
dist/esm.79a76316.js 27.71kb +0.00b 1.46s +85.00ms ⚠️
dist/DatePicker.10cd8416.js 21.03kb +0.00b 1.45s +93.00ms ⚠️
dist/workerHasher.2aeac069.js 11.90kb +0.00b 1.46s +79.00ms ⚠️
dist/card.ef28e700.js 5.71kb +0.00b 1.48s +82.00ms ⚠️
dist/EmojiPickerComponent.b200d273.js 3.56kb +0.00b 1.46s +73.00ms ⚠️
dist/Modal.be4d7ece.js 3.15kb +0.00b 1.41s +194.00ms ⚠️
dist/ResourcedEmojiComponent.621cc121.js 2.15kb +0.00b 1.46s +73.00ms ⚠️
dist/feedback.85c9ab3e.js 1.86kb +0.00b 1.43s +76.00ms ⚠️
dist/workerHasher.8ad4130a.js 1.75kb +0.00b 1.46s +85.00ms ⚠️
dist/status.faf50fa4.js 1.68kb +0.00b 1.41s +86.00ms ⚠️
dist/link.d81f6056.js 1.53kb +0.00b 1.37s +73.00ms ⚠️
dist/heading6.4821a289.js 1.53kb +0.00b 1.43s +76.00ms ⚠️
dist/heading3.5de7fd77.js 1.51kb +0.00b 1.44s +89.00ms ⚠️
dist/16.e42a1bf9.js 1.45kb +0.00b 1.41s -185.00ms 🚀
dist/heading5.78c94393.js 1.40kb +0.00b 1.43s +76.00ms ⚠️
dist/16.5859a374.js 1.34kb +0.00b 1.41s -185.00ms 🚀
dist/heading2.cf643822.js 1.33kb +0.00b 1.43s +89.00ms ⚠️
dist/heading4.6f7ba126.js 1.29kb +0.00b 1.43s +79.00ms ⚠️
dist/16.5360f030.js 1.27kb +0.00b 1.41s -185.00ms 🚀
dist/quote.e4f5d46b.js 1.25kb +0.00b 1.40s +71.00ms ⚠️
dist/panel-warning.df708655.js 1.21kb +0.00b 1.39s +70.00ms ⚠️
dist/heading1.abaeff01.js 1.18kb +0.00b 1.43s +89.00ms ⚠️
dist/panel.0d33c8ed.js 1.10kb +0.00b 1.39s +70.00ms ⚠️
dist/table.f7812624.js 1.09kb +0.00b 1.43s +89.00ms ⚠️
dist/media-picker-analytics-error-boundary.6408ae55.js 1.05kb +0.00b 1.49s +75.00ms ⚠️
dist/panel-success.4e7a918e.js 1.05kb +0.00b 1.39s +70.00ms ⚠️
dist/media-card-analytics-error-boundary.d50f5ebb.js 1.05kb +0.00b 1.48s +88.00ms ⚠️
dist/simpleHasher.07c456a1.js 755.00b +0.00b 1.46s +82.00ms ⚠️

Three.js x4 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

Click here to view a detailed benchmark overview.

@wbinnssmith wbinnssmith force-pushed the wbinnssmith/scope-hoist-browserify-compat branch 2 times, most recently from 86a31ba to ee7d027 Compare December 20, 2019 00:46
@wbinnssmith wbinnssmith changed the title Scope hoisting: support bundling browserify-built bundles RFC: Scope hoisting: support bundling browserify-built bundles Dec 20, 2019
@wbinnssmith
Copy link
Contributor Author

cc @mischnic

@mischnic
Copy link
Member

I think the best solution would be:

diff --git packages/shared/scope-hoisting/src/hoist.js packages/shared/scope-hoisting/src/hoist.js
index e87bea3d..04f75017 100644
--- packages/shared/scope-hoisting/src/hoist.js
+++ packages/shared/scope-hoisting/src/hoist.js
@@ -279,26 +279,31 @@ const VISITOR: Visitor<MutableAsset> = {
   ReferencedIdentifier(path, asset: MutableAsset) {
     if (
       path.node.name === 'exports' &&
       !path.scope.hasBinding('exports') &&
       !path.scope.getData('shouldWrap')
     ) {
       path.replaceWith(getCJSExportsIdentifier(asset, path.scope));
       asset.meta.isCommonJS = true;
     }
 
     if (path.node.name === 'global' && !path.scope.hasBinding('global')) {
       path.replaceWith(t.identifier('$parcel$global'));
     }
+
+    if (path.node.name === 'require' && !path.scope.hasBinding('require')) {
+      // require() calls were already handled.
+      path.replaceWith(t.identifier('undefined'));
+    }
   },

@mischnic mischnic force-pushed the wbinnssmith/scope-hoist-browserify-compat branch from 448dbaf to 55246f3 Compare December 9, 2020 22:47
@mischnic
Copy link
Member

mischnic commented Dec 9, 2020

I think the best solution would be

I've implemented that but some situations are still broken (because JSRuntime inserts require("./" + "xyz.js") for shared bundles on Node).

@mischnic mischnic deleted the wbinnssmith/scope-hoist-browserify-compat branch May 24, 2022 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught ReferenceError: require is not defined
3 participants