-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
mini repl for svelte2tsx #744
Changes from 3 commits
d30b89b
b8c54c2
19aff52
09ba333
91e7009
5924cf3
5d94d7f
60cb0a4
d6ee63f
0e2a4e7
d245308
51ceb0c
0f42fb2
a9cfc6f
7c98152
4d7a25f
852505d
e4f073a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
/index.mjs | ||
test/typecheck/samples/**/input.svelte.tsx | ||
test/build | ||
repl/output |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs from 'fs'; | ||
import svelte2tsx from '../src'; | ||
const content = fs.readFileSync(`${__dirname}/index.svelte`, 'utf-8'); | ||
svelte2tsx(content); | ||
|
||
/** | ||
* Run the "dev" package script to get started | ||
* | ||
* Inputs at "repl/index.svelte" use the modified source code | ||
* and are compiled to "repl/output/" on save. | ||
* | ||
* Alternatively, attach a debugger to the "debug" package script | ||
* and place breakpoints directly in the ts source files. | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import json from '@rollup/plugin-json'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import builtins from 'builtin-modules'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
function repl() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite sure why we need this? Isn't all this handled without Rollup, just through sucrase? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part uses rollup watch, so just by having the dev script running in the background it automatically updates the repl results on save. i.e. Everything is instant, just hit ctrl+s on any change anywhere ( source or repl input ) and the results get live updates like an actual repl would It is true that sucrase computes the same thing but you have to run it yourself and checking values in the debugger is a much slower process There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a side note that part only outputs tsx right now, I imagine there are other outputs that could be interesting to print |
||
return { | ||
name: 'dev-repl', | ||
buildStart() { | ||
this.addWatchFile('./repl/index.svelte'); | ||
}, | ||
writeBundle() { | ||
if (!this.meta.watchMode) return; | ||
|
||
const repl = `${__dirname}/repl/`; | ||
const output = `${__dirname}/repl/output/`; | ||
|
||
delete require.cache[path.resolve(__dirname, 'index.js')]; | ||
const svelte2tsx = require('./index.js'); | ||
|
||
const tsx = svelte2tsx(fs.readFileSync(`${repl}/index.svelte`, 'utf-8')); | ||
|
||
if (!fs.existsSync(output)) fs.mkdirSync(output); | ||
fs.writeFileSync(`${repl}/output/code.tsx`, tsx.code); | ||
} | ||
}; | ||
} | ||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
|
@@ -22,7 +46,8 @@ export default [ | |
resolve({ browser: false, preferBuiltins: true }), | ||
commonjs(), | ||
json(), | ||
typescript({ include: ['src/**/*'] }) | ||
typescript({ include: ['src/**/*'] }), | ||
repl() | ||
], | ||
watch: { | ||
clearScreen: false | ||
|
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.
Could we use
ts-node
instead? We already have that in this repo and it might serve the same use case and we avoid another dependency.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 agree and I tried many things, but ts-node refuses to work due to a side issue in tsconfig
Sucrase just works, it's also much faster afaik