1- import slash from ' slash' ;
1+ import slash from " slash" ;
22import { promises } from "fs" ;
33import { dirname , relative } from "path" ;
44import { transformFile , transformFileSync } from "@swc/core" ;
55import type { Options , Output } from "@swc/core" ;
66
7- const {
8- mkdir,
9- stat,
10- writeFile
11- } = promises ;
7+ const { mkdir, stat, writeFile } = promises ;
128
13- function withSourceMap ( output : Output , options : Options , destFile : string , destDir : string ) {
9+ function withSourceMap (
10+ output : Output ,
11+ options : Options ,
12+ destFile : string ,
13+ destDir : string
14+ ) {
1415 if ( ! output . map || options . sourceMaps === "inline" ) {
1516 return {
1617 sourceCode : output . code ,
17- }
18+ } ;
1819 }
1920 // TODO: remove once fixed in core https://github.com/swc-project/swc/issues/1388
2021 const sourceMap = JSON . parse ( output . map ) ;
2122 if ( options . sourceFileName ) {
22- sourceMap [ ' sources' ] [ 0 ] = options . sourceFileName ;
23+ sourceMap [ " sources" ] [ 0 ] = options . sourceFileName ;
2324 }
2425 if ( options . sourceRoot ) {
25- sourceMap [ ' sourceRoot' ] = options . sourceRoot ;
26+ sourceMap [ " sourceRoot" ] = options . sourceRoot ;
2627 }
2728 output . map = JSON . stringify ( sourceMap ) ;
2829
2930 const sourceMapPath = destFile + ".map" ;
30- output . code += `\n//# sourceMappingURL=${ slash ( relative ( destDir , sourceMapPath ) ) } ` ;
31+ output . code += `\n//# sourceMappingURL=${ slash (
32+ relative ( destDir , sourceMapPath )
33+ ) } `;
3134
3235 return {
3336 sourceMap : output . map ,
3437 sourceMapPath,
35- sourceCode : output . code
36- }
38+ sourceCode : output . code ,
39+ } ;
3740}
3841
3942export async function outputResult (
@@ -44,11 +47,12 @@ export async function outputResult(
4447) {
4548 const destDir = dirname ( destFile ) ;
4649
47- const {
48- sourceMap,
49- sourceMapPath,
50- sourceCode
51- } = withSourceMap ( output , options , destFile , destDir ) ;
50+ const { sourceMap, sourceMapPath, sourceCode } = withSourceMap (
51+ output ,
52+ options ,
53+ destFile ,
54+ destDir
55+ ) ;
5256
5357 await mkdir ( destDir , { recursive : true } ) ;
5458 const { mode } = await stat ( sourceFile ) ;
@@ -58,7 +62,7 @@ export async function outputResult(
5862 } else {
5963 await Promise . all ( [
6064 writeFile ( destFile , sourceCode , { mode } ) ,
61- writeFile ( sourceMapPath , sourceMap , { mode } )
65+ writeFile ( sourceMapPath , sourceMap , { mode } ) ,
6266 ] ) ;
6367 }
6468}
@@ -80,7 +84,7 @@ export async function compile(
8084 : await transformFile ( filename , options ) ;
8185
8286 return result ;
83- } catch ( err ) {
87+ } catch ( err : any ) {
8488 if ( ! err . message . includes ( "ignored by .swcrc" ) ) {
8589 throw err ;
8690 }
0 commit comments