-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathmod.rs
More file actions
145 lines (125 loc) · 4.18 KB
/
Copy pathmod.rs
File metadata and controls
145 lines (125 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
use anyhow::Result;
use clap::Subcommand;
use crate::sourcemaps::{
args::{
FileSelectionArgs, ReleaseArgs, ReleaseMode, UploadConcurrencyArgs, UploadConflictArgs,
},
inject::InjectArgs,
};
pub mod inject;
pub mod upload;
#[derive(Subcommand)]
pub enum SourcemapCommand {
/// Inject each bundled chunk with a posthog chunk ID
Inject(InjectArgs),
/// Upload the bundled chunks to PostHog
Upload(upload::Args),
/// Run inject and upload in one command
Process(ProcessArgs),
}
#[derive(clap::Args)]
pub struct ProcessArgs {
#[clap(flatten)]
pub file_selection: FileSelectionArgs,
/// If your bundler adds a public path prefix to sourcemap URLs,
/// we need to ignore it while searching for them
/// For use alongside e.g. esbuilds "publicPath" config setting.
#[arg(short, long)]
pub public_path_prefix: Option<String>,
#[clap(flatten)]
pub release: ReleaseArgs,
/// Whether to delete the source map files and strip sourceMappingURL comments after uploading them
/// [default: false]
#[arg(long, default_value = "false")]
pub delete_after: bool,
/// The maximum number of chunks to upload in a single batch
#[arg(long, default_value = "50")]
pub batch_size: usize,
#[clap(flatten)]
pub conflict: UploadConflictArgs,
#[clap(flatten)]
pub upload_concurrency: UploadConcurrencyArgs,
/// How the release is associated with exceptions. `event` (the default) injects the release
/// id into each chunk as `_posthogReleaseId` (alongside content-addressed chunk ids) so the
/// SDK reports the release per event; symbol sets stay release-independent. `symbol-set`
/// stamps the release id onto the uploaded symbol sets instead. Also settable via
/// `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
default_value = "event"
)]
pub release_mode: ReleaseMode,
}
impl ProcessArgs {
/// Resolve stdin paths once so they can be shared between inject and upload.
pub fn resolve_stdin(mut self) -> Result<Self> {
self.file_selection = self.file_selection.resolve_stdin()?;
Ok(self)
}
}
impl From<ProcessArgs> for (InjectArgs, upload::Args) {
fn from(args: ProcessArgs) -> Self {
let inject_args = InjectArgs {
file_selection: args.file_selection.clone(),
release: args.release.clone(),
public_path_prefix: args.public_path_prefix.clone(),
release_mode: args.release_mode,
};
let upload_args = upload::Args {
file_selection: args.file_selection,
public_path_prefix: args.public_path_prefix,
delete_after: args.delete_after,
skip_ssl_verification: false,
batch_size: args.batch_size,
release: args.release,
conflict: args.conflict,
upload_concurrency: args.upload_concurrency,
release_mode: args.release_mode,
};
(inject_args, upload_args)
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[derive(Parser)]
struct SourcemapCli {
#[command(subcommand)]
command: SourcemapCommand,
}
#[test]
fn process_accepts_concurrency_override() {
let parsed = SourcemapCli::try_parse_from([
"test",
"process",
"--directory",
".",
"--concurrency",
"18",
])
.expect("process args should parse");
let SourcemapCommand::Process(args) = parsed.command else {
panic!("expected process command");
};
assert_eq!(args.upload_concurrency.concurrency.get(), 18);
}
#[test]
fn upload_accepts_concurrency_override() {
let parsed = SourcemapCli::try_parse_from([
"test",
"upload",
"--directory",
".",
"--concurrency",
"24",
])
.expect("upload args should parse");
let SourcemapCommand::Upload(args) = parsed.command else {
panic!("expected upload command");
};
assert_eq!(args.upload_concurrency.concurrency.get(), 24);
}
}