Skip to content
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

Initial version of a ts-plugin #114

Merged
merged 1 commit into from
Jan 24, 2024
Merged

Initial version of a ts-plugin #114

merged 1 commit into from
Jan 24, 2024

Conversation

captbaritone
Copy link
Owner

TypeScript lets you specify a plugin in your typescript config which can add additional functionality in the editor. This is a good fit for Grats which is built around the TypeScript compiler and could report helpful errors.

I'm still working to figure out a way to efficiently (re)compute cross-file validations, but this should give us a start by reporting syntax-only issues.

Ideally we could specify grats as the plugin itself, but from what I can tell TypeScript's requirements around the way the plugin is invoked are going to be hard to get to work inside the grats module itself:

  1. The module has to use common js exports
  2. The init function has the be the sole export from the module
  3. The plugin module name must not have a slash in it

We could still explore having grats expose both a commonjs and ES Module version and have the commonjs version export the initi funciton with all the actual exports as properties on the function, but that's getting pretty crazy.

Since the logic of the plugin will be tightly coupled with Grats, I'm having the plugin extension just re-export the actual implementation from the grats module.

Example

Screen.Recording.2024-01-23.at.7.52.31.PM.mov

Setup

Add the plugin to your tsconfig

{
  "grats": {
    "nullableByDefault": false
  },
  "compilerOptions": {
    // LIKE THIS
    "plugins": [{ "name": "grats-ts-plugin" }],
    "outDir": "dist",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "esnext",
    "lib": ["esnext"],
    "strict": true
  }
}

Configure VSCode to use your local version of TypeScript. Via CMD+P "TypeScript: Select TypeScript Version..." with a .ts file open or a .vscode/settings.json for your project with:

{
    "typescript.tsdk": "node_modules/typescript/lib"
}

Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for grats ready!

Name Link
🔨 Latest commit 21965a3
🔍 Latest deploy log https://app.netlify.com/sites/grats/deploys/65b089c543e60b00082e0d38
😎 Deploy Preview https://deploy-preview-114--grats.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@captbaritone captbaritone merged commit ac3c27f into main Jan 24, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant