@@ -3,6 +3,9 @@ import fs from 'node:fs'
33import { builtinModules } from 'node:module'
44import type { Plugin } from 'rollup'
55
6+ type MaybeFalsy < T > = T | undefined | null | false
7+ type MaybeArray < T > = T | T [ ]
8+
69export interface ExternalsOptions {
710
811 /**
@@ -62,14 +65,14 @@ export interface ExternalsOptions {
6265 *
6366 * Defaults to `[]`
6467 */
65- include ?: string | RegExp | ( string | RegExp ) [ ]
68+ include ?: MaybeArray < MaybeFalsy < string | RegExp > >
6669
6770 /**
6871 * Force exclude these deps from the list of externals, regardless of other settings.
6972 *
7073 * Defaults to `[]`
7174 */
72- exclude ?: string | RegExp | ( string | RegExp ) [ ]
75+ exclude ?: MaybeArray < MaybeFalsy < string | RegExp > >
7376}
7477
7578// Listing only fields of interest in package.json
@@ -135,7 +138,7 @@ function externals(options: ExternalsOptions = {}): Plugin {
135138
136139 // Map the include and exclude options to arrays of regexes.
137140 const [ include , exclude ] = ( [ 'include' , 'exclude' ] as const ) . map ( option =>
138- ( [ ] as ( string | RegExp ) [ ] )
141+ ( [ ] as ( string | RegExp | null | undefined | false ) [ ] )
139142 . concat ( config [ option ] )
140143 . reduce ( ( result , entry , index ) => {
141144 if ( entry instanceof RegExp )
@@ -158,9 +161,10 @@ function externals(options: ExternalsOptions = {}): Plugin {
158161 ? [ config . packagePath ]
159162 : [ ]
160163
164+ // Populate packagePaths if not given by getting all package.json files
165+ // from cwd up to the root of the monorepo, the root of the git repo,
166+ // or the root of the volume, whichever comes first.
161167 if ( packagePaths . length === 0 ) {
162- // Get all package.json files from cwd up to the root of the monorepo,
163- // the root of the git epo, or the root of the volume, whichever comes first.
164168 for (
165169 let current = process . cwd ( ) , previous : string | null = null ;
166170 previous !== current ;
@@ -194,8 +198,8 @@ function externals(options: ExternalsOptions = {}): Plugin {
194198 config . optDeps && pkg . optionalDependencies
195199 )
196200
197- // Break early if this is a npm/yarn workspace root
198- if ( 'workspaces' in pkg )
201+ // Break early if this is a npm/yarn workspace root.
202+ if ( 'workspaces' in pkg || 'packages' in pkg )
199203 break
200204 }
201205 catch {
0 commit comments