Skip to content

Commit

Permalink
fix: @parcel/source-map default import
Browse files Browse the repository at this point in the history
  • Loading branch information
bashmish committed Aug 31, 2023
1 parent 5f0f3c9 commit 3337905
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-countries-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chialab/estransform": patch
---

Fix @parcel/source-map default import.
5 changes: 5 additions & 0 deletions packages/estransform/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ esbuild.build({
external: [
'@parcel/source-map',
],
banner: {
js: `import { createRequire as __moduleCreateRequire } from 'module';
const require = __moduleCreateRequire(import.meta.url);
`,
},
});
3 changes: 3 additions & 0 deletions packages/estransform/lib/parcel-source-map-default.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// we need to require the module for compatibility with the default export
// eslint-disable-next-line @typescript-eslint/no-var-requires
module.exports = require('@parcel/source-map').default;
8 changes: 5 additions & 3 deletions packages/estransform/lib/sourcemaps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { readFile } from 'fs/promises';
import path from 'path';
import sourceMapDefault from '@parcel/source-map';

const { default: SourceMapNode } = sourceMapDefault;
import SourceMapNode from './parcel-source-map-default.cjs';

const SOURCEMAP_REGEX = /(?:(\/\*+\s*?sourceMappingURL\s*=)([\s\S]*?)(\*\/))|(?:(\/\/#?\s*?sourceMappingURL\s*=)(.*?)([\r\n]|$))/;

Expand All @@ -17,6 +15,10 @@ const SOURCEMAP_REGEX = /(?:(\/\*+\s*?sourceMappingURL\s*=)([\s\S]*?)(\*\/))|(?:
* @property {string} [file]
*/

/**
* @typedef {import('@parcel/source-map').default} SourceMapNode
*/

/**
* @param {string} map
* @returns {SourceMap}
Expand Down
24 changes: 0 additions & 24 deletions packages/estransform/modules.d.ts
Original file line number Diff line number Diff line change
@@ -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';
}
Expand Down

0 comments on commit 3337905

Please sign in to comment.