Comparing version 0.38.0 to 0.38.1
17
bin.js
@@ -13,4 +13,4 @@ #!/usr/bin/env node | ||
try { | ||
require("./install_api").runInstall(); | ||
runDprintExe(); | ||
const resolvedExePath = require("./install_api").runInstall(); | ||
runDprintExe(resolvedExePath); | ||
} catch (err) { | ||
@@ -25,6 +25,7 @@ if (err !== undefined && typeof err.message === "string") { | ||
} else { | ||
runDprintExe(); | ||
runDprintExe(exePath); | ||
} | ||
function runDprintExe() { | ||
/** @param exePath {string} */ | ||
function runDprintExe(exePath) { | ||
const result = child_process.spawnSync( | ||
@@ -42,8 +43,8 @@ exePath, | ||
process.exitCode = result.status; | ||
} | ||
function throwIfNoExePath() { | ||
if (!fs.existsSync(exePath)) { | ||
throw new Error("Could not find exe at path '" + exePath + "'. Maybe try running dprint again."); | ||
function throwIfNoExePath() { | ||
if (!fs.existsSync(exePath)) { | ||
throw new Error("Could not find exe at path '" + exePath + "'. Maybe try running dprint again."); | ||
} | ||
} | ||
} |
@@ -13,3 +13,3 @@ // @ts-check | ||
const dprintFileName = os.platform() === "win32" ? "dprint.exe" : "dprint"; | ||
const executableFilePath = path.join( | ||
const targetExecutablePath = path.join( | ||
__dirname, | ||
@@ -19,89 +19,124 @@ dprintFileName, | ||
if (fs.existsSync(executableFilePath)) { | ||
return Promise.resolve(); | ||
if (fs.existsSync(targetExecutablePath)) { | ||
return targetExecutablePath; | ||
} | ||
const target = getTarget(); | ||
const targetPackagePath = path.dirname(require.resolve("@dprint/" + target + "/package.json")); | ||
const executablePath = path.join(targetPackagePath, dprintFileName); | ||
if (!fs.existsSync(executablePath)) { | ||
throw new Error("Could not find executable for @dprint/" + target + " at " + executablePath); | ||
const sourcePackagePath = path.dirname(require.resolve("@dprint/" + target + "/package.json")); | ||
const sourceExecutablePath = path.join(sourcePackagePath, dprintFileName); | ||
if (!fs.existsSync(sourceExecutablePath)) { | ||
throw new Error("Could not find executable for @dprint/" + target + " at " + sourceExecutablePath); | ||
} | ||
fs.copyFileSync(executablePath, executableFilePath); | ||
if (os.platform() !== "win32") { | ||
// chomd +x | ||
const perms = fs.statSync(executableFilePath).mode; | ||
fs.chmodSync(executableFilePath, perms | 0o111); | ||
} | ||
function getTarget() { | ||
const platform = os.platform(); | ||
if (platform === "linux") { | ||
return platform + "-" + getArch() + "-" + getLinuxFamily(); | ||
} else { | ||
return platform + "-" + getArch(); | ||
try { | ||
if (process.env.DPRINT_SIMULATED_READONLY_FILE_SYSTEM === "1") { | ||
console.warn("Simulating readonly file system for testing."); | ||
throw new Error("Throwing for testing purposes."); | ||
} | ||
} | ||
function getArch() { | ||
const arch = os.arch(); | ||
if (arch !== "arm64" && arch !== "x64") { | ||
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available."); | ||
// in order to make things faster the next time we run, copy the | ||
// executable into the dprint package folder | ||
fs.copyFileSync(sourceExecutablePath, targetExecutablePath); | ||
if (os.platform() !== "win32") { | ||
// chomd +x | ||
chmodX(targetExecutablePath); | ||
} | ||
return arch; | ||
return targetExecutablePath; | ||
} catch (err) { | ||
// this may fail on readonly file systems... in this case, fall | ||
// back to using the resolved package path | ||
if (process.env.DPRINT_DEBUG === "1") { | ||
console.warn( | ||
"Failed to copy executable from " | ||
+ sourceExecutablePath + " to " + targetExecutablePath | ||
+ ". Using resolved package path instead.", | ||
err, | ||
); | ||
} | ||
// use the path found in the specific package | ||
try { | ||
chmodX(sourceExecutablePath); | ||
} catch (_err) { | ||
// ignore | ||
} | ||
return sourceExecutablePath; | ||
} | ||
}, | ||
}; | ||
function getLinuxFamily() { | ||
return getIsMusl() ? "musl" : "glibc"; | ||
/** @filePath {string} */ | ||
function chmodX(filePath) { | ||
const perms = fs.statSync(filePath).mode; | ||
fs.chmodSync(filePath, perms | 0o111); | ||
} | ||
function getIsMusl() { | ||
// code adapted from https://github.com/lovell/detect-libc | ||
// Copyright Apache 2.0 license, the detect-libc maintainers | ||
if (cachedIsMusl == null) { | ||
cachedIsMusl = innerGet(); | ||
} | ||
return cachedIsMusl; | ||
function getTarget() { | ||
const platform = os.platform(); | ||
if (platform === "linux") { | ||
return platform + "-" + getArch() + "-" + getLinuxFamily(); | ||
} else { | ||
return platform + "-" + getArch(); | ||
} | ||
} | ||
function innerGet() { | ||
try { | ||
if (os.platform() !== "linux") { | ||
return false; | ||
} | ||
return isProcessReportMusl() || isConfMusl(); | ||
} catch (err) { | ||
// just in case | ||
console.warn("Error checking if musl.", err); | ||
return false; | ||
} | ||
} | ||
function getArch() { | ||
const arch = os.arch(); | ||
if (arch !== "arm64" && arch !== "x64") { | ||
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available."); | ||
} | ||
return arch; | ||
} | ||
function isProcessReportMusl() { | ||
if (!process.report) { | ||
return false; | ||
} | ||
const rawReport = process.report.getReport(); | ||
const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport; | ||
if (!report || !(report.sharedObjects instanceof Array)) { | ||
return false; | ||
} | ||
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-")); | ||
} | ||
function getLinuxFamily() { | ||
return getIsMusl() ? "musl" : "glibc"; | ||
function isConfMusl() { | ||
const output = getCommandOutput(); | ||
const [_, ldd1] = output.split(/[\r\n]+/); | ||
return ldd1 && ldd1.includes("musl"); | ||
} | ||
function getIsMusl() { | ||
// code adapted from https://github.com/lovell/detect-libc | ||
// Copyright Apache 2.0 license, the detect-libc maintainers | ||
if (cachedIsMusl == null) { | ||
cachedIsMusl = innerGet(); | ||
} | ||
return cachedIsMusl; | ||
function getCommandOutput() { | ||
try { | ||
const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true"; | ||
return require("child_process").execSync(command, { encoding: "utf8" }); | ||
} catch (_err) { | ||
return ""; | ||
} | ||
function innerGet() { | ||
try { | ||
if (os.platform() !== "linux") { | ||
return false; | ||
} | ||
return isProcessReportMusl() || isConfMusl(); | ||
} catch (err) { | ||
// just in case | ||
console.warn("Error checking if musl.", err); | ||
return false; | ||
} | ||
} | ||
}, | ||
}; | ||
function isProcessReportMusl() { | ||
if (!process.report) { | ||
return false; | ||
} | ||
const rawReport = process.report.getReport(); | ||
const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport; | ||
if (!report || !(report.sharedObjects instanceof Array)) { | ||
return false; | ||
} | ||
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-")); | ||
} | ||
function isConfMusl() { | ||
const output = getCommandOutput(); | ||
const [_, ldd1] = output.split(/[\r\n]+/); | ||
return ldd1 && ldd1.includes("musl"); | ||
} | ||
function getCommandOutput() { | ||
try { | ||
const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true"; | ||
return require("child_process").execSync(command, { encoding: "utf8" }); | ||
} catch (_err) { | ||
return ""; | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "dprint", | ||
"version": "0.38.0", | ||
"version": "0.38.1", | ||
"description": "Pluggable and configurable code formatting platform written in Rust.", | ||
@@ -20,10 +20,11 @@ "bin": "bin.js", | ||
"homepage": "https://github.com/dprint/dprint#readme", | ||
"preferUnplugged": true, | ||
"optionalDependencies": { | ||
"@dprint/win32-x64": "0.38.0", | ||
"@dprint/darwin-x64": "0.38.0", | ||
"@dprint/darwin-arm64": "0.38.0", | ||
"@dprint/linux-x64-glibc": "0.38.0", | ||
"@dprint/linux-x64-musl": "0.38.0", | ||
"@dprint/linux-arm64-glibc": "0.38.0" | ||
"@dprint/win32-x64": "0.38.1", | ||
"@dprint/darwin-x64": "0.38.1", | ||
"@dprint/darwin-arm64": "0.38.1", | ||
"@dprint/linux-x64-glibc": "0.38.1", | ||
"@dprint/linux-x64-musl": "0.38.1", | ||
"@dprint/linux-arm64-glibc": "0.38.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7152
164
2
5