-
Notifications
You must be signed in to change notification settings - Fork 14
Add a TypeScript pass, and revive package.json pass #63
Conversation
This pass updates an element repo to include typings generated by https://github.com/Polymer/gen-typescript-declarations/ and configures an "update-types" NPM script that can be run to re-generate them. Also: - Replace custom node-git typings with the Definitely Typed version. - Add a package-lock.json.
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 also update travis to fail if the types were not updated?
Good idea. Same idea as your Polymer/polymer#5003. Assuming we are happy with the slight extra time this will add to every Travis run. Looks like we already have a Travis pass, so hopefully we can just add it there. |
cleanup-passes/typescript.ts
Outdated
try { | ||
packageJson = await fse.readJson(packageJsonPath); | ||
} catch { | ||
throw new 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.
why not make a minimal one here? I think you can get away with just having scripts and devDeps.
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 -- I rewrote the existing package-json pass to create a super minimal one, and added it to this PR. It looks like the previous code there was pretty out of date and is now superseded by modulizer.
cleanup-passes/typescript.ts
Outdated
`Missing or invalid package.json for element: ${element.ghRepo.name}`); | ||
} | ||
|
||
if (packageJson.devDependencies === undefined) { |
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.
You can be a little more declarative if you want with object spread:
try {
packageJson = {
scripts: {},
devDependencies: {},
...await fse.readJson(packageJsonPath);
};
} ...
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, although since I'm not used to that pattern I think it would have taken me a sec to figure out what was going on.
I've added a new NpmConfig
type (shared with the new package-json pass, see above) which declares these fields as undefined. TypeScript doesn't infer that they can't be undefined with the suggested snippet, so another reason I think I'll stick with mine.
cleanup-passes/typescript.ts
Outdated
// If all we did was update the package lock, don't bother with the | ||
// commit. But do include it if we changed something else. | ||
commitFiles.push(filepath); | ||
} |
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.
do we expect other file paths? If not, should we log unexpected ones?
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.
Added a console.log to point these out.
cleanup-passes/typescript.ts
Outdated
// We also have to bower install because the generator needs to see the | ||
// dependencies. | ||
await execFilePromise('bower', ['install'], execOpts); | ||
await execFilePromise('npm', ['run', npmScriptName], execOpts); |
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.
my add a comment to highlight that this actually runs the generator
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.
It looks like previously this was an early attempt at generating package.jsons for actually publishing. Now that's done by modulizer, so all we need here is to create a super minimal one. It also updates .gitignore to ignore node_modules. If any package.json exists, this pass now does absolutely nothing.
PTAL! |
I'm waiting on Polymer/gen-typescript-declarations#71 and Polymer/gen-typescript-declarations#72 to be published before I pull the trigger on running this pass. |
I've run this on more than half the element repos. Tracking at https://github.com/Polymer/gen-typescript-declarations/issues/79. @justinfagnani I think this can be committed now, PTAL? |
This is done. |
// Update the types. | ||
'npm run update-types && ' + | ||
// If there were any changes, this git command will return non-zero. | ||
'git diff --exit-code || ' + |
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.
🎉 🎉 🎉 🎉
That error echo is really nice. Maybe update the script in polymer/polymer as well? 😄
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.
That error echo is really nice. Maybe update the script in polymer/polymer as well? 😄
Done in Polymer/polymer#5099
cleanup-passes/package-json.ts
Outdated
// npm warns if any of these fields aren't set. | ||
description: bowerConfig.description, | ||
repository: bowerConfig.repository, | ||
license: bowerConfig.license, |
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.
The bower config license field is not a standard SPDX license identifier that package.json should have. I'd just hard code this as "BSD-3-Clause"
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.
'use strict'; | ||
|
||
import * as fs from 'fs'; | ||
import * as fse from 'fs-extra'; |
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 we can just import this as fs
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 much prefer giving it a distinct name, since actually all the APIs I use are not part of the standard fs, and I've seen fse
in some other repos.
This pass updates an element repo to include typings generated by https://github.com/Polymer/gen-typescript-declarations/ and configures an
update-types
NPM script that can be run to re-generate them.It also revives the existing package.json pass to be much simpler (just the most minimal possible package.json), and to update the gitignore file.
Also:
node-git
typings with the Definitely Typed version.package-lock.json
.util.promisify
.