-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
add TypeScript support at project init #41
Conversation
This PR lgtm. Is the I'd probably lean away from having |
Yeah the random filenames are part of https://github.com/atlassian/changesets |
I've been asking myself if |
I read the extra moving part as referring to including it as something to be installed with the template, regardless of which repo the code lived in. It would probably be nice if package.json could be varied depending on whether the user chose to init their app in TS mode. |
Completely agree with the varied |
some discussion about an official typescript template took place here sveltejs/svelte#5016, may still be relevant? In svite i started with a small script too but ultimately went with degit and only slight modifications to package.json because i think it can be helpful to have the template laid out in a git repo so it is accessible outside of a created project on disc (eg linking for documentation, discussions etc). But that can be solved with some form of automation that updates an example repo every time the base template or a modification changes. And i really like the concept of modifications! Even more so if they turned out to be "standalone" and accessible via cli later. Maybe i missed some things but should this modification add a tsconfig.json like (see https://github.com/sveltejs/template/blob/431bd4d58e59b46ebfa1f4fc2c1ab55853fc1521/scripts/setupTypeScript.js#L90) Other ideas for modifications: add svelte-check , add vscode extension recommendation. |
Here's the one for Sapper (which is rather recent and a bit more involved): https://github.com/sveltejs/sapper-template/blob/master/scripts/setupTypeScript.js |
Answering @dominikg
Isn't that what this prompt also does? It relies on some initial standalone template as far as I can see and then applies modifications to it.
Yes, that's missing from this PR, should be added.
Answering @kaisermann
I think it would be better to hide this behind more semantic flags/prompts like "add typescript?", "what styling solution do you want to use? (css, scss, less, other)", and depending on the inputs of the user |
Yeah, what I meant was to at least have a method to do it on a need-basis, preventing the lib to be hardcoded in the package.json ✌️ . Semantic options would indeed be DX friendly and I think we should cover just the basic cases like |
Yes, but as is this modification only works for the vanilla template (eg assumes Counter.svelte exists). What i meant with standalone was that it could be called later-later, when the user already started working on the project and now feels a need to add typescript. |
Ah, I get it now, thanks. Maybe we can get the best of both worlds and run certain modifications only on creation. So there would be a common subset, and |
my thoughts:
looking into the tsconfig.json thing, good catch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concept seems good to me 👍🏻
Brittleness would be a problem indeed. To some extent that also applies to modifications to the vanilla template. Another thing that the typescript modification could add is an extra npm script for validation via |
- add more devDependencies - add snowpack typescript plugin - add svelte-preprocess only when TS selected - add globals.d.ts - add tsconfig.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I continued work on this setup.
- add more devDependencies
- add snowpack typescript plugin
- add svelte-preprocess only when TS selected
- add globals.d.ts
- add tsconfig.json
I did the codemods through simple string-replacements for now. I did not add svelte-check
because this could also be added to the snowpack plugin.
"@sveltejs/snowpack-config": "workspace:*", | ||
"@sveltejs/adapter-node": "^0.0.1", | ||
"@sveltejs/kit": "^0.0.1", | ||
"@sveltejs/snowpack-config": "^0.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed these back because they are part of the template, else someone installing from npm would immediately get errors I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^0.0.1
will only match 0.0.1
because of special behavior with leading zeros. We'd want ~0.0.1
for the time being, or 0.0.x
, until we advance beyond that point in the versioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we can do better still, by adding a prepublishOnly
step for this package that grabs the latest versions for all workspace:*
dependencies in the template and injects them when a project is scaffolded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, fetches and injects them when you publish the create-svelte package, or fetches and injects them when somebody runs create-svelte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I- wh- what's done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. you may have a point
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the tsconfig from the base repo because I changed the way the *.svelte
files are picked up for TS: by adding that definition to the globals.d.ts
. That makes the "types": ["svelte"]
obsolete. We should change that back someday and sync up with @tsconfig/svelte
again. We cannot do this now because it breaks the existing code bases. FYI @orta
One possible approach to #31 — adds an init-time prompt that asks if you want to add TypeScript, and if so adds it to
package.json
and edits the example component to uselang="ts"
.It also adds
svelte-preprocess
by default, which I'm not totally sold on (since it's an extra moving part), but i'm probably in the minority there. (Should svelte-preprocess be moved into this repo? It feels like it probably belongs)