Skip to content

Commit

Permalink
Fix legacy importer calls after relative imports
Browse files Browse the repository at this point in the history
Closes #120
  • Loading branch information
nex3 committed Apr 6, 2022
1 parent 921b83e commit b8e07ec
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/src/legacy/importer.ts
Expand Up @@ -6,6 +6,7 @@ import {strict as assert} from 'assert';
import {pathToFileURL, URL as NodeURL} from 'url';
import * as fs from 'fs';
import * as p from 'path';
import * as util from 'util';

import {resolvePath} from './resolve-path';
import {
Expand Down Expand Up @@ -96,7 +97,10 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
fileUrlToPathCrossPlatform(url),
options.fromImport
);
if (resolved !== null) return pathToFileURL(resolved);
if (resolved !== null) {
this.prev.push({url: resolved, path: true});
return pathToFileURL(resolved);
}
}

this.expectingRelativeLoad = false;
Expand All @@ -111,6 +115,13 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
if (result instanceof Error) throw result;
if (result === null) return null;

if (typeof result !== 'object') {
throw (
'Expected importer to return an object, got ' +
`${util.inspect(result)}.`
);
}

if ('contents' in result || !('file' in result)) {
this.lastContents = result.contents ?? '';

Expand Down

0 comments on commit b8e07ec

Please sign in to comment.