Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Add a TypeScript pass, and revive package.json pass #63

Merged
merged 12 commits into from
Feb 7, 2018
Merged

Conversation

aomarks
Copy link
Contributor

@aomarks aomarks commented Jan 24, 2018

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:

  • Replace custom node-git typings with the Definitely Typed version.
  • Add custom typings for BowerConfig and NpmConfig.
  • Add a package-lock.json.
  • Bump engines and types to Node 8 so we can use util.promisify.

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.
@aomarks aomarks requested a review from justinfagnani January 24, 2018 07:04
Copy link
Contributor

@TimvdLippe TimvdLippe left a 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?

@aomarks
Copy link
Contributor Author

aomarks commented Jan 24, 2018

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.

try {
packageJson = await fse.readJson(packageJsonPath);
} catch {
throw new Error(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

`Missing or invalid package.json for element: ${element.ghRepo.name}`);
}

if (packageJson.devDependencies === undefined) {
Copy link
Contributor

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);
  };
} ...

Copy link
Contributor Author

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.

// 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);
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

// 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);
Copy link
Contributor

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

Copy link
Contributor Author

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.
@aomarks
Copy link
Contributor Author

aomarks commented Jan 25, 2018

PTAL!

@aomarks aomarks changed the title Add a TypeScript pass. Add a TypeScript pass, and revive package.json pass Jan 25, 2018
@aomarks
Copy link
Contributor Author

aomarks commented Jan 25, 2018

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.

@aomarks
Copy link
Contributor Author

aomarks commented Feb 2, 2018

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?

@aomarks
Copy link
Contributor Author

aomarks commented Feb 6, 2018

Maybe also update travis to fail if the types were not updated?

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 || ' +
Copy link
Contributor

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? 😄

Copy link
Contributor Author

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

// npm warns if any of these fields aren't set.
description: bowerConfig.description,
repository: bowerConfig.repository,
license: bowerConfig.license,
Copy link
Contributor

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"

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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.

@aomarks aomarks merged commit db10790 into master Feb 7, 2018
@aomarks aomarks deleted the typescript branch February 7, 2018 22:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants