Skip to content

Commit fd073fc

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 525898e commit fd073fc

File tree

101 files changed

+3157
-97
lines changed

Some content is hidden

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

101 files changed

+3157
-97
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"
@@ -137,6 +139,7 @@ tracing-subscriber = "0.3.19"
137139
tracing-test = "0.2.5"
138140
url = "2.5.4"
139141
url-search-params = "12.0.0"
142+
vlq = "0.5.1"
140143
which = "7.0.3"
141144
whoami = "1.5.2"
142145
xxhash-rust = "0.8.15"
@@ -146,7 +149,7 @@ serde_yaml = "0.9.34+deprecated"
146149

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

152155
## 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};
@@ -153,8 +154,8 @@ impl TransformerPlugin for AtlaspackCssTransformerPlugin {
153154
},
154155
)?;
155156

156-
let mut lightning_source_map: Option<ParcelSourceMap> = if asset.env.source_map.is_some() {
157-
let mut sm = ParcelSourceMap::new(&self.project_root.to_string_lossy());
157+
let mut lightning_source_map: Option<ParcelSourceMapExt> = if asset.env.source_map.is_some() {
158+
let mut sm = ParcelSourceMapExt::new(&self.project_root.to_string_lossy());
158159
sm.add_source(&asset.file_path.to_string_lossy());
159160
sm.set_source_content(0, asset.code.as_str()?)?;
160161
Some(sm)
@@ -494,8 +495,12 @@ impl TransformerPlugin for AtlaspackCssTransformerPlugin {
494495
css_code.push(css.code);
495496
asset.code = Code::from(css_code.join("\n"));
496497

497-
if let Some(source_map) = lightning_source_map.clone() {
498-
let mut source_map = SourceMap::from(source_map);
498+
if let Some(mut source_map) = lightning_source_map {
499+
// The Lightning CSS sourcemap is a Parcel SourceMap, but we need an Atlaspack SourceMap - the only safe way to convert
500+
// from one to the other is via JSON - as a buffer will use rkyv and requires binary compatibility
501+
let lightning_source_map_json =
502+
source_map.to_json(Some(&self.project_root.to_string_lossy()))?;
503+
let mut source_map = SourceMap::from_json(&self.project_root, &lightning_source_map_json)?;
499504

500505
if let Some(original_map) = asset.map {
501506
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
@@ -23,6 +23,7 @@ atlaspack_napi_helpers = { path = "../atlaspack_napi_helpers" }
2323
atlaspack_vcs = { path = "../atlaspack_vcs" }
2424
atlaspack_swc_runner = { path = "../atlaspack_swc_runner" }
2525
lmdb-js-lite = { path = "../lmdb-js-lite" }
26+
parcel_sourcemap = { path = "../parcel_sourcemap" }
2627

2728
aho-corasick = { workspace = true }
2829
anyhow = { workspace = true }
@@ -32,6 +33,7 @@ mockall = { workspace = true }
3233
napi-derive = { workspace = true }
3334
num_cpus = { workspace = true }
3435
parking_lot = { workspace = true }
36+
rkyv = { workspace = true }
3537
serde = { workspace = true, features = ["derive"] }
3638
serde_json = { workspace = true }
3739
toml = { workspace = true }
@@ -69,5 +71,8 @@ napi = { workspace = true, features = ["serde-json"] }
6971
[target.'cfg(windows)'.dependencies]
7072
mimalloc = { workspace = true }
7173

74+
[target.'cfg(target_os = "macos")'.dependencies]
75+
jemallocator = { workspace = true, features = ["disable_initial_exec_tls"]}
76+
7277
[build-dependencies]
7378
napi-build = { workspace = true }

crates/node-bindings/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod atlaspack;
2323
pub mod lmdb;
2424
mod optimizers;
2525
mod resolver;
26+
mod sourcemap;
2627
mod string_ops;
2728
mod transformer;
2829
pub mod vcs;

0 commit comments

Comments
 (0)