Skip to content

Commit

Permalink
Merge pull request #1039 from neon-bindings/kv/cp-artifact-hotfix
Browse files Browse the repository at this point in the history
fix(cargo-cp-artifact): Hotfix for change in cargo diagnostics naming
  • Loading branch information
kjvalencik committed May 10, 2024
2 parents c4a8e9b + a328375 commit 91427d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion 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": [
Expand Down
22 changes: 20 additions & 2 deletions pkgs/cargo-cp-artifact/src/index.js
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/electron/package.json
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion test/napi/package.json
Expand Up @@ -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"
}
Expand Down

0 comments on commit 91427d2

Please sign in to comment.