Skip to content

Commit a3f684b

Browse files
committed
chore: fix update-deps.ts to handle target specific deps
1 parent 904d6a0 commit a3f684b

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"[json]": {
1010
"editor.defaultFormatter": "denoland.vscode-deno"
1111
},
12+
"[markdown]": {
13+
"editor.defaultFormatter": "denoland.vscode-deno"
14+
},
1215
"[yaml]": {
1316
"editor.defaultFormatter": "denoland.vscode-deno"
1417
},

scripts/update-deps.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,45 @@ const denoDependencies = denoCargoToml.workspace.dependencies;
1919
const localCargoTomlPath = rootDir.join("src/rs_lib/Cargo.toml");
2020
const localCargoToml = toml.parse(localCargoTomlPath.readTextSync()) as any;
2121

22-
for (const [key, value] of Object.entries(localCargoToml.dependencies)) {
23-
const newVersion = getVersion(denoDependencies[key]);
24-
if (newVersion == null) {
25-
continue;
22+
updateDependencies(localCargoToml.dependencies, denoDependencies);
23+
24+
// update target-specific dependencies
25+
if (localCargoToml.target) {
26+
for (const targetDeps of Object.values(localCargoToml.target)) {
27+
if (
28+
targetDeps != null &&
29+
typeof targetDeps === "object" &&
30+
"dependencies" in targetDeps
31+
) {
32+
updateDependencies(
33+
(targetDeps as any).dependencies,
34+
denoDependencies,
35+
);
36+
}
2637
}
27-
if (typeof value === "string") {
28-
if (value !== newVersion) {
29-
$.logLight(`Updating ${key}@${value} to ${newVersion}`);
30-
localCargoToml.dependencies[key] = newVersion;
38+
}
39+
40+
function updateDependencies(
41+
localDeps: Record<string, any>,
42+
sourceDeps: Record<string, any>,
43+
) {
44+
for (const [key, value] of Object.entries(localDeps)) {
45+
const newVersion = getVersion(sourceDeps[key]);
46+
if (newVersion == null) {
47+
continue;
3148
}
32-
} else if (value != null && typeof value === "object" && "version" in value) {
33-
if (value.version !== newVersion) {
34-
$.logLight(`Updating ${key}@${value.version} to ${newVersion}`);
35-
value.version = newVersion;
49+
if (typeof value === "string") {
50+
if (value !== newVersion) {
51+
$.logLight(`Updating ${key}@${value} to ${newVersion}`);
52+
localDeps[key] = newVersion;
53+
}
54+
} else if (
55+
value != null && typeof value === "object" && "version" in value
56+
) {
57+
if (value.version !== newVersion) {
58+
$.logLight(`Updating ${key}@${value.version} to ${newVersion}`);
59+
value.version = newVersion;
60+
}
3661
}
3762
}
3863
}

0 commit comments

Comments
 (0)