From 98f022cd08b2f3fddbbb3245c7824bbd6c3f5019 Mon Sep 17 00:00:00 2001 From: Mikhail Bashkirov Date: Thu, 31 Aug 2023 02:40:04 +0200 Subject: [PATCH] fix: @parcel/source-map default import --- .changeset/long-countries-count.md | 5 +++++ packages/estransform/lib/sourcemaps.js | 5 +++-- packages/estransform/modules.d.ts | 24 ------------------------ 3 files changed, 8 insertions(+), 26 deletions(-) create mode 100644 .changeset/long-countries-count.md diff --git a/.changeset/long-countries-count.md b/.changeset/long-countries-count.md new file mode 100644 index 00000000..33905f2f --- /dev/null +++ b/.changeset/long-countries-count.md @@ -0,0 +1,5 @@ +--- +"@chialab/estransform": patch +--- + +Fix @parcel/source-map default import. diff --git a/packages/estransform/lib/sourcemaps.js b/packages/estransform/lib/sourcemaps.js index ab1c8dbe..074b829d 100644 --- a/packages/estransform/lib/sourcemaps.js +++ b/packages/estransform/lib/sourcemaps.js @@ -1,8 +1,9 @@ import { readFile } from 'fs/promises'; +import { createRequire } from 'module'; import path from 'path'; -import sourceMapDefault from '@parcel/source-map'; -const { default: SourceMapNode } = sourceMapDefault; +const require = createRequire(import.meta.url); +const SourceMapNode = require('@parcel/source-map').default; const SOURCEMAP_REGEX = /(?:(\/\*+\s*?sourceMappingURL\s*=)([\s\S]*?)(\*\/))|(?:(\/\/#?\s*?sourceMappingURL\s*=)(.*?)([\r\n]|$))/; diff --git a/packages/estransform/modules.d.ts b/packages/estransform/modules.d.ts index 22f15d01..3837a55b 100644 --- a/packages/estransform/modules.d.ts +++ b/packages/estransform/modules.d.ts @@ -1,27 +1,3 @@ -declare type SourceMap = { - version?: number; - sources: string[]; - names: string[]; - sourceRoot?: string; - sourcesContent?: string[]; - mappings: string; - file?: string; -}; - -declare module '@parcel/source-map' { - class SourceMapNode { - setSourceContent(filename: string, contents: string); - addVLQMap(mapping: SourceMap); - extends(buffer: Buffer|SourceMapNode); - toVLQ(): SourceMap; - toBuffer(): Buffer; - } - - export default { - default: SourceMapNode, - }; -}; - declare module 'sucrase/dist/parser/index.js' { export { File, parse } from 'sucrase'; }