56 Commits

Author SHA1 Message Date
Matt Godbolt
f94ff8332a Refactor: Split app.ts into smaller modules (#7681)
## Summary
This PR significantly improves maintainability by breaking up the 880+ line monolithic app.ts file into smaller, focused modules with proper testing. The code is now organized into dedicated modules under the lib/app/ directory, making the codebase more maintainable and testable.

## Key changes
- Extract functionality into modules under lib/app/ directory:
  - Command-line handling (cli.ts)
  - Configuration loading (config.ts)
  - Web server setup and middleware (server.ts)
  - Core application initialization (main.ts)
  - URL handlers, routing, rendering, and controllers
- Add comprehensive unit tests for all new modules
- Make compilationQueue non-optional in the compilation environment
- Improve separation of concerns with dedicated interfaces
- Ensure backward compatibility with existing functionality
- Maintain cross-platform compatibility (Windows/Linux)

## Benefits
- Improved code organization and modularity
- Enhanced testability with proper unit tests
- Better separation of concerns
- Reduced complexity in individual files
- Easier maintenance and future development

This refactoring is a significant step toward a more maintainable codebase while preserving all existing functionality.
2025-05-20 17:53:24 -05:00
Matt Godbolt
d7330ce3d5 (re-)support comma separation for languages 2025-05-12 14:46:34 -05:00
Matt Godbolt
07d1f7aa50 webpack content -> static 2025-05-12 13:33:00 -05:00
Matt Godbolt
1dab667564 Support hostnameForLogging too, more out of date refences 2025-05-12 12:59:57 -05:00
Matt Godbolt
54c942ba76 Replace nopt with commander.js for argument parsing (#7673)
- Replace nopt with commander.js for better command-line argument parsing
- Add automatic help generation with detailed descriptions
- Maintain backward compatibility with existing arguments
- Remove unused nopt dependency from package.json

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-05-12 12:49:28 -05:00
Matt Godbolt
59aceae9c4 Simplify and extract types (#7680)
- prevents anything importing from `app.js`
- generally tidies up and removes unused stuff
- makes typing a bit more correct
2025-05-12 10:28:51 -05:00
Matt Godbolt
eaa083edc3 Simplify noscript handling, and add types (#7677) 2025-05-12 08:32:21 -05:00
Matt Godbolt
2f892583ba Remove global handler_config variable (#7675)
The global handler_config was being used to allow compilers to find
other compilers. This change replaces that global with a proper method
on the CompilationEnvironment class, allowing compilers to find other
compilers through the environment instead of using a global variable.

🤖 PR description generated with [Claude Code](https://claude.ai/code) -
code by @mattgodbolt though :)

Co-authored-by: Claude <noreply@anthropic.com>
2025-05-11 19:47:58 -05:00
Matt Godbolt
ad5bec7626 Remove top-level global for base directory (#7674)
This PR removes the top-level global variable for the base directory and replaces it with a module-level variable managed through a setter function. Key changes include removing the global declaration in lib/global.ts, introducing a local ce_base_directory variable and setBaseDirectory function in lib/assert.ts, and updating app.ts to use the new setter.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-05-11 19:28:04 -05:00
Matt Godbolt
04bcf21900 Bump to latest sentry; preload etc (#7617)
New node sentry prefers some node.js "preload" nonsense. I use this
"hack" to avoid having to make a lock-step change to the runner: tested
locally and then deployed to staging and tested there with both
server-side and client-side errors.
2025-04-26 13:36:11 -05:00
Matt Godbolt
20048616da Migrate to express 5 (#7572)
Main changes:
- type checker cares about the return value (`void`) of handlers, so no
more `return res.send("...")` as that returns `express` type.
- regexes on slugs no longer supported, but we weren't really using them
in any meaningful way. The two places that had to be updated:
- `/clientstate/:clientstate64` - now uses a regex directly and tests added (thanks @partouf for spotting #4844)
- `/bits/:bits.html` - was some `\w+` but I believe that's unnecessary
for the same reasons
- actually call the Sentry handler. I don't know if this actually worked
before but the API checks suggest not.
2025-04-19 14:34:41 -05:00
Matt Godbolt
a4995a9c1c Move to using async file reads (#7433)
Remove most, if not all, of the synchronous file reads. Hopefully this
will help a little with performance and "event loop lag". Mostly, it's
"try not to use third party packages when builtins now do the work".

Local testing seems OK - but needs a good poke around on staging to
exercise all the paths.
2025-02-26 11:11:12 -06:00
Mats Jun Larsen
943d9fb233 Move noscript compile handler into own controller file (#7371)
Continuation of my previous work on the http endpoints. This leaves the
old noscriptHandler to only serve the HTML pages.
2025-02-10 16:51:50 +00:00
Mats Jun Larsen
5eea63328f Migrate to Biome for linting and formatting (#7033) 2025-02-02 17:54:31 +00:00
Matt Godbolt
f1e930b7fc Decommision the "AWS" magic compiler name (#7321)
Nothing was using it, we're using other methods these days to discover
remote compilers (and have been for years), and it was broken (see
#1790).

Also cleans up some config (moving it from aws to ceProps; though it was
unused, default used only), and also some workarounds for remote
compilers that refer back to the MS compiler era (#1768).

This leaves the ability in `aws.ts` to fetch instances in case we ever
need the functionality, as this is tested and still works.

Closes #1790
2025-01-29 08:36:01 -06:00
Atharva Rai
a3c64dc4dc Remove body-parser dependency (#7176)
This PR addresses issue #7158 by removing the body-parser dependency in
favor of express.json() and other built-in middleware functionalities
provided by Express.js.
2024-12-07 01:47:06 +09:00
Mats Jun Larsen
630015c3f3 Remove addStaticHeaders and contentPolicyHeader functions (#7159)
Stops passing these functions around and instead configures the headers
by chaining express handlers
2024-12-01 16:22:41 +09:00
Mats Jun Larsen
e03f3d058c Remove old shortener path (#7160)
This has been dangling as a TODO from @mattgodbolt since 2021. Running
the following Athena query:

```sql
SELECT COUNT(*) as reqs, uri, date
from cloudfront_logs
WHERE uri LIKE '/shortener%'
GROUP BY date, uri
```

Yields about 8-20 requests per day. I think this is an insignificant
enough amount of traffic to justify removing it now.
2024-12-01 10:07:45 +09:00
Mats Jun Larsen
fba4ba672a De-couple formatter from http server (#7155)
This patch decouples the formatting logic (which is used by the
clang-format feature) from the http API logic.

This is done with the new FormattingService populates the formatters
from the config, and wraps formatter execution. This way, both the http
controller and the clang-format functionality can use it, reducing tight
coupling.
2024-11-30 12:14:11 +09:00
Mats Jun Larsen
3b695d0469 Hoist healthcheck router above logging middleware (#7157)
Fixes #7156
2024-11-30 11:49:26 +09:00
Mats Jun Larsen
788e576762 Add controller for healthcheck endpoint (#7145)
Follow up to building separate express routers for each domain. Now
handles the healthcheck in a separate controller
2024-11-29 01:06:50 +09:00
Mats Jun Larsen
eb45763ff0 Add correct types to healthcheck endpoints (#7144)
Removes the any types and properly types the option
2024-11-29 00:24:04 +09:00
Mats Jun Larsen
b29a0809ad Introduce HttpController interface for http routers (#7142)
By requiring controllers to declare their own routes, we ensure
consistency between tests and the actual server
2024-11-29 00:12:06 +09:00
Mats Jun Larsen
52e27d5a37 Rewrite assembly documentation handler to controller form (#7130)
Follow-up to #7090
2024-11-28 22:39:10 +09:00
Mats
b09b027201 Add controller for site templates (#7131)
Equivalent of #7130 for site templates
2024-11-28 21:55:39 +09:00
Mats
ea29a6e9d6 Separate list and load actions for source API (#7090)
This is the first PR in API consistency with more to come:

1. The source API urls have been properly defined with
`/source/:source/list` and `/source/:source/load/:language/:filename`
- These used to be two API endpoints mushed together into one `handle()`
function. They are now separate
- While it may appear from the tests that this is an API breakage,
there's currently no way to have the source API spit out responses for
stuff like `/source/moose/load/Grunkle`.
2. The frontend code calling the list api now has shared types
3. Code has been migrated to `/lib/handlers/api/source.ts`
- I've moved code here, because I would like to separate the stuff
that's under the API and the stuff that isn't (e.g., healthcheck)
- The source endpoint is currently not under /api, but I believe it
makes sense to move it.
4. GitHub is terrible at showing the diff, but the `browser.ts` file has
been removed, since it's never actually used. Our frontend only calls
`/source/builtin/...` and it never had any entries. Besides, the type
used on the frontend for the locally stored stuff is different...
2024-11-27 13:54:47 +09:00
Mats Jun
73ee43da66 Handle site template importing asynchronously (#7089)
1. Gives a proper type to the metadata
2. Fixes a typo in `screenshot_dimentions`
3. Removes home-made partition function in favor of underscore
4. Reads file asynchronously (and consequently rest of API is async)
5. Strips the `https://godbolt.org/#` from each entry in the config file

As an added benefit this should also cut some startup time reading this
file before it's used :)
2024-11-15 10:03:12 +09:00
Matt Godbolt
84b8f116ad Support multiple --language arguments (#7075)
Still supports comma-separated languages.

See
https://github.com/compiler-explorer/compiler-explorer/discussions/7074
2024-11-09 10:27:16 -06:00
Ofek
63dd5e35a5 Various tsifications (#7025) 2024-10-27 15:28:38 +02:00
Patrick Quist
4fe8397fac Remote execution (#6700) 2024-10-26 17:42:22 +02:00
Ofek
4e5348ab77 Tsify tools (mostly) (#7018)
This includes among others:
 - Proper tsification of various tools code,
 - Elimination of the `CompilationInfo2` type,
 - Use of `CompilationInfo` instead of `Record<any, any>` in some places
 - These lines in CompilationResult:
```
    // Temp hack until we get all code to agree on type of asm
    asm?: ResultLine[] | string;
```

The next task would be to get all code to agree on the type of
CompilationResult.asm, thereby enabling fixing of most the remaining
TSification.
2024-10-26 10:58:30 +03:00
Mats Jun
cc9de7e478 Remove legacy non-existing monaco worker route (#6995)
_No functional change intended_

According to
7ce90a3388
and
0d0a52e249
the route was added a very long time ago (4-5 years) to support compat
for workers downloaded to the user's browsers.

In addition to this being very long ago to the point that the chance of
anybody having an old CE worker being extremely low, those files no
longer exist.

We tag our webpack bundles with a "magic version" (current .v53.) to
force the browsers to re-fetch the bundles for major changes. That means
that if somebody had `editor.v10.worker.[hash].js` from years ago, that
file won't even be in our current bundle, and has to be in their
browser's cache (unlikely because it's so old, but even then their
browser wouldn't hit this route due to cache)
2024-10-22 21:39:15 +09:00
Ofek
f715dc2932 More tsification (#6877)
About half way through. Only 708 tsification errors to go..
2024-09-28 10:32:36 +03:00
Ofek
9ef46fbafe Binge of (mostly) mindless tsification (#6838)
Turned on `noImplicitAny` in tsconfig, then went around fixing some
random easy stuff.
Hopefully tsification-PRs with more real content coming up.
2024-09-07 14:36:43 +03:00
Patrick Quist
75acc5bd44 Attempt to detect faulty compiler/language population (#6610) 2024-07-07 13:09:51 +02:00
Patrick Quist
d2c7a5222e Local/Remote Execution environment (#6413) 2024-05-26 22:09:01 +02:00
Matt Godbolt
f358067cec Migrate to eslint-plugin-n; as ...-node is deprecated (#6387)
Replaces #6310
2024-04-23 06:45:55 -05:00
Matt Godbolt
613d7f688a Unify the way tmp dir is used (#6052)
Instead of having several globals, set via environment variables,
explicitly set the "correct" env var if passed `--tmpDir` and then
consistently use it in the rest of the program.

See @apmorton's comments in #1707
2024-01-28 18:50:46 -06:00
Jeremy Rifkin
c43e69bfdd Use CompilerInfo[] in a couple places that were previously any or never (#6029)
Depends on #6028
2024-01-22 21:47:45 -06:00
Jeremy Rifkin
e5fb8e1afc Improve typings for the now-global HandlerConfig (#6027)
This PR populates types in the HandlerConfig
2024-01-21 10:29:58 -06:00
Ofek
21fe5523c0 Since ES6 there's no reason to use underscores map and filter (#5989)
Mindless replacements of the form 
`_.filter(options, option =>...`  --> `options.filter(option =>...`.

One not *entirely* mindless replacement at the bottom of
compiler-dropin-tool.ts :
```
-        return _.filter(pathFilteredFlags) as string[];
+        return pathFilteredFlags.filter(Boolean) as string[];
```
6 files can now stop importing underscore.
2024-01-13 18:35:11 +02:00
kevinjeon-g
fb0f0a86d9 Add the HandlerConfig type to the global handler config (#5858) 2023-12-10 14:03:34 -06:00
kevinjeon-g
7efe253f5f Add support for Android D8 (8.1.56) (#5756)
Adds D8Compiler, which applies to the Android Java and Android Kotlin
languages. D8Compiler instantiates a JavaCompiler or KotlinCompiler
using the java/kotlin dependencies' paths for D8 in the infra repo.

compiler-finder.ts has been updated to allow for duplicate compiler IDs
for 'android-java' and 'android-kotlin', as it is expected that the
compilers used for these languages is the same.
2023-12-04 19:35:56 -06:00
Jeremy Rifkin
fb147126e8 Fix WSL for systems that don't have windows paths (#5480)
Attempt to fix #5476. As far as I can tell `process.env.winTmp` is
needed just for windows executables and WslVcCompiler. It should be
possible to just ignore the exec error and continue. If for some reason
the user doesn't have windows paths in their WSL but does want to run
windows executables they can pass `-tmpDir`.
2023-09-16 15:59:26 -04:00
Jeremy
2a3c1738d8 Hotfix for WSL2 detection 2023-08-20 15:57:06 -04:00
Jeremy Rifkin
4260313e13 Common utilities and type work (#5200)
This PR refactors some common utilities out of lib/ and into shared/ and
eliminates some use of underscore.js, as well as general type
improvements done along the way.
2023-06-28 20:13:10 -04:00
Jeremy Rifkin
acdd5ad45c Capture errors in sentry better (#5128)
Fixes #5127 and similar issues.

Rationale: Whenever something that is not an Error object is passed to
Sentry.captureException we get pretty much no useful information in
sentry

![image](https://github.com/compiler-explorer/compiler-explorer/assets/51220084/c7345449-f7a0-46cb-a198-abe0bd80a8b1)
(usually not even a stacktrace)
2023-06-11 17:31:51 -04:00
Matt Godbolt
4187390952 Update eslint et al (#5115) 2023-06-06 21:17:25 -05:00
Patrick Quist
a08f6957f4 add option for custom papertrail hostname (#4912) 2023-03-30 23:44:19 +02:00
Patrick Quist
7d192ccde1 add properties and test for cewrapper (#4761) 2023-03-18 11:46:27 +01:00