@@ -270,159 +270,6 @@ const sortScripts = onObject((scripts, packageJson) => {
270270  return  sortObjectKeys ( scripts ,  order ) 
271271} ) 
272272
273- /** 
274-  * Sorts an array in relative terms defined by the `order` 
275-  * 
276-  * The effect of relative sort is that keys not in the `order` will be kept 
277-  * in the order they were in the original array unless it is shifted to 
278-  * accommodate a key in the `order` 
279-  */ 
280- const  relativeOrderSort  =  ( list ,  order )  =>  { 
281-   const  orderMap  =  new  Map ( 
282-     order . map ( ( key ,  index )  =>  { 
283-       return  [ key ,  index ] 
284-     } ) , 
285-   ) 
286-   const  indexes  =  list . flatMap ( ( item ,  i )  =>  { 
287-     if  ( orderMap . has ( item ) )  { 
288-       return  i 
289-     } 
290-     return  [ ] 
291-   } ) 
292-   const  sortedIndexes  =  [ ...indexes ] . sort ( ( a ,  b )  =>  { 
293-     const  aIndex  =  orderMap . get ( list [ a ] ) 
294-     const  bIndex  =  orderMap . get ( list [ b ] ) 
295-     return  aIndex  -  bIndex 
296-   } ) 
297- 
298-   const  copy  =  [ ...list ] 
299-   sortedIndexes . forEach ( ( desiredIndex ,  thisIndex )  =>  { 
300-     copy [ indexes [ thisIndex ] ]  =  list [ desiredIndex ] 
301-   } ) 
302- 
303-   return  copy 
304- } 
305- 
306- const  withLastKey  =  ( keyName ,  {  [ keyName ] : keyValue ,  ...rest  } )  => 
307-   typeof  keyValue  !==  'undefined' 
308-     ? { 
309-         ...rest , 
310-         [ keyName ] : keyValue , 
311-       } 
312-     : rest 
313- 
314- const  withFirstKey  =  ( keyName ,  {  [ keyName ] : keyValue ,  ...rest  } )  => 
315-   typeof  keyValue  !==  'undefined' 
316-     ? { 
317-         [ keyName ] : keyValue , 
318-         ...rest , 
319-       } 
320-     : rest 
321- 
322- const  sortConditionObject  =  ( conditionObject )  =>  { 
323-   /** 
324-    * Sources: 
325-    * - WinterCG maintained list of standard runtime keys: https://runtime-keys.proposal.wintercg.org 
326-    * - Node.js conditional exports: https://nodejs.org/api/packages.html#conditional-exports 
327-    * - Webpack conditions: https://webpack.js.org/guides/package-exports/#conditions 
328-    * - Bun condition: https://bun.sh/docs/runtime/modules#importing-packages 
329-    * - Bun macro condition: https://bun.sh/docs/bundler/macros#export-condition-macro 
330-    */ 
331-   const  bundlerConditions  =  [ 'vite' ,  'rollup' ,  'webpack' ] 
332- 
333-   const  serverVariantConditions  =  [ 'react-server' ] 
334-   const  edgeConditions  =  [ 
335-     'azion' , 
336-     'edge-light' , 
337-     'edge-routine' , 
338-     'fastly' , 
339-     'lagon' , 
340-     'netlify' , 
341-     'wasmer' , 
342-     'workerd' , 
343-   ] 
344- 
345-   const  referenceSyntaxConditions  =  [ 
346-     'svelte' , 
347-     'asset' , 
348-     'sass' , 
349-     'stylus' , 
350-     'style' , 
351-     /** 
352-      * 'script' condition must come before 'module' condition, as 'script' 
353-      * may also be used by bundlers but in more specific conditions than 
354-      * 'module' 
355-      */ 
356-     'script' , 
357-     'esmodules' , 
358-     /** 
359-      * 'module' condition must come before 'import'. import may include pure node ESM modules 
360-      * that are only compatible with node environments, while 'module' may be 
361-      * used by bundlers and leverage other bundler features 
362-      */ 
363-     'module' , 
364-     'import' , 
365-     /** 
366-      * `module-sync` condition must come before `require` condition and after 
367-      * `import`. 
368-      */ 
369-     'module-sync' , 
370-     'require' , 
371-   ] 
372- 
373-   const  targetEnvironmentConditions  =  [ 
374-     /** 
375-      * bun macro condition must come before 'bun' 
376-      */ 
377-     'macro' , 
378-     'bun' , 
379-     'deno' , 
380-     'browser' , 
381-     'electron' , 
382-     'kiesel' ,  // https://runtime-keys.proposal.wintercg.org/#kiesel 
383-     'node-addons' , 
384-     'node' , 
385-     'moddable' ,  // https://runtime-keys.proposal.wintercg.org/#moddable 
386-     'react-native' , 
387-     'worker' , 
388-     'worklet' , 
389-   ] 
390- 
391-   const  environmentConditions  =  [ 'test' ,  'development' ,  'production' ] 
392- 
393-   const  order  =  relativeOrderSort ( Object . keys ( conditionObject ) ,  [ 
394-     /** 
395-      * Environment conditions at the top as they are generally used to override 
396-      * default behavior based on the environment 
397-      */ 
398-     ...environmentConditions , 
399-     /** 
400-      * Bundler conditions are generally more important than other conditions 
401-      * because they leverage code that will not work outside of the 
402-      * bundler environment 
403-      */ 
404-     ...bundlerConditions , 
405-     /** 
406-      * Edge run-times are often variants of other target environments, so they must come 
407-      * before the target environment conditions 
408-      */ 
409-     ...edgeConditions , 
410-     /** 
411-      * Server variants need to be placed before `referenceSyntaxConditions` and 
412-      * `targetEnvironmentConditions` since they may use multiple syntaxes and target 
413-      * environments. They should also go after `edgeConditions` 
414-      * to allow custom implementations per edge runtime. 
415-      */ 
416-     ...serverVariantConditions , 
417-     ...targetEnvironmentConditions , 
418-     ...referenceSyntaxConditions , 
419-   ] ) 
420-   return  withFirstKey ( 
421-     'types' , 
422-     withLastKey ( 'default' ,  sortObjectKeys ( conditionObject ,  order ) ) , 
423-   ) 
424- } 
425- 
426273const  sortPathLikeObjectWithWildcards  =  onObject ( ( object )  =>  { 
427274  // Replace all '*' with the highest possible unicode character 
428275  // To force all wildcards to be at the end, but relative to 
@@ -448,24 +295,17 @@ const sortExportsOrImports = onObject((exportOrImports) => {
448295  ) 
449296
450297  const  keys  =  Object . keys ( exportsWithSortedChildren ) 
451-   let  isConditionObject  =  true 
452298  let  isPathLikeObject  =  true 
453299  for  ( const  key  of  keys )  { 
454300    const  keyIsPathLike  =  key . startsWith ( '.' )  ||  key . startsWith ( '#' ) 
455- 
456-     isConditionObject  =  isConditionObject  &&  ! keyIsPathLike 
457301    isPathLikeObject  =  isPathLikeObject  &&  keyIsPathLike 
458302  } 
459303
460-   if  ( isConditionObject )  { 
461-     return  sortConditionObject ( exportsWithSortedChildren ) 
462-   } 
463- 
464304  if  ( isPathLikeObject )  { 
465305    return  sortPathLikeObjectWithWildcards ( exportsWithSortedChildren ) 
466306  } 
467307
468-   // Object is improperly formatted. Leave it alone  
308+   // Object is likely condition object  
469309  return  exportOrImports 
470310} ) 
471311
0 commit comments