Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Conversation

@FredKSchott
Copy link
Contributor

@usergenic and I ran into problems with gulp-typescript yesterday, this upgrades to the latest 2.0 version and fixes some issues with config, custom_typings, etc.

/cc @usergenic @justinfagnani

@justinfagnani
Copy link
Contributor

yay! taking a look

serviceWorker.generateServiceWorker();
}, Error.AssertionError, '`project` & `buildRoot` options are required');
return serviceWorker.generateServiceWorker()
.then(() => { throw new Error('generateServiceWorker() resolved, expected rejection!'); })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do Promise inversions as two callback to then(), so that you don't have to worry about the exception you throw in then() flowing into catch(). Then just assert.fail() in the first callback. Alternatively, we have a handy invert() function hangout out around here somewhere...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, I like this.

tsconfig.json Outdated
"src/**/*.ts",
"typings/index.d.ts"
],
"files": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS 2.x supports includes and excludes. Use those instead of files.

Copy link
Contributor Author

@FredKSchott FredKSchott Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 nice! It's behavior is a little weird, which is why I hadn't been able to get it working before. Files still need to be referenced in the files array. ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't. We don't use files at all in the analyzer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to remove files before submitting. One file is replaced by compilerOptions.lib, the other should go in includes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 got it! Taking out"typings/index.d.ts" was what caused the error I was seeing, but it turns out it was a problem with typings and not typescript.

"gulp": "registry:dt/gulp#3.8.0+20160316155526",
"gulp-if": "registry:dt/gulp-if#0.0.0+20160316155526",
"gulp-util": "registry:dt/gulp-util#0.0.0+20160316155526",
"merge-stream": "registry:dt/merge-stream#1.0.0+20160313224417",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you migrate to @types while we're at this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not all of them are supported yet, but I'll migrate the ones I can

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which ones? All of these come from DT, so they should be available in @types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only DT stuff in their 2.0 branch is in @types. They're using this as a chance to standardize on modern practices.

Copy link
Contributor

@usergenic usergenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG ITS WORKING

@usergenic
Copy link
Contributor

usergenic commented Sep 21, 2016

TRAVIS Y U NO LIKE?

npm ERR! peerinvalid The package typescript@2.1.0-dev.20160921 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer tslint@3.15.1 wants typescript@>=1.7.3

Anything we can do to fix that here too so we have green travis checks?

wrt https://travis-ci.org/Polymer/polymer-build/jobs/161702741

(unless node 4 is no longer unsupported)

@FredKSchott
Copy link
Contributor Author

@usergenic the typescript@next dev versions were messing with semver matching, which was causing problems with npm2 installations. Switching back to the latest stable version (which we should be on, now that TS 2.0 is stable) fixes it.

@FredKSchott
Copy link
Contributor Author

@justinfagnani PTAL

tsconfig.json Outdated
}
"include": [
"custom_typings/**/*.ts",
"node_modules/@types/**/*.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need or want this line. tsc automatically looks for these when you use node resolution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

"rewriteTsconfig": true
}
"include": [
"custom_typings/**/*.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rictic do you remember why we use /// <reference path="../custom_typings/main.d.ts" /> in analyzer.ts rather than include custom_typings in tsconfig? Is it for declarations and dependers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's for the generated .d.ts declarations file. If you only mention the dependency in your tsconfig then downstream users won't see the custom typings.

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'll add this for the sw-precache custom typing and we can look into publishing it directly to npm. All the others are internal only and shouldn't affect the polymer-build declarations

gulpfile.js Outdated

gulp.task('depcheck', () =>
depcheck(__dirname, {})
depcheck(__dirname, {ignoreMatches: ['@types/**']})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you comment the ignore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really make that part of the default ignoreMatches

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+10, I'll create a PR and comment for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already tracking here: depcheck/depcheck#163

}, Error.AssertionError, '`project` & `buildRoot` options are required');
return serviceWorker.generateServiceWorker()
.then(
() => { throw new Error('generateServiceWorker() resolved, expected rejection!'); },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of throwing, you can: assert.fail('generateServiceWorker() resolved, expected rejection!')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to prefer assert.fail over 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.

The UX. I think an uncaught error is reported different, and tries to display a stacktrace. Here we know it's a plain failure and the stack won't help.

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'm fine with either, the difference seems minor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use fail()

@FredKSchott
Copy link
Contributor Author

@justinfagnani @rictic PTAL

shellFile.contents = new Buffer(newShellContent);
}
async _buildBundles(): Promise<Map<string, string>> {
let bundles = await this._getBundles();
Copy link
Contributor

@rictic rictic Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere: preferred style is const by default, let only when necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'd like to keep the scope of this PR small for now. I'll make a separate PR to address this across the repo once this has been merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed w/ the agree. In the future, just do the async/await in another PR also :)

? urlFromPath(this.root, this.shell)
: this.sharedBundleUrl;
let sharedDeps = bundles.get(sharedDepsBundle) || [];
let promises: Promise<any>[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimize use of any, it's usually a code smell. Would this work?

const promises: Promise<{url: string, contents: string}>[] = []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'd like to keep the scope of this PR small for now. This diff was only a indentation change due to a move over to async-await above. I'll make a separate PR to address this.

"declaration": true,
"noImplicitAny": true,
"removeComments": false,
"noLib": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noLib still makes sense, or

"lib": ["es2017"],

"gulp": "registry:dt/gulp#3.8.0+20160316155526",
"gulp-if": "registry:dt/gulp-if#0.0.0+20160316155526",
"gulp-util": "registry:dt/gulp-util#0.0.0+20160316155526",
"merge-stream": "registry:dt/merge-stream#1.0.0+20160313224417",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only DT stuff in their 2.0 branch is in @types. They're using this as a chance to standardize on modern practices.

@rictic
Copy link
Contributor

rictic commented Sep 21, 2016

As a code review style note, when possible instead of rewriting existing commits add --fixup commits instead, and you can rebase them right before going to master. It makes it easier for us to see only the new changes.

@FredKSchott
Copy link
Contributor Author

@rictic TIL! I've never used the --fixup feature before, I'll play around with it.

@rictic @justinfagnani thanks for the help so far with all the different TypeScript config options, feeling much more confident in our config setup now.

shellFile.contents = new Buffer(newShellContent);
}
async _buildBundles(): Promise<Map<string, string>> {
let bundles = await this._getBundles();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed w/ the agree. In the future, just do the async/await in another PR also :)

@FredKSchott FredKSchott merged commit 6d13fac into master Sep 21, 2016
@FredKSchott FredKSchott deleted the typescript-fix branch September 21, 2016 21:41
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.

4 participants