@@ -53,10 +53,12 @@ export type DetectOptions = {
5353export type DetectResult = Readonly < {
5454 agent : AgentPlusBun
5555 agentVersion : string | undefined
56+ isPrivate : boolean
57+ isWorkspace : boolean
5658 lockPath : string | undefined
5759 lockSrc : string | undefined
5860 pkgJson : PackageJSONObject | undefined
59- pkgPath : string | undefined
61+ pkgJsonPath : string | undefined
6062 pkgJsonStr : string | undefined
6163 supported : boolean
6264 targets : {
@@ -104,14 +106,14 @@ export async function detect({
104106 const lockPath = await findUp ( Object . keys ( LOCKS ) , { cwd } )
105107 const isHiddenLockFile = lockPath ?. endsWith ( '.package-lock.json' ) ?? false
106108
107- const pkgPath = lockPath
109+ const pkgJsonPath = lockPath
108110 ? path . resolve ( lockPath , `${ isHiddenLockFile ? '../' : '' } ../package.json` )
109111 : await findUp ( 'package.json' , { cwd } )
110112
111113 // Read Corepack `packageManager` field in package.json:
112114 // https://nodejs.org/api/packages.html#packagemanager
113- const pkgJsonStr = existsSync ( pkgPath )
114- ? await readFileUtf8 ( pkgPath )
115+ const pkgJsonStr = existsSync ( pkgJsonPath )
116+ ? await readFileUtf8 ( pkgJsonPath )
115117 : undefined
116118
117119 const pkgJson =
@@ -128,12 +130,14 @@ export async function detect({
128130 let agent : AgentPlusBun | undefined
129131 let agentVersion : string | undefined
130132 if ( pkgManager ) {
131- const parts = pkgManager . split ( '@' )
132- const name = < AgentPlusBun > parts [ 0 ]
133- const maybeVersion = parts . length > 1 ? parts [ 1 ] : undefined
134- if ( maybeVersion && AGENTS . includes ( name ) ) {
135- agent = name
136- agentVersion = maybeVersion
133+ const atSignIndex = pkgManager . lastIndexOf ( '@' )
134+ if ( atSignIndex !== - 1 ) {
135+ const name = < AgentPlusBun > pkgManager . slice ( 0 , atSignIndex )
136+ const version = pkgManager . slice ( atSignIndex + 1 )
137+ if ( version && AGENTS . includes ( name ) ) {
138+ agent = name
139+ agentVersion = version
140+ }
137141 }
138142 }
139143 if (
@@ -154,7 +158,16 @@ export async function detect({
154158 node : true
155159 }
156160
161+ let isPrivate = false
162+ let isWorkspace = false
157163 if ( pkgJson ) {
164+ const pkgPath = path . dirname ( pkgJsonPath ! )
165+ isPrivate = ! ! pkgJson [ 'private' ]
166+ isWorkspace =
167+ ! ! pkgJson [ 'workspaces' ] ||
168+ ( agent === 'pnpm' &&
169+ existsSync ( path . join ( pkgPath , 'pnpm-workspace.yaml' ) ) )
170+
158171 let browser : boolean | undefined
159172 let node : boolean | undefined
160173 const browserField = getOwn ( pkgJson , 'browser' )
@@ -195,10 +208,12 @@ export async function detect({
195208 return < DetectResult > {
196209 agent,
197210 agentVersion,
211+ isPrivate,
212+ isWorkspace,
198213 lockPath,
199214 lockSrc,
200215 pkgJson,
201- pkgPath ,
216+ pkgJsonPath ,
202217 pkgJsonStr,
203218 supported : targets . browser || targets . node ,
204219 targets
0 commit comments