-
-
Notifications
You must be signed in to change notification settings - Fork 223
mini repl for svelte2tsx #744
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
Changes from all 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,13 @@ | ||
| import fs from 'fs'; | ||
| import svelte2tsx from '../src'; | ||
| const content = fs.readFileSync(`${__dirname}/index.svelte`, 'utf-8'); | ||
| svelte2tsx(content); | ||
| /** | ||
| * To enable the REPL, simply run the "dev" package script. | ||
| * | ||
| * The "/repl/index.svelte" file will be converted to tsx | ||
| * at "/repl/output/" using the modified source code on change. | ||
| * | ||
| * Alternatively you may run this file with a debugger attached, | ||
| * to do so, hit "Ctrl+Shift+D" and select "svelte2tsx" in the dropdown. | ||
| */ | ||
| 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() { | ||
|
Member
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?
Contributor
Author
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
Contributor
Author
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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.