@financial-times/dotcom-server-react-jsx 2.6.1 → 4.1.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.
|
@@ -8,14 +8,15 @@ const react_1 = require("react");
|
|
|
8
8
|
const server_1 = require("react-dom/server");
|
|
9
9
|
const interopRequire_1 = __importDefault(require("./interopRequire"));
|
|
10
10
|
const defaultOptions = {
|
|
11
|
-
useStaticRendering: false
|
|
11
|
+
useStaticRendering: false,
|
|
12
|
+
includeDoctype: true
|
|
12
13
|
};
|
|
13
14
|
class PageKitReactJSX {
|
|
14
15
|
constructor(userOptions = {}) {
|
|
15
16
|
this.options = { ...defaultOptions, ...userOptions };
|
|
16
17
|
this.engine = this.renderView.bind(this);
|
|
17
18
|
}
|
|
18
|
-
async render(component, templateContext, includeDoctype) {
|
|
19
|
+
async render(component, templateContext, includeDoctype = this.options.includeDoctype) {
|
|
19
20
|
if (typeof component.getInitialProps === 'function') {
|
|
20
21
|
templateContext = await component.getInitialProps(templateContext);
|
|
21
22
|
}
|
|
@@ -30,7 +31,7 @@ class PageKitReactJSX {
|
|
|
30
31
|
if (typeof element !== 'function') {
|
|
31
32
|
throw Error(`The module ${viewPath} requires a default export.`);
|
|
32
33
|
}
|
|
33
|
-
const output = await this.render(element, templateContext
|
|
34
|
+
const output = await this.render(element, templateContext);
|
|
34
35
|
callback(null, output);
|
|
35
36
|
}
|
|
36
37
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/dotcom-server-react-jsx",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"clean:node_modules": "rm -rf node_modules",
|
|
13
13
|
"build:node": "npm run tsc -- --module commonjs --outDir ./dist/node",
|
|
14
14
|
"build": "npm run build:node",
|
|
15
|
-
"dev": "npm run clean:dist && npm run build:node -- --watch"
|
|
15
|
+
"dev": "npm run clean:dist && npm run build:node -- --watch",
|
|
16
|
+
"preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [],
|
|
18
19
|
"author": "",
|
|
@@ -22,12 +23,19 @@
|
|
|
22
23
|
"react-dom": "^16.8.6"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
|
-
"node": ">= 12.0.0"
|
|
26
|
+
"node": ">= 12.0.0",
|
|
27
|
+
"npm": "7.x || 8.x"
|
|
26
28
|
},
|
|
27
29
|
"repository": {
|
|
28
30
|
"type": "git",
|
|
29
31
|
"repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
|
|
30
32
|
"directory": "packages/dotcom-server-react-jsx"
|
|
31
33
|
},
|
|
32
|
-
"homepage": "https://github.com/Financial-Times/dotcom-page-kit/tree/HEAD/packages/dotcom-server-react-jsx"
|
|
34
|
+
"homepage": "https://github.com/Financial-Times/dotcom-page-kit/tree/HEAD/packages/dotcom-server-react-jsx",
|
|
35
|
+
"volta": {
|
|
36
|
+
"extends": "../../package.json"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"check-engine": "^1.10.1"
|
|
40
|
+
}
|
|
33
41
|
}
|
package/src/PageKitReactJSX.ts
CHANGED
|
@@ -4,11 +4,13 @@ import interopRequire from './interopRequire'
|
|
|
4
4
|
import { Renderable, RenderCallback } from './types'
|
|
5
5
|
|
|
6
6
|
export interface TPageKitReactJSXOptions {
|
|
7
|
-
useStaticRendering?: boolean
|
|
7
|
+
useStaticRendering?: boolean,
|
|
8
|
+
includeDoctype?: boolean
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const defaultOptions: TPageKitReactJSXOptions = {
|
|
11
|
-
useStaticRendering: false
|
|
12
|
+
useStaticRendering: false,
|
|
13
|
+
includeDoctype: true
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export class PageKitReactJSX {
|
|
@@ -20,7 +22,7 @@ export class PageKitReactJSX {
|
|
|
20
22
|
this.engine = this.renderView.bind(this)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
async render(component: Renderable, templateContext: any, includeDoctype
|
|
25
|
+
async render(component: Renderable, templateContext: any, includeDoctype: boolean = this.options.includeDoctype): Promise<string> {
|
|
24
26
|
if (typeof component.getInitialProps === 'function') {
|
|
25
27
|
templateContext = await component.getInitialProps(templateContext)
|
|
26
28
|
}
|
|
@@ -40,7 +42,7 @@ export class PageKitReactJSX {
|
|
|
40
42
|
throw Error(`The module ${viewPath} requires a default export.`)
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
const output = await this.render(element, templateContext
|
|
45
|
+
const output = await this.render(element, templateContext)
|
|
44
46
|
|
|
45
47
|
callback(null, output)
|
|
46
48
|
} catch (error) {
|