@@ -283,60 +283,81 @@ async function getEntryPoints(
283
283
284
284
const exportsEntries = Object . entries ( pkg . exports ) ;
285
285
286
- for ( const [ subpath , target ] of exportsEntries ) {
287
- if ( typeof target !== 'string' ) {
288
- throw new Error (
289
- `Invalid exports field in package.json for ${ packageName } . ` +
290
- `exports["${ subpath } "] must be a string target.` ,
291
- ) ;
286
+ for ( const [ subpath , targetOrConditionsObject ] of exportsEntries ) {
287
+ const targets /*: string[] */ = [ ] ;
288
+ if (
289
+ typeof targetOrConditionsObject === 'object' &&
290
+ targetOrConditionsObject != null
291
+ ) {
292
+ for ( const [ condition , target ] of Object . entries (
293
+ targetOrConditionsObject ,
294
+ ) ) {
295
+ if ( typeof target !== 'string' ) {
296
+ throw new Error (
297
+ `Invalid exports field in package.json for ${ packageName } . ` +
298
+ `exports["${ subpath } "]["${ condition } "] must be a string target.` ,
299
+ ) ;
300
+ }
301
+ targets . push ( target ) ;
302
+ }
303
+ } else {
304
+ if ( typeof targetOrConditionsObject !== 'string' ) {
305
+ throw new Error (
306
+ `Invalid exports field in package.json for ${ packageName } . ` +
307
+ `exports["${ subpath } "] must be a string target.` ,
308
+ ) ;
309
+ }
310
+ targets . push ( targetOrConditionsObject ) ;
292
311
}
293
312
294
- // Skip non-JS files
295
- if ( ! target . endsWith ( '.js' ) ) {
296
- continue ;
297
- }
313
+ for ( const target of targets ) {
314
+ // Skip non-JS files
315
+ if ( ! target . endsWith ( '.js' ) ) {
316
+ continue ;
317
+ }
298
318
299
- if ( target . includes ( '*' ) ) {
300
- console . warn (
301
- `${ chalk . yellow ( 'Warning' ) } : Encountered subpath pattern ${ subpath } ` +
302
- ` in package.json exports for ${ packageName } . Matched entry points ` +
303
- 'will not be validated.' ,
304
- ) ;
305
- continue ;
306
- }
319
+ if ( target . includes ( '*' ) ) {
320
+ console . warn (
321
+ `${ chalk . yellow ( 'Warning' ) } : Encountered subpath pattern ${ subpath } ` +
322
+ ` in package.json exports for ${ packageName } . Matched entry points ` +
323
+ 'will not be validated.' ,
324
+ ) ;
325
+ continue ;
326
+ }
307
327
308
- // Normalize to original path if previously rewritten
309
- const original = normalizeExportsTarget ( target ) ;
328
+ // Normalize to original path if previously rewritten
329
+ const original = normalizeExportsTarget ( target ) ;
310
330
311
- if ( original . endsWith ( '.flow.js' ) ) {
312
- throw new Error (
313
- `Package ${ packageName } defines exports["${ subpath } "] = "${ original } ". ` +
314
- 'Expecting a .js wrapper file. See other monorepo packages for examples.' ,
315
- ) ;
316
- }
331
+ if ( original . endsWith ( '.flow.js' ) ) {
332
+ throw new Error (
333
+ `Package ${ packageName } defines exports["${ subpath } "] = "${ original } ". ` +
334
+ 'Expecting a .js wrapper file. See other monorepo packages for examples.' ,
335
+ ) ;
336
+ }
317
337
318
- // Our special case for wrapper files that need to be stripped
319
- const resolvedTarget = path . resolve ( PACKAGES_DIR , packageName , original ) ;
320
- const resolvedFlowTarget = resolvedTarget . replace ( / \. j s $ / , '.flow.js' ) ;
338
+ // Our special case for wrapper files that need to be stripped
339
+ const resolvedTarget = path . resolve ( PACKAGES_DIR , packageName , original ) ;
340
+ const resolvedFlowTarget = resolvedTarget . replace ( / \. j s $ / , '.flow.js' ) ;
321
341
322
- try {
323
- await Promise . all ( [
324
- fs . access ( resolvedTarget ) ,
325
- fs . access ( resolvedFlowTarget ) ,
326
- ] ) ;
327
- } catch {
328
- throw new Error (
329
- `${ resolvedFlowTarget } does not exist when building ${ packageName } .
342
+ try {
343
+ await Promise . all ( [
344
+ fs . access ( resolvedTarget ) ,
345
+ fs . access ( resolvedFlowTarget ) ,
346
+ ] ) ;
347
+ } catch {
348
+ throw new Error (
349
+ `${ resolvedFlowTarget } does not exist when building ${ packageName } .
330
350
331
351
From package.json exports["${ subpath } "]:
332
352
- found: ${ path . relative ( REPO_ROOT , resolvedTarget ) }
333
353
- missing: ${ path . relative ( REPO_ROOT , resolvedFlowTarget ) }
334
354
335
355
This is needed so users can directly import this entry point from the monorepo.` ,
336
- ) ;
337
- }
356
+ ) ;
357
+ }
338
358
339
- entryPoints . add ( resolvedFlowTarget ) ;
359
+ entryPoints . add ( resolvedFlowTarget ) ;
360
+ }
340
361
}
341
362
342
363
return entryPoints ;
0 commit comments