Skip to content

Commit

Permalink
Reenable EsbuildCompilation on EXP_C (#36105)
Browse files Browse the repository at this point in the history
* Revert "Disable EsbuildCompilation experiment. (#35814)"

This reverts commit e2d167b.

* Flexibly receive either filename

* lil bugs found in sister branch

* Address rsimha feedback

* rsimha feedback
  • Loading branch information
samouri committed Sep 23, 2021
1 parent 39b46da commit debee40
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion build-system/global-configs/experiments-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"expiration_date_utc": "2021-06-30",
"define_experiment_constant": "R1_IMG_DEFERRED_BUILD"
},
"experimentC": {}
"experimentC": {
"name": "EsbuildCompilation",
"environment": "AMP",
"issue": "https://github.com/ampproject/amphtml/issues/35264",
"expiration_date_utc": "2021-10-30",
"define_experiment_constant": "ESBUILD_COMPILATION"
}
}
12 changes: 9 additions & 3 deletions build-system/tasks/check-sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ function checkSourcemapMappings(sourcemapJson, map) {
throw new Error('Could not find mappings array');
}

// Zeroth sub-array corresponds to ';' and has no mappings.
// See https://www.npmjs.com/package/sourcemap-codec#usage
const firstLineMapping = decode(sourcemapJson.mappings)[1][0];
// In closure builds there is a newline immediately after the AMP_CONFIG.
// This whole segment has no mapping to the original source.
// Therefore we must skip the zeroth sub-array, indicated by a ';'.
// In esbuild builds there is no newline after the config, so the
// first line is fair game.
const firstLineIndex = shouldUseClosure() ? 1 : 0;

// See https://www.npmjs.com/package/sourcemap-codec#usage.
const firstLineMapping = decode(sourcemapJson.mappings)[firstLineIndex][0];
const [, sourceIndex = 0, sourceCodeLine = 0, sourceCodeColumn] =
firstLineMapping;

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ async function esbuildCompile(srcDir, srcFilename, destDir, options) {
};
}
const {banner, footer} = splitWrapper();
const config = await getAmpConfigForFile(srcFilename, options);
const config = await getAmpConfigForFile(destFilename, options);
const compiledFile = await getCompiledFile(srcFilename);
banner.js = config + banner.js + compiledFile;

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/visual-diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ async function ensureOrBuildAmpRuntimeInTestMode_() {
}

if (argv.nobuild) {
const isInTestMode = /AMP_CONFIG=\{(?:.+,)?"test":true\b/.test(
const isInTestMode = /AMP_CONFIG=\{(?:.+,)?"test":(!0|true)\b/.test(
fs.readFileSync('dist/v0.js', 'utf8')
);
if (!isInTestMode) {
Expand Down

0 comments on commit debee40

Please sign in to comment.