Skip to content

Create a new generated npm workspace for typescript ANTLR generated code #1371

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yingyingcheng
Copy link
Contributor

Context

As described in #716, we're looking for opportunities to do some client side search query validation or autocompletion, so we need to be able to get ANTLR generated code from the typescript side. This PR will unlock #717 and #718

Changes

  • Updated the Makefile so that it generates TypeScript code to lib/gen/antlrv4/ts-antlrv4 along with Go code generation
  • Updated the overall package.json file to include the new workspace - lib/gen/antlrv4/ts-antlrv4
  • Added package.json and tsconfig.json to ts-antlrv4 so that it can later be imported into frontend code as well as get compiled.
  • Updated .gitignore to exclude generated ANTLR files

Screenshot with generated typescript code:

ts-antlrv4

With the changes, we should be able to import the package to frontend with:

package.json (frontend):

"dependencies": {
  "@webstatus.dev/ts-antlrv4": "file:../lib/gen/antlrv4/ts-antlrv4"
}

any ts file (frontend):

import { FeatureSearchLexer } from '@webstatus.dev/ts-antlrv4'

@jcscottiii
Copy link
Collaborator

FYI: I was away last week. Will be reviewing this today.

Copy link
Collaborator

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Before we accept this, I have some suggestions. These suggestions should add this into our current build process to prevent it from going stale before actually using it.

Comment on lines +9 to +10
"build": "tsc",
"clean": "rimraf dist"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"build": "tsc",
"clean": "rimraf dist"
"build": "tsc",
"clean": "rm -rf dist"

We should rely on the system rm command.

Comment on lines +17 to +18
"typescript": "^5.0.0",
"rimraf": "^5.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this

Suggested change
"typescript": "^5.0.0",
"rimraf": "^5.0.0"
"typescript": "^5.0.0"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should have a common tsconfig that both the frontend and this package extend

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a new target like: build-antlr-ts

It should call the npm run build command in the lib/gen/antlrv4/ts-antlrv4 directory.

We currently have one shot commands such as make start-local and make debug-local and make precommit and make playwright-test. It will be necessary to add this target as a pre-requisite target for those.

https://github.com/GoogleChrome/webstatus.dev/blob/401f3e814e1ce0d6eebbd73d77c2bafd3a3c3f1f/DEVELOPMENT.md

https://github.com/GoogleChrome/webstatus.dev/blob/401f3e814e1ce0d6eebbd73d77c2bafd3a3c3f1f/docs/testing.md

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.

2 participants