@@ -43,8 +43,6 @@ export interface Options {
43
43
typeCheck ?: boolean | null
44
44
transpileOnly ?: boolean | null
45
45
files ?: boolean | null
46
- cache ?: boolean | null
47
- cacheDirectory ?: string
48
46
compiler ?: string
49
47
ignore ?: string | string [ ]
50
48
project ?: string
@@ -79,9 +77,7 @@ export interface TypeInfo {
79
77
*/
80
78
export const DEFAULTS : Options = {
81
79
files : yn ( process . env [ 'TS_NODE_FILES' ] ) ,
82
- cache : yn ( process . env [ 'TS_NODE_CACHE' ] , { default : true } ) ,
83
80
pretty : yn ( process . env [ 'TS_NODE_PRETTY' ] ) ,
84
- cacheDirectory : process . env [ 'TS_NODE_CACHE_DIRECTORY' ] ,
85
81
compiler : process . env [ 'TS_NODE_COMPILER' ] ,
86
82
compilerOptions : parse ( process . env [ 'TS_NODE_COMPILER_OPTIONS' ] ) ,
87
83
ignore : split ( process . env [ 'TS_NODE_IGNORE' ] ) ,
@@ -150,7 +146,6 @@ export class TSError extends BaseError {
150
146
export interface Register {
151
147
cwd : string
152
148
extensions : string [ ]
153
- cachedir : string
154
149
ts : typeof ts
155
150
compile ( code : string , fileName : string , lineOffset ?: number ) : string
156
151
getTypeInfo ( code : string , fileName : string , position : number ) : TypeInfo
@@ -170,7 +165,6 @@ function getTmpDir (): string {
170
165
*/
171
166
export function register ( opts : Options = { } ) : Register {
172
167
const options = Object . assign ( { } , DEFAULTS , opts )
173
- const cacheDirectory = options . cacheDirectory || getTmpDir ( )
174
168
const originalJsHandler = require . extensions [ '.js' ]
175
169
176
170
const ignoreDiagnostics = arrify ( options . ignoreDiagnostics ) . concat ( [
@@ -210,18 +204,6 @@ export function register (opts: Options = {}): Register {
210
204
const extensions = [ '.ts' , '.tsx' ]
211
205
const fileNames = options . files ? config . fileNames : [ ]
212
206
213
- const cachedir = join (
214
- resolve ( cwd , cacheDirectory ) ,
215
- getCompilerDigest ( {
216
- version : ts . version ,
217
- options : config . options ,
218
- fileNames,
219
- typeCheck,
220
- ignoreDiagnostics,
221
- compiler
222
- } )
223
- )
224
-
225
207
const diagnosticHost : ts . FormatDiagnosticsHost = {
226
208
getNewLine : ( ) => EOL ,
227
209
getCurrentDirectory : ( ) => cwd ,
@@ -372,8 +354,15 @@ export function register (opts: Options = {}): Register {
372
354
}
373
355
}
374
356
375
- const compile = readThrough ( cachedir , options . cache === true , memoryCache , getOutput , getExtension )
376
- const register : Register = { cwd, compile, getTypeInfo, extensions, cachedir, ts }
357
+ // Create a simple TypeScript compiler proxy.
358
+ function compile ( code : string , fileName : string , lineOffset ?: number ) {
359
+ const [ value , sourceMap ] = getOutput ( code , fileName , lineOffset )
360
+ const output = updateOutput ( value , fileName , sourceMap , getExtension )
361
+ memoryCache . outputs [ fileName ] = output
362
+ return output
363
+ }
364
+
365
+ const register : Register = { cwd, compile, getTypeInfo, extensions, ts }
377
366
378
367
// Register the extensions.
379
368
extensions . forEach ( extension => {
@@ -494,57 +483,6 @@ function readConfig (
494
483
*/
495
484
type SourceOutput = [ string , string ]
496
485
497
- /**
498
- * Wrap the function with caching.
499
- */
500
- function readThrough (
501
- cachedir : string ,
502
- shouldCache : boolean ,
503
- memoryCache : MemoryCache ,
504
- compile : ( code : string , fileName : string , lineOffset ?: number ) => SourceOutput ,
505
- getExtension : ( fileName : string ) => string
506
- ) {
507
- if ( shouldCache === false ) {
508
- return function ( code : string , fileName : string , lineOffset ?: number ) {
509
- debug ( 'readThrough' , fileName )
510
-
511
- const [ value , sourceMap ] = compile ( code , fileName , lineOffset )
512
- const output = updateOutput ( value , fileName , sourceMap , getExtension )
513
-
514
- memoryCache . outputs [ fileName ] = output
515
-
516
- return output
517
- }
518
- }
519
-
520
- // Make sure the cache directory exists before continuing.
521
- mkdirp . sync ( cachedir )
522
-
523
- return function ( code : string , fileName : string , lineOffset ?: number ) {
524
- debug ( 'readThrough' , fileName )
525
-
526
- const cachePath = join ( cachedir , getCacheName ( code , fileName ) )
527
- const extension = getExtension ( fileName )
528
- const outputPath = `${ cachePath } ${ extension } `
529
-
530
- try {
531
- const output = readFileSync ( outputPath , 'utf8' )
532
- if ( isValidCacheContent ( output ) ) {
533
- memoryCache . outputs [ fileName ] = output
534
- return output
535
- }
536
- } catch ( err ) { /* Ignore. */ }
537
-
538
- const [ value , sourceMap ] = compile ( code , fileName , lineOffset )
539
- const output = updateOutput ( value , fileName , sourceMap , getExtension )
540
-
541
- memoryCache . outputs [ fileName ] = output
542
- writeFileSync ( outputPath , output )
543
-
544
- return output
545
- }
546
- }
547
-
548
486
/**
549
487
* Update the output remapping the source map.
550
488
*/
@@ -567,25 +505,6 @@ function updateSourceMap (sourceMapText: string, fileName: string) {
567
505
return JSON . stringify ( sourceMap )
568
506
}
569
507
570
- /**
571
- * Get the file name for the cache entry.
572
- */
573
- function getCacheName ( sourceCode : string , fileName : string ) {
574
- return crypto . createHash ( 'sha256' )
575
- . update ( extname ( fileName ) , 'utf8' )
576
- . update ( '\x00' , 'utf8' )
577
- . update ( sourceCode , 'utf8' )
578
- . digest ( 'hex' )
579
- }
580
-
581
- /**
582
- * Ensure the given cached content is valid by sniffing for a base64 encoded '}'
583
- * at the end of the content, which should exist if there is a valid sourceMap present.
584
- */
585
- function isValidCacheContent ( contents : string ) {
586
- return / (?: 9 | 0 = | Q = = ) $ / . test ( contents . slice ( - 3 ) )
587
- }
588
-
589
508
/**
590
509
* Create a hash of the current configuration.
591
510
*/
0 commit comments