Skip to content

Commit

Permalink
fix(resolve): fix ts resolve module for transpile sync
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 28, 2020
1 parent 93b53e2 commit 7e538f4
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/compiler/sys/resolve/resolve-module-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,32 @@ export const resolveRemoteModuleIdSync = (config: d.Config, inMemoryFs: d.InMemo
};

const resolveRemotePackageJsonSync = (config: d.Config, inMemoryFs: d.InMemoryFileSystem, moduleId: string) => {
const filePath = normalizePath(config.sys.getLocalModulePath({ rootDir: config.rootDir, moduleId, path: 'package.json' }));
let pkgJson = inMemoryFs.readFileSync(filePath);
if (!isString(pkgJson) && IS_WEB_WORKER_ENV) {
const url = config.sys.getRemoteModuleUrl({ moduleId, path: 'package.json' });
pkgJson = fetchModuleSync(config.sys, inMemoryFs, packageVersions, url, filePath);
}
if (typeof pkgJson === 'string') {
try {
return JSON.parse(pkgJson) as d.PackageJsonData;
} catch (e) {}
if (inMemoryFs) {
const filePath = normalizePath(config.sys.getLocalModulePath({ rootDir: config.rootDir, moduleId, path: 'package.json' }));
let pkgJson = inMemoryFs.readFileSync(filePath);
if (!isString(pkgJson) && IS_WEB_WORKER_ENV) {
const url = config.sys.getRemoteModuleUrl({ moduleId, path: 'package.json' });
pkgJson = fetchModuleSync(config.sys, inMemoryFs, packageVersions, url, filePath);
}
if (typeof pkgJson === 'string') {
try {
return JSON.parse(pkgJson) as d.PackageJsonData;
} catch (e) {}
}
}
return null;
};

export const resolveModuleIdSync = (sys: d.CompilerSystem, inMemoryFs: d.InMemoryFileSystem, opts: d.ResolveModuleIdOptions) => {
const resolverOpts = createCustomResolverSync(sys, inMemoryFs, opts.exts);
resolverOpts.basedir = dirname(opts.containingFile);
resolverOpts.packageFilter = opts.packageFilter;
if (inMemoryFs) {
const resolverOpts = createCustomResolverSync(sys, inMemoryFs, opts.exts);
resolverOpts.basedir = dirname(opts.containingFile);
resolverOpts.packageFilter = opts.packageFilter;

const resolvedModule = resolve.sync(opts.moduleId, resolverOpts);
return resolvedModule;
const resolvedModule = resolve.sync(opts.moduleId, resolverOpts);
return resolvedModule;
}
return null;
};

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

0 comments on commit 7e538f4

Please sign in to comment.