Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fnpm-io/cli

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fnpm-io/cli - npm Package Compare versions

Comparing version 0.4.20 to 0.4.21

build/commands/autocompletion.js

17

build/commands/benchmark.js
import chalk from "chalk";
import { exec } from "child_process";
import { exec, spawn } from "child_process";
import ora from "ora";

@@ -210,13 +210,16 @@ import { performance } from "perf_hooks";

}, 1000);
exec(test.command, (error, stdout, stderr)=>{
if (error) {
const child = spawn(test.command, {
shell: true,
stdio: "pipe"
});
child.on("exit", (code)=>{
if (code === 0) {
end = performance.now();
resolve(error);
ora(chalk.red(`[Error] ${error}`)).fail();
err = true;
resolve(true);
clearInterval(interval);
} else {
end = performance.now();
resolve(stdout);
resolve(true);
clearInterval(interval);
err = true;
}

@@ -223,0 +226,0 @@ });

@@ -10,39 +10,79 @@ import { clear } from "./clear.js";

import remove from "./remove.js";
const comms = [
{
name: "install",
description: "Install a package",
command: install,
abr: "i",
params: true
},
{
name: "benchmark",
description: "Benchmark a package",
command: benchmark,
abr: "b",
params: false
},
{
name: "upgrade",
description: "Upgrade FNPM",
command: upgrade,
abr: "u",
params: false
},
{
name: "set",
description: "Set a config value",
command: update,
abr: "s",
params: true
},
{
name: "list",
description: "List package versions",
command: list,
abr: "ls",
params: true
},
{
name: "run",
description: "Run a script",
command: run,
abr: "r",
params: true
},
{
name: "create",
description: "Create a new package from a template",
command: create,
abr: "c",
params: true
},
{
name: "remove",
description: "Remove a package",
command: remove,
abr: "rm",
params: true
},
{
name: "clear",
description: "Clear the cache",
command: clear,
abr: "c",
params: false
},
];
export async function commands(args) {
const [command, ...rest] = args;
switch(command){
case "install":
await install(rest);
break;
case "i":
await install(rest);
break;
case "benchmark":
await benchmark(rest);
break;
case "clear":
await clear();
break;
case "upgrade":
await upgrade();
break;
case "ls":
await list(rest[0]);
break;
case "run":
await run(rest);
break;
case "set":
update(rest);
break;
case "create":
await create(rest);
break;
case "remove":
await remove(rest);
break;
default:
console.log(`Unknown command: ${command}`);
const comm = comms.find((c)=>c.name === command || c.abr === command);
if (comm) {
// @ts-ignore-next-line
return comm.command(rest);
}
// Disabled until I can show this only once
/* await checkVersion(); */ }
console.log("Unknown command");
console.log("Available commands:");
comms.forEach((c)=>{
console.log(`- ${c.name}: ${c.description}`);
});
}
import chalk from "chalk";
import ora from "ora";
import { writeFile, readFile, unlink } from "fs/promises";
import { mkdirSync, existsSync, symlinkSync, chmodSync } from "fs";
import path from "path";
import { performance } from "perf_hooks";
import { getDeps } from "../utils/getDeps.js";
import { installBins } from "../utils/addBinaries.js";
import { getDepsWorkspaces } from "../utils/getDepsWorkspaces.js";

@@ -28,9 +28,7 @@ import { installLocalDep } from "../utils/installLocalDep.js";

export default async function install(opts) {
const addDeps = await getParamsDeps(opts);
const flag = opts.filter((opt)=>opt.startsWith("-"))[0];
await createModules();
const newDeps = opts.filter((opt)=>!opt.startsWith("-")).length > 0;
// Read fnpm.lock file as JSON
const lockFile = await readFile(path.join(process.cwd(), "fnpm.lock"), "utf-8").catch(()=>null);
const lock = lockFile ? JSON.parse(lockFile) : null;
if (lock && addDeps.length === 0) {
if (lock && !newDeps) {
try {

@@ -57,2 +55,19 @@ const __install = ora(chalk.green("Installing dependencies...")).start();

await hardLink(cache, pathname);
const manifest = readPackage(path.join(pathname, "package.json"));
const bins = manifest.bin;
if (bins) {
for (const bin of Object.keys(bins)){
try {
const binPath = path.join(pathname, bins[bin]);
const binLink = path.join(process.cwd(), "node_modules", ".bin", bin);
if (existsSync(binPath)) {
mkdirSync(path.dirname(binLink), {
recursive: true
});
symlinkSync(binPath, binLink);
chmodSync(binPath, 0o755);
}
} catch (e) {}
}
}
}

@@ -62,8 +77,5 @@ }

__install.succeed(chalk.green(`Installed dependencies in ${chalk.grey(parseTime(start, end))} ${chalk.grey("(from lockfile)")}`));
const __binaries = ora(chalk.green("Installing binaries...")).start();
await installBins();
__binaries.succeed(chalk.green("Installed binaries!"));
return;
} catch (e) {
ora(chalk.red(`Error: ${e}`)).fail();
} catch (e1) {
ora(chalk.red(`Error: ${e1}`)).fail();
ora(chalk.yellow("Lockfile is outdated, installing from cache...")).warn();

@@ -75,2 +87,5 @@ await unlink(path.join(process.cwd(), "fnpm.lock"));

}
const addDeps = await getParamsDeps(opts);
const flag = opts.filter((opt)=>opt.startsWith("-"))[0];
await createModules();
ora(chalk.blue(`Using ${REGISTRY} as registry...`)).info();

@@ -81,3 +96,3 @@ // Read package.json

const workspaces = pkg1.workspaces || null;
const wsDeps = await getDepsWorkspaces(workspaces);
const wsDeps = workspaces ? await getDepsWorkspaces(workspaces) : [];
// Get all dependencies with version

@@ -136,7 +151,2 @@ const deps = getDeps(pkg1).concat(wsDeps).concat(addDeps);

__install1.succeed(chalk.green(`Installed packages in ${chalk.gray(parseTime(__install_start, __install_end))}`));
const __binaries1 = ora(chalk.blue("Installing binaries...")).start();
const __binaries_start = performance.now();
await installBins();
const __binaries_end = performance.now();
__binaries1.succeed(chalk.blue(`Installed binaries in ${chalk.gray(parseTime(__binaries_start, __binaries_end))}`));
// If addDeps is not empty, add them to package.json using flag

@@ -143,0 +153,0 @@ if (addDeps.length > 0) {

@@ -7,4 +7,4 @@ import chalk from "chalk";

import path from "path";
export default async function list(pkg) {
if (!pkg) {
export default async function list(pkgs) {
if (!pkgs) {
ora(chalk.red("Missing package name")).fail();

@@ -15,15 +15,17 @@ const packages = await readdir(path.join(os.homedir(), ".fnpm-cache"));

}
const pathName = path.join(os.homedir(), ".fnpm-cache", pkg);
if (!existsSync(pathName)) {
ora(chalk(`${pkg} is not installed with FNPM!`)).fail();
return;
}
const dir = await lstat(pathName);
if (dir.isDirectory()) {
const versions = await readdir(pathName);
console.log(`${chalk.blue(versions.length)} version${versions.length > 1 ? "s" : ""} of ${chalk.green(pkg)} ${versions.length > 1 ? "are" : "is"} installed:`);
for (const version of versions){
console.log(chalk.grey("-") + " " + version);
pkgs.forEach(async (pkg)=>{
const pathName = path.join(os.homedir(), ".fnpm-cache", pkg);
if (!existsSync(pathName)) {
ora(chalk(`${pkg} is not installed with FNPM!`)).fail();
return;
}
}
const dir = await lstat(pathName);
if (dir.isDirectory()) {
const versions = await readdir(pathName);
console.log(`${chalk.blue(versions.length)} version${versions.length > 1 ? "s" : ""} of ${chalk.green(pkg)} ${versions.length > 1 ? "are" : "is"} installed:`);
for (const version of versions){
console.log(chalk.grey("-") + " " + version);
}
}
});
};
import chalk from "chalk";
import ora from "ora";
import readPackage from "./readPackage.js";
import { mkdirSync, existsSync, writeFileSync, readFileSync } from "fs";
import { mkdirSync, existsSync, writeFileSync, readFileSync, symlinkSync, chmodSync } from "fs";
import { exec } from "child_process";

@@ -82,8 +82,26 @@ import path from "path";

await hardLink(cacheFolder, pkgProjectDir).catch((e)=>{});
const pkg = readPackage(path.join(pkgProjectDir, "package.json"));
// Get deps from file
const cachedDeps = JSON.parse(readFileSync(`${cacheFolder}/${downloadFile}`, "utf-8"));
// Symlink bin files
const bins = pkg.bin;
if (bins) {
for (const bin of Object.keys(bins)){
try {
const binPath = path.join(pkgProjectDir, bins[bin]);
const binLink = path.join(process.cwd(), "node_modules", ".bin", bin);
if (existsSync(binPath)) {
mkdirSync(path.dirname(binLink), {
recursive: true
});
symlinkSync(binPath, binLink);
chmodSync(binPath, 0o755);
}
} catch (e) {}
}
}
for (const dep of Object.keys(cachedDeps)){
const name = dep;
const version = Object.keys(cachedDeps[dep])[0];
const { tarball , spec } = cachedDeps[dep][version];
const { tarball , spec , bins: bins1 } = cachedDeps[dep][version];
await installPkg({

@@ -106,4 +124,4 @@ name,

try {
const pkg = readPackage(`${cacheFolder}/package.json`);
const deps = getDeps(pkg, {
const pkg1 = readPackage(`${cacheFolder}/package.json`);
const deps = getDeps(pkg1, {
dev: true

@@ -146,3 +164,3 @@ });

// Execute postinstall script if exists
const postinstall = pkg.scripts.postinstall;
const postinstall = pkg1.scripts.postinstall;
if (postinstall) {

@@ -157,2 +175,17 @@ const postinstallPath = path.join(cacheFolder, "node_modules", ".");

}
// Symlink bin files
const bins2 = pkg1.bin;
if (bins2) {
for (const bin1 of Object.keys(bins2)){
const binPath1 = path.join(pkgProjectDir, bins2[bin1]);
const binLink1 = path.join(process.cwd(), "node_modules", ".bin", bin1);
if (existsSync(binPath1)) {
mkdirSync(path.dirname(binLink1), {
recursive: true
});
symlinkSync(binPath1, binLink1);
chmodSync(binPath1, 0o755);
}
}
}
return;

@@ -159,0 +192,0 @@ } catch (error) {

@@ -1,7 +0,8 @@

import pacote from "pacote";
import manifestFetcher from "./manifestFetcher.js";
import { REGISTRY } from "../commands/install.js";
export default async function getParamsDeps(opts) {
const instalableDeps = opts.filter((opt)=>!opt.startsWith("-"));
const addDeps = instalableDeps.map(async (dep)=>{
const res = await pacote.manifest(dep, {
registry: "https://registry.npmjs.org/"
const res = await manifestFetcher(dep, {
registry: REGISTRY
});

@@ -8,0 +9,0 @@ // Return the dependency with version

{
"name": "@fnpm-io/cli",
"version": "0.4.20",
"version": "0.4.21",
"description": "FNPM CLI Tool.",

@@ -5,0 +5,0 @@ "private": false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc