@@ -57,56 +57,6 @@ function maybeWindowsPath(path) {
5757 return '//?/' + resolve ( path ) . replace ( / \\ / g, '/' ) ;
5858}
5959
60- /**
61- * Clean up the given input string by removing the given patterns if
62- * found as line prefixes.
63- */
64- function stripLinesPrefixes ( input , prefixPatterns ) {
65- return input
66- . split ( '\n' )
67- . map ( ( line ) =>
68- prefixPatterns . reduce ( ( line , n ) => line . replace ( n , '' ) , line ) ,
69- )
70- . join ( '\n' )
71- . trim ( ) ;
72- }
73-
74- const WizerErrorCause = `Error: the \`componentize.wizer\` function trapped
75-
76- Caused by:` ;
77-
78- const WizerExitCode = 'Exited with i32 exit status' ;
79-
80- function parseWizerStderr ( stderr ) {
81- let output = `${ stderr } ` ;
82- let causeStart = output . indexOf ( WizerErrorCause ) ;
83- let exitCodeStart = output . indexOf ( WizerExitCode ) ;
84- if ( causeStart === - 1 || exitCodeStart === - 1 ) {
85- return output ;
86- }
87-
88- let causeEnd = output . indexOf ( '\n' , exitCodeStart + 1 ) ;
89- return `${ output . substring ( 0 , causeStart ) } ${ output . substring ( causeEnd ) } ` . trim ( ) ;
90- }
91-
92- /**
93- * Check whether a value is numeric (including BigInt)
94- *
95- * @param {any } n
96- * @returns {boolean } whether the value is numeric
97- */
98- function isNumeric ( n ) {
99- switch ( typeof n ) {
100- case 'bigint' :
101- case 'number' :
102- return true ;
103- case 'object' :
104- return n . constructor == BigInt || n . constructor == Number ;
105- default :
106- return false ;
107- }
108- }
109-
11060export async function componentize (
11161 opts ,
11262 _deprecatedWitWorldOrOpts = undefined ,
@@ -497,3 +447,54 @@ function defaultMinStackSize(freeMemoryBytes) {
497447 freeMemoryBytes = freeMemoryBytes ?? freemem ( ) ;
498448 return Math . max ( 8 * 1024 * 1024 , Math . floor ( freeMemoryBytes * 0.1 ) ) ;
499449}
450+
451+ /**
452+ * Clean up the given input string by removing the given patterns if
453+ * found as line prefixes.
454+ */
455+ function stripLinesPrefixes ( input , prefixPatterns ) {
456+ return input
457+ . split ( '\n' )
458+ . map ( ( line ) =>
459+ prefixPatterns . reduce ( ( line , n ) => line . replace ( n , '' ) , line ) ,
460+ )
461+ . join ( '\n' )
462+ . trim ( ) ;
463+ }
464+
465+ /**
466+ * Parse output of post-processing step (whether Wizer or Weval)
467+ *
468+ * @param {Stream } stderr
469+ * @returns {string } String that can be printed to describe error output
470+ */
471+ function parseWizerStderr ( stderr ) {
472+ let output = `${ stderr } ` ;
473+ let causeStart = output . indexOf ( WIZER_ERROR_CAUSE_PREFIX ) ;
474+ let exitCodeStart = output . indexOf ( WIZER_EXIT_CODE_PREFIX ) ;
475+ if ( causeStart === - 1 || exitCodeStart === - 1 ) {
476+ return output ;
477+ }
478+
479+ let causeEnd = output . indexOf ( '\n' , exitCodeStart + 1 ) ;
480+ return `${ output . substring ( 0 , causeStart ) } ${ output . substring ( causeEnd ) } ` . trim ( ) ;
481+ }
482+
483+ /**
484+ * Check whether a value is numeric (including BigInt)
485+ *
486+ * @param {any } n
487+ * @returns {boolean } whether the value is numeric
488+ */
489+ function isNumeric ( n ) {
490+ switch ( typeof n ) {
491+ case 'bigint' :
492+ case 'number' :
493+ return true ;
494+ case 'object' :
495+ return n . constructor == BigInt || n . constructor == Number ;
496+ default :
497+ return false ;
498+ }
499+ }
500+
0 commit comments