Skip to content
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

feat(tsc-wrapped): Support of vinyl like config file was added #13987

Merged
merged 7 commits into from
Jan 24, 2017

Conversation

jolly-roger
Copy link
Contributor

This feature was implemented in order to provide easier way of use in gulp

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

What is the new behavior?

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[ ] No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@@ -23,11 +23,16 @@ export type CodegenExtension =
Promise<void>;

export function main(
project: string, cliOptions: CliOptions, codegen?: CodegenExtension,
project: any, cliOptions: CliOptions, codegen?: CodegenExtension,
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 any, can it be string|{path:string}, or can you introduce an interface that structurally matches like VinylFile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree

@@ -97,7 +97,7 @@ export class Tsc implements CompilerInterface {

constructor(private readFile = ts.sys.readFile, private readDirectory = ts.sys.readDirectory) {}

readConfiguration(project: string, basePath: string, existingOptions?: ts.CompilerOptions) {
readConfiguration(project: any, basePath: string, existingOptions?: ts.CompilerOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

again, can you avoid any?

Copy link
Contributor Author

@jolly-roger jolly-roger Jan 19, 2017

Choose a reason for hiding this comment

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

again, agree

.then(() => {
const out = readOut('js');
// No helpers since decorators were lowered
expect(out).not.toContain('__decorate');
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 we should repeat all the assertions here - you just need to assert enough to be sure the vinyl file path and contents were used. Just check that some of your config was used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@@ -7,12 +7,11 @@
*/

import * as ts from 'typescript';
import {Tsc} from '../src/tsc';
import {Tsc, tsc} from '../src/tsc';
Copy link
Contributor

Choose a reason for hiding this comment

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

this import is now shadowed by the variable on line 25, can you avoid that?

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

Copy link
Contributor

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

thanks looking close

if (fs.lstatSync(project).isFile()) {
projectDir = path.dirname(project);
// project is vinyl like file object
if ((project as VinylFile).path) {
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 add isVinylFile to ./vinyl that returns project is VinylFile
See User-Defined Type Guards on https://www.typescriptlang.org/docs/handbook/advanced-types.html

Then just call isVinylFile instead of casting here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, type guard - nice. Sure will add.

this.basePath = basePath;

// Allow a directory containing tsconfig.json as the project value
// Note, TS@next returns an empty array, while earlier versions throw
try {
if (this.readDirectory(project).length > 0) {
project = path.join(project, 'tsconfig.json');
if (this.readDirectory(project as string).length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use !isVinylFile to narrow the type instead of casting

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.

projectDir = path.dirname(project.path);
}
// project is path to project file
else if (fs.lstatSync(project as string).isFile()) {
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 need a cast here anymore - the project type will have the VinylFile narrowed out since isVinylFile is known to be false in this else 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.

Wow, very tricky, but now I know it :)

this.basePath = basePath;

// Allow a directory containing tsconfig.json as the project value
// Note, TS@next returns an empty array, while earlier versions throw
try {
if (this.readDirectory(project).length > 0) {
project = path.join(project, 'tsconfig.json');
if (!isVinylFile(project) && this.readDirectory(project as string).length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here I believe

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

}
// project is path to project file
else {
return ts.readConfigFile(project as string, this.readFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

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

@alexeagle alexeagle added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews pr_state: LGTM action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jan 20, 2017
@alxhub
Copy link
Member

alxhub commented Jan 20, 2017

I'm getting conflicts when rebasing this on master, please rebase and fix them and then I can merge it. Thanks, @jolly-roger

@alxhub alxhub added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Jan 20, 2017
@alxhub alxhub assigned jolly-roger and unassigned alexeagle Jan 20, 2017
@jolly-roger
Copy link
Contributor Author

@alxhub, Rebasing and resolving conflicts are done.
Thanks a lot.

@alexeagle alexeagle removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 23, 2017
@alexeagle alexeagle modified the milestone: rg Jan 23, 2017
@alexeagle alexeagle added the action: merge The PR is ready for merge by the caretaker label Jan 23, 2017
@alxhub alxhub merged commit 0c7726d into angular:master Jan 24, 2017
@jolly-roger jolly-roger deleted the tsc-wrapper-config-obj branch January 25, 2017 09:09
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
…ar#13987)

This feature was implemented in order to provide easier way of use in gulp
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants