Skip to content

Commit a21c5af

Browse files
committed
refactor[ci/build]: preserve header format in artifacts
1 parent 52d542a commit a21c5af

2 files changed

Lines changed: 246 additions & 113 deletions

File tree

scripts/rollup/build.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
@@ -484,6 +483,21 @@ function getPlugins(
484483
);
485484
},
486485
},
486+
// License and haste headers for artifacts with sourcemaps
487+
// For artifacts with sourcemaps we apply these headers
488+
// before passing sources to the Closure compiler, which will be building sourcemaps
489+
needsSourcemaps && {
490+
name: 'license-and-signature-header-for-artifacts-with-sourcemaps',
491+
renderChunk(source) {
492+
return Wrappers.wrapWithLicenseHeader(
493+
source,
494+
bundleType,
495+
globalName,
496+
filename,
497+
moduleType
498+
);
499+
},
500+
},
487501
// Apply dead code elimination and/or minification.
488502
// closure doesn't yet support leaving ESM imports intact
489503
needsMinifiedByClosure &&
@@ -527,7 +541,7 @@ function getPlugins(
527541
}),
528542
needsSourcemaps && {
529543
name: 'generate-prod-bundle-sourcemaps',
530-
async renderChunk(codeAfterLicense, chunk, options, meta) {
544+
async renderChunk(minifiedCodeWithChangedHeader, chunk, options, meta) {
531545
// We want to generate a sourcemap that shows the production bundle source
532546
// as it existed before Closure Compiler minified that chunk, rather than
533547
// showing the "original" individual source files. This better shows
@@ -583,7 +597,7 @@ function getPlugins(
583597

584598
// Add the sourcemap URL to the actual bundle, so that tools pick it up
585599
const sourceWithMappingUrl =
586-
codeAfterLicense +
600+
minifiedCodeWithChangedHeader +
587601
`\n//# sourceMappingURL=${finalSourcemapFilename}`;
588602

589603
return {
@@ -592,6 +606,21 @@ function getPlugins(
592606
};
593607
},
594608
},
609+
// License and haste headers for artifacts without sourcemaps
610+
// Primarily used for FB-artifacts, which should preserve specific format of the header
611+
// Which potentially can be changed by Closure minification
612+
!needsSourcemaps && {
613+
name: 'license-and-signature-header-for-artifacts-without-sourcemaps',
614+
renderChunk(source) {
615+
return Wrappers.wrapWithLicenseHeader(
616+
source,
617+
bundleType,
618+
globalName,
619+
filename,
620+
moduleType
621+
);
622+
},
623+
},
595624
// Record bundle size.
596625
sizes({
597626
getSize: (size, gzip) => {

0 commit comments

Comments
 (0)