From ca318b0d9794746ad39b0bcb18efb013133902ee Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Tue, 15 Oct 2024 13:45:34 -0700 Subject: [PATCH] Fix compatibility with older Node versions --- lib/src/legacy/utils.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/legacy/utils.ts b/lib/src/legacy/utils.ts index dda2bc1..c33f25a 100644 --- a/lib/src/legacy/utils.ts +++ b/lib/src/legacy/utils.ts @@ -8,6 +8,7 @@ import {pathToFileURL} from 'url'; import {fileUrlToPathCrossPlatform} from '../utils'; import {SourceSpan} from '../vendor/sass'; import {legacyImporterFileProtocol} from './importer'; +import { remove } from 'immutable'; /** * The URL protocol to use for URLs canonicalized using `LegacyImporterWrapper`. @@ -39,12 +40,12 @@ export function removeLegacyImporter(string: string): string { export function removeLegacyImporterFromSpan(span: SourceSpan): SourceSpan { if (!span.url) return span; const url = removeLegacyImporter(span.url.toString()); - return { - ...span, - url: URL.canParse(url) - ? new URL(url) - : new URL(url, `file://${process.cwd()}/`), - }; + try { + return {...span, url: new URL(url)}; + } catch (_) { + // Relative URL + return {...span, url: new URL(url, `file://${process.cwd()}`)}; + } } // Converts [path] to a `file:` URL and adds the [legacyImporterProtocolPrefix]