@@ -53,10 +53,12 @@ export type DetectOptions = {
53
53
export type DetectResult = Readonly < {
54
54
agent : AgentPlusBun
55
55
agentVersion : string | undefined
56
+ isPrivate : boolean
57
+ isWorkspace : boolean
56
58
lockPath : string | undefined
57
59
lockSrc : string | undefined
58
60
pkgJson : PackageJSONObject | undefined
59
- pkgPath : string | undefined
61
+ pkgJsonPath : string | undefined
60
62
pkgJsonStr : string | undefined
61
63
supported : boolean
62
64
targets : {
@@ -104,14 +106,14 @@ export async function detect({
104
106
const lockPath = await findUp ( Object . keys ( LOCKS ) , { cwd } )
105
107
const isHiddenLockFile = lockPath ?. endsWith ( '.package-lock.json' ) ?? false
106
108
107
- const pkgPath = lockPath
109
+ const pkgJsonPath = lockPath
108
110
? path . resolve ( lockPath , `${ isHiddenLockFile ? '../' : '' } ../package.json` )
109
111
: await findUp ( 'package.json' , { cwd } )
110
112
111
113
// Read Corepack `packageManager` field in package.json:
112
114
// 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 )
115
117
: undefined
116
118
117
119
const pkgJson =
@@ -128,12 +130,14 @@ export async function detect({
128
130
let agent : AgentPlusBun | undefined
129
131
let agentVersion : string | undefined
130
132
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
+ }
137
141
}
138
142
}
139
143
if (
@@ -154,7 +158,16 @@ export async function detect({
154
158
node : true
155
159
}
156
160
161
+ let isPrivate = false
162
+ let isWorkspace = false
157
163
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
+
158
171
let browser : boolean | undefined
159
172
let node : boolean | undefined
160
173
const browserField = getOwn ( pkgJson , 'browser' )
@@ -195,10 +208,12 @@ export async function detect({
195
208
return < DetectResult > {
196
209
agent,
197
210
agentVersion,
211
+ isPrivate,
212
+ isWorkspace,
198
213
lockPath,
199
214
lockSrc,
200
215
pkgJson,
201
- pkgPath ,
216
+ pkgJsonPath ,
202
217
pkgJsonStr,
203
218
supported : targets . browser || targets . node ,
204
219
targets
0 commit comments