Comparing version
@@ -88,6 +88,6 @@ #!/usr/bin/env node | ||
} | ||
function getPackages(positionals) { | ||
function getPackages(positionals, allowEmpty) { | ||
const pkgArgs = positionals.slice(1); | ||
const packages = pkgArgs.map((p) => utils_1.JsrPackage.from(p)); | ||
if (pkgArgs.length === 0) { | ||
if (!allowEmpty && pkgArgs.length === 0) { | ||
console.error(kl.red(`Missing packages argument.`)); | ||
@@ -183,3 +183,3 @@ console.log(); | ||
run(async () => { | ||
const packages = getPackages(options.positionals); | ||
const packages = getPackages(options.positionals, true); | ||
await (0, commands_1.install)(packages, { | ||
@@ -197,3 +197,3 @@ mode: options.values["save-dev"] | ||
run(async () => { | ||
const packages = getPackages(options.positionals); | ||
const packages = getPackages(options.positionals, false); | ||
await (0, commands_1.remove)(packages, { pkgManagerName }); | ||
@@ -200,0 +200,0 @@ }); |
@@ -80,16 +80,18 @@ "use strict"; | ||
async function install(packages, options) { | ||
const pkgManager = await (0, pkg_manager_1.getPkgManager)(process.cwd(), options.pkgManagerName); | ||
if (pkgManager instanceof pkg_manager_1.Bun) { | ||
// Bun doesn't support reading from .npmrc yet | ||
await setupBunfigToml(pkgManager.cwd); | ||
const { pkgManager, root } = await (0, pkg_manager_1.getPkgManager)(process.cwd(), options.pkgManagerName); | ||
if (packages.length > 0) { | ||
if (pkgManager instanceof pkg_manager_1.Bun) { | ||
// Bun doesn't support reading from .npmrc yet | ||
await setupBunfigToml(root); | ||
} | ||
else if (pkgManager instanceof pkg_manager_1.YarnBerry) { | ||
// Yarn v2+ does not read from .npmrc intentionally | ||
// https://yarnpkg.com/migration/guide#update-your-configuration-to-the-new-settings | ||
await pkgManager.setConfigValue(JSR_YARN_BERRY_CONFIG_KEY, JSR_NPM_REGISTRY_URL); | ||
} | ||
else { | ||
await setupNpmRc(root); | ||
} | ||
console.log(`Installing ${kl.cyan(packages.join(", "))}...`); | ||
} | ||
else if (pkgManager instanceof pkg_manager_1.YarnBerry) { | ||
// Yarn v2+ does not read from .npmrc intentionally | ||
// https://yarnpkg.com/migration/guide#update-your-configuration-to-the-new-settings | ||
await pkgManager.setConfigValue(JSR_YARN_BERRY_CONFIG_KEY, JSR_NPM_REGISTRY_URL); | ||
} | ||
else { | ||
await setupNpmRc(pkgManager.cwd); | ||
} | ||
console.log(`Installing ${kl.cyan(packages.join(", "))}...`); | ||
await pkgManager.install(packages, options); | ||
@@ -99,3 +101,3 @@ } | ||
async function remove(packages, options) { | ||
const pkgManager = await (0, pkg_manager_1.getPkgManager)(process.cwd(), options.pkgManagerName); | ||
const { pkgManager } = await (0, pkg_manager_1.getPkgManager)(process.cwd(), options.pkgManagerName); | ||
console.log(`Removing ${kl.cyan(packages.join(", "))}...`); | ||
@@ -147,3 +149,3 @@ await pkgManager.remove(packages); | ||
async function runScript(cwd, script, options) { | ||
const pkgManager = await (0, pkg_manager_1.getPkgManager)(cwd, options.pkgManagerName); | ||
const { pkgManager } = await (0, pkg_manager_1.getPkgManager)(cwd, options.pkgManagerName); | ||
await pkgManager.runScript(script); | ||
@@ -150,0 +152,0 @@ } |
@@ -10,9 +10,2 @@ import { InstallOptions } from "./commands"; | ||
} | ||
declare class Npm implements PackageManager { | ||
cwd: string; | ||
constructor(cwd: string); | ||
install(packages: JsrPackage[], options: InstallOptions): Promise<void>; | ||
remove(packages: JsrPackage[]): Promise<void>; | ||
runScript(script: string): Promise<void>; | ||
} | ||
declare class Yarn implements PackageManager { | ||
@@ -33,9 +26,2 @@ cwd: string; | ||
} | ||
declare class Pnpm implements PackageManager { | ||
cwd: string; | ||
constructor(cwd: string); | ||
install(packages: JsrPackage[], options: InstallOptions): Promise<void>; | ||
remove(packages: JsrPackage[]): Promise<void>; | ||
runScript(script: string): Promise<void>; | ||
} | ||
export declare class Bun implements PackageManager { | ||
@@ -49,3 +35,6 @@ cwd: string; | ||
export type PkgManagerName = "npm" | "yarn" | "pnpm" | "bun"; | ||
export declare function getPkgManager(cwd: string, pkgManagerName: PkgManagerName | null): Promise<Yarn | Pnpm | Bun | Npm>; | ||
export declare function getPkgManager(cwd: string, pkgManagerName: PkgManagerName | null): Promise<{ | ||
root: string; | ||
pkgManager: PackageManager; | ||
}>; | ||
export {}; |
@@ -121,3 +121,3 @@ "use strict"; | ||
async remove(packages) { | ||
await execWithLog("yarn", ["remove", ...packages.map((pkg) => pkg.toString())], this.cwd); | ||
await execWithLog("pnpm", ["remove", ...packages.map((pkg) => pkg.toString())], this.cwd); | ||
} | ||
@@ -167,6 +167,8 @@ async runScript(script) { | ||
: null; | ||
const { projectDir, pkgManagerName: fromLockfile } = await (0, utils_1.findProjectDir)(cwd); | ||
const { projectDir, pkgManagerName: fromLockfile, root } = await (0, utils_1.findProjectDir)(cwd); | ||
const rootPath = root || projectDir; | ||
const result = pkgManagerName || fromEnv || fromLockfile || "npm"; | ||
let pkgManager; | ||
if (result === "yarn") { | ||
return await isYarnBerry(projectDir) | ||
pkgManager = await isYarnBerry(projectDir) | ||
? new YarnBerry(projectDir) | ||
@@ -176,10 +178,13 @@ : new Yarn(projectDir); | ||
else if (result === "pnpm") { | ||
return new Pnpm(projectDir); | ||
pkgManager = new Pnpm(projectDir); | ||
} | ||
else if (result === "bun") { | ||
return new Bun(projectDir); | ||
pkgManager = new Bun(projectDir); | ||
} | ||
return new Npm(projectDir); | ||
else { | ||
pkgManager = new Npm(projectDir); | ||
} | ||
return { root: rootPath, pkgManager }; | ||
} | ||
exports.getPkgManager = getPkgManager; | ||
//# sourceMappingURL=pkg_manager.js.map |
@@ -21,2 +21,3 @@ import { PkgManagerName } from "./pkg_manager"; | ||
pkgJsonPath: string | null; | ||
root: string | null; | ||
} | ||
@@ -37,2 +38,3 @@ export declare function findProjectDir(cwd: string, dir?: string, result?: ProjectInfo): Promise<ProjectInfo>; | ||
license?: string; | ||
workspaces?: string[]; | ||
dependencies?: Record<string, string>; | ||
@@ -39,0 +41,0 @@ devDependencies?: Record<string, string>; |
@@ -74,2 +74,3 @@ "use strict"; | ||
pkgJsonPath: null, | ||
root: null, | ||
}) { | ||
@@ -87,2 +88,15 @@ // Ensure we check for `package.json` first as this defines | ||
} | ||
else { | ||
const pkgJsonPath = path.join(dir, "package.json"); | ||
if (await fileExists(pkgJsonPath)) { | ||
const json = await readJson(pkgJsonPath); | ||
// npm + yarn + bun workspaces | ||
if (Array.isArray(json.workspaces)) { | ||
result.root = dir; | ||
} // pnpm workspaces | ||
else if (await fileExists(path.join(dir, "pnpm-workspace.yaml"))) { | ||
result.root = dir; | ||
} | ||
} | ||
} | ||
const npmLockfile = path.join(dir, "package-lock.json"); | ||
@@ -89,0 +103,0 @@ if (await fileExists(npmLockfile)) { |
{ | ||
"name": "jsr", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"description": "jsr.io package manager for node", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"build": "rimraf dist dist-esm && tsc && tsc -p tsconfig.esm.json", | ||
"prepublishOnly": "tsc" | ||
"prepack": "npm run build" | ||
}, | ||
@@ -26,0 +26,0 @@ "keywords": [ |
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
173668
104.17%45
87.5%2545
111.55%9
80%