Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cargo-cp-artifact): use copyArtifact from @neon-rs/artifact #1046

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkgs/cargo-cp-artifact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"homepage": "https://github.com/neon-bindings/neon/tree/main/pkgs/cargo-cp-artifact",
"devDependencies": {
"mocha": "^10.2.0"
},
"dependencies": {
"@neon-rs/artifact": "^0.1.0"
}
}
49 changes: 1 addition & 48 deletions pkgs/cargo-cp-artifact/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"use strict";

const { spawn } = require("child_process");
const {
promises: { copyFile, mkdir, stat, unlink },
} = require("fs");
const { dirname, extname } = require("path");
const readline = require("readline");
const { copyArtifact } = require("@neon-rs/artifact");

const { ParseError, getArtifactName, parse } = require("./args");

Expand Down Expand Up @@ -118,50 +115,6 @@ function getOutputFiles(kind, name, artifacts) {
};
}

async function isNewer(filename, outputFile) {
try {
const prevStats = await stat(outputFile);
const nextStats = await stat(filename);

return nextStats.mtime > prevStats.mtime;
} catch (_err) {}

return true;
}

async function copyArtifact(filename, outputFile) {
if (!(await isNewer(filename, outputFile))) {
return;
}

const outputDir = dirname(outputFile);

// Don't try to create the current directory
if (outputDir && outputDir !== ".") {
await mkdir(outputDir, { recursive: true });
}

// Apple Silicon (M1, etc.) requires shared libraries to be signed. However,
// the macOS code signing cache isn't cleared when overwriting a file.
// Deleting the file before copying works around the issue.
//
// Unfortunately, this workaround is incomplete because the file must be
// deleted from the location it is loaded. If further steps in the user's
// build process copy or move the file in place, the code signing cache
// will not be cleared.
//
// https://github.com/neon-bindings/neon/issues/911
if (extname(outputFile) === ".node") {
try {
await unlink(outputFile);
} catch (_e) {
// Ignore errors; the file might not exist
}
}

await copyFile(filename, outputFile);
}

function parseArgs(argv, env) {
try {
return parse(argv, env);
Expand Down
Loading