git.delta.rocks / jrsonnet / refs/commits / 363bd28e4d9b

difftreelog

feat bundler

qpttwnpnYaroslav Bolyukin2026-05-26parent: #a9ea23a.patch.diff
in: master

17 files changed

modifiedCargo.lockdiffbeforeafterboth
2389name = "jrb"2389name = "jrb"
2390version = "0.5.0-pre99"2390version = "0.5.0-pre99"
2391dependencies = [2391dependencies = [
2392 "base64",
2392 "clap",2393 "clap",
2394 "jrsonnet-lexer",
2395 "jrsonnet-pack",
2393 "jrsonnet-pkg",2396 "jrsonnet-pkg",
2397 "jrsonnet-rowan-parser",
2394 "rustls",2398 "rustls",
2395 "serde",2399 "serde",
2396 "serde_json",2400 "serde_json",
2429name = "jrsonnet-deps"2433name = "jrsonnet-deps"
2430version = "0.5.0-pre99"2434version = "0.5.0-pre99"
2431dependencies = [2435dependencies = [
2436 "base64",
2432 "clap",2437 "clap",
2433 "jrsonnet-cli",2438 "jrsonnet-cli",
2434 "jrsonnet-evaluator",2439 "jrsonnet-evaluator",
2435 "jrsonnet-ir",2440 "jrsonnet-ir",
2436 "jrsonnet-ir-parser",2441 "jrsonnet-ir-parser",
2442 "jrsonnet-pack",
2443 "serde_json",
2437]2444]
24382445
2439[[package]]2446[[package]]
2558 "syn-dissect-closure",2565 "syn-dissect-closure",
2559]2566]
2567
2568[[package]]
2569name = "jrsonnet-pack"
2570version = "0.5.0-pre99"
2571dependencies = [
2572 "base64",
2573 "jrsonnet-evaluator",
2574 "jrsonnet-ir",
2575 "jrsonnet-ir-parser",
2576 "jrsonnet-lexer",
2577 "jrsonnet-rowan-parser",
2578 "serde",
2579 "serde_json",
2580 "thiserror",
2581]
25602582
2561[[package]]2583[[package]]
2562name = "jrsonnet-peg-parser"2584name = "jrsonnet-peg-parser"
modifiedCargo.tomldiffbeforeafterboth
36jrsonnet-formatter = { path = "./crates/jrsonnet-formatter", version = "0.5.0-pre99" }36jrsonnet-formatter = { path = "./crates/jrsonnet-formatter", version = "0.5.0-pre99" }
37jrsonnet-lexer = { path = "./crates/jrsonnet-lexer", version = "0.5.0-pre99" }37jrsonnet-lexer = { path = "./crates/jrsonnet-lexer", version = "0.5.0-pre99" }
38jrsonnet-pkg = { path = "./crates/jrsonnet-pkg", version = "0.5.0-pre99" }38jrsonnet-pkg = { path = "./crates/jrsonnet-pkg", version = "0.5.0-pre99" }
39jrsonnet-pack = { path = "./crates/jrsonnet-pack", version = "0.5.0-pre99" }
39jrsonnet-gcmodule = { version = "0.5.0" }40jrsonnet-gcmodule = { version = "0.5.0" }
40# Diagnostics.41# Diagnostics.
41# hi-doc is my library, which handles text formatting very well, but isn't polished enough yet42# hi-doc is my library, which handles text formatting very well, but isn't polished enough yet
modifiedcmds/jrb/Cargo.tomldiffbeforeafterboth
1212
13[dependencies]13[dependencies]
14jrsonnet-pkg.workspace = true14jrsonnet-pkg.workspace = true
1515jrsonnet-rowan-parser.workspace = true
16jrsonnet-lexer.workspace = true
17jrsonnet-pack.workspace = true
18
19base64.workspace = true
16clap = { workspace = true, features = ["derive"] }20clap = { workspace = true, features = ["derive"] }
17serde = { workspace = true }21serde = { workspace = true }
18serde_json.workspace = true22serde_json.workspace = true
modifiedcmds/jrb/src/main.rsdiffbeforeafterboth
8 install,8 install,
9 jsonnet_bundler::{GitSource, JsonnetFile},9 jsonnet_bundler::{GitSource, JsonnetFile},
10};10};
11use tracing::{error, info, warn};11use tracing::{debug, error, info, warn};
12
13mod rewrite;
1214
13#[derive(Parser)]15#[derive(Parser)]
14#[clap(about = "A jsonnet package manager")]16#[clap(about = "A jsonnet package manager")]
48 #[clap(long)]50 #[clap(long)]
49 dry_run: bool,51 dry_run: bool,
50 },52 },
53 /// Rewrite `legacyImports`-style import paths to their canonical equivalents
54 Rewrite {
55 /// Paths to scan (defaults to current directory)
56 paths: Vec<PathBuf>,
57 /// Show what would be rewritten without making changes
58 #[clap(long)]
59 dry_run: bool,
60 },
51}61}
5262
53const MANIFEST: &str = "jsonnetfile.json";63const MANIFEST: &str = "jsonnetfile.json";
223 save_json(Path::new(LOCKFILE), &manifest);233 save_json(Path::new(LOCKFILE), &manifest);
224 }234 }
225 }235 }
236 Command::Rewrite { paths, dry_run } => {
237 let rules = rewrite::rules_from_vendor(&opts.jsonnetpkg_home);
238 if rules.is_empty() {
239 warn!(
240 "no legacy symlinks found under {} — nothing to rewrite",
241 opts.jsonnetpkg_home.display(),
242 );
243 return;
244 }
245 for r in &rules {
246 debug!("rule: {} -> {}", r.legacy, r.canonical);
247 }
248 let scan_paths = if paths.is_empty() {
249 vec![PathBuf::from(".")]
250 } else {
251 paths
252 };
253 let stats = rewrite::rewrite(&scan_paths, &opts.jsonnetpkg_home, &rules, dry_run);
254 let verb = if dry_run { "would rewrite" } else { "rewrote" };
255 info!(
256 "scanned {} file(s); {verb} {} import(s) across {} file(s)",
257 stats.files_scanned, stats.imports_rewritten, stats.files_modified,
258 );
259 }
226 }260 }
227}261}
228262
addedcmds/jrb/src/rewrite.rsdiffbeforeafterboth

no changes

modifiedcmds/jrsonnet-deps/Cargo.tomldiffbeforeafterboth
17jrsonnet-ir.workspace = true17jrsonnet-ir.workspace = true
18jrsonnet-ir-parser.workspace = true18jrsonnet-ir-parser.workspace = true
19jrsonnet-cli.workspace = true19jrsonnet-cli.workspace = true
20jrsonnet-pack.workspace = true
2021
21clap = { workspace = true, features = ["derive"] }22clap = { workspace = true, features = ["derive"] }
23base64.workspace = true
24serde_json.workspace = true
2225
modifiedcmds/jrsonnet-deps/src/main.rsdiffbeforeafterboth
1use std::{collections::BTreeSet, process::exit};1use std::{
22 collections::{BTreeMap, btree_map::Entry},
3 process::exit,
4};
5
6use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
3use clap::Parser;7use clap::{Parser, ValueEnum};
4use jrsonnet_cli::MiscOpts;8use jrsonnet_cli::MiscOpts;
5use jrsonnet_evaluator::{FileImportResolver, ImportResolver};9use jrsonnet_evaluator::{FileImportResolver, ImportResolver};
6use jrsonnet_ir::{IStr, Source, SourcePath, visit::Visitor};10use jrsonnet_ir::{IStr, Source, SourcePath, visit::Visitor};
7use jrsonnet_ir_parser::ParserSettings;11use jrsonnet_ir_parser::ParserSettings;
12use jrsonnet_pack::{bundle_onefile, bundle_playground};
813
9#[derive(Parser)]14#[derive(Parser)]
10struct Opts {15struct Opts {
11 /// Path to the file to start dependency search from16 /// Path to the file to start dependency search from
12 input: String,17 input: String,
18 /// Bundle the entry and its imports.
19 #[clap(long, value_enum, num_args = 0..=1, default_missing_value = "json")]
20 bundle: Option<BundleMode>,
21 /// Output format for the bundled playground (e.g. json, yaml, toml, string)
22 #[clap(long)]
23 bundle_format: Option<String>,
13 #[clap(flatten)]24 #[clap(flatten)]
14 misc: MiscOpts,25 misc: MiscOpts,
15}26}
27
28#[derive(Clone, Copy, ValueEnum, Debug)]
29enum BundleMode {
30 /// Plain playground bundle JSON.
31 Json,
32 /// Playground bundle as a shareable URL.
33 Url,
34 /// Single self-contained jsonnet expression.
35 Onefile,
36}
1637
17struct FoundImports(Vec<(IStr, bool)>);38struct FoundImports(Vec<(IStr, bool)>);
18impl Visitor for FoundImports {39impl Visitor for FoundImports {
24fn collect_deps(45fn collect_deps(
25 resolver: &FileImportResolver,46 resolver: &FileImportResolver,
26 source: &SourcePath,47 source: &SourcePath,
27 deps: &mut BTreeSet<String>,48 deps: &mut BTreeMap<String, SourcePath>,
28) -> Result<(), String> {49) -> Result<(), String> {
29 let contents = resolver50 let contents = resolver
30 .load_file_contents(source)51 .load_file_contents(source)
46 let resolved = resolver67 let resolved = resolver
47 .resolve_from(source, &&*path)68 .resolve_from(source, &&*path)
48 .map_err(|e| format!("{e}"))?;69 .map_err(|e| format!("{e}"))?;
49 let path_str = format!("{resolved}");70 let key = format!("{resolved}");
50 if deps.insert(path_str) && expression {71 if let Entry::Vacant(e) = deps.entry(key) {
72 e.insert(resolved.clone());
73 if expression {
51 collect_deps(resolver, &resolved, deps)?;74 collect_deps(resolver, &resolved, deps)?;
52 }75 }
76 }
53 }77 }
5478
55 Ok(())79 Ok(())
66 exit(1);90 exit(1);
67 });91 });
6892
69 let mut deps = BTreeSet::new();93 if let Some(mode) = opts.bundle {
94 match mode {
95 BundleMode::Json => {
96 let b =
97 bundle_playground(&resolver, &source, opts.bundle_format).unwrap_or_else(|e| {
98 eprintln!("{e}");
99 exit(1);
100 });
101 let json = serde_json::to_string_pretty(&b).expect("bundle serialization");
102 println!("{json}");
103 }
104 BundleMode::Url => {
105 let b =
106 bundle_playground(&resolver, &source, opts.bundle_format).unwrap_or_else(|e| {
107 eprintln!("{e}");
108 exit(1);
109 });
110 let json = serde_json::to_string(&b).expect("bundle serialization");
111 let encoded = URL_SAFE_NO_PAD.encode(json.as_bytes());
112 println!("https://delta.rocks/jrsonnet/playground?state={encoded}");
113 }
114 BundleMode::Onefile => {
115 let src = bundle_onefile(&resolver, &source).unwrap_or_else(|e| {
116 eprintln!("{e}");
117 exit(1);
118 });
119 print!("{src}");
120 }
121 }
122 } else {
123 let mut deps = BTreeMap::new();
70 if let Err(e) = collect_deps(&resolver, &source, &mut deps) {124 if let Err(e) = collect_deps(&resolver, &source, &mut deps) {
71 eprintln!("{e}");125 eprintln!("{e}");
72 exit(1);126 exit(1);
73 }127 }
74
75 for dep in &deps {128 for dep in deps.keys() {
76 println!("{dep}");129 println!("{dep}");
77 }130 }
131 }
78}132}
79133
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
38 /// Library search dirs. (right-most wins)38 /// Library search dirs. (right-most wins)
39 /// Any not found `imported` file will be searched in these.39 /// Any not found `imported` file will be searched in these.
40 /// This can also be specified via `JSONNET_PATH` variable,40 /// This can also be specified via `JSONNET_PATH` variable,
41 /// which should contain a colon-separated (semicolon-separated on Windows) list of directories.41 #[cfg_attr(
42 windows,
43 doc = "which should contain a semicolon-separated list of directories."
44 )]
45 #[cfg_attr(
46 not(windows),
47 doc = "which should contain a colon-separated list of directories."
48 )]
42 #[clap(long, short = 'J')]49 #[clap(long, short = 'J')]
43 jpath: Vec<PathBuf>,50 jpath: Vec<PathBuf>,
44}51}
addedcrates/jrsonnet-pack/Cargo.tomldiffbeforeafterboth

no changes

addedcrates/jrsonnet-pack/src/lib.rsdiffbeforeafterboth

no changes

modifiedcrates/jrsonnet-rowan-parser/src/lib.rsdiffbeforeafterboth
22
3use event::Sink;3use event::Sink;
4use generated::nodes::{SourceFile, Trivia};4use generated::nodes::{SourceFile, Trivia};
5use parser::{LocatedSyntaxError, Parser};5use parser::Parser;
6pub use rowan;6pub use rowan;
77
8mod ast;8mod ast;
19pub use ast::{AstChildren, AstNode, AstToken};19pub use ast::{AstChildren, AstNode, AstToken};
20pub use generated::{nodes, syntax_kinds::SyntaxKind};20pub use generated::{nodes, syntax_kinds::SyntaxKind};
21pub use language::*;21pub use language::*;
22pub use parser::LocatedSyntaxError;
22pub use token_set::SyntaxKindSet;23pub use token_set::SyntaxKindSet;
2324
24pub fn parse(input: &str) -> (SourceFile, Vec<LocatedSyntaxError>) {25pub fn parse(input: &str) -> (SourceFile, Vec<LocatedSyntaxError>) {
modifiedflake.nixdiffbeforeafterboth
387 lld387 lld
388 hyperfine388 hyperfine
389 graphviz389 graphviz
390 vega-lite
390 ]391 ]
391 ++ optionals (!stdenv.isDarwin) [392 ++ optionals (!stdenv.isDarwin) [
392 valgrind393 valgrind
addedtests/realworld/bin.jsonnetdiffbeforeafterboth

no changes

modifiedtests/realworld/entry-loki.jsonnetdiffbeforeafterboth
1local loki = import 'loki/loki.libsonnet';1local loki = import 'github.com/grafana/loki/production/ksonnet/loki/loki.libsonnet';
22
3loki {3loki {
4 _config+:: {4 _config+:: {
modifiedtests/realworld/entry-mimir.jsonnetdiffbeforeafterboth
1local mimir = import 'mimir/mimir.libsonnet';1local mimir = import 'github.com/grafana/mimir/operations/mimir/mimir.libsonnet';
22
3mimir {3mimir {
4 _config+:: {4 _config+:: {
modifiedtests/realworld/entry-tempo.jsonnetdiffbeforeafterboth
1local tempo = import 'microservices/tempo.libsonnet';1local tempo = import 'github.com/grafana/tempo/operations/jsonnet/microservices/tempo.libsonnet';
22
3tempo {3tempo {
4 _images+:: {4 _images+:: {
modifiedtests/realworld/k.libsonnetdiffbeforeafterboth
1import '1.32/main.libsonnet'1import 'github.com/jsonnet-libs/k8s-libsonnet/1.32/main.libsonnet'
22