Skip to content

Commit

Permalink
fix: sourcemap url in bundless mode (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
2239559319 committed Dec 6, 2022
1 parent 462b17a commit a96c02a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/builder/utils.ts
Expand Up @@ -6,7 +6,7 @@ export function addSourceMappingUrl(code: string, loc: string) {
return (
code +
'\n//# sourceMappingURL=' +
path.basename(loc.replace(/\.(jsx|tsx?)$/, '.js'))
path.basename(loc.replace(/\.(jsx|tsx?)$/, '.js.map'))
);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/build/build-sourcemap/expect.ts
Expand Up @@ -9,6 +9,8 @@ export default (files: Record<string, string>) => {

// esm transform by babel
expect('esm/index.js.map' in files).toBe(true);
expect(files['esm/index.js']).toContain('//# sourceMappingURL=index.js.map');

const map1 = JSON.parse(
readFileSync(join(__dirname, 'dist/esm/index.js.map'), 'utf-8'),
);
Expand All @@ -21,6 +23,7 @@ export default (files: Record<string, string>) => {

// cjs transform by esbuild
expect('cjs/index.js.map' in files).toBe(true);
expect(files['cjs/index.js']).toContain('//# sourceMappingURL=index.js.map');
const map3 = JSON.parse(
readFileSync(join(__dirname, 'dist/cjs/index.js.map'), 'utf-8'),
);
Expand Down
7 changes: 5 additions & 2 deletions tests/fixtures/build/bundless-swc-sourcemap/expect.ts
Expand Up @@ -7,8 +7,10 @@ export default (files: Record<string, string>) => {
'//# sourceMappingURL=index.min.js.map',
);

// esm transform by babel
// esm transform by swc
expect('esm/index.js.map' in files).toBe(true);
expect(files['esm/index.js']).toContain('//# sourceMappingURL=index.js.map');

const map1 = JSON.parse(
readFileSync(join(__dirname, 'dist/esm/index.js.map'), 'utf-8'),
);
Expand All @@ -19,8 +21,9 @@ export default (files: Record<string, string>) => {
);
expect(map2.sources[0]).toEqual('../../../src/utils/index.ts');

// cjs transform by esbuild
// cjs transform by swc
expect('cjs/index.js.map' in files).toBe(true);
expect(files['cjs/index.js']).toContain('//# sourceMappingURL=index.js.map');
const map3 = JSON.parse(
readFileSync(join(__dirname, 'dist/cjs/index.js.map'), 'utf-8'),
);
Expand Down

0 comments on commit a96c02a

Please sign in to comment.