Skip to content

Commit 7e538f4

Browse files
committed
fix(resolve): fix ts resolve module for transpile sync
1 parent 93b53e2 commit 7e538f4

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

src/compiler/sys/resolve/resolve-module-sync.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,32 @@ export const resolveRemoteModuleIdSync = (config: d.Config, inMemoryFs: d.InMemo
2525
};
2626

2727
const 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

4244
export 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

5156
export const createCustomResolverSync = (sys: d.CompilerSystem, inMemoryFs: d.InMemoryFileSystem, exts: string[]): SyncOpts => {

0 commit comments

Comments
 (0)