@@ -470,11 +470,10 @@ function getPlugins(
470470 // I'm going to port "art" to ES modules to avoid this problem.
471471 // Please don't enable this for anything else!
472472 isUMDBundle && entry === 'react-art' && commonjs ( ) ,
473- // License and haste headers, top-level `if` blocks.
474473 {
475- name : 'license-and-headers ' ,
474+ name : 'top-level-definitions ' ,
476475 renderChunk ( source ) {
477- return Wrappers . wrapBundle (
476+ return Wrappers . wrapWithTopLevelDefinitions (
478477 source ,
479478 bundleType ,
480479 globalName ,
@@ -517,6 +516,19 @@ function getPlugins(
517516 } ,
518517 { needsSourcemaps}
519518 ) ,
519+ // License and haste headers
520+ {
521+ name : 'license-and-signature-header' ,
522+ renderChunk ( source ) {
523+ return Wrappers . wrapWithLicenseHeader (
524+ source ,
525+ bundleType ,
526+ globalName ,
527+ filename ,
528+ moduleType
529+ ) ;
530+ } ,
531+ } ,
520532 // Add the whitespace back if necessary.
521533 shouldStayReadable &&
522534 prettier ( {
@@ -561,9 +573,32 @@ function getPlugins(
561573 // Because it sits on disk, there's no need to have it in the `sourcesContent` array.
562574 // That also makes the file easier to read, and available for use by scripts.
563575 // This should be the only file in the array.
564- const [ preMinifiedBundleSource ] =
576+ const [ preMinifiedBundleSourceWithoutLicense ] =
565577 sourcemapAfterClosure . sourcesContent ;
566578
579+ // We were passing sources without license headers to the Closure compiler.
580+ // The reason for it is its optimization for multiline comment:
581+ // it will change the format by removing * prefixes This doesn't work well with Haste.
582+ const preMinifiedBundleSource = Wrappers . wrapWithLicenseHeader (
583+ preMinifiedBundleSourceWithoutLicense ,
584+ bundleType ,
585+ globalName ,
586+ filename ,
587+ moduleType
588+ ) ;
589+
590+ // Update the lineCount field, since we've added the license header
591+ // to the minified source, but Closure didn't know about it.
592+ const sourceCodeLines = codeAfterLicense . split ( / \r \n | \r | \n / ) ;
593+ // There is probably an empty line at the end after the Prettier run
594+ while (
595+ sourceCodeLines . length > 0 &&
596+ sourceCodeLines [ sourceCodeLines . length - 1 ] === ''
597+ ) {
598+ sourceCodeLines . pop ( ) ;
599+ }
600+ sourcemapAfterClosure . lineCount = sourceCodeLines . length ;
601+
567602 // Remove this entirely - we're going to write the file to disk instead.
568603 delete sourcemapAfterClosure . sourcesContent ;
569604
0 commit comments