Skip to content

Commit

Permalink
♻️ 🏗 Create proxy for kleur/colors to expand typing. (#34243)
Browse files Browse the repository at this point in the history
* references to kleur/colors now pass through build-system/common/colors

Co-authored-by: Raghu Simha <rsimha@amp.dev>

* update babel.config
  • Loading branch information
rileyajones authored May 7, 2021
1 parent 57e1205 commit d47ba35
Show file tree
Hide file tree
Showing 78 changed files with 114 additions and 76 deletions.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

'use strict';

const {cyan, yellow} = require('kleur/colors');
const {cyan, yellow} = require('./build-system/common/colors');
const {log} = require('./build-system/common/logging');

/**
Expand Down
30 changes: 30 additions & 0 deletions build-system/common/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const colors = require('kleur/colors');

/**
* @fileoverview kleur/color provides a collection of untyped color formatting
* functions. This file provides a generically typed wrapper for each of them in
* order to satisfy our type checks without changing any functionality. For more
* info, see https://github.com/lukeed/kleur/blob/master/colors.{mjs,d.ts}.
*/
module.exports = Object.entries(colors).reduce((map, [key, formatter]) => {
map[key] =
typeof formatter == 'function'
? (txt) => /** @type {function} */ (formatter)(txt)
: formatter;
return map;
}, /** @type {Record<keyof typeof colors, (input?: *) => string>} */ ({}));
2 changes: 1 addition & 1 deletion build-system/common/ctrlcHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const colors = require('kleur/colors');
const colors = require('./colors');
const {execScriptAsync, exec} = require('./exec');
const {logLocalDev} = require('./logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/common/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
const argv = require('minimist')(process.argv.slice(2));
const tempy = require('tempy');
const {blue, bold, cyan, red} = require('kleur/colors');
const {blue, bold, cyan, red} = require('./colors');
const {getStdout} = require('./process');
const {log, logWithoutTimestamp} = require('./logging');
const {writeFile} = require('fs-extra');
Expand Down
2 changes: 1 addition & 1 deletion build-system/common/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const childProcess = require('child_process');
const {log} = require('./logging');
const {spawnProcess} = require('./process');
const {yellow} = require('kleur/colors');
const {yellow} = require('./colors');

const shellCmd = process.platform == 'win32' ? 'cmd' : '/bin/bash';

Expand Down
2 changes: 1 addition & 1 deletion build-system/common/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
'use strict';

const {bold, yellow, gray} = require('kleur/colors');
const {bold, yellow, gray} = require('./colors');
const {isCiBuild} = require('./ci');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/common/npm-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const fs = require('fs-extra');
const path = require('path');
const {cyan, red} = require('kleur/colors');
const {cyan, red} = require('./colors');
const {exec} = require('./exec');
const {gitDiffColor, gitDiffNameOnly} = require('./git');
const {log, logWithoutTimestamp} = require('./logging');
Expand Down
2 changes: 1 addition & 1 deletion build-system/common/update-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const checkDependencies = require('check-dependencies');
const del = require('del');
const fs = require('fs-extra');
const path = require('path');
const {cyan, red} = require('kleur/colors');
const {cyan, red} = require('./colors');
const {execOrDie} = require('./exec');
const {getOutput} = require('./process');
const {isCiBuild} = require('./ci');
Expand Down
2 changes: 1 addition & 1 deletion build-system/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {default: ignore} = require('ignore');
const {doBuild} = require('../tasks/build');
const {doDist} = require('../tasks/dist');
const {gitDiffNameOnlyMain} = require('./git');
const {green, cyan, red, yellow} = require('kleur/colors');
const {green, cyan, red, yellow} = require('./colors');
const {log, logLocalDev} = require('./logging');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/bundles.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';
const extensionBundles = require('./bundles.config.extensions.json');
const wrappers = require('./compile-wrappers');
const {cyan, red} = require('kleur/colors');
const {cyan, red} = require('../common/colors');
const {log} = require('../common/logging');

const {VERSION: internalRuntimeVersion} = require('./internal-version');
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/check-for-unknown-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra');
const {log} = require('../common/logging');
const {red, cyan, yellow} = require('kleur/colors');
const {red, cyan, yellow} = require('../common/colors');

/**
* Searches for the identifier "module$", which Closure uses to uniquely
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/closure-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const compiler = require('@ampproject/google-closure-compiler');
const vinylFs = require('vinyl-fs');
const {cyan, red, yellow} = require('kleur/colors');
const {cyan, red, yellow} = require('../common/colors');
const {getBabelOutputDir} = require('./pre-closure-babel');
const {log, logWithoutTimestamp} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const path = require('path');
const {checkForUnknownDeps} = require('./check-for-unknown-deps');
const {CLOSURE_SRC_GLOBS} = require('./sources');
const {cpus} = require('os');
const {green, cyan} = require('kleur/colors');
const {green, cyan} = require('../common/colors');
const {log, logLocalDev} = require('../common/logging');
const {postClosureBabel} = require('./post-closure-babel');
const {preClosureBabel} = require('./pre-closure-babel');
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/debug-compilation-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs');
const path = require('path');
const tempy = require('tempy');
const {cyan, red} = require('kleur/colors');
const {cyan, red} = require('../common/colors');
const {log} = require('../common/logging');

const logFile = path.resolve(process.cwd(), 'dist', 'debug-compilation.log');
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/log-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra');
const {cyan} = require('kleur/colors');
const {cyan} = require('../common/colors');
const {log} = require('../common/logging');

const pathPrefix = 'dist/log-messages';
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/pre-closure-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const tempy = require('tempy');
const {BABEL_SRC_GLOBS} = require('./sources');
const {debug, CompilationLifecycles} = require('./debug-compilation-lifecycle');
const {log} = require('../common/logging');
const {red, cyan} = require('kleur/colors');
const {red, cyan} = require('../common/colors');
const {TransformCache, batchedRead, md5} = require('../common/transform-cache');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/eslint-rules/no-forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const {cyan} = require('kleur/colors');
const {cyan} = require('../common/colors');
const {matchForbiddenTerms} = require('../test-configs/forbidden-terms');
const {relative} = require('path');

Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-check/build-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config = require('../test-configs/config');
const globby = require('globby');
const minimatch = require('minimatch');
const path = require('path');
const {cyan} = require('kleur/colors');
const {cyan} = require('../common/colors');
const {getLoggingPrefix, logWithoutTimestamp} = require('../common/logging');
const {gitDiffNameOnlyMain} = require('../common/git');
const {isCiBuild} = require('../common/ci');
Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-check/ci-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
} = require('../common/logging');
const {determineBuildTargets} = require('./build-targets');
const {isPullRequestBuild} = require('../common/ci');
const {red} = require('kleur/colors');
const {red} = require('../common/colors');
const {updatePackages} = require('../common/update-packages');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-check/cross-browser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const {buildTargetsInclude, Targets} = require('./build-targets');
const {log} = require('../common/logging');
const {red, cyan} = require('kleur/colors');
const {red, cyan} = require('../common/colors');
const {reportAllExpectedTests} = require('../tasks/report-test-status');
const {runCiJob} = require('./ci-job');
const {skipDependentJobs, timedExecOrDie} = require('./utils');
Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-check/nomodule-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
} = require('./utils');
const {buildTargetsInclude, Targets} = require('./build-targets');
const {log} = require('../common/logging');
const {red, yellow} = require('kleur/colors');
const {red, yellow} = require('../common/colors');
const {runCiJob} = require('./ci-job');
const {signalPrDeployUpload} = require('../tasks/pr-deploy-bot-utils');

Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-check/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
gitCiMainBaseline,
shortSha,
} = require('../common/git');
const {cyan, green, yellow} = require('kleur/colors');
const {cyan, green, yellow} = require('../common/colors');
const {execOrDie, execOrThrow, execWithError, exec} = require('../common/exec');
const {getLoggingPrefix, logWithoutTimestamp} = require('../common/logging');
const {replaceUrls} = require('../tasks/pr-deploy-bot-utils');
Expand Down
2 changes: 1 addition & 1 deletion build-system/server/app-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

const minimist = require('minimist');
const {cyan, green} = require('kleur/colors');
const {cyan, green} = require('../common/colors');
const {log} = require('../common/logging');

let serveMode = 'default';
Expand Down
2 changes: 1 addition & 1 deletion build-system/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const {
const {getServeMode} = require('./app-utils');
const {logWithoutTimestamp} = require('../common/logging');
const {log} = require('../common/logging');
const {red} = require('kleur/colors');
const {red} = require('../common/colors');
const {renderShadowViewer} = require('./shadow-viewer');
const {replaceUrls, isRtvMode} = require('./app-utils');

Expand Down
2 changes: 1 addition & 1 deletion build-system/server/routes/a4a-envelopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fetch = require('node-fetch');
const fs = require('fs');
const {getServeMode, replaceUrls} = require('../app-utils');
const {log} = require('../../common/logging');
const {red} = require('kleur/colors');
const {red} = require('../../common/colors');

const app = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion build-system/server/typescript-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
const esbuild = require('esbuild');
const globby = require('globby');
const path = require('path');
const {cyan, green} = require('kleur/colors');
const {cyan, green} = require('../common/colors');
const {endBuildStep} = require('../tasks/helpers');
const {exec} = require('../common/exec');
const {log} = require('../common/logging');
Expand Down
2 changes: 1 addition & 1 deletion build-system/task-runner/amp-task-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
updatePackages,
updateSubpackages,
} = require('../common/update-packages');
const {cyan, red, green, magenta} = require('kleur/colors');
const {cyan, red, green, magenta} = require('../common/colors');
const {isCiBuild} = require('../common/ci');
const {log} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/task-runner/install-amp-task-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

const fs = require('fs-extra');
const path = require('path');
const {cyan, green, yellow} = require('kleur/colors');
const {cyan, green, yellow} = require('../common/colors');
const {getStdout} = require('../common/process');
const {logWithoutTimestamp: log} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/3p-vendor-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const debounce = require('debounce');
const globby = require('globby');
const {compileJsWithEsbuild} = require('./helpers');
const {endBuildStep} = require('./helpers');
const {red, cyan} = require('kleur/colors');
const {red, cyan} = require('../common/colors');
const {VERSION} = require('../compile/internal-version');
const {watchDebounceDelay} = require('./helpers');
const {watch} = require('chokidar');
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/bundle-size/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const {
const {
VERSION: internalRuntimeVersion,
} = require('../../compile/internal-version');
const {cyan, red, yellow} = require('kleur/colors');
const {cyan, red, yellow} = require('../../common/colors');
const {log, logWithoutTimestamp} = require('../../common/logging');
const {report, NoTTYReport} = require('@ampproject/filesize');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/caches-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const path = require('path');
const {log, logLocalDev} = require('../common/logging');
const {red, green, cyan} = require('kleur/colors');
const {red, green, cyan} = require('../common/colors');

const expectedCaches = ['google', 'bing'];
const cachesJsonPath = '../global-configs/caches.json';
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';

const fs = require('fs').promises;
const {cyan, red, green} = require('kleur/colors');
const {cyan, red, green} = require('../common/colors');
const {log} = require('../common/logging');

const DEV_ASSERT_SENTINEL = '__devAssert_sentinel__';
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-build-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {cyan, green} = require('kleur/colors');
const {cyan, green} = require('../common/colors');
const {execOrThrow} = require('../common/exec');
const {log} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-exact-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const fs = require('fs-extra');
const globby = require('globby');
const semver = require('semver');
const {cyan, green, red} = require('kleur/colors');
const {cyan, green, red} = require('../common/colors');
const {gitDiffFileMain} = require('../common/git');
const {log, logLocalDev, logWithoutTimestamp} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-invalid-whitespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const {getFilesToCheck} = require('../common/utils');
const {getStdout} = require('../common/process');
const {green, red} = require('kleur/colors');
const {green, red} = require('../common/colors');
const {invalidWhitespaceGlobs} = require('../test-configs/config');
const {log, logLocalDev, logWithoutTimestamp} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const markdownLinkCheck = require('markdown-link-check');
const path = require('path');
const {getFilesToCheck, usesFilesOrLocalChanges} = require('../common/utils');
const {gitDiffAddedNameOnlyMain} = require('../common/git');
const {green, cyan, red, yellow} = require('kleur/colors');
const {green, cyan, red, yellow} = require('../common/colors');
const {linkCheckGlobs} = require('../test-configs/config');
const {log, logLocalDev} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-owners.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
const fetch = require('node-fetch');
const fs = require('fs-extra');
const JSON5 = require('json5');
const {cyan, red, green} = require('kleur/colors');
const {cyan, red, green} = require('../common/colors');
const {getFilesToCheck, usesFilesOrLocalChanges} = require('../common/utils');
const {log, logLocalDev} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-renovate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

'use strict';

const {cyan, red, green} = require('kleur/colors');
const {cyan, red, green} = require('../common/colors');
const {getOutput} = require('../common/process');
const {log} = require('../common/logging');

Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs');
const {cyan, green, red} = require('kleur/colors');
const {cyan, green, red} = require('../common/colors');
const {decode} = require('sourcemap-codec');
const {execOrDie} = require('../common/exec');
const {log} = require('../common/logging');
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/check-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {
const {cleanupBuildDir, closureCompile} = require('../compile/compile');
const {compileCss} = require('./css');
const {compileJison} = require('./compile-jison');
const {cyan, green, yellow, red} = require('kleur/colors');
const {cyan, green, yellow, red} = require('../common/colors');
const {extensions, maybeInitializeExtensions} = require('./extension-helpers');
const {logClosureCompilerError} = require('../compile/closure-compile');
const {log} = require('../common/logging');
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/cherry-pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const argv = require('minimist')(process.argv.slice(2));
const {execOrThrow} = require('../common/exec');
const {getOutput} = require('../common/process');
const {green, cyan, red, yellow} = require('kleur/colors');
const {green, cyan, red, yellow} = require('../common/colors');
const {log} = require('../common/logging');

/**
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const argv = require('minimist')(process.argv.slice(2));
const del = require('del');
const path = require('path');
const {cyan} = require('kleur/colors');
const {cyan} = require('../common/colors');
const {log} = require('../common/logging');

const ROOT_DIR = path.resolve(__dirname, '../../');
Expand Down
Loading

0 comments on commit d47ba35

Please sign in to comment.