@platformatic/basic 2.0.0-alpha.3 → 2.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/config.d.ts +159 -0
  2. package/eslint.config.js +3 -1
  3. package/index.js +15 -2
  4. package/lib/base.js +7 -5
  5. package/lib/errors.js +8 -0
  6. package/lib/next.js +105 -0
  7. package/lib/schema.js +23 -0
  8. package/lib/server.js +8 -9
  9. package/lib/utils.js +5 -34
  10. package/lib/vite.js +105 -0
  11. package/lib/worker/child-manager.js +78 -0
  12. package/lib/worker/child-process.js +84 -0
  13. package/lib/worker/next-loader.js +137 -0
  14. package/lib/worker/server-listener.js +29 -0
  15. package/package.json +22 -8
  16. package/schema.json +522 -0
  17. package/test/express.test.js +9 -9
  18. package/test/fastify.test.js +9 -9
  19. package/test/fixtures/next/composer-autodetect-prefix/next.config.mjs +5 -0
  20. package/test/fixtures/next/composer-autodetect-prefix/package.json +15 -0
  21. package/test/fixtures/next/composer-autodetect-prefix/platformatic.application.json +8 -0
  22. package/test/fixtures/next/composer-autodetect-prefix/platformatic.runtime.json +21 -0
  23. package/test/fixtures/next/composer-autodetect-prefix/src/app/layout.js +7 -0
  24. package/test/fixtures/next/composer-autodetect-prefix/src/app/page.js +5 -0
  25. package/test/fixtures/next/composer-with-prefix/next.config.js +1 -0
  26. package/test/fixtures/next/composer-with-prefix/package.json +15 -0
  27. package/test/fixtures/next/composer-with-prefix/platformatic.application.json +11 -0
  28. package/test/fixtures/next/composer-with-prefix/platformatic.runtime.json +21 -0
  29. package/test/fixtures/next/composer-with-prefix/src/app/layout.js +7 -0
  30. package/test/fixtures/next/composer-with-prefix/src/app/page.js +5 -0
  31. package/test/fixtures/next/composer-without-prefix/next.config.mjs +3 -0
  32. package/test/fixtures/next/composer-without-prefix/package.json +15 -0
  33. package/test/fixtures/next/composer-without-prefix/platformatic.application.json +8 -0
  34. package/test/fixtures/next/composer-without-prefix/platformatic.runtime.json +21 -0
  35. package/test/fixtures/next/composer-without-prefix/src/app/layout.js +7 -0
  36. package/test/fixtures/next/composer-without-prefix/src/app/page.js +5 -0
  37. package/test/fixtures/next/standalone/next.config.mjs +3 -0
  38. package/test/fixtures/next/standalone/package.json +15 -0
  39. package/test/fixtures/next/standalone/platformatic.runtime.json +18 -0
  40. package/test/fixtures/next/standalone/src/app/layout.js +7 -0
  41. package/test/fixtures/next/standalone/src/app/page.js +5 -0
  42. package/test/fixtures/platformatic-composer/platformatic.composer.json +20 -0
  43. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +23 -0
  44. package/test/fixtures/platformatic-composer/plugin.js +9 -0
  45. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +3 -0
  46. package/test/fixtures/vite/composer-autodetect-prefix/index.html +13 -0
  47. package/test/fixtures/vite/composer-autodetect-prefix/main.js +3 -0
  48. package/test/fixtures/vite/composer-autodetect-prefix/package.json +14 -0
  49. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +11 -0
  50. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +21 -0
  51. package/test/fixtures/vite/composer-with-prefix/index.html +13 -0
  52. package/test/fixtures/vite/composer-with-prefix/main.js +3 -0
  53. package/test/fixtures/vite/composer-with-prefix/package.json +14 -0
  54. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +11 -0
  55. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +21 -0
  56. package/test/fixtures/vite/composer-without-prefix/index.html +13 -0
  57. package/test/fixtures/vite/composer-without-prefix/main.js +3 -0
  58. package/test/fixtures/vite/composer-without-prefix/package.json +14 -0
  59. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +8 -0
  60. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +21 -0
  61. package/test/fixtures/vite/standalone/custom.vite.config.js +3 -0
  62. package/test/fixtures/vite/standalone/index.html +13 -0
  63. package/test/fixtures/vite/standalone/main.js +3 -0
  64. package/test/fixtures/vite/standalone/package.json +14 -0
  65. package/test/fixtures/vite/standalone/platformatic.runtime.json +18 -0
  66. package/test/helper.js +85 -14
  67. package/test/next.test.js +85 -0
  68. package/test/node.test.js +13 -13
  69. package/test/vite.test.js +89 -0
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "next",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.0.0",
12
+ "react-dom": "^18.0.0",
13
+ "next": "^14.2.5"
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "application": {
9
+ "base": "/frontend"
10
+ }
11
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "frontend",
15
+ "path": ".",
16
+ "config": "platformatic.application.json"
17
+ },
18
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
+ { "id": "main", "config": "platformatic.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,7 @@
1
+ export default function RootLayout ({ children }) {
2
+ return (
3
+ <html lang='en'>
4
+ <body>{children}</body>
5
+ </html>
6
+ )
7
+ }
@@ -0,0 +1,5 @@
1
+ import { version } from '../../../../../tmp/version.js'
2
+
3
+ export default function Home () {
4
+ return <div>Hello from {version}</div>
5
+ }
@@ -0,0 +1,3 @@
1
+ export default function () {
2
+ return {}
3
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "next",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.0.0",
12
+ "react-dom": "^18.0.0",
13
+ "next": "^14.2.5"
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "frontend",
15
+ "path": ".",
16
+ "config": "platformatic.application.json"
17
+ },
18
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
+ { "id": "main", "config": "platformatic.no-prefix.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,7 @@
1
+ export default function RootLayout ({ children }) {
2
+ return (
3
+ <html lang='en'>
4
+ <body>{children}</body>
5
+ </html>
6
+ )
7
+ }
@@ -0,0 +1,5 @@
1
+ import { version } from '../../../../../tmp/version.js'
2
+
3
+ export default function Home () {
4
+ return <div>Hello from {version}</div>
5
+ }
@@ -0,0 +1,3 @@
1
+ const nextConfig = {}
2
+
3
+ export default nextConfig
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "next",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.0.0",
12
+ "react-dom": "^18.0.0",
13
+ "next": "^14.2.5"
14
+ }
15
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": "."
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,7 @@
1
+ export default function RootLayout ({ children }) {
2
+ return (
3
+ <html lang='en'>
4
+ <body>{children}</body>
5
+ </html>
6
+ )
7
+ }
@@ -0,0 +1,5 @@
1
+ import { version } from '../../../../../tmp/version.js'
2
+
3
+ export default function Home () {
4
+ return <div>Hello from {version}</div>
5
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/composer/1.52.0.json",
3
+ "composer": {
4
+ "services": [
5
+ {
6
+ "id": "frontend"
7
+ },
8
+ {
9
+ "id": "service"
10
+ }
11
+ ]
12
+ },
13
+ "plugins": {
14
+ "paths": [
15
+ {
16
+ "path": "./plugin.js"
17
+ }
18
+ ]
19
+ }
20
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/composer/1.52.0.json",
3
+ "composer": {
4
+ "services": [
5
+ {
6
+ "id": "frontend",
7
+ "proxy": {
8
+ "prefix": ""
9
+ }
10
+ },
11
+ {
12
+ "id": "service"
13
+ }
14
+ ]
15
+ },
16
+ "plugins": {
17
+ "paths": [
18
+ {
19
+ "path": "./plugin.js"
20
+ }
21
+ ]
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ export default async function (app) {
2
+ app.get('/plugin', async () => {
3
+ return { ok: true }
4
+ })
5
+
6
+ app.get('/frontend/plugin', async () => {
7
+ return { ok: true }
8
+ })
9
+ }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ base: '/nested/base/dir',
3
+ }
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "vite",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "vite": {
9
+ "configFile": "custom.vite.config.js"
10
+ }
11
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "frontend",
15
+ "path": ".",
16
+ "config": "platformatic.application.json"
17
+ },
18
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
+ { "id": "main", "config": "platformatic.no-prefix.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "vite",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "application": {
9
+ "base": "/frontend"
10
+ }
11
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "frontend",
15
+ "path": ".",
16
+ "config": "platformatic.application.json"
17
+ },
18
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
+ { "id": "main", "config": "platformatic.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "vite",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "frontend",
15
+ "path": ".",
16
+ "config": "platformatic.application.json"
17
+ },
18
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
+ { "id": "main", "config": "platformatic.no-prefix.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ base: '/nested/base/dir',
3
+ }
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "vite",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": "."
16
+ }
17
+ ]
18
+ }
package/test/helper.js CHANGED
@@ -1,10 +1,16 @@
1
- import { deepStrictEqual, strictEqual } from 'node:assert'
2
- import { resolve } from 'node:path'
1
+ import { createDirectory, withResolvers } from '@platformatic/utils'
2
+ import { deepStrictEqual, ok, strictEqual } from 'node:assert'
3
+ import { writeFile } from 'node:fs/promises'
4
+ import { dirname, resolve } from 'node:path'
3
5
  import { setTimeout as sleep } from 'node:timers/promises'
4
6
  import { Client, request } from 'undici'
7
+ import WebSocket from 'ws'
5
8
  import { loadConfig } from '../../config/index.js'
6
9
  import { buildServer, platformaticRuntime } from '../../runtime/index.js'
7
10
 
11
+ export { setTimeout as sleep } from 'node:timers/promises'
12
+
13
+ let hrmVersion = Date.now()
8
14
  export const fixturesDir = resolve(import.meta.dirname, './fixtures')
9
15
 
10
16
  export async function createRuntime (t, path) {
@@ -20,18 +26,6 @@ export async function createRuntime (t, path) {
20
26
  return { runtime, url }
21
27
  }
22
28
 
23
- export async function verifyViaHTTP (baseUrl, path, expectedCode, expectedContent) {
24
- const { statusCode, body } = await request(baseUrl + path)
25
- strictEqual(statusCode, expectedCode)
26
- deepStrictEqual(await body.json(), expectedContent)
27
- }
28
-
29
- export async function verifyViaInject (app, serviceId, method, url, expectedCode, expectedContent) {
30
- const { statusCode, body } = await app.inject(serviceId, { method, url })
31
- strictEqual(statusCode, expectedCode)
32
- deepStrictEqual(JSON.parse(body), expectedContent)
33
- }
34
-
35
29
  export async function getLogs (app) {
36
30
  const client = new Client(
37
31
  {
@@ -63,3 +57,80 @@ export async function getLogs (app) {
63
57
  .filter(l => l)
64
58
  .map(m => JSON.parse(m))
65
59
  }
60
+
61
+ export async function updateHMRVersion () {
62
+ const versionFile = resolve(fixturesDir, '../tmp/version.js')
63
+ await createDirectory(dirname(versionFile))
64
+ await writeFile(versionFile, `export const version = ${hrmVersion++}\n`, 'utf-8')
65
+ }
66
+
67
+ export async function verifyJSONViaHTTP (baseUrl, path, expectedCode, expectedContent) {
68
+ const { statusCode, body } = await request(baseUrl + path)
69
+ strictEqual(statusCode, expectedCode)
70
+ deepStrictEqual(await body.json(), expectedContent)
71
+ }
72
+
73
+ export async function verifyJSONViaInject (app, serviceId, method, url, expectedCode, expectedContent) {
74
+ const { statusCode, body } = await app.inject(serviceId, { method, url })
75
+ strictEqual(statusCode, expectedCode)
76
+ deepStrictEqual(JSON.parse(body), expectedContent)
77
+ }
78
+
79
+ export async function verifyHTMLViaHTTP (baseUrl, path, contents) {
80
+ const { statusCode, headers, body } = await request(baseUrl + path, { maxRedirections: 1 })
81
+ const html = await body.text()
82
+
83
+ deepStrictEqual(statusCode, 200)
84
+ ok(headers['content-type'].startsWith('text/html'))
85
+
86
+ for (const content of contents) {
87
+ ok(html.includes(content))
88
+ }
89
+ }
90
+
91
+ export async function verifyHTMLViaInject (app, serviceId, url, contents) {
92
+ const { statusCode, headers, body: html } = await app.inject(serviceId, { method: 'GET', url })
93
+
94
+ deepStrictEqual(statusCode, 200)
95
+ ok(headers['content-type'].startsWith('text/html'))
96
+
97
+ for (const content of contents) {
98
+ ok(html.includes(content))
99
+ }
100
+ }
101
+
102
+ export async function verifyHMR (baseUrl, path, versionFile, protocol, handler) {
103
+ const connection = withResolvers()
104
+ const reload = withResolvers()
105
+ const ac = new AbortController()
106
+ const timeout = sleep(10000, 'timeout', { signal: ac.signal })
107
+
108
+ const url = baseUrl.replace('http:', 'ws:') + path
109
+ const webSocket = new WebSocket(url, protocol)
110
+
111
+ webSocket.on('error', err => {
112
+ clearTimeout(timeout)
113
+ connection.reject(err)
114
+ reload.reject(err)
115
+ })
116
+
117
+ webSocket.on('message', data => {
118
+ handler(JSON.parse(data), connection.resolve, reload.resolve)
119
+ })
120
+
121
+ try {
122
+ if ((await Promise.race([connection.promise, timeout])) === 'timeout') {
123
+ throw new Error('Timeout while waiting for HMR connection')
124
+ }
125
+
126
+ await sleep(1000)
127
+ await updateHMRVersion()
128
+
129
+ if ((await Promise.race([reload.promise, timeout])) === 'timeout') {
130
+ throw new Error('Timeout while waiting for HMR reload')
131
+ }
132
+ } finally {
133
+ webSocket.terminate()
134
+ ac.abort()
135
+ }
136
+ }