@@ -37,7 +37,6 @@ import * as ts from "./typescript";
3737import * as ast_extractor from "./ast_extractor" ;
3838
3939import { Project } from "./common" ;
40- import { VirtualSourceRoot } from "./virtual_source_root" ;
4140
4241// Remove limit on stack trace depth.
4342Error . stackTraceLimit = Infinity ;
@@ -46,13 +45,6 @@ interface ParseCommand {
4645 command : "parse" ;
4746 filename : string ;
4847}
49- interface LoadCommand {
50- tsConfig : string ;
51- sourceRoot : string | null ;
52- virtualSourceRoot : string | null ;
53- packageEntryPoints : [ string , string ] [ ] ;
54- packageJsonFiles : [ string , string ] [ ] ;
55- }
5648interface ResetCommand {
5749 command : "reset" ;
5850}
@@ -340,98 +332,6 @@ function parseSingleFile(filename: string): { ast: ts.SourceFile, code: string }
340332 return { ast, code } ;
341333}
342334
343- /**
344- * Matches a path segment referencing a package in a node_modules folder, and extracts
345- * two capture groups: the package name, and the relative path in the package.
346- *
347- * For example `lib/node_modules/@foo/bar/src/index.js` extracts the capture groups [`@foo/bar`, `src/index.js`].
348- */
349- const nodeModulesRex = / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] ( (?: @ [ \w . - ] + [ / \\ ] ) ? \w [ \w . - ] * ) [ / \\ ] ( .* ) / ;
350-
351- interface LoadedConfig {
352- config : ts . ParsedCommandLine ;
353- basePath : string ;
354- packageEntryPoints : Map < string , string > ;
355- packageJsonFiles : Map < string , string > ;
356- virtualSourceRoot : VirtualSourceRoot ;
357- ownFiles : string [ ] ;
358- }
359-
360- function loadTsConfig ( command : LoadCommand ) : LoadedConfig {
361- let tsConfig = ts . readConfigFile ( command . tsConfig , ts . sys . readFile ) ;
362- let basePath = pathlib . dirname ( command . tsConfig ) ;
363-
364- let packageEntryPoints = new Map ( command . packageEntryPoints ) ;
365- let packageJsonFiles = new Map ( command . packageJsonFiles ) ;
366- let virtualSourceRoot = new VirtualSourceRoot ( command . sourceRoot , command . virtualSourceRoot ) ;
367-
368- /**
369- * Rewrites path segments of form `node_modules/PACK/suffix` to be relative to
370- * the location of package PACK in the source tree, if it exists.
371- */
372- function redirectNodeModulesPath ( path : string ) {
373- let nodeModulesMatch = nodeModulesRex . exec ( path ) ;
374- if ( nodeModulesMatch == null ) return null ;
375- let packageName = nodeModulesMatch [ 1 ] ;
376- let packageJsonFile = packageJsonFiles . get ( packageName ) ;
377- if ( packageJsonFile == null ) return null ;
378- let packageDir = pathlib . dirname ( packageJsonFile ) ;
379- let suffix = nodeModulesMatch [ 2 ] ;
380- let finalPath = pathlib . join ( packageDir , suffix ) ;
381- if ( ! ts . sys . fileExists ( finalPath ) ) return null ;
382- return finalPath ;
383- }
384-
385- /**
386- * Create the host passed to the tsconfig.json parser.
387- *
388- * We override its file system access in case there is an "extends"
389- * clause pointing into "./node_modules", which must be redirected to
390- * the location of an installed package or a checked-in package.
391- */
392- let parseConfigHost : ts . ParseConfigHost = {
393- useCaseSensitiveFileNames : true ,
394- readDirectory : ( rootDir , extensions , excludes ?, includes ?, depth ?) => {
395- // Perform the glob matching in both real and virtual source roots.
396- let exclusions = excludes == null ? [ ] : [ ...excludes ] ;
397- if ( virtualSourceRoot . virtualSourceRoot != null ) {
398- // qltest puts the virtual source root inside the real source root (.testproj).
399- // Make sure we don't find files inside the virtual source root in this pass.
400- exclusions . push ( virtualSourceRoot . virtualSourceRoot ) ;
401- }
402- let originalResults = ts . sys . readDirectory ( rootDir , extensions , exclusions , includes , depth )
403- let virtualDir = virtualSourceRoot . toVirtualPath ( rootDir ) ;
404- if ( virtualDir == null ) {
405- return originalResults ;
406- }
407- // Make sure glob matching does not to discover anything in node_modules.
408- let virtualExclusions = excludes == null ? [ ] : [ ...excludes ] ;
409- virtualExclusions . push ( '**/node_modules/**/*' ) ;
410- let virtualResults = ts . sys . readDirectory ( virtualDir , extensions , virtualExclusions , includes , depth )
411- return [ ...originalResults , ...virtualResults ] ;
412- } ,
413- fileExists : ( path : string ) => {
414- return ts . sys . fileExists ( path )
415- || virtualSourceRoot . toVirtualPathIfFileExists ( path ) != null
416- || redirectNodeModulesPath ( path ) != null ;
417- } ,
418- readFile : ( path : string ) => {
419- if ( ! ts . sys . fileExists ( path ) ) {
420- let virtualPath = virtualSourceRoot . toVirtualPathIfFileExists ( path ) ;
421- if ( virtualPath != null ) return ts . sys . readFile ( virtualPath ) ;
422- virtualPath = redirectNodeModulesPath ( path ) ;
423- if ( virtualPath != null ) return ts . sys . readFile ( virtualPath ) ;
424- }
425- return ts . sys . readFile ( path ) ;
426- }
427- } ;
428- let config = ts . parseJsonConfigFileContent ( tsConfig . config , parseConfigHost , basePath ) ;
429-
430- let ownFiles = config . fileNames . map ( file => pathlib . resolve ( file ) ) ;
431-
432- return { config, basePath, packageJsonFiles, packageEntryPoints, virtualSourceRoot, ownFiles } ;
433- }
434-
435335function handleResetCommand ( command : ResetCommand ) {
436336 reset ( ) ;
437337 console . log ( JSON . stringify ( {
0 commit comments