ToddThomson / tsproject

Typescript minifier and modular typescript bundle optimizer for gulp (Ts Vinyl Adapter).
Other
57 stars 12 forks source link

Use Typescript 4.0 build features #105

Closed niemyjski closed 4 years ago

niemyjski commented 7 years ago

I updated my local project to typescript 2.4 and ensured it was installed correctly and I removed my modules folder and made sure I don't have typescript installed globally. But every time my project runs it says version 2.3.4. I looked through the code and I don't see why this would be happing, do you have any ideas?

[TsProject] Building Project with: src/integrations/tsconfig.json
[TsProject] TypeScript compiler version:  2.3.4
ToddThomson commented 6 years ago

@niemyjski I had a request to update tsproject to the latest version of Typescript. Are you still using/interested in TsProject?

niemyjski commented 6 years ago

Yes, we still use it and I don't think we can get off it unless it's easy to upgrade to something else. I noticed yesterday when I updated my deps that tsproject uses a specific version.

niemyjski commented 6 years ago

Any ideas if real bundling will be built into typescript some day?

ToddThomson commented 6 years ago

@niemyjski I began updating TsProject to utilize the latest Typescript version. There is an issue with a Typescript AST change which restricts identifier names to be changes ( the field is marked readonly ). This makes the minifier with TsProject fail. I will need to test a fix for the problem and then conduct further testing to see if other issues present themselves.

niemyjski commented 6 years ago

Thanks for the update, really appreciate it.

niemyjski commented 6 years ago

I was just checking in to see if there was any status updates on latest ts support :)

slavafomin commented 6 years ago

Hello! Thank you for your effort. Are you planning to finish adding support for the latest TypeScript? We are looking for a way to create a merged type definitions and this tool looks like a good fit.

ToddThomson commented 6 years ago

@slavafomin I just don't have any time to make the changes required for the latest Typescript version. My apologies! PR would be welcomed!

niemyjski commented 5 years ago

I know everyone has very little time these days including myself. I was wondering if there was any time to upgrade the deps to latest typescript? I'd be willing to donate to be on latest :)

ToddThomson commented 5 years ago

@niemyjski Hi Blake. If I remember correctly, (it has been a long while since I last looked at the code) there were a few changes to the Typescript AST that caused grief. I will take a few hours to at least determine the scope of work.

ToddThomson commented 5 years ago

@niemyjski I am updating TsProject to utilize Typescript 3.5.x. You may have to do some testing...

Currently, TsProject builds using TS 3.5.1. I will update the GitHub source once I have done some testing.

ToddThomson commented 5 years ago

@niemyjski @slavafomin OK. I've finished my research into the scope of work required to bring TsProject up to date with Typescript 3.5. Typescript has come a long way over the last couple of years! I can now make use of Transforms!

I will update the following task list to keep you informed on my progress:

Ts2Js is feature complete and testing is almost complete. Continuing to develop tests for TsMinifier and TsBundler.

ToddThomson commented 5 years ago

@niemyjski I am adding Mocha as the testing framework for TsTools. What is your opinion of Mocha vs other testing frameworks?

niemyjski commented 5 years ago

I don't have any preference, I've typically used mocha but I know there might be better alternatives out there but this works for me :) Thanks -Blake Niemyjski

On Thu, Jun 27, 2019 at 4:46 PM Todd Thomson notifications@github.com wrote:

@niemyjski https://github.com/niemyjski I am adding Mocha as the testing framework for TsTools. What is your opinion of Mocha vs other testing frameworks?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ToddThomson/tsproject/issues/105?email_source=notifications&email_token=AAHZFIY4VIYI3UKL3R6OKL3P4UYM3A5CNFSM4DQ74XH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYYPAHY#issuecomment-506523679, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHZFI762OOFLOB7SNY45YTP4UYM3ANCNFSM4DQ74XHQ .

niemyjski commented 5 years ago

I see you pushed a release to TS2JS, do you know exactly what I'd need to do to update to the latest releases? I get that this project is now split? Or will this just be a dependency on that and I won't have to change much?

ToddThomson commented 5 years ago

@niemyjski

Or will this just be a dependency on that and I won't have to change much?

The Compiler (Ts2Js), Minifier, and Bundler are now just dependencies that TsProject will require. The TsProject.Src() function that is used within your gulp build pipeline will not change. TsProject will just contain Typescript "Build" related features.

ToddThomson commented 5 years ago

Weekly update: The 3.0.0 release of all TsTool components is progressing. I am currently working on TsBundler and converting it to run as a Typescript custom transformer. Likely another week or 2 to get to a RC release for each.

niemyjski commented 5 years ago

Awesome, thank you for all of your work!

ToddThomson commented 5 years ago

@niemyjski I am currently working on release 3 of TsProject. Typescript 3.6 is opening the compiler API to project "build" features. I have decided that I will take a dependency on Typescript 3.6 for TsProject. It makes sense as the release of Typescript 3.6 will be in August and TsProject will likely be released towards the end of August.

niemyjski commented 5 years ago

Awesome!!! Thanks -Blake Niemyjski

On Tue, Jul 30, 2019 at 10:30 AM Todd Thomson notifications@github.com wrote:

@niemyjski https://github.com/niemyjski I am currently working on release 3 of TsProject. Typescript 3.6 is opening the compiler API to project "build" features. I have decided that I will take a dependency on Typescript 3.6 for TsProject. It makes sense as the release of Typescript 3.6 will be in August and TsProject will likely be released towards the end of August.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ToddThomson/tsproject/issues/105?email_source=notifications&email_token=AAHZFI24BMHOJCJEP5Q45QLQCBNA5A5CNFSM4DQ74XH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3ELSTA#issuecomment-516471116, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHZFI4Y2MADYVMJVCQCPL3QCBNA5ANCNFSM4DQ74XHQ .

niemyjski commented 5 years ago

Looks like typescript 3.7 is out with some amazing features. Hoping they made it easy to upgrade to.

niemyjski commented 4 years ago

I was wondering if there was anything I can do to help with testing of 3.8 support. I know we are all pretty busy but will try to help in any way I can time permitting.

niemyjski commented 4 years ago

Updated title for 3.9, hope you are doing well. stay safe.

niemyjski commented 4 years ago

Is there any thing I can do to help finish this up?

ToddThomson commented 4 years ago

Hi @niemyjski , I will need to review this code/project as I have not looked at it for a long time. I can't promise anything, but I will take a couple of hours to determine the scope of work.

I hope you are doing well!

niemyjski commented 4 years ago

I'm doing good, trying my best to stay safe. Glad to hear from you again. I was running into weird issues when I tried to use beta3 where the bundles was undefined and then after I changed that it broke someplace else. I also had to change the tsproject require import as it was an object and src wasn't defined until I exported const { TsProject } = require("tsproject"); Thanks again for your time.

ToddThomson commented 4 years ago

@niemyjski I have update the dev branch to utilize Typescript 4.0. On my development system I built the src directory using Typescript 4 ( tsc --p ./src from the command line ). I then used the build tasks to generate a bundled TsProject. It all 'seemed' to work. However, I haven't spent any time on seeing if TsProject still works to your needs.

Can you please clone the dev branch and test things out.

ToddThomson commented 4 years ago

@niemyjski npm package published: tsproject 4.0.0-beta.1

I haven't tested this yet. Please also give it a try and let me know how it goes.

niemyjski commented 4 years ago

Hey, Thanks for pushing a beta and for spending time on this project. I updated to beta 2 in a branch: The first issue I ran into was this:

>gulp build
Error: Cannot find module 'ts2js'
Require stack:
- D:\Code\Exceptionless.JavaScript\node_modules\tsproject\lib\tsproject.js
- D:\Code\Exceptionless.JavaScript\gulpfile.js
- C:\Users\blake\AppData\Roaming\npm\node_modules\gulp-cli\lib\shared\require-or-import.js
- C:\Users\blake\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js  
- C:\Users\blake\AppData\Roaming\npm\node_modules\gulp-cli\index.js
- C:\Users\blake\AppData\Roaming\npm\node_modules\gulp-cli\bin\gulp.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\Code\Exceptionless.JavaScript\node_modules\tsproject\lib\tsproject.js:16:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Code\\Exceptionless.JavaScript\\node_modules\\tsproject\\lib\\tsproject.js',
    'D:\\Code\\Exceptionless.JavaScript\\gulpfile.js',
    'C:\\Users\\blake\\AppData\\Roaming\\npm\\node_modules\\gulp-cli\\lib\\shared\\require-or-import.js',
    'C:\\Users\\blake\\AppData\\Roaming\\npm\\node_modules\\gulp-cli\\lib\\versioned\\^4.0.0\\index.js',
    'C:\\Users\\blake\\AppData\\Roaming\\npm\\node_modules\\gulp-cli\\index.js',
    'C:\\Users\\blake\\AppData\\Roaming\\npm\\node_modules\\gulp-cli\\bin\\gulp.js'
  ]
}

So I ran npm install ts2js --save-dev

gulp build
[07:23:23] Using gulpfile D:\Code\Exceptionless.JavaScript\gulpfile.js
[07:23:23] Starting 'build'...
[07:23:23] Starting 'clean'...
[07:23:23] Finished 'clean' after 11 ms
[07:23:23] Starting 'lint'...
[07:23:24] Finished 'lint' after 1.37 s
[07:23:24] Starting 'exceptionless'...
[07:23:24] Starting 'exceptionless.umd'...
[07:23:24] Starting 'typescript.integrations'...
[07:23:24] Starting 'typescript'...
[07:23:24] 'typescript' errored after 792 μs
[07:23:24] TypeError: tsProject.src is not a function
    at typescript (D:\Code\Exceptionless.JavaScript\gulpfile.js:16:28)
    at typescript (D:\Code\Exceptionless.JavaScript\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:430:14)
    at runBound (domain.js:443:12)
    at asyncRunner (D:\Code\Exceptionless.JavaScript\node_modules\async-done\index.js:55:18)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
[07:23:24] 'typescript.integrations' errored after 3 ms
[07:23:24] 'exceptionless.umd' errored after 4.01 ms
[07:23:24] 'exceptionless' errored after 4.86 ms
[07:23:24] 'build' errored after 1.39 s

My initial import and task looked like this:

const tsProject = require('tsproject');

gulp.task('typescript', function typescript(done) {
  const stream = tsProject.src('src/tsconfig.json').pipe(gulp.dest('dist/temp'));
  stream.on('finish', done);
});

Logging out the existing tsProject require showed that this has changed:

{
  Project: [Function: Project],
  ProjectBuilder: [Function: ProjectBuilder],
  TsProject: {
    getProjectConfig: [Function: getProjectConfig],
    builder: [Function: builder],
    src: [Function: src]
  }
}

and it works if I do

const { TsProject } = require('tsproject');
gulp.task('typescript', function typescript(done) {
  const stream = TsProject.src('src/tsconfig.json').pipe(gulp.dest('dist/temp'));
  stream.on('finish', done);
});

This gets me building but now the build artifacts in the dist folder have no dynamic type definitions and the generated code is completely different with tons of code missing / removed and replaced with single line requires. All you need to do is run gulp build on my repo and you can take a look at the dist folder changes in the git diff. I can also post here if needed.

If you wish to take a look I've committed this all to GitHub in a branch in stages: https://github.com/exceptionless/Exceptionless.JavaScript/tree/feature/tsproject4

ToddThomson commented 4 years ago

@niemyjski I've fixed up the issue with the ts2js dependency. Please give the npm beta.3 lib.

I will look at your build issues once TsProject compiles and builds your bundled code.

niemyjski commented 4 years ago

Awesome! I just updated it and the reference and import is now resolved. The generated type definitions are now populated but is a bit different (same with the generated code) and I'm not completely sure if it's correct or just changes in typescript version.

ToddThomson commented 4 years ago

@niemyjski Please test and let me know how things go. I am doing the same. There will likely be some changes required.

niemyjski commented 4 years ago

Will do thank you!

niemyjski commented 4 years ago

I've been running into some issues running all my tests (CORS and outdated samples...) but I think it's unrelated and I'll continue testing but I haven't ran into any errors so far. It seems to be running good from the e2e samples I've ran so far with the updated code. But I did have a question: Any ideas why it's voiding out all the exports?

exports.NodeSubmissionAdapter = exports.NodeFileStorageProvider = exports.NodeRequestInfoCollector = exports.NodeModuleCollector = exports.NodeErrorParser = exports.NodeEnvironmentInfoCollector = exports.NodeFileStorage = exports.KeyValueStorageBase = exports.InMemoryStorage = exports.SubmissionMethodPlugin = exports.RequestInfoPlugin = exports.ModuleInfoPlugin = exports.EventExclusionPlugin = exports.ErrorPlugin = exports.EnvironmentInfoPlugin = exports.DuplicateCheckerPlugin = exports.ConfigurationDefaultsPlugin = exports.EventBuilder = exports.SettingsResponse = exports.Configuration = exports.ContextData = exports.ExceptionlessClient = exports.SubmissionResponse = exports.SettingsManager = exports.Utils = exports.DefaultSubmissionClient = exports.InMemoryStorageProvider = exports.DefaultEventQueue = exports.EventPluginManager = exports.EventPluginContext = exports.ReferenceIdPlugin = exports.HeartbeatPlugin = exports.NullLog = exports.ConsoleLog = exports.DefaultLastReferenceIdManager = void 0;
ToddThomson commented 4 years ago

@niemyjski I don't have a context to look at the issue with your exports all being assigned with void. It is likely better that I continue with my testing and if you encounter a problem then I can look at the specifics.

niemyjski commented 4 years ago

I was curious if you ran into any issues? I haven't seen any yet other than this build error on the ci server (https://github.com/exceptionless/Exceptionless.JavaScript/runs/1371996235?check_suite_focus=true) but I'm getting to the point I'm going to be running mass e2e testing very soon.


  gulp build
3
  shell: /bin/bash -e {0}
4
  env:
5
    npm_config_cache: /home/runner/.npm
7
Error: Cannot find module '/home/runner/work/Exceptionless.JavaScript/Exceptionless.JavaScript/node_modules/tsproject/lib/tsproject.js'. Please verify that the package.json has a valid "main" entry
8
    at tryPackage (internal/modules/cjs/loader.js:303:19)
9
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
10
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
11
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
12
    at Module.require (internal/modules/cjs/loader.js:952:19)
13
    at require (internal/modules/cjs/helpers.js:88:18)
14
    at Object.<anonymous> (/home/runner/work/Exceptionless.JavaScript/Exceptionless.JavaScript/gulpfile.js:7:19)
15
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
16
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
17
    at Module.load (internal/modules/cjs/loader.js:928:32) {
18
  code: 'MODULE_NOT_FOUND',
19
  path: '/home/runner/work/Exceptionless.JavaScript/Exceptionless.JavaScript/node_modules/tsproject/package.json',
20
  requestPath: 'tsproject'
21
}```

It looks like you are missing a main entry in the package.json. The weird part is I don't see this locally.
niemyjski commented 4 years ago

It looks like casing matters

  "main": "./lib/tsproject.js",
  "typings": "./lib/tsproject.d.ts",

image

niemyjski commented 4 years ago

I just submitted a pr which I think will resolve this issue.

ToddThomson commented 4 years ago

@niemyjski Thank-you for your contribution to TsProject.

I have not found any issues with TsProject v4. I will soon publish a new NPM package with version 4.0.0-rc.1 with your changes ( and other small changes ).

niemyjski commented 4 years ago

Sounds great! Please let me know when you tag and push it

ToddThomson commented 4 years ago

@niemyjski NPM v4.0.0-rc.1 now published. Github dev branch has been updated to be in sync with my internal repository.

niemyjski commented 4 years ago

Thanks!

That resolved that issue but for some reason on linux I'm getting

[TsProject] src/exceptionless.ts(1,27): error TS2307: Cannot find module 'TraceKit' or its corresponding type declarations.
50
Error: [TsProject] /home/runner/work/Exceptionless.JavaScript/Exceptionless.JavaScript/src/services/DefaultErrorParser.ts(1,27): error TS2307: Cannot find module 'TraceKit' or its corresponding type declarations.

No idea why it doesn't fail on macOS, I'm also going to try on windows.

niemyjski commented 4 years ago

Looking at this closer something doesn't add up as the exceptionless.node.json file doesn't even have a reference to this parser at all. So I don't know why it's being referenced. Also the main tsconfig is resolving everything properly.

[00:15:00] Starting 'typescript.node'...
[TsProject] Building Project with: src/tsconfig.node.json
[TsProject] TypeScript compiler version:  4.0.5
[TsProject] Compiling project files...
[TsProject] src/exceptionless.ts(1,27): error TS2307: Cannot find module 'TraceKit' or its corresponding type declarations.
[TsProject] /home/codespace/workspace/Exceptionless.JavaScript/src/services/DefaultErrorParser.ts(1,27): error TS2307: Cannot find module 'TraceKit' or its corresponding type declarations.
[TsProject] Build completed with errors. Outputs generated.

Is there a good way to output the logs for this?

ToddThomson commented 4 years ago

@niemyjski You could just run tsc with full output verbosity. The output from above, TsProject is just doing the Ts compilation phase.

It appears that the module resolution by the typescript compiler is picking up TraceKit from somewhere.

niemyjski commented 4 years ago

Is there a good way to see what arguments tsproject is passing to tsc?

ToddThomson commented 4 years ago

TsProject does not use '''tsc'''. It uses the Typescript API.

All the configuration comes from the tsconfig.json file. TsProject doesn't add or change any config.

Try running tsc from the command line. It has many ways to peer into what Typescript module resolution is occurring.

ToddThomson commented 4 years ago

@niemyjski Try --traceresolution and perhaps --listfiles

niemyjski commented 4 years ago

I'm not even sure how I'd pass that to tsproject via gulp, will need to figure that out. Perhaps an option we can set in our tsconfig file that tsproject could pick up?

ToddThomson commented 4 years ago

@niemyjski Use tsc with --traceresolution. You don't need to use TsProject to just compile your project.

ToddThomson commented 4 years ago

@niemyjski I will also see if I can include module resolution host tracing in the 4.0 milestone. It looks easy, but I have other features which I want to complete first.