@@ -6,13 +6,13 @@ let { abort } = require("./util");
66let path = require ( "path" ) ;
77
88module . exports = class Manifest {
9- constructor ( referenceDir , { target, key, value, baseURI, webRoot } ) {
9+ constructor ( referenceDir , { target, key, value, baseURI, webRoot } = { } ) {
1010 if ( target ) {
1111 this . filepath = resolvePath ( target , referenceDir , {
1212 enforceRelative : true
1313 } ) ;
1414 }
15- this . _index = { } ;
15+ this . _index = new Map ( ) ;
1616
1717 if ( key === "short" ) {
1818 this . keyTransform = ( fp , targetDir ) => path . relative ( targetDir , fp ) ;
@@ -34,19 +34,24 @@ module.exports = class Manifest {
3434 }
3535
3636 get ( originalPath ) {
37- return this . _index [ originalPath ] ;
37+ return this . _index . get ( originalPath ) ;
3838 }
3939
4040 set ( originalPath , actualPath , targetDir ) {
4141 let key = this . keyTransform ( originalPath , targetDir ) ;
4242 let uri = this . valueTransform ( actualPath ) ;
43- this . _index [ key ] = uri ;
43+ this . _index . set ( key , uri ) ;
4444
4545 let fp = this . filepath ;
4646 return fp ? createFile ( fp , this . toJSON ( ) ) : Promise . resolve ( null ) ;
4747 }
4848
4949 toJSON ( ) {
50- return JSON . stringify ( this . _index ) + "\n" ;
50+ let index = this . _index ;
51+ let manifest = Array . from ( index . keys ( ) ) . sort ( ) . reduce ( ( memo , key ) => {
52+ memo [ key ] = index . get ( key ) ;
53+ return memo ;
54+ } , { } ) ;
55+ return JSON . stringify ( manifest ) + "\n" ;
5156 }
5257} ;
0 commit comments