Skip to content

Commit 2f2b5ef

Browse files
committed
update version/dependencies, and refactor routines from them
1 parent 7b99e2f commit 2f2b5ef

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

installer.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { spawnSync } from 'child_process';
1515
import { unpack } from 'node-unar';
1616
import { wget, isString } from 'node-wget-fetch';
17+
import { isWindows } from 'node-sys';
1718

1819
const __filename = fileURLToPath(
1920
import.meta.url);
@@ -150,7 +151,7 @@ function makeExecutable(binary = [], binaryFolder = '') {
150151

151152
let extractionPromises = [];
152153
let platforms = [linuxPlatform, appleMacPlatform, windowsOtherPlatform];
153-
if (process.platform == 'win32')
154+
if (isWindows())
154155
platforms = [linuxPlatform, appleMacPlatform, windowsPlatform, windowsOtherPlatform];
155156

156157
platforms.forEach((dataFor) => {
@@ -214,8 +215,8 @@ Promise.all(extractionPromises)
214215
extracted.forEach(function (dataFor) {
215216
if (dataFor.sfxModules && dataFor.platform == process.platform) {
216217
try {
217-
const directory = (process.platform == "win32") ? dataFor.binaryDestinationDir : binaryDestination;
218-
extraUnpack(join(binaryDestination, (process.platform == "win32") ? '7z.exe' : '7z'),
218+
const directory = isWindows() ? dataFor.binaryDestinationDir : binaryDestination;
219+
extraUnpack(join(binaryDestination, (isWindows() ? '7z.exe' : '7z')),
219220
dataFor.extraSourceFile,
220221
directory,
221222
dataFor.sfxModules

lib/createSfx.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from 'path';
1313
import fs from 'fs-extra';
1414
import { Binary } from './utility.js';
15+
import { isArray, isWindows } from 'node-sys';
1516

1617
const platformTitle = {
1718
win32: 'Windows OS',
@@ -132,7 +133,7 @@ export const createSfx = function (
132133
let directory = (destination != '' && fs.existsSync(destination)) ? destination : getPath('when');
133134
let SfxDirectory = join(directory, 'SfxPackages');
134135
fs.ensureDirSync(SfxDirectory);
135-
let override = ((process.platform == 'win32') && (platform == 'linux' || platform == 'darwin'));
136+
let override = (isWindows() && (platform == 'linux' || platform == 'darwin'));
136137
let binaryDirectory = Binary(override);
137138
let configFile = join(binaryDirectory.path, 'config.txt');
138139
//let configFile = join(SfxDirectory, 'config.txt');
@@ -182,7 +183,7 @@ export const createSfx = function (
182183

183184
let sfxModule = (type == 'gui') ? '7zwin32.sfx' : '7zCon' + platform + '.sfx';
184185
let sfx = name.includes(extension) ? name : name + extension;
185-
let list = Array.isArray(files) ? [configFile].concat(files) : configFile + ' ' + files;
186+
let list = isArray(files) ? [configFile].concat(files) : configFile + ' ' + files;
186187
sfx = join(SfxDirectory, sfx);
187188
let params = Object.assign(options, {
188189
sfx: sfxModule

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import when from 'when';
44
import { Files, ReplaceNativeSeparator, Run } from './utility.js';
55

66
import { createSfx } from './createSfx.js';
7+
import { isWindows } from 'node-sys';
78

89
function retry(command, options, override, progress, onprogress, resolve, reject, archive, noRetry = false) {
910
// Start the command
@@ -267,15 +268,15 @@ export const listArchive = SevenZip.listArchive = function (filepath, options, o
267268
// Create a string that can be parsed by `run`.
268269
let command = 'l "' + filepath + '" ';
269270

270-
Run((process.platform == 'win32' ? '7z' : '7za'), command, options, override)
271+
Run((isWindows() ? '7z' : '7za'), command, options, override)
271272
.progress(function (data) {
272273
return progress(onprogress(data));
273274
})
274275
.then(function () {
275276
return resolve(spec);
276277
})
277278
.catch(function (err) {
278-
if (process.platform == 'win32') {
279+
if (isWindows()) {
279280
console.error('ListArchive failed using `7z`, retying with `7za`.');
280281
Run('7za', command, options, override)
281282
.progress(function (data) {

lib/utility.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import when from 'when';
44
import { EOL } from 'os';
55
import { fileURLToPath } from 'url';
66
import { dirname, join, sep, sep as nativeSeparator, normalize } from 'path';
7-
import { spawning, isUndefined, isArray, isString } from 'node-sys';
7+
import { spawning, isUndefined, isArray, isString, isWindows, isBool } from 'node-sys';
88

99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = dirname(__filename);
1111

1212
export const Binary = function (override = false, binary = '7z') {
13-
let path = join(__dirname, '..', "binaries", (override == true ? process.platform + sep + 'other32' : process.platform));
14-
let filename = (process.platform == "win32") ? binary + '.exe' : binary;
13+
let path = join(__dirname, '..', "binaries", (override === true ? process.platform + sep + 'other32' : process.platform));
14+
let filename = isWindows() ? binary + '.exe' : binary;
1515
return {
1616
path: path,
1717
filename: filename,
@@ -75,7 +75,7 @@ export const Run = function (binary = '7z', command = null, switches = {}, overr
7575
// Parse the command variable. If the command is not a string reject the
7676
// Promise. Otherwise transform the command into two variables: the command
7777
// name and the arguments.
78-
if (typeof command !== 'string' || typeof binary !== 'string') {
78+
if (!isString(command) || !isString(binary)) {
7979
return reject(new Error('Command and Binary must be a string'));
8080
}
8181

@@ -222,7 +222,7 @@ export const Switches = function (switches) {
222222
// Switches with a value. Detect if the value contains a space. If it does
223223
// wrap the value with double quotes. Else just add the switch and its value
224224
// to the string. Doubles quotes are used for parsing with a RegExp later.
225-
if (typeof switches[s] !== 'boolean') {
225+
if (!isBool(switches[s])) {
226226

227227
// Special treatment for wildcards
228228
if (s === 'wildcards') {

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-7z-archive",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "ESM front-end to 7-Zip, featuring alternative full 7z CLI tools, binaries for Linux, Windows, Mac OSX, seamlessly create 7zip SFX self extracting archives targeting different platforms.",
55
"type": "module",
66
"main": "lib/index.js",
@@ -73,8 +73,8 @@
7373
"node": ">=12.0.0"
7474
},
7575
"dependencies": {
76-
"node-unar": "^1.0.5",
77-
"node-sys": "^1.1.1",
76+
"node-unar": "^1.0.6",
77+
"node-sys": "^1.1.3",
7878
"fs-extra": "^9.0.1",
7979
"node-wget-fetch": "^1.1.0",
8080
"when": "^3.7.8",

0 commit comments

Comments
 (0)