@platformatic/next 3.32.0-alpha.0 → 3.32.0-alpha.1
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/config.d.ts +38 -4
- package/lib/capability.js +34 -9
- package/package.json +5 -5
- package/schema.json +87 -40
package/config.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export interface PlatformaticNextJsConfig {
|
|
9
9
|
$schema?: string;
|
|
10
10
|
logger?: {
|
|
11
|
-
level
|
|
11
|
+
level?: (
|
|
12
12
|
| ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
|
|
13
13
|
| {
|
|
14
14
|
[k: string]: unknown;
|
|
@@ -139,7 +139,7 @@ export interface PlatformaticNextJsConfig {
|
|
|
139
139
|
};
|
|
140
140
|
workersRestartDelay?: number | string;
|
|
141
141
|
logger?: {
|
|
142
|
-
level
|
|
142
|
+
level?: (
|
|
143
143
|
| ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
|
|
144
144
|
| {
|
|
145
145
|
[k: string]: unknown;
|
|
@@ -242,7 +242,6 @@ export interface PlatformaticNextJsConfig {
|
|
|
242
242
|
maxHeapTotal?: number | string;
|
|
243
243
|
maxYoungGeneration?: number | string;
|
|
244
244
|
codeRangeSize?: number | string;
|
|
245
|
-
noHeapCheck?: boolean | string;
|
|
246
245
|
};
|
|
247
246
|
undici?: {
|
|
248
247
|
agentOptions?: {
|
|
@@ -294,6 +293,18 @@ export interface PlatformaticNextJsConfig {
|
|
|
294
293
|
maxSize?: number;
|
|
295
294
|
maxEntrySize?: number;
|
|
296
295
|
maxCount?: number;
|
|
296
|
+
/**
|
|
297
|
+
* Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., "/https:\\/\\/.*\\.example\\.com/").
|
|
298
|
+
*/
|
|
299
|
+
origins?: string[];
|
|
300
|
+
/**
|
|
301
|
+
* Default cache duration in seconds for responses without explicit expiration headers.
|
|
302
|
+
*/
|
|
303
|
+
cacheByDefault?: number;
|
|
304
|
+
/**
|
|
305
|
+
* Cache type. "shared" caches may be shared between users, "private" caches are user-specific.
|
|
306
|
+
*/
|
|
307
|
+
type?: "shared" | "private";
|
|
297
308
|
[k: string]: unknown;
|
|
298
309
|
};
|
|
299
310
|
watch?: boolean | string;
|
|
@@ -523,6 +534,18 @@ export interface PlatformaticNextJsConfig {
|
|
|
523
534
|
[k: string]: string | [string, ...string[]];
|
|
524
535
|
};
|
|
525
536
|
};
|
|
537
|
+
compileCache?:
|
|
538
|
+
| boolean
|
|
539
|
+
| {
|
|
540
|
+
/**
|
|
541
|
+
* Enable Node.js module compile cache for faster startup
|
|
542
|
+
*/
|
|
543
|
+
enabled?: boolean;
|
|
544
|
+
/**
|
|
545
|
+
* Directory to store compile cache. Defaults to .plt/compile-cache in app root
|
|
546
|
+
*/
|
|
547
|
+
directory?: string;
|
|
548
|
+
};
|
|
526
549
|
application?: {
|
|
527
550
|
reuseTcpPorts?: boolean;
|
|
528
551
|
workers?:
|
|
@@ -546,7 +569,6 @@ export interface PlatformaticNextJsConfig {
|
|
|
546
569
|
maxHeapTotal?: number | string;
|
|
547
570
|
maxYoungGeneration?: number | string;
|
|
548
571
|
codeRangeSize?: number | string;
|
|
549
|
-
noHeapCheck?: boolean | string;
|
|
550
572
|
};
|
|
551
573
|
arguments?: string[];
|
|
552
574
|
env?: {
|
|
@@ -582,6 +604,18 @@ export interface PlatformaticNextJsConfig {
|
|
|
582
604
|
)[];
|
|
583
605
|
[k: string]: unknown;
|
|
584
606
|
};
|
|
607
|
+
compileCache?:
|
|
608
|
+
| boolean
|
|
609
|
+
| {
|
|
610
|
+
/**
|
|
611
|
+
* Enable Node.js module compile cache for faster startup
|
|
612
|
+
*/
|
|
613
|
+
enabled?: boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Directory to store compile cache. Defaults to .plt/compile-cache in app root
|
|
616
|
+
*/
|
|
617
|
+
directory?: string;
|
|
618
|
+
};
|
|
585
619
|
};
|
|
586
620
|
};
|
|
587
621
|
next?: {
|
package/lib/capability.js
CHANGED
|
@@ -13,6 +13,7 @@ import { ChildProcess } from 'node:child_process'
|
|
|
13
13
|
import { once } from 'node:events'
|
|
14
14
|
import { existsSync } from 'node:fs'
|
|
15
15
|
import { glob, readFile, writeFile } from 'node:fs/promises'
|
|
16
|
+
import { createRequire } from 'node:module'
|
|
16
17
|
import { dirname, resolve as resolvePath, sep } from 'node:path'
|
|
17
18
|
import { fileURLToPath } from 'node:url'
|
|
18
19
|
import { parse, satisfies } from 'semver'
|
|
@@ -32,6 +33,7 @@ export class NextCapability extends BaseCapability {
|
|
|
32
33
|
#child
|
|
33
34
|
#server
|
|
34
35
|
#configModified
|
|
36
|
+
#isStandalone
|
|
35
37
|
|
|
36
38
|
constructor (root, config, context) {
|
|
37
39
|
super('next', version, root, config, context)
|
|
@@ -42,6 +44,20 @@ export class NextCapability extends BaseCapability {
|
|
|
42
44
|
async init () {
|
|
43
45
|
await super.init()
|
|
44
46
|
|
|
47
|
+
if (this.isProduction) {
|
|
48
|
+
try {
|
|
49
|
+
const buildInfo = JSON.parse(await readFile(resolvePath(this.root, '.platformatic-build.json'), 'utf-8'))
|
|
50
|
+
|
|
51
|
+
if (buildInfo.standalone) {
|
|
52
|
+
this.#isStandalone = true
|
|
53
|
+
this.#nextVersion = parse(buildInfo.version)
|
|
54
|
+
}
|
|
55
|
+
return
|
|
56
|
+
} catch (error) {
|
|
57
|
+
// No-op
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
45
61
|
// This is needed to avoid Next.js to throw an error when the lockfile is not correct
|
|
46
62
|
// and the user is using npm but has pnpm in its $PATH.
|
|
47
63
|
//
|
|
@@ -253,11 +269,10 @@ export class NextCapability extends BaseCapability {
|
|
|
253
269
|
this.#getChildManagerScripts()
|
|
254
270
|
)
|
|
255
271
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (existsSync(resolvePath(this.root, '.next/standalone'))) {
|
|
272
|
+
if (this.#isStandalone) {
|
|
259
273
|
return this.#startProductionStandaloneNext()
|
|
260
274
|
} else {
|
|
275
|
+
this.verifyOutputDirectory(resolvePath(this.root, '.next'))
|
|
261
276
|
return this.#startProductionNext()
|
|
262
277
|
}
|
|
263
278
|
}
|
|
@@ -300,19 +315,17 @@ export class NextCapability extends BaseCapability {
|
|
|
300
315
|
}
|
|
301
316
|
|
|
302
317
|
async #startProductionStandaloneNext () {
|
|
303
|
-
const rootDir = resolvePath(this.root, '.next', 'standalone')
|
|
304
|
-
|
|
305
318
|
// If built in standalone mode, the generated standalone directory is not on the root of the project but somewhere
|
|
306
319
|
// inside .next/standalone due to turbopack limitations in determining the root of the project.
|
|
307
320
|
// In that case we search a server.js next to a .next folder inside the .next /standalone folder.
|
|
308
321
|
const serverEntrypoints = await Array.fromAsync(
|
|
309
|
-
glob(['**/server.js'], { cwd:
|
|
322
|
+
glob(['**/server.js'], { cwd: this.root, ignore: ['node_modules', '**/node_modules/**'] })
|
|
310
323
|
)
|
|
311
324
|
|
|
312
325
|
let serverEntrypoint
|
|
313
326
|
for (const entrypoint of serverEntrypoints) {
|
|
314
|
-
if (existsSync(resolvePath(
|
|
315
|
-
serverEntrypoint = resolvePath(
|
|
327
|
+
if (existsSync(resolvePath(this.root, dirname(entrypoint), '.next'))) {
|
|
328
|
+
serverEntrypoint = resolvePath(this.root, entrypoint)
|
|
316
329
|
break
|
|
317
330
|
}
|
|
318
331
|
}
|
|
@@ -370,7 +383,9 @@ export class NextCapability extends BaseCapability {
|
|
|
370
383
|
|
|
371
384
|
// This is needed by Next.js standalone server to pick up the correct configuration
|
|
372
385
|
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig)
|
|
373
|
-
const
|
|
386
|
+
const require = createRequire(serverEntrypoint)
|
|
387
|
+
const serverModule = require('next/dist/server/lib/start-server.js')
|
|
388
|
+
const { startServer } = serverModule.default ?? serverModule
|
|
374
389
|
|
|
375
390
|
await startServer({
|
|
376
391
|
dir: dirname(serverEntrypoint),
|
|
@@ -450,6 +465,16 @@ export class NextCapability extends BaseCapability {
|
|
|
450
465
|
await writeFile(requiredServerFilesPath, JSON.stringify(requiredServerFiles, null, 2))
|
|
451
466
|
}
|
|
452
467
|
}
|
|
468
|
+
|
|
469
|
+
// This is needed to allow to have a standalone server working correctly
|
|
470
|
+
if (existsSync(resolvePath(distDir, 'standalone'))) {
|
|
471
|
+
await writeFile(
|
|
472
|
+
resolvePath(distDir, 'standalone/.platformatic-build.json'),
|
|
473
|
+
JSON.stringify({ standalone: true, version: this.#nextVersion.version }),
|
|
474
|
+
'utf-8'
|
|
475
|
+
)
|
|
476
|
+
}
|
|
477
|
+
|
|
453
478
|
return distDir
|
|
454
479
|
}
|
|
455
480
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/next",
|
|
3
|
-
"version": "3.32.0-alpha.
|
|
3
|
+
"version": "3.32.0-alpha.1",
|
|
4
4
|
"description": "Platformatic Next.js Capability",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"iovalkey": "^0.3.0",
|
|
24
24
|
"msgpackr": "^1.11.2",
|
|
25
25
|
"semver": "^7.6.3",
|
|
26
|
-
"@platformatic/basic": "3.32.0-alpha.
|
|
27
|
-
"@platformatic/foundation": "3.32.0-alpha.
|
|
26
|
+
"@platformatic/basic": "3.32.0-alpha.1",
|
|
27
|
+
"@platformatic/foundation": "3.32.0-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@fastify/reply-from": "^12.0.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"next": "^16.0.0",
|
|
41
41
|
"typescript": "^5.5.4",
|
|
42
42
|
"ws": "^8.18.0",
|
|
43
|
-
"@platformatic/gateway": "3.32.0-alpha.
|
|
44
|
-
"@platformatic/service": "3.32.0-alpha.
|
|
43
|
+
"@platformatic/gateway": "3.32.0-alpha.1",
|
|
44
|
+
"@platformatic/service": "3.32.0-alpha.1"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=22.19.0"
|
package/schema.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/next/3.32.0-alpha.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/next/3.32.0-alpha.1.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Next.js Config",
|
|
5
5
|
"type": "object",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"properties": {
|
|
13
13
|
"level": {
|
|
14
14
|
"type": "string",
|
|
15
|
-
"default": "info",
|
|
16
15
|
"oneOf": [
|
|
17
16
|
{
|
|
18
17
|
"enum": [
|
|
@@ -155,9 +154,6 @@
|
|
|
155
154
|
"additionalProperties": true
|
|
156
155
|
}
|
|
157
156
|
},
|
|
158
|
-
"required": [
|
|
159
|
-
"level"
|
|
160
|
-
],
|
|
161
157
|
"default": {},
|
|
162
158
|
"additionalProperties": true
|
|
163
159
|
},
|
|
@@ -574,16 +570,6 @@
|
|
|
574
570
|
"type": "string"
|
|
575
571
|
}
|
|
576
572
|
]
|
|
577
|
-
},
|
|
578
|
-
"noHeapCheck": {
|
|
579
|
-
"anyOf": [
|
|
580
|
-
{
|
|
581
|
-
"type": "boolean"
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
"type": "string"
|
|
585
|
-
}
|
|
586
|
-
]
|
|
587
573
|
}
|
|
588
574
|
},
|
|
589
575
|
"additionalProperties": false
|
|
@@ -708,6 +694,28 @@
|
|
|
708
694
|
}
|
|
709
695
|
}
|
|
710
696
|
}
|
|
697
|
+
},
|
|
698
|
+
"compileCache": {
|
|
699
|
+
"anyOf": [
|
|
700
|
+
{
|
|
701
|
+
"type": "boolean"
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
"type": "object",
|
|
705
|
+
"properties": {
|
|
706
|
+
"enabled": {
|
|
707
|
+
"type": "boolean",
|
|
708
|
+
"default": true,
|
|
709
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
710
|
+
},
|
|
711
|
+
"directory": {
|
|
712
|
+
"type": "string",
|
|
713
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
"additionalProperties": false
|
|
717
|
+
}
|
|
718
|
+
]
|
|
711
719
|
}
|
|
712
720
|
}
|
|
713
721
|
}
|
|
@@ -787,7 +795,6 @@
|
|
|
787
795
|
"properties": {
|
|
788
796
|
"level": {
|
|
789
797
|
"type": "string",
|
|
790
|
-
"default": "info",
|
|
791
798
|
"oneOf": [
|
|
792
799
|
{
|
|
793
800
|
"enum": [
|
|
@@ -930,9 +937,6 @@
|
|
|
930
937
|
"additionalProperties": true
|
|
931
938
|
}
|
|
932
939
|
},
|
|
933
|
-
"required": [
|
|
934
|
-
"level"
|
|
935
|
-
],
|
|
936
940
|
"default": {},
|
|
937
941
|
"additionalProperties": true
|
|
938
942
|
},
|
|
@@ -1228,17 +1232,6 @@
|
|
|
1228
1232
|
}
|
|
1229
1233
|
],
|
|
1230
1234
|
"default": 268435456
|
|
1231
|
-
},
|
|
1232
|
-
"noHeapCheck": {
|
|
1233
|
-
"anyOf": [
|
|
1234
|
-
{
|
|
1235
|
-
"type": "boolean"
|
|
1236
|
-
},
|
|
1237
|
-
{
|
|
1238
|
-
"type": "string"
|
|
1239
|
-
}
|
|
1240
|
-
],
|
|
1241
|
-
"default": false
|
|
1242
1235
|
}
|
|
1243
1236
|
},
|
|
1244
1237
|
"additionalProperties": false
|
|
@@ -1370,6 +1363,26 @@
|
|
|
1370
1363
|
},
|
|
1371
1364
|
"maxCount": {
|
|
1372
1365
|
"type": "integer"
|
|
1366
|
+
},
|
|
1367
|
+
"origins": {
|
|
1368
|
+
"type": "array",
|
|
1369
|
+
"items": {
|
|
1370
|
+
"type": "string"
|
|
1371
|
+
},
|
|
1372
|
+
"description": "Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., \"/https:\\\\/\\\\/.*\\\\.example\\\\.com/\")."
|
|
1373
|
+
},
|
|
1374
|
+
"cacheByDefault": {
|
|
1375
|
+
"type": "integer",
|
|
1376
|
+
"description": "Default cache duration in seconds for responses without explicit expiration headers."
|
|
1377
|
+
},
|
|
1378
|
+
"type": {
|
|
1379
|
+
"type": "string",
|
|
1380
|
+
"enum": [
|
|
1381
|
+
"shared",
|
|
1382
|
+
"private"
|
|
1383
|
+
],
|
|
1384
|
+
"default": "shared",
|
|
1385
|
+
"description": "Cache type. \"shared\" caches may be shared between users, \"private\" caches are user-specific."
|
|
1373
1386
|
}
|
|
1374
1387
|
}
|
|
1375
1388
|
}
|
|
@@ -1985,6 +1998,28 @@
|
|
|
1985
1998
|
],
|
|
1986
1999
|
"additionalProperties": false
|
|
1987
2000
|
},
|
|
2001
|
+
"compileCache": {
|
|
2002
|
+
"anyOf": [
|
|
2003
|
+
{
|
|
2004
|
+
"type": "boolean"
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
"type": "object",
|
|
2008
|
+
"properties": {
|
|
2009
|
+
"enabled": {
|
|
2010
|
+
"type": "boolean",
|
|
2011
|
+
"default": true,
|
|
2012
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
2013
|
+
},
|
|
2014
|
+
"directory": {
|
|
2015
|
+
"type": "string",
|
|
2016
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
2017
|
+
}
|
|
2018
|
+
},
|
|
2019
|
+
"additionalProperties": false
|
|
2020
|
+
}
|
|
2021
|
+
]
|
|
2022
|
+
},
|
|
1988
2023
|
"application": {
|
|
1989
2024
|
"type": "object",
|
|
1990
2025
|
"properties": {
|
|
@@ -2132,16 +2167,6 @@
|
|
|
2132
2167
|
"type": "string"
|
|
2133
2168
|
}
|
|
2134
2169
|
]
|
|
2135
|
-
},
|
|
2136
|
-
"noHeapCheck": {
|
|
2137
|
-
"anyOf": [
|
|
2138
|
-
{
|
|
2139
|
-
"type": "boolean"
|
|
2140
|
-
},
|
|
2141
|
-
{
|
|
2142
|
-
"type": "string"
|
|
2143
|
-
}
|
|
2144
|
-
]
|
|
2145
2170
|
}
|
|
2146
2171
|
},
|
|
2147
2172
|
"additionalProperties": false
|
|
@@ -2259,6 +2284,28 @@
|
|
|
2259
2284
|
}
|
|
2260
2285
|
}
|
|
2261
2286
|
}
|
|
2287
|
+
},
|
|
2288
|
+
"compileCache": {
|
|
2289
|
+
"anyOf": [
|
|
2290
|
+
{
|
|
2291
|
+
"type": "boolean"
|
|
2292
|
+
},
|
|
2293
|
+
{
|
|
2294
|
+
"type": "object",
|
|
2295
|
+
"properties": {
|
|
2296
|
+
"enabled": {
|
|
2297
|
+
"type": "boolean",
|
|
2298
|
+
"default": true,
|
|
2299
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
2300
|
+
},
|
|
2301
|
+
"directory": {
|
|
2302
|
+
"type": "string",
|
|
2303
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
2304
|
+
}
|
|
2305
|
+
},
|
|
2306
|
+
"additionalProperties": false
|
|
2307
|
+
}
|
|
2308
|
+
]
|
|
2262
2309
|
}
|
|
2263
2310
|
},
|
|
2264
2311
|
"additionalProperties": false
|