sentry-cli 2.20.3__tar.gz → 2.20.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/Cargo.lock +23 -3
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/Cargo.toml +3 -2
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/PKG-INFO +1 -1
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/sentry_cli.egg-info/PKG-INFO +1 -1
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/sourcemaps/inject.rs +61 -218
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/sourcemaps.rs +144 -112
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/LICENSE +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/MANIFEST.in +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/README.md +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/build.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/pyproject.toml +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/sentry_cli.egg-info/SOURCES.txt +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/sentry_cli.egg-info/dependency_links.txt +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/sentry_cli.egg-info/top_level.txt +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/setup.cfg +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/setup.py +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/api.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/bashsupport.sh +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/bash_hook.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/bundle_jvm.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/bundle_sources.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/check.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/find.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/print_sources.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/debug_files/upload.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/deploys/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/deploys/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/deploys/new.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/events/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/events/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/files/delete.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/files/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/files/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/files/upload.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/info.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/issues/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/issues/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/issues/mute.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/issues/resolve.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/issues/unresolve.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/login.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/monitors/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/monitors/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/monitors/run.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/organizations/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/organizations/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/projects/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/projects/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/react_native/appcenter.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/react_native/gradle.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/react_native/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/react_native/xcode.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/archive.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/delete.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/finalize.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/info.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/new.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/propose_version.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/restore.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/releases/set_commits.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/repos/list.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/repos/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/send_envelope.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/send_event.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/sourcemaps/explain.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/sourcemaps/inject.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/sourcemaps/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/sourcemaps/resolve.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/sourcemaps/upload.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/uninstall.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/update.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/upload_dif.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/upload_dsym.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/commands/upload_proguard.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/config.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/constants.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/main.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/android.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/appcenter.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/args.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/chunks.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/codepush.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/cordova.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/dif.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/dif_upload.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/enc.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/event.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/file_search.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/file_upload.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/formatting.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/fs.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/http.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/logging.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/mod.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/progress.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/releases.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/retry.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/snapshots/sentry_cli__utils__vcs__generate_patch_default_twenty.snap +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/snapshots/sentry_cli__utils__vcs__generate_patch_ignore_missing.snap +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/snapshots/sentry_cli__utils__vcs__generate_patch_set_base.snap +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/snapshots/sentry_cli__utils__vcs__generate_patch_set_previous_commit.snap +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/snapshots/sentry_cli__utils__vcs__get_commits_from_git.snap +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/system.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/ui.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/update.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/vcs.rs +0 -0
- {sentry_cli-2.20.3 → sentry_cli-2.20.4}/src/utils/xcode.rs +0 -0
|
@@ -1326,6 +1326,19 @@ dependencies = [
|
|
|
1326
1326
|
"cc",
|
|
1327
1327
|
]
|
|
1328
1328
|
|
|
1329
|
+
[[package]]
|
|
1330
|
+
name = "magic_string"
|
|
1331
|
+
version = "0.3.4"
|
|
1332
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1333
|
+
checksum = "6c8033ce8c43f7ccb207e4699f30eed50d7526379ee08fab47159f80b7934e18"
|
|
1334
|
+
dependencies = [
|
|
1335
|
+
"base64",
|
|
1336
|
+
"regex",
|
|
1337
|
+
"serde",
|
|
1338
|
+
"serde_json",
|
|
1339
|
+
"vlq",
|
|
1340
|
+
]
|
|
1341
|
+
|
|
1329
1342
|
[[package]]
|
|
1330
1343
|
name = "match_cfg"
|
|
1331
1344
|
version = "0.1.0"
|
|
@@ -2189,7 +2202,7 @@ dependencies = [
|
|
|
2189
2202
|
|
|
2190
2203
|
[[package]]
|
|
2191
2204
|
name = "sentry-cli"
|
|
2192
|
-
version = "2.20.
|
|
2205
|
+
version = "2.20.4"
|
|
2193
2206
|
dependencies = [
|
|
2194
2207
|
"anyhow",
|
|
2195
2208
|
"anylog",
|
|
@@ -2221,6 +2234,7 @@ dependencies = [
|
|
|
2221
2234
|
"libc",
|
|
2222
2235
|
"log",
|
|
2223
2236
|
"mac-process-info",
|
|
2237
|
+
"magic_string",
|
|
2224
2238
|
"might-be-minified",
|
|
2225
2239
|
"mockito",
|
|
2226
2240
|
"open",
|
|
@@ -2468,9 +2482,9 @@ dependencies = [
|
|
|
2468
2482
|
|
|
2469
2483
|
[[package]]
|
|
2470
2484
|
name = "sourcemap"
|
|
2471
|
-
version = "6.
|
|
2485
|
+
version = "6.4.0"
|
|
2472
2486
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2473
|
-
checksum = "
|
|
2487
|
+
checksum = "e9221a6bba3e9cfa7decfe64edf5233311e1bf837ea3234df6e7f35836e1093d"
|
|
2474
2488
|
dependencies = [
|
|
2475
2489
|
"data-encoding",
|
|
2476
2490
|
"debugid",
|
|
@@ -2947,6 +2961,12 @@ version = "0.9.4"
|
|
|
2947
2961
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2948
2962
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
2949
2963
|
|
|
2964
|
+
[[package]]
|
|
2965
|
+
name = "vlq"
|
|
2966
|
+
version = "0.5.1"
|
|
2967
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2968
|
+
checksum = "65dd7eed29412da847b0f78bcec0ac98588165988a8cfe41d4ea1d429f8ccfff"
|
|
2969
|
+
|
|
2950
2970
|
[[package]]
|
|
2951
2971
|
name = "wait-timeout"
|
|
2952
2972
|
version = "0.2.0"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
|
|
3
3
|
build = "build.rs"
|
|
4
4
|
name = "sentry-cli"
|
|
5
|
-
version = "2.20.
|
|
5
|
+
version = "2.20.4"
|
|
6
6
|
edition = "2021"
|
|
7
7
|
rust-version = "1.65"
|
|
8
8
|
|
|
@@ -65,7 +65,7 @@ sentry = { version = "0.31.2", default-features = false, features = [
|
|
|
65
65
|
serde = { version = "1.0.152", features = ["derive"] }
|
|
66
66
|
serde_json = "1.0.93"
|
|
67
67
|
sha1_smol = { version = "1.0.0", features = ["serde"] }
|
|
68
|
-
sourcemap = { version = "6.
|
|
68
|
+
sourcemap = { version = "6.4.0", features = ["ram_bundle"] }
|
|
69
69
|
symbolic = { version = "12.1.5", features = ["debuginfo-serde", "il2cpp"] }
|
|
70
70
|
thiserror = "1.0.38"
|
|
71
71
|
url = "2.3.1"
|
|
@@ -75,6 +75,7 @@ walkdir = "2.3.2"
|
|
|
75
75
|
which = "4.4.0"
|
|
76
76
|
zip = "0.6.4"
|
|
77
77
|
data-encoding = "2.3.3"
|
|
78
|
+
magic_string = "0.3.4"
|
|
78
79
|
|
|
79
80
|
[dev-dependencies]
|
|
80
81
|
insta = { version = "1.26.0", features = ["redactions", "yaml"] }
|
|
@@ -7,18 +7,26 @@ use std::fmt;
|
|
|
7
7
|
use std::io::{BufRead, Write};
|
|
8
8
|
use std::path::PathBuf;
|
|
9
9
|
|
|
10
|
-
use anyhow::
|
|
10
|
+
use anyhow::Result;
|
|
11
11
|
use lazy_static::lazy_static;
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
use magic_string::{GenerateDecodedMapOptions, MagicString};
|
|
13
14
|
use sentry::types::DebugId;
|
|
14
|
-
use
|
|
15
|
+
use sourcemap::SourceMap;
|
|
15
16
|
|
|
16
17
|
const CODE_SNIPPET_TEMPLATE: &str = r#"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="__SENTRY_DEBUG_ID__")}catch(e){}}();"#;
|
|
17
18
|
const DEBUGID_PLACEHOLDER: &str = "__SENTRY_DEBUG_ID__";
|
|
18
19
|
const DEBUGID_COMMENT_PREFIX: &str = "//# debugId";
|
|
19
20
|
|
|
20
21
|
lazy_static! {
|
|
21
|
-
|
|
22
|
+
// A regex that captures
|
|
23
|
+
// 1. an optional initial hashbang,
|
|
24
|
+
// 2. a block of line comments, block comments, and empty lines,
|
|
25
|
+
// 3. and an optional `"use strict";` statement.`
|
|
26
|
+
static ref PRE_INJECT_RE: Regex = Regex::new(
|
|
27
|
+
r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';[\n\r]?)?"#
|
|
28
|
+
)
|
|
29
|
+
.unwrap();
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
fn print_section_with_debugid(
|
|
@@ -105,110 +113,48 @@ impl fmt::Display for InjectReport {
|
|
|
105
113
|
/// `<CODE_SNIPPET>[<debug_id>]`
|
|
106
114
|
/// is inserted at the earliest possible position, which is after an
|
|
107
115
|
/// optional hashbang, followed by a
|
|
108
|
-
/// block of comments, empty lines, and `"use […]";` or `'use […]';`
|
|
116
|
+
/// block of comments, empty lines, and an optional `"use […]";` or `'use […]';` pragma.
|
|
109
117
|
/// 2. A comment of the form `//# debugId=<debug_id>` is appended to the file.
|
|
110
|
-
/// 3. The last source mapping comment (a comment starting with
|
|
111
|
-
/// `//# sourceMappingURL=` or `//@ sourceMappingURL=`) is moved to
|
|
112
|
-
/// the very end of the file, after the debug id comment from 2.
|
|
113
|
-
///
|
|
114
|
-
/// This function will naturally mess with the correspondence between a source file
|
|
115
|
-
/// and its sourcemap. Use [`insert_empty_mapping`] on the sourcemap to fix this.
|
|
116
|
-
/// # Example
|
|
117
|
-
/// ```
|
|
118
|
-
/// let file = "
|
|
119
|
-
/// // a
|
|
120
|
-
/// // comment
|
|
121
|
-
/// // block
|
|
122
|
-
///
|
|
123
|
-
/// // another
|
|
124
|
-
/// // comment
|
|
125
|
-
/// // block
|
|
126
|
-
///
|
|
127
|
-
/// 'use strict';
|
|
128
|
-
/// function t(t) {
|
|
129
|
-
/// return '[object Object]' === Object.prototype.toString.call(t);
|
|
130
|
-
/// }
|
|
131
|
-
/// //# sourceMappingURL=/path/to/sourcemap
|
|
132
|
-
/// ";
|
|
133
|
-
///
|
|
134
|
-
/// let mut file = file.as_bytes().to_vec();
|
|
135
|
-
/// fixup_js_file(&mut file, DebugId::default()).unwrap();
|
|
136
|
-
///
|
|
137
|
-
/// assert_eq!(
|
|
138
|
-
/// std::str::from_utf8(&file).unwrap(),
|
|
139
|
-
/// r#"
|
|
140
|
-
/// // a
|
|
141
|
-
/// // comment
|
|
142
|
-
/// // block
|
|
143
|
-
///
|
|
144
|
-
/// // another
|
|
145
|
-
/// // comment
|
|
146
|
-
/// // block
|
|
147
118
|
///
|
|
148
|
-
///
|
|
149
|
-
///
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/// }
|
|
153
|
-
/// //# debugId=00000000-0000-0000-0000-000000000000
|
|
154
|
-
/// //# sourceMappingURL=/path/to/sourcemap
|
|
155
|
-
/// "#
|
|
156
|
-
/// );
|
|
157
|
-
/// ```
|
|
158
|
-
pub fn fixup_js_file(js_contents: &mut Vec<u8>, debug_id: DebugId) -> Result<()> {
|
|
159
|
-
let mut js_lines = js_contents.lines().collect::<Result<Vec<_>, _>>()?;
|
|
119
|
+
/// This function returns a [`SourceMap`] that maps locations in the injected file
|
|
120
|
+
/// to their corresponding places in the original file.
|
|
121
|
+
pub fn fixup_js_file(js_contents: &mut Vec<u8>, debug_id: DebugId) -> Result<SourceMap> {
|
|
122
|
+
let contents = std::str::from_utf8(js_contents)?;
|
|
160
123
|
|
|
161
|
-
|
|
124
|
+
let m = PRE_INJECT_RE
|
|
125
|
+
.find(contents)
|
|
126
|
+
.expect("regex is infallible")
|
|
127
|
+
.range();
|
|
162
128
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
.
|
|
166
|
-
|
|
167
|
-
.rev()
|
|
168
|
-
.find(|(_idx, line)| {
|
|
169
|
-
line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=")
|
|
170
|
-
})
|
|
171
|
-
.map(|(idx, _)| idx);
|
|
172
|
-
|
|
173
|
-
let sourcemap_comment = sourcemap_comment_idx.map(|idx| js_lines.remove(idx));
|
|
129
|
+
let code_snippet = format!(
|
|
130
|
+
"\n{}\n",
|
|
131
|
+
CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string())
|
|
132
|
+
);
|
|
174
133
|
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
// Handle initial hashbang
|
|
178
|
-
if let Some(hashbang) = js_lines.next_if(|line| line.trim().starts_with("#!")) {
|
|
179
|
-
writeln!(js_contents, "{hashbang}")?;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Write comments and empty lines at the start back to the file
|
|
183
|
-
while let Some(comment_or_empty) =
|
|
184
|
-
js_lines.next_if(|line| line.trim().is_empty() || line.trim().starts_with("//"))
|
|
185
|
-
{
|
|
186
|
-
writeln!(js_contents, "{comment_or_empty}")?;
|
|
187
|
-
}
|
|
134
|
+
let debug_id_comment = format!("\n{DEBUGID_COMMENT_PREFIX}={debug_id}\n");
|
|
188
135
|
|
|
189
|
-
|
|
190
|
-
while let Some(use_pragma) = js_lines.next_if(|line| USE_PRAGMA_RE.is_match(line)) {
|
|
191
|
-
writeln!(js_contents, "{use_pragma}")?;
|
|
192
|
-
}
|
|
136
|
+
let mut magic = MagicString::new(contents);
|
|
193
137
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
138
|
+
magic
|
|
139
|
+
.append_left(m.end as u32, &code_snippet)
|
|
140
|
+
.unwrap()
|
|
141
|
+
.append(&debug_id_comment)
|
|
142
|
+
.unwrap();
|
|
197
143
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
writeln!(js_contents, "{line}")?;
|
|
201
|
-
}
|
|
144
|
+
js_contents.clear();
|
|
145
|
+
write!(js_contents, "{}", magic.to_string())?;
|
|
202
146
|
|
|
203
|
-
|
|
204
|
-
|
|
147
|
+
let map = magic
|
|
148
|
+
.generate_map(GenerateDecodedMapOptions {
|
|
149
|
+
source: Some("pre_injection.js".to_string()),
|
|
150
|
+
include_content: true,
|
|
151
|
+
..Default::default()
|
|
152
|
+
})
|
|
153
|
+
.unwrap();
|
|
205
154
|
|
|
206
|
-
|
|
207
|
-
if let Some(sourcemap_comment) = sourcemap_comment {
|
|
208
|
-
writeln!(js_contents, "{sourcemap_comment}")?;
|
|
209
|
-
}
|
|
155
|
+
let map = map.to_string().unwrap();
|
|
210
156
|
|
|
211
|
-
Ok(())
|
|
157
|
+
Ok(SourceMap::from_slice(map.as_bytes()).unwrap())
|
|
212
158
|
}
|
|
213
159
|
|
|
214
160
|
/// Fixes up a minified JS source file with a debug id without messing with mappings.
|
|
@@ -231,14 +177,9 @@ pub fn fixup_js_file_end(js_contents: &mut Vec<u8>, debug_id: DebugId) -> Result
|
|
|
231
177
|
|
|
232
178
|
js_contents.clear();
|
|
233
179
|
|
|
234
|
-
let sourcemap_comment_idx = js_lines
|
|
235
|
-
.
|
|
236
|
-
|
|
237
|
-
.rev()
|
|
238
|
-
.find(|(_idx, line)| {
|
|
239
|
-
line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=")
|
|
240
|
-
})
|
|
241
|
-
.map(|(idx, _)| idx);
|
|
180
|
+
let sourcemap_comment_idx = js_lines.iter().rposition(|line| {
|
|
181
|
+
line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=")
|
|
182
|
+
});
|
|
242
183
|
|
|
243
184
|
let sourcemap_comment = sourcemap_comment_idx.map(|idx| js_lines.remove(idx));
|
|
244
185
|
|
|
@@ -248,11 +189,10 @@ pub fn fixup_js_file_end(js_contents: &mut Vec<u8>, debug_id: DebugId) -> Result
|
|
|
248
189
|
|
|
249
190
|
let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string());
|
|
250
191
|
writeln!(js_contents, "{to_inject}")?;
|
|
251
|
-
writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?;
|
|
252
|
-
|
|
253
192
|
if let Some(sourcemap_comment) = sourcemap_comment {
|
|
254
193
|
writeln!(js_contents, "{sourcemap_comment}")?;
|
|
255
194
|
}
|
|
195
|
+
writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?;
|
|
256
196
|
|
|
257
197
|
Ok(())
|
|
258
198
|
}
|
|
@@ -264,11 +204,10 @@ pub fn fixup_js_file_end(js_contents: &mut Vec<u8>, debug_id: DebugId) -> Result
|
|
|
264
204
|
pub fn replace_sourcemap_url(js_contents: &mut Vec<u8>, new_url: &str) -> Result<()> {
|
|
265
205
|
let js_lines = js_contents.lines().collect::<Result<Vec<_>, _>>()?;
|
|
266
206
|
|
|
267
|
-
let sourcemap_comment_idx =
|
|
207
|
+
let Some(sourcemap_comment_idx) = js_lines.iter().rposition(|line| {
|
|
268
208
|
line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=")
|
|
269
|
-
}) {
|
|
270
|
-
|
|
271
|
-
None => return Ok(()),
|
|
209
|
+
}) else {
|
|
210
|
+
return Ok(());
|
|
272
211
|
};
|
|
273
212
|
|
|
274
213
|
js_contents.clear();
|
|
@@ -295,74 +234,6 @@ pub fn debug_id_from_bytes_hashed(bytes: &[u8]) -> DebugId {
|
|
|
295
234
|
DebugId::from_uuid(uuid::Builder::from_sha1_bytes(sha1_bytes).into_uuid())
|
|
296
235
|
}
|
|
297
236
|
|
|
298
|
-
/// Fixes up a sourcemap file with a debug id.
|
|
299
|
-
///
|
|
300
|
-
/// If the file already contains a debug id under the `debug_id` key, it is left unmodified.
|
|
301
|
-
/// Otherwise, a fresh debug id is inserted under that key.
|
|
302
|
-
///
|
|
303
|
-
/// In either case, the value of the `debug_id` key is returned.
|
|
304
|
-
pub fn fixup_sourcemap(sourcemap_contents: &mut Vec<u8>) -> Result<(DebugId, bool)> {
|
|
305
|
-
match sourcemap::decode_slice(sourcemap_contents).context("Invalid sourcemap")? {
|
|
306
|
-
sourcemap::DecodedMap::Regular(mut sm) => {
|
|
307
|
-
if let Some(debug_id) = sm.get_debug_id() {
|
|
308
|
-
debug!("Sourcemap already has a debug id");
|
|
309
|
-
Ok((debug_id, false))
|
|
310
|
-
} else {
|
|
311
|
-
let debug_id = debug_id_from_bytes_hashed(sourcemap_contents);
|
|
312
|
-
sm.set_debug_id(Some(debug_id));
|
|
313
|
-
|
|
314
|
-
sourcemap_contents.clear();
|
|
315
|
-
sm.to_writer(sourcemap_contents)?;
|
|
316
|
-
Ok((debug_id, true))
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
sourcemap::DecodedMap::Hermes(mut smh) => {
|
|
320
|
-
if let Some(debug_id) = smh.get_debug_id() {
|
|
321
|
-
debug!("Sourcemap already has a debug id");
|
|
322
|
-
Ok((debug_id, false))
|
|
323
|
-
} else {
|
|
324
|
-
let debug_id = debug_id_from_bytes_hashed(sourcemap_contents);
|
|
325
|
-
smh.set_debug_id(Some(debug_id));
|
|
326
|
-
|
|
327
|
-
sourcemap_contents.clear();
|
|
328
|
-
smh.to_writer(sourcemap_contents)?;
|
|
329
|
-
Ok((debug_id, true))
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
sourcemap::DecodedMap::Index(_) => {
|
|
333
|
-
bail!("DebugId injection is not supported for sourcemap indexes")
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/// This adds an empty mapping at the start of a sourcemap.
|
|
339
|
-
///
|
|
340
|
-
/// This is used to adjust a sourcemap when the corresponding source file has a
|
|
341
|
-
/// new line injected near the top (see [`fixup_js_file`]).
|
|
342
|
-
pub fn insert_empty_mapping(sourcemap_contents: &mut Vec<u8>) -> Result<()> {
|
|
343
|
-
let mut sourcemap: Value = serde_json::from_slice(sourcemap_contents)?;
|
|
344
|
-
|
|
345
|
-
let Some(map) = sourcemap.as_object_mut() else {
|
|
346
|
-
bail!("Invalid sourcemap");
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
let Some(mappings) = map.get_mut("mappings") else {
|
|
350
|
-
bail!("Invalid sourcemap");
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
let Value::String(mappings) = mappings else {
|
|
354
|
-
bail!("Invalid sourcemap");
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// Insert empty mapping at the start
|
|
358
|
-
*mappings = format!(";{mappings}");
|
|
359
|
-
|
|
360
|
-
sourcemap_contents.clear();
|
|
361
|
-
serde_json::to_writer(sourcemap_contents, &sourcemap)?;
|
|
362
|
-
|
|
363
|
-
Ok(())
|
|
364
|
-
}
|
|
365
|
-
|
|
366
237
|
/// Computes a normalized sourcemap URL from a source file's own URL und the relative URL of its sourcemap.
|
|
367
238
|
///
|
|
368
239
|
/// Roughly, this will combine a source URL of `some/dir/source.js` and a sourcemap URL of `path/to/source.min.js`
|
|
@@ -441,44 +312,12 @@ pub fn find_matching_paths(candidate_paths: &[String], expected_path: &str) -> V
|
|
|
441
312
|
|
|
442
313
|
#[cfg(test)]
|
|
443
314
|
mod tests {
|
|
444
|
-
use std::io::Write;
|
|
445
|
-
|
|
446
315
|
use sentry::types::DebugId;
|
|
447
316
|
|
|
448
317
|
use crate::utils::fs::TempFile;
|
|
449
318
|
|
|
450
319
|
use super::*;
|
|
451
320
|
|
|
452
|
-
#[test]
|
|
453
|
-
fn test_fixup_sourcemap() {
|
|
454
|
-
for sourcemap_path in &[
|
|
455
|
-
"server/chunks/1.js.map",
|
|
456
|
-
"server/edge-runtime-webpack.js.map",
|
|
457
|
-
"server/pages/_document.js.map",
|
|
458
|
-
"server/pages/asdf.js.map",
|
|
459
|
-
"static/chunks/575-bb7d7e0e6de8d623.js.map",
|
|
460
|
-
"static/chunks/app/client/page-d5742c254d9533f8.js.map",
|
|
461
|
-
"static/chunks/pages/asdf-05b39167abbe433b.js.map",
|
|
462
|
-
] {
|
|
463
|
-
let mut sourcemap_contents = std::fs::read(format!(
|
|
464
|
-
"tests/integration/_fixtures/inject/{sourcemap_path}"
|
|
465
|
-
))
|
|
466
|
-
.unwrap();
|
|
467
|
-
|
|
468
|
-
assert!(
|
|
469
|
-
sourcemap::decode_slice(&sourcemap_contents).is_ok(),
|
|
470
|
-
"sourcemap is valid before injection"
|
|
471
|
-
);
|
|
472
|
-
|
|
473
|
-
fixup_sourcemap(&mut sourcemap_contents).unwrap();
|
|
474
|
-
|
|
475
|
-
assert!(
|
|
476
|
-
sourcemap::decode_slice(&sourcemap_contents).is_ok(),
|
|
477
|
-
"sourcemap is valid after injection"
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
321
|
#[test]
|
|
483
322
|
fn test_fixup_js_file() {
|
|
484
323
|
let source = r#"//# sourceMappingURL=fake1
|
|
@@ -494,12 +333,13 @@ something else"#;
|
|
|
494
333
|
fixup_js_file(&mut source, debug_id).unwrap();
|
|
495
334
|
|
|
496
335
|
let expected = r#"//# sourceMappingURL=fake1
|
|
336
|
+
|
|
497
337
|
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}();
|
|
498
338
|
some line
|
|
499
339
|
//# sourceMappingURL=fake2
|
|
340
|
+
//# sourceMappingURL=real
|
|
500
341
|
something else
|
|
501
342
|
//# debugId=00000000-0000-0000-0000-000000000000
|
|
502
|
-
//# sourceMappingURL=real
|
|
503
343
|
"#;
|
|
504
344
|
|
|
505
345
|
assert_eq!(std::str::from_utf8(&source).unwrap(), expected);
|
|
@@ -547,6 +387,7 @@ something else"#;
|
|
|
547
387
|
let expected = r#"//# sourceMappingURL=fake
|
|
548
388
|
|
|
549
389
|
|
|
390
|
+
|
|
550
391
|
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}();
|
|
551
392
|
some line
|
|
552
393
|
//# sourceMappingURL=fake
|
|
@@ -562,9 +403,9 @@ some line
|
|
|
562
403
|
//# sourceMappingURL=fake
|
|
563
404
|
//# sourceMappingURL=fake
|
|
564
405
|
//# sourceMappingURL=fake
|
|
406
|
+
//# sourceMappingURL=real
|
|
565
407
|
something else
|
|
566
408
|
//# debugId=00000000-0000-0000-0000-000000000000
|
|
567
|
-
//# sourceMappingURL=real
|
|
568
409
|
"#;
|
|
569
410
|
|
|
570
411
|
println!("{}", result);
|
|
@@ -594,14 +435,15 @@ something else"#;
|
|
|
594
435
|
//# sourceMappingURL=fake1
|
|
595
436
|
|
|
596
437
|
// some other comment
|
|
597
|
-
"use strict";
|
|
598
|
-
'use strict';
|
|
438
|
+
"use strict";
|
|
599
439
|
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}();
|
|
440
|
+
rest of the line
|
|
441
|
+
'use strict';
|
|
600
442
|
some line
|
|
601
443
|
//# sourceMappingURL=fake2
|
|
444
|
+
//# sourceMappingURL=real
|
|
602
445
|
something else
|
|
603
446
|
//# debugId=00000000-0000-0000-0000-000000000000
|
|
604
|
-
//# sourceMappingURL=real
|
|
605
447
|
"#;
|
|
606
448
|
|
|
607
449
|
assert_eq!(std::str::from_utf8(&source).unwrap(), expected);
|
|
@@ -630,14 +472,15 @@ something else"#;
|
|
|
630
472
|
//# sourceMappingURL=fake1
|
|
631
473
|
|
|
632
474
|
// some other comment
|
|
633
|
-
"use strict";
|
|
475
|
+
"use strict";
|
|
634
476
|
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}();
|
|
477
|
+
rest of the line
|
|
635
478
|
(this.foo=this.bar||[]).push([[2],[function(e,t,n){"use strict"; […] }
|
|
636
479
|
some line
|
|
637
480
|
//# sourceMappingURL=fake2
|
|
481
|
+
//# sourceMappingURL=real
|
|
638
482
|
something else
|
|
639
483
|
//# debugId=00000000-0000-0000-0000-000000000000
|
|
640
|
-
//# sourceMappingURL=real
|
|
641
484
|
"#;
|
|
642
485
|
|
|
643
486
|
assert_eq!(std::str::from_utf8(&source).unwrap(), expected);
|
|
@@ -13,12 +13,12 @@ use indicatif::ProgressStyle;
|
|
|
13
13
|
use log::{debug, info, warn};
|
|
14
14
|
use sentry::types::DebugId;
|
|
15
15
|
use sha1_smol::Digest;
|
|
16
|
+
use sourcemap::SourceMap;
|
|
16
17
|
use symbolic::debuginfo::js::{
|
|
17
18
|
discover_debug_id, discover_sourcemap_embedded_debug_id, discover_sourcemaps_location,
|
|
18
19
|
};
|
|
19
20
|
use symbolic::debuginfo::sourcebundle::SourceFileType;
|
|
20
21
|
use url::Url;
|
|
21
|
-
use uuid::Uuid;
|
|
22
22
|
|
|
23
23
|
use crate::api::Api;
|
|
24
24
|
use crate::utils::enc::decode_unknown_string;
|
|
@@ -790,134 +790,166 @@ impl SourceMapProcessor {
|
|
|
790
790
|
continue;
|
|
791
791
|
}
|
|
792
792
|
|
|
793
|
-
//
|
|
794
|
-
//
|
|
795
|
-
//
|
|
796
|
-
let
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
793
|
+
// Modify the source file and the sourcemap.
|
|
794
|
+
// There are several cases to consider according to whether we have a sourcemap for the source file and
|
|
795
|
+
// whether it's embedded or external.
|
|
796
|
+
let debug_id = match sourcemap_url {
|
|
797
|
+
None => {
|
|
798
|
+
// Case 1: We have no sourcemap for the source file. Hash the file contents for the debug id.
|
|
799
|
+
let source_file = self.sources.get_mut(source_url).unwrap();
|
|
800
|
+
let debug_id = inject::debug_id_from_bytes_hashed(&source_file.contents);
|
|
801
|
+
|
|
802
|
+
// If we don't have a sourcemap, it's not safe to inject the code snippet at the beginning,
|
|
803
|
+
// because that would throw off all the mappings. Instead, inject the snippet at the very end.
|
|
804
|
+
// This isn't ideal, but it's the best we can do in this case.
|
|
805
|
+
inject::fixup_js_file_end(&mut source_file.contents, debug_id)
|
|
806
|
+
.context(format!("Failed to process {}", source_file.path.display()))?;
|
|
807
|
+
debug_id
|
|
808
|
+
}
|
|
809
|
+
Some(sourcemap_url) => {
|
|
810
|
+
if let Some(encoded) = sourcemap_url.strip_prefix(DATA_PREAMBLE) {
|
|
811
|
+
// Case 2: The source file has an embedded sourcemap.
|
|
812
|
+
|
|
813
|
+
let Ok(mut decoded) = data_encoding::BASE64.decode(encoded.as_bytes())
|
|
814
|
+
else {
|
|
815
|
+
bail!("Invalid embedded sourcemap in source file {source_url}");
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
let sourcemap = SourceMap::from_slice(&decoded)
|
|
819
|
+
.context("Invalid embedded sourcemap in source file {source_url}")?;
|
|
820
|
+
|
|
821
|
+
let debug_id = sourcemap
|
|
822
|
+
.get_debug_id()
|
|
823
|
+
.unwrap_or_else(|| inject::debug_id_from_bytes_hashed(&decoded));
|
|
824
|
+
|
|
825
|
+
let source_file = self.sources.get_mut(source_url).unwrap();
|
|
826
|
+
let adjustment_map =
|
|
827
|
+
inject::fixup_js_file(&mut source_file.contents, debug_id).context(
|
|
828
|
+
format!("Failed to process {}", source_file.path.display()),
|
|
829
|
+
)?;
|
|
830
|
+
let mut adjusted_map =
|
|
831
|
+
SourceMap::adjust_mappings(&sourcemap, &adjustment_map);
|
|
832
|
+
adjusted_map.set_debug_id(Some(debug_id));
|
|
819
833
|
|
|
820
|
-
|
|
834
|
+
decoded.clear();
|
|
835
|
+
adjusted_map.to_writer(&mut decoded)?;
|
|
821
836
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
inject::debug_id_from_bytes_hashed(new_sourcemap_url.as_bytes());
|
|
837
|
+
let encoded = data_encoding::BASE64.encode(&decoded);
|
|
838
|
+
let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}");
|
|
825
839
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
840
|
+
inject::replace_sourcemap_url(
|
|
841
|
+
&mut source_file.contents,
|
|
842
|
+
&new_sourcemap_url,
|
|
843
|
+
)?;
|
|
844
|
+
*sourcemap_url = new_sourcemap_url;
|
|
831
845
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
846
|
+
debug_id
|
|
847
|
+
} else {
|
|
848
|
+
// Handle external sourcemaps
|
|
849
|
+
|
|
850
|
+
let normalized = inject::normalize_sourcemap_url(source_url, sourcemap_url);
|
|
851
|
+
let matches = inject::find_matching_paths(&sourcemaps, &normalized);
|
|
852
|
+
|
|
853
|
+
let sourcemap_url = match &matches[..] {
|
|
854
|
+
[] => normalized,
|
|
855
|
+
[x] => x.to_string(),
|
|
856
|
+
_ => {
|
|
857
|
+
warn!("Ambiguous matches for sourcemap path {normalized}:");
|
|
858
|
+
for path in matches {
|
|
859
|
+
warn!("{path}");
|
|
860
|
+
}
|
|
861
|
+
normalized
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
if self.sources.contains_key(&sourcemap_url) {
|
|
866
|
+
// Case 3: We have an external sourcemap for the source file.
|
|
867
|
+
|
|
868
|
+
// We need to do a bit of a dance here because we can't mutably
|
|
869
|
+
// borrow the source file and the sourcemap at the same time.
|
|
870
|
+
let (sourcemap, debug_id, debug_id_fresh) = {
|
|
871
|
+
let sourcemap_file = &self.sources[&sourcemap_url];
|
|
872
|
+
|
|
873
|
+
let sm = SourceMap::from_slice(&sourcemap_file.contents).context(
|
|
874
|
+
format!("Invalid sourcemap at {}", sourcemap_file.url),
|
|
875
|
+
)?;
|
|
876
|
+
|
|
877
|
+
match sm.get_debug_id() {
|
|
878
|
+
Some(debug_id) => (sm, debug_id, false),
|
|
879
|
+
None => {
|
|
880
|
+
let debug_id = inject::debug_id_from_bytes_hashed(
|
|
881
|
+
&sourcemap_file.contents,
|
|
882
|
+
);
|
|
883
|
+
(sm, debug_id, true)
|
|
847
884
|
}
|
|
848
|
-
normalized
|
|
849
885
|
}
|
|
850
886
|
};
|
|
851
887
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
sourcemap_file
|
|
879
|
-
.headers
|
|
880
|
-
.push(("debug-id".to_string(), debug_id.to_string()));
|
|
881
|
-
|
|
882
|
-
if !dry_run {
|
|
883
|
-
let mut file = std::fs::File::create(&sourcemap_file.path)?;
|
|
884
|
-
file.write_all(&sourcemap_file.contents).context(
|
|
885
|
-
format!(
|
|
886
|
-
"Failed to write sourcemap file {}",
|
|
887
|
-
sourcemap_file.path.display()
|
|
888
|
-
),
|
|
889
|
-
)?;
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
if sourcemap_modified {
|
|
893
|
-
report
|
|
894
|
-
.sourcemaps
|
|
895
|
-
.push((sourcemap_file.path.clone(), debug_id));
|
|
896
|
-
} else {
|
|
897
|
-
report
|
|
898
|
-
.skipped_sourcemaps
|
|
899
|
-
.push((sourcemap_file.path.clone(), debug_id));
|
|
900
|
-
}
|
|
888
|
+
let source_file = self.sources.get_mut(source_url).unwrap();
|
|
889
|
+
let adjustment_map =
|
|
890
|
+
inject::fixup_js_file(&mut source_file.contents, debug_id)
|
|
891
|
+
.context(format!(
|
|
892
|
+
"Failed to process {}",
|
|
893
|
+
source_file.path.display()
|
|
894
|
+
))?;
|
|
895
|
+
let mut adjusted_map =
|
|
896
|
+
SourceMap::adjust_mappings(&sourcemap, &adjustment_map);
|
|
897
|
+
adjusted_map.set_debug_id(Some(debug_id));
|
|
898
|
+
|
|
899
|
+
let sourcemap_file = self.sources.get_mut(&sourcemap_url).unwrap();
|
|
900
|
+
sourcemap_file.contents.clear();
|
|
901
|
+
adjusted_map.to_writer(&mut sourcemap_file.contents)?;
|
|
902
|
+
|
|
903
|
+
sourcemap_file
|
|
904
|
+
.headers
|
|
905
|
+
.push(("debug-id".to_string(), debug_id.to_string()));
|
|
906
|
+
|
|
907
|
+
if !dry_run {
|
|
908
|
+
let mut file = std::fs::File::create(&sourcemap_file.path)?;
|
|
909
|
+
file.write_all(&sourcemap_file.contents).context(format!(
|
|
910
|
+
"Failed to write sourcemap file {}",
|
|
911
|
+
sourcemap_file.path.display()
|
|
912
|
+
))?;
|
|
913
|
+
}
|
|
901
914
|
|
|
902
|
-
|
|
903
|
-
|
|
915
|
+
if debug_id_fresh {
|
|
916
|
+
report
|
|
917
|
+
.sourcemaps
|
|
918
|
+
.push((sourcemap_file.path.clone(), debug_id));
|
|
919
|
+
} else {
|
|
920
|
+
report
|
|
921
|
+
.skipped_sourcemaps
|
|
922
|
+
.push((sourcemap_file.path.clone(), debug_id));
|
|
904
923
|
}
|
|
924
|
+
|
|
925
|
+
debug_id
|
|
926
|
+
} else {
|
|
927
|
+
// Case 4: We have a URL for the external sourcemap, but we can't find it.
|
|
928
|
+
// This is substantially the same as case 1.
|
|
929
|
+
debug!("Sourcemap file {} not found", sourcemap_url);
|
|
930
|
+
// source map cannot be found, fall back to hashing the contents.
|
|
931
|
+
let source_file = self.sources.get_mut(source_url).unwrap();
|
|
932
|
+
let debug_id =
|
|
933
|
+
inject::debug_id_from_bytes_hashed(&source_file.contents);
|
|
934
|
+
|
|
935
|
+
// If we don't have a sourcemap, it's not safe to inject the code snippet at the beginning,
|
|
936
|
+
// because that would throw off all the mappings. Instead, inject the snippet at the very end.
|
|
937
|
+
// This isn't ideal, but it's the best we can do in this case.
|
|
938
|
+
inject::fixup_js_file_end(&mut source_file.contents, debug_id)
|
|
939
|
+
.context(format!(
|
|
940
|
+
"Failed to process {}",
|
|
941
|
+
source_file.path.display()
|
|
942
|
+
))?;
|
|
943
|
+
|
|
944
|
+
debug_id
|
|
905
945
|
}
|
|
906
946
|
}
|
|
907
947
|
}
|
|
908
948
|
};
|
|
909
949
|
|
|
910
|
-
// Finally,
|
|
950
|
+
// Finally, some housekeeping.
|
|
911
951
|
let source_file = self.sources.get_mut(source_url).unwrap();
|
|
912
952
|
|
|
913
|
-
if inject_at_start {
|
|
914
|
-
inject::fixup_js_file(&mut source_file.contents, debug_id)
|
|
915
|
-
.context(format!("Failed to process {}", source_file.path.display()))?;
|
|
916
|
-
} else {
|
|
917
|
-
inject::fixup_js_file_end(&mut source_file.contents, debug_id)
|
|
918
|
-
.context(format!("Failed to process {}", source_file.path.display()))?;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
953
|
source_file
|
|
922
954
|
.headers
|
|
923
955
|
.push(("debug-id".to_string(), debug_id.to_string()));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|