@@ -58,6 +58,7 @@ export interface PackageJsonData {
5858 scripts ?: Record < string , string > ;
5959 workspaces ?: unknown ;
6060 dependencies ?: Record < string , string > ;
61+ optionalDependencies ?: Record < string , string > ;
6162 peerDependencies ?: Record < string , string > ;
6263 peerDependenciesMeta ?: Record < string , { optional ?: boolean } > ;
6364 [ key : string ] : unknown ;
@@ -157,7 +158,7 @@ export async function normalizeLibraryOptions(
157158 packageName ,
158159 ) ;
159160
160- const allowedNonPeerDependencies : RegExp [ ] = [ ] ;
161+ const allowedNonPeerDependencies : RegExp [ ] = [ / ^ t s l i b $ / ] ;
161162 for ( const pattern of rawAllowedNonPeerDependencies ) {
162163 try {
163164 allowedNonPeerDependencies . push ( new RegExp ( pattern ) ) ;
@@ -186,10 +187,12 @@ export async function normalizeLibraryOptions(
186187 } ) ;
187188 }
188189
189- const combinedAssets = [ ...defaultAssets , ...( rawAssets ?? [ ] ) ] ;
190- const assets = combinedAssets . length
191- ? normalizeAssetPatterns ( combinedAssets , workspaceRoot , projectRoot , projectSourceRoot )
192- : [ ] ;
190+ const assets = normalizeAssetPatterns (
191+ [ ...defaultAssets , ...( rawAssets ?? [ ] ) ] ,
192+ workspaceRoot ,
193+ projectRoot ,
194+ projectSourceRoot ,
195+ ) ;
193196
194197 const cacheOptions = normalizeCacheOptions ( projectMetadata , workspaceRoot ) ;
195198
@@ -237,19 +240,21 @@ export async function normalizeLibraryOptions(
237240 * Normalizes a single entry point specification.
238241 *
239242 * @param key The entry point key from package.json exports (e.g. '.' or './testing').
243+ * @param posixKey Normalized POSIX key without trailing slashes.
244+ * @param isPrimary Whether this is the primary entry point.
240245 * @param targetPath The relative file path string from exports.
241246 * @param projectRoot The library project root directory.
242247 * @param packageName The root package name (e.g. `@my/lib`).
243248 * @returns The normalized entry point descriptor.
244249 */
245250function normalizeEntryPoint (
246251 key : string ,
252+ posixKey : string ,
253+ isPrimary : boolean ,
247254 targetPath : string ,
248255 projectRoot : string ,
249256 packageName : string ,
250257) : NormalizedEntryPoint {
251- const posixKey = toPosixPath ( key ) . replace ( / \/ + $ / , '' ) ;
252- const isPrimary = posixKey === '.' || posixKey === '' ;
253258 const name = isPrimary
254259 ? '.'
255260 : posixKey [ 0 ] === '.' && posixKey [ 1 ] === '/'
@@ -264,11 +269,11 @@ function normalizeEntryPoint(
264269
265270 const subpath = isPrimary ? '.' : `./${ name } ` ;
266271 const displayName = isPrimary ? packageName : `${ packageName } /${ name } ` ;
267- const bundleName = getEntryPointBundleName ( packageName , name , isPrimary ) ;
272+ const bundleName = getEntryPointBundleName ( packageName , name ) ;
268273
269274 const entryFilePath = path . resolve ( projectRoot , targetPath ) ;
270275
271- if ( ! / \. (?: t s | m t s ) $ / . test ( entryFilePath ) || / \. d \. (?: t s | m t s ) $ / . test ( entryFilePath ) ) {
276+ if ( ! / (?< ! \. d ) \. (?: t s | m t s ) $ / . test ( entryFilePath ) ) {
272277 throw new Error (
273278 `Entry point '${ key } ' file path must be a TypeScript file ('.ts' or '.mts'): '${ entryFilePath } '.` ,
274279 ) ;
@@ -312,6 +317,7 @@ function normalizeEntryPoints(
312317
313318 for ( const [ key , value ] of Object . entries ( exportsRecord ) ) {
314319 let target : string | undefined ;
320+
315321 if ( typeof value === 'string' ) {
316322 target = value ;
317323 } else if (
@@ -333,26 +339,33 @@ function normalizeEntryPoints(
333339 `or a 'default' condition pointing to a TypeScript file.` ,
334340 ) ;
335341 }
342+
336343 // Non-JS/TS conditional export (e.g., sass/style-only subpath); preserve in package.json without compiling.
337344 continue ;
338345 }
339346
340- if ( ! isPrimary ) {
341- const isTsSource = / \. (?: t s | m t s ) $ / . test ( target ) && ! / \. d \. (?: t s | m t s ) $ / . test ( target ) ;
342- const isInvalidCodeEntry = / \. (?: d \. [ c m ] ? t s | c t s | t s x | j s x ) $ / . test ( target ) ;
343- if ( ! isTsSource && ! isInvalidCodeEntry ) {
344- // Static asset, stylesheet, or package.json export; preserve in package.json without compiling.
345- continue ;
346- }
347+ if ( ! isPrimary && ! / \. m ? t s $ / . test ( target ) ) {
348+ // Static asset, stylesheet, or package.json export; preserve in package.json without compiling.
349+ continue ;
347350 }
348351
349- const entryPoint = normalizeEntryPoint ( key , target , projectRoot , packageName ) ;
352+ const entryPoint = normalizeEntryPoint (
353+ key ,
354+ posixKey ,
355+ isPrimary ,
356+ target ,
357+ projectRoot ,
358+ packageName ,
359+ ) ;
360+
350361 if ( entryPoints . has ( entryPoint . name ) ) {
351362 throw new Error (
352363 `Duplicate entry point detected: '${ key } ' resolves to the same name ('${ entryPoint . name } ') as an existing entry point.` ,
353364 ) ;
354365 }
366+
355367 entryPoints . set ( entryPoint . name , entryPoint ) ;
368+
356369 if ( entryPoint . isPrimary ) {
357370 hasPrimary = true ;
358371 }
0 commit comments