@platformatic/watt-extra 1.19.0 → 1.19.1-alpha.2
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.
- package/lib/watt.js +25 -2
- package/package.json +10 -9
- package/pnpm-workspace.yaml +5 -0
- package/test/fixtures/runtime-health/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-health-custom/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health-custom/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-health-disabled/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health-disabled/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-next-components/package.json +5 -0
- package/test/fixtures/runtime-next-components/platformatic.json +9 -0
- package/test/fixtures/runtime-next-components/web/next/next.config.js +2 -0
- package/test/fixtures/runtime-next-components/web/next/package.json +7 -0
- package/test/fixtures/runtime-next-components/web/next/platformatic.json +8 -0
- package/test/fixtures/runtime-next-components/web/next/src/app/layout.jsx +7 -0
- package/test/fixtures/runtime-next-components/web/next/src/app/page.jsx +17 -0
- package/test/fixtures/runtime-next-components/web/next/src/lib/message.js +4 -0
- package/test/fixtures/runtime-scheduler/main/package.json +1 -1
- package/test/fixtures/runtime-service/main/package.json +1 -1
- package/test/next-cache.test.js +49 -7
package/lib/watt.js
CHANGED
|
@@ -3,6 +3,7 @@ import dns from 'node:dns/promises'
|
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
4
|
import { join, resolve } from 'node:path'
|
|
5
5
|
import { createRequire } from 'node:module'
|
|
6
|
+
import { pathToFileURL } from 'node:url'
|
|
6
7
|
import semver from 'semver'
|
|
7
8
|
|
|
8
9
|
const require = createRequire(import.meta.url)
|
|
@@ -606,10 +607,11 @@ class Watt {
|
|
|
606
607
|
}
|
|
607
608
|
|
|
608
609
|
async #configureNextService (runtime, service) {
|
|
610
|
+
let nextPackage
|
|
609
611
|
let nextSchema
|
|
610
612
|
|
|
611
613
|
try {
|
|
612
|
-
|
|
614
|
+
nextPackage = createRequire(
|
|
613
615
|
resolve(service.path, 'index.js')
|
|
614
616
|
).resolve('@platformatic/next')
|
|
615
617
|
nextSchema = JSON.parse(
|
|
@@ -634,8 +636,12 @@ class Watt {
|
|
|
634
636
|
'Missing required environment variables for Redis cache, not setting up HTTP next cache'
|
|
635
637
|
)
|
|
636
638
|
} else {
|
|
639
|
+
// Merging only sets the connection, keeping the cache options of the application.
|
|
640
|
+
// Older versions don't support the operation, so the cache options are replaced.
|
|
641
|
+
const op = await this.#supportsMergePatches(nextPackage) ? 'merge' : 'add'
|
|
642
|
+
|
|
637
643
|
patches.push({
|
|
638
|
-
op
|
|
644
|
+
op,
|
|
639
645
|
path: '/cache',
|
|
640
646
|
value: {
|
|
641
647
|
adapter: 'valkey',
|
|
@@ -662,6 +668,23 @@ class Watt {
|
|
|
662
668
|
}
|
|
663
669
|
}
|
|
664
670
|
|
|
671
|
+
// The patches are applied by the @platformatic/foundation used by the application
|
|
672
|
+
async #supportsMergePatches (nextPackage) {
|
|
673
|
+
try {
|
|
674
|
+
const basicPackage = createRequire(nextPackage).resolve('@platformatic/basic')
|
|
675
|
+
const foundationPackage = createRequire(basicPackage).resolve('@platformatic/foundation')
|
|
676
|
+
const { applyConfigPatch } = await import(pathToFileURL(foundationPackage))
|
|
677
|
+
|
|
678
|
+
return typeof applyConfigPatch === 'function'
|
|
679
|
+
} catch (e) {
|
|
680
|
+
this.#logger.warn(
|
|
681
|
+
{ err: ensureLoggableError(e) },
|
|
682
|
+
'Failed to detect the support of merge patches, replacing the Next.js cache options'
|
|
683
|
+
)
|
|
684
|
+
return false
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
665
688
|
async #configurePlatformaticServices (runtime, app) {
|
|
666
689
|
if (app.entrypoint) {
|
|
667
690
|
const config = app
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/watt-extra",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1-alpha.2",
|
|
4
4
|
"description": "The Platformatic runtime manager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -19,27 +19,28 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@fastify/websocket": "^11.1.0",
|
|
22
|
-
"@platformatic/composer": "^3.
|
|
23
|
-
"@platformatic/next": "^3.
|
|
24
|
-
"@platformatic/node": "^3.
|
|
25
|
-
"@platformatic/service": "^3.
|
|
22
|
+
"@platformatic/composer": "^3.73.0-alpha.0",
|
|
23
|
+
"@platformatic/next": "^3.73.0-alpha.0",
|
|
24
|
+
"@platformatic/node": "^3.73.0-alpha.0",
|
|
25
|
+
"@platformatic/service": "^3.73.0-alpha.0",
|
|
26
26
|
"atomic-sleep": "^1.0.0",
|
|
27
27
|
"borp": "^1.0.0",
|
|
28
28
|
"eslint": "10",
|
|
29
29
|
"fastify": "^5.10.0",
|
|
30
30
|
"fastify-plugin": "^6.0.0",
|
|
31
|
+
"iovalkey": "^0.4.0",
|
|
31
32
|
"neostandard": "0.14.0-next.1",
|
|
32
33
|
"next": "^16.2.10",
|
|
33
|
-
"platformatic": "^3.
|
|
34
|
+
"platformatic": "^3.73.0-alpha.0",
|
|
34
35
|
"pprof-format": "^2.1.0",
|
|
35
36
|
"why-is-node-running": "^2.3.0"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@datadog/pprof": "^5.9.0",
|
|
39
40
|
"@fastify/error": "^4.2.0",
|
|
40
|
-
"@platformatic/foundation": "^3.
|
|
41
|
-
"@platformatic/runtime": "^3.
|
|
42
|
-
"@platformatic/wattpm-pprof-capture": "^3.
|
|
41
|
+
"@platformatic/foundation": "^3.73.0-alpha.0",
|
|
42
|
+
"@platformatic/runtime": "^3.73.0-alpha.0",
|
|
43
|
+
"@platformatic/wattpm-pprof-capture": "^3.73.0-alpha.0",
|
|
43
44
|
"avvio": "^9.1.0",
|
|
44
45
|
"commist": "^3.2.0",
|
|
45
46
|
"env-schema": "^8.0.0",
|
package/pnpm-workspace.yaml
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { connection } from 'next/server'
|
|
2
|
+
import { Suspense } from 'react'
|
|
3
|
+
import { getMessage } from '../lib/message.js'
|
|
4
|
+
|
|
5
|
+
export default function Home () {
|
|
6
|
+
return (
|
|
7
|
+
<Suspense fallback={null}>
|
|
8
|
+
<Message />
|
|
9
|
+
</Suspense>
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Waiting for a request avoids calling the cached function during the build
|
|
14
|
+
async function Message () {
|
|
15
|
+
await connection()
|
|
16
|
+
return <div>{await getMessage('watt-extra')}</div>
|
|
17
|
+
}
|
package/test/next-cache.test.js
CHANGED
|
@@ -4,7 +4,10 @@ import { randomUUID } from 'node:crypto'
|
|
|
4
4
|
import { existsSync } from 'node:fs'
|
|
5
5
|
import { dirname, join } from 'node:path'
|
|
6
6
|
import { test } from 'node:test'
|
|
7
|
+
import { setTimeout as sleep } from 'node:timers/promises'
|
|
7
8
|
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import Valkey from 'iovalkey'
|
|
10
|
+
import { request } from 'undici'
|
|
8
11
|
|
|
9
12
|
import { start } from '../index.js'
|
|
10
13
|
import { setUpEnvironment, startICC } from './helper.js'
|
|
@@ -13,14 +16,11 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
|
13
16
|
|
|
14
17
|
// Matches the host port exposed by docker-compose.yml and the CI service
|
|
15
18
|
const valkeyPort = 6390
|
|
19
|
+
const appPort = 3043
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
// runtimes said 'next'). The Next patches, cache adapter included, must be
|
|
19
|
-
// applied in both cases.
|
|
20
|
-
test('should configure the Next.js cache adapter for @platformatic/next applications', async (t) => {
|
|
21
|
+
async function startNextApp (t, fixture, applicationId) {
|
|
21
22
|
const applicationName = 'test-next'
|
|
22
|
-
const
|
|
23
|
-
const applicationPath = join(__dirname, 'fixtures', 'runtime-next')
|
|
23
|
+
const applicationPath = join(__dirname, 'fixtures', fixture)
|
|
24
24
|
|
|
25
25
|
// The application starts in production mode, so the fixture needs a build;
|
|
26
26
|
// reuse an existing one to keep local reruns fast.
|
|
@@ -57,7 +57,7 @@ test('should configure the Next.js cache adapter for @platformatic/next applicat
|
|
|
57
57
|
PLT_APP_NAME: applicationName,
|
|
58
58
|
PLT_APP_DIR: applicationPath,
|
|
59
59
|
PLT_ICC_URL: icc.iccUrl,
|
|
60
|
-
PLT_APP_PORT:
|
|
60
|
+
PLT_APP_PORT: appPort,
|
|
61
61
|
PLT_METRICS_PORT: 9092
|
|
62
62
|
})
|
|
63
63
|
|
|
@@ -68,6 +68,16 @@ test('should configure the Next.js cache adapter for @platformatic/next applicat
|
|
|
68
68
|
await icc.close()
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
+
return app
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The runtime reports a Next.js application as '@platformatic/next' (older
|
|
75
|
+
// runtimes said 'next'). The Next patches, cache adapter included, must be
|
|
76
|
+
// applied in both cases.
|
|
77
|
+
test('should configure the Next.js cache adapter for @platformatic/next applications', async (t) => {
|
|
78
|
+
const applicationId = randomUUID()
|
|
79
|
+
const app = await startNextApp(t, 'runtime-next', applicationId)
|
|
80
|
+
|
|
71
81
|
const runtimeConfig = app.watt.runtime.getRuntimeConfig(true)
|
|
72
82
|
const nextApplication = runtimeConfig.applications.find((application) => application.id === 'next')
|
|
73
83
|
assert.strictEqual(nextApplication.type, '@platformatic/next')
|
|
@@ -80,3 +90,35 @@ test('should configure the Next.js cache adapter for @platformatic/next applicat
|
|
|
80
90
|
maxTTL: 604800
|
|
81
91
|
})
|
|
82
92
|
})
|
|
93
|
+
|
|
94
|
+
// The fixture enables the Cache Components in its own cache options, which must
|
|
95
|
+
// survive the patch that sets the Valkey connection
|
|
96
|
+
test('should keep the cache options of @platformatic/next applications', async (t) => {
|
|
97
|
+
const applicationId = randomUUID()
|
|
98
|
+
const app = await startNextApp(t, 'runtime-next-components', applicationId)
|
|
99
|
+
|
|
100
|
+
const nextConfig = await app.watt.runtime.getApplicationConfig('next')
|
|
101
|
+
assert.deepStrictEqual(nextConfig.cache, {
|
|
102
|
+
adapter: 'valkey',
|
|
103
|
+
url: `valkey://cache-user:cache-pass@127.0.0.1:${valkeyPort}`,
|
|
104
|
+
prefix: `${applicationId}:`,
|
|
105
|
+
maxTTL: 604800,
|
|
106
|
+
cacheComponents: true
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const { statusCode, body } = await request(`http://127.0.0.1:${appPort}/`)
|
|
110
|
+
assert.strictEqual(statusCode, 200)
|
|
111
|
+
assert.match(await body.text(), /Hello watt-extra/)
|
|
112
|
+
|
|
113
|
+
// The "use cache" entry is stored in Valkey, under the prefix set by watt-extra
|
|
114
|
+
const valkey = new Valkey(`valkey://cache-user:cache-pass@127.0.0.1:${valkeyPort}`)
|
|
115
|
+
t.after(() => valkey.quit())
|
|
116
|
+
|
|
117
|
+
let keys = []
|
|
118
|
+
for (const deadline = Date.now() + 5000; !keys.length && Date.now() < deadline;) {
|
|
119
|
+
await sleep(100)
|
|
120
|
+
keys = await valkey.keys(`${applicationId}::cache:next:*:components:values:*`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
assert.strictEqual(keys.length, 1)
|
|
124
|
+
})
|