@fnpm-io/cli
Advanced tools
Comparing version 0.4.17 to 0.4.19
@@ -198,2 +198,3 @@ import chalk from "chalk"; | ||
test.spinner.succeed(); | ||
await sleep(2000); | ||
} | ||
@@ -241,1 +242,4 @@ // Sort the results by time | ||
} | ||
async function sleep(ms) { | ||
return new Promise((resolve)=>setTimeout(resolve, ms)); | ||
} |
import chalk from "chalk"; | ||
import ora from "ora"; | ||
import rpjf from "read-package-json-fast"; | ||
import { writeFile, readFile } from "fs/promises"; | ||
import { writeFile, readFile, unlink } from "fs/promises"; | ||
import path from "path"; | ||
import pacote from "pacote"; | ||
import { performance } from "perf_hooks"; | ||
@@ -37,19 +36,27 @@ import { getDeps } from "../utils/getDeps.js"; | ||
if (lock) { | ||
const __install = ora(chalk.green("Installing dependencies...")).start(); | ||
const start = performance.now(); | ||
// Hardlink all the packages in fnpm.lock to each path from cache | ||
for(const pkg in lock){ | ||
for(const version in lock[pkg]){ | ||
__install.text = chalk.green(`Installing ${pkg}@${version} from cache...`); | ||
const pathname = path.join(process.cwd(), lock[pkg][version].path); | ||
const cache = path.join(userFnpmCache, lock[pkg][version].cache); | ||
await hardLink(cache, pathname); | ||
try { | ||
const __install = ora(chalk.green("Installing dependencies...")).start(); | ||
const start = performance.now(); | ||
// Hardlink all the packages in fnpm.lock to each path from cache | ||
for(const pkg in lock){ | ||
for(const version in lock[pkg]){ | ||
__install.text = chalk.green(`Installing ${pkg}@${version} from cache...`); | ||
const pathname = path.join(process.cwd(), lock[pkg][version].path); | ||
const cache = path.join(userFnpmCache, lock[pkg][version].cache); | ||
await hardLink(cache, pathname); | ||
} | ||
} | ||
const end = performance.now(); | ||
__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(); | ||
ora(chalk.yellow("Lockfile is outdated, installing from cache...")).warn(); | ||
await unlink(path.join(process.cwd(), "fnpm.lock")); | ||
await install(opts); | ||
return; | ||
} | ||
const end = performance.now(); | ||
__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; | ||
} | ||
@@ -95,3 +102,3 @@ // Read package.json | ||
if (!isInstalled) { | ||
const manifest = await pacote.manifest(`${pkg}@latest`, { | ||
const manifest = await manifestFetcher(`${pkg}@latest`, { | ||
registry: REGISTRY | ||
@@ -98,0 +105,0 @@ }); |
@@ -5,3 +5,3 @@ import path from "path"; | ||
import ora from "ora"; | ||
import { chmod, symlink } from "fs/promises"; | ||
import { chmodSync, symlinkSync } from "fs"; | ||
import rpjf from "read-package-json-fast"; | ||
@@ -28,6 +28,4 @@ export async function installBins() { | ||
// Create symlink to bin file | ||
await symlink(path.join(packagePath, bin[key]), binPath).catch((err)=>{ | ||
throw err; | ||
}); | ||
await chmod(binPath, 0o755); | ||
symlinkSync(path.join(packagePath, bin[key]), binPath); | ||
chmodSync(binPath, 0o755); | ||
break; | ||
@@ -39,6 +37,4 @@ } | ||
// Create symlink to bin file | ||
await symlink(path.join(packagePath, bin), binPath1).catch((err)=>{ | ||
throw err; | ||
}); | ||
await chmod(path.join(binPath1), 0o755); | ||
symlinkSync(path.join(packagePath, bin), binPath1); | ||
chmodSync(path.join(binPath1), 0o755); | ||
return; | ||
@@ -45,0 +41,0 @@ } |
@@ -1,19 +0,18 @@ | ||
import chalk from "chalk"; | ||
import { link, lstat, mkdir, readdir, copyFile } from "fs/promises"; | ||
import { linkSync, lstatSync, mkdirSync, readdirSync, copyFileSync } from "fs"; | ||
import { constants } from "fs"; | ||
import ora from "ora"; | ||
import path from "path"; | ||
import os from "os"; | ||
import ora from "ora"; | ||
import chalk from "chalk"; | ||
const isMac = os.platform() === "darwin"; | ||
export async function hardLink(dir, targetDir) { | ||
try { | ||
const files = await readdir(dir); | ||
const files = readdirSync(dir); | ||
return await Promise.all(files.map(async (file)=>{ | ||
const filePath = path.join(dir, file); | ||
const targetPath = path.join(targetDir, file); | ||
const stat = await lstat(filePath); | ||
const stat = lstatSync(filePath); | ||
if (stat.isDirectory()) { | ||
await mkdir(targetPath).catch((e)=>{ | ||
if (e.code !== "EEXIST") return; | ||
if (e.code === "ENOENT") ora(chalk.red(e.message)).fail(); | ||
mkdirSync(targetPath, { | ||
recursive: true | ||
}); | ||
@@ -23,20 +22,15 @@ await hardLink(filePath, targetPath); | ||
// Create previous folders if they don't exist | ||
await mkdir(path.dirname(targetPath), { | ||
mkdirSync(path.dirname(targetPath), { | ||
recursive: true | ||
}); | ||
if (!isMac) { | ||
await link(filePath, targetPath).catch((e)=>{ | ||
if (e.code === "EEXIST") { | ||
return; | ||
} | ||
ora(chalk.red(e.message)).fail(); | ||
}); | ||
try { | ||
linkSync(filePath, targetPath); | ||
} catch (e) { | ||
if (e.code === "EEXIST") return; | ||
ora(chalk.red(`Error: ${e.message} (file: ${filePath}, target: ${targetPath})`)).fail(); | ||
} | ||
} else { | ||
// Use clonefile on mac | ||
await copyFile(filePath, targetPath, constants.COPYFILE_FICLONE).catch((e)=>{ | ||
if (e.code === "EEXIST") { | ||
return; | ||
} | ||
ora(chalk.red(e.message)).fail(); | ||
}); | ||
copyFileSync(filePath, targetPath, constants.COPYFILE_FICLONE); | ||
} | ||
@@ -43,0 +37,0 @@ } |
import chalk from "chalk"; | ||
import ora from "ora"; | ||
import rpjf from "read-package-json-fast"; | ||
import { mkdir, writeFile } from "fs/promises"; | ||
import { mkdirSync, existsSync, writeFileSync, readFileSync } from "fs"; | ||
import { exec } from "child_process"; | ||
import path from "path"; | ||
import { existsSync, readFileSync } from "fs"; | ||
import semver from "semver"; | ||
@@ -59,10 +58,2 @@ import { getDeps } from "../utils/getDeps.js"; | ||
} | ||
// Check if parent exists | ||
if (parent) { | ||
if (!existsSync(`${parent}/node_modules`)) { | ||
await mkdir(`${parent}/node_modules`, { | ||
recursive: true | ||
}); | ||
} | ||
} | ||
let savedDeps = null; | ||
@@ -82,5 +73,3 @@ // Push to downloaded package info | ||
// Create directory for package without the last folder | ||
const dirs = pkgProjectDir.split("/"); | ||
dirs.pop(); | ||
await mkdir(dirs.join("/"), { | ||
mkdirSync(path.dirname(pkgProjectDir), { | ||
recursive: true | ||
@@ -106,5 +95,3 @@ }); | ||
// Create directory for package without the last folder | ||
const dirs1 = pkgProjectDir.split("/"); | ||
dirs1.pop(); | ||
await mkdir(dirs1.join("/"), { | ||
mkdirSync(path.dirname(pkgProjectDir), { | ||
recursive: true | ||
@@ -153,3 +140,3 @@ }); | ||
}); | ||
await writeFile(`${cacheFolder}/${downloadFile}`, JSON.stringify(object, null, 2), "utf-8"); | ||
writeFileSync(`${cacheFolder}/${downloadFile}`, JSON.stringify(object, null, 2), "utf-8"); | ||
// Execute postinstall script if exists | ||
@@ -156,0 +143,0 @@ const postinstall = pkg.scripts.postinstall; |
import os from "os"; | ||
import path from "path"; | ||
import pacote from "pacote"; | ||
import { readFile, writeFile, mkdir } from "fs/promises"; | ||
import { mkdir } from "fs/promises"; | ||
import { readFileSync, writeFileSync, mkdirSync } from "fs"; | ||
const cacheFolder = path.join(os.homedir(), ".fnpm", "__manifests__"); | ||
@@ -17,31 +18,43 @@ const specialChars = [ | ||
export default async function manifestFetcher(spec, props) { | ||
await mkdir(cacheFolder, { | ||
recursive: true | ||
}).catch((e)=>{}); | ||
const cacheFile = path.join(cacheFolder, `${spec}.json`); | ||
const now = Date.now(); | ||
const isExact = !specialChars.some((char)=>spec.includes(char)); | ||
// Check if cache file exists | ||
const cacheExists = await readFile(cacheFile, "utf-8").catch(()=>null); | ||
if (cacheExists) { | ||
const cache = JSON.parse(cacheExists); | ||
// Check if cache is expired | ||
if (cache.expires > now || isExact) { | ||
return cache.manifest; | ||
try { | ||
await mkdir(cacheFolder, { | ||
recursive: true | ||
}).catch((e)=>{}); | ||
const isExact = !specialChars.some((char)=>spec.includes(char)); | ||
// Check if cache file exists | ||
const cacheExists = readFileSync(cacheFile, "utf-8"); | ||
if (cacheExists) { | ||
const cache = JSON.parse(cacheExists); | ||
// Check if cache is expired | ||
if (cache.expires > now || isExact) { | ||
return cache.manifest; | ||
} | ||
} | ||
// Fetch manifest | ||
const manifest = await pacote.manifest(spec, props); | ||
mkdirSync(path.dirname(cacheFile), { | ||
recursive: true | ||
}); | ||
// Save manifest to cache | ||
writeFileSync(cacheFile, JSON.stringify({ | ||
manifest, | ||
// Add 5 minutes to cache | ||
expires: now + 300000 | ||
}), "utf-8"); | ||
return manifest; | ||
} catch (e) { | ||
const manifest1 = await pacote.manifest(spec, props); | ||
mkdirSync(path.dirname(cacheFile), { | ||
recursive: true | ||
}); | ||
// Save manifest to cache | ||
writeFileSync(cacheFile, JSON.stringify({ | ||
manifest: manifest1, | ||
// Add 5 minutes to cache | ||
expires: now + 300000 | ||
}), "utf-8"); | ||
return manifest1; | ||
} | ||
// Fetch manifest | ||
const manifest = await pacote.manifest(spec, props); | ||
const dirs = cacheFile.split("/"); | ||
dirs.pop(); | ||
await mkdir(dirs.join("/"), { | ||
recursive: true | ||
}); | ||
// Save manifest to cache | ||
await writeFile(cacheFile, JSON.stringify({ | ||
manifest, | ||
// Add 5 minutes to cache | ||
expires: now + 300000 | ||
}), "utf-8"); | ||
return manifest; | ||
}; |
{ | ||
"name": "@fnpm-io/cli", | ||
"version": "0.4.17", | ||
"version": "0.4.19", | ||
"description": "FNPM CLI Tool.", | ||
@@ -5,0 +5,0 @@ "private": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59888
1528