@@ -20,35 +20,26 @@ const packageJsonEntryPoints = new Set<string>()
20
20
* Recursively collects entry points from the `package.json` exports field.
21
21
*
22
22
* @param packageJsonExports - The exports field from `package.json`.
23
- * @returns - A set of package entry points.
23
+ * @returns A set of package entry points.
24
24
*/
25
- const collectPackageJsonExports = async (
25
+ const collectPackageJsonExports = (
26
26
packageJsonExports :
27
27
| string
28
28
| Record < string , any >
29
29
| null
30
30
| typeof import ( './package.json' ) . exports ,
31
31
) => {
32
- if ( typeof packageJsonExports === 'string' ) {
32
+ if (
33
+ typeof packageJsonExports === 'string' &&
34
+ packageJsonExports . endsWith ( 'js' )
35
+ ) {
33
36
packageJsonEntryPoints . add (
34
37
packageJsonExports . startsWith ( './' )
35
38
? packageJsonExports
36
39
: `./${ packageJsonExports } ` ,
37
40
)
38
-
39
- return packageJsonEntryPoints
40
- }
41
-
42
- if ( typeof packageJsonExports === 'object' && packageJsonExports !== null ) {
43
- await Promise . all (
44
- Object . entries ( packageJsonExports )
45
- . filter (
46
- ( [ condition ] ) =>
47
- condition !== './package.json' && condition !== 'types' ,
48
- )
49
- . map ( ( [ _condition , entryPoint ] ) => entryPoint )
50
- . map ( collectPackageJsonExports ) ,
51
- )
41
+ } else if ( packageJsonExports && typeof packageJsonExports === 'object' ) {
42
+ Object . values ( packageJsonExports ) . forEach ( collectPackageJsonExports )
52
43
}
53
44
54
45
return packageJsonEntryPoints
@@ -62,7 +53,7 @@ const collectPackageJsonExports = async (
62
53
const getAllPackageEntryPoints = async ( ) => {
63
54
const packageJson = await import ( './package.json' , { with : { type : 'json' } } )
64
55
65
- const packageExports = await collectPackageJsonExports ( packageJson . exports )
56
+ const packageExports = collectPackageJsonExports ( packageJson . exports )
66
57
67
58
return [ ...packageExports ]
68
59
}
@@ -82,9 +73,9 @@ const getAllImportsForEntryPoint = async (
82
73
entryPoint : string ,
83
74
index : number ,
84
75
) : Promise < SizeLimitConfig > => {
85
- const allNamedImports : typeof import ( './src/index' ) = await import ( entryPoint )
76
+ const allNamedImports = Object . keys ( await import ( entryPoint ) )
86
77
87
- return Object . keys ( allNamedImports )
78
+ return allNamedImports
88
79
. map < Check > ( ( namedImport ) => ( {
89
80
path : entryPoint ,
90
81
name : `${ index + 1 } . import { ${ namedImport } } from "${ entryPoint } "` ,
@@ -112,6 +103,7 @@ const getAllImportsForEntryPoint = async (
112
103
const setNodeEnv = ( nodeEnv : NodeEnv ) => {
113
104
const modifyWebpackConfig = ( ( config : Configuration ) => {
114
105
; ( config . optimization ??= { } ) . nodeEnv = nodeEnv
106
+
115
107
return config
116
108
} ) satisfies Check [ 'modifyWebpackConfig' ]
117
109
0 commit comments