From e90f20caa9cfc6f8423f0e160a6c7b45e6f7e92e Mon Sep 17 00:00:00 2001 From: develar Date: Sat, 19 May 2018 09:15:54 +0200 Subject: [PATCH] feat: be nice to buggy npm --- .gitattributes | 2 +- index.d.ts | 7 ++----- index.js | 27 ++++++++++++++++----------- linux/index.js | 3 --- mac/index.js | 3 --- package.json | 2 +- win/index.js | 3 --- 7 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 linux/index.js delete mode 100644 mac/index.js delete mode 100644 win/index.js diff --git a/.gitattributes b/.gitattributes index a394704..a7de953 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -osx/7za filter=lfs diff=lfs merge=lfs -text +mac/7za filter=lfs diff=lfs merge=lfs -text linux/ia32/7za filter=lfs diff=lfs merge=lfs -text linux/x64/7za filter=lfs diff=lfs merge=lfs -text *.dll filter=lfs diff=lfs merge=lfs -text diff --git a/index.d.ts b/index.d.ts index 07b270e..bfc4c48 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,2 @@ -declare module "7zip-bin" { - export const path7za: string - export const path7x: string - export const pathCompressStdIn: string -} \ No newline at end of file +export const path7za: string +export const path7x: string \ No newline at end of file diff --git a/index.js b/index.js index 00b6142..4156633 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,21 @@ "use strict" -const path = require("path") +function getPath() { + if (process.env.USE_SYSTEM_7ZA === "true") { + return "7za" + } -const nameMap = { - "darwin": "mac", - "win32": "win", - "linux": "linux", + const path = require("path") + if (process.platform === "darwin") { + return path.join(__dirname, "mac", "7za") + } + else if (process.platform === "win32") { + return path.join(__dirname, "win", process.arch, "7za.exe") + } + else { + return path.join(__dirname, "linux", process.arch, "7za") + } } -const suffix = nameMap[process.platform] -if (suffix == null) { - throw new Error("Unsupported platform " + process.platform) -} -exports.path7za = process.env.USE_SYSTEM_7ZA === "true" ? "7za" : require(`./${suffix}`).path7za -exports.path7x = path.join(__dirname, "7x.sh") +exports.path7za = getPath() +exports.path7x = path.join(__dirname, "7x.sh") \ No newline at end of file diff --git a/linux/index.js b/linux/index.js deleted file mode 100644 index e3ea3ad..0000000 --- a/linux/index.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict" - -exports.path7za = require("path").join(__dirname, process.arch, "7za") \ No newline at end of file diff --git a/mac/index.js b/mac/index.js deleted file mode 100644 index b75e336..0000000 --- a/mac/index.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict" - -exports.path7za = require("path").join(__dirname, "7za") \ No newline at end of file diff --git a/package.json b/package.json index 74b5c2d..0b55c79 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "7zip-bin", "description": "7-Zip precompiled binaries", - "version": "3.1.0", + "version": "4.0.1", "files": [ "*.js", "7x.sh", diff --git a/win/index.js b/win/index.js deleted file mode 100644 index 62bb66a..0000000 --- a/win/index.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict" - -exports.path7za = require("path").join(__dirname, process.arch, "7za.exe") \ No newline at end of file