7
7
8
8
const parseJson = require ( "json-parse-better-errors" ) ;
9
9
const asyncLib = require ( "neo-async" ) ;
10
- const path = require ( "path" ) ;
11
10
const {
12
11
SyncHook,
13
12
SyncBailHook,
@@ -25,6 +24,7 @@ const RequestShortener = require("./RequestShortener");
25
24
const ResolverFactory = require ( "./ResolverFactory" ) ;
26
25
const Stats = require ( "./Stats" ) ;
27
26
const Watching = require ( "./Watching" ) ;
27
+ const { join, dirname, mkdirp } = require ( "./util/fs" ) ;
28
28
const { makePathsRelative } = require ( "./util/identifier" ) ;
29
29
30
30
/** @typedef {import("webpack-sources").Source } Source */
@@ -36,6 +36,9 @@ const { makePathsRelative } = require("./util/identifier");
36
36
/** @typedef {import("./Chunk") } Chunk */
37
37
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry } FileSystemInfoEntry */
38
38
/** @typedef {import("./Module") } Module */
39
+ /** @typedef {import("./util/fs").InputFileSystem } InputFileSystem */
40
+ /** @typedef {import("./util/fs").IntermediateFileSystem } IntermediateFileSystem */
41
+ /** @typedef {import("./util/fs").OutputFileSystem } OutputFileSystem */
39
42
40
43
/**
41
44
* @typedef {Object } CompilationParams
@@ -151,7 +154,11 @@ class Compiler {
151
154
/** @type {string } */
152
155
this . outputPath = "" ;
153
156
157
+ /** @type {OutputFileSystem } */
154
158
this . outputFileSystem = null ;
159
+ /** @type {IntermediateFileSystem } */
160
+ this . intermediateFileSystem = null ;
161
+ /** @type {InputFileSystem } */
155
162
this . inputFileSystem = null ;
156
163
this . watchFileSystem = null ;
157
164
@@ -353,7 +360,8 @@ class Compiler {
353
360
354
361
const writeOut = err => {
355
362
if ( err ) return callback ( err ) ;
356
- const targetPath = this . outputFileSystem . join (
363
+ const targetPath = join (
364
+ this . outputFileSystem ,
357
365
outputPath ,
358
366
targetFile
359
367
) ;
@@ -424,11 +432,9 @@ class Compiler {
424
432
} ;
425
433
426
434
if ( targetFile . match ( / \/ | \\ / ) ) {
427
- const dir = path . dirname ( targetFile ) ;
428
- this . outputFileSystem . mkdirp (
429
- this . outputFileSystem . join ( outputPath , dir ) ,
430
- writeOut
431
- ) ;
435
+ const fs = this . outputFileSystem ;
436
+ const dir = dirname ( fs , join ( fs , outputPath , targetFile ) ) ;
437
+ mkdirp ( fs , dir , writeOut ) ;
432
438
} else {
433
439
writeOut ( ) ;
434
440
}
@@ -448,7 +454,7 @@ class Compiler {
448
454
this . hooks . emit . callAsync ( compilation , err => {
449
455
if ( err ) return callback ( err ) ;
450
456
outputPath = compilation . getPath ( this . outputPath , { } ) ;
451
- this . outputFileSystem . mkdirp ( outputPath , emitFiles ) ;
457
+ mkdirp ( this . outputFileSystem , outputPath , emitFiles ) ;
452
458
} ) ;
453
459
}
454
460
@@ -458,14 +464,6 @@ class Compiler {
458
464
*/
459
465
emitRecords ( callback ) {
460
466
if ( ! this . recordsOutputPath ) return callback ( ) ;
461
- const idx1 = this . recordsOutputPath . lastIndexOf ( "/" ) ;
462
- const idx2 = this . recordsOutputPath . lastIndexOf ( "\\" ) ;
463
- let recordsOutputPathDirectory = null ;
464
- if ( idx1 > idx2 ) {
465
- recordsOutputPathDirectory = this . recordsOutputPath . substr ( 0 , idx1 ) ;
466
- } else if ( idx1 < idx2 ) {
467
- recordsOutputPathDirectory = this . recordsOutputPath . substr ( 0 , idx2 ) ;
468
- }
469
467
470
468
const writeFile = ( ) => {
471
469
this . outputFileSystem . writeFile (
@@ -491,10 +489,14 @@ class Compiler {
491
489
) ;
492
490
} ;
493
491
492
+ const recordsOutputPathDirectory = dirname (
493
+ this . outputFileSystem ,
494
+ this . recordsOutputPath
495
+ ) ;
494
496
if ( ! recordsOutputPathDirectory ) {
495
497
return writeFile ( ) ;
496
498
}
497
- this . outputFileSystem . mkdirp ( recordsOutputPathDirectory , err => {
499
+ mkdirp ( this . outputFileSystem , recordsOutputPathDirectory , err => {
498
500
if ( err ) return callback ( err ) ;
499
501
writeFile ( ) ;
500
502
} ) ;
@@ -630,11 +632,12 @@ class Compiler {
630
632
}
631
633
632
634
createNormalModuleFactory ( ) {
633
- const normalModuleFactory = new NormalModuleFactory (
634
- this . options . context ,
635
- this . resolverFactory ,
636
- this . options . module || { }
637
- ) ;
635
+ const normalModuleFactory = new NormalModuleFactory ( {
636
+ context : this . options . context ,
637
+ fs : this . inputFileSystem ,
638
+ resolverFactory : this . resolverFactory ,
639
+ options : this . options . module || { }
640
+ } ) ;
638
641
this . hooks . normalModuleFactory . call ( normalModuleFactory ) ;
639
642
return normalModuleFactory ;
640
643
}
0 commit comments