@ossy/app 1.4.0 → 1.4.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.
Files changed (3) hide show
  1. package/cli/build.js +10 -27
  2. package/cli/server.js +2 -14
  3. package/package.json +10 -10
package/cli/build.js CHANGED
@@ -159,8 +159,8 @@ export function createOssyAppBundlePlugins ({ nodeEnv }) {
159
159
  }),
160
160
  json(),
161
161
  nodeExternals({
162
- deps: true,
163
- devDeps: false,
162
+ deps: false,
163
+ devDeps: true,
164
164
  peerDeps: true,
165
165
  packagePath: path.join(process.cwd(), 'package.json'),
166
166
  }),
@@ -185,8 +185,8 @@ export function createOssyClientRollupPlugins ({ nodeEnv, copyPublicFrom, buildP
185
185
  }),
186
186
  json(),
187
187
  nodeExternals({
188
- deps: true,
189
- devDeps: false,
188
+ deps: false,
189
+ devDeps: true,
190
190
  peerDeps: true,
191
191
  packagePath: path.join(process.cwd(), 'package.json'),
192
192
  }),
@@ -407,21 +407,18 @@ 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, pagesGeneratedPath }) {
410
+ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir }) {
411
411
  const rel = relToGeneratedImport(stubAbsPath, pageAbsPath)
412
- const pagesRel = relToGeneratedImport(stubAbsPath, pagesGeneratedPath)
413
412
  const { id, path: routePath } = filePathToRoute(pageAbsPath, srcDir)
414
413
  const pathLiteral = JSON.stringify(routePath)
415
414
  const idLiteral = JSON.stringify(id)
416
415
  return [
417
416
  '// Generated by @ossy/app — do not edit',
418
417
  '',
419
- "import React, { cloneElement, createElement } from 'react'",
418
+ "import React, { cloneElement } from 'react'",
420
419
  "import 'react-dom'",
421
420
  "import { hydrateRoot } from 'react-dom/client'",
422
- "import { App } from '@ossy/connected-components'",
423
421
  `import * as _page from './${rel}'`,
424
- `import pageRoutes from './${pagesRel}'`,
425
422
  '',
426
423
  'function toPage(mod, derived) {',
427
424
  ' const meta = mod?.metadata || {}',
@@ -434,17 +431,9 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir, p
434
431
  '',
435
432
  `const _route = toPage(_page, { id: ${idLiteral}, path: ${pathLiteral} })`,
436
433
  'const initialConfig = window.__INITIAL_APP_CONFIG__ || {}',
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
- '})',
434
+ 'const rootTree = _route?.element',
435
+ ' ? cloneElement(_route.element, initialConfig)',
436
+ " : React.createElement('p', null, 'Not found')",
448
437
  'hydrateRoot(document, rootTree)',
449
438
  '',
450
439
  ].join('\n')
@@ -452,7 +441,6 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir, p
452
441
 
453
442
  /** Writes `hydrate-<id>.jsx` for each page; removes stale `hydrate-*` outputs in `ossyDir` first. */
454
443
  export function writePageHydrateStubs (pageFiles, srcDir, ossyDir) {
455
- const pagesGeneratedPath = path.join(ossyDir, OSSY_GEN_PAGES_BASENAME)
456
444
  if (!fs.existsSync(ossyDir)) fs.mkdirSync(ossyDir, { recursive: true })
457
445
  for (const ent of fs.readdirSync(ossyDir, { withFileTypes: true })) {
458
446
  const full = path.join(ossyDir, ent.name)
@@ -479,12 +467,7 @@ export function writePageHydrateStubs (pageFiles, srcDir, ossyDir) {
479
467
  fs.mkdirSync(path.dirname(stubPath), { recursive: true })
480
468
  fs.writeFileSync(
481
469
  stubPath,
482
- generatePageHydrateModule({
483
- pageAbsPath: f,
484
- stubAbsPath: stubPath,
485
- srcDir,
486
- pagesGeneratedPath,
487
- })
470
+ generatePageHydrateModule({ pageAbsPath: f, stubAbsPath: stubPath, srcDir })
488
471
  )
489
472
  }
490
473
  }
package/cli/server.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import path from 'path';
2
2
  import url from 'url'
3
- import React, { cloneElement, createElement } from 'react';
3
+ import React, { cloneElement } 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'
8
7
  import { prerenderToNodeStream } from 'react-dom/static'
9
8
  import { ProxyInternal } from './proxy-internal.js'
10
9
  import cookieParser from 'cookie-parser'
@@ -142,18 +141,7 @@ app.all('*all', (req, res) => {
142
141
  return
143
142
  }
144
143
 
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)
144
+ prerenderHtmlDocument(cloneElement(route.element, appConfig), appConfig, route.id)
157
145
  .then(html => { res.send(html) })
158
146
  .catch(err => { res.send(err) })
159
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
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.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",
30
+ "@ossy/connected-components": "^1.4.1",
31
+ "@ossy/design-system": "^1.4.1",
32
+ "@ossy/pages": "^1.4.1",
33
+ "@ossy/router": "^1.4.1",
34
+ "@ossy/router-react": "^1.4.1",
35
+ "@ossy/sdk": "^1.4.1",
36
+ "@ossy/sdk-react": "^1.4.1",
37
+ "@ossy/themes": "^1.4.1",
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": "69e80ed4e43a04263df106e0f504c6d2fb55e0fb"
70
+ "gitHead": "ffccd09f5b13bddbf48e2b88ebb8b9d1e02c43f1"
71
71
  }