Skip to content

Commit a328375

Browse files
committed
fix(cargo-cp-artifact): Hotfix for change in cargo diagnostics naming
1 parent c4a8e9b commit a328375

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

RELEASES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# `cargo-cp-artifact`
2+
3+
`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`.
4+
15
# Version 1.0.0
26

37
## Commitment to Compatibility

pkgs/cargo-cp-artifact/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cargo-cp-artifact",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "Copies compiler artifacts emitted by rustc by parsing Cargo metadata",
55
"main": "src/index.js",
66
"files": [

pkgs/cargo-cp-artifact/src/index.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function processCargoBuildLine(options, copied, line) {
8080
// `kind` and `filenames` zip up as key/value pairs
8181
kinds.forEach((kind, i) => {
8282
const filename = filenames[i];
83-
const key = getArtifactName({ artifactType: kind, crateName: name });
84-
const outputFiles = options.artifacts[key];
83+
const { key, outputFiles } =
84+
getOutputFiles(kind, name, options.artifacts) || {};
8585

8686
if (!outputFiles || !filename) {
8787
return;
@@ -100,6 +100,24 @@ function processCargoBuildLine(options, copied, line) {
100100
});
101101
}
102102

103+
function getOutputFiles(kind, name, artifacts) {
104+
const key = getArtifactName({ artifactType: kind, crateName: name });
105+
const outputFiles = artifacts[key];
106+
107+
if (outputFiles) {
108+
return { key, outputFiles };
109+
}
110+
111+
// Cargo started replacing `-` with `_` in artifact names. Reverse the process
112+
// and check again. https://github.com/rust-lang/cargo/issues/13867
113+
const altKey = key.replace(/_/g, "-");
114+
115+
return {
116+
key: altKey,
117+
outputFiles: artifacts[altKey],
118+
};
119+
}
120+
103121
async function isNewer(filename, outputFile) {
104122
try {
105123
const prevStats = await stat(outputFile);

test/electron/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"repository": "https://github.com/electron/electron-quick-start",
1414
"devDependencies": {
1515
"@playwright/test": "^1.40.1",
16-
"cargo-cp-artifact": "^0.1.8",
16+
"cargo-cp-artifact": "^0.1.9",
1717
"electron": "^27.1.3",
1818
"playwright": "^1.40.1"
1919
}

test/napi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": "mocha --v8-expose-gc --timeout 5000 --recursive lib"
1111
},
1212
"devDependencies": {
13-
"cargo-cp-artifact": "^0.1.8",
13+
"cargo-cp-artifact": "^0.1.9",
1414
"chai": "^4.3.10",
1515
"mocha": "^10.2.0"
1616
}

0 commit comments

Comments
 (0)