Skip to content

Commit

Permalink
fix(app-vite): bex -> portName consistency on unix & windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Nov 7, 2024
1 parent 9413120 commit ead885c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
5 changes: 2 additions & 3 deletions app-vite/lib/modes/bex/bex-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { getBuildSystemDefine } from '../../utils/env.js'

function generateDefaultEntry (quasarConf) {
return {
rawName: 'file',
name: 'file.js',
name: 'file', // or subdir/file (regardless of OS)
from: quasarConf.ctx.appPaths.resolve.bex('file.js'),
to: join(quasarConf.build.distDir, 'file.js')
}
Expand All @@ -34,7 +33,7 @@ export const quasarBexConfig = {
...cfg.define,
...getBuildSystemDefine({
buildEnv: {
__QUASAR_BEX_SCRIPT_NAME__: entry.rawName,
__QUASAR_BEX_SCRIPT_NAME__: entry.name,
__QUASAR_BEX_SERVER_PORT__: quasarConf.devServer.port || 0
}
})
Expand Down
3 changes: 1 addition & 2 deletions app-vite/lib/modes/bex/bex-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ function getScriptSetEntry (quasarConf, filePath) {
const scriptName = entry.substring(0, entry.length - extension.length - 1)

return {
rawName: scriptName,
name: scriptName,
name: scriptName.replaceAll('\\', '/'),
from: filePath,
to: join(quasarConf.build.distDir, `${ scriptName }.js`)
}
Expand Down
10 changes: 7 additions & 3 deletions app-vite/templates/bex/default/my-content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { createBridge } from '@quasar/app-vite/bex/content'

// The use of the bridge is optional.
const bridge = createBridge({ debug: false })
/**
* bridge.portName is 'content@<path>-<number>'
* where <path> is the relative path of this content script
* filename (without extension) from /src-bex
* (eg. 'my-content-script', 'subdir/my-script')
* and <number> is a unique instance number (1-10000).
*/

// Hook into the bridge to listen for events sent from the other BEX parts.
bridge.on('some.event', message => {
Expand Down Expand Up @@ -115,9 +122,6 @@ bridge.on('@quasar:ports', ({ portList, added, removed }) => {
}
})
// Current bridge port name (can be 'content@<name>-<xxxxx>')
console.log(bridge.portName)
// Dynamically set debug mode
bridge.setDebug(true) // boolean
Expand Down
7 changes: 7 additions & 0 deletions app-vite/templates/bex/ts/my-content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { createBridge } from '@quasar/app-vite/bex/content';

// The use of the bridge is optional.
const bridge = createBridge({ name: 'my-content-script', debug: false });
/**
* bridge.portName is 'content@<path>-<number>'
* where <path> is the relative path of this content script
* filename (without extension) from /src-bex
* (eg. 'my-content-script', 'subdir/my-script')
* and <number> is a unique instance number (1-10000).
*/

declare module '@quasar/app-vite' {
interface BexEventMap {
Expand Down
12 changes: 12 additions & 0 deletions docs/src/pages/quasar-cli-vite/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,13 @@ import { createBridge } from '@quasar/app-vite/bex/content'

// The use of the bridge is optional.
const bridge = createBridge({ name: 'my-content-script', debug: false })
/**
* bridge.portName is 'content@<path>-<number>'
* where <path> is the relative path of this content script
* filename (without extension) from /src-bex
* (eg. 'my-content-script', 'subdir/my-script')
* and <number> is a unique instance number (1-10000).
*/

// Attach initial bridge listeners...

Expand Down Expand Up @@ -885,6 +892,7 @@ import { useQuasar } from 'quasar'
const $q = useQuasar()

// Use $q.bex (the bridge)
// $q.bex.portName is "app"
</script>
<<| html Composition API + script |>>
<template>
Expand All @@ -898,6 +906,7 @@ export default {
setup () {
const $q = useQuasar()
// Use $q.bex (the bridge)
// $q.bex.portName is "app"
}
}
</script>
Expand All @@ -909,10 +918,13 @@ export default {
<script>
export default {
// Use this.$q.bex (the bridge)
// this.$q.bex.portName is "app"
}
</script>
```
Please note that the popup/page portName will be `app`.
#### The new BEX bridge
```js Bex Bridge messaging
Expand Down

0 comments on commit ead885c

Please sign in to comment.