Skip to content

Commit dadbbd4

Browse files
committed
Revert "fix: improve sourcemap support"
This reverts commit 5065082.
1 parent e46a803 commit dadbbd4

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
},
3939
"dependencies": {
4040
"@babel/runtime": "^7.23.7",
41-
"@jridgewell/sourcemap-codec": "^1.5.0",
4241
"@rollup/pluginutils": "^5.1.0",
4342
"estree-walker": "^3.0.3",
44-
"is-reference": "^3.0.2"
43+
"is-reference": "^3.0.2",
44+
"magic-string": "^0.30.7"
4545
},
4646
"devDependencies": {
4747
"@gera2ld/plaid": "~2.7.0",

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { encode } from '@jridgewell/sourcemap-codec';
21
import { readFile } from 'fs/promises';
2+
import MagicString from 'magic-string';
33
import type { Plugin } from 'rollup';
44
import { collectGmApi, getMetadata } from './util';
55

@@ -32,7 +32,7 @@ export default (transform?: (metadata: string) => string): Plugin => {
3232
* Use `renderChunk` instead of `banner` to preserve the metadata after minimization.
3333
* Note that this plugin must be put after `@rollup/plugin-terser`.
3434
*/
35-
async renderChunk(code, chunk, options) {
35+
async renderChunk(code, chunk) {
3636
const metadataFile =
3737
chunk.isEntry &&
3838
[chunk.facadeModuleId, ...Object.keys(chunk.modules)]
@@ -51,27 +51,11 @@ export default (transform?: (metadata: string) => string): Plugin => {
5151
}
5252
metadata = getMetadata(metadata, grantSet);
5353
if (transform) metadata = transform(metadata);
54-
let map = null;
55-
56-
if (options.sourcemap) {
57-
const mappings = [
58-
...Array.from(metadata.split('\n'), () => []),
59-
[],
60-
...Array.from(code.split('\n'), () => [[0, 0, 0, 0]]),
61-
];
62-
map = {
63-
version: 3,
64-
file: chunk.fileName,
65-
sources: [chunk.fileName],
66-
sourcesContent: [code],
67-
names: [],
68-
mappings: encode(mappings),
69-
};
70-
}
71-
54+
const s = new MagicString(code);
55+
s.prepend(`${metadata}\n\n`);
7256
return {
73-
code: `${metadata}\n\n${code}`,
74-
map,
57+
code: s.toString(),
58+
map: s.generateMap({ hires: 'boundary' }).toString(),
7559
};
7660
},
7761
};

0 commit comments

Comments
 (0)