Support for arbitrary/more extensions (`.mts`, `.cts`, `.mjs`,…)
Hey, I love this project, thanks for your hard work!
I wonder if it's possible to add any kind extensions to the CLI, like you could with Prettier or ESLint.
Actually, it's only for .js or .ts`, meaning you can't use some files in a lot of projects.
At least, standard extensions : ctsx, cjsx, js, ts, mts, cts, mjs, cjs (I hope I haven't forgot one 😅) would be awesome.
Bye
Thanks for the idea, this is interesting
I can potentially extend https://github.com/JasonShin/sqlx-ts/blob/953ee1c47da9c9e113e0c4dbeba45d411b5c6f93/src/common/cli.rs#L28C9-L28C12 to support the additional JS types.
jsx/tsx is a tricky one because that requires a whole lot of work in the parser to grab sql string literals - (maybe or maybe not)
No worries for the JSX/TSX part. I think that, conceptually, this is not the typical place where you should put sql queries ;)
I think most dev will agree, even more if it add difficulty for dev/maintenance.
I tried sqlx-ts with ESM and CommonJS, and excluding the file extension issue, it went smoothly.
I will assign this task to @AnantSutar
We will support tjs, mjs, cjs
What needs to be done
Support tjs, mjs, and cjs in the codebase
- extend JsExtension enum
- extend Display impl for this enum so when clap renders the list of supported JsExtensions, we get the correct
.tjs,.mjs, and.cjsrendered on the terminal - add some mjs, tjs and cjs files under
tests/staging<< this is a folder that is not commited- in the staging files, add some raw SQLs for testing, make sure sqls are picked up correctly
- and some mjs, tjs, cjs specific syntax so the Javascript parser that we have can handle any special syntax that can live in these extensions (e.g. top level await)
- ensure that scan_folder logic picks up these files and pick up SQLs inside the source code
- Add some tests under
testsfolder that picks up these file extensions - Update docs
- And then inform @JasonShin so I can tag a new version << this will a minor version bump
Fixed https://github.com/JasonShin/sqlx-ts/releases/tag/v0.31.0