Skip to content

Commit

Permalink
refactor: use copyArtifact from @neon-rs/artifact
Browse files Browse the repository at this point in the history
- closes #1045
  • Loading branch information
dherman committed May 19, 2024
1 parent f0e8547 commit b82f280
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
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

0 comments on commit b82f280

Please sign in to comment.