@@ -3,6 +3,7 @@ import { Path, Package, PackageRequirement, utils, hooks, plumbing, Installation
33const { flatmap, host } = utils
44const { usePantry } = hooks
55const { hydrate } = plumbing
6+ import resolve_pkg from "./resolve-pkg.ts"
67
78export interface Config {
89 pkg : Package
@@ -33,32 +34,7 @@ export interface ConfigPath {
3334}
3435
3536export default async function config ( arg ?: string ) : Promise < Config > {
36- if ( ! arg ) {
37- arg ||= Deno . env . get ( "BREWKIT_PKGJSON" )
38- arg ||= Deno . env . get ( "BREWKIT_PKGSPEC" )
39- arg ||= ( await get_pantry_status ( ) ) ?. [ 0 ]
40- if ( ! arg ) throw new Error ( `usage: ${ Deno . execPath ( ) } <pkgspec>` )
41- }
42-
43- const { pkg, constraint, path } = await ( async ( arg : string ) => {
44- if ( arg . startsWith ( "{" ) ) {
45- const json = JSON . parse ( arg )
46- const project = json . project
47- const version = new SemVer ( json . version . raw )
48- const [ found ] = await usePantry ( ) . find ( project )
49- return {
50- pkg : { project, version} ,
51- constraint : new semver . Range ( `=${ version } ` ) ,
52- path : found . path
53- }
54- } else {
55- const { constraint, project } = utils . pkg . parse ( arg . trim ( ) )
56- const [ found , ...rest ] = await usePantry ( ) . find ( project )
57- if ( rest . length ) throw new Error ( "ambiguous pkg spec" )
58- const pkg = await usePantry ( ) . resolve ( { project : found . project , constraint} )
59- return { constraint, path : found . path , pkg }
60- }
61- } ) ( arg )
37+ const { pkg, path, constraint } = await resolve_pkg ( arg )
6238
6339 let pantry = path
6440 for ( let x = 0 , N = pkg . project . split ( '/' ) . length + 1 ; x < N ; x ++ ) {
0 commit comments