New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ 🏗 🚀 Begin adding type checking to the build-system directory. #32531
Conversation
Hey @rsimha! These files were changed:
Hey @danielrozenberg! These files were changed:
Hey @alanorozco! These files were changed:
|
I am aware that this is a large change containing a lot of files, so, given that it is currently nonfunctional, I'm happy to split it apart further if anyone would prefer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR! I've added a few preliminary comments for the CI and task code. Can we split them off into one PR, and fix the server code in a separate PR? (They are fairly isolated from each other.)
@@ -31,7 +31,7 @@ const shellCmd = process.platform == 'win32' ? 'cmd' : '/bin/bash'; | |||
* object. | |||
* | |||
* @param {string} cmd | |||
* @param {?Object} options | |||
* @param {?Object=} options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: If this is being changed, would it make sense to change the signature as follows?
function exec(cmd, options = {'stdio': 'inherit'}) {
(Same question applies to other instances)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would make sense in this instance, I'm not sure about all the others.
f69269c
to
d60c09c
Compare
@@ -0,0 +1,13 @@ | |||
declare global { | |||
interface Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @ types/node will help here too instead of defining a custom interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately neither showStack nor status is not an attribute of Error so we either need this or a custom Error type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see.. looks like it's a gulp type. I don't know about status but I found showStack here https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/plugin-error/index.d.ts#L13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, showStack
is for gulp
, and should go away when we adopt a more lightweight task runner.
status
is something we set in exec.js
, so it might be possible to use a different mechanism:
amphtml/build-system/common/exec.js
Lines 80 to 97 in 29fdb58
/** | |
* Executes the provided command, piping the parent process' stderr, throwing | |
* an error with the provided message the command fails, and returns the | |
* process object. | |
* @param {string} cmd | |
* @param {string} msg | |
* @return {!Object} | |
*/ | |
function execOrThrow(cmd, msg) { | |
const p = exec(cmd, {'stdio': ['inherit', 'inherit', 'pipe']}); | |
if (p.status && p.status != 0) { | |
log(yellow('ERROR:'), msg); | |
const error = new Error(p.stderr); | |
error.status = p.status; | |
throw error; | |
} | |
return p; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not alter the existing error message handling system for now. Given that those are both properties that we do actually use this type extension makes sense to me, but should remove these properties once the code using them is gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's fair, how about adding a TODO in global.d.ts to delete it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
506c879
to
7db52e9
Compare
…is always defined
…project#32531) Begin adding type checking to the build-system directory. * create tsconfig and fix lots of type errors
By using typescript to compile the existing javascript we can catch a lot before they are introduced to the codebase without having to fully switch to typescript.
Unfortunately the existing code contains a significant number of errors so prior to adding this as a build step they there will need to be several pull requests filled with just typing changes.
For reference without this change there are 280 errors.
With this change there are 109
With this change and
@types/mocha
installed the number falls to 44.Those 44 errors almost all actually errors that should be fixed and that we likely would not have found without this check.
#28387