packageNameOf
uses node:module
The package an import names: react/jsx-runtime → react, @scope/pkg/sub → @scope/pkg.
import { builtinModules } from "node:module"; export function packageNameOf(specifier: string): string | undefined { if (/^[./#]/.test(specifier) || specifier.startsWith("node:") || builtinModules.includes(specifier.split("/")[0]!)) return undefined; const parts = specifier.split("/"); return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]; }