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

feat: Support plugin, shortcode & helper files written in Typescript #170

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

Conversation

vhfmag
Copy link

@vhfmag vhfmag commented May 12, 2021

Firstly, thank y'all for this project. I had been daydreaming about something like partial hydration for quite a while, and to see this executed through the svelte ecosystem is a huge plus!

This PR has the same goals as #72: provide support for writing plugin, shortcode & helper files in Typescript.

To achieve that, I omitted the file extension when calling require directly, to be able to handle any extension that the environment supports. I also tried to use require.resolve for cases where the path had to be known (e.g. when passing a path to fs.existsSync), but since jest cannot mock it (as per jestjs/jest#9543), I had to recur to hardcoding .ts as a possible extension for those files.

I got my own personal site to build with these changes, but I've just started migrating it to elder.js, so tests with larger codebases would be nice before considering merging.

@nickreese
Copy link
Contributor

nickreese commented May 13, 2021

This is great. I haven't written an Elder.js project in TS but I have a question.

My initial though was to just have TS files output in a build directory, detect the build directory from the tsconfig.json and update the ./src/ routes accordingly. This would allow users to write in TS but Elder.js and hopefully decrease complexity for Elder.js.

In my initial testing this worked. I setup the tsconfig.json to output to a build directory and then had Elder.js bootstrap from that directory instead of ./src/.

Contrast this to this PR which would allow Elder.js to consume TS directly.

The thing I'm not clear on is when does the compilation happen? Is the user expected to run ts-node? I ask because #169 is in process and we will be removing nodemon from the template so TS compilation has to happen at some point.

Maybe this is my naivety around TS. Any thoughts here?

@nickreese
Copy link
Contributor

nickreese commented May 13, 2021

Here is a rough idea of how we were handling it in early versions before TS was dropped.

https://github.com/Elderjs/elderjs/blob/48d81275038d0851564c1142a322b744cd299274/src/utils/getConfig.ts

Thinking about it further, couldn't the user just set their tsconfig build folder as their srcDir in their elder.config.js?

@nickreese nickreese linked an issue May 18, 2021 that may be closed by this pull request
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.

Writing routes in typescript
2 participants