Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ COMMANDS:
mcp [install] Start stdio MCP server or 1-click install for Claude Desktop, Cursor, Windsurf
init [--ide] Initialize workspace or generate AI agent guidelines (.cursorrules, CLAUDE.md)
completion <shell> Generate native shell tab auto-completion (bash, zsh, fish, powershell)
which <ecosystem> Show active CLI binary for an ecosystem (npm, jsr, pypi, conda, cargo, go)
which <ecosystem> Show active CLI binary for an ecosystem (npm, jsr, pypi, conda, cargo, go, nuget, composer, gem, pub)

OPTIONS:
-D, --dev Install as a development dependency
Expand Down
2 changes: 1 addition & 1 deletion src/compliance/osv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class OsvClient {
name: pkg.name,
ecosystem: osvEcosystem,
},
version: pkg.version.replace(/^[~^>=<]/, "").trim(),
version: pkg.version.replace(/^[~^>=<\s]+/, "").trim(),
}));

try {
Expand Down
7 changes: 4 additions & 3 deletions src/compliance/sbom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export class SbomGenerator {

const components = packages.map((pkg) => {
const purlEcosystem = engineRegistry.getSbomPurlType(pkg.ecosystem);
const cleanVer = pkg.version.replace(/^[~^>=<\s]+/, "");
return {
type: "library",
name: pkg.packageName,
version: pkg.version.replace(/^[~^>=<]/, ""),
purl: `pkg:${purlEcosystem}/${pkg.packageName}@${pkg.version.replace(/^[~^>=<]/, "")}`,
version: cleanVer,
purl: `pkg:${purlEcosystem}/${pkg.packageName}@${cleanVer}`,
licenses: [
{
license: {
Expand Down Expand Up @@ -93,7 +94,7 @@ export class SbomGenerator {
return {
name: pkg.packageName,
SPDXID: `SPDXRef-Package-${safeId}-${idx}`,
versionInfo: pkg.version.replace(/^[~^>=<]/, ""),
versionInfo: pkg.version.replace(/^[~^>=<\s]+/, ""),
downloadLocation: "NOASSERTION",
filesAnalyzed: false,
licenseConcluded: pkg.license,
Expand Down
55 changes: 55 additions & 0 deletions src/doctor/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class PolyDoctor {
this.checkPythonToolchain(checks);
this.checkRustToolchain(checks);
this.checkGoToolchain(checks);
this.checkBackendAndMobileToolchains(checks);

// 2. Build Environment
this.checkBuildEnvironment(checks);
Expand Down Expand Up @@ -233,6 +234,60 @@ export class PolyDoctor {
}
}

private checkBackendAndMobileToolchains(checks: DiagnosticCheckItem[]): void {
const toolchains: Array<{
id: string;
name: string;
cmd: string;
args: string[];
hint: string;
}> = [
{
id: "toolchain-dotnet",
name: ".NET / NuGet CLI",
cmd: "dotnet",
args: ["--version"],
hint: "https://dotnet.microsoft.com",
},
{
id: "toolchain-composer",
name: "PHP Composer",
cmd: "composer",
args: ["--version"],
hint: "https://getcomposer.org",
},
{
id: "toolchain-bundler",
name: "Ruby Bundler",
cmd: "bundle",
args: ["--version"],
hint: "https://bundler.io",
},
{
id: "toolchain-dart",
name: "Dart / Flutter Pub",
cmd: "dart",
args: ["--version"],
hint: "https://dart.dev/get-dart",
},
];

for (const tc of toolchains) {
const res = this.runCommandSafe(tc.cmd, tc.args);
if (res.available) {
const ver = res.output.trim().split(/\r?\n/)[0].trim();
checks.push({
id: tc.id,
name: tc.name,
category: "Toolchain",
status: "OK",
version: ver,
message: `${ver} active`,
});
}
}
}

private checkBuildEnvironment(checks: DiagnosticCheckItem[]): void {
const hasGcc = this.runCommandSafe("gcc", ["--version"]).available;
const hasClang = this.runCommandSafe("clang", ["--version"]).available;
Expand Down
219 changes: 219 additions & 0 deletions src/engines/backend-mobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import fs from "node:fs";
import path from "node:path";
import type { EngineContext, PackageSpec } from "../types.js";
import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js";

function isFlutterProject(ctx?: EngineContext): boolean {
if (ctx?.preferredCli === "flutter") return true;
if (ctx?.cwd) {
const pubspec = path.join(ctx.cwd, ctx.manifest || "pubspec.yaml");
if (fs.existsSync(pubspec)) {
try {
const content = fs.readFileSync(pubspec, "utf-8");
if (/(?:sdk:\s*flutter|^\s*flutter:\s*$)/m.test(content)) {
return true;
}
} catch {
// Ignore read failure and fall back to dart
}
}
}
return false;
}

function isPaketProject(ctx?: EngineContext): boolean {
return (
ctx?.preferredCli === "paket" ||
ctx?.manifest === "paket.dependencies" ||
ctx?.lockfile === "paket.lock"
);
}

function isGemCliProject(ctx?: EngineContext): boolean {
if (ctx?.preferredCli === "gem") return true;
if (ctx?.manifest?.endsWith(".gemspec") && ctx?.cwd) {
return !fs.existsSync(path.join(ctx.cwd, "Gemfile"));
}
return false;
}

function isPearProject(ctx?: EngineContext): boolean {
return ctx?.preferredCli === "pear" || ctx?.manifest === "package.xml";
}

function isProjectXmlManifest(manifest?: string): manifest is string {
return Boolean(manifest && /\.(cs|fs|vb)proj$/i.test(manifest));
}

function formatScopedName(pkg: PackageSpec): string {
return pkg.namespace ? `${pkg.namespace}/${pkg.name}` : pkg.name;
}

/** C# / .NET — NuGet (dotnet CLI) & Paket */
export const nugetAdapter: EngineAdapter = defineDeclarativeAdapter({
id: "dotnet",
ecosystem: "nuget",
aliases: ["dotnet", "csharp", "paket"],
purlTypes: ["nuget"],
manifests: ["*.csproj", "*.fsproj", "*.vbproj", "paket.dependencies"],
lockfiles: ["packages.lock.json", "paket.lock"],
osvEcosystem: "NuGet",
sbomPurlType: "nuget",
supportedClis: ["dotnet", "paket"],
commands: {
command: (ctx) => (isPaketProject(ctx) ? "paket" : "dotnet"),
add: (pkg, ctx) => {
const cleanVer = pkg.version?.replace(/^[~^>=<]+/, "");
if (isPaketProject(ctx)) {
return ["add", pkg.name, ...(cleanVer ? ["--version", cleanVer] : [])];
}
const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : [];
return [
"add",
...targetProj,
"package",
pkg.name,
...(cleanVer ? ["--version", cleanVer] : []),
];
},
remove: (pkg, ctx) => {
if (isPaketProject(ctx)) {
return ["remove", pkg.name];
}
const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : [];
return ["remove", ...targetProj, "package", pkg.name];
},
install: (ctx) => (isPaketProject(ctx) ? ["install"] : ["restore"]),
update: (pkg, ctx) => {
if (isPaketProject(ctx)) {
return pkg ? ["update", pkg.name] : ["update"];
}
const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : [];
return pkg ? ["add", ...targetProj, "package", pkg.name] : ["restore", "--force"];
},
},
resolveScriptCommand: (script) => {
if (script === "test") return ["dotnet", ["test"]];
if (script === "build") return ["dotnet", ["build"]];
return ["dotnet", ["run"]];
},
injectRegistryEnv: (endpoint, env) => {
env.NUGET_SOURCE = endpoint.url;
},
injectRegistryFlags: (endpoint, args) => {
if ((args[0] === "add" || args[0] === "restore") && !args.includes("--source")) {
args.push("--source", endpoint.url);
}
},
});

/** PHP — Composer (Packagist) & legacy PEAR fallback */
export const composerAdapter: EngineAdapter = defineDeclarativeAdapter({
id: "composer",
ecosystem: "composer",
aliases: ["php", "packagist", "pear"],
purlTypes: ["composer"],
manifests: ["composer.json", "package.xml"],
lockfiles: ["composer.lock"],
osvEcosystem: "Packagist",
sbomPurlType: "composer",
supportedClis: ["composer", "pear"],
commands: {
command: (ctx) => (isPearProject(ctx) ? "pear" : "composer"),
add: (pkg, ctx) => {
const fullName = formatScopedName(pkg);
if (isPearProject(ctx)) {
return ["install", pkg.version ? `${fullName}-${pkg.version}` : fullName];
}
const target = pkg.version ? `${fullName}:${pkg.version}` : fullName;
return ["require", target, ...(pkg.isDev ? ["--dev"] : [])];
},
remove: (pkg, ctx) => {
const fullName = formatScopedName(pkg);
if (isPearProject(ctx)) {
return ["uninstall", fullName];
}
return ["remove", fullName, ...(pkg.isDev ? ["--dev"] : [])];
},
install: (ctx) => (isPearProject(ctx) ? ["install", "package.xml"] : ["install"]),
update: (pkg, ctx) => {
const fullName = pkg ? formatScopedName(pkg) : undefined;
if (isPearProject(ctx)) {
return fullName ? ["upgrade", fullName] : ["upgrade"];
}
return fullName ? ["update", fullName] : ["update"];
},
},
resolveScriptCommand: (script) => ["composer", [script]],
injectRegistryEnv: (endpoint, env) => {
env.COMPOSER_MIRROR_URL = endpoint.url;
},
});

/** Ruby — Bundler / RubyGems */
export const gemAdapter: EngineAdapter = defineDeclarativeAdapter({
id: "bundler",
ecosystem: "gem",
aliases: ["ruby", "bundler", "rubygems"],
purlTypes: ["gem"],
manifests: ["Gemfile", "*.gemspec"],
lockfiles: ["Gemfile.lock"],
osvEcosystem: "RubyGems",
sbomPurlType: "gem",
supportedClis: ["bundle", "gem"],
commands: {
command: (ctx) => (isGemCliProject(ctx) ? "gem" : "bundle"),
add: (pkg, ctx) => {
if (isGemCliProject(ctx)) {
return ["install", pkg.name, ...(pkg.version ? ["-v", pkg.version] : [])];
}
const args = ["add", pkg.name];
if (pkg.version) args.push("--version", pkg.version);
if (pkg.isDev) args.push("--group", "development");
return args;
},
remove: (pkg, ctx) =>
isGemCliProject(ctx) ? ["uninstall", "-x", pkg.name] : ["remove", pkg.name],
install: () => ["install"],
update: (pkg) => (pkg ? ["update", pkg.name] : ["update"]),
},
resolveScriptCommand: (script) => ["bundle", ["exec", script]],
injectRegistryEnv: (endpoint, env) => {
env.BUNDLE_MIRROR__ALL = endpoint.url;
},
});

/** Dart / Flutter — Pub */
export const pubAdapter: EngineAdapter = defineDeclarativeAdapter({
id: "pub",
ecosystem: "pub",
aliases: ["dart", "flutter"],
purlTypes: ["pub"],
manifests: ["pubspec.yaml"],
lockfiles: ["pubspec.lock"],
osvEcosystem: "Pub",
sbomPurlType: "pub",
supportedClis: ["dart", "flutter"],
commands: {
command: (ctx) => (isFlutterProject(ctx) ? "flutter" : "dart"),
add: (pkg) => {
const target = pkg.version ? `${pkg.name}:${pkg.version}` : pkg.name;
return ["pub", "add", pkg.isDev ? `dev:${target}` : target];
},
remove: (pkg) => ["pub", "remove", pkg.name],
install: () => ["pub", "get"],
update: (pkg) => (pkg ? ["pub", "upgrade", pkg.name] : ["pub", "upgrade"]),
},
resolveScriptCommand: (script, ctx) =>
isFlutterProject(ctx) ? ["flutter", [script]] : ["dart", [script]],
injectRegistryEnv: (endpoint, env) => {
env.PUB_HOSTED_URL = endpoint.url;
},
});

export const BACKEND_MOBILE_ADAPTERS: readonly EngineAdapter[] = [
nugetAdapter,
composerAdapter,
gemAdapter,
pubAdapter,
];
7 changes: 7 additions & 0 deletions src/engines/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export { BaseEngine } from "./base.js";
export {
BACKEND_MOBILE_ADAPTERS,
composerAdapter,
gemAdapter,
nugetAdapter,
pubAdapter,
} from "./backend-mobile.js";
export {
DeclarativeEngine,
defineDeclarativeAdapter,
Expand Down
6 changes: 5 additions & 1 deletion src/engines/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import type { Ecosystem, EngineContext, PackageSpec } from "../types.js";
import type { Ecosystem, EngineContext } from "../types.js";
import { BACKEND_MOBILE_ADAPTERS } from "./backend-mobile.js";
import type { BaseEngine } from "./base.js";
import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js";
import { GoEngine } from "./go.js";
Expand Down Expand Up @@ -286,6 +287,9 @@ engineRegistry.register(pypiAdapter);
engineRegistry.register(condaAdapter);
engineRegistry.register(cargoAdapter);
engineRegistry.register(goAdapter);
for (const adapter of BACKEND_MOBILE_ADAPTERS) {
engineRegistry.register(adapter);
}

/** Ensures a PackageSpec target cleanly detects its first existing manifest file in cwd if missing. */
export function resolveEcosystemLockContext(ecosystem: Ecosystem, cwd: string): EngineContext {
Expand Down
Loading
Loading