@@ -77,6 +77,52 @@ export function applyUploadConfigDefaults(uploadConfig, ciInfo) {
77
77
} ;
78
78
}
79
79
80
+ /**
81
+ * Normalizes entries to ensure they have a consistent format and ids are unique
82
+ * @param {EntryPoint[] } entries - The array of entries from the config
83
+ * @returns {ObjectEntry[] } - Normalized entries with uniqueness enforced
84
+ */
85
+ function normalizeEntries ( entries ) {
86
+ const usedIds = new Set ( ) ;
87
+
88
+ return entries . map ( ( entry ) => {
89
+ if ( typeof entry === 'string' ) {
90
+ // Transform string entries into object entries
91
+ const [ importSrc , importName ] = entry . split ( '#' ) ;
92
+ if ( importName ) {
93
+ // For entries like '@mui/material#Button', create an object with import and importedNames
94
+ entry = {
95
+ id : entry ,
96
+ import : importSrc ,
97
+ importedNames : [ importName ] ,
98
+ } ;
99
+ } else {
100
+ // For entries like '@mui/material', create an object with import only
101
+ entry = {
102
+ id : entry ,
103
+ import : importSrc ,
104
+ } ;
105
+ }
106
+ }
107
+
108
+ if ( ! entry . id ) {
109
+ throw new Error ( 'Object entries must have an id property' ) ;
110
+ }
111
+
112
+ if ( ! entry . code && ! entry . import ) {
113
+ throw new Error ( `Entry "${ entry . id } " must have either code or import property defined` ) ;
114
+ }
115
+
116
+ if ( usedIds . has ( entry . id ) ) {
117
+ throw new Error ( `Duplicate entry id found: "${ entry . id } ". Entry ids must be unique.` ) ;
118
+ }
119
+
120
+ usedIds . add ( entry . id ) ;
121
+
122
+ return entry ;
123
+ } ) ;
124
+ }
125
+
80
126
/**
81
127
* Apply default values to the configuration using CI environment
82
128
* @param {BundleSizeCheckerConfigObject } config - The loaded configuration
@@ -99,34 +145,7 @@ function applyConfigDefaults(config) {
99
145
// Clone the config to avoid mutating the original
100
146
/** @type {NormalizedBundleSizeCheckerConfig } */
101
147
const result = {
102
- entrypoints : config . entrypoints . map ( ( entry , i ) => {
103
- if ( typeof entry === 'string' ) {
104
- // Transform string entries into object entries
105
- const [ importSrc , importName ] = entry . split ( '#' ) ;
106
- if ( importName ) {
107
- // For entries like '@mui/material#Button', create an object with import and importedNames
108
- return {
109
- id : entry ,
110
- import : importSrc ,
111
- importedNames : [ importName ] ,
112
- } ;
113
- }
114
- // For entries like '@mui/material', create an object with import only
115
- return {
116
- id : entry ,
117
- import : importSrc ,
118
- } ;
119
- }
120
-
121
- if ( entry && typeof entry === 'object' ) {
122
- // For existing object entries, return them as is
123
- return entry ;
124
- }
125
-
126
- throw new Error (
127
- `Invalid entry format config.entrypoints[${ i } ]. Must be a string or an object.` ,
128
- ) ;
129
- } ) ,
148
+ entrypoints : normalizeEntries ( config . entrypoints ) ,
130
149
upload : null , // Default to disabled
131
150
} ;
132
151
0 commit comments