@ossy/app 1.11.2 → 1.11.3

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.
Files changed (3) hide show
  1. package/cli/build.js +39 -1
  2. package/cli/server.js +24 -2
  3. package/package.json +10 -10
package/cli/build.js CHANGED
@@ -67,6 +67,8 @@ export const OSSY_API_RUNTIME_BASENAME = 'api.runtime.mjs'
67
67
  export const OSSY_TASKS_RUNTIME_BASENAME = 'tasks.runtime.mjs'
68
68
 
69
69
  export const OSSY_PAGE_MODULES_DIRNAME = 'page-modules'
70
+ /** Tiny Rollup inputs that re-export `metadata` so per-page server bundles keep i18n paths. */
71
+ export const OSSY_PAGE_SERVER_ENTRIES_DIRNAME = 'page-server-entries'
70
72
  export const OSSY_API_MODULES_DIRNAME = 'api-modules'
71
73
  export const OSSY_TASK_MODULES_DIRNAME = 'task-modules'
72
74
 
@@ -371,19 +373,24 @@ export async function compilePageServerModules ({
371
373
  onWarn,
372
374
  }) {
373
375
  const modsDir = path.join(ossyDir, OSSY_PAGE_MODULES_DIRNAME)
376
+ const entriesDir = path.join(ossyDir, OSSY_PAGE_SERVER_ENTRIES_DIRNAME)
374
377
  fs.rmSync(modsDir, { recursive: true, force: true })
378
+ fs.rmSync(entriesDir, { recursive: true, force: true })
375
379
  if (pageFiles.length === 0) {
376
380
  return []
377
381
  }
378
382
  fs.mkdirSync(modsDir, { recursive: true })
383
+ fs.mkdirSync(entriesDir, { recursive: true })
379
384
  const bundlePages = []
380
385
  for (const f of pageFiles) {
381
386
  const pageId = clientHydrateIdForPage(f, srcDir)
382
387
  const safeId = String(pageId).replace(/[^a-zA-Z0-9_-]+/g, '-') || 'page'
383
388
  const outName = `${safeId}.mjs`
384
389
  const outFile = path.join(modsDir, outName)
390
+ const stubPath = path.join(entriesDir, `${safeId}.mjs`)
391
+ writePageServerRollupEntry({ pageAbsPath: f, stubPath })
385
392
  await bundleOssyNodeEntry({
386
- inputPath: f,
393
+ inputPath: stubPath,
387
394
  outputFile: outFile,
388
395
  nodeEnv,
389
396
  onWarn,
@@ -500,6 +507,37 @@ export function clientHydrateIdForPage (pageAbsPath, srcDir) {
500
507
  return idMatch ? idMatch[1] : derived.id
501
508
  }
502
509
 
510
+ export function pageSourceExportsMetadata (pageAbsPath) {
511
+ try {
512
+ const src = fs.readFileSync(pageAbsPath, 'utf8')
513
+ return /\bexport\s+const\s+metadata\b/.test(src)
514
+ } catch {
515
+ return false
516
+ }
517
+ }
518
+
519
+ /**
520
+ * Rollup tree-shakes `export const metadata` when the page file is the entry and `default`
521
+ * never references it — breaks i18n `path` objects at runtime. Re-export from a shim entry
522
+ * so `metadata` stays in the module graph.
523
+ */
524
+ export function writePageServerRollupEntry ({ pageAbsPath, stubPath }) {
525
+ const rel = relToGeneratedImport(stubPath, pageAbsPath)
526
+ const meta = pageSourceExportsMetadata(pageAbsPath)
527
+ ? ', metadata'
528
+ : ''
529
+ fs.mkdirSync(path.dirname(stubPath), { recursive: true })
530
+ fs.writeFileSync(
531
+ stubPath,
532
+ [
533
+ '// Generated by @ossy/app — do not edit',
534
+ `export { default${meta} } from '${rel}'`,
535
+ '',
536
+ ].join('\n'),
537
+ 'utf8'
538
+ )
539
+ }
540
+
503
541
  /**
504
542
  * One client entry per page: imports only that page module and hydrates the document.
505
543
  * Keeps the same `toPage` shape as `pages.runtime.mjs` + manifests so SSR and client trees match.
package/cli/server.js CHANGED
@@ -17,6 +17,23 @@ const apiRouteList = ApiRoutes ?? []
17
17
 
18
18
  const sitePageList = Array.isArray(pageRoutes) ? pageRoutes : []
19
19
 
20
+ /** When `src/config.js` is minimal, infer language list from the first multi-path page. */
21
+ function pageRouterLanguageOptions (config, pages) {
22
+ let supported = config?.supportedLanguages
23
+ let defaultLanguage = config?.defaultLanguage
24
+ if ((!supported || supported.length <= 1) && pages.length > 0) {
25
+ const p0 = pages[0]
26
+ if (p0 && typeof p0.path === 'object' && p0.path != null) {
27
+ supported = Object.keys(p0.path)
28
+ defaultLanguage = defaultLanguage || supported[0]
29
+ }
30
+ }
31
+ return {
32
+ supportedLanguages: Array.isArray(supported) ? supported : [],
33
+ defaultLanguage,
34
+ }
35
+ }
36
+
20
37
  const app = express();
21
38
 
22
39
  const currentDir = path.dirname(url.fileURLToPath(import.meta.url))
@@ -110,10 +127,15 @@ const apiRouter = OssyRouter.of({
110
127
  pages: apiRouteList,
111
128
  })
112
129
 
130
+ const { supportedLanguages, defaultLanguage } = pageRouterLanguageOptions(
131
+ buildTimeConfig,
132
+ sitePageList
133
+ )
134
+
113
135
  const pageRouter = OssyRouter.of({
114
136
  pages: sitePageList,
115
- defaultLanguage: buildTimeConfig.defaultLanguage,
116
- supportedLanguages: buildTimeConfig.supportedLanguages || [],
137
+ defaultLanguage,
138
+ supportedLanguages,
117
139
  })
118
140
 
119
141
  app.all('*all', async (req, res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "1.11.2",
3
+ "version": "1.11.3",
4
4
  "description": "",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
@@ -27,14 +27,14 @@
27
27
  "@babel/eslint-parser": "^7.15.8",
28
28
  "@babel/preset-react": "^7.26.3",
29
29
  "@babel/register": "^7.25.9",
30
- "@ossy/connected-components": "^1.11.2",
31
- "@ossy/design-system": "^1.11.2",
32
- "@ossy/pages": "^1.11.2",
33
- "@ossy/router": "^1.11.2",
34
- "@ossy/router-react": "^1.11.2",
35
- "@ossy/sdk": "^1.11.2",
36
- "@ossy/sdk-react": "^1.11.2",
37
- "@ossy/themes": "^1.11.2",
30
+ "@ossy/connected-components": "^1.11.3",
31
+ "@ossy/design-system": "^1.11.3",
32
+ "@ossy/pages": "^1.11.3",
33
+ "@ossy/router": "^1.11.3",
34
+ "@ossy/router-react": "^1.11.3",
35
+ "@ossy/sdk": "^1.11.3",
36
+ "@ossy/sdk-react": "^1.11.3",
37
+ "@ossy/themes": "^1.11.3",
38
38
  "@rollup/plugin-alias": "^6.0.0",
39
39
  "@rollup/plugin-babel": "6.1.0",
40
40
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -67,5 +67,5 @@
67
67
  "README.md",
68
68
  "tsconfig.json"
69
69
  ],
70
- "gitHead": "3998c8b461e8b7317462c3d1d65b25b9454ba18a"
70
+ "gitHead": "c8b8fe48b3462ef9f7994894a1b17d844740dc11"
71
71
  }