diff --git a/RELEASES.md b/RELEASES.md index dea6fd75d..e511f2197 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,7 @@ +# `cargo-cp-artifact` + +`0.1.9` supports a [breaking change in `cargo`](https://github.com/rust-lang/cargo/issues/13867) that converts artifact names from `kebab-case` to `snake_case`. + # Version 1.0.0 ## Commitment to Compatibility diff --git a/pkgs/cargo-cp-artifact/package.json b/pkgs/cargo-cp-artifact/package.json index 7aa481d4a..214192ff1 100644 --- a/pkgs/cargo-cp-artifact/package.json +++ b/pkgs/cargo-cp-artifact/package.json @@ -1,6 +1,6 @@ { "name": "cargo-cp-artifact", - "version": "0.1.8", + "version": "0.1.9", "description": "Copies compiler artifacts emitted by rustc by parsing Cargo metadata", "main": "src/index.js", "files": [ diff --git a/pkgs/cargo-cp-artifact/src/index.js b/pkgs/cargo-cp-artifact/src/index.js index 2ae2c876c..612e07d5e 100644 --- a/pkgs/cargo-cp-artifact/src/index.js +++ b/pkgs/cargo-cp-artifact/src/index.js @@ -80,8 +80,8 @@ function processCargoBuildLine(options, copied, line) { // `kind` and `filenames` zip up as key/value pairs kinds.forEach((kind, i) => { const filename = filenames[i]; - const key = getArtifactName({ artifactType: kind, crateName: name }); - const outputFiles = options.artifacts[key]; + const { key, outputFiles } = + getOutputFiles(kind, name, options.artifacts) || {}; if (!outputFiles || !filename) { return; @@ -100,6 +100,24 @@ function processCargoBuildLine(options, copied, line) { }); } +function getOutputFiles(kind, name, artifacts) { + const key = getArtifactName({ artifactType: kind, crateName: name }); + const outputFiles = artifacts[key]; + + if (outputFiles) { + return { key, outputFiles }; + } + + // Cargo started replacing `-` with `_` in artifact names. Reverse the process + // and check again. https://github.com/rust-lang/cargo/issues/13867 + const altKey = key.replace(/_/g, "-"); + + return { + key: altKey, + outputFiles: artifacts[altKey], + }; +} + async function isNewer(filename, outputFile) { try { const prevStats = await stat(outputFile); diff --git a/test/electron/package.json b/test/electron/package.json index b473fb829..b10d3c7d2 100644 --- a/test/electron/package.json +++ b/test/electron/package.json @@ -13,7 +13,7 @@ "repository": "https://github.com/electron/electron-quick-start", "devDependencies": { "@playwright/test": "^1.40.1", - "cargo-cp-artifact": "^0.1.8", + "cargo-cp-artifact": "^0.1.9", "electron": "^27.1.3", "playwright": "^1.40.1" } diff --git a/test/napi/package.json b/test/napi/package.json index 95414d099..af42ecb82 100644 --- a/test/napi/package.json +++ b/test/napi/package.json @@ -10,7 +10,7 @@ "test": "mocha --v8-expose-gc --timeout 5000 --recursive lib" }, "devDependencies": { - "cargo-cp-artifact": "^0.1.8", + "cargo-cp-artifact": "^0.1.9", "chai": "^4.3.10", "mocha": "^10.2.0" }