Skip to content

Commit

Permalink
Merge pull request #1 from BarbossHack/support-dot-version
Browse files Browse the repository at this point in the history
Support toml .version and improve path detection
  • Loading branch information
BarbossHack authored Jun 29, 2024
2 parents c8acd6c + ecd4c0b commit 81846b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions sample/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ Inflector = "0.11.4"
block-modes = "0.8.1" # crates: disable-check
jpegxl-sys = "0.8.2"
tracing = "=0.1.37"
smoldot.version = "0.17.0"

[dependencies.depsonpath]
version = "7.0.0-alpha1"
path = "../lib"

[workspace.dependencies]
my_package.path = "../lib"
my_package2 = { path = "../" }

[dependencies.clap]
version = "3.0.0-beta.2"
Expand Down
2 changes: 1 addition & 1 deletion src/core/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export default class Item {
key: string = "";
values: Array<any> = [];
values: Array<Item> = [];
value: string | undefined = "";
start: number = -1;
end: number = -1;
Expand Down
7 changes: 4 additions & 3 deletions src/toml/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export function findCrateAndVersion(
function findVersion(item: Item): Item[] {
let dependencies: Item[] = [];
for (const field of item.values) {
if (field.key.endsWith(".workspace")) continue;
if (field.key.endsWith(".workspace") || field.key.endsWith(".path")) continue;
if (field.values.length > 0) {
const dependency = findVersionTable(field);
if (dependency) dependencies.push(dependency);
} else if (field.value != null) {
if (field.key.endsWith(".version")) field.key = field.key.replace(".version", "");
dependencies.push(field)
}
}
Expand All @@ -80,7 +81,7 @@ function findVersionTable(table: Item): Item | null {
let item = null
let itemName = null;
for (const field of table.values) {
if (field.key === "workspace") return null;
if (field.key === "workspace" || field.key === "path") return null;
if (field.key === "version") {
item = new Item(field);
item.key = table.key;
Expand Down Expand Up @@ -226,7 +227,7 @@ function isCratesDep(i: Item): boolean {
for (let value of i.values) {
if (value.key === "git" || value.key === "path") {
return false;
} else if (value.key === "package") {
} else if (value.key === "package" && value.value !== undefined) {
i.key = value.value;
}
}
Expand Down

0 comments on commit 81846b3

Please sign in to comment.