From b82f28046fa842a251163d8e5b1173fbcff7656b Mon Sep 17 00:00:00 2001 From: David Herman Date: Sun, 19 May 2024 11:00:30 -0700 Subject: [PATCH] refactor: use copyArtifact from @neon-rs/artifact - closes #1045 --- package-lock.json | 16 +++++++--- pkgs/cargo-cp-artifact/package.json | 3 ++ pkgs/cargo-cp-artifact/src/index.js | 49 +---------------------------- 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index fac55a862..60eb9a3a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -832,6 +832,11 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@neon-rs/artifact": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@neon-rs/artifact/-/artifact-0.1.0.tgz", + "integrity": "sha512-GdrnE9PNGTJYKNQsCTFgi2oRmm6Uexp0/9JcuhRIYeOJKnEgDe/AWOOY+4CfG95Eolf4/EKEPcan/Sb22o47Ug==" + }, "node_modules/@neon-rs/manifest": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/@neon-rs/manifest/-/manifest-0.0.6.tgz", @@ -6056,8 +6061,11 @@ } }, "pkgs/cargo-cp-artifact": { - "version": "0.1.8", + "version": "0.1.9", "license": "MIT", + "dependencies": { + "@neon-rs/artifact": "^0.1.0" + }, "bin": { "cargo-cp-artifact": "bin/cargo-cp-artifact.js" }, @@ -6066,7 +6074,7 @@ } }, "pkgs/create-neon": { - "version": "0.3.0", + "version": "0.4.0", "license": "MIT", "dependencies": { "@neon-rs/manifest": "^0.0.6", @@ -6113,7 +6121,7 @@ "license": "MIT", "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" } @@ -6124,7 +6132,7 @@ "hasInstallScript": true, "license": "MIT", "devDependencies": { - "cargo-cp-artifact": "^0.1.8", + "cargo-cp-artifact": "^0.1.9", "chai": "^4.3.10", "mocha": "^10.2.0" } diff --git a/pkgs/cargo-cp-artifact/package.json b/pkgs/cargo-cp-artifact/package.json index 214192ff1..2632308d0 100644 --- a/pkgs/cargo-cp-artifact/package.json +++ b/pkgs/cargo-cp-artifact/package.json @@ -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" } } diff --git a/pkgs/cargo-cp-artifact/src/index.js b/pkgs/cargo-cp-artifact/src/index.js index 612e07d5e..b1ceb44e2 100644 --- a/pkgs/cargo-cp-artifact/src/index.js +++ b/pkgs/cargo-cp-artifact/src/index.js @@ -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"); @@ -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);