@@ -10,6 +10,7 @@ const VirtualModulePlugin = require('virtual-module-webpack-plugin');
10
10
const readFile = util . promisify ( fs . readFile ) ;
11
11
const unlink = util . promisify ( fs . unlink ) ;
12
12
const stat = util . promisify ( fs . stat ) ;
13
+ const mkdir = util . promisify ( fs . mkdir ) ;
13
14
14
15
async function exists ( path : fs . PathLike ) {
15
16
try {
@@ -191,10 +192,20 @@ export default class I18nextPlugin {
191
192
) ) ;
192
193
try {
193
194
// write missing
194
- await Promise . all ( _ . map ( this . missingKeys , async ( namespaces , lng ) =>
195
- _ . map ( namespaces , async ( keys , ns ) => new Promise < void > ( resolve => {
195
+ await Promise . all ( _ . map ( this . missingKeys , async ( namespaces , lng ) => {
196
+ const resourceTemplate = path . join ( this . context , getPath ( this . option . pathToSaveMissing , lng ) ) ;
197
+ const resourceDir = path . dirname ( resourceTemplate ) ;
198
+ try {
199
+ await mkdir ( resourceDir ) ;
200
+ } catch ( e ) {
201
+ if ( e . code !== 'EEXIST' ) {
202
+ throw e ;
203
+ }
204
+ }
205
+
206
+ return _ . map ( namespaces , async ( keys , ns ) => new Promise < void > ( resolve => {
196
207
delete remains [ lng ] [ ns ] ;
197
- const missingPath = path . join ( this . context , getPath ( this . option . pathToSaveMissing , lng , ns ) ) ;
208
+ const missingPath = getPath ( resourceTemplate , undefined , ns ) ;
198
209
const stream = fs . createWriteStream ( missingPath , {
199
210
defaultEncoding : "utf-8"
200
211
} ) ;
@@ -206,8 +217,8 @@ export default class I18nextPlugin {
206
217
stream . on ( "close" , ( ) => resolve ( ) ) ;
207
218
208
219
compilation . warnings . push ( `missing translation ${ keys . length } keys in ${ lng } /${ ns } ` ) ;
209
- } ) )
210
- ) ) ;
220
+ } ) ) ;
221
+ } ) ) ;
211
222
// remove previous missings
212
223
await Promise . all ( _ . map ( remains , async ( namespaces , lng ) =>
213
224
_ . map ( namespaces , async ( __ , ns ) => {
0 commit comments