@@ -25,27 +25,32 @@ export const resolveRemoteModuleIdSync = (config: d.Config, inMemoryFs: d.InMemo
2525} ;
2626
2727const resolveRemotePackageJsonSync = ( config : d . Config , inMemoryFs : d . InMemoryFileSystem , moduleId : string ) => {
28- const filePath = normalizePath ( config . sys . getLocalModulePath ( { rootDir : config . rootDir , moduleId, path : 'package.json' } ) ) ;
29- let pkgJson = inMemoryFs . readFileSync ( filePath ) ;
30- if ( ! isString ( pkgJson ) && IS_WEB_WORKER_ENV ) {
31- const url = config . sys . getRemoteModuleUrl ( { moduleId, path : 'package.json' } ) ;
32- pkgJson = fetchModuleSync ( config . sys , inMemoryFs , packageVersions , url , filePath ) ;
33- }
34- if ( typeof pkgJson === 'string' ) {
35- try {
36- return JSON . parse ( pkgJson ) as d . PackageJsonData ;
37- } catch ( e ) { }
28+ if ( inMemoryFs ) {
29+ const filePath = normalizePath ( config . sys . getLocalModulePath ( { rootDir : config . rootDir , moduleId, path : 'package.json' } ) ) ;
30+ let pkgJson = inMemoryFs . readFileSync ( filePath ) ;
31+ if ( ! isString ( pkgJson ) && IS_WEB_WORKER_ENV ) {
32+ const url = config . sys . getRemoteModuleUrl ( { moduleId, path : 'package.json' } ) ;
33+ pkgJson = fetchModuleSync ( config . sys , inMemoryFs , packageVersions , url , filePath ) ;
34+ }
35+ if ( typeof pkgJson === 'string' ) {
36+ try {
37+ return JSON . parse ( pkgJson ) as d . PackageJsonData ;
38+ } catch ( e ) { }
39+ }
3840 }
3941 return null ;
4042} ;
4143
4244export const resolveModuleIdSync = ( sys : d . CompilerSystem , inMemoryFs : d . InMemoryFileSystem , opts : d . ResolveModuleIdOptions ) => {
43- const resolverOpts = createCustomResolverSync ( sys , inMemoryFs , opts . exts ) ;
44- resolverOpts . basedir = dirname ( opts . containingFile ) ;
45- resolverOpts . packageFilter = opts . packageFilter ;
45+ if ( inMemoryFs ) {
46+ const resolverOpts = createCustomResolverSync ( sys , inMemoryFs , opts . exts ) ;
47+ resolverOpts . basedir = dirname ( opts . containingFile ) ;
48+ resolverOpts . packageFilter = opts . packageFilter ;
4649
47- const resolvedModule = resolve . sync ( opts . moduleId , resolverOpts ) ;
48- return resolvedModule ;
50+ const resolvedModule = resolve . sync ( opts . moduleId , resolverOpts ) ;
51+ return resolvedModule ;
52+ }
53+ return null ;
4954} ;
5055
5156export const createCustomResolverSync = ( sys : d . CompilerSystem , inMemoryFs : d . InMemoryFileSystem , exts : string [ ] ) : SyncOpts => {
0 commit comments