@@ -33,73 +33,6 @@ function isUnpackedDir(dirPath: string, pattern: string, unpackDirs: string[]) {
33
33
}
34
34
}
35
35
36
- export type FileProperties = {
37
- filepath : string ;
38
- properties : {
39
- unpack ?: boolean ;
40
- } ;
41
- } ;
42
-
43
- async function getFileOrdering (
44
- options : CreateOptions ,
45
- src : string ,
46
- filenames : string [ ] ,
47
- ) : Promise < FileProperties [ ] > {
48
- if ( ! options . ordering ) {
49
- return filenames . map < FileProperties > ( ( filepath ) => ( { filepath, properties : { } } ) ) ;
50
- }
51
- const orderingMap : FileProperties [ ] = ( await fs . readFile ( options . ordering ) )
52
- . toString ( )
53
- . split ( '\n' )
54
- . map < FileProperties > ( ( line ) => {
55
- line = line . trim ( ) ;
56
- const config : FileProperties = { filepath : line , properties : { } } ;
57
- const colonIndex = line . indexOf ( ':' ) ;
58
- if ( colonIndex > - 1 ) {
59
- config . filepath = line . substring ( 0 , colonIndex ) ; // file path
60
- const props = line . substring ( colonIndex + 1 ) ; // props on other side of the `:`
61
- config . properties = props . length > 2 ? JSON . parse ( props ) : { } ; // file properties
62
- }
63
- if ( config . filepath . startsWith ( '/' ) ) {
64
- config . filepath = config . filepath . slice ( 1 ) ;
65
- }
66
- return config ;
67
- } ) ;
68
-
69
- const ordering : FileProperties [ ] = [ ] ;
70
- for ( const config of orderingMap ) {
71
- const pathComponents = config . filepath . split ( path . sep ) ;
72
- let str = src ;
73
- for ( const pathComponent of pathComponents ) {
74
- str = path . join ( str , pathComponent ) ;
75
- ordering . push ( { filepath : str , properties : config . properties } ) ;
76
- }
77
- }
78
-
79
- let missing = 0 ;
80
- const total = filenames . length ;
81
-
82
- const fileOrderingSorted : FileProperties [ ] = [ ] ;
83
- const isAlreadySorted = ( file : string ) =>
84
- fileOrderingSorted . findIndex ( ( config ) => file === config . filepath ) > - 1 ;
85
-
86
- for ( const config of ordering ) {
87
- if ( ! isAlreadySorted ( config . filepath ) && filenames . includes ( config . filepath ) ) {
88
- fileOrderingSorted . push ( config ) ;
89
- }
90
- }
91
-
92
- for ( const file of filenames ) {
93
- if ( ! isAlreadySorted ( file ) ) {
94
- fileOrderingSorted . push ( { filepath : file , properties : { } } ) ;
95
- missing += 1 ;
96
- }
97
- }
98
-
99
- console . log ( `Ordering file has ${ ( ( total - missing ) / total ) * 100 } % coverage.` ) ;
100
- return fileOrderingSorted ;
101
- }
102
-
103
36
export async function createPackage ( src : string , dest : string ) {
104
37
return createPackageWithOptions ( src , dest , { } ) ;
105
38
}
@@ -151,10 +84,54 @@ export async function createPackageFromFiles(
151
84
const links : disk . BasicFilesArray = [ ] ;
152
85
const unpackDirs : string [ ] = [ ] ;
153
86
154
- const filenamesSorted : FileProperties [ ] = await getFileOrdering ( options , src , filenames ) ;
87
+ let filenamesSorted : string [ ] = [ ] ;
88
+ if ( options . ordering ) {
89
+ const orderingFiles = ( await fs . readFile ( options . ordering ) )
90
+ . toString ( )
91
+ . split ( '\n' )
92
+ . map ( ( line ) => {
93
+ if ( line . includes ( ':' ) ) {
94
+ line = line . split ( ':' ) . pop ( ) ! ;
95
+ }
96
+ line = line . trim ( ) ;
97
+ if ( line . startsWith ( '/' ) ) {
98
+ line = line . slice ( 1 ) ;
99
+ }
100
+ return line ;
101
+ } ) ;
102
+
103
+ const ordering : string [ ] = [ ] ;
104
+ for ( const file of orderingFiles ) {
105
+ const pathComponents = file . split ( path . sep ) ;
106
+ let str = src ;
107
+ for ( const pathComponent of pathComponents ) {
108
+ str = path . join ( str , pathComponent ) ;
109
+ ordering . push ( str ) ;
110
+ }
111
+ }
112
+
113
+ let missing = 0 ;
114
+ const total = filenames . length ;
115
+
116
+ for ( const file of ordering ) {
117
+ if ( ! filenamesSorted . includes ( file ) && filenames . includes ( file ) ) {
118
+ filenamesSorted . push ( file ) ;
119
+ }
120
+ }
121
+
122
+ for ( const file of filenames ) {
123
+ if ( ! filenamesSorted . includes ( file ) ) {
124
+ filenamesSorted . push ( file ) ;
125
+ missing += 1 ;
126
+ }
127
+ }
155
128
156
- const handleFile = async function ( config : FileProperties ) {
157
- const filename = config . filepath ;
129
+ console . log ( `Ordering file has ${ ( ( total - missing ) / total ) * 100 } % coverage.` ) ;
130
+ } else {
131
+ filenamesSorted = filenames ;
132
+ }
133
+
134
+ const handleFile = async function ( filename : string ) {
158
135
if ( ! metadata [ filename ] ) {
159
136
const fileType = await determineFileType ( filename ) ;
160
137
if ( ! fileType ) {
@@ -169,9 +146,6 @@ export async function createPackageFromFiles(
169
146
unpack : string | undefined ,
170
147
unpackDir : string | undefined ,
171
148
) {
172
- if ( config . properties . unpack != null ) {
173
- return config . properties . unpack ;
174
- }
175
149
let shouldUnpack = false ;
176
150
if ( unpack ) {
177
151
shouldUnpack = minimatch ( filename , unpack , { matchBase : true } ) ;
@@ -216,12 +190,12 @@ export async function createPackageFromFiles(
216
190
217
191
const names = filenamesSorted . slice ( ) ;
218
192
219
- const next = async function ( config ?: FileProperties ) {
220
- if ( ! config ) {
193
+ const next = async function ( name ?: string ) {
194
+ if ( ! name ) {
221
195
return insertsDone ( ) ;
222
196
}
223
197
224
- await handleFile ( config ) ;
198
+ await handleFile ( name ) ;
225
199
return next ( names . shift ( ) ) ;
226
200
} ;
227
201
0 commit comments