@ossy/app 1.5.0 → 1.7.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 +7 -0
- package/cli/render-page.task.js +10 -1
- package/cli/server.js +17 -7
- package/package.json +10 -10
package/cli/build.js
CHANGED
|
@@ -247,6 +247,13 @@ export function copyOssyAppRuntime ({ scriptDir, buildPath }) {
|
|
|
247
247
|
for (const name of ['server.js', 'proxy-internal.js']) {
|
|
248
248
|
fs.copyFileSync(path.join(scriptDir, name), path.join(buildPath, name))
|
|
249
249
|
}
|
|
250
|
+
const taskRuntimeFiles = fs
|
|
251
|
+
.readdirSync(scriptDir, { withFileTypes: true })
|
|
252
|
+
.filter((ent) => ent.isFile() && ent.name.endsWith('.task.js'))
|
|
253
|
+
.map((ent) => ent.name)
|
|
254
|
+
for (const name of taskRuntimeFiles) {
|
|
255
|
+
fs.copyFileSync(path.join(scriptDir, name), path.join(buildPath, name))
|
|
256
|
+
}
|
|
250
257
|
fs.copyFileSync(path.join(scriptDir, 'worker-entry.js'), path.join(buildPath, 'worker.js'))
|
|
251
258
|
fs.copyFileSync(path.join(scriptDir, 'worker-runtime.js'), path.join(buildPath, 'worker-runtime.js'))
|
|
252
259
|
}
|
package/cli/render-page.task.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import React, { cloneElement } from 'react'
|
|
2
2
|
import { prerenderToNodeStream } from 'react-dom/static'
|
|
3
3
|
|
|
4
|
+
/** Strips non-JSON content (e.g. React elements on `pages`) for the bootstrap script. */
|
|
5
|
+
export function appConfigForBootstrap (appConfig) {
|
|
6
|
+
if (!appConfig || typeof appConfig !== 'object') return appConfig
|
|
7
|
+
const pages = Array.isArray(appConfig.pages)
|
|
8
|
+
? appConfig.pages.map(({ id, path }) => ({ id, path }))
|
|
9
|
+
: appConfig.pages
|
|
10
|
+
return { ...appConfig, pages }
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
export const BuildPage = {
|
|
5
14
|
async handle ({ route, appConfig, isDevReloadEnabled }) {
|
|
6
15
|
const rootElement = cloneElement(route.element, appConfig)
|
|
@@ -10,7 +19,7 @@ export const BuildPage = {
|
|
|
10
19
|
|
|
11
20
|
const hydrateUrl = `/static/hydrate-${route.id}.js`
|
|
12
21
|
const { prelude } = await prerenderToNodeStream(rootElement, {
|
|
13
|
-
bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(appConfig)};${devReloadScript}`,
|
|
22
|
+
bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(appConfigForBootstrap(appConfig))};${devReloadScript}`,
|
|
14
23
|
bootstrapModules: [hydrateUrl],
|
|
15
24
|
})
|
|
16
25
|
|
package/cli/server.js
CHANGED
|
@@ -111,12 +111,18 @@ const Router = OssyRouter.of({
|
|
|
111
111
|
pages: [...apiRouteList, ...pageList]
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
function resolveAppConfig ({ req, buildTimeConfig }) {
|
|
114
|
+
function resolveAppConfig ({ req, buildTimeConfig, activeRouteId }) {
|
|
115
115
|
const userAppSettings = req.userAppSettings || {}
|
|
116
|
-
const pages = pageList.map((page) =>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
const pages = pageList.map((page) => {
|
|
117
|
+
const entry = {
|
|
118
|
+
id: page?.id,
|
|
119
|
+
path: page?.path,
|
|
120
|
+
}
|
|
121
|
+
if (activeRouteId != null && page?.id === activeRouteId) {
|
|
122
|
+
entry.element = page?.element
|
|
123
|
+
}
|
|
124
|
+
return entry
|
|
125
|
+
})
|
|
120
126
|
return {
|
|
121
127
|
...buildTimeConfig,
|
|
122
128
|
url: req.originalUrl,
|
|
@@ -141,13 +147,17 @@ app.all('*all', (req, res) => {
|
|
|
141
147
|
return
|
|
142
148
|
}
|
|
143
149
|
|
|
144
|
-
const appConfig = resolveAppConfig({ req, buildTimeConfig })
|
|
145
|
-
|
|
146
150
|
if (!route?.element) {
|
|
147
151
|
res.status(404).send('Not found')
|
|
148
152
|
return
|
|
149
153
|
}
|
|
150
154
|
|
|
155
|
+
const appConfig = resolveAppConfig({
|
|
156
|
+
req,
|
|
157
|
+
buildTimeConfig,
|
|
158
|
+
activeRouteId: route.id,
|
|
159
|
+
})
|
|
160
|
+
|
|
151
161
|
BuildPage.handle({ route, appConfig, isDevReloadEnabled })
|
|
152
162
|
.then(html => { res.send(html) })
|
|
153
163
|
.catch(err => { res.send(err) })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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.7.0",
|
|
31
|
+
"@ossy/design-system": "^1.7.0",
|
|
32
|
+
"@ossy/pages": "^1.7.0",
|
|
33
|
+
"@ossy/router": "^1.7.0",
|
|
34
|
+
"@ossy/router-react": "^1.7.0",
|
|
35
|
+
"@ossy/sdk": "^1.7.0",
|
|
36
|
+
"@ossy/sdk-react": "^1.7.0",
|
|
37
|
+
"@ossy/themes": "^1.7.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": "cb708db38cffe7bf0918e5ffb44bb0b13cf00d54"
|
|
71
71
|
}
|