@financial-times/dotcom-server-react-jsx 7.3.0 → 7.3.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.
- package/dist/node/PageKitReactJSX.d.ts +12 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/interopRequire.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +2013 -0
- package/package.json +6 -4
- package/src/PageKitReactJSX.ts +0 -52
- package/src/index.ts +0 -1
- package/src/interopRequire.ts +0 -4
- package/src/types.d.ts +0 -35
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/dotcom-server-react-jsx",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"tsc": "../../node_modules/.bin/tsc --incremental",
|
|
10
9
|
"clean": "npm run clean:dist && npm run clean:node_modules",
|
|
11
10
|
"clean:dist": "rm -rf dist",
|
|
12
11
|
"clean:node_modules": "rm -rf node_modules",
|
|
13
|
-
"build:node": "
|
|
12
|
+
"build:node": "tsc",
|
|
14
13
|
"build": "npm run build:node",
|
|
15
14
|
"dev": "npm run clean:dist && npm run build:node -- --watch",
|
|
16
15
|
"preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
|
|
@@ -26,6 +25,9 @@
|
|
|
26
25
|
"node": ">= 14.0.0",
|
|
27
26
|
"npm": "7.x || 8.x"
|
|
28
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/"
|
|
30
|
+
],
|
|
29
31
|
"repository": {
|
|
30
32
|
"type": "git",
|
|
31
33
|
"repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
|
|
@@ -38,4 +40,4 @@
|
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"check-engine": "^1.10.1"
|
|
40
42
|
}
|
|
41
|
-
}
|
|
43
|
+
}
|
package/src/PageKitReactJSX.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react'
|
|
2
|
-
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
|
|
3
|
-
import interopRequire from './interopRequire'
|
|
4
|
-
import { Renderable, RenderCallback } from './types'
|
|
5
|
-
|
|
6
|
-
export interface TPageKitReactJSXOptions {
|
|
7
|
-
useStaticRendering?: boolean,
|
|
8
|
-
includeDoctype?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const defaultOptions: TPageKitReactJSXOptions = {
|
|
12
|
-
useStaticRendering: false,
|
|
13
|
-
includeDoctype: true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class PageKitReactJSX {
|
|
17
|
-
public options: TPageKitReactJSXOptions
|
|
18
|
-
public engine: Function
|
|
19
|
-
|
|
20
|
-
constructor(userOptions: TPageKitReactJSXOptions = {}) {
|
|
21
|
-
this.options = { ...defaultOptions, ...userOptions }
|
|
22
|
-
this.engine = this.renderView.bind(this)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async render(component: Renderable, templateContext: any, includeDoctype: boolean = this.options.includeDoctype): Promise<string> {
|
|
26
|
-
if (typeof component.getInitialProps === 'function') {
|
|
27
|
-
templateContext = await component.getInitialProps(templateContext)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const outputPrefix = includeDoctype ? '<!DOCTYPE html>' : ''
|
|
31
|
-
const renderMethod = this.options.useStaticRendering ? renderToStaticMarkup : renderToString
|
|
32
|
-
const outputHTML = renderMethod(createElement(component, templateContext))
|
|
33
|
-
|
|
34
|
-
return outputPrefix + outputHTML
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async renderView(viewPath: string, templateContext: any, callback: RenderCallback): Promise<void> {
|
|
38
|
-
try {
|
|
39
|
-
const element = interopRequire(viewPath) as Renderable
|
|
40
|
-
|
|
41
|
-
if (typeof element !== 'function') {
|
|
42
|
-
throw Error(`The module ${viewPath} requires a default export.`)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const output = await this.render(element, templateContext)
|
|
46
|
-
|
|
47
|
-
callback(null, output)
|
|
48
|
-
} catch (error) {
|
|
49
|
-
callback(error)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PageKitReactJSX'
|
package/src/interopRequire.ts
DELETED
package/src/types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
// Extend @types/react to support optional additional .getInitialProps() method.
|
|
4
|
-
// This is adapted from the @types/next:
|
|
5
|
-
// <https://github.com/DefinitelyTyped/DefinitelyTyped/blob/HEAD/types/next/index.d.ts>
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Next.js style counterpart of React.FunctionComponent.
|
|
9
|
-
*
|
|
10
|
-
* @template P Component props.
|
|
11
|
-
* @template C Context passed to getInitialProps.
|
|
12
|
-
*/
|
|
13
|
-
type NextFunctionComponent<P = {}, C = {}> = React.FunctionComponent<P> & NextStaticLifecycle<P, C>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Next.js style counterpart of React.ComponentClass.
|
|
17
|
-
*
|
|
18
|
-
* @template P Component props.
|
|
19
|
-
* @template C Context passed to getInitialProps.
|
|
20
|
-
*/
|
|
21
|
-
type NextComponentClass<P = {}, C = {}> = React.ComponentClass<P> & NextStaticLifecycle<P, C>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Next.js style lifecycle methods.
|
|
25
|
-
*
|
|
26
|
-
* @template P Props returned from getInitialProps and passed to the component.
|
|
27
|
-
* @template C Context passed to getInitialProps.
|
|
28
|
-
*/
|
|
29
|
-
interface NextStaticLifecycle<P, C> {
|
|
30
|
-
getInitialProps?: (templateContext: C) => Promise<P> | P
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type Renderable = NextComponentClass | NextFunctionComponent
|
|
34
|
-
|
|
35
|
-
export type RenderCallback = (error?: Error, output?: string) => any
|