Skip to content

Commit

Permalink
update typing in response to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyajones committed Feb 10, 2021
1 parent afa6904 commit f69269c
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 26 deletions.
3 changes: 1 addition & 2 deletions build-system/common/check-package-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function yellow(text) {
* package manager being used is determined.
**/
function ensureNpm() {
// @ts-ignore: Object is possibly 'undefined'.
if (!process.env.npm_execpath.includes('npm')) {
console.log(npmInfoMessage);
process.exit(1);
Expand All @@ -100,7 +99,7 @@ function ensureNpm() {
/**
* Check the node version and print a warning if it is not the latest LTS.
*
* @return {Promise<void>}
* @return {Promise}
**/
function checkNodeVersion() {
const nodeVersion = getStdout('node --version').trim();
Expand Down
3 changes: 1 addition & 2 deletions build-system/common/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const shellCmd = process.platform == 'win32' ? 'cmd' : '/bin/bash';
* @param {?Object=} options
* @return {!Object}
*/
function exec(cmd, options) {
options = options || {'stdio': 'inherit'};
function exec(cmd, options = {'stdio': 'inherit'}) {
return spawnProcess(cmd, options);
}

Expand Down
4 changes: 2 additions & 2 deletions build-system/common/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function spawnProcess(cmd, options) {
/**
* Executes the provided command, returning the process object.
* @param {string} cmd
* @param {?Object} options
* @param {?Object=} options
* @return {!Object}
*/
function getOutput(cmd, options = {}) {
Expand All @@ -64,7 +64,7 @@ function getStdout(cmd, options) {
/**
* Executes the provided command, returning its stderr.
* @param {string} cmd
* @param {?Object} options
* @param {?Object=} options
* @return {string}
*/
function getStderr(cmd, options) {
Expand Down
3 changes: 1 addition & 2 deletions build-system/compile/check-for-unknown-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'use strict';

const through = require('through2');
const Stream = require('stream');
const {log} = require('../common/logging');
const {red, cyan, yellow} = require('kleur/colors');

Expand All @@ -25,7 +24,7 @@ const {red, cyan, yellow} = require('kleur/colors');
* reference module imports. If any are found, that means Closure couldn't
* import the module correctly.
*
* @return {!Stream}
* @return {!Stream} require('stream')
*/
exports.checkForUnknownDeps = function () {
const regex = /[\w$]*module\$[\w$]+/;
Expand Down
2 changes: 2 additions & 0 deletions build-system/compile/closure-compile.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
interface Stream { }
interface Writable { }
5 changes: 2 additions & 3 deletions build-system/compile/closure-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
const closureCompiler = require('@ampproject/google-closure-compiler');
const path = require('path');
const pumpify = require('pumpify');
const { default: Stream, Writable } = require('stream');
const sourcemaps = require('gulp-sourcemaps');
const {cyan, red, yellow} = require('kleur/colors');
const {EventEmitter} = require('events');
Expand Down Expand Up @@ -101,7 +100,7 @@ function logError(message) {
* file relative to the sourcemap. Since the sourcemap for `src/foo.js` "lives"
* in `src/`, it ends up resolving to `src/src/foo.js`.
*
* @param {!Stream} closureStream
* @param {!Stream} closureStream require('stream')
* @return {!Stream}
*/
function makeSourcemapsRelative(closureStream) {
Expand All @@ -115,7 +114,7 @@ function makeSourcemapsRelative(closureStream) {

/**
* @param {Array<string>} compilerOptions
* @return {Writable}
* @return {Writable} require('stream').Writable
*/
function gulpClosureCompile(compilerOptions) {
const pluginOptions = {
Expand Down
37 changes: 36 additions & 1 deletion build-system/compile/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ const MAX_PARALLEL_CLOSURE_INVOCATIONS =
* production use. During development we intend to continue using
* babel, as it has much faster incremental compilation.
*
* @param {string} entryModuleFilename
* @param {string} outputDir
* @param {string} outputFilename
* @param {{
* esmPassCompilation?: string,
* wrapper?: string,
* extraGlobs?: string,
* include3pDirectories?: boolean,
* includePolyfills?: boolean,
* externs?: string[],
* compilationLevel?: string,
* verboseLogging?: boolean,
* typeCheckOnly?: boolean,
* skipUnknownDepsCheck?: boolean,
* }} options
* @param {{startTime?: number}} timeInfo
* @return {Promise<void>}
*/
async function closureCompile(
Expand Down Expand Up @@ -102,6 +118,25 @@ function cleanupBuildDir() {
fs.mkdirsSync('build/fake-polyfills/src/polyfills');
}

/**
* @param {string[]|string} entryModuleFilenames
* @param {string} outputDir
* @param {string} outputFilename
* @param {{
* esmPassCompilation?: string,
* wrapper?: string,
* extraGlobs?: string,
* include3pDirectories?: boolean,
* includePolyfills?: boolean,
* externs?: string[],
* compilationLevel?: string,
* verboseLogging?: boolean,
* typeCheckOnly?: boolean,
* skipUnknownDepsCheck?: boolean,
* }} options
* @param {{startTime?: number}} timeInfo
* @return {Promise<void>}
*/
function compile(
entryModuleFilenames,
outputDir,
Expand Down Expand Up @@ -217,7 +252,7 @@ function compile(

/**
* TODO(#28387) write a type for this.
* @type {*}
* @type {Object}
*/
/* eslint "google-camelcase/google-camelcase": 0*/
const compilerOptions = {
Expand Down
3 changes: 2 additions & 1 deletion build-system/compile/internal-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function getVersion() {
`HEAD~${numberOfCherryPicks}`
).slice(0, -2);

return `${lastCommitFormattedTime}${String(numberOfCherryPicks).padStart(3, '0')}`;
const numberOfCherryPicksStr = String(numberOfCherryPicks).padStart(3, '0');
return `${lastCommitFormattedTime}${numberOfCherryPicksStr}`;
}

// Used to e.g. references the ads binary from the runtime to get version lock.
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/post-closure-babel.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 babel = require('@babel/core');
const path = require('path');
const remapping = require('@ampproject/remapping').default;
const remapping = require('@ampproject/remapping');
const terser = require('terser');
const through = require('through2');
const {debug, CompilationLifecycles} = require('./debug-compilation-lifecycle');
Expand Down
2 changes: 1 addition & 1 deletion build-system/compile/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports.transpileTs = async function (srcDir, srcFilename) {
};
// TODO(#28387) fix this typing.
/** @type {*} */
const transformerHost = {
const transformerHost = {
host: compilerHost,
options: tsOptions,
pathToModuleName,
Expand Down
5 changes: 5 additions & 0 deletions build-system/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
declare global {
interface Error {
/**
* In the build-system, Error objects contain useful info like underlying
* stack traces in the message field, so we print that and hide the less
* useful nodejs stack.
*/
showStack?: boolean;
status?: string;
}
Expand Down
5 changes: 4 additions & 1 deletion build-system/server/app-index/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ const ExamplesSelectModeOptional = ({basepath, selectModePrefix}) =>
selectModePrefix,
});

/** @param {{ name: string, href: string, boundHref?: string|undefined }} config */
/**
* @param {{ name: string, href: string, boundHref?: string|undefined }} config
* @return {string}
*/
const FileListItem = ({name, href, boundHref}) =>
html`
<div class="file-link-container" role="listitem">
Expand Down
2 changes: 1 addition & 1 deletion build-system/server/app-index/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function renderTemplate(opt_params = {}) {
isMainPage = false,
fileSet = [],
serveMode = 'default',
selectModePrefix = '/'
selectModePrefix = '/',
} = opt_params;

const body = joinFragments([
Expand Down
7 changes: 4 additions & 3 deletions build-system/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ app.use('/form/echo-json/post', (req, res) => {
}
fields[realName].push(value);
});
form.parse(req, (_unusedErr) => {
form.parse(req, () => {
res.setHeader('Content-Type', 'application/json; charset=utf-8');
if (fields['email'] == 'already@subscribed.com') {
res.statusCode = 500;
Expand Down Expand Up @@ -1449,9 +1449,10 @@ app.use('/mraid/', (req, res) => {
* @return {number}
*/
function nearestFiveMinutes() {
let date = new Date();
const date = new Date();
// Round down to the nearest 5 minutes.
let time = Number(date) -
const time =
Number(date) -
(date.getMinutes() % 5) * 1000 * 60 +
date.getSeconds() * 1000 +
date.getMilliseconds();
Expand Down
6 changes: 3 additions & 3 deletions build-system/server/routes/a4a-envelopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

const { Request, Router } = require('express');
const express = require('express');
const fs = require('fs');
const request = require('request');
const {getServeMode, replaceUrls} = require('../app-utils');
const {log} = require('../../common/logging');
const {red} = require('kleur/colors');

const app = Router();
const app = express.Router();

// In-a-box envelope.
// Examples:
Expand Down Expand Up @@ -99,7 +99,7 @@ app.use('/a4a(|-3p)/', async (req, res) => {
});

/**
* @param {Request} req
* @param {express.Request} req
* @param {string=} extraExperiment
* @return {!URL}
*/
Expand Down
4 changes: 1 addition & 3 deletions build-system/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@
"./server/**/*.js",
"./server/**/*.ts"
],
"exclude": [
"**/node_modules"
]
"exclude": ["**/node_modules","common/check-package-manager.js"]
}

0 comments on commit f69269c

Please sign in to comment.