Skip to content

Commit f9c9ba7

Browse files
committed
Merge remote-tracking branch 'origin/main' into chore/modernize-ci-and-readme
# Conflicts: # Cargo.toml # scripts/update.ts
2 parents 62c3e2b + 2a97263 commit f9c9ba7

3 files changed

Lines changed: 26 additions & 30 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dprint-plugin-mago"
3-
version = "0.0.1"
3+
version = "0.19.1"
44
authors = ["David Sherret <dsherret@gmail.com>"]
55
edition = "2024"
66
homepage = "https://github.com/dprint/dprint-plugin-mago"

scripts/update.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,40 +108,36 @@ async function getLatestMagoVersions(): Promise<MagoVersions> {
108108
return { formatter, phpVersion };
109109
}
110110

111-
async function getLatestCrateVersion(crateName: string): Promise<string> {
112-
const data = await $.request(`https://crates.io/api/v1/crates/${crateName}`).json();
113-
const latestVersion = data.crate?.newest_version;
114-
if (latestVersion == null) {
115-
throw new Error(`Could not find latest version of ${crateName} on crates.io.`);
116-
}
117-
$.logLight(`Latest ${crateName} version on crates.io:`, latestVersion);
118-
return latestVersion;
119-
}
120-
121-
async function updateRustToolchain(formatterVersion: string) {
122-
const data = await $.request(`https://crates.io/api/v1/crates/mago-formatter/${formatterVersion}`).json();
123-
const requiredRustVersion = data.version?.rust_version;
124-
if (requiredRustVersion == null) {
125-
$.log(`mago-formatter ${formatterVersion} does not declare a rust_version; leaving rust-toolchain.toml alone.`);
126-
return;
111+
async function updateRustToolchain(magoVersion: string) {
112+
const content = await $.request(
113+
`https://raw.githubusercontent.com/carthage-software/mago/${magoVersion}/Cargo.toml`,
114+
).text();
115+
const match = content.match(/rust-version\s*=\s*"([^"]+)"/);
116+
if (match == null) {
117+
throw new Error("Could not find rust-version in mago's Cargo.toml.");
127118
}
128-
119+
const magoRustVersion = match[1];
129120
const toolchainPath = rootDirPath.join("rust-toolchain.toml");
130121
const localContent = toolchainPath.readTextSync();
131122
const localMatch = localContent.match(/channel\s*=\s*"([^"]+)"/);
132123
if (localMatch == null) {
133124
throw new Error("Could not find channel in local rust-toolchain.toml.");
134125
}
135-
// crates.io rust_version may be "1.84" (no patch); pad to MAJOR.MINOR.PATCH
136-
// so @std/semver can parse it.
137-
const normalize = (v: string) => /^\d+\.\d+$/.test(v) ? `${v}.0` : v;
138-
// only bump up; never downgrade. compare as semver so 1.95.0 > 1.92.0.
139-
const local = semver.parse(normalize(localMatch[1]));
140-
const required = semver.parse(normalize(requiredRustVersion));
141-
if (semver.greaterThan(required, local)) {
142-
$.log(`Updating Rust toolchain: ${localMatch[1]} -> ${requiredRustVersion}`);
143-
toolchainPath.writeTextSync(localContent.replace(localMatch[0], `channel = "${requiredRustVersion}"`));
126+
if (localMatch[1] !== magoRustVersion) {
127+
$.log(`Updating Rust toolchain: ${localMatch[1]} -> ${magoRustVersion}`);
128+
toolchainPath.writeTextSync(localContent.replace(localMatch[0], `channel = "${magoRustVersion}"`));
144129
} else {
145-
$.log(`Rust toolchain at ${localMatch[1]} already satisfies mago-formatter ${formatterVersion} (needs >= ${requiredRustVersion}).`);
130+
$.log(`Rust toolchain already at ${magoRustVersion}.`);
146131
}
147132
}
133+
134+
async function getLatestCrateVersion(crateName: string): Promise<string> {
135+
const data = await $.request(`https://crates.io/api/v1/crates/${crateName}`)
136+
.json<{ crate?: { newest_version?: string } }>();
137+
const latestVersion = data.crate?.newest_version;
138+
if (latestVersion == null) {
139+
throw new Error(`Could not find latest version of ${crateName} on crates.io.`);
140+
}
141+
$.logLight(`Latest ${crateName} version on crates.io:`, latestVersion);
142+
return latestVersion;
143+
}

tests/specs/EmptyBraces.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Foo
3030
public function __construct() {}
3131
}
3232

33-
== should not inline empty method braces (default) ==
33+
== should inline empty method braces (default) ==
3434
<?php
3535
class Foo {
3636
public function bar() {}
@@ -44,7 +44,7 @@ class Foo
4444
public function bar() {}
4545
}
4646

47-
== should not inline empty function braces (default) ==
47+
== should inline empty function braces (default) ==
4848
<?php
4949
function foo() {}
5050

0 commit comments

Comments
 (0)