Skip to content

Commit

Permalink
Update to napi-rs v2 (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Apr 7, 2023
1 parent 30fd52a commit 6ef1795
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 1,122 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ target
bench.txt

parcel_sourcemap_wasm/dist-*
parcel_sourcemap_node/artifacts
124 changes: 113 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@babel/preset-env": "^7.14.2",
"@babel/preset-flow": "^7.13.13",
"@babel/register": "^7.13.16",
"@napi-rs/cli": "^1.0.4",
"@napi-rs/cli": "^2.14.8",
"cross-env": "^7.0.3",
"flow-bin": "^0.151.0",
"flow-copy-source": "^2.0.9",
Expand All @@ -79,9 +79,6 @@
"source-map": "^0.7.3",
"tiny-benchy": "^2.1.0"
},
"dependencies": {
"detect-libc": "^1.0.3"
},
"browser": {
"./dist/node.js": "./dist/wasm.js",
"./dist/wasm-bindings.js": "./dist/wasm-bindings-web.js"
Expand Down
2 changes: 1 addition & 1 deletion parcel_sourcemap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "parcel_sourcemap"
version = "2.1.1"
authors = [ "Jasper De Moor <jasperdemoor@gmail.com>" ]
edition = "2018"
edition = "2021"
description = "Parcel Source Map Library"
license = "MIT"
keywords = [ "sourcemap", "Node", "Parcel" ]
Expand Down
8 changes: 4 additions & 4 deletions parcel_sourcemap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl SourceMap {
previous_source = original_source;

let original_line = original.original_line as i64;
vlq::encode((original_line - previous_original_line) as i64, output)?;
vlq::encode(original_line - previous_original_line, output)?;
previous_original_line = original_line;

let original_column = original.original_column as i64;
Expand Down Expand Up @@ -692,7 +692,7 @@ impl SourceMap {
let mut sources_content = Vec::with_capacity(json.sources.len());
for i in 0..json.sources.len() {
sources_content.push(if let Some(Some(content)) = json.sources_content.get(i) {
content.to_owned()
content.clone()
} else {
"".into()
});
Expand Down Expand Up @@ -772,13 +772,13 @@ fn test_buffers() {
let mut output = AlignedVec::new();
match map.to_buffer(&mut output) {
Ok(_) => {}
Err(err) => panic!(err),
Err(err) => panic!("{}", err),
}
match SourceMap::from_buffer("/", &output) {
Ok(map) => {
println!("{:?}", map)
}
Err(err) => panic!(err),
Err(err) => panic!("{}", err),
}
}

Expand Down
2 changes: 1 addition & 1 deletion parcel_sourcemap/src/vlq_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ where
B: Iterator<Item = u8>,
{
let decoded = decode(input)?;
let (new, overflowed) = (*previous as i64).overflowing_add(decoded);
let (new, overflowed) = (*previous).overflowing_add(decoded);
if overflowed || new > (u32::MAX as i64) {
return Err(SourceMapError::new(
SourceMapErrorType::UnexpectedlyBigNumber,
Expand Down
8 changes: 4 additions & 4 deletions parcel_sourcemap_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
authors = ["Jasper De Moor <jasperdemoor@gmail.com>"]
edition = "2018"
edition = "2021"
name = "parcel_sourcemap_node"
version = "2.1.1"

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = {version = "1.7.3", features = ["napi4", "serde-json"]}
napi-derive = "1.1.0"
napi = {version = "2.12.2", features = ["napi4", "serde-json"]}
napi-derive = "2.12.2"
parcel_sourcemap = {path = "../parcel_sourcemap"}
serde = "1"
serde_json = "1"
Expand All @@ -19,4 +19,4 @@ rkyv = "0.7.38"
jemallocator = {version = "0.3.2", features = ["disable_initial_exec_tls"]}

[build-dependencies]
napi-build = "1.0.2"
napi-build = "2"
15 changes: 0 additions & 15 deletions parcel_sourcemap_node/index.js

This file was deleted.

Loading

1 comment on commit 6ef1795

@github-actions
Copy link

Choose a reason for hiding this comment

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

Parcel sourcemap benchmark

Benchmark suite Current: 6ef1795 Previous: 30fd52a Ratio
consume#consume buffer 105742 ops/sec (±13%) 150193 ops/sec (±18%) 1.42
consume#consume JS Mappings 46788 ops/sec (±7.4%) 52720 ops/sec (±5.6%) 1.13
consume#consume vlq mappings 40540 ops/sec (±21%) 46739 ops/sec (±13%) 1.15
serialize#Save buffer 366 ops/sec (±2.1%) 348 ops/sec (±0.86%) 0.95
serialize#Serialize to vlq 195 ops/sec (±13%) 295 ops/sec (±0.93%) 1.51
modify#negative column offset 79258 ops/sec (±13%) 67938 ops/sec (±13%) 0.86
modify#positive column offset 75517 ops/sec (±19%) 72784 ops/sec (±19%) 0.96
modify#negative line offset 57800 ops/sec (±12%) 34400 ops/sec (±5.3%) 0.60
modify#positive line offset 53879 ops/sec (±9.9%) 33653 ops/sec (±7.8%) 0.62
append#addSourceMap 190 ops/sec (±11%) 199 ops/sec (±1.1%) 1.05

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.