package-manager-manager
Advanced tools
Comparing version 0.1.3-69fef32 to 0.1.3-f6ce4f4
@@ -1,3 +0,9 @@ | ||
import type { PackageManager } from '../packageManager'; | ||
import type { PackageManager, PackageManagerMetadata } from '../packageManager'; | ||
import type { CommandExecStruct } from './CommandStruct'; | ||
/** | ||
* The subset of properties of PackageManager that are relevant when dealing with exec commands | ||
*/ | ||
type PackageManagerForExec = Pick<PackageManager, 'name' | 'version' | 'getPackageInfo'> & { | ||
metadata: Pick<PackageManagerMetadata, 'isYarnClassic'>; | ||
}; | ||
export type GetRunExecOptions = { | ||
@@ -30,3 +36,3 @@ /** | ||
export type GetRunExecStruct = (command: string, options?: Partial<GetRunExecOptions>) => Promise<CommandExecStruct | null>; | ||
export declare function getRunExecFunctions(packageManager: Pick<PackageManager, 'name' | 'version' | 'getPackageInfo'>): { | ||
export declare function getRunExecFunctions(packageManager: PackageManagerForExec): { | ||
getRunExec: GetRunExec; | ||
@@ -33,0 +39,0 @@ getRunExecStruct: GetRunExecStruct; |
@@ -1,32 +0,25 @@ | ||
var b = (r, e, s) => { | ||
var y = (r, e, t) => { | ||
if (!e.has(r)) | ||
throw TypeError("Cannot " + s); | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var u = (r, e, s) => { | ||
var u = (r, e, t) => { | ||
if (e.has(r)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
e instanceof WeakSet ? e.add(r) : e.set(r, s); | ||
e instanceof WeakSet ? e.add(r) : e.set(r, t); | ||
}; | ||
var l = (r, e, s) => (b(r, e, "access private method"), s); | ||
import "node:fs/promises"; | ||
import "node:path"; | ||
import "node:process"; | ||
import "../utils/locks.js"; | ||
import { isYarnClassic as x } from "../utils/yarn.js"; | ||
import "../utils/shellac.js"; | ||
import "shellac"; | ||
var i, f, n, o; | ||
const h = class { | ||
constructor(e, s, t) { | ||
this.pkgCmd = s, this.pmCmd = void 0, this.targetArgs = (t == null ? void 0 : t.args) ?? []; | ||
const c = (t == null ? void 0 : t.format) ?? "short", m = (t == null ? void 0 : t.download) ?? "prefer-always"; | ||
this.cmd = e.name, this.structIsReady = new Promise((a) => { | ||
var l = (r, e, t) => (y(r, e, "access private method"), t); | ||
var n, f, a, w; | ||
const i = class { | ||
constructor(e, t, s) { | ||
this.pkgCmd = t, this.pmCmd = void 0, this.targetArgs = (s == null ? void 0 : s.args) ?? []; | ||
const d = (s == null ? void 0 : s.format) ?? "short", m = (s == null ? void 0 : s.download) ?? "prefer-always"; | ||
this.cmd = e.name, this.structIsReady = new Promise((h) => { | ||
var g; | ||
l(g = h, i, f).call(g, e, s, c, m).then( | ||
({ cmd: w, pmCmd: C }) => { | ||
var p; | ||
this.cmd = w, this.pmCmd = C, ["yarn", "pnpm"].includes(e.name) && C === "exec" && (this.pkgCmd = l(p = h, n, o).call(p, this.pkgCmd)), e.name === "npm" && this.pmCmd === "exec" && (this.argsNeedDoubleDashes = !0), a(); | ||
l(g = i, n, f).call(g, e, t, d, m).then( | ||
({ cmd: b, pmCmd: C }) => { | ||
var x; | ||
this.cmd = b, this.pmCmd = C, ["yarn", "pnpm"].includes(e.name) && C === "exec" && (this.pkgCmd = l(x = i, a, w).call(x, this.pkgCmd)), e.name === "npm" && this.pmCmd === "exec" && (this.argsNeedDoubleDashes = !0), h(); | ||
} | ||
); | ||
}), this.argsNeedDoubleDashes = x(e); | ||
}), this.argsNeedDoubleDashes = e.metadata.isYarnClassic; | ||
} | ||
@@ -45,11 +38,11 @@ get cmdArgs() { | ||
}; | ||
let d = h; | ||
i = new WeakSet(), f = async function(e, s, t, c) { | ||
let c = i; | ||
n = new WeakSet(), f = async function(e, t, s, d) { | ||
switch (e.name) { | ||
case "bun": | ||
return t === "short" ? { cmd: "bunx" } : { cmd: "bun", pmCmd: "x" }; | ||
return s === "short" ? { cmd: "bunx" } : { cmd: "bun", pmCmd: "x" }; | ||
case "npm": | ||
return t === "short" ? { cmd: "npx" } : { cmd: "npm", pmCmd: "exec" }; | ||
return s === "short" ? { cmd: "npx" } : { cmd: "npm", pmCmd: "exec" }; | ||
case "yarn": | ||
if (x(e)) | ||
if (e.metadata.isYarnClassic) | ||
return { cmd: "yarn", pmCmd: "exec" }; | ||
@@ -59,3 +52,3 @@ break; | ||
const m = { cmd: e.name }; | ||
switch (c) { | ||
switch (d) { | ||
case "prefer-always": | ||
@@ -68,4 +61,4 @@ m.pmCmd = "dlx"; | ||
case "prefer-if-needed": { | ||
const a = await e.getPackageInfo(s); | ||
m.pmCmd = a ? "exec" : "dlx"; | ||
const h = await e.getPackageInfo(t); | ||
m.pmCmd = h ? "exec" : "dlx"; | ||
break; | ||
@@ -75,6 +68,6 @@ } | ||
return m; | ||
}, n = new WeakSet(), o = function(e) { | ||
const s = e.match(/^@[^/]+\/(.*)/); | ||
return (s == null ? void 0 : s[1]) ?? e; | ||
}, u(d, i), /** | ||
}, a = new WeakSet(), w = function(e) { | ||
const t = e.match(/^@[^/]+\/(.*)/); | ||
return (t == null ? void 0 : t[1]) ?? e; | ||
}, u(c, n), /** | ||
* Unscopes a given command, for example it converts "@org/my-cmd" to "my-cmd" | ||
@@ -86,18 +79,18 @@ * (already non scoped commands are left untouched) | ||
*/ | ||
u(d, n); | ||
function R(r) { | ||
const e = async (t, c) => { | ||
if (!t) | ||
u(c, a); | ||
function $(r) { | ||
const e = async (s, d) => { | ||
if (!s) | ||
return null; | ||
const m = new d(r, t, c); | ||
const m = new c(r, s, d); | ||
return await m.structIsReady, m; | ||
}; | ||
return { getRunExec: async (...t) => { | ||
var c; | ||
return ((c = await e(...t)) == null ? void 0 : c.toString()) ?? null; | ||
return { getRunExec: async (...s) => { | ||
var d; | ||
return ((d = await e(...s)) == null ? void 0 : d.toString()) ?? null; | ||
}, getRunExecStruct: e }; | ||
} | ||
export { | ||
R as getRunExecFunctions | ||
$ as getRunExecFunctions | ||
}; | ||
//# sourceMappingURL=getRunExec.js.map |
import type { PackageManager } from '../packageManager'; | ||
import type { CommandScriptStruct } from './CommandStruct'; | ||
/** | ||
* The subset of properties of PackageManager that are relevant when dealing with scripts | ||
*/ | ||
type PackageManagerForScripts = Pick<PackageManager, 'name' | 'cliCommandKeywords'>; | ||
export type GetRunScriptOptions = { | ||
@@ -21,6 +25,7 @@ /** | ||
export type GetRunScriptStruct = (script: string, options?: Partial<GetRunScriptOptions>) => Promise<CommandScriptStruct | null>; | ||
export declare function getRunScriptFunctions(packageManager: Pick<PackageManager, 'name' | 'cliCommandKeywords'>): { | ||
export declare function getRunScriptFunctions(packageManager: PackageManagerForScripts): { | ||
getRunScript: GetRunScript; | ||
getRunScriptStruct: GetRunScriptStruct; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=getRunScript.d.ts.map |
@@ -1,14 +0,7 @@ | ||
import { getRunScriptFunctions as u } from "./getRunScript.js"; | ||
import { getRunExecFunctions as f } from "./getRunExec.js"; | ||
import "node:fs/promises"; | ||
import "node:path"; | ||
import "node:process"; | ||
import "../utils/locks.js"; | ||
import "../utils/yarn.js"; | ||
import "../utils/shellac.js"; | ||
import "shellac"; | ||
import { getRunScriptFunctions as o } from "./getRunScript.js"; | ||
import { getRunExecFunctions as r } from "./getRunExec.js"; | ||
export { | ||
f as getRunExecFunctions, | ||
u as getRunScriptFunctions | ||
r as getRunExecFunctions, | ||
o as getRunScriptFunctions | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,6 @@ | ||
import { getPackageManager as j } from "./packageManager.js"; | ||
import { getPackageManager as h } from "./packageManager.js"; | ||
import "./commands/getRunScript.js"; | ||
import "./commands/getRunExec.js"; | ||
import "./package/index.js"; | ||
import "./package/bun.js"; | ||
import "node:fs/promises"; | ||
@@ -8,7 +10,4 @@ import "node:path"; | ||
import "./utils/locks.js"; | ||
import "./utils/yarn.js"; | ||
import "./utils/shellac.js"; | ||
import "shellac"; | ||
import "./package/index.js"; | ||
import "./package/bun.js"; | ||
import "./package/npm.js"; | ||
@@ -21,4 +20,4 @@ import "./package/pnpm.js"; | ||
export { | ||
j as getPackageManager | ||
h as getPackageManager | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "package-manager-manager", | ||
"version": "0.1.3-69fef32", | ||
"version": "0.1.3-f6ce4f4", | ||
"description": "Utilities for managing package managers.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,8 @@ | ||
import type { PackageManager } from '../packageManager'; | ||
import type { PackageManager, PackageManagerMetadata } from '../packageManager'; | ||
/** | ||
* The subset of properties of PackageManager that are relevant when dealing with packages | ||
*/ | ||
type PackageManagerForPackages = Pick<PackageManager, 'name' | 'version'> & { | ||
metadata: Pick<PackageManagerMetadata, 'isYarnClassic'>; | ||
}; | ||
export type PackageInfo = { | ||
@@ -15,3 +21,4 @@ /** The name of the package */ | ||
*/ | ||
export declare function getPackageInfoFunction(packageManager: Pick<PackageManager, 'name' | 'version'>): GetPackageInfo; | ||
export declare function getPackageInfoFunction(packageManager: PackageManagerForPackages): GetPackageInfo; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
import { getBunGetPackageInfoFunction as n } from "./bun.js"; | ||
import { getNpmGetPackageInfoFunction as o } from "./npm.js"; | ||
import { getPnpmGetPackageInfoFunction as r } from "./pnpm.js"; | ||
import { getYarnGetPackageInfoFunction as e } from "./yarn.js"; | ||
import { getNpmGetPackageInfoFunction as e } from "./npm.js"; | ||
import { getPnpmGetPackageInfoFunction as o } from "./pnpm.js"; | ||
import { getYarnGetPackageInfoFunction as r } from "./yarn.js"; | ||
import "node:fs/promises"; | ||
@@ -11,11 +11,10 @@ import "node:path"; | ||
import "shellac"; | ||
import "../utils/yarn.js"; | ||
function I(t) { | ||
function F(t) { | ||
switch (t.name) { | ||
case "npm": | ||
return e(); | ||
case "pnpm": | ||
return o(); | ||
case "pnpm": | ||
return r(); | ||
case "yarn": | ||
return e(t); | ||
return r(t); | ||
case "bun": | ||
@@ -28,4 +27,4 @@ return n(); | ||
export { | ||
I as getPackageInfoFunction | ||
F as getPackageInfoFunction | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,6 @@ | ||
import type { PackageManager } from '../packageManager'; | ||
import type { PackageManager, PackageManagerMetadata } from '../packageManager'; | ||
import type { GetPackageInfo } from './index'; | ||
export declare function getYarnGetPackageInfoFunction(packageManager: Pick<PackageManager, 'name' | 'version'>): (packageName: string) => ReturnType<GetPackageInfo>; | ||
export declare function getYarnGetPackageInfoFunction(packageManager: Pick<PackageManager, 'name' | 'version'> & { | ||
metadata: Pick<PackageManagerMetadata, 'isYarnClassic'>; | ||
}): (packageName: string) => ReturnType<GetPackageInfo>; | ||
//# sourceMappingURL=yarn.d.ts.map |
@@ -5,10 +5,9 @@ import "node:fs/promises"; | ||
import "../utils/locks.js"; | ||
import { isYarnClassic as c } from "../utils/yarn.js"; | ||
import { shellac as i } from "../utils/shellac.js"; | ||
import "shellac"; | ||
function w(s) { | ||
function m(s) { | ||
return async (...[r]) => { | ||
try { | ||
let o; | ||
if (c(s)) { | ||
if (s.metadata.isYarnClassic) { | ||
const n = (await i`$ yarn list pattern ${r}`).stdout, e = new RegExp(`^[└─\\s]*${r}@(\\S*)`, "im"), t = n.match(e); | ||
@@ -27,4 +26,4 @@ o = t == null ? void 0 : t[1]; | ||
export { | ||
w as getYarnGetPackageInfoFunction | ||
m as getYarnGetPackageInfoFunction | ||
}; | ||
//# sourceMappingURL=yarn.js.map |
@@ -63,3 +63,17 @@ import type { GetRunExec, GetRunExecStruct, GetRunScript, GetRunScriptStruct } from './commands'; | ||
cliCommandKeywords: Set<string>; | ||
/** | ||
* Set of metadata associated to the package manager. | ||
*/ | ||
metadata: PackageManagerMetadata; | ||
}; | ||
export type PackageManagerMetadata = { | ||
/** | ||
* Flag indicating whether the package manager is yarn classic (meaning that it is yarn and its version is less than 2) | ||
*/ | ||
isYarnClassic: boolean; | ||
/** | ||
* Flag indicating whether the package manager is yarn berry (meaning that it is yarn and its version greater than 2) | ||
*/ | ||
isYarnBerry: boolean; | ||
}; | ||
/** | ||
@@ -66,0 +80,0 @@ * Gets the current package manager information based on the current directory |
import { getRunScriptFunctions as u } from "./commands/getRunScript.js"; | ||
import { getRunExecFunctions as m } from "./commands/getRunExec.js"; | ||
import { getPackageInfoFunction as p } from "./package/index.js"; | ||
import { getRunExecFunctions as p } from "./commands/getRunExec.js"; | ||
import { getPackageInfoFunction as l } from "./package/index.js"; | ||
import "node:fs/promises"; | ||
@@ -8,8 +8,7 @@ import "node:path"; | ||
import "./utils/locks.js"; | ||
import { getPmCliCommandKeywords as s } from "./utils/cliCommands.js"; | ||
import { detectPackageManagerName as l } from "./utils/pmDetection.js"; | ||
import { shellac as R } from "./utils/shellac.js"; | ||
import "./utils/yarn.js"; | ||
import { getPmCliCommandKeywords as y } from "./utils/cliCommands.js"; | ||
import { detectPackageManagerName as R } from "./utils/pmDetection.js"; | ||
import { shellac as S } from "./utils/shellac.js"; | ||
import "./package/bun.js"; | ||
import "shellac"; | ||
import "./package/bun.js"; | ||
import "./package/npm.js"; | ||
@@ -19,13 +18,17 @@ import "./package/pnpm.js"; | ||
import "./utils/workspace.js"; | ||
async function S(e) { | ||
const { stdout: n } = await R`$ ${e} --version`; | ||
return n; | ||
async function f(n) { | ||
const { stdout: e } = await S`$ ${n} --version`; | ||
return e; | ||
} | ||
async function j() { | ||
const { packageManagerName: e, filesBasedPackageManager: n } = await l(); | ||
if (e) { | ||
const a = e, r = await S(e), t = { | ||
name: e, | ||
version: r, | ||
projectPackageManager: n, | ||
async function W() { | ||
const { packageManagerName: n, filesBasedPackageManager: e } = await R(); | ||
if (n) { | ||
const r = n, a = await f(n), c = a.startsWith("0.") || a.startsWith("1."), o = r === "yarn" && c, t = { | ||
name: n, | ||
version: a, | ||
projectPackageManager: e, | ||
metadata: { | ||
isYarnClassic: o, | ||
isYarnBerry: r === "yarn" && !c | ||
}, | ||
// initialization of dummy fields which get populated in the next steps | ||
@@ -39,5 +42,9 @@ cliCommandKeywords: /* @__PURE__ */ new Set(), | ||
}; | ||
t.cliCommandKeywords = s(t), t.getPackageInfo = p({ name: a, version: r }); | ||
const { getRunScript: c, getRunScriptStruct: o } = u(t), { getRunExec: i, getRunExecStruct: g } = m(t); | ||
return t.getRunScript = c, t.getRunScriptStruct = o, t.getRunExec = i, t.getRunExecStruct = g, t; | ||
t.cliCommandKeywords = y(t), t.getPackageInfo = l({ | ||
name: r, | ||
version: a, | ||
metadata: { isYarnClassic: o } | ||
}); | ||
const { getRunScript: i, getRunScriptStruct: s } = u(t), { getRunExec: g, getRunExecStruct: m } = p(t); | ||
return t.getRunScript = i, t.getRunScriptStruct = s, t.getRunExec = g, t.getRunExecStruct = m, t; | ||
} | ||
@@ -47,4 +54,4 @@ return null; | ||
export { | ||
j as getPackageManager | ||
W as getPackageManager | ||
}; | ||
//# sourceMappingURL=packageManager.js.map |
@@ -1,2 +0,2 @@ | ||
import type { PackageManager } from 'src/packageManager'; | ||
import type { PackageManager, PackageManagerMetadata } from '../packageManager'; | ||
/** | ||
@@ -14,3 +14,5 @@ * Gets the set of all CLI command keywords available for the provided package manager | ||
*/ | ||
export declare function getPmCliCommandKeywords(packageManager: Pick<PackageManager, 'name' | 'version'>): Readonly<Set<string>>; | ||
export declare function getPmCliCommandKeywords(packageManager: Pick<PackageManager, 'name' | 'version'> & { | ||
metadata: Pick<PackageManagerMetadata, 'isYarnClassic'>; | ||
}): Readonly<Set<string>>; | ||
//# sourceMappingURL=cliCommands.d.ts.map |
@@ -1,3 +0,2 @@ | ||
import { isYarnClassic as n } from "./yarn.js"; | ||
const i = [ | ||
const n = [ | ||
"access", | ||
@@ -67,3 +66,3 @@ "adduser", | ||
"whoami" | ||
], o = [ | ||
], i = [ | ||
"add", | ||
@@ -111,3 +110,3 @@ "audit", | ||
"workspaces" | ||
], s = [ | ||
], o = [ | ||
"add", | ||
@@ -140,3 +139,3 @@ "bin", | ||
"why" | ||
], r = [ | ||
], s = [ | ||
"add", | ||
@@ -180,14 +179,14 @@ "audit", | ||
"why" | ||
], l = ["add", "install", "link", "pm", "remove", "run", "test", "x"]; | ||
function d(e) { | ||
], a = ["add", "install", "link", "pm", "remove", "run", "test", "x"]; | ||
function r(e) { | ||
let t = []; | ||
return e.name !== "yarn" ? t = { | ||
npm: i, | ||
pnpm: r, | ||
bun: l | ||
}[e.name] : t = n(e) ? o : s, new Set(t); | ||
npm: n, | ||
pnpm: s, | ||
bun: a | ||
}[e.name] : t = e.metadata.isYarnClassic ? i : o, new Set(t); | ||
} | ||
export { | ||
d as getPmCliCommandKeywords | ||
r as getPmCliCommandKeywords | ||
}; | ||
//# sourceMappingURL=cliCommands.js.map |
export * from './os'; | ||
export * from './workspace'; | ||
export * from './locks'; | ||
export * from './yarn'; | ||
export * from './cliCommands'; | ||
@@ -6,0 +5,0 @@ export * from './pmDetection'; |
import { isWindows as i } from "./os.js"; | ||
import { getProjectRootDir as c } from "./workspace.js"; | ||
import { isLockFile as g, lockFiles as n } from "./locks.js"; | ||
import { isYarnClassic as l } from "./yarn.js"; | ||
import { getPmCliCommandKeywords as x } from "./cliCommands.js"; | ||
import { detectPackageManagerBasedOnFiles as P, detectPackageManagerBasedOnUserAgent as C, detectPackageManagerName as F } from "./pmDetection.js"; | ||
import { shellac as w } from "./shellac.js"; | ||
import { getProjectRootDir as p } from "./workspace.js"; | ||
import { isLockFile as g, lockFiles as d } from "./locks.js"; | ||
import { getPmCliCommandKeywords as l } from "./cliCommands.js"; | ||
import { detectPackageManagerBasedOnFiles as x, detectPackageManagerBasedOnUserAgent as k, detectPackageManagerName as P } from "./pmDetection.js"; | ||
import { shellac as M } from "./shellac.js"; | ||
import "node:fs/promises"; | ||
@@ -13,13 +12,12 @@ import "node:path"; | ||
export { | ||
P as detectPackageManagerBasedOnFiles, | ||
C as detectPackageManagerBasedOnUserAgent, | ||
F as detectPackageManagerName, | ||
x as getPmCliCommandKeywords, | ||
c as getProjectRootDir, | ||
x as detectPackageManagerBasedOnFiles, | ||
k as detectPackageManagerBasedOnUserAgent, | ||
P as detectPackageManagerName, | ||
l as getPmCliCommandKeywords, | ||
p as getProjectRootDir, | ||
g as isLockFile, | ||
i as isWindows, | ||
l as isYarnClassic, | ||
n as lockFiles, | ||
w as shellac | ||
d as lockFiles, | ||
M as shellac | ||
}; | ||
//# sourceMappingURL=index.js.map |
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
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
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
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
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
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
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
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
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
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
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
142629
1044
11
111