From fca416e63f3ab6152cee822c13d4a8ebb9341001 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 6 Apr 2022 13:32:50 -0700 Subject: [PATCH] Fix legacy importer calls after relative imports (#125) 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 ?? '';