Skip to content

Commit 8b7ca45

Browse files
committed
In-source @parcel/source-map
In sources the @parcel/source-map Rust and JavaScript code into Atlaspack, and updates all of the usages. Introduces a `safeToBuffer` method to ensure that any Parcel sourcemaps don't cause problems from the outside.
1 parent 71900f3 commit 8b7ca45

File tree

103 files changed

+3164
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3164
-87
lines changed

.changeset/thirty-planets-peel.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@atlaspack/parcel-to-atlaspack': minor
3+
'@atlaspack/transformer-typescript-types': minor
4+
'@atlaspack/transformer-typescript-tsc': minor
5+
'@atlaspack/eslint-plugin-internal': minor
6+
'@atlaspack/optimizer-inline-requires': minor
7+
'@atlaspack/integration-tests': minor
8+
'@atlaspack/types-internal': minor
9+
'@atlaspack/feature-flags': minor
10+
'@atlaspack/optimizer-cssnano': minor
11+
'@atlaspack/transformer-babel': minor
12+
'@atlaspack/eslint-config': minor
13+
'@atlaspack/optimizer-terser': minor
14+
'@atlaspack/transformer-less': minor
15+
'@atlaspack/transformer-sass': minor
16+
'@atlaspack/transformer-css': minor
17+
'@atlaspack/source-map': minor
18+
'@atlaspack/transformer-js': minor
19+
'@atlaspack/optimizer-css': minor
20+
'@atlaspack/optimizer-swc': minor
21+
'@atlaspack/packager-css': minor
22+
'@atlaspack/packager-js': minor
23+
'@atlaspack/utils': minor
24+
'@atlaspack/core': minor
25+
'@atlaspack/rust': minor
26+
---
27+
28+
Use an in-sourced version of @parcel/source-map, as @atlaspack/source-map

Cargo.lock

Lines changed: 39 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ anyhow = "1.0.95"
4040
assert_fs = "1.1.2"
4141
async-trait = "0.1.85"
4242
base64 = "0.22.1"
43+
base64-simd = "0.7"
4344
bitflags = "2.6.0"
4445
browserslist-rs = "0.17.0"
4546
cfg-if = "1.0.0"
@@ -50,6 +51,7 @@ criterion = "0.5.1"
5051
crossbeam = "0.8.4"
5152
crossbeam-channel = "0.5.14"
5253
data-encoding = "2.6.0"
54+
data-url = "0.1.1"
5355
derive_builder = "0.20.2"
5456
dunce = "1.0.5"
5557
dyn-hash = "0.2.0"
@@ -140,6 +142,7 @@ tracing-subscriber = "0.3.19"
140142
tracing-test = "0.2.5"
141143
url = "2.5.4"
142144
url-search-params = "12.0.0"
145+
vlq = "0.5.1"
143146
which = "7.0.3"
144147
whoami = "1.5.2"
145148
xxhash-rust = "0.8.15"
@@ -149,7 +152,7 @@ serde_yaml = "0.9.34+deprecated"
149152

150153
# CANNOT UPDATE
151154
## rkyv includes a breaking change in a minor release which breaks parcel_sourcemap
152-
parcel_sourcemap = "2.1.1"
155+
parcel_sourcemap_ext = { package = "parcel_sourcemap", version="2.1.1" }
153156
rkyv = "0.7.38"
154157

155158
## Other

crates/atlaspack_plugin_transformer_css/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ async-trait = { workspace = true }
1414
atlaspack_core = { path = "../atlaspack_core" }
1515
atlaspack_filesystem = { path = "../atlaspack_filesystem" }
1616
lightningcss = { workspace = true, features = ["browserslist", "sourcemap"] }
17-
parcel_sourcemap = { workspace = true}
17+
parcel_sourcemap_ext = { workspace = true }
18+
parcel_sourcemap = { path = "../parcel_sourcemap" }
1819
serde = { workspace = true, features = ["derive"] }
1920
serde_json = { workspace = true }
2021

22+
2123
[dev-dependencies]
2224
pretty_assertions = { workspace = true }
2325
tokio = { workspace = true, features = ["full"] }

crates/atlaspack_plugin_transformer_css/src/css_transformer.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use lightningcss::dependencies::DependencyOptions;
1818
use lightningcss::printer::PrinterOptions;
1919
use lightningcss::stylesheet::{ParserFlags, ParserOptions, StyleSheet};
2020
use lightningcss::targets::{Browsers, Targets};
21-
use parcel_sourcemap::SourceMap as ParcelSourceMap;
21+
// Lightning CSS uses the upstream Parcel SourceMap, but Atlaspack uses the in-sourced version (which will eventually be renamed)
22+
use parcel_sourcemap_ext::SourceMap as ParcelSourceMapExt;
2223
use serde::Deserialize;
2324

2425
use crate::css_transformer_config::{CssModulesConfig, CssModulesFullConfig, CssTransformerConfig};
@@ -184,8 +185,8 @@ impl TransformerPlugin for AtlaspackCssTransformerPlugin {
184185
},
185186
)?;
186187

187-
let mut lightning_source_map: Option<ParcelSourceMap> = if asset.env.source_map.is_some() {
188-
let mut sm = ParcelSourceMap::new(&self.project_root.to_string_lossy());
188+
let mut lightning_source_map: Option<ParcelSourceMapExt> = if asset.env.source_map.is_some() {
189+
let mut sm = ParcelSourceMapExt::new(&self.project_root.to_string_lossy());
189190
sm.add_source(&asset.file_path.to_string_lossy());
190191
sm.set_source_content(0, asset.code.as_str()?)?;
191192
Some(sm)
@@ -525,8 +526,12 @@ impl TransformerPlugin for AtlaspackCssTransformerPlugin {
525526
css_code.push(css.code);
526527
asset.code = Code::from(css_code.join("\n"));
527528

528-
if let Some(source_map) = lightning_source_map.clone() {
529-
let mut source_map = SourceMap::from(source_map);
529+
if let Some(mut source_map) = lightning_source_map {
530+
// The Lightning CSS sourcemap is a Parcel SourceMap, but we need an Atlaspack SourceMap - the only safe way to convert
531+
// from one to the other is via JSON - as a buffer will use rkyv and requires binary compatibility
532+
let lightning_source_map_json =
533+
source_map.to_json(Some(&self.project_root.to_string_lossy()))?;
534+
let mut source_map = SourceMap::from_json(&self.project_root, &lightning_source_map_json)?;
530535

531536
if let Some(original_map) = asset.map {
532537
source_map.extends(&mut original_map.clone())?;

crates/atlaspack_sourcemap/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ workspace = true
1010

1111
[dependencies]
1212
atlaspack_filesystem = { path = "../atlaspack_filesystem" }
13-
parcel_sourcemap = { workspace = true, features = ["json"] }
13+
parcel_sourcemap = { path = "../parcel_sourcemap", features = ["json"] }
1414
regex = { workspace = true }
1515
rkyv = { workspace = true }
1616
serde = { workspace = true, features = ["derive"] }

crates/node-bindings/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ atlaspack_vcs = { path = "../atlaspack_vcs" }
2525
atlaspack_swc_runner = { path = "../atlaspack_swc_runner" }
2626
atlassian_swc_compiled_css = { path = "../atlassian-swc-compiled-css", features = ["napi"] }
2727
lmdb-js-lite = { path = "../lmdb-js-lite" }
28+
parcel_sourcemap = { path = "../parcel_sourcemap" }
2829

2930
aho-corasick = { workspace = true }
3031
anyhow = { workspace = true }
@@ -34,6 +35,7 @@ mockall = { workspace = true }
3435
napi-derive = { workspace = true }
3536
num_cpus = { workspace = true }
3637
parking_lot = { workspace = true }
38+
rkyv = { workspace = true }
3739
serde = { workspace = true, features = ["derive"] }
3840
serde_json = { workspace = true }
3941
toml = { workspace = true }
@@ -76,5 +78,8 @@ mimalloc = { workspace = true }
7678
indoc = { workspace = true }
7779
tempfile = { workspace = true }
7880

81+
[target.'cfg(target_os = "macos")'.dependencies]
82+
jemallocator = { workspace = true, features = ["disable_initial_exec_tls"]}
83+
7984
[build-dependencies]
8085
napi-build = { workspace = true }

crates/node-bindings/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod lmdb;
2424
mod optimizers;
2525
mod plugin_compiled_css_in_js;
2626
mod resolver;
27+
mod sourcemap;
2728
mod string_ops;
2829
mod transformer;
2930
pub mod vcs;

0 commit comments

Comments
 (0)