Skip to content

TS compilation improvements #3415

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
May 6, 2025
Merged

TS compilation improvements #3415

merged 6 commits into from
May 6, 2025

Conversation

CarsonF
Copy link
Member

@CarsonF CarsonF commented May 6, 2025

Transpilation vs type check

Now we do not check types on build/transpilation/script execution. This treats TS more as a linter, which is a good separation from transpilation. This allows scripts to be ran even if TS is mad.

This was a particularly painful with Gel - TS interaction.
We use the app to generate Gel access policies, which is needed to make Gel schema changes, and generate TS types from this new schema.
This cycle caused us to deadlock. We couldn't make Gel schema changes, because we needed APs. And we couldn't make APs because the app had model changes that were not yet in sync with generated Gel types.

This feature was added in TS 5.6 so this depends on #3410

Script execution

Now we use Nest & its standard TS setup, to execute scripts instead of ts-node.
This is more straight forward, as obvious by the diff.
Now all TS files are incrementally compiled to the dist folder first, then commands are executed.
Somehow before I believe there were no pre-compiled cached js files, and so every execution needed to take that set for all files.
Now this pre-compiled cache (TS incremental builds) are actually effective.

Scripts execute much faster now, between the incremental cache and the no type check on build setting.

Note: ts-node is needed by jest/ts-jest, so it's been kept...for now 😈

CarsonF added 6 commits May 6, 2025 09:12
This allows scripts to be ran even if TS is mad,
which is a lot of cases could fix the TS errors.

This is available now that we are on TS 5.6+

We still run type checks separately in CI as well,
so the checking here was a wasted step.
It is used for entry point's relative path; not just the cli generator commands.
This causes src files to be put into dist/src/ now.
I've avoided this in the past, but I think it is fine now,
as I'm intentionally doing it.
This leaves room for other top-level folders as well.
Copy link

coderabbitai bot commented May 6, 2025

📝 Walkthrough

Walkthrough

This change updates build and execution configurations by modifying script paths and invocation methods in package.json, adjusting TypeScript build options, and removing a custom TypeScript loader. The dynamic import logic for seed scripts is revised to import compiled JavaScript files. The NestJS CLI configuration and build exclusions are also updated.

Changes

File(s) Change Summary
nest-cli.json Removed the "sourceRoot": "src/components" property from the NestJS CLI configuration.
package.json Updated scripts to use yarn start with entryFile arguments; adjusted output paths; removed some scripts.
src/core/gel/seeds.run.ts Changed dynamic import logic to replace .ts with .js for seed script imports, ensuring JS files are loaded.
tools/ts-loader.js Deleted the custom TypeScript loader script for ESM transpilation.
tsconfig.build.json Added "noCheck": true to disable type checking; removed "dbschema" from build exclusions.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 332e11b and 91d66d2.

📒 Files selected for processing (5)
  • nest-cli.json (0 hunks)
  • package.json (1 hunks)
  • src/core/gel/seeds.run.ts (1 hunks)
  • tools/ts-loader.js (0 hunks)
  • tsconfig.build.json (1 hunks)
💤 Files with no reviewable changes (2)
  • nest-cli.json
  • tools/ts-loader.js
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: Generate (head)
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: Generate (base)
  • GitHub Check: lint
  • GitHub Check: Clean
  • GitHub Check: Unit
🔇 Additional comments (6)
tsconfig.build.json (2)

6-15:

❓ Verification inconclusive

Verify impact of including dbschema directory in build

The dbschema directory is no longer excluded from the build process. This aligns with the PR objectives to improve build process, but ensure this won't have unintended consequences.


🏁 Script executed:

#!/bin/bash
# Check if there are any TypeScript files in the dbschema directory that might now be included in the build
echo "TypeScript files in dbschema directory:"
fd -e ts -p dbschema/ --type f | wc -l

# Check the number of .ts files that would be included in the build
echo "Checking files included in build (excludes node_modules, test, etc. but includes dbschema):"
fd -e ts --type f | grep -v "node_modules\|test\|tools\|\.spec\.ts\|\.test\.ts\|\.eslintrc.cjs\|jest.config.ts\|dist" | head -n 5

Length of output: 556


Verify TS files now included from dbschema

The dbschema directory contains 3 TypeScript files that will no longer be excluded by tsconfig.build.json. Please confirm these are meant to be compiled and won’t introduce unintended artifacts or bundle bloat.

Action items:

  • Inspect each file under dbschema/ to ensure it only contains intended code (e.g., type definitions vs. runtime logic).
  • Confirm the build succeeds without errors once these files are included.
  • If they’re solely type declarations, consider converting them to .d.ts or relocating to a dedicated types directory to avoid emitting JavaScript.
  • Review the final build output to verify no unwanted modules or extra payload are introduced.

3-5:

❌ Incorrect review comment

Verify TypeScript compiler option "noCheck"

The "noCheck": true option appears to be non-standard. TypeScript's official compiler options don't include a noCheck property. Consider using standard TypeScript options instead.


🌐 Web query:

Is "noCheck" a valid TypeScript compiler option?

💡 Result:

Yes, noCheck is a valid TypeScript compiler option that was introduced in TypeScript 5.6. This option allows you to disable full type checking for all input files, only reporting critical parse and emit errors[1][3].

Purpose and Functionality

When you use the noCheck option, TypeScript skips type checking for all input files while still performing the minimal semantic analysis necessary for emitting output files[3]. This can be particularly useful in several scenarios:

  • Separating JavaScript generation from type-checking: You can run tsc --noCheck while iterating on your code, and then run tsc --noEmit later for thorough type checking[3].
  • Parallel processing: You can run type checking and file generation concurrently, even in watch mode (though you might want to specify different --tsBuildInfoFile paths)[3].
  • Faster declaration file generation: In projects that conform to --isolatedDeclarations, TypeScript can quickly generate declaration files without a full type-checking pass[3].

Usage Methods

You can enable this option in several ways:

  1. Command line: Use the --noCheck flag with the TypeScript compiler[2][3].

    tsc --noCheck
  2. TSConfig file: Add the noCheck property to your compilerOptions in tsconfig.json[1].

    {
      "compilerOptions": {
        "noCheck": true
      }
    }
  3. File-level directive: For individual files, you can use a comment at the top of the file[5]:

    // @ts-nocheck

Important Notes

  • Even with noCheck enabled, TypeScript may still perform some type checking if necessary to generate .d.ts files, especially if your project doesn't use --isolatedDeclarations[3].
  • The noCheck option is also available via the TypeScript API as a standard option[3].
  • Internally, functions like transpileModule and transpileDeclaration already used noCheck to speed things up (as of TypeScript 5.5)[3].
  • This option is different from the file-level // @ts-nocheck comment, which only disables type checking for a specific file[5].

If you're looking to improve build performance while maintaining type safety in your workflow, the noCheck option provides a valuable way to separate and optimize these processes.

Citations:


Incorrect suggestion: noCheck is a valid TypeScript compiler option

The noCheck flag was introduced in TypeScript 5.6 to disable full type-checking on all input files while still reporting critical parse and emit errors. No change is needed in your tsconfig.build.json.

Likely an incorrect or invalid review comment.

src/core/gel/seeds.run.ts (1)

103-105: Dynamic import path updated to use compiled JS files

The import path has been updated to use .js files instead of .ts files, aligning with the PR objective of running scripts from compiled JavaScript rather than direct TypeScript execution.

This change ensures compatibility with the updated build process where TypeScript files are compiled to JavaScript before execution, leveraging TypeScript's incremental build cache more effectively.

package.json (3)

15-16: Script execution standardized to use compiled JS

The console script has been updated to use the standardized approach of running through yarn start with entry file arguments, and the production version now directly uses Node with the extensionless register import hook.

This change aligns with the PR goal of separating transpilation from type checking and improving execution efficiency by using pre-compiled JavaScript.


20-20: Production start command updated to use compiled JS

The start:prod script now uses Node with the extensionless register import hook and enables source maps, pointing to the compiled JavaScript file.

The addition of --enable-source-maps is a good practice that will help with debugging production issues by providing accurate stack traces that map to the original TypeScript code.


22-23: Gel scripts standardized to use NestJS execution pattern

The gel generator and seed scripts have been updated to use the standardized yarn start --entryFile pattern instead of direct TypeScript execution.

This change complements the update in src/core/gel/seeds.run.ts where imports were modified to use .js files, ensuring consistent execution of compiled JavaScript throughout the application.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@CarsonF CarsonF merged commit 1b9689b into develop May 6, 2025
18 checks passed
@CarsonF CarsonF deleted the ts-compiler-stuff branch May 6, 2025 15:17
CarsonF added a commit that referenced this pull request May 6, 2025
```
yarn gel:gen
```
now runs the standard ts compilation which generates the js files in dist/

Previously the gel user did not have permission to this dir,
as we only applied the owner change to src/ (old line 87).

Now we'll set the current user as "gel" and copy in all files as that owner.
This is more idiomatic for Docker.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant