@@ -147,38 +147,39 @@ export default class I18nextPlugin {
147
147
compiler . plugin ( "after-emit" , this . onAfterEmit . bind ( this ) ) ;
148
148
}
149
149
150
- protected onEmit ( compilation : wp . Compilation , callback : ( err ?: Error ) => void ) {
150
+ protected async onEmit ( compilation : wp . Compilation , callback : ( err ?: Error ) => void ) {
151
151
// emit translation files
152
- const promises : Promise < any > [ ] = [ ] ;
153
-
154
- for ( const lng of this . option . languages ) {
155
- const resourceTemplate = path . join ( this . context , getPath ( this . option . resourcePath , lng ) ) ;
156
- try {
152
+ try {
153
+ await Promise . all ( _ . map ( this . option . languages , lng => {
154
+ const resourceTemplate = path . join ( this . context , getPath ( this . option . resourcePath , lng ) ) ;
157
155
const resourceDir = path . dirname ( resourceTemplate ) ;
158
- fs . statSync ( resourceDir ) ;
159
- // compilation.contextDependencies .push(resourceDir);
160
- } catch ( e ) {
156
+ if ( ! exists ( resourceDir ) ) {
157
+ compilation . missingDependencies . push ( resourceDir ) ;
158
+ }
161
159
162
- }
160
+ return _ . map ( this . option . namespaces , async ns => {
161
+ const resourcePath = getPath ( resourceTemplate , undefined , ns ) ;
162
+ const outPath = getPath ( this . option . outPath , lng , ns ) ;
163
163
164
- for ( const ns of this . option . namespaces ) {
165
- const resourcePath = getPath ( resourceTemplate , undefined , ns ) ;
166
- const outPath = getPath ( this . option . outPath , lng , ns ) ;
164
+ try {
165
+ const v = await readFile ( resourcePath ) ;
166
+ compilation . assets [ outPath ] = {
167
+ size ( ) { return v . length ; } ,
168
+ source ( ) { return v ; }
169
+ } ;
167
170
168
- promises . push ( readFile ( resourcePath ) . then ( v => {
169
- compilation . assets [ outPath ] = {
170
- size ( ) { return v . length ; } ,
171
- source ( ) { return v ; }
172
- } ;
171
+ compilation . fileDependencies . push ( path . resolve ( resourcePath ) ) ;
172
+ } catch ( e ) {
173
+ compilation . missingDependencies . push ( resourcePath ) ;
174
+ compilation . warnings . push ( `Can't emit ${ outPath } . It looks like ${ resourcePath } is not exists.` ) ;
175
+ }
176
+ } ) ;
177
+ } ) ) ;
173
178
174
- compilation . fileDependencies . push ( path . resolve ( resourcePath ) ) ;
175
- } ) . catch ( ( ) => {
176
- compilation . warnings . push ( `Can't emit ${ outPath } . It looks like ${ resourcePath } is not exists.` ) ;
177
- } ) ) ;
178
- }
179
+ callback ( ) ;
180
+ } catch ( e ) {
181
+ callback ( e ) ;
179
182
}
180
-
181
- Promise . all ( promises ) . then ( ( ) => callback ( ) ) . catch ( callback ) ;
182
183
}
183
184
184
185
protected async onAfterEmit ( compilation : wp . Compilation , callback : ( err ?: Error ) => void ) {
0 commit comments