-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Sort global deps before injecting imports #8818
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark ResultsKitchen Sink ✅
Timings
Cold BundlesNo bundle changes detected. Cached Bundles
React HackerNews ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. AtlasKit Editor ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. |
Haven't we tried to use indexedmap at some point for some part of the transformer but then went with arrays for some reason? Was it performance? @devongovett --- packages/transformers/js/core/Cargo.toml
+++ packages/transformers/js/core/Cargo.toml
@@ -20,3 +20,4 @@ sha-1 = "0.10.0"
dunce = "1.0.1"
pathdiff = "0.2.0"
path-slash = "0.1.4"
+indexmap = "1.9.2"
diff --git packages/transformers/js/core/src/global_replacer.rs packages/transformers/js/core/src/global_replacer.rs
index e249e6da2..80ed0a56a 100644
--- packages/transformers/js/core/src/global_replacer.rs
+++ packages/transformers/js/core/src/global_replacer.rs
@@ -1,7 +1,8 @@
use path_slash::PathBufExt;
-use std::collections::{HashMap, HashSet};
+use std::collections::HashSet;
use std::path::Path;
+use indexmap::IndexMap;
use swc_atoms::JsWord;
use swc_common::{Mark, SourceMap, SyntaxContext, DUMMY_SP};
use swc_ecmascript::ast::{self, ComputedPropName, Id};
@@ -14,9 +15,10 @@ pub struct GlobalReplacer<'a> {
pub source_map: &'a SourceMap,
pub items: &'a mut Vec<DependencyDescriptor>,
pub global_mark: Mark,
- pub globals: HashMap<JsWord, (SyntaxContext, ast::Stmt)>,
+ pub globals: IndexMap<JsWord, (SyntaxContext, ast::Stmt)>,
pub project_root: &'a Path,
pub filename: &'a Path,
pub decls: &'a mut HashSet<Id>,
pub scope_hoist: bool,
}
diff --git packages/transformers/js/core/src/lib.rs packages/transformers/js/core/src/lib.rs
index e0d51e61b..b8497eb33 100644
--- packages/transformers/js/core/src/lib.rs
+++ packages/transformers/js/core/src/lib.rs
@@ -22,6 +22,7 @@ mod node_replacer;
mod typeof_replacer;
mod utils;
+use indexmap::IndexMap;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::str::FromStr;
@@ -369,7 +370,7 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
source_map: &source_map,
items: &mut global_deps,
global_mark,
- globals: HashMap::new(),
+ globals: IndexMap::new(),
project_root: Path::new(&config.project_root),
filename: Path::new(&config.filename),
decls: &mut decls, |
mischnic
approved these changes
Feb 6, 2023
marcins
pushed a commit
to marcins/parcel
that referenced
this pull request
Jul 14, 2023
* upstream/v2: Sort global deps before injecting imports (parcel-bundler#8818) Sort CSS module exports (parcel-bundler#8817) fix: add extra information to unique bundles (parcel-bundler#8784) Don't blow up HMR when <link />s don't have hrefs (parcel-bundler#8800)
lettertwo
added a commit
that referenced
this pull request
Nov 6, 2023
* upstream/v2: (128 commits) [webextension] Add support for `chrome_style` (#8867) Switch to SWC minifier by default (#8860) Use BitSet for bundler intersections (#8862) best key logic truncating package names (#8865) Add support for loadConfig to resolver plugins (#8847) Missing edge for multiple targets (#8854) Split large runtime manifest into separate bundles (#8837) Improvements to new resolver (#8844) Fix published files for resolver New resolver implementation in Rust (#8807) Update yarn.lock (#8843) Bump napi-rs to latest (#8838) Support .proxyrc.cjs (#8833) Sort global deps before injecting imports (#8818) Sort CSS module exports (#8817) fix: add extra information to unique bundles (#8784) Don't blow up HMR when <link />s don't have hrefs (#8800) v2.8.3 Changelog for v2.8.3 Address bug by updating an asset reference and merge conditions (#8762) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
↪️ Pull Request
The global replacer currently injects imports to polyfills for node global APIs, however their order is not consistent between builds. This can be due to
SWC not visiting the expressions in orderorHashMap
not storing values in insertion order.The PR sorts globals by key before inserting them to ensure consistent ordering between builds.This PR switches
HashMap
forIndexMap
which respects insertion order.🚨 Test instructions
Existing tests are sufficient.
✔️ PR Todo