@@ -118,9 +118,63 @@ async function main() {
118118 }
119119 }
120120
121+ // Create exports object with proper ordering:
122+ // 1. Main exports (. and ./index)
123+ // 2. SCREAMING_SNAKE_CASE constants
124+ // 3. kebab-case constants
125+ // 4. Non-constants lib exports
126+ // 5. JSON files
127+ const mainExports = { }
128+ const jsonExports2 = { }
129+ const libExports = { }
130+ const screamingSnakeCaseExports = { }
131+ const kebabCaseExports = { }
132+
133+ for ( const { 0 : key , 1 : value } of Object . entries ( {
134+ ...subpathExports ,
135+ ...jsonExports ,
136+ } ) ) {
137+ if ( key === '.' || key === './index' ) {
138+ mainExports [ key ] = value
139+ } else if ( key . endsWith ( '.json' ) ) {
140+ jsonExports2 [ key ] = value
141+ } else if ( key . startsWith ( './lib/constants/' ) ) {
142+ const pathAfterConstants = key . slice ( './lib/constants/' . length )
143+ // SCREAMING_SNAKE_CASE paths contain _ or start with uppercase
144+ if (
145+ pathAfterConstants . includes ( '_' ) ||
146+ / ^ [ A - Z ] / . test ( pathAfterConstants )
147+ ) {
148+ screamingSnakeCaseExports [ key ] = value
149+ } else {
150+ kebabCaseExports [ key ] = value
151+ }
152+ } else {
153+ // Non-constants lib paths
154+ libExports [ key ] = value
155+ }
156+ }
157+
158+ // Ensure . comes before ./index
159+ const sortedMainExports = { }
160+ if ( mainExports [ '.' ] ) {
161+ sortedMainExports [ '.' ] = mainExports [ '.' ]
162+ }
163+ if ( mainExports [ './index' ] ) {
164+ sortedMainExports [ './index' ] = mainExports [ './index' ]
165+ }
166+
167+ const exports = {
168+ ...sortedMainExports ,
169+ ...toSortedObject ( screamingSnakeCaseExports ) ,
170+ ...toSortedObject ( kebabCaseExports ) ,
171+ ...toSortedObject ( libExports ) ,
172+ ...toSortedObject ( jsonExports2 ) ,
173+ }
174+
121175 registryEditablePkgJson . update ( {
122176 browser : toSortedObject ( browser ) ,
123- exports : toSortedObject ( { ... subpathExports , ... jsonExports } ) ,
177+ exports,
124178 engines : { node : constants . PACKAGE_DEFAULT_NODE_RANGE } ,
125179 } )
126180 await registryEditablePkgJson . save ( )
0 commit comments