From b8e07ec2a2546efe2dceda21899168b22051d200 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 5 Apr 2022 17:44:55 -0700 Subject: [PATCH] Fix legacy importer calls after relative imports Closes #120 --- lib/src/legacy/importer.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/src/legacy/importer.ts b/lib/src/legacy/importer.ts index 44eef795..09438e38 100644 --- a/lib/src/legacy/importer.ts +++ b/lib/src/legacy/importer.ts @@ -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 { @@ -96,7 +97,10 @@ export class LegacyImporterWrapper 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; @@ -111,6 +115,13 @@ export class LegacyImporterWrapper 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 ?? '';