@antfu/install-pkg
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -1,6 +0,6 @@ | ||
import execa from 'execa'; | ||
import * as execa from 'execa'; | ||
declare type PackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun'; | ||
type PackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun'; | ||
declare const AGENTS: readonly ["pnpm", "yarn", "npm", "pnpm@6", "yarn@berry", "bun"]; | ||
declare type Agent = typeof AGENTS[number]; | ||
type Agent = typeof AGENTS[number]; | ||
declare function detectPackageManager(cwd?: string): Promise<Agent | null>; | ||
@@ -19,2 +19,2 @@ | ||
export { Agent, InstallPackageOptions, PackageManager, detectPackageManager, installPackage }; | ||
export { type Agent, type InstallPackageOptions, type PackageManager, detectPackageManager, installPackage }; |
@@ -1,38 +0,6 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
detectPackageManager: () => detectPackageManager, | ||
installPackage: () => installPackage | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/detect.ts | ||
var import_fs = __toESM(require("fs")); | ||
var import_path = __toESM(require("path")); | ||
var import_find_up = __toESM(require("find-up")); | ||
import fs from "fs"; | ||
import path from "path"; | ||
import process from "process"; | ||
import { findUp } from "find-up"; | ||
var AGENTS = ["pnpm", "yarn", "npm", "pnpm@6", "yarn@berry", "bun"]; | ||
@@ -48,18 +16,18 @@ var LOCKS = { | ||
let agent = null; | ||
const lockPath = await (0, import_find_up.default)(Object.keys(LOCKS), { cwd }); | ||
const lockPath = await findUp(Object.keys(LOCKS), { cwd }); | ||
let packageJsonPath; | ||
if (lockPath) | ||
packageJsonPath = import_path.default.resolve(lockPath, "../package.json"); | ||
packageJsonPath = path.resolve(lockPath, "../package.json"); | ||
else | ||
packageJsonPath = await (0, import_find_up.default)("package.json", { cwd }); | ||
if (packageJsonPath && import_fs.default.existsSync(packageJsonPath)) { | ||
packageJsonPath = await findUp("package.json", { cwd }); | ||
if (packageJsonPath && fs.existsSync(packageJsonPath)) { | ||
try { | ||
const pkg = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf8")); | ||
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); | ||
if (typeof pkg.packageManager === "string") { | ||
const [name, version] = pkg.packageManager.split("@"); | ||
if (name === "yarn" && parseInt(version) > 1) | ||
if (name === "yarn" && Number.parseInt(version) > 1) | ||
agent = "yarn@berry"; | ||
else if (name === "pnpm" && parseInt(version) < 7) | ||
else if (name === "pnpm" && Number.parseInt(version) < 7) | ||
agent = "pnpm@6"; | ||
else if (name in AGENTS) | ||
else if (AGENTS.includes(name)) | ||
agent = name; | ||
@@ -73,3 +41,3 @@ else | ||
if (!agent && lockPath) | ||
agent = LOCKS[import_path.default.basename(lockPath)]; | ||
agent = LOCKS[path.basename(lockPath)]; | ||
return agent; | ||
@@ -79,3 +47,3 @@ } | ||
// src/install.ts | ||
var import_execa = __toESM(require("execa")); | ||
import { execa } from "execa"; | ||
async function installPackage(names, options = {}) { | ||
@@ -93,3 +61,3 @@ const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm"; | ||
} | ||
return (0, import_execa.default)( | ||
return execa( | ||
agent, | ||
@@ -108,6 +76,5 @@ [ | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
export { | ||
detectPackageManager, | ||
installPackage | ||
}); | ||
}; |
{ | ||
"name": "@antfu/install-pkg", | ||
"version": "0.1.1", | ||
"packageManager": "pnpm@7.12.0", | ||
"type": "module", | ||
"version": "0.2.0", | ||
"packageManager": "pnpm@8.10.5", | ||
"description": "Install package programmatically.", | ||
@@ -22,8 +23,8 @@ "author": "Anthony Fu <anthonyfu117@hotmail.com>", | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
@@ -34,14 +35,14 @@ "files": [ | ||
"dependencies": { | ||
"execa": "^5.1.1", | ||
"find-up": "^5.0.0" | ||
"execa": "^8.0.1", | ||
"find-up": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^0.27.0", | ||
"@antfu/ni": "^0.18.0", | ||
"@types/node": "^16.11.59", | ||
"bumpp": "^8.2.1", | ||
"eslint": "^8.23.1", | ||
"esno": "^0.16.3", | ||
"tsup": "^6.2.3", | ||
"typescript": "^4.8.3" | ||
"@antfu/eslint-config": "^2.0.0", | ||
"@antfu/ni": "^0.21.10", | ||
"@types/node": "^20.9.3", | ||
"bumpp": "^9.2.0", | ||
"eslint": "^8.54.0", | ||
"esno": "^4.0.0", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.2" | ||
}, | ||
@@ -48,0 +49,0 @@ "scripts": { |
@@ -5,3 +5,3 @@ # install-pkg | ||
Install package programmatically. Detect package managers automatically (`npm`, `yarn` and `pnpm`). | ||
Install package programmatically. Detect package managers automatically (`npm`, `yarn`, `bun` and `pnpm`). | ||
@@ -8,0 +8,0 @@ ```bash |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
10952
7
200
Yes
1
+ Addedexeca@8.0.1(transitive)
+ Addedfind-up@7.0.0(transitive)
+ Addedget-stream@8.0.1(transitive)
+ Addedhuman-signals@5.0.0(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedlocate-path@7.2.0(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedp-limit@4.0.0(transitive)
+ Addedp-locate@6.0.0(transitive)
+ Addedpath-exists@5.0.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
+ Addedunicorn-magic@0.1.0(transitive)
+ Addedyocto-queue@1.1.1(transitive)
- Removedexeca@5.1.1(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedhuman-signals@2.1.0(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
- Removedyocto-queue@0.1.0(transitive)
Updatedexeca@^8.0.1
Updatedfind-up@^7.0.0