Skip to content

Commit

Permalink
build-system: consolidate all build time constants (#34327)
Browse files Browse the repository at this point in the history
* Consolidate all babel replacements

* fix bs tsconfig

* also remove internal-runtime-version

* Fix constant selection, modify internal-version to use indent.

* minify replaced in getMode....why

* Minify-replace does not work when the vars are declared.

* remove amp-mode-transform

* Revert "remove amp-mode-transform"

This reverts commit 853c8da.

* bring back the amp-mode minified transform

* revert seemingly unrelated change

* Update build-system/compile/build-constants.js

Co-authored-by: Ryan Cebulko <ryan@cebulko.com>

* address rcebulko feedback

* forbidden terms message update

* further cleanup

Co-authored-by: Jake Fried <4656974+samouri@users.noreply.github.com>
Co-authored-by: Ryan Cebulko <ryan@cebulko.com>
  • Loading branch information
3 people authored Jul 9, 2021
1 parent 2732f55 commit 5869aed
Show file tree
Hide file tree
Showing 39 changed files with 74 additions and 628 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ module.exports = {
...getExperimentGlobals(),
'IS_ESM': 'readonly',
'IS_SXG': 'readonly',
'IS_MINIFIED': 'readonly',
'IS_FORTESTING': 'readonly',
'INTERNAL_RUNTIME_VERSION': 'readonly',
'AMP': 'readonly',
'context': 'readonly',
'global': 'readonly',
Expand Down
23 changes: 10 additions & 13 deletions build-system/babel-config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const argv = require('minimist')(process.argv.slice(2));
const experimentsConfig = require('../global-configs/experiments-config.json');
const experimentsConstantBackup = require('../global-configs/experiments-const.json');
const {BUILD_CONSTANTS} = require('../compile/build-constants');

/**
* Get experiment constant to define from command line arguments, if any
Expand Down Expand Up @@ -46,24 +47,20 @@ function getExperimentConstant() {
function getReplacePlugin() {
/**
* @param {string} identifierName the identifier name to replace
* @param {boolean} value the value to replace with
* @param {boolean|string} value the value to replace with
* @return {!Object} replacement options used by minify-replace plugin
*/
function createReplacement(identifierName, value) {
return {
identifierName,
replacement: {type: 'booleanLiteral', value: !!value},
};
const replacement =
typeof value === 'boolean'
? {type: 'booleanLiteral', value}
: {type: 'stringLiteral', value};
return {identifierName, replacement};
}

// We build on the idea that SxG is an upgrade to the ESM build.
// Therefore, all conditions set by ESM will also hold for SxG.
// However, we will also need to introduce a separate IS_SxG flag
// for conditions only true for SxG.
const replacements = [
createReplacement('IS_ESM', argv.esm || argv.sxg),
createReplacement('IS_SXG', argv.sxg),
];
const replacements = Object.entries(BUILD_CONSTANTS).map(([ident, val]) =>
createReplacement(ident, val)
);

const experimentConstant = getExperimentConstant();
if (experimentConstant) {
Expand Down
5 changes: 0 additions & 5 deletions build-system/babel-config/minified-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ function getMinifiedConfig() {
'./build-system/babel-plugins/babel-plugin-transform-json-import',
{freeze: false},
],
'./build-system/babel-plugins/babel-plugin-is_minified-constant-transformer',
'./build-system/babel-plugins/babel-plugin-transform-html-template',
'./build-system/babel-plugins/babel-plugin-transform-jss',
'./build-system/babel-plugins/babel-plugin-transform-version-call',
'./build-system/babel-plugins/babel-plugin-transform-simple-array-destructure',
'./build-system/babel-plugins/babel-plugin-transform-default-assignment',
replacePlugin,
Expand All @@ -75,9 +73,6 @@ function getMinifiedConfig() {
'./build-system/babel-plugins/babel-plugin-amp-mode-transformer',
{isEsmBuild: !!argv.esm},
],
argv.fortesting
? null
: './build-system/babel-plugins/babel-plugin-is_fortesting-constant-transformer',
].filter(Boolean);
const presetEnv = [
'@babel/preset-env',
Expand Down
5 changes: 0 additions & 5 deletions build-system/babel-config/pre-closure-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ function getPreClosureConfig() {
'./build-system/babel-plugins/babel-plugin-transform-json-import',
{freeze: false},
],
'./build-system/babel-plugins/babel-plugin-is_minified-constant-transformer',
'./build-system/babel-plugins/babel-plugin-transform-amp-extension-call',
'./build-system/babel-plugins/babel-plugin-transform-html-template',
'./build-system/babel-plugins/babel-plugin-transform-jss',
'./build-system/babel-plugins/babel-plugin-transform-version-call',
'./build-system/babel-plugins/babel-plugin-transform-simple-array-destructure',
'./build-system/babel-plugins/babel-plugin-transform-default-assignment',
replacePlugin,
Expand All @@ -84,9 +82,6 @@ function getPreClosureConfig() {
{isEsmBuild: !!argv.esm},
]
: null,
!(isFortesting || isCheckTypes)
? './build-system/babel-plugins/babel-plugin-is_fortesting-constant-transformer'
: null,
].filter(Boolean);
const presetEnv = [
'@babel/preset-env',
Expand Down
7 changes: 0 additions & 7 deletions build-system/babel-config/unminified-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const {
VERSION: internalRuntimeVersion,
} = require('../compile/internal-version');
const {getImportResolverPlugin} = require('./import-resolver');
const {getReplacePlugin} = require('./helpers');

Expand Down Expand Up @@ -54,10 +51,6 @@ function getUnminifiedConfig() {
argv.coverage ? 'babel-plugin-istanbul' : null,
replacePlugin,
'./build-system/babel-plugins/babel-plugin-transform-json-import',
[
'./build-system/babel-plugins/babel-plugin-transform-internal-version',
{version: internalRuntimeVersion},
],
'./build-system/babel-plugins/babel-plugin-transform-json-configuration',
'./build-system/babel-plugins/babel-plugin-transform-jss',
'./build-system/babel-plugins/babel-plugin-transform-fix-leading-comments',
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5869aed

Please sign in to comment.