Skip to content

Configure TypeScript validator with sensible defaults #40

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

Closed
micaelgallego opened this issue Mar 25, 2016 · 15 comments
Closed

Configure TypeScript validator with sensible defaults #40

micaelgallego opened this issue Mar 25, 2016 · 15 comments
Milestone

Comments

@micaelgallego
Copy link

I was testing TypeScript validation feature and I think it will be good to have more sensible defaults in it, for example:

  • Exclude node_modules folder: This folder is used to download "dependencies", not for used code. Moreover, it has potentially thousands of JS files. I think a sensible default is exclude this folder.
  • Exclude other "non source code" folders: For example "tmp" or "build" folders

Also, I was wondering it "Validation builder" can be added to project automatically when adding TypeScript nature to project. The steps in https://github.com/angelozerr/typescript.java/wiki/Editor-Features#validation are a bit messy to newbies.

@angelozerr
Copy link
Owner

I was testing TypeScript validation feature and I think it will be good to have more sensible defaults in it,

I would like to avoid hard coding this rules (exclude node_modules, etc). My idea is to use tsconfig.json files and exclude like explained at http://www.typescriptlang.org/docs/handbook/tsconfig.json.html

Also, I was wondering it "Validation builder" can be added to project automatically when adding TypeScript nature to project.

It doesn't exists TypeScript nature today see #12 (comment)

The steps in https://github.com/angelozerr/typescript.java/wiki/Editor-Features#validation are a bit messy to newbies.

I know, I think it's more an issue with WTP. If I have a simple idea, I will implement it, but I don't want to take time about that.

@micaelgallego
Copy link
Author

+1 to honor tsconfig.json for includes and excludes.

Although there is no “TypeScript nature“ currently, I think if it is available is more newbies friendly than activate the validator.

Continue your awesome work. I’m waiting for the first release to migrate from atom to eclipse.

@angelozerr
Copy link
Owner

@micaelgallego I have implemented my idea with tsconfig.json. I will update the wiki with this new features. The basic idea is when validate is done for a folder, or build, it check that it exists a tsconfig.json in the folder of the file to validate (and parent folder of tsconfig.json is not found).

When a tsconfig.json is found, valudation must be done if:

  • the file is contained in the "files" section of tsconfig.json
  • or if the file is not excluded by "exclude" section.

Tell me if it works for you. Thanks!

I’m waiting for the first release to migrate from atom to eclipse.

I would like to finish my implementation with compile feature (with compileOnSave).

Just one question, why do you wish to migrat efrom atom to eclipse? atom is more powerfull today than typescript.java, no?

@angelozerr angelozerr added this to the 1.0.0 milestone Apr 9, 2016
@micaelgallego
Copy link
Author

I've been testing the current SNAPSHOT (from update site) and I've the same issue as before.

The angular-cli project generates a project structure like this:

config
dist
e2e
node_modules
src
  app
    app.component.html
    app.component.ts
  app.ts
  index.html
  tsconfig.json
  typings.d.ts
tmp
typings
package.json
typings.json

And the tsconfig.json has the following contents:

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "",
    "module": "system",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../dist/",
    "rootDir": ".",
    "sourceMap": true,
    "sourceRoot": "/",
    "target": "es5"
  },
  "compileOnSave": false
}

Then... your strategy of using tsconfig.json contents doesn't work in this case. I think several projects has folder structures like this.

It is a bit complex to configure validator por the project, exclude several folders, etc... Maybe you have to think again about "TypeScript Nature" to tackle these kind of things. First, because configuring validations it is to complex. And second, becase I think that 'node_modules' it is a common name to disable it from validation as default. I you don't automatically active validation as default and configure it right, nobody will use it (or at least, less people than you expect).

What do you think?

@angelozerr
Copy link
Owner

Then... your strategy of using tsconfig.json contents doesn't work in this case. I think several projects has folder structures like this.

What is the problem? I use files or exlude info coming from the tsconfig.json (in the same folder of the ts to validate or parent folder)

What do you think?

I agree it's a little complex. But I liked the idea not to configure something to import project from vscode for instance inside Eclipse.

First, because configuring validations it is to complex.

Le me think about this problem.

And second, becase I think that 'node_modules' it is a common name to disable it from validation as default.

You mean that you would like to avoud adding "node_modules" in the exclude of tsconfig.json? If yoy add node_modules in the exclude, does it work for validation?

@micaelgallego
Copy link
Author

I've configured validation for the whole project. Then, node_modules folder have been started to be validated (I've stopped it after a while).

In the tsconfig.json (generated with angular-cli) there is nothing about "node_modules" because it is in the parent folder and then tsc compiler executed in the src folder doesn't try to compile it at all.

I've tried again and if I try to validate the whole project, node_modules is validated although tsconfig.json contains

"exclude": [
    "node_modules"
  ]

Also, I have a lot of errors like this in the "Error log" view:

eclipse.buildId=4.5.1.M20150904-0015
java.version=1.8.0_77
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=es_ES
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product
This is a continuation of log file /home/mica/Data/Docencia/Asignaturas/DAW/2015-2016/TypeScript/wsTest/.metadata/.bak_1.log
Created Time: 2016-04-09 17:34:10.026
org.eclipse.wst.validation
Error
Sat Apr 09 17:34:17 CEST 2016
Path must include project and resource name: /tsconfig.json
java.lang.IllegalArgumentException: Path must include project and resource name: /tsconfig.json
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2075)
    at org.eclipse.core.internal.resources.Container.getFile(Container.java:192)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:41)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:45)
    at ts.eclipse.ide.core.utils.WorkbenchResourceUtil.findFileRecursively(WorkbenchResourceUtil.java:27)
    at ts.eclipse.ide.internal.core.resources.jsonconfig.JsonConfigResourcesManager.findTsconfig(JsonConfigResourcesManager.java:66)
    at ts.eclipse.ide.internal.core.resources.IDETypeScriptProject.canValidate(IDETypeScriptProject.java:195)
    at ts.eclipse.ide.validator.internal.core.validation.TypeScriptValidator.validate(TypeScriptValidator.java:62)
    at org.eclipse.wst.validation.Validator$V2.validate(Validator.java:1159)
    at org.eclipse.wst.validation.internal.ValManager.validate(ValManager.java:704)
    at org.eclipse.wst.validation.internal.ValManager$1.visit(ValManager.java:665)
    at org.eclipse.wst.validation.internal.ValManager.accept(ValManager.java:810)
    at org.eclipse.wst.validation.internal.ValManager.validate(ValManager.java:669)
    at org.eclipse.wst.validation.internal.ValidationRunner.execute(ValidationRunner.java:134)
    at org.eclipse.wst.validation.internal.ValidationRunner.validate(ValidationRunner.java:68)
    at org.eclipse.wst.validation.ui.internal.ManualValidationRunner.runInWorkspace(ManualValidationRunner.java:83)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

And

eclipse.buildId=4.5.1.M20150904-0015
java.version=1.8.0_77
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=es_ES
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product
This is a continuation of log file /home/mica/Data/Docencia/Asignaturas/DAW/2015-2016/TypeScript/wsTest/.metadata/.bak_1.log
Created Time: 2016-04-09 17:34:10.026
org.eclipse.wst.validation
Error
Sat Apr 09 17:37:16 CEST 2016
TypeScript Validator finished validating: file:/home/mica/Data/Docencia/Asignaturas/DAW/2015-2016/TypeScript/code/ejem11/node_modules/angular-cli/node_modules/ember-cli/node_modules/markdown-it-terminal/node_modules/ansi-styles/node_modules/color-convert/index.js

@angelozerr
Copy link
Owner

Could you share your project please. Thanks

@micaelgallego
Copy link
Author

Sure... Here is: ejem11.zip

After decompressing it, you have to download dependencies to node_modules folder executing "npm install" command (of course, you need to have installed node and npm)

@angelozerr
Copy link
Owner

Thanks @micaelgallego ! it will be easy for me and you to discuss about future problem if we have a commons project. But perhaps a better idea is that you could create a github project?

I have though about your 2 problems, and here my idea:

  1. how to exclude node_modules?

At first I thought, thate there were 2 cases:

  • when "node_modules" is inside a folder which have a parent folder which contains a tsconfig.json. In this case you add "exclude" node_modules (this case works today)
  • when "node_modules" has not folder which have a parent folder which contains a tsconfig.json. It is your case (the case of project generated by angular-cli). In this case the validation must be NOT done because it doesn't find a tsconfig.json

In other words validation must be done only if we find a tsconfig.json and this tsconfig.json doesn't exclude a folder. But....a a tsconfig.json can exist inside a node_modlules folder.

In other words my idea with tsconfig.json is not enough. I will add this exclude folder for node_modules. It will hard coded and there were none UI to customize it.

  1. Activate Validation Builder

My idea is when user save the first time a ts file in a project, it displays a popup with a message ike "Do you want display errors in the Problem View when you save ts files?"

What do you think?

angelozerr pushed a commit that referenced this issue Apr 9, 2016
angelozerr pushed a commit that referenced this issue Apr 9, 2016
validate ts file which tsconfig.json cannot be found. See
#40 (comment)
@micaelgallego
Copy link
Author

I have several projects generated with angular-cli and with ionic cli tool
in this github repository:

https://github.com/codeurjc/learn-ng2-ionic2

Ionic projects have tsconfig.json in the root and node_modules is excluded
(among other folders).

I think is a good set of projects to make testing...

Your proposed behavior it is ok for me. tsconfig.json guides the compiler
activation.
El 9/4/2016 21:33, "Angelo" [email protected] escribió:

Thanks @micaelgallego https://github.com/micaelgallego ! it will be
easy for me and you to discuss about future problem if we have a commons
project. But perhaps a better idea is that you could create a github
project?

I have though about your 2 problems, and here my idea:

  1. how to exclude node_modules?

There are 2 cases:

  • when "node_modules" is inside a folder which have a parent folder
    which contains a tsconfig.json. In this case you add "exclude" node_modules
    (this case works today)
  • when "node_modules" has not folder which have a parent folder which
    contains a tsconfig.json. It is your case (the case of project generated by
    angular-cli). In this case the validation must be NOT done because it
    doesn't find a tsconfig.json

In other words validation must be done only if we find a tsconfig.json and
this tsconfig.json doesn't exclude a folder.

What do you think about this idea?

I will fix too your error.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#40 (comment)

@peterswords
Copy link

Hi Angelo, first of all: great job with the typescript.java project.

I don't know if this is the same problem as documented by Michael above. I have set up an Angular2 project in Eclipse. It was originally created as an Eclipse static web project, so the content is in a folder called WebContent. In that folder I have a tsconfig.json, a node_modules folder containing Angular, and a single sample xyz.ts that I want to compile. My tsconfig.json file references the node_modules folder in "excludes".

If I run the tsc compiler myself at the command line, I get no errors. However, when I let it build in Eclipse I have many errors in Angular declarations. These are mostly (TS2304): 'Cannot find name xxx' ... with the names Map, Set, and Promise. Any thoughts as to what is going on. Why isn't the compiler behaving the same in Eclipse as on the command line?

@angelozerr
Copy link
Owner

angelozerr commented Jun 11, 2016

Hi Angelo, first of all: great job with the typescript.java project.

Thanks!

Could you share your project please and tell me which files causes problem. It will be more easy for me to understand, thanks

Why isn't the compiler behaving the same in Eclipse as on the command line?

I use tsc too, but it seems that I don't call it with the same parameter than you. It will will help me if you share your project and tell me where you do tsc (which folder) and which parameters command.

@peterswords
Copy link

peterswords commented Jun 11, 2016

TS1.zip
Zip file attached. It is extremely simple. One .ts file in WebContent. You will need to run npm install in WebContent to recreate node_modules. You can see in the project settings I have configured to use typescript compiler and server from node_modules instead of the embedded one. While I was reviewing this I realised that the one I am running at the command line is at:

C:\Users\peter\workspaces\sendev\TS1\WebContent>where tsc
C:\Users\peter\AppData\Roaming\npm\tsc
C:\Users\peter\AppData\Roaming\npm\tsc.cmd

Maybe a different version?
C:\Users\peter\workspaces\sendev\TS1\WebContent>tsc -version
Version 1.8.10

I don't know how to tell what version is the one in node_modules, because I don't seem to be able to run it from the command line.

EDIT: I get the same errors when I configure the Eclipse project to use the built-in typescript.

@angelozerr
Copy link
Owner

angelozerr commented Jun 11, 2016

Thanks for the project. At first I suggest you that you remove JSDT nature because JavaScript Validator will be executed and you need not that.

I have tested your project and I have too errors by using Eclipse but with simple command too (with tsc 1.8.10). I don't know why tsc try to compile ts files from node_modules although node_modules is excluded inside tsconfig.json? Is it a bug of tsc?

@angelozerr
Copy link
Owner

None anwser, I close this issue. @peterswords please create a new issue if you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants