forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@ngtools/webpack): decorate file system
Followup to angular#7169
- Loading branch information
1 parent
29988d5
commit 8f9156b
Showing
4 changed files
with
137 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/@ngtools/webpack/src/virtual_file_system_decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Stats } from 'fs'; | ||
import { InputFileSystem, Callback } from './webpack'; | ||
import { WebpackCompilerHost } from './compiler_host'; | ||
|
||
|
||
export class VirtualFileSystemDecorator implements InputFileSystem { | ||
constructor( | ||
private _inputFileSystem: InputFileSystem, | ||
private _webpackCompilerHost: WebpackCompilerHost | ||
) { } | ||
|
||
private _readFileSync(path: string): string | null { | ||
if (this._webpackCompilerHost.fileExists(path, false)) { | ||
return this._webpackCompilerHost.readFile(path); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private _statSync(path: string): Stats | null { | ||
if (this._webpackCompilerHost.fileExists(path, false) | ||
|| this._webpackCompilerHost.directoryExists(path, false)) { | ||
return this._webpackCompilerHost.stat(path); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private _readDirSync(path: string): string[] | null { | ||
if (this._webpackCompilerHost.directoryExists(path, false)) { | ||
const dirs = this._webpackCompilerHost.getDirectories(path); | ||
const files = this._webpackCompilerHost.getFiles(path); | ||
return files.concat(dirs); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
stat(path: string, callback: Callback<any>): void { | ||
const result = this._statSync(path); | ||
if (result) { | ||
callback(null, result); | ||
} else { | ||
this._inputFileSystem.stat(path, callback); | ||
} | ||
} | ||
|
||
readdir(path: string, callback: Callback<any>): void { | ||
const result = this._readDirSync(path); | ||
if (result) { | ||
callback(null, result); | ||
} else { | ||
this._inputFileSystem.readdir(path, callback); | ||
} | ||
} | ||
|
||
readFile(path: string, callback: Callback<any>): void { | ||
const result = this._readFileSync(path); | ||
if (result) { | ||
callback(null, result); | ||
} else { | ||
this._inputFileSystem.readFile(path, callback); | ||
} | ||
} | ||
|
||
readJson(path: string, callback: Callback<any>): void { | ||
this._inputFileSystem.readJson(path, callback); | ||
} | ||
|
||
readlink(path: string, callback: Callback<any>): void { | ||
this._inputFileSystem.readlink(path, callback); | ||
} | ||
|
||
statSync(path: string): Stats { | ||
const result = this._statSync(path); | ||
return result || this._inputFileSystem.statSync(path); | ||
} | ||
|
||
readdirSync(path: string): string[] { | ||
const result = this._readDirSync(path); | ||
return result || this._inputFileSystem.readdirSync(path); | ||
} | ||
|
||
readFileSync(path: string): string { | ||
const result = this._readFileSync(path); | ||
return result || this._inputFileSystem.readFileSync(path); | ||
} | ||
|
||
readJsonSync(path: string): string { | ||
return this._inputFileSystem.readJsonSync(path); | ||
} | ||
|
||
readlinkSync(path: string): string { | ||
return this._inputFileSystem.readlinkSync(path); | ||
} | ||
|
||
purge(changes: string[]): void { | ||
changes.forEach((fileName: string) => this._webpackCompilerHost.invalidate(fileName)); | ||
if (this._inputFileSystem.purge) { | ||
this._inputFileSystem.purge(changes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters