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: devtools #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"scripts": {
"release": "node scripts/release.mjs",
"stub": "pnpm run -r --filter './packages/{core,vite-plugin-vue-termui,cli}' stub",
"build": "pnpm run -r --filter './packages/{core,vite-plugin-vue-termui,cli}' build",
"stub": "pnpm run -r --filter './packages/{core,vite-plugin-vue-termui,cli,devtools}' stub",
"build": "pnpm run -r --filter './packages/{core,vite-plugin-vue-termui,cli,devtools}' build",
"play:dev": "pnpm run --filter './packages/playground' dev",
"lint": "prettier --check packages README.md",
"lint:fix": "prettier --write packages README.md",
Expand Down
71 changes: 71 additions & 0 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@vue-termui/devtools",
"private": false,
"publishConfig": {
"access": "public"
},
"type": "module",
"version": "0.0.1",
"scripts": {
"stub": "unbuild --stub",
"build": "tsup",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @vue-termui/devtools -r 1"
},
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"./*": "./*"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
"vtui-devtools": "./node_modules/.bin/vue-devtools"
},
"files": [
"dist/**/*.js",
"dist/**/*.mjs",
"dist/**/*.cjs",
"dist/**/*.d.ts",
"vtui.mjs"
],
"keywords": [
"devtools",
"@vue/devtools"
],
"funding": "https://github.com/vue-terminal/vue-termui?sponsor=1",
"license": "MIT",
"author": "webfansplz",
"repository": {
"type": "git",
"url": "https://github.com/vue-terminal/vue-termui.git",
"directory": "packages/devtools"
},
"engines": {
"node": ">=14.0.0"
},
"bugs": {
"url": "https://github.com/vue-terminal/vue-termui/issues"
},
"homepage": "https://github.com/vue-terminal/vue-termui#readme",
"dependencies": {
"@vue/devtools": "^6.4.5",
"express": "^4.18.2",
"launch-editor-middleware": "^2.6.0"
},
"unbuild": {
"entries": [
"src/index"
],
"rollup": {
"emitCJS": true
},
"clean": true
},
"devDependencies": {
"@types/express": "^4.17.14"
}
}
13 changes: 13 additions & 0 deletions packages/devtools/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare global {
var document: {
title: string
createElement: () => {}
querySelector: () => {}
querySelectorAll: () => []
}
var VUE_DEVTOOLS_CONFIG: {
openInEditorHost: string
}
}

export {}
44 changes: 44 additions & 0 deletions packages/devtools/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import devtools from '@vue/devtools'
import express from 'express'
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add one of these for later:

Suggested change
// @ts-ignore
// @ts-ignore: TODO: type the module

import launchMiddleware from 'launch-editor-middleware'

export interface DevtoolsOptions {
title?: string
host?: string
openInEditor?: boolean
}

const SERVER_PORT = 8098

export function createDevtools(options: DevtoolsOptions = {}) {
const {
host = 'http://localhost',
openInEditor = true,
title = 'vue-termui devtools',
} = options

// workaround for @vue/devtools
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixable in @vue/devtools as it has been done in the past like https://github.com/vuejs/devtools/pull/1780/files

global.document = {
title,
createElement: () => ({}),
querySelector: () => ({}),
querySelectorAll: () => [],
}

if (openInEditor) {
global.VUE_DEVTOOLS_CONFIG = {
openInEditorHost: `${host}:${SERVER_PORT}/`,
}
const app = express()
app.use('/__open-in-editor', launchMiddleware())
app.listen(SERVER_PORT)
Copy link
Member Author

@webfansplz webfansplz Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@posva

I reused the @vue/devtools server instead of create new server.

I think reused the @vue/devtools server is enough, which that we can also focus all the logic on the devtools package. (I’ve tried reuse the vtui dev server,but it doesn’t work fine)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

If we move this server to the cli we can probably ensure it's always created before the app starts. It would also ensure only one express app is created even when restarting the app (force reload that isn't yet implemented)

}

return {
devtools,
connect() {
devtools.connect(host, SERVER_PORT)
},
}
}
10 changes: 10 additions & 0 deletions packages/devtools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"sourceMap": true,
"lib": ["esnext"]
},
"include": ["src/*.ts", "src/*.d.ts"]
}
14 changes: 14 additions & 0 deletions packages/devtools/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'tsup'
import { dependencies } from './package.json'

export default defineConfig({
clean: true,
target: 'node14',
format: ['esm', 'cjs'],
dts: true,
esbuildOptions(options) {
if (options.format === 'esm') options.outExtension = { '.js': '.mjs' }
},
entry: ['src/index.ts'],
external: [...Object.keys(dependencies)],
})
7 changes: 0 additions & 7 deletions packages/playground/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ export {}

declare module '@vue/runtime-core' {
export interface GlobalComponents {
Box: typeof import('vue-termui')['TuiBox']
Br: typeof import('vue-termui')['TuiNewline']
Div: typeof import('vue-termui')['TuiBox']
Input: typeof import('./src/components/Input.vue')['default']
Link: typeof import('vue-termui')['TuiLink']
Newline: typeof import('vue-termui')['TuiNewline']
Progressbar: typeof import('vue-termui')['TuiProgressBar']
Text: typeof import('vue-termui')['TuiText']
}
}
6 changes: 4 additions & 2 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "module",
"scripts": {
"dev": "vtui dev",
"build": "vtui build"
"build": "vtui build",
"devtools": "vtui-devtools"
},
"license": "MIT",
"engines": {
Expand All @@ -14,6 +15,7 @@
"@vue-termui/cli": "workspace:*",
"@vue/runtime-core": "^3.2.41",
"vite-plugin-vue-termui": "workspace:*",
"vue-termui": "workspace:*"
"vue-termui": "workspace:*",
"@vue-termui/devtools": "workspace:*"
}
}
7 changes: 5 additions & 2 deletions packages/playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// import devtools from '@vue/devtools'
// import devtools from '@vue/devtools/node'
if (process.env.NODE_ENV === 'development') {
import('@vue-termui/devtools').then(({ createDevtools }) => {
createDevtools().connect()
})
}
Comment on lines +1 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird it needs to be first though 🤔 if it goes after the othor imports, it gives an error about the port being already used
I think there might be some other bugs pending in vue-devtools

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably find a way to add this directly from the vtui cli in development and skip it in production. That way the user doesn't need to write anything

import { createApp } from 'vue-termui'
// import App from './Focusables.vue'
// import App from './Fragments.vue'
Expand Down
1 change: 1 addition & 0 deletions packages/playground/vite.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default defineConfig({
alias: {
// Use development version instead of dist
'vue-termui': resolve('../core/src/index.ts'),
'@vue-termui/devtools': resolve('../devtools/src/index.ts'),
},
},

Expand Down
Loading