Skip to content

Commit

Permalink
Revert "fix: improve sourcemap support"
Browse files Browse the repository at this point in the history
This reverts commit 5065082.
  • Loading branch information
gera2ld committed Jan 7, 2025
1 parent e46a803 commit dadbbd4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
},
"dependencies": {
"@babel/runtime": "^7.23.7",
"@jridgewell/sourcemap-codec": "^1.5.0",
"@rollup/pluginutils": "^5.1.0",
"estree-walker": "^3.0.3",
"is-reference": "^3.0.2"
"is-reference": "^3.0.2",
"magic-string": "^0.30.7"
},
"devDependencies": {
"@gera2ld/plaid": "~2.7.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 6 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { encode } from '@jridgewell/sourcemap-codec';
import { readFile } from 'fs/promises';
import MagicString from 'magic-string';
import type { Plugin } from 'rollup';
import { collectGmApi, getMetadata } from './util';

Expand Down Expand Up @@ -32,7 +32,7 @@ export default (transform?: (metadata: string) => string): Plugin => {
* Use `renderChunk` instead of `banner` to preserve the metadata after minimization.
* Note that this plugin must be put after `@rollup/plugin-terser`.
*/
async renderChunk(code, chunk, options) {
async renderChunk(code, chunk) {
const metadataFile =
chunk.isEntry &&
[chunk.facadeModuleId, ...Object.keys(chunk.modules)]
Expand All @@ -51,27 +51,11 @@ export default (transform?: (metadata: string) => string): Plugin => {
}
metadata = getMetadata(metadata, grantSet);
if (transform) metadata = transform(metadata);
let map = null;

if (options.sourcemap) {
const mappings = [
...Array.from(metadata.split('\n'), () => []),
[],
...Array.from(code.split('\n'), () => [[0, 0, 0, 0]]),
];
map = {
version: 3,
file: chunk.fileName,
sources: [chunk.fileName],
sourcesContent: [code],
names: [],
mappings: encode(mappings),
};
}

const s = new MagicString(code);
s.prepend(`${metadata}\n\n`);
return {
code: `${metadata}\n\n${code}`,
map,
code: s.toString(),
map: s.generateMap({ hires: 'boundary' }).toString(),
};
},
};
Expand Down

0 comments on commit dadbbd4

Please sign in to comment.