mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 21:55:15 +00:00
Add option for emitting absolute paths to rojo sourcemap (#1092)
Co-authored-by: Micah <micah@uplift.games>
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -65,7 +65,7 @@ jobs:
|
|||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: dtolnay/rust-toolchain@1.70.0
|
uses: dtolnay/rust-toolchain@1.79.0
|
||||||
|
|
||||||
- name: Restore Rust Cache
|
- name: Restore Rust Cache
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
* Changed the background of the server's in-browser UI to be gray instead of white ([#1080])
|
* Changed the background of the server's in-browser UI to be gray instead of white ([#1080])
|
||||||
* Fixed `Auto Connect Playtest Server` no longer functioning due to Roblox change ([#1066])
|
* Fixed `Auto Connect Playtest Server` no longer functioning due to Roblox change ([#1066])
|
||||||
* Added an update indicator to the version header when a new version of the plugin is available. ([#1069])
|
* Added an update indicator to the version header when a new version of the plugin is available. ([#1069])
|
||||||
|
* Added `--absolute` flag to the sourcemap subcommand, which will emit absolute paths instead of relative paths. ([#1092])
|
||||||
|
|
||||||
[#1093]: https://github.com/rojo-rbx/rojo/pull/1093
|
[#1093]: https://github.com/rojo-rbx/rojo/pull/1093
|
||||||
[#1084]: https://github.com/rojo-rbx/rojo/pull/1084
|
[#1084]: https://github.com/rojo-rbx/rojo/pull/1084
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
[#1080]: https://github.com/rojo-rbx/rojo/pull/1080
|
[#1080]: https://github.com/rojo-rbx/rojo/pull/1080
|
||||||
[#1049]: https://github.com/rojo-rbx/rojo/pull/1066
|
[#1049]: https://github.com/rojo-rbx/rojo/pull/1066
|
||||||
[#1069]: https://github.com/rojo-rbx/rojo/pull/1069
|
[#1069]: https://github.com/rojo-rbx/rojo/pull/1069
|
||||||
|
[#1092]: https://github.com/rojo-rbx/rojo/pull/1092
|
||||||
|
|
||||||
## 7.5.1 - April 25th, 2025
|
## 7.5.1 - April 25th, 2025
|
||||||
* Fixed output spam related to `Instance.Capabilities` in the plugin
|
* Fixed output spam related to `Instance.Capabilities` in the plugin
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rojo"
|
name = "rojo"
|
||||||
version = "7.5.1"
|
version = "7.5.1"
|
||||||
rust-version = "1.70.0"
|
rust-version = "1.79.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Lucien Greathouse <me@lpghatguy.com>",
|
"Lucien Greathouse <me@lpghatguy.com>",
|
||||||
"Micah Reid <git@dekkonot.com>",
|
"Micah Reid <git@dekkonot.com>",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
io::{BufWriter, Write},
|
io::{BufWriter, Write},
|
||||||
mem::forget,
|
mem::forget,
|
||||||
path::{Path, PathBuf},
|
path::{self, Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@@ -20,6 +21,7 @@ use crate::{
|
|||||||
use super::resolve_path;
|
use super::resolve_path;
|
||||||
|
|
||||||
const PATH_STRIP_FAILED_ERR: &str = "Failed to create relative paths for project file!";
|
const PATH_STRIP_FAILED_ERR: &str = "Failed to create relative paths for project file!";
|
||||||
|
const ABSOLUTE_PATH_FAILED_ERR: &str = "Failed to turn relative path into absolute path!";
|
||||||
|
|
||||||
/// Representation of a node in the generated sourcemap tree.
|
/// Representation of a node in the generated sourcemap tree.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -32,7 +34,7 @@ struct SourcemapNode<'a> {
|
|||||||
skip_serializing_if = "Vec::is_empty",
|
skip_serializing_if = "Vec::is_empty",
|
||||||
serialize_with = "crate::path_serializer::serialize_vec_absolute"
|
serialize_with = "crate::path_serializer::serialize_vec_absolute"
|
||||||
)]
|
)]
|
||||||
file_paths: Vec<PathBuf>,
|
file_paths: Vec<Cow<'a, Path>>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
children: Vec<SourcemapNode<'a>>,
|
children: Vec<SourcemapNode<'a>>,
|
||||||
@@ -60,6 +62,10 @@ pub struct SourcemapCommand {
|
|||||||
/// Whether to automatically recreate a snapshot when any input files change.
|
/// Whether to automatically recreate a snapshot when any input files change.
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
pub watch: bool,
|
pub watch: bool,
|
||||||
|
|
||||||
|
/// Whether the sourcemap should use absolute paths instead of relative paths.
|
||||||
|
#[clap(long)]
|
||||||
|
pub absolute: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourcemapCommand {
|
impl SourcemapCommand {
|
||||||
@@ -86,7 +92,7 @@ impl SourcemapCommand {
|
|||||||
.build_global()
|
.build_global()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
write_sourcemap(&session, self.output.as_deref(), filter)?;
|
write_sourcemap(&session, self.output.as_deref(), filter, self.absolute)?;
|
||||||
|
|
||||||
if self.watch {
|
if self.watch {
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
@@ -97,7 +103,7 @@ impl SourcemapCommand {
|
|||||||
cursor = new_cursor;
|
cursor = new_cursor;
|
||||||
|
|
||||||
if patch_set_affects_sourcemap(&session, &patch_set, filter) {
|
if patch_set_affects_sourcemap(&session, &patch_set, filter) {
|
||||||
write_sourcemap(&session, self.output.as_deref(), filter)?;
|
write_sourcemap(&session, self.output.as_deref(), filter, self.absolute)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,13 +169,16 @@ fn recurse_create_node<'a>(
|
|||||||
referent: Ref,
|
referent: Ref,
|
||||||
project_dir: &Path,
|
project_dir: &Path,
|
||||||
filter: fn(&InstanceWithMeta) -> bool,
|
filter: fn(&InstanceWithMeta) -> bool,
|
||||||
|
use_absolute_paths: bool,
|
||||||
) -> Option<SourcemapNode<'a>> {
|
) -> Option<SourcemapNode<'a>> {
|
||||||
let instance = tree.get_instance(referent).expect("instance did not exist");
|
let instance = tree.get_instance(referent).expect("instance did not exist");
|
||||||
|
|
||||||
let children: Vec<_> = instance
|
let children: Vec<_> = instance
|
||||||
.children()
|
.children()
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.filter_map(|&child_id| recurse_create_node(tree, child_id, project_dir, filter))
|
.filter_map(|&child_id| {
|
||||||
|
recurse_create_node(tree, child_id, project_dir, filter, use_absolute_paths)
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// If this object has no children and doesn't pass the filter, it doesn't
|
// If this object has no children and doesn't pass the filter, it doesn't
|
||||||
@@ -184,14 +193,30 @@ fn recurse_create_node<'a>(
|
|||||||
.iter()
|
.iter()
|
||||||
// Not all paths listed as relevant are guaranteed to exist.
|
// Not all paths listed as relevant are guaranteed to exist.
|
||||||
.filter(|path| path.is_file())
|
.filter(|path| path.is_file())
|
||||||
.map(|path| path.strip_prefix(project_dir).expect(PATH_STRIP_FAILED_ERR))
|
.map(|path| path.as_path());
|
||||||
.map(|path| path.to_path_buf())
|
|
||||||
.collect();
|
let mut output_file_paths: Vec<Cow<'a, Path>> =
|
||||||
|
Vec::with_capacity(instance.metadata().relevant_paths.len());
|
||||||
|
|
||||||
|
if use_absolute_paths {
|
||||||
|
// It's somewhat important to note here that `path::absolute` takes in a Path and returns a PathBuf
|
||||||
|
for val in file_paths {
|
||||||
|
output_file_paths.push(Cow::Owned(
|
||||||
|
path::absolute(val).expect(ABSOLUTE_PATH_FAILED_ERR),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for val in file_paths {
|
||||||
|
output_file_paths.push(Cow::from(
|
||||||
|
val.strip_prefix(project_dir).expect(PATH_STRIP_FAILED_ERR),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Some(SourcemapNode {
|
Some(SourcemapNode {
|
||||||
name: instance.name(),
|
name: instance.name(),
|
||||||
class_name: instance.class_name(),
|
class_name: instance.class_name(),
|
||||||
file_paths,
|
file_paths: output_file_paths,
|
||||||
children,
|
children,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -200,10 +225,17 @@ fn write_sourcemap(
|
|||||||
session: &ServeSession,
|
session: &ServeSession,
|
||||||
output: Option<&Path>,
|
output: Option<&Path>,
|
||||||
filter: fn(&InstanceWithMeta) -> bool,
|
filter: fn(&InstanceWithMeta) -> bool,
|
||||||
|
use_absolute_paths: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let tree = session.tree();
|
let tree = session.tree();
|
||||||
|
|
||||||
let root_node = recurse_create_node(&tree, tree.get_root_id(), session.root_dir(), filter);
|
let root_node = recurse_create_node(
|
||||||
|
&tree,
|
||||||
|
tree.get_root_id(),
|
||||||
|
session.root_dir(),
|
||||||
|
filter,
|
||||||
|
use_absolute_paths,
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(output_path) = output {
|
if let Some(output_path) = output {
|
||||||
let mut file = BufWriter::new(File::create(output_path)?);
|
let mut file = BufWriter::new(File::create(output_path)?);
|
||||||
|
|||||||
Reference in New Issue
Block a user