-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
[🟦] Migrate server-side code to TypeScript #1573
Comments
I would like to work on it :) |
You are more than welcome to! 👍 |
Hi, I have one questions :)
Do "all code files" also include test files? |
Absolutely, the tests should also be in TypeScript. In the end all code should be TS, so we can have consistent linting rules and programming patterns across frontend, backend and tests. |
Understood! 👍 |
Hi @paseaf! How's it going? Did you make some progress? Anything you need help with? |
@bkimminich Hi! I've already installed and set up typescript, and am currently in the middle of migrating I do have a question, which scripts should be passed locally for the migration? I'm currently checking |
Wow, that sounds great already! Yeah, those test scripts are exactly the ones that run on server side. |
Help wanted
I have tried all fixes on Google's first page but none has worked. I will try something different to avoid global import if it cannot be solved easily. |
@paseaf I'm no expert in this typescript / module stuff, but the problem seems to be that the registerWebsocketEvents itself is loaded via https://github.com/paseaf/juice-shop/blob/zl/ts-migrate_v3/server.ts#L597 I've changed the way to the following and that seems to have fixed the error. import('./lib/startup/registerWebsocketEvents').then(
({ default: registerWebsocketEvents }) => {
registerWebsocketEvents(server);
}
) |
@J12934 You are right! 👍 Problem is solved after changing the syntax there. |
Hey @bkimminich, I have some questions. 👋 Current Progress [branch:
Questions:
|
Impressive! 👍 I'll check out your fork in the next days and see if I can reproduce the e2e and insecurity behavior. 👀 |
I'm running into an error with
|
Sorry, I didn't know Windows doesn't have |
I just realized that I could compare the compiled code with the code before migration to find the problem. I'll check it and see what I can find 👍 |
This is what I now get on my Windows 10 with Node 14:
|
These are expected type checking errors (because we only renamed the file without really adding any type annotations), and they shouldn't stop Typescript from compiling the code. I thought the current issue was only to rename the files without fixing type errors. But seems we should suppress these errors to avoid confusion. |
I'm totally fine with those warnings showing up, don't get me wrong. I just didn't expect the compiling to fail, and it seems it worked for you. |
Does |
|
The error was because I found some trick to suppress the error for both Windows and Linux. - "postinstall": cd frontend && npm install && cd .. && npm run build:frontend && npm run copy-static-files && npm run build:server
+ "postinstall": cd frontend && npm install && cd .. && npm run build:frontend && npm run copy-static-files && (npm run --silent build:server || cd .) The update is pushed, and I hope you don't see any npm errors for
I can see two solutions:
I would prefer the 2nd solution but I'm open to any other solutions. :) |
I agree that 2.) sounds a lot cleaner, because fiddling with the frontend can be avoided and it kind of leaves server-side JS files where they are today. I'm currently testing, compiling works now for me. |
Frisby tests pass for me with current version, Protractor suite also passed completely for me. So, that's all 👍! I'll check the insecurity.js issues next. |
Okay, I can confirm 10 frisby tests are failing once I rename |
Could be. I will look into it in the next days. 👍 |
Hi @paseaf, if you have some new version for us to test locally, you'll ping us, right? You can of course also just open a PR and we'll test it that way (also our CI/CD will have a chance to take a look) but I'm also happy to do some testing rounds before. The last version looked really promising already, so I hope you didn't throw the towel or anything... 😁 |
Hi @bkimminich, sorry for the delay. I failed to figure out the issue regarding |
I think it‘s perfectly fine to keep |
I suppose there might be some interactions between the test cases which I don't yet understand. (maybe due to updating the module syntax) Here is something I've tried
Just posting here as a note. |
Great! I'll just move things into |
Hey @bkimminich, to confirm before moving. 👀
Am I missing anything, or including any unnecessary files? |
That should be it, yep... Also, very important, please do a rebase with |
@bkimminich I just realized that we can avoid copying static files to |
Running Juice Shop from source or a packaged distro now works fine on this branch. The only thing having trouble is the Docker image. On CI/CD it fails the smoke tests already, so the build/publish jobs are not even trying to run currently. |
I guess this is why the Docker tests fail from a missing
|
Looks like everything's fine now! Smoke tests (I realized these never checked the unpackaged archive but the main folder ever since, so this was a nice catch along the way), Docker smoke tests, the code snippets are still working from source, ... ... anyone wants to do some more tests or specific checks before we merge into |
So, I think all sources should now be in the packaged archives and they should have been in the Dockerfile all along. To be sure I've added a smoke test that retrieves the snippet for one of the backend challenges, which will fail in case the underlying source file is missing. I guess we really want to merge into |
@paseaf, please send me an email with your address so I can send some "Thank you!"-package* on its way, as this was a) your first and b) a veeery sophisticated contribution (that even we from core team didn't dare touch until now ourselves...)!!! ⭐⭐⭐⭐⭐! 😀 (*Depending on where you are located I might send you some gift card instead for getting a Juice Shop shirt printed locally or something like that.) |
I agree.. |
I just merged it into |
Great!! |
Hey ho 👋 I think there are some parts of the code base which are "harder" problem, e.g. the models but would provide massive benefits if we could figure out how to properly type them. Do we want to open up separate tickets for the different parts of the code base, so that we can work on them in a distributed manner? Or are there better ways to do it? |
I alteady started fixing some of the easier linter errors, like using template strings over concatenation of non-string types with strings. Not sure if this approach will work out, as there are probably not so many "easy" issues to address. |
We're down to this list of ESLint complaints:
I would have hoped some a auto-fixable - like using template strings over string concatenation - but it seems none of them is, unfortunately. |
This thread has been automatically locked because it has not had recent activity after it was closed. 🔒 Please open a new issue for regressions or related bugs. |
typescript
and necesary type packages on backend.js
to.ts
npm install
process to transpilenpm start
to run server from transpiled JavaScript codeAfter the above steps typing can be gradually introduced in the codebase.
The text was updated successfully, but these errors were encountered: