You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

lazy-js-utils

Package Overview
Dependencies
Maintainers
0
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-js-utils - npm Package Compare versions

Comparing version

to
0.1.24

dist/types-82873c18.d.ts

14

dist/node/index.d.ts

@@ -1,3 +0,3 @@

import { I as IShellMessage, P as PkgTool, N as NodeWorkerPayload } from '../types-a148dfb7.js';
import { StdioOptions, SpawnSyncOptions } from 'node:child_process';
import { I as IShellMessage, P as PkgTool, N as NodeWorkerPayload } from '../types-82873c18.js';
import { StdioOptions, SpawnOptions } from 'node:child_process';

@@ -10,3 +10,3 @@ /**

*/
declare function fileCopy(urls: string[], destination: string): IShellMessage;
declare function fileCopy(urls: string[], destination: string): Promise<IShellMessage>;

@@ -56,5 +56,5 @@ /**

cwd?: string;
options?: SpawnSyncOptions;
options?: SpawnOptions;
}
declare function jsShell<T extends string | string[]>(commander: T, options?: Options | Options['stdio']): T extends string ? IShellMessage : IShellMessage[];
declare function jsShell<T extends string | string[]>(commander: T, options?: Options | Options['stdio']): T extends string ? Promise<IShellMessage> : Promise<IShellMessage[]>;

@@ -106,6 +106,6 @@ /**

*/
declare function hasPkg(rootPath: string): boolean;
declare function hasPkg(rootPath: string): Promise<boolean>;
declare function isInstallPkg(pkg: string): boolean;
declare function isInstallPkg(pkg: string): Promise<boolean>;
export { fileCopy, getExportBundle, getPkg, getPkgTool, hasPkg, isInstallPkg, jsShell, transformArgv, useNodeWorker, useProcressNodeWorker, withTaskName, writeFile };

@@ -49,3 +49,3 @@ "use strict";

// src/node/jsShell.ts
var import_node_child_process = __toESM(require("child_process"));
var import_node_child_process = require("child_process");
var import_node_process = __toESM(require("process"));

@@ -74,33 +74,51 @@

}
return isArray(commander) ? commander.map((command) => executor(command)) : executor(commander);
return isArray(commander) ? Promise.all(commander.map((command) => executor(command))) : executor(commander);
function executor(commander2) {
var _a, _b;
const { status, output, stdout, stderr, error, signal, pid } = import_node_child_process.default.spawnSync(commander2, args, {
shell: true,
encoding: "utf8",
stdio,
cwd,
..._options
return new Promise((resolve, reject) => {
var _a, _b;
const child = (0, import_node_child_process.spawn)(commander2, args, {
shell: true,
stdio,
cwd,
..._options
});
const pid = child.pid;
let result = "";
(_a = child.stdout) == null ? void 0 : _a.on("data", (data) => {
result += data.toString();
});
(_b = child.stderr) == null ? void 0 : _b.on("data", (data) => {
if (isLog)
console.error(data.toString());
});
child.on("close", (status) => {
result = result.trim();
if (status === 130) {
if (isLog)
console.log("\u5DF2\u53D6\u6D88...");
resolve({ status, result, pid });
} else if (status !== 0) {
if (isLog)
console.error(`Command failed with status ${status}`);
if (errorExit) {
reject(new Error(result));
import_node_process.default.exit(1);
} else {
resolve({ status, result, pid });
}
} else {
resolve({ status, result, pid });
}
});
child.on("error", (error) => {
if (isLog)
console.error(error.message);
if (errorExit) {
reject(new Error(error.message));
import_node_process.default.exit(1);
} else {
resolve({ status: null, result: error.message, pid });
}
});
});
const result = typeof output[1] === "string" ? (_a = output[1]) == null ? void 0 : _a.trim() : (_b = output[1]) == null ? void 0 : _b.toString();
if (status === 130) {
if (isLog)
console.log("\u5DF2\u53D6\u6D88...");
return { status, result };
}
if (status !== 0) {
if (isLog)
console.log(result || (error == null ? void 0 : error.message));
if (errorExit)
import_node_process.default.exit(1);
}
return {
status,
result,
stdout,
stderr,
error,
signal,
pid
};
}

@@ -302,5 +320,8 @@ }

var import_node_path7 = __toESM(require("path"));
function hasPkg(rootPath) {
async function hasPkg(rootPath) {
const url = import_node_path7.default.resolve(rootPath, "package.json");
const { result } = jsShell(`test -f "${url}" && echo "0"|| echo "1"`, "pipe");
const { result } = await jsShell(
`test -f "${url}" && echo "0"|| echo "1"`,
"pipe"
);
return result === "0";

@@ -310,4 +331,4 @@ }

// src/node/isInstallPkg.ts
function isInstallPkg(pkg) {
const { status } = jsShell(`if ! command -v ${pkg} &> /dev/null; then
async function isInstallPkg(pkg) {
const { status } = await jsShell(`if ! command -v ${pkg} &> /dev/null; then
exit 1

@@ -314,0 +335,0 @@ else

@@ -41,3 +41,3 @@ "use strict";

// src/node/jsShell.ts
var import_node_child_process = __toESM(require("child_process"));
var import_node_child_process = require("child_process");
var import_node_process2 = __toESM(require("process"));

@@ -61,33 +61,51 @@ function jsShell(commander, options) {

}
return isArray(commander) ? commander.map((command) => executor(command)) : executor(commander);
return isArray(commander) ? Promise.all(commander.map((command) => executor(command))) : executor(commander);
function executor(commander2) {
var _a, _b;
const { status, output, stdout, stderr, error, signal, pid } = import_node_child_process.default.spawnSync(commander2, args, {
shell: true,
encoding: "utf8",
stdio,
cwd,
..._options
return new Promise((resolve, reject) => {
var _a, _b;
const child = (0, import_node_child_process.spawn)(commander2, args, {
shell: true,
stdio,
cwd,
..._options
});
const pid = child.pid;
let result = "";
(_a = child.stdout) == null ? void 0 : _a.on("data", (data) => {
result += data.toString();
});
(_b = child.stderr) == null ? void 0 : _b.on("data", (data) => {
if (isLog)
console.error(data.toString());
});
child.on("close", (status) => {
result = result.trim();
if (status === 130) {
if (isLog)
console.log("\u5DF2\u53D6\u6D88...");
resolve({ status, result, pid });
} else if (status !== 0) {
if (isLog)
console.error(`Command failed with status ${status}`);
if (errorExit) {
reject(new Error(result));
import_node_process2.default.exit(1);
} else {
resolve({ status, result, pid });
}
} else {
resolve({ status, result, pid });
}
});
child.on("error", (error) => {
if (isLog)
console.error(error.message);
if (errorExit) {
reject(new Error(error.message));
import_node_process2.default.exit(1);
} else {
resolve({ status: null, result: error.message, pid });
}
});
});
const result = typeof output[1] === "string" ? (_a = output[1]) == null ? void 0 : _a.trim() : (_b = output[1]) == null ? void 0 : _b.toString();
if (status === 130) {
if (isLog)
console.log("\u5DF2\u53D6\u6D88...");
return { status, result };
}
if (status !== 0) {
if (isLog)
console.log(result || (error == null ? void 0 : error.message));
if (errorExit)
import_node_process2.default.exit(1);
}
return {
status,
result,
stdout,
stderr,
error,
signal,
pid
};
}

@@ -94,0 +112,0 @@ }

{
"name": "lazy-js-utils",
"version": "0.1.23",
"version": "0.1.24",
"description": "A collection of lazy-loaded JavaScript utilities for efficient development",

@@ -51,3 +51,3 @@ "author": "Simon He",

"spark-md5": "^3.0.2",
"lazy-js-utils": "^0.1.23"
"lazy-js-utils": "^0.1.24"
},

@@ -54,0 +54,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet