@platformatic/next 3.32.0-alpha.1 → 3.33.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 CHANGED
@@ -619,6 +619,7 @@ export interface PlatformaticNextJsConfig {
619
619
  };
620
620
  };
621
621
  next?: {
622
+ standalone?: boolean;
622
623
  trailingSlash?: boolean;
623
624
  useExperimentalAdapter?: boolean;
624
625
  };
package/lib/capability.js CHANGED
@@ -44,44 +44,12 @@ export class NextCapability extends BaseCapability {
44
44
  async init () {
45
45
  await super.init()
46
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
-
61
- // This is needed to avoid Next.js to throw an error when the lockfile is not correct
62
- // and the user is using npm but has pnpm in its $PATH.
63
- //
64
- // See: https://github.com/platformatic/composer-next-node-fastify/pull/3
65
- //
66
- // PS by Paolo: Sob.
67
- process.env.NEXT_IGNORE_INCORRECT_LOCKFILE = 'true'
68
-
69
- this.#next = resolvePath(dirname(await resolvePackageViaCJS(this.root, 'next')), '../..')
70
- const nextPackage = JSON.parse(await readFile(resolvePath(this.#next, 'package.json'), 'utf-8'))
71
- this.#nextVersion = parse(nextPackage.version)
72
-
73
- if (this.#nextVersion.major < 15 || (this.#nextVersion.major <= 15 && this.#nextVersion.minor < 1)) {
74
- await import('./create-context-patch.js')
75
- }
76
-
77
- if (this.#nextVersion.major < 16 && this.config.next?.useExperimentalAdapter === true) {
78
- this.config.next.useExperimentalAdapter = false
47
+ if (this.isProduction && this.config.next?.standalone) {
48
+ this.#isStandalone = true
49
+ return
79
50
  }
80
51
 
81
- /* c8 ignore next 3 */
82
- if (!supportedVersions.some(v => satisfies(nextPackage.version, v))) {
83
- throw new basicErrors.UnsupportedVersion('next', nextPackage.version, supportedVersions)
84
- }
52
+ return this.#init()
85
53
  }
86
54
 
87
55
  async start ({ listen }) {
@@ -140,7 +108,7 @@ export class NextCapability extends BaseCapability {
140
108
 
141
109
  async build () {
142
110
  if (!this.#nextVersion) {
143
- await this.init()
111
+ await this.#init()
144
112
  }
145
113
 
146
114
  const config = this.config
@@ -188,6 +156,33 @@ export class NextCapability extends BaseCapability {
188
156
  return context
189
157
  }
190
158
 
159
+ async #init () {
160
+ // This is needed to avoid Next.js to throw an error when the lockfile is not correct
161
+ // and the user is using npm but has pnpm in its $PATH.
162
+ //
163
+ // See: https://github.com/platformatic/composer-next-node-fastify/pull/3
164
+ //
165
+ // PS by Paolo: Sob.
166
+ process.env.NEXT_IGNORE_INCORRECT_LOCKFILE = 'true'
167
+
168
+ this.#next = resolvePath(dirname(await resolvePackageViaCJS(this.root, 'next')), '../..')
169
+ const nextPackage = JSON.parse(await readFile(resolvePath(this.#next, 'package.json'), 'utf-8'))
170
+ this.#nextVersion = parse(nextPackage.version)
171
+
172
+ if (this.#nextVersion.major < 15 || (this.#nextVersion.major <= 15 && this.#nextVersion.minor < 1)) {
173
+ await import('./create-context-patch.js')
174
+ }
175
+
176
+ if (this.#nextVersion.major < 16 && this.config.next?.useExperimentalAdapter === true) {
177
+ this.config.next.useExperimentalAdapter = false
178
+ }
179
+
180
+ /* c8 ignore next 3 */
181
+ if (!supportedVersions.some(v => satisfies(nextPackage.version, v))) {
182
+ throw new basicErrors.UnsupportedVersion('next', nextPackage.version, supportedVersions)
183
+ }
184
+ }
185
+
191
186
  async #startDevelopment () {
192
187
  const config = this.config
193
188
  const loaderUrl = new URL('./loader.js', import.meta.url)
@@ -383,9 +378,7 @@ export class NextCapability extends BaseCapability {
383
378
 
384
379
  // This is needed by Next.js standalone server to pick up the correct configuration
385
380
  process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig)
386
- const require = createRequire(serverEntrypoint)
387
- const serverModule = require('next/dist/server/lib/start-server.js')
388
- const { startServer } = serverModule.default ?? serverModule
381
+ const { startServer } = this.#requireStandaloneEntrypoint(serverEntrypoint)
389
382
 
390
383
  await startServer({
391
384
  dir: dirname(serverEntrypoint),
@@ -466,15 +459,18 @@ export class NextCapability extends BaseCapability {
466
459
  }
467
460
  }
468
461
 
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
- )
462
+ return distDir
463
+ }
464
+
465
+ #requireStandaloneEntrypoint (serverEntrypoint) {
466
+ let serverModule
467
+
468
+ try {
469
+ serverModule = createRequire(serverEntrypoint)('next/dist/server/lib/start-server.js')
470
+ } catch (e) { // Fallback to bundled capability
471
+ serverModule = createRequire(import.meta.file)('next/dist/server/lib/start-server.js')
476
472
  }
477
473
 
478
- return distDir
474
+ return serverModule.default ?? serverModule
479
475
  }
480
476
  }
package/lib/schema.js CHANGED
@@ -42,6 +42,9 @@ export const cache = {
42
42
  const next = {
43
43
  type: 'object',
44
44
  properties: {
45
+ standalone: {
46
+ type: 'boolean',
47
+ },
45
48
  trailingSlash: {
46
49
  type: 'boolean',
47
50
  default: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/next",
3
- "version": "3.32.0-alpha.1",
3
+ "version": "3.33.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.1",
27
- "@platformatic/foundation": "3.32.0-alpha.1"
26
+ "@platformatic/basic": "3.33.0-alpha.1",
27
+ "@platformatic/foundation": "3.33.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.1",
44
- "@platformatic/service": "3.32.0-alpha.1"
43
+ "@platformatic/gateway": "3.33.0-alpha.1",
44
+ "@platformatic/service": "3.33.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.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/next/3.33.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",
@@ -2316,6 +2316,9 @@
2316
2316
  "next": {
2317
2317
  "type": "object",
2318
2318
  "properties": {
2319
+ "standalone": {
2320
+ "type": "boolean"
2321
+ },
2319
2322
  "trailingSlash": {
2320
2323
  "type": "boolean",
2321
2324
  "default": false