cli icon indicating copy to clipboard operation
cli copied to clipboard

generate TypeScript d.ts for aurelia-cli

Open atsu85 opened this issue 9 years ago • 27 comments

reason

Currently when selecting TypeScript as a transpiler the build scripts are also generated in TypeScript, but IDE can't do much without the typescript definitions.

atsu85 avatar Jun 22 '16 21:06 atsu85

I agree. I'm not sure how best to handle this yet. There's more to it than the cli d.ts. We can certainly create one of those. But, we need gulp and all the plugins really.

EisenbergEffect avatar Jun 22 '16 21:06 EisenbergEffect

@EisenbergEffect,

But, we need gulp and ...

if You referred to TypeScript IDE support for writing gulp files, then see #183

atsu85 avatar Jun 22 '16 23:06 atsu85

This also affects the generators since without the cli .d.ts the generator code is a mess

jasoncarreira avatar Jun 24 '16 16:06 jasoncarreira

The cli api is a bit unstable currently. We can certainly add a d.ts just remember this is alpha and it is likely to change over the next few months.

EisenbergEffect avatar Jun 29 '16 17:06 EisenbergEffect

I can deal with changes... I just can't build right now ;)

jasoncarreira avatar Jun 29 '16 17:06 jasoncarreira

I don't understand why you can't build. Can you explain?

EisenbergEffect avatar Jun 29 '16 17:06 EisenbergEffect

Maybe au would build but my IDE (Intellij IDEA) highlights all of the failed classes and won't do the automatic build-as-you-go with classes broken

jasoncarreira avatar Jun 29 '16 17:06 jasoncarreira

Ok, that compilation is done on the fly, automatically by the Aurelia CLI itself, as needed. So, there's no need to have the ide touch that. However, we can work to address this in the future. Is there a way to have your IDE ignore that folder for now?

EisenbergEffect avatar Jun 29 '16 17:06 EisenbergEffect

Yes, I can ignore it and just use the CLI. Seeing the red is just an annoyance, I suppose, but I've been trained by my IDE to go and fix things highlighted in red.

jasoncarreira avatar Jun 29 '16 17:06 jasoncarreira

@jasoncarreira, I've managed to fix most of the errors with that PR.

atsu85 avatar Jun 29 '16 17:06 atsu85

I currently have this problem with Visual Studio. As soon as I press F5 I get the build errors and then the CLI will also no longer build with the below error.

(function (exports, require, module, __filename, __dirname) { define(["require", "exports", 'gulp', 'gulp-changed-in-place', 'gulp-plumber', 'gulp-sourcemaps', 'gulp-notify', 'gulp-rename', 'gulp-typescript', '../aurelia.json', 'aurelia-cli'], function (require, exports, gulp, changedInPlace, plumber, sourcemaps, notify, rename, ts, project, aurelia_cli_1) { ^

ReferenceError: define is not defined at Object. (C:\Local Development\au\WebApplication1\src\WebApplication1\aurelia_project\tasks\transpile.js:1:63) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (C:\Local Development\au\WebApplication1\src\WebApplication1\aurelia_project\tasks\build.ts:3:19) at Module._compile (module.js:409:26) at Object.require.extensions..ts (C:\Local Development\au\WebApplication1\src\WebApplication1\node_modules\aurelia-cli\lib\project.js:131:19)

Am I doing anything stupid?

beatsm avatar Jul 04 '16 15:07 beatsm

@beatsm You say that you have build errors when you build within Visual Studio. I don't know if it is the same issue but I cannot build using VS due to an older tsc version

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "C:\Users\sro\Documents\Visual Studio 2015\Projects\AureliaTestCli\src\AureliaTestCli\tsconfig.json" C:\Users\sro\Documents\Visual Studio 2015\Projects\AureliaTestCli\src\AureliaTestCli\error TS5023:Build:Unknown compiler option 'lib'.

I don't know if it is possible to update the version of tsc used by msbuild. The official package is still 1.8 Ideally, it should be possible to entirely disable TS compilation, but I haven't found anything about that.

srollinet avatar Jul 20 '16 08:07 srollinet

@srollinet @beatsm Visual Studio 2015 by default will try to compile Typescript on build. If you're missing any Typescript definition files, like aurelia-cli which are not on definitively Typed or in the project, you won't be able to build. Since the cli will handle all the client-side building (compile typescript, css, bundle, minify, etc) you should disable Typescript compilation by VS anyway. It's not well documented but instructions are here: http://www.philipholly.com/post/148366570426/aurelia-typescript-errors-and-how-to-get-visual

Also on that article there are instructions on how to upgrade Visual Studio to Typescript 2.0.0.0-beta.

pholly avatar Aug 05 '16 13:08 pholly

@pholly thanks.

This works a treat. http://rostacik.net/2015/08/14/how-to-disable-building-of-typescript-files-in-visual-studio-2015/

Regards

beatsm avatar Aug 26 '16 16:08 beatsm

I'll mention, that this is just a workaround, that doesn't help us to write Gulp files or change/customize/add aurelia-cli generators written in TypeScript.

atsu85 avatar Aug 26 '16 17:08 atsu85

I would very much like to see a type definition for the cli. Is there any progress on this topic? Does it have any priority?

I'm setting up a new project and we are using ts lint, we do not allow code without type declaration. I now have to ignore all the code in the aurelia project since i'm missing type definitions and its not a trivial task to create them (I would have to make lots of guesses since the code is not extremely clear to me on types and flow). I auto generated the basics for the cli but it's far from complete. This will help a bit when writing new generators/tasks but a proper d.ts would improve quality allot imho.

As a side question are there any plans to (re)write the cli project in TS?

michaelw85 avatar Feb 22 '19 09:02 michaelw85

We've been discussing moving the entire CLI to TypeScript and some general refactoring across the board as well. @huochunpeng and @jwx might have some thoughts on that. It's not the top priority at this moment.

@michaelw85 If you've got a partial d.ts file that you've generated, we could bring that into this project to help other community members and then we could just patch that along the way as needed until we move this library to TS.

EisenbergEffect avatar Feb 23 '19 00:02 EisenbergEffect

Ok good to hear, if I can help rewriting some part to ts please let me know where to start.

For the generated d.ts file, sure I can share but its very crude. Its missing methods and defaults all params and return types to any. Would it be an idea to put this in a types package (@types/aurelia-cli)?

michaelw85 avatar Feb 23 '19 07:02 michaelw85

Here's the auto generated file: aurelia-cli.d.ts.txt

I only edited a single method with different types I think.

michaelw85 avatar Feb 23 '19 07:02 michaelw85

Let's hear what @huochunpeng and @jwx think is best at this point since they are our core team members who usually end up working on the CLI most.

EisenbergEffect avatar Feb 23 '19 07:02 EisenbergEffect

I know nothing about TS (one less problem for me than all of you) :-) But I don’t mind someone to convert the code base.

The main problem of the conversion: we don’t have enough test coverage.

3cp avatar Feb 23 '19 07:02 3cp

@huochunpeng Good time to start 😉 I was skeptic about the benefits at first but I feel like plain JS is holding me back these days. TS helps me improve overall quality in my code, it also helps me be more productive because of improved intellisense.

To start somewhere I think we could try and setup the typescript compiler to allow js and see if we could output the current setup as-is. This would already enable some generation of d.ts files and it immediately allows us to start using TS by "simply" changing the extension of files (and making it compatible this is the hard part ofc). But a good start could be to see if the unit tests can be setup in TS this should not impact the code I guess, not sure if this is viable though. After that slowly changing files to ts and adding type definitions as a follow up.

michaelw85 avatar Feb 23 '19 08:02 michaelw85

@michaelw85 If you are interested to give this a shot, we're open to that. My guidance would be to try to make the smallest possible initial PR to get things in place and working. Minimal changes at first. Send us a PR for that, and we can review and discuss. Once the initial setup is in place, we can then do small, successive PRs to chip away at the conversion. I'd like to avoid a "big bang" gigantic PR if we can.

EisenbergEffect avatar Feb 23 '19 18:02 EisenbergEffect

Yes I would love to try! I totally agree on the agile approach, I will try to refrain as much as possible from editing existing files for the first setup.

michaelw85 avatar Feb 23 '19 18:02 michaelw85

My guidance would be to try to make the smallest possible initial PR to get things in place and working.

@michaelw85, if you plan to start with the PR containing just the autogenerated file you linked previously, then i suggest you to mark the unknown types so later it whould be possible to distinguish parameters and return types that are really any vs those that are just unknown. So initially you could just add following as a first line declare type undiscovered = any; and replace all other occurrences of any with undiscovered - this should be simple enough and serve as an invitation to other Aurelia community members to refine types at their own pace without requiring to await rewriting this repo to TS or needing to refine everything or wast time on figuring if specific parameter/return value is really any or just unknown for now.

atsu85 avatar Feb 23 '19 23:02 atsu85

aah, by the way, if anyone is interested in solution how i managed to get rid of IntelliJ IDEA warnings from TypeScript files from aurelia_project/tasks folder after generating new aurelia project with TS, then:

  1. i created aurelia_project/tasks/tsconfig.json:
{
  "compileOnSave": false,
  "compilerOptions": {
    "resolveJsonModule": true,
    "lib": [
      "es2017"
    ]
  },
  "include": [
    "./**/*.ts"
  ]
}
  1. added some devDependencies to package.json:
    "@types/browser-sync": "0.0.42",
    "@types/connect-history-api-fallback": "^1.3.1",
    "@types/debounce": "^1.2.0",
    "@types/gulp-plumber": "0.0.32",
    "@types/gulp-tslint": "^4.2.0",
    "@types/gulp-typescript": "^2.13.0",
    "@types/gulp-watch": "^4.1.34",
    "@types/merge2": "^1.1.4",
    "@types/plugin-error": "^0.1.0",
  1. ignored couple of packages in tasks TS files using // @ts-ignore before import line (such as gulp-changed-in-place and gulp-notify)
  2. did some minor changes like replacing project.build.copyFiles with project.build['copyFiles'] to make TS compiler happy

It was pretty painless :) Sadly i didn't have time to investigate how to improve the CLI to turn that knowledge into PR for others to benefit

atsu85 avatar Feb 23 '19 23:02 atsu85

My guidance would be to try to make the smallest possible initial PR to get things in place and working.

@michaelw85, if you plan to start with the PR containing just the autogenerated file you linked previously, then i suggest you to mark the unknown types so later it whould be possible to distinguish parameters and return types that are really any vs those that are just unknown. So initially you could just add following as a first line declare type undiscovered = any; and replace all other occurrences of any with undiscovered - this should be simple enough and serve as an invitation to other Aurelia community members to refine types at their own pace without requiring to await rewriting this repo to TS or needing to refine everything or wast time on figuring if specific parameter/return value is really any or just unknown for now.

That is a very good suggestion! Definitely one to keep in mind. For a first PR I will only focus on enabling writing TS and get all code to run as-is. So only adding a tsc build. I will have a look if I can already compile with a similar auto generated d.ts else I will manually include it at first.

michaelw85 avatar Feb 24 '19 07:02 michaelw85