@ossy/app 1.1.0 → 1.3.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 +40 -18
- package/cli/dev.js +9 -8
- package/cli/server.js +17 -5
- package/package.json +10 -10
package/cli/build.js
CHANGED
|
@@ -59,6 +59,8 @@ export const OSSY_GEN_TASKS_BASENAME = 'tasks.generated.js'
|
|
|
59
59
|
export const OSSY_PAGES_SERVER_BUNDLE = 'pages.bundle.js'
|
|
60
60
|
export const OSSY_API_SERVER_BUNDLE = 'api.bundle.js'
|
|
61
61
|
export const OSSY_TASKS_SERVER_BUNDLE = 'tasks.bundle.js'
|
|
62
|
+
export const OSSY_CONFIG_RUNTIME_BASENAME = 'config.runtime.js'
|
|
63
|
+
export const OSSY_MIDDLEWARE_RUNTIME_BASENAME = 'middleware.runtime.js'
|
|
62
64
|
|
|
63
65
|
/** Per-page client entries: `hydrate-<pageId>.jsx` under `.ossy/` */
|
|
64
66
|
const HYDRATE_STUB_PREFIX = 'hydrate-'
|
|
@@ -221,20 +223,30 @@ export async function bundleOssyNodeEntry ({ inputPath, outputFile, nodeEnv }) {
|
|
|
221
223
|
}
|
|
222
224
|
|
|
223
225
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
+
* Re-exports the resolved config and middleware via `file:` URLs so `src/config.js` can keep
|
|
227
|
+
* relative imports (copying those files into `build/` would break them).
|
|
226
228
|
*/
|
|
227
|
-
export function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
229
|
+
export function writeAppRuntimeShims ({ configSourcePath, middlewareSourcePath, ossyDir }) {
|
|
230
|
+
const cfgHref = url.pathToFileURL(path.resolve(configSourcePath)).href
|
|
231
|
+
const mwHref = url.pathToFileURL(path.resolve(middlewareSourcePath)).href
|
|
232
|
+
fs.writeFileSync(
|
|
233
|
+
path.join(ossyDir, OSSY_CONFIG_RUNTIME_BASENAME),
|
|
234
|
+
`// Generated by @ossy/app — do not edit\nexport { default } from '${cfgHref}'\n`
|
|
235
|
+
)
|
|
236
|
+
fs.writeFileSync(
|
|
237
|
+
path.join(ossyDir, OSSY_MIDDLEWARE_RUNTIME_BASENAME),
|
|
238
|
+
`// Generated by @ossy/app — do not edit\nexport { default } from '${mwHref}'\n`
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Copies framework runtime into `build/`: server, worker entry, proxy.
|
|
244
|
+
* Config/middleware load via `./.ossy/config.runtime.js` and `middleware.runtime.js`.
|
|
245
|
+
*/
|
|
246
|
+
export function copyOssyAppRuntime ({ scriptDir, buildPath }) {
|
|
233
247
|
for (const name of ['server.js', 'proxy-internal.js']) {
|
|
234
248
|
fs.copyFileSync(path.join(scriptDir, name), path.join(buildPath, name))
|
|
235
249
|
}
|
|
236
|
-
fs.copyFileSync(middlewareSourcePath, path.join(buildPath, 'middleware.js'))
|
|
237
|
-
fs.copyFileSync(configSourcePath, path.join(buildPath, 'config.js'))
|
|
238
250
|
fs.copyFileSync(path.join(scriptDir, 'worker-entry.js'), path.join(buildPath, 'worker.js'))
|
|
239
251
|
fs.copyFileSync(path.join(scriptDir, 'worker-runtime.js'), path.join(buildPath, 'worker-runtime.js'))
|
|
240
252
|
}
|
|
@@ -403,10 +415,12 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
|
|
|
403
415
|
return [
|
|
404
416
|
'// Generated by @ossy/app — do not edit',
|
|
405
417
|
'',
|
|
406
|
-
"import React, { cloneElement } from 'react'",
|
|
418
|
+
"import React, { cloneElement, createElement } from 'react'",
|
|
407
419
|
"import 'react-dom'",
|
|
408
420
|
"import { hydrateRoot } from 'react-dom/client'",
|
|
421
|
+
"import { App } from '@ossy/connected-components'",
|
|
409
422
|
`import * as _page from './${rel}'`,
|
|
423
|
+
`import pageRoutes from './${OSSY_GEN_PAGES_BASENAME}'`,
|
|
410
424
|
'',
|
|
411
425
|
'function toPage(mod, derived) {',
|
|
412
426
|
' const meta = mod?.metadata || {}',
|
|
@@ -419,9 +433,17 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
|
|
|
419
433
|
'',
|
|
420
434
|
`const _route = toPage(_page, { id: ${idLiteral}, path: ${pathLiteral} })`,
|
|
421
435
|
'const initialConfig = window.__INITIAL_APP_CONFIG__ || {}',
|
|
422
|
-
'const
|
|
423
|
-
'
|
|
424
|
-
|
|
436
|
+
'const pagesForApp = pageRoutes.map((p) =>',
|
|
437
|
+
' p.id === _route.id',
|
|
438
|
+
' ? { ...p, element: cloneElement(p.element, initialConfig) }',
|
|
439
|
+
' : p',
|
|
440
|
+
')',
|
|
441
|
+
'const rootTree = createElement(App, {',
|
|
442
|
+
' ...initialConfig,',
|
|
443
|
+
' url: window.location.href,',
|
|
444
|
+
' pages: pagesForApp,',
|
|
445
|
+
' includeDocumentShell: false,',
|
|
446
|
+
'})',
|
|
425
447
|
'hydrateRoot(document, rootTree)',
|
|
426
448
|
'',
|
|
427
449
|
].join('\n')
|
|
@@ -658,12 +680,12 @@ export const build = async (cliArgs) => {
|
|
|
658
680
|
nodeEnv: 'production',
|
|
659
681
|
})
|
|
660
682
|
|
|
661
|
-
|
|
662
|
-
scriptDir,
|
|
663
|
-
buildPath,
|
|
664
|
-
middlewareSourcePath,
|
|
683
|
+
writeAppRuntimeShims({
|
|
665
684
|
configSourcePath,
|
|
685
|
+
middlewareSourcePath,
|
|
686
|
+
ossyDir,
|
|
666
687
|
})
|
|
688
|
+
copyOssyAppRuntime({ scriptDir, buildPath })
|
|
667
689
|
|
|
668
690
|
const clientPlugins = createOssyClientRollupPlugins({
|
|
669
691
|
nodeEnv: 'production',
|
package/cli/dev.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
resetOssyBuildDir,
|
|
12
12
|
bundleOssyNodeEntry,
|
|
13
13
|
copyOssyAppRuntime,
|
|
14
|
+
writeAppRuntimeShims,
|
|
14
15
|
createOssyAppBundlePlugins,
|
|
15
16
|
createOssyClientRollupPlugins,
|
|
16
17
|
writePageHydrateStubs,
|
|
@@ -109,12 +110,12 @@ export const dev = async (cliArgs) => {
|
|
|
109
110
|
outputFile: tasksBundlePath,
|
|
110
111
|
nodeEnv: 'development',
|
|
111
112
|
})
|
|
112
|
-
|
|
113
|
-
scriptDir,
|
|
114
|
-
buildPath,
|
|
115
|
-
middlewareSourcePath,
|
|
113
|
+
writeAppRuntimeShims({
|
|
116
114
|
configSourcePath,
|
|
115
|
+
middlewareSourcePath,
|
|
116
|
+
ossyDir,
|
|
117
117
|
})
|
|
118
|
+
copyOssyAppRuntime({ scriptDir, buildPath })
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
await runNodeBundles()
|
|
@@ -233,12 +234,12 @@ export const dev = async (cliArgs) => {
|
|
|
233
234
|
console.log(`[@ossy/app][dev] Built in ${event.duration}ms`)
|
|
234
235
|
}
|
|
235
236
|
if (event.code === 'END') {
|
|
236
|
-
|
|
237
|
-
scriptDir,
|
|
238
|
-
buildPath,
|
|
239
|
-
middlewareSourcePath,
|
|
237
|
+
writeAppRuntimeShims({
|
|
240
238
|
configSourcePath,
|
|
239
|
+
middlewareSourcePath,
|
|
240
|
+
ossyDir,
|
|
241
241
|
})
|
|
242
|
+
copyOssyAppRuntime({ scriptDir, buildPath })
|
|
242
243
|
scheduleRestart()
|
|
243
244
|
}
|
|
244
245
|
})
|
package/cli/server.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
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'
|
|
10
11
|
|
|
11
12
|
import pages from './.ossy/pages.bundle.js'
|
|
12
13
|
import ApiRoutes from './.ossy/api.bundle.js'
|
|
13
|
-
import Middleware from '
|
|
14
|
-
import configModule from '
|
|
14
|
+
import Middleware from './.ossy/middleware.runtime.js'
|
|
15
|
+
import configModule from './.ossy/config.runtime.js'
|
|
15
16
|
|
|
16
17
|
const buildTimeConfig = configModule?.default ?? configModule ?? {}
|
|
17
18
|
|
|
@@ -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.3.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.3.0",
|
|
31
|
+
"@ossy/design-system": "^1.3.0",
|
|
32
|
+
"@ossy/pages": "^1.3.0",
|
|
33
|
+
"@ossy/router": "^1.3.0",
|
|
34
|
+
"@ossy/router-react": "^1.3.0",
|
|
35
|
+
"@ossy/sdk": "^1.3.0",
|
|
36
|
+
"@ossy/sdk-react": "^1.3.0",
|
|
37
|
+
"@ossy/themes": "^1.3.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": "15e5a4ab14895064b6281eec4daf1cea3340806e"
|
|
71
71
|
}
|