@platformatic/react-router 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 PlatformaticReactRouterConfig {
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
  /**
@@ -224,46 +224,6 @@ export interface PlatformaticReactRouterConfig {
224
224
  };
225
225
  [k: string]: unknown;
226
226
  };
227
- server?: {
228
- hostname?: string;
229
- port?: number | string;
230
- /**
231
- * 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).
232
- */
233
- portAssignment?: "shared" | "perWorkerIncrement";
234
- /**
235
- * The maximum length of the queue of pending connections
236
- */
237
- backlog?: number;
238
- http2?: boolean;
239
- https?: {
240
- allowHTTP1?: boolean;
241
- key:
242
- | string
243
- | {
244
- path?: string;
245
- }
246
- | (
247
- | string
248
- | {
249
- path?: string;
250
- }
251
- )[];
252
- cert:
253
- | string
254
- | {
255
- path?: string;
256
- }
257
- | (
258
- | string
259
- | {
260
- path?: string;
261
- }
262
- )[];
263
- requestCert?: boolean;
264
- rejectUnauthorized?: boolean;
265
- };
266
- };
267
227
  reuseTcpPorts?: boolean;
268
228
  startTimeout?: number;
269
229
  restartOnError?: boolean | number;
package/index.js CHANGED
@@ -29,3 +29,5 @@ export async function create (configOrRoot, sourceOrConfig, context) {
29
29
 
30
30
  export * from './lib/capability.js'
31
31
  export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
32
+
33
+ export * from './lib/factory.js'
package/lib/capability.js CHANGED
@@ -55,12 +55,7 @@ export class ReactRouterCapability extends ViteCapability {
55
55
  this.subprocessTerminationSignal = 'SIGKILL'
56
56
  }
57
57
 
58
- async start ({ listen }) {
59
- // Make this idempotent
60
- if (this.url) {
61
- return this.url
62
- }
63
-
58
+ async _start () {
64
59
  const config = this.config
65
60
  const reactRouterConfig = await this.#getReactRouterConfig()
66
61
 
@@ -75,13 +70,11 @@ export class ReactRouterCapability extends ViteCapability {
75
70
  }
76
71
 
77
72
  if (reactRouterConfig.ssr) {
78
- await super._start({ listen })
79
-
80
- return this.#startSSRProduction(listen)
73
+ return this.#startSSRProduction()
81
74
  }
82
75
  }
83
76
 
84
- return super.start({ listen })
77
+ return super._start()
85
78
  }
86
79
 
87
80
  async build () {
@@ -122,21 +115,7 @@ export class ReactRouterCapability extends ViteCapability {
122
115
  return reactRouterConfig ?? {}
123
116
  }
124
117
 
125
- async #startSSRProduction (listen) {
126
- // Listen if entrypoint
127
- if (this.#app && listen) {
128
- const serverOptions = this.serverConfig
129
- const listenOptions = buildListenOptions(serverOptions)
130
-
131
- if (typeof serverOptions?.backlog === 'number') {
132
- createServerListener(false, false, { backlog: serverOptions.backlog })
133
- }
134
-
135
- await this.#app.listen(listenOptions)
136
- this.url = getServerUrl(this.#app.server)
137
- return this.url
138
- }
139
-
118
+ async #startSSRProduction () {
140
119
  const config = this.config
141
120
 
142
121
  const clientRoot = resolve(this.root, config.reactRouter.outputDirectory, 'client')
@@ -213,6 +192,17 @@ export class ReactRouterCapability extends ViteCapability {
213
192
 
214
193
  await this.#app.ready()
215
194
  await this._collectMetrics()
195
+
196
+ if (typeof this.serverConfig?.port === 'undefined') {
197
+ return
198
+ }
199
+
200
+ const serverOptions = this.serverConfig
201
+ const listenOptions = buildListenOptions(serverOptions)
202
+ const serverPromise = createServerListener()
203
+
204
+ await Promise.all([this.#app.listen(listenOptions), serverPromise])
205
+ this.url = getServerUrl(this.#app.server)
216
206
  }
217
207
 
218
208
  #handleRequest (handle, req) {
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 reactRouter = defineCapabilityFactory('@platformatic/react-router', schema, {
10
+ version,
11
+ flatten: ['vite', 'reactRouter']
12
+ })
package/lib/schema.js CHANGED
@@ -1,12 +1,17 @@
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
+ // Extends ViteCapability and selects its SSR production path at worker startup, so which
11
+ // application it builds is not visible here — but it builds one either way, so that it serves
12
+ // stays decidable even though what it serves is not.
13
+ export const servesWithoutPort = { development: false, production: true }
14
+
10
15
  export const reactRouter = {
11
16
  type: 'object',
12
17
  properties: {
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@platformatic/react-router",
3
- "version": "3.68.0",
3
+ "version": "4.0.0-new-config.1",
4
4
  "description": "Platformatic React Router Capability",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./schema": "./schema.js",
10
+ "./package.json": "./package.json",
11
+ "./*": "./*"
12
+ },
7
13
  "repository": {
8
14
  "type": "git",
9
15
  "url": "git+https://github.com/platformatic/platformatic.git"
@@ -18,10 +24,10 @@
18
24
  "@fastify/static": "^10.0.0",
19
25
  "fastify": "^5.0.0",
20
26
  "semver": "^7.6.3",
21
- "@platformatic/basic": "3.68.0",
22
- "@platformatic/foundation": "3.68.0",
23
- "@platformatic/vite": "3.68.0",
24
- "@platformatic/globals": "3.68.0"
27
+ "@platformatic/basic": "4.0.0-new-config.1",
28
+ "@platformatic/foundation": "4.0.0-new-config.1",
29
+ "@platformatic/globals": "4.0.0-new-config.1",
30
+ "@platformatic/vite": "4.0.0-new-config.1"
25
31
  },
26
32
  "devDependencies": {
27
33
  "@react-router/dev": "^7.10.0",
@@ -42,8 +48,8 @@
42
48
  "typescript": "~6.0.3",
43
49
  "vite": "^7.1.7",
44
50
  "ws": "^8.18.0",
45
- "@platformatic/gateway": "3.68.0",
46
- "@platformatic/service": "3.68.0"
51
+ "@platformatic/gateway": "4.0.0-new-config.1",
52
+ "@platformatic/service": "4.0.0-new-config.1"
47
53
  },
48
54
  "engines": {
49
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/react-router/3.68.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/react-router/4.0.0-new-config.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic React Router 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",
@@ -536,7 +536,14 @@
536
536
  "resolvePath": true
537
537
  },
538
538
  "config": {
539
- "type": "string"
539
+ "anyOf": [
540
+ {
541
+ "type": "string"
542
+ },
543
+ {
544
+ "type": "object"
545
+ }
546
+ ]
540
547
  },
541
548
  "url": {
542
549
  "type": "string"
@@ -545,12 +552,6 @@
545
552
  "type": "string",
546
553
  "default": "main"
547
554
  },
548
- "useHttp": {
549
- "type": "boolean"
550
- },
551
- "websocket": {
552
- "type": "boolean"
553
- },
554
555
  "reuseTcpPorts": {
555
556
  "type": "boolean",
556
557
  "default": true
@@ -1164,133 +1165,6 @@
1164
1165
  "default": {},
1165
1166
  "additionalProperties": true
1166
1167
  },
1167
- "server": {
1168
- "type": "object",
1169
- "properties": {
1170
- "hostname": {
1171
- "type": "string"
1172
- },
1173
- "port": {
1174
- "anyOf": [
1175
- {
1176
- "type": "integer"
1177
- },
1178
- {
1179
- "type": "string"
1180
- }
1181
- ]
1182
- },
1183
- "portAssignment": {
1184
- "type": "string",
1185
- "enum": [
1186
- "shared",
1187
- "perWorkerIncrement"
1188
- ],
1189
- "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)."
1190
- },
1191
- "backlog": {
1192
- "type": "integer",
1193
- "description": "The maximum length of the queue of pending connections"
1194
- },
1195
- "http2": {
1196
- "type": "boolean"
1197
- },
1198
- "https": {
1199
- "type": "object",
1200
- "properties": {
1201
- "allowHTTP1": {
1202
- "type": "boolean"
1203
- },
1204
- "key": {
1205
- "anyOf": [
1206
- {
1207
- "type": "string"
1208
- },
1209
- {
1210
- "type": "object",
1211
- "properties": {
1212
- "path": {
1213
- "type": "string",
1214
- "resolvePath": true
1215
- }
1216
- },
1217
- "additionalProperties": false
1218
- },
1219
- {
1220
- "type": "array",
1221
- "items": {
1222
- "anyOf": [
1223
- {
1224
- "type": "string"
1225
- },
1226
- {
1227
- "type": "object",
1228
- "properties": {
1229
- "path": {
1230
- "type": "string",
1231
- "resolvePath": true
1232
- }
1233
- },
1234
- "additionalProperties": false
1235
- }
1236
- ]
1237
- }
1238
- }
1239
- ]
1240
- },
1241
- "cert": {
1242
- "anyOf": [
1243
- {
1244
- "type": "string"
1245
- },
1246
- {
1247
- "type": "object",
1248
- "properties": {
1249
- "path": {
1250
- "type": "string",
1251
- "resolvePath": true
1252
- }
1253
- },
1254
- "additionalProperties": false
1255
- },
1256
- {
1257
- "type": "array",
1258
- "items": {
1259
- "anyOf": [
1260
- {
1261
- "type": "string"
1262
- },
1263
- {
1264
- "type": "object",
1265
- "properties": {
1266
- "path": {
1267
- "type": "string",
1268
- "resolvePath": true
1269
- }
1270
- },
1271
- "additionalProperties": false
1272
- }
1273
- ]
1274
- }
1275
- }
1276
- ]
1277
- },
1278
- "requestCert": {
1279
- "type": "boolean"
1280
- },
1281
- "rejectUnauthorized": {
1282
- "type": "boolean"
1283
- }
1284
- },
1285
- "additionalProperties": false,
1286
- "required": [
1287
- "key",
1288
- "cert"
1289
- ]
1290
- }
1291
- },
1292
- "additionalProperties": false
1293
- },
1294
1168
  "reuseTcpPorts": {
1295
1169
  "type": "boolean",
1296
1170
  "default": true