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

Upgrade Vite for internal packages #1157

Open
wants to merge 3 commits 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
6 changes: 3 additions & 3 deletions internal/e2e-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
},
"dependencies": {
"@sw-internal/playground-js": "0.0.15",
"node-fetch": "^2.6.7",
"vite": "^5.4.10"
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@playwright/test": "^1.35.1",
"playwrigth-ws-inspector": "^1.0.0"
"playwrigth-ws-inspector": "^1.0.0",
"vite": "^6.0.7"
}
}
6 changes: 3 additions & 3 deletions internal/e2e-js/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { v4 as uuid } from 'uuid'
// #region Utilities for Playwright test server & fixture

type CreateTestServerOptions = {
target: 'heroku' | 'blank'
target: 'video' | 'blank'
}

const TARGET_ROOT_PATH: Record<
Expand All @@ -24,9 +24,9 @@ const TARGET_ROOT_PATH: Record<
}
> = {
blank: { path: './templates/blank', port: 1337 },
heroku: {
video: {
path: path.dirname(
require.resolve('@sw-internal/playground-js/src/heroku/index.html')
require.resolve('@sw-internal/playground-js/src/video/index.html')
),
port: 1336,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/e2e-realtime-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"devDependencies": {
"@playwright/test": "^1.35.1",
"@types/tap": "^15.0.8",
"esbuild-register": "^3.4.2"
"esbuild-register": "^3.4.2",
"vite": "^6.0.7"
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",
"tap": "^18.7.2",
"vite": "^5.4.10",
"ws": "^8.17.1"
}
}
35 changes: 34 additions & 1 deletion internal/playground-js/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
<h1>JS SDK Playground</h1>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/svg+xml"
href="https://signalwire.com/favicon.svg"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SignalWire Playground</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>

<body>
<div id="root">
<div class="flex flex-col max-w-4xl mx-auto mt-10">
<h1 class="text-3xl font-bold text-indigo-900 mb-3">Playgrounds</h1>
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div
class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8"
>
<div
class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg"
>
<!-- FOLDER_LIST_PLACEHOLDER -->
<div id="folder-list"></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
6 changes: 3 additions & 3 deletions internal/playground-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"serve": "vite preview",
"test": ""
},
"devDependencies": {
"vite": "^5.4.10"
},
"dependencies": {
"firebase": "^10.12.0",
"pako": "^2.1.0"
},
"devDependencies": {
"vite": "^6.0.7"
}
}
98 changes: 39 additions & 59 deletions internal/playground-js/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,53 @@
import { defineConfig } from 'vite'
import { defineConfig, ViteDevServer } from 'vite'
import path from 'node:path'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { IncomingMessage, ServerResponse } from 'node:http'

const getHtmlList = (list: any) => {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="https://signalwire.com/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SignalWire Playground</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
// ESM-friendly approach as compared to the Node's __dirname
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

function createFolderList() {
const pwd = path.join(__dirname, 'src')
const folders = fs.readdirSync(pwd, { withFileTypes: true })

// Filter directories only
const folderNames: string[] = folders
.map((file) => (file.isDirectory() ? file.name + '/' : ''))
.filter((name) => !!name)

<body>
<div id="root">
<div class="flex flex-col max-w-4xl mx-auto mt-10">
<h1 class="text-3xl font-bold text-indigo-900 mb-3">Playgrounds</h1>
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<ul>
${list
.map(
(vv: any) =>
`<li><a href="src/${vv}" class="block mx-3 my-4 font-bold text-indigo-600">☞ ${vv}</a></li>`
)
.join('')}
</ul>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
`
// Build an <ul> with links
return `
<ul>
${folderNames
.map(
(name) =>
`<li><a href="src/${name}" class="block mx-3 my-4 font-bold text-indigo-600">☞ ${name}</a></li>`
)
.join('')}
</ul>`
}

/**
* Plugin for automatically listing the folders as HTML
* items.
* Custom plugin that lists subfolders of /src at the root URL.
*/
function listPlugin() {
return {
name: 'sw-list-folders',
configureServer(server: any) {
server.middlewares.use((req: any, res: any, next: any) => {
const { url } = req
// Inject the list into the HTML template
transformIndexHtml(html: string) {
const folderListMarkup = createFolderList()

const target = '<div id="folder-list"></div>'
if (html.includes(target)) {
return html.replace(
target,
`<div id="folder-list">${folderListMarkup}</div>`
)
}

if (url === '/') {
const pwd = path.join(__dirname, 'src')
const folders = fs.readdirSync(pwd, {
withFileTypes: true,
})
const list2 = folders
.map((file) => {
if (file.isDirectory()) {
return file.name + '/'
}
return false
})
.filter((l) => l)
res.end(getHtmlList(list2))
} else {
next()
}
})
return html
},
}
}
Expand All @@ -80,7 +60,7 @@ export default defineConfig({
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
heroku: path.resolve(__dirname, 'src/heroku/index.html'),
video: path.resolve(__dirname, 'src/video/index.html'),
chat: path.resolve(__dirname, 'src/chat/index.html'),
fabric: path.resolve(__dirname, 'src/fabric/index.html'),
pubSub: path.resolve(__dirname, 'src/pubSub/index.html'),
Expand Down
Loading
Loading