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.19 to 0.4.20

build/utils/readPackage.js

50

build/commands/benchmark.js

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

import { execa } from "execa";
import rpjf from "read-package-json-fast";
import { fileURLToPath } from "url";
import readPackage from "../utils/readPackage.js";
const homeDir = os.homedir();

@@ -39,3 +39,10 @@ const __filename = fileURLToPath(import.meta.url);

},
{
/* {
name: "NPM add",
command: "npm install @swc/core -D --force",
pre: "ls",
post: "npm uninstall @swc/core -D --force",
spinner: ora(chalk.green(`Running "NPM add" ...`)).stop(),
group: 4,
}, */ {
name: "YARN install (no cache / no lockfile)",

@@ -61,3 +68,10 @@ command: "yarn install --force",

},
{
/* {
name: "YARN add",
command: "yarn add @swc/core -D --force",
pre: "ls",
post: "yarn remove @swc/core -D --force",
spinner: ora(chalk.green(`Running "YARN add" ...`)).stop(),
group: 4,
}, */ {
name: "FNPM install (no cache / no lockfile)",

@@ -83,3 +97,10 @@ command: "fnpm install",

},
{
/* {
name: "FNPM add",
command: "fnpm install @swc/core -D",
pre: "ls",
post: "fnpm remove @swc/core",
spinner: ora(chalk.green(`Running "FNPM add" ...`)).stop(),
group: 4,
}, */ {
name: "PNPM install (no cache / no lockfile)",

@@ -105,3 +126,10 @@ command: "pnpm install --force",

},
{
/* {
name: "PNPM add",
command: "pnpm add @swc/core -D",
pre: "ls",
post: "pnpm remove @swc/core",
spinner: ora(chalk.green(`Running "PNPM add" ...`)).stop(),
group: 4,
}, */ {
name: "Bun install (no cache / no lockfile)",

@@ -126,11 +154,12 @@ command: "bun install",

group: 3
},
}
];
export async function benchmark(args) {
var ref;
const pkg = await rpjf(path.join(__dirname, "..", "..", "package.json"));
const currentPkg = await rpjf(path.join(process.cwd(), "package.json"));
const pkg = readPackage(path.join(__dirname, "..", "..", "package.json"));
const currentPkg = readPackage(path.join(process.cwd(), "package.json"));
// If the user passed flag --only-fnpm, we only run the fnpm tests
const onlyfnpm = args.includes("--only-fnpm");
const ignoreBun = args.includes("--ignore-bun");
const ignorePnpm = args.includes("--ignore-pnpm");
if (onlyfnpm) ora(chalk.yellow("Only running fnpm tests")).warn();

@@ -145,2 +174,7 @@ const selectedGroup = (ref = args.find((arg)=>arg.startsWith("--group="))) == null ? void 0 : ref.replace("--group=", "");

}
if (ignorePnpm) {
const firstPnpmTestIndex = testsToRun.findIndex((test)=>test.name.includes("PNPM"));
testsToRun.splice(firstPnpmTestIndex, 3);
ora(chalk.yellow(`Pnpm tests have been ignored. To run them, remove the --ignore-pnpm flag.`)).warn();
}
const __init = ora(chalk.green("Starting benchmark...")).start();

@@ -147,0 +181,0 @@ await execa("npm", [

4

build/commands/clear.js

@@ -5,8 +5,8 @@ import os from "os";

import ora from "ora";
import rpjf from "read-package-json-fast";
import glob from "glob";
import readPackage from "../utils/readPackage.js";
export async function clear() {
const cacheFolder = `${os.homedir()}/.fnpm-cache`;
const packageJson = `${process.cwd()}/package.json`;
const pkg = await rpjf(packageJson);
const pkg = readPackage(packageJson);
const workspaces = pkg.workspaces || null;

@@ -13,0 +13,0 @@ const __clear = ora("Clearing cache...").start();

@@ -6,3 +6,2 @@ import ora from "ora";

import path from "path";
import rpjf from "read-package-json-fast";
import { execa } from "execa";

@@ -12,2 +11,3 @@ import { existsSync, rmSync, symlinkSync } from "fs";

import { getDeps } from "../utils/getDeps.js";
import readPackage from "../utils/readPackage.js";
export default async function create(args) {

@@ -55,3 +55,3 @@ if (args.length === 0) {

// Get bin path
const bin = await rpjf(globalPath + "/package.json").then((res)=>res.bin);
const bin = readPackage(globalPath + "/package.json").then((res)=>res.bin);
const isObject = bin && typeof bin === "object";

@@ -79,3 +79,3 @@ const binName = isObject ? Object.keys(bin)[0] : bin;

// Read package.json
const pkg = await rpjf(path.join(installPath, "package.json"));
const pkg = readPackage(path.join(installPath, "package.json"));
const deps = getDeps(pkg, {

@@ -82,0 +82,0 @@ dev: true

import chalk from "chalk";
import ora from "ora";
import rpjf from "read-package-json-fast";
import { writeFile, readFile, unlink } from "fs/promises";

@@ -19,2 +18,3 @@ import path from "path";

import manifestFetcher from "../utils/manifestFetcher.js";
import readPackage from "../utils/readPackage.js";
let pkgs = [];

@@ -29,3 +29,2 @@ export const __INSTALLED = [];

export default async function install(opts) {
ora(chalk.blue(`Using ${REGISTRY} as registry...`)).info();
const addDeps = await getParamsDeps(opts);

@@ -37,3 +36,3 @@ const flag = opts.filter((opt)=>opt.startsWith("-"))[0];

const lock = lockFile ? JSON.parse(lockFile) : null;
if (lock) {
if (lock && addDeps.length === 0) {
try {

@@ -47,2 +46,13 @@ const __install = ora(chalk.green("Installing dependencies...")).start();

const pathname = path.join(process.cwd(), lock[pkg][version].path);
// If version is local, it's a local dependency
if (version === "local") {
await installLocalDep({
name: pkg,
version: pathname
}).catch((err)=>{
ora(chalk.red(`Error installing ${pkg}@${version}`)).fail();
throw err;
});
continue;
}
const cache = path.join(userFnpmCache, lock[pkg][version].cache);

@@ -66,4 +76,5 @@ await hardLink(cache, pathname);

}
ora(chalk.blue(`Using ${REGISTRY} as registry...`)).info();
// Read package.json
const pkg1 = await rpjf("./package.json");
const pkg1 = readPackage("./package.json");
// Read "workspaces" field

@@ -79,2 +90,7 @@ const workspaces = pkg1.workspaces || null;

if (islocal) {
__DOWNLOADED.push({
name: dep.name,
version: "local",
path: dep.version
});
await installLocalDep(dep);

@@ -97,3 +113,3 @@ return;

__fetch.succeed(chalk.green(`Fetched packages in ${chalk.gray(parseTime(__fetch_start, __fetch_end))}`));
const __install1 = spinnerGradient("Installing packages...");
const __install1 = spinnerGradient(chalk.green("Installing packages..."));
const __install_start = performance.now();

@@ -157,2 +173,7 @@ await Promise.all(pkgs.map(async (pkg)=>{

});
// Remove empty objects
if (Object.keys(pkg1.dependencies).length === 0) delete pkg1.dependencies;
if (Object.keys(pkg1.devDependencies).length === 0) delete pkg1.devDependencies;
if (Object.keys(pkg1.peerDependencies).length === 0) delete pkg1.peerDependencies;
if (Object.keys(pkg1.optionalDependencies).length === 0) delete pkg1.optionalDependencies;
await writeFile(path.join(process.cwd(), "package.json"), JSON.stringify(pkg1, null, 2), "utf-8");

@@ -168,3 +189,4 @@ }

path: pkg.path,
cache: pkg.cache
cache: pkg.cache,
tarball: pkg.tarball
};

@@ -171,0 +193,0 @@ return;

@@ -1,4 +0,4 @@

import rpjf from "read-package-json-fast";
import chalk from "chalk";
import { writeFile } from "fs/promises";
import readPackage from "../utils/readPackage.js";
export default async function remove(args) {

@@ -10,3 +10,3 @@ if (args.length === 0) {

// Read CWD package.json
const pkg = await rpjf(process.cwd() + "/package.json");
const pkg = readPackage(process.cwd() + "/package.json");
// Remove packages from dependencies

@@ -13,0 +13,0 @@ for (const arg of args){

import path from "path";
import rpjf from "read-package-json-fast";
import ora from "ora";

@@ -9,4 +8,5 @@ import chalk from "chalk";

import checkNodeVersion from "../utils/checkNodeVersion.js";
import readPackage from "../utils/readPackage.js";
export default async function run(args) {
const pkg = await rpjf(path.join(process.cwd(), "package.json"));
const pkg = readPackage(path.join(process.cwd(), "package.json"));
await checkNodeVersion(pkg.engines);

@@ -13,0 +13,0 @@ const { scripts } = pkg;

@@ -6,3 +6,3 @@ import path from "path";

import { chmodSync, symlinkSync } from "fs";
import rpjf from "read-package-json-fast";
import readPackage from "./readPackage.js";
export async function installBins() {

@@ -17,3 +17,3 @@ try {

return await Promise.allSettled(packages.map(async (data)=>{
const packageJSON = await rpjf(path.join(process.cwd(), "node_modules", data));
const packageJSON = readPackage(path.join(process.cwd(), "node_modules", data));
const { bin } = packageJSON;

@@ -20,0 +20,0 @@ const packagePath = path.join(process.cwd(), "node_modules", packageJSON.name);

import glob from "glob";
import path from "path";
import rpjf from "read-package-json-fast";
import { getDeps } from "./getDeps.js";
import readPackage from "./readPackage.js";
export async function getDepsWorkspaces(globs) {

@@ -12,3 +12,3 @@ if (!globs) return [];

for await (const file of files){
const pkg = await rpjf(file);
const pkg = readPackage(file);
const packageName = pkg.name;

@@ -37,3 +37,3 @@ // Save the package name with its file path if package is not private

pkg.version = `file:${process.cwd()}/${localDep.path}`;
} else if (pkg.version === "*") {
} else if (pkg.version.includes("*")) {
// Find package in local deps and replace version with the path

@@ -40,0 +40,0 @@ const localDep1 = localDeps.find((dep)=>dep.name === pkg.name);

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

import { linkSync, lstatSync, mkdirSync, readdirSync, copyFileSync } from "fs";
import { constants } from "fs";
import { linkSync, lstatSync, mkdirSync, readdirSync, copyFileSync, constants } from "fs";
import path from "path";

@@ -4,0 +3,0 @@ import os from "os";

import { existsSync } from "fs";
import { mkdir, rm, symlink } from "fs/promises";
import { mkdirSync, rmSync, symlinkSync } from "fs";
import path from "path";
export async function installLocalDep(pkg) {

@@ -8,19 +9,15 @@ // Create symlink from local package to node_modules

if (existsSync(pkgProjectDir)) {
await rm(pkgProjectDir, {
rmSync(pkgProjectDir, {
recursive: true
});
const dirs = pkgProjectDir.split("/");
dirs.pop();
await mkdir(dirs.join("/"), {
mkdirSync(path.dirname(pkgProjectDir), {
recursive: true
});
await symlink(pkg.version.split("file:")[1], pkgProjectDir, "dir");
symlinkSync(pkg.version.split("file:")[1], pkgProjectDir, "junction");
return;
} else {
const dirs1 = pkgProjectDir.split("/");
dirs1.pop();
await mkdir(dirs1.join("/"), {
mkdirSync(path.dirname(pkgProjectDir), {
recursive: true
});
await symlink(pkg.version.split("file:")[1], pkgProjectDir, "dir");
symlinkSync(pkg.version.split("file:")[1], pkgProjectDir, "junction");
return;

@@ -27,0 +24,0 @@ }

import chalk from "chalk";
import ora from "ora";
import rpjf from "read-package-json-fast";
import readPackage from "./readPackage.js";
import { mkdirSync, existsSync, writeFileSync, readFileSync } from "fs";

@@ -20,34 +20,41 @@ import { exec } from "child_process";

}
if (__INSTALLED.find((pkg)=>pkg.name === manifest.name && pkg.version === manifest.version)) {
return;
}
const pkgInstalled = manifest.spec && __INSTALLED.find((pkg)=>pkg.name === manifest.name && semver.satisfies(pkg.version, manifest.spec));
if (pkgInstalled) {
if (spinner) {
spinner.text = chalk.green(`Skipping ${manifest.name}@${manifest.spec} as it's satisfied by ${pkgInstalled.version}`);
}
return;
}
// Check if package is already in root node_modules
const isInRoot = existsSync(path.join(process.cwd(), "node_modules", manifest.name));
const getDir = ()=>{
if (!isInRoot || !parent) {
return path.join(process.cwd(), "node_modules", manifest.name);
}
// Check how many node_modules are in the path
const count = parent.split("node_modules").length - 1;
if (count === 1) {
try {
if (!isInRoot || !parent) {
return path.join(process.cwd(), "node_modules", manifest.name);
}
// Check how many node_modules are in the path
const count = parent.split("node_modules").length - 1;
if (count === 1) {
return path.join(parent, "node_modules", manifest.name);
}
// Check if the dir exists in previous node_modules
const dir = path.join(process.cwd(), "node_modules", parent.split("node_modules")[1], "node_modules", manifest.name);
if (!existsSync(dir)) {
return dir;
}
// If it exists, check if the version is suitable with manifest.spec
const pkg = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf-8"));
if (semver.satisfies(pkg.version, manifest.spec)) {
return dir;
}
return path.join(parent, "node_modules", manifest.name);
} catch (e) {
return parent ? path.join(parent, "node_modules", manifest.name) : path.join(process.cwd(), "node_modules", manifest.name);
}
// Check if the dir exists in previous node_modules
const dir = path.join(process.cwd(), "node_modules", parent.split("node_modules")[1], "node_modules", manifest.name);
if (!existsSync(dir)) {
return dir;
}
// If it exists, check if the version is suitable with manifest.spec
const pkg = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf-8"));
if (semver.satisfies(pkg.version, manifest.spec)) {
return dir;
}
return path.join(parent, "node_modules", manifest.name);
};
const pkgProjectDir = getDir();
if (existsSync(pkgProjectDir)) return;
if (__INSTALLED.find((pkg)=>pkg.name === manifest.name && pkg.version === manifest.version)) {
return;
}
const pkgInstalled = manifest.spec && __INSTALLED.find((pkg)=>pkg.name === manifest.name && semver.satisfies(pkg.version, manifest.spec));
if (pkgInstalled) {
return;
}
if (!isInRoot) {

@@ -59,3 +66,2 @@ __INSTALLED.push({

}
let savedDeps = null;
// Push to downloaded package info

@@ -101,67 +107,52 @@ __DOWNLOADED.push({

try {
const pkg = await rpjf(`${cacheFolder}/package.json`);
if (!savedDeps) {
const deps = getDeps(pkg, {
dev: true
const pkg = readPackage(`${cacheFolder}/package.json`);
const deps = getDeps(pkg, {
dev: true
});
// Install production deps
const installed = await Promise.all(deps.map(async (dep)=>{
const manifest = await manifestFetcher(`${dep.name}@${dep.version}`, {
registry: REGISTRY
});
// Install production deps
const installed = await Promise.all(deps.map(async (dep)=>{
const manifest = await manifestFetcher(`${dep.name}@${dep.version}`, {
registry: REGISTRY
});
if (manifest.deprecated) {
ora(`[DEPR] ${chalk.bgYellowBright.black(manifest.name + "@" + manifest.version)} - ${manifest.deprecated}`).warn();
}
await installPkg({
name: dep.name,
version: manifest.version,
tarball: manifest.dist.tarball,
spec: dep.version
}, pkgProjectDir, spinner);
return {
name: dep.name,
version: manifest.version,
spec: dep.version,
tarball: manifest.dist.tarball,
path: path.join(userFnpmCache, dep.name, manifest.version)
};
}));
// Save installed deps with its path in .fnpm file as objects
let object = {};
installed.forEach((dep)=>{
object[dep.name] = {
[dep.version]: {
path: dep.path,
tarball: dep.tarball,
spec: dep.spec
}
};
});
writeFileSync(`${cacheFolder}/${downloadFile}`, JSON.stringify(object, null, 2), "utf-8");
// Execute postinstall script if exists
const postinstall = pkg.scripts.postinstall;
if (postinstall) {
const postinstallPath = path.join(cacheFolder, "node_modules", ".");
const postinstallScript = path.join(postinstallPath, postinstall);
if (existsSync(postinstallScript)) {
exec(`${postinstallScript}`, {
cwd: postinstallPath
});
}
if (manifest.deprecated) {
ora(`[DEPR] ${chalk.bgYellowBright.black(manifest.name + "@" + manifest.version)} - ${manifest.deprecated}`).warn();
}
return;
} else {
// Execute postinstall script if exists
const postinstall1 = pkg.scripts.postinstall;
if (postinstall1) {
const postinstallPath1 = path.join(cacheFolder, "node_modules", ".");
const postinstallScript1 = path.join(postinstallPath1, postinstall1);
if (existsSync(postinstallScript1)) {
exec(`${postinstallScript1}`, {
cwd: postinstallPath1
});
await installPkg({
name: dep.name,
version: manifest.version,
tarball: manifest.dist.tarball,
spec: dep.version
}, pkgProjectDir, spinner);
return {
name: dep.name,
version: manifest.version,
spec: dep.version,
tarball: manifest.dist.tarball,
path: path.join(userFnpmCache, dep.name, manifest.version)
};
}));
// Save installed deps with its path in .fnpm file as objects
let object = {};
installed.forEach((dep)=>{
object[dep.name] = {
[dep.version]: {
path: dep.path,
tarball: dep.tarball,
spec: dep.spec
}
};
});
writeFileSync(`${cacheFolder}/${downloadFile}`, JSON.stringify(object, null, 2), "utf-8");
// Execute postinstall script if exists
const postinstall = pkg.scripts.postinstall;
if (postinstall) {
const postinstallPath = path.join(cacheFolder, "node_modules", ".");
const postinstallScript = path.join(postinstallPath, postinstall);
if (existsSync(postinstallScript)) {
exec(`${postinstallScript}`, {
cwd: postinstallPath
});
}
return;
}
return;
} catch (error) {

@@ -168,0 +159,0 @@ return;

@@ -0,1 +1,15 @@

function _extends() {
_extends = Object.assign || function(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i];
for(var key in source){
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
import os from "os";

@@ -6,3 +20,5 @@ import path from "path";

import { readFileSync, writeFileSync, mkdirSync } from "fs";
import readConfig from "./readConfig.js";
const cacheFolder = path.join(os.homedir(), ".fnpm", "__manifests__");
const token = readConfig().token;
const specialChars = [

@@ -36,3 +52,5 @@ "^",

// Fetch manifest
const manifest = await pacote.manifest(spec, props);
const manifest = await pacote.manifest(spec, _extends({}, props, {
_authToken: token ? token : null
}));
mkdirSync(path.dirname(cacheFile), {

@@ -49,3 +67,5 @@ recursive: true

} catch (e) {
const manifest1 = await pacote.manifest(spec, props);
const manifest1 = await pacote.manifest(spec, _extends({}, props, {
_authToken: token ? token : null
}));
mkdirSync(path.dirname(cacheFile), {

@@ -52,0 +72,0 @@ recursive: true

@@ -27,3 +27,3 @@ import os from "os";

const configPath = `${os.homedir()}/.fnpm/.fnpmrc`;
const config = readConfig();
const config = JSON.parse(readFileSync(configPath, "utf8"));
const [key, value] = params;

@@ -30,0 +30,0 @@ config[key] = value;

{
"name": "@fnpm-io/cli",
"version": "0.4.19",
"version": "0.4.20",
"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