@ossy/app 1.2.0 → 1.4.0
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/cli/build.js +23 -6
- package/cli/server.js +15 -3
- package/package.json +10 -10
package/cli/build.js
CHANGED
|
@@ -407,18 +407,21 @@ export function clientHydrateIdForPage (pageAbsPath, srcDir) {
|
|
|
407
407
|
* One client entry per page: imports only that page module and hydrates the document.
|
|
408
408
|
* Keeps the same `toPage` shape as `generatePagesModule` so SSR and client trees match.
|
|
409
409
|
*/
|
|
410
|
-
export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir }) {
|
|
410
|
+
export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir, pagesGeneratedPath }) {
|
|
411
411
|
const rel = relToGeneratedImport(stubAbsPath, pageAbsPath)
|
|
412
|
+
const pagesRel = relToGeneratedImport(stubAbsPath, pagesGeneratedPath)
|
|
412
413
|
const { id, path: routePath } = filePathToRoute(pageAbsPath, srcDir)
|
|
413
414
|
const pathLiteral = JSON.stringify(routePath)
|
|
414
415
|
const idLiteral = JSON.stringify(id)
|
|
415
416
|
return [
|
|
416
417
|
'// Generated by @ossy/app — do not edit',
|
|
417
418
|
'',
|
|
418
|
-
"import React, { cloneElement } from 'react'",
|
|
419
|
+
"import React, { cloneElement, createElement } from 'react'",
|
|
419
420
|
"import 'react-dom'",
|
|
420
421
|
"import { hydrateRoot } from 'react-dom/client'",
|
|
422
|
+
"import { App } from '@ossy/connected-components'",
|
|
421
423
|
`import * as _page from './${rel}'`,
|
|
424
|
+
`import pageRoutes from './${pagesRel}'`,
|
|
422
425
|
'',
|
|
423
426
|
'function toPage(mod, derived) {',
|
|
424
427
|
' const meta = mod?.metadata || {}',
|
|
@@ -431,9 +434,17 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
|
|
|
431
434
|
'',
|
|
432
435
|
`const _route = toPage(_page, { id: ${idLiteral}, path: ${pathLiteral} })`,
|
|
433
436
|
'const initialConfig = window.__INITIAL_APP_CONFIG__ || {}',
|
|
434
|
-
'const
|
|
435
|
-
'
|
|
436
|
-
|
|
437
|
+
'const pagesForApp = pageRoutes.map((p) =>',
|
|
438
|
+
' p.id === _route.id',
|
|
439
|
+
' ? { ...p, element: cloneElement(p.element, initialConfig) }',
|
|
440
|
+
' : p',
|
|
441
|
+
')',
|
|
442
|
+
'const rootTree = createElement(App, {',
|
|
443
|
+
' ...initialConfig,',
|
|
444
|
+
' url: window.location.href,',
|
|
445
|
+
' pages: pagesForApp,',
|
|
446
|
+
' includeDocumentShell: false,',
|
|
447
|
+
'})',
|
|
437
448
|
'hydrateRoot(document, rootTree)',
|
|
438
449
|
'',
|
|
439
450
|
].join('\n')
|
|
@@ -441,6 +452,7 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
|
|
|
441
452
|
|
|
442
453
|
/** Writes `hydrate-<id>.jsx` for each page; removes stale `hydrate-*` outputs in `ossyDir` first. */
|
|
443
454
|
export function writePageHydrateStubs (pageFiles, srcDir, ossyDir) {
|
|
455
|
+
const pagesGeneratedPath = path.join(ossyDir, OSSY_GEN_PAGES_BASENAME)
|
|
444
456
|
if (!fs.existsSync(ossyDir)) fs.mkdirSync(ossyDir, { recursive: true })
|
|
445
457
|
for (const ent of fs.readdirSync(ossyDir, { withFileTypes: true })) {
|
|
446
458
|
const full = path.join(ossyDir, ent.name)
|
|
@@ -467,7 +479,12 @@ export function writePageHydrateStubs (pageFiles, srcDir, ossyDir) {
|
|
|
467
479
|
fs.mkdirSync(path.dirname(stubPath), { recursive: true })
|
|
468
480
|
fs.writeFileSync(
|
|
469
481
|
stubPath,
|
|
470
|
-
generatePageHydrateModule({
|
|
482
|
+
generatePageHydrateModule({
|
|
483
|
+
pageAbsPath: f,
|
|
484
|
+
stubAbsPath: stubPath,
|
|
485
|
+
srcDir,
|
|
486
|
+
pagesGeneratedPath,
|
|
487
|
+
})
|
|
471
488
|
)
|
|
472
489
|
}
|
|
473
490
|
}
|
package/cli/server.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import url from 'url'
|
|
3
|
-
import React, { cloneElement } from 'react';
|
|
3
|
+
import React, { cloneElement, createElement } from 'react';
|
|
4
4
|
import express from 'express'
|
|
5
5
|
import morgan from 'morgan'
|
|
6
6
|
import { Router as OssyRouter } from '@ossy/router'
|
|
7
|
+
import { App } from '@ossy/connected-components'
|
|
7
8
|
import { prerenderToNodeStream } from 'react-dom/static'
|
|
8
9
|
import { ProxyInternal } from './proxy-internal.js'
|
|
9
10
|
import cookieParser from 'cookie-parser'
|
|
@@ -127,7 +128,7 @@ app.all('*all', (req, res) => {
|
|
|
127
128
|
|
|
128
129
|
const appConfig = {
|
|
129
130
|
...buildTimeConfig,
|
|
130
|
-
url: req.
|
|
131
|
+
url: req.originalUrl,
|
|
131
132
|
theme: userAppSettings.theme || buildTimeConfig.theme || 'light',
|
|
132
133
|
isAuthenticated: req.isAuthenticated || false,
|
|
133
134
|
workspaceId: userAppSettings.workspaceId || buildTimeConfig.workspaceId,
|
|
@@ -141,7 +142,18 @@ app.all('*all', (req, res) => {
|
|
|
141
142
|
return
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
const pagesForApp = pageList.map((p) =>
|
|
146
|
+
p.id === route.id
|
|
147
|
+
? { ...p, element: cloneElement(p.element, appConfig) }
|
|
148
|
+
: p
|
|
149
|
+
)
|
|
150
|
+
const rootElement = createElement(App, {
|
|
151
|
+
...appConfig,
|
|
152
|
+
pages: pagesForApp,
|
|
153
|
+
includeDocumentShell: false,
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
prerenderHtmlDocument(rootElement, appConfig, route.id)
|
|
145
157
|
.then(html => { res.send(html) })
|
|
146
158
|
.catch(err => { res.send(err) })
|
|
147
159
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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.
|
|
31
|
-
"@ossy/design-system": "^1.
|
|
32
|
-
"@ossy/pages": "^1.
|
|
33
|
-
"@ossy/router": "^1.
|
|
34
|
-
"@ossy/router-react": "^1.
|
|
35
|
-
"@ossy/sdk": "^1.
|
|
36
|
-
"@ossy/sdk-react": "^1.
|
|
37
|
-
"@ossy/themes": "^1.
|
|
30
|
+
"@ossy/connected-components": "^1.4.0",
|
|
31
|
+
"@ossy/design-system": "^1.4.0",
|
|
32
|
+
"@ossy/pages": "^1.4.0",
|
|
33
|
+
"@ossy/router": "^1.4.0",
|
|
34
|
+
"@ossy/router-react": "^1.4.0",
|
|
35
|
+
"@ossy/sdk": "^1.4.0",
|
|
36
|
+
"@ossy/sdk-react": "^1.4.0",
|
|
37
|
+
"@ossy/themes": "^1.4.0",
|
|
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": "
|
|
70
|
+
"gitHead": "69e80ed4e43a04263df106e0f504c6d2fb55e0fb"
|
|
71
71
|
}
|