6
6
*
7
7
* @see https://github.com/babel/babel-loader/
8
8
*/
9
- import * as fs from "fs"
10
- import * as os from "os"
11
- import * as path from " path"
12
- import * as zlib from " zlib"
13
- import * as crypto from " crypto"
14
- import * as findCacheDir from " find-cache-dir"
15
- import * as makeDir from " make-dir"
16
- import { promisify } from " util"
17
- import { CacheOptions , TransformParams } from " ./types"
18
- import { transform } from "."
9
+ import * as fs from 'fs'
10
+ import * as os from 'os'
11
+ import * as path from ' path'
12
+ import * as zlib from ' zlib'
13
+ import * as crypto from ' crypto'
14
+ import * as findCacheDir from ' find-cache-dir'
15
+ import * as makeDir from ' make-dir'
16
+ import { promisify } from ' util'
17
+ import { CacheOptions , TransformParams } from ' ./types'
18
+ import { transform } from '.'
19
19
20
20
// Lazily instantiated when needed
21
21
let defaultCacheDirectory : string | null = null
@@ -33,7 +33,7 @@ const gzip = promisify(zlib.gzip)
33
33
* @params {Boolean} compress
34
34
*/
35
35
const read = async function ( filename : string , compress : boolean ) {
36
- const data = await readFile ( filename + ( compress ? " .gz" : "" ) )
36
+ const data = await readFile ( filename + ( compress ? ' .gz' : '' ) )
37
37
const content = compress ? await gunzip ( data ) : data
38
38
39
39
return JSON . parse ( content . toString ( ) )
@@ -51,7 +51,7 @@ const write = async function (filename: string, compress: boolean, result: strin
51
51
const content = JSON . stringify ( result )
52
52
53
53
const data = compress ? await gzip ( content ) : content
54
- return await writeFile ( filename + ( compress ? " .gz" : "" ) , data )
54
+ return await writeFile ( filename + ( compress ? ' .gz' : '' ) , data )
55
55
}
56
56
57
57
/**
@@ -63,13 +63,13 @@ const write = async function (filename: string, compress: boolean, result: strin
63
63
* @return {String }
64
64
*/
65
65
const filename = function ( source : string , identifier : string ) {
66
- const hash = crypto . createHash ( " md4" )
66
+ const hash = crypto . createHash ( ' md4' )
67
67
68
68
const contents = JSON . stringify ( { source, identifier } )
69
69
70
70
hash . update ( contents )
71
71
72
- return hash . digest ( " hex" ) + " .json"
72
+ return hash . digest ( ' hex' ) + ' .json'
73
73
}
74
74
75
75
/**
@@ -95,7 +95,7 @@ const handleCache = async function (
95
95
// continue regardless of error
96
96
}
97
97
98
- const fallback = typeof cacheDirectory !== " string" && directory !== os . tmpdir ( )
98
+ const fallback = typeof cacheDirectory !== ' string' && directory !== os . tmpdir ( )
99
99
100
100
// Make sure the directory exists.
101
101
try {
@@ -138,11 +138,11 @@ const handleCache = async function (
138
138
export async function cache ( cacheOptions : CacheOptions , transformParams : TransformParams ) : Promise < string > {
139
139
let directory
140
140
141
- if ( typeof cacheOptions . cacheDirectory === " string" ) {
141
+ if ( typeof cacheOptions . cacheDirectory === ' string' ) {
142
142
directory = cacheOptions . cacheDirectory
143
143
} else {
144
144
if ( defaultCacheDirectory === null ) {
145
- defaultCacheDirectory = findCacheDir ( { name : " responsive-loader" } ) || os . tmpdir ( )
145
+ defaultCacheDirectory = findCacheDir ( { name : ' responsive-loader' } ) || os . tmpdir ( )
146
146
}
147
147
148
148
directory = defaultCacheDirectory
0 commit comments