@@ -1659,11 +1659,7 @@ export interface WorkflowBundleWithSourceMapAndFilename {
1659
1659
}
1660
1660
1661
1661
export function parseWorkflowCode ( code : string , codePath ?: string ) : WorkflowBundleWithSourceMapAndFilename {
1662
- const sourceMappingUrlDataRegex = / \s * \n [ / ] [ / ] [ # ] \s + s o u r c e M a p p i n g U R L = d a t a : (?: [ ^ , ] * ; ) b a s e 6 4 , ( [ 0 - 9 A - Z a - z + / = ] + ) \s * $ / ;
1663
- const sourceMapMatcher = code . match ( sourceMappingUrlDataRegex ) ;
1664
- if ( ! sourceMapMatcher ) throw new Error ( "Can't extract inlined source map from the provided Workflow Bundle" ) ;
1665
-
1666
- const sourceMapJson = Buffer . from ( sourceMapMatcher [ 1 ] , 'base64' ) . toString ( ) ;
1662
+ const [ actualCode , sourceMapJson ] = extractSourceMap ( code ) ;
1667
1663
const sourceMap : RawSourceMap = JSON . parse ( sourceMapJson ) ;
1668
1664
1669
1665
// JS debuggers (at least VSCode's) have a few requirements regarding the script and its source map, notably:
@@ -1675,7 +1671,7 @@ export function parseWorkflowCode(code: string, codePath?: string): WorkflowBund
1675
1671
sourceMap . file = filename ;
1676
1672
const patchedSourceMapJson = Buffer . from ( JSON . stringify ( sourceMap ) ) . toString ( 'base64' ) ;
1677
1673
const fixedSourceMappingUrl = `\n//# sourceMappingURL=data:application/json;base64,${ patchedSourceMapJson } ` ;
1678
- code = code . slice ( 0 , - sourceMapMatcher [ 1 ] . length ) + fixedSourceMappingUrl ;
1674
+ code = actualCode + fixedSourceMappingUrl ;
1679
1675
}
1680
1676
1681
1677
// Preloading the script makes breakpoints significantly more reliable and more responsive
@@ -1697,6 +1693,20 @@ export function parseWorkflowCode(code: string, codePath?: string): WorkflowBund
1697
1693
return { code, sourceMap, filename } ;
1698
1694
}
1699
1695
1696
+ function extractSourceMap ( code : string ) {
1697
+ const sourceMapCommentPos = code . lastIndexOf ( '//# sourceMappingURL=data:' ) ;
1698
+ if ( sourceMapCommentPos > 0 ) {
1699
+ const base64TagIndex = code . indexOf ( 'base64,' , sourceMapCommentPos ) ;
1700
+ if ( base64TagIndex > 0 ) {
1701
+ const sourceMapJson = Buffer . from ( code . slice ( base64TagIndex + 'base64,' . length ) . trimEnd ( ) , 'base64' ) . toString ( ) ;
1702
+ const actualCode = code . slice ( 0 , sourceMapCommentPos ) ;
1703
+ return [ actualCode , sourceMapJson ] ;
1704
+ }
1705
+ }
1706
+
1707
+ throw new Error ( "Can't extract inlined source map from the provided Workflow Bundle" ) ;
1708
+ }
1709
+
1700
1710
type NonNullableObject < T > = { [ P in keyof T ] -?: NonNullable < T [ P ] > } ;
1701
1711
1702
1712
/**
0 commit comments