Home Reference Source Test Repository
import FileChangedCache from 'electron-compile/src/file-change-cache.js'
public class | source

FileChangedCache

This class caches information about files and determines whether they have changed contents or not. Most importantly, this class caches the hash of seen files so that at development time, we don't have to recalculate them constantly.

This class is also the core of how electron-compile runs quickly in production mode - after precompilation, the cache is serialized along with the rest of the data in CompilerHost, so that when we load the app in production mode, we don't end up calculating hashes of file content at all, only using the contents of this cache.

Static Method Summary

Static Public Methods
public static

loadFromData(data: Object, appRoot: string, failOnCacheMiss: boolean): FileChangedCache

Allows you to create a FileChangedCache from serialized data saved from getSavedData.

public static

loadFromFile(file: string, appRoot: string, failOnCacheMiss: boolean): FileChangedCache

Allows you to create a FileChangedCache from serialized data saved from save.

Constructor Summary

Public Constructor
public

constructor(appRoot: *, failOnCacheMiss: boolean)

Member Summary

Public Members
public

appRoot: *

public
public

Method Summary

Public Methods
public

calculateHashForFile(absoluteFilePath: *): *

public

calculateHashForFileSync(absoluteFilePath: *): *

public

getHashForPath(absoluteFilePath: string): Object

Returns information about a given file, including its hash.

public

getHashForPathSync(absoluteFilePath: string): Object

Returns information about a given file, including its hash.

public

Returns data that can passed to loadFromData to rehydrate this cache.

public

save(filePath: string): Promise

Serializes this object's data to a file.

public

saveSync(filePath: string): Promise

Serializes this object's data to a file.

Static Public Methods

public static loadFromData(data: Object, appRoot: string, failOnCacheMiss: boolean): FileChangedCache source

Allows you to create a FileChangedCache from serialized data saved from getSavedData.

Params:

NameTypeAttributeDescription
data Object

Saved data from getSavedData.

appRoot string

The top-level directory for your application (i.e. the one which has your package.json).

failOnCacheMiss boolean

(optional) If True, cache misses will throw.

public static loadFromFile(file: string, appRoot: string, failOnCacheMiss: boolean): FileChangedCache source

Allows you to create a FileChangedCache from serialized data saved from save.

Params:

NameTypeAttributeDescription
file string

Saved data from save.

appRoot string

The top-level directory for your application (i.e. the one which has your package.json).

failOnCacheMiss boolean

(optional) If True, cache misses will throw.

Public Constructors

public constructor(appRoot: *, failOnCacheMiss: boolean) source

Params:

NameTypeAttributeDescription
appRoot *
failOnCacheMiss boolean
  • optional
  • default: false

Public Members

public appRoot: * source

public changeCache: * source

public failOnCacheMiss: * source

Public Methods

public calculateHashForFile(absoluteFilePath: *): * source

Params:

NameTypeAttributeDescription
absoluteFilePath *

Return:

*

public calculateHashForFileSync(absoluteFilePath: *): * source

Params:

NameTypeAttributeDescription
absoluteFilePath *

Return:

*

public getHashForPath(absoluteFilePath: string): Object source

Returns information about a given file, including its hash. This method is the main method for this cache.

Params:

NameTypeAttributeDescription
absoluteFilePath string

The path to a file to retrieve info on.

Return:

Object

Return Properties:

NameTypeAttributeDescription
hash string

The SHA1 hash of the file

isMinified boolean

True if the file is minified

isInNodeModules boolean

True if the file is in a library directory

hasSourceMap boolean

True if the file has a source map

isFileBinary boolean

True if the file is not a text file

binaryData Buffer

(optional) The buffer that was read if the file was binary and there was a cache miss.

code string

(optional) The string that was read if the file was text and there was a cache miss

public getHashForPathSync(absoluteFilePath: string): Object source

Returns information about a given file, including its hash. This method is the main method for this cache.

Params:

NameTypeAttributeDescription
absoluteFilePath string

The path to a file to retrieve info on.

Return:

Object

Return Properties:

NameTypeAttributeDescription
hash string

The SHA1 hash of the file

isMinified boolean

True if the file is minified

isInNodeModules boolean

True if the file is in a library directory

hasSourceMap boolean

True if the file has a source map

isFileBinary boolean

True if the file is not a text file

binaryData Buffer

(optional) The buffer that was read if the file was binary and there was a cache miss.

code string

(optional) The string that was read if the file was text and there was a cache miss

public getSavedData(): Object source

Returns data that can passed to loadFromData to rehydrate this cache.

Return:

Object

public save(filePath: string): Promise source

Serializes this object's data to a file.

Params:

NameTypeAttributeDescription
filePath string

The path to save data to.

Return:

Promise

Completion.

public saveSync(filePath: string): Promise source

Serializes this object's data to a file.

Params:

NameTypeAttributeDescription
filePath string

The path to save data to.

Return:

Promise

Completion.