Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Jan 11, 2024
1 parent 916b44f commit d93ce42
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 55 deletions.
5 changes: 5 additions & 0 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./hook": {
"types": "./dist/hook.d.ts",
"import": "./dist/hook.mjs",
"require": "./dist/hook.cjs"
}
},
"main": "./dist/index.cjs",
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools/src/hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { devtools } from '@vue/devtools-kit'

devtools.init()
1 change: 1 addition & 0 deletions packages/devtools/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Options } from 'tsup'
export default <Options>{
entryPoints: [
'src/index.ts',
'src/hook.ts',
],
esbuildOptions(options) {
if (options.format === 'esm')
Expand Down
9 changes: 8 additions & 1 deletion packages/electron/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ async function buildBundle() {
build({
entry: [resolve('./src/user-app.ts')],
...baseOptions,
format: ['cjs', 'esm', 'iife'],
format: ['cjs', 'esm'],
clean: false,
})

build({
entry: [resolve('./src/user-app.iife.ts')],
...baseOptions,
format: ['iife'],
clean: false,
})

Expand Down
2 changes: 1 addition & 1 deletion packages/electron/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function init() {
app.use(
'/',
eventHandler(() => {
const userAppContent = fs.readFileSync(path.join(__dirname, './user-app.js'), 'utf-8')
const userAppContent = fs.readFileSync(path.join(__dirname, './user-app.iife.js'), 'utf-8')
const processSyntaxPolyfill = `if(!window.process){window.process={env:{}}};`
return processSyntaxPolyfill + userAppContent
}),
Expand Down
49 changes: 49 additions & 0 deletions packages/electron/src/user-app.core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { isBrowser, target } from '@vue/devtools-shared'
import { Bridge } from '../../core/src/bridge'
import { prepareInjection } from '../../core/src/injection'
import { devtools } from '../../devtools-kit/src/index'

export function init(io) {
const createSocket = io
const host = target.__VUE_DEVTOOLS_HOST__ || 'http://localhost'
const port = target.__VUE_DEVTOOLS_PORT__ !== undefined ? target.__VUE_DEVTOOLS_PORT__ : 8098
const fullHost = port ? `${host}:${port}` : host
const socket = createSocket(fullHost)

// @TODO: de-duplicate
devtools.init()

const bridge = new Bridge({
tracker(fn) {
socket.on('vue-devtools:message', (data) => {
fn(data)
})
},
trigger(data) {
socket.emit('vue-devtools:message', data)
},
})

socket.on('connect', () => {
prepareInjection(bridge)
socket.emit('vue-devtools:init')
})

// Global disconnect handler. Fires in two cases:
// - after calling above socket.disconnect()
// - once devtools is closed (that's why we need socket.disconnect() here too, to prevent further polling)
socket.on('disconnect', () => {
socket.disconnect()
})

// Disconnect socket once other client is connected
socket.on('vue-devtools:disconnect-user-app', () => {
socket.disconnect()
})

if (isBrowser) {
window.addEventListener('beforeunload', () => {
socket.emit('vue-devtools:disconnect')
})
}
}
4 changes: 4 additions & 0 deletions packages/electron/src/user-app.iife.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import io from 'socket.io-client/dist/socket.io.js'
import { init } from './user-app.core'

init(io)
49 changes: 2 additions & 47 deletions packages/electron/src/user-app.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,4 @@
// import io from 'socket.io-client/dist/socket.io.js'
import io from 'socket.io-client'
import { isBrowser, target } from '@vue/devtools-shared'
import { Bridge } from '../../core/src/bridge'
import { prepareInjection } from '../../core/src/injection'
import { devtools } from '../../devtools-kit/src/index'
import { init } from './user-app.core'

const createSocket = io
const host = target.__VUE_DEVTOOLS_HOST__ || 'http://localhost'
const port = target.__VUE_DEVTOOLS_PORT__ !== undefined ? target.__VUE_DEVTOOLS_PORT__ : 8098
const fullHost = port ? `${host}:${port}` : host
const socket = createSocket(fullHost)

// @TODO: de-duplicate
devtools.init()

const bridge = new Bridge({
tracker(fn) {
socket.on('vue-devtools:message', (data) => {
fn(data)
})
},
trigger(data) {
socket.emit('vue-devtools:message', data)
},
})

socket.on('connect', () => {
prepareInjection(bridge)
socket.emit('vue-devtools:init')
})

// Global disconnect handler. Fires in two cases:
// - after calling above socket.disconnect()
// - once devtools is closed (that's why we need socket.disconnect() here too, to prevent further polling)
socket.on('disconnect', () => {
socket.disconnect()
})

// Disconnect socket once other client is connected
socket.on('vue-devtools:disconnect-user-app', () => {
socket.disconnect()
})

if (isBrowser) {
window.addEventListener('beforeunload', () => {
socket.emit('vue-devtools:disconnect')
})
}
init(io)
9 changes: 3 additions & 6 deletions packages/vue-termui-playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { devtools } from '@vue/devtools'
import '@vue/devtools/hook'
import { createApp } from 'vue-termui'
import App from './App.vue'

globalThis.document = {
createElement: () => {},
Expand All @@ -7,11 +10,5 @@ globalThis.document = {

devtools.connect('http://localhost', 8098)

// eslint-disable-next-line import/first
import { createApp } from 'vue-termui'

// eslint-disable-next-line import/first
import App from './App.vue'

const app = createApp(App)
app.mount()

0 comments on commit d93ce42

Please sign in to comment.