@platformatic/nitro 3.68.0 → 4.0.0-new-config.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 CHANGED
@@ -66,7 +66,7 @@ export interface PlatformaticNitroConfig {
66
66
  hostname?: string;
67
67
  port?: number | string;
68
68
  /**
69
- * Configures how entrypoint server worker ports are assigned. When set to shared, all workers listen on the same port. When set to perWorkerIncrement, each worker will use its own port, starting from port (worker 0).
69
+ * Configures how the port is assigned when the application runs multiple workers. When set to shared (the default), all workers listen on the same port (which requires SO_REUSEPORT support). When set to perWorkerIncrement, each worker listens on its own port, starting from port (worker 0) and incrementing by one for each additional worker.
70
70
  */
71
71
  portAssignment?: "shared" | "perWorkerIncrement";
72
72
  /**
@@ -223,46 +223,6 @@ export interface PlatformaticNitroConfig {
223
223
  };
224
224
  [k: string]: unknown;
225
225
  };
226
- server?: {
227
- hostname?: string;
228
- port?: number | string;
229
- /**
230
- * Configures how entrypoint server worker ports are assigned. When set to shared, all workers listen on the same port. When set to perWorkerIncrement, each worker will use its own port, starting from port (worker 0).
231
- */
232
- portAssignment?: "shared" | "perWorkerIncrement";
233
- /**
234
- * The maximum length of the queue of pending connections
235
- */
236
- backlog?: number;
237
- http2?: boolean;
238
- https?: {
239
- allowHTTP1?: boolean;
240
- key:
241
- | string
242
- | {
243
- path?: string;
244
- }
245
- | (
246
- | string
247
- | {
248
- path?: string;
249
- }
250
- )[];
251
- cert:
252
- | string
253
- | {
254
- path?: string;
255
- }
256
- | (
257
- | string
258
- | {
259
- path?: string;
260
- }
261
- )[];
262
- requestCert?: boolean;
263
- rejectUnauthorized?: boolean;
264
- };
265
- };
266
226
  reuseTcpPorts?: boolean;
267
227
  startTimeout?: number;
268
228
  restartOnError?: boolean | number;
package/index.js CHANGED
@@ -37,3 +37,5 @@ export async function create (configOrRoot, sourceOrConfig, context) {
37
37
 
38
38
  export * from './lib/capability.js'
39
39
  export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
40
+
41
+ export * from './lib/factory.js'
package/lib/capability.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  BaseCapability,
3
- buildAdditionalServerOptions,
4
3
  cleanBasePath,
5
4
  createServerListener,
6
5
  ensureTrailingSlash,
@@ -170,13 +169,8 @@ export class NitroCapability extends BaseCapability {
170
169
  })
171
170
  }
172
171
 
173
- async start ({ listen }) {
174
- /* c8 ignore next 3 */
175
- if (this.url) {
176
- return this.url
177
- }
178
-
179
- await super._start({ listen })
172
+ async _start () {
173
+ await super._start()
180
174
 
181
175
  const command = this.config.application.commands[this.isProduction ? 'production' : 'development']
182
176
  if (command) {
@@ -187,6 +181,10 @@ export class NitroCapability extends BaseCapability {
187
181
  return this.startWithCommand(command)
188
182
  }
189
183
 
184
+ if (typeof this.serverConfig?.port === 'undefined') {
185
+ return
186
+ }
187
+
190
188
  if (this.isProduction) {
191
189
  await this.#startProduction()
192
190
  } else {
@@ -194,11 +192,10 @@ export class NitroCapability extends BaseCapability {
194
192
  }
195
193
 
196
194
  await this._collectMetrics()
197
- return this.url
198
195
  }
199
196
 
200
- async stop () {
201
- await super.stop()
197
+ async _stop () {
198
+ await super._stop()
202
199
 
203
200
  if (this.childManager) {
204
201
  return this.stopCommand()
@@ -360,11 +357,7 @@ export class NitroCapability extends BaseCapability {
360
357
  let serverPromise
361
358
 
362
359
  try {
363
- serverPromise = createServerListener(
364
- serverConfig?.port ?? true,
365
- serverConfig?.hostname ?? true,
366
- await buildAdditionalServerOptions(serverConfig)
367
- )
360
+ serverPromise = createServerListener()
368
361
  await importFile(entrypointPath)
369
362
  this.#server = await serverPromise
370
363
  this.#dispatcher = this.#server.listeners('request')[0]
@@ -452,9 +445,9 @@ export class NitroViteCapability extends ViteCapability {
452
445
  this.registerGlobals({ basePath: this.#basePath })
453
446
  }
454
447
 
455
- async stop () {
448
+ async _stop () {
456
449
  const commandWasRunning = !!this.childManager
457
- await super.stop()
450
+ await super._stop()
458
451
 
459
452
  if (!commandWasRunning && this.isProduction && this.#server?.listening) {
460
453
  return this._closeServer(this.#server)
@@ -586,6 +579,10 @@ export class NitroViteCapability extends ViteCapability {
586
579
  )
587
580
  }
588
581
 
582
+ if (typeof this.serverConfig?.port === 'undefined') {
583
+ return
584
+ }
585
+
589
586
  const serverConfig = this.serverConfig
590
587
  const host = serverConfig?.hostname ?? '127.0.0.1'
591
588
  const port = serverConfig?.port ?? 0
@@ -611,11 +608,7 @@ export class NitroViteCapability extends ViteCapability {
611
608
  let serverPromise
612
609
 
613
610
  try {
614
- serverPromise = createServerListener(
615
- serverConfig?.port ?? true,
616
- serverConfig?.hostname ?? true,
617
- await buildAdditionalServerOptions(serverConfig)
618
- )
611
+ serverPromise = createServerListener()
619
612
  await importFile(entrypointPath)
620
613
  this.#server = await serverPromise
621
614
  this.#dispatcher = this.#server.listeners('request')[0]
package/lib/factory.js ADDED
@@ -0,0 +1,12 @@
1
+ import { defineCapabilityFactory } from '@platformatic/basic'
2
+ import { schema, version } from './schema.js'
3
+
4
+ /*
5
+ Vite-derived capabilities flatten the vite block alongside their own; outputDirectory comes
6
+ from the capability's block while application.outputDirectory stays nested, which is why the
7
+ application block is not flattened anywhere.
8
+ */
9
+ export const nitro = defineCapabilityFactory('@platformatic/nitro', schema, {
10
+ version,
11
+ flatten: ['vite', 'nitro']
12
+ })
package/lib/schema.js CHANGED
@@ -1,12 +1,16 @@
1
- import { schemaComponents as basicSchemaComponents } from '@platformatic/basic'
2
- import { schemaComponents as utilsSchemaComponents } from '@platformatic/foundation'
3
- import { schemaComponents as viteSchemaComponents } from '@platformatic/vite'
1
+ import { schemaComponents as basicSchemaComponents } from '@platformatic/basic/lib/schema.js'
2
+ import { schemaComponents as utilsSchemaComponents } from '@platformatic/foundation/lib/schema.js'
3
+ import { schemaComponents as viteSchemaComponents } from '@platformatic/vite/lib/schema.js'
4
4
  import { readFileSync } from 'node:fs'
5
5
  import { resolve } from 'node:path'
6
6
 
7
7
  export const packageJson = JSON.parse(readFileSync(resolve(import.meta.dirname, '../package.json'), 'utf8'))
8
8
  export const version = packageJson.version
9
9
 
10
+ // The port is checked before any startup path is selected, in both capability classes
11
+ // this package ships.
12
+ export const servesWithoutPort = { development: false, production: false }
13
+
10
14
  export const nitro = {
11
15
  type: 'object',
12
16
  properties: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/nitro",
3
- "version": "3.68.0",
3
+ "version": "4.0.0-new-config.1",
4
4
  "description": "Platformatic Nitro Capability",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,6 +16,7 @@
16
16
  "import": "./lib/scheduler/module.js",
17
17
  "default": "./lib/scheduler/module.js"
18
18
  },
19
+ "./schema": "./schema.js",
19
20
  "./*": "./*"
20
21
  },
21
22
  "repository": {
@@ -31,10 +32,10 @@
31
32
  "dependencies": {
32
33
  "light-my-request": "^6.6.0",
33
34
  "semver": "^7.6.3",
34
- "@platformatic/basic": "3.68.0",
35
- "@platformatic/foundation": "3.68.0",
36
- "@platformatic/globals": "3.68.0",
37
- "@platformatic/vite": "3.68.0"
35
+ "@platformatic/basic": "4.0.0-new-config.1",
36
+ "@platformatic/foundation": "4.0.0-new-config.1",
37
+ "@platformatic/vite": "4.0.0-new-config.1",
38
+ "@platformatic/globals": "4.0.0-new-config.1"
38
39
  },
39
40
  "devDependencies": {
40
41
  "cleaner-spec-reporter": "^0.5.0",
@@ -47,8 +48,8 @@
47
48
  "typescript": "~6.0.3",
48
49
  "vite": "^7.2.4",
49
50
  "ws": "^8.18.0",
50
- "@platformatic/gateway": "3.68.0",
51
- "@platformatic/service": "3.68.0"
51
+ "@platformatic/gateway": "4.0.0-new-config.1",
52
+ "@platformatic/service": "4.0.0-new-config.1"
52
53
  },
53
54
  "engines": {
54
55
  "node": ">=22.19.0"
package/schema.js ADDED
@@ -0,0 +1,7 @@
1
+ // The light /schema subpath, part of the v4 capability contract. It carries the schema and the
2
+ // package-level metadata main-side preparation needs, and imports nothing that would pull the
3
+ // capability's implementation in with it — boot resolves this rather than the package entry.
4
+ //
5
+ // Light is a statement about import cost, never about safety: this executes in the main process
6
+ // with full privileges, like any capability code.
7
+ export * from './lib/schema.js'
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/nitro/3.68.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/nitro/4.0.0-new-config.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Nitro Config",
5
5
  "type": "object",
@@ -202,7 +202,7 @@
202
202
  "shared",
203
203
  "perWorkerIncrement"
204
204
  ],
205
- "description": "Configures how entrypoint server worker ports are assigned. When set to shared, all workers listen on the same port. When set to perWorkerIncrement, each worker will use its own port, starting from port (worker 0)."
205
+ "description": "Configures how the port is assigned when the application runs multiple workers. When set to shared (the default), all workers listen on the same port (which requires SO_REUSEPORT support). When set to perWorkerIncrement, each worker listens on its own port, starting from port (worker 0) and incrementing by one for each additional worker."
206
206
  },
207
207
  "backlog": {
208
208
  "type": "integer",
@@ -530,7 +530,14 @@
530
530
  "resolvePath": true
531
531
  },
532
532
  "config": {
533
- "type": "string"
533
+ "anyOf": [
534
+ {
535
+ "type": "string"
536
+ },
537
+ {
538
+ "type": "object"
539
+ }
540
+ ]
534
541
  },
535
542
  "url": {
536
543
  "type": "string"
@@ -539,12 +546,6 @@
539
546
  "type": "string",
540
547
  "default": "main"
541
548
  },
542
- "useHttp": {
543
- "type": "boolean"
544
- },
545
- "websocket": {
546
- "type": "boolean"
547
- },
548
549
  "reuseTcpPorts": {
549
550
  "type": "boolean",
550
551
  "default": true
@@ -1158,133 +1159,6 @@
1158
1159
  "default": {},
1159
1160
  "additionalProperties": true
1160
1161
  },
1161
- "server": {
1162
- "type": "object",
1163
- "properties": {
1164
- "hostname": {
1165
- "type": "string"
1166
- },
1167
- "port": {
1168
- "anyOf": [
1169
- {
1170
- "type": "integer"
1171
- },
1172
- {
1173
- "type": "string"
1174
- }
1175
- ]
1176
- },
1177
- "portAssignment": {
1178
- "type": "string",
1179
- "enum": [
1180
- "shared",
1181
- "perWorkerIncrement"
1182
- ],
1183
- "description": "Configures how entrypoint server worker ports are assigned. When set to shared, all workers listen on the same port. When set to perWorkerIncrement, each worker will use its own port, starting from port (worker 0)."
1184
- },
1185
- "backlog": {
1186
- "type": "integer",
1187
- "description": "The maximum length of the queue of pending connections"
1188
- },
1189
- "http2": {
1190
- "type": "boolean"
1191
- },
1192
- "https": {
1193
- "type": "object",
1194
- "properties": {
1195
- "allowHTTP1": {
1196
- "type": "boolean"
1197
- },
1198
- "key": {
1199
- "anyOf": [
1200
- {
1201
- "type": "string"
1202
- },
1203
- {
1204
- "type": "object",
1205
- "properties": {
1206
- "path": {
1207
- "type": "string",
1208
- "resolvePath": true
1209
- }
1210
- },
1211
- "additionalProperties": false
1212
- },
1213
- {
1214
- "type": "array",
1215
- "items": {
1216
- "anyOf": [
1217
- {
1218
- "type": "string"
1219
- },
1220
- {
1221
- "type": "object",
1222
- "properties": {
1223
- "path": {
1224
- "type": "string",
1225
- "resolvePath": true
1226
- }
1227
- },
1228
- "additionalProperties": false
1229
- }
1230
- ]
1231
- }
1232
- }
1233
- ]
1234
- },
1235
- "cert": {
1236
- "anyOf": [
1237
- {
1238
- "type": "string"
1239
- },
1240
- {
1241
- "type": "object",
1242
- "properties": {
1243
- "path": {
1244
- "type": "string",
1245
- "resolvePath": true
1246
- }
1247
- },
1248
- "additionalProperties": false
1249
- },
1250
- {
1251
- "type": "array",
1252
- "items": {
1253
- "anyOf": [
1254
- {
1255
- "type": "string"
1256
- },
1257
- {
1258
- "type": "object",
1259
- "properties": {
1260
- "path": {
1261
- "type": "string",
1262
- "resolvePath": true
1263
- }
1264
- },
1265
- "additionalProperties": false
1266
- }
1267
- ]
1268
- }
1269
- }
1270
- ]
1271
- },
1272
- "requestCert": {
1273
- "type": "boolean"
1274
- },
1275
- "rejectUnauthorized": {
1276
- "type": "boolean"
1277
- }
1278
- },
1279
- "additionalProperties": false,
1280
- "required": [
1281
- "key",
1282
- "cert"
1283
- ]
1284
- }
1285
- },
1286
- "additionalProperties": false
1287
- },
1288
1162
  "reuseTcpPorts": {
1289
1163
  "type": "boolean",
1290
1164
  "default": true