@sequencemedia/react-render 2.3.51 → 2.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.
package/babel.config.cjs CHANGED
@@ -12,5 +12,7 @@ module.exports = {
12
12
  ],
13
13
  '@babel/react'
14
14
  ],
15
- ignore: [/node_modules\/(?!@sequencemedia\/react-render)/]
15
+ ignore: [
16
+ /node_modules\/(?!@sequencemedia\/react-render)/
17
+ ]
16
18
  }
@@ -0,0 +1,147 @@
1
+ import globals from 'globals'
2
+ import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
3
+ import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
4
+ import babelParser from '@babel/eslint-parser'
5
+ import typescriptParser from '@typescript-eslint/parser'
6
+ import reactPlugin from 'eslint-plugin-react'
7
+
8
+ const reactParserOptions = {
9
+ ecmaFeatures: {
10
+ jsx: true
11
+ }
12
+ }
13
+
14
+ const reactPlugins = {
15
+ react: reactPlugin
16
+ }
17
+
18
+ const reactRules = {
19
+ 'no-unused-vars': [
20
+ 'error',
21
+ {
22
+ varsIgnorePattern: 'React'
23
+ }
24
+ ],
25
+ quotes: [
26
+ 'error',
27
+ 'single'
28
+ ],
29
+ 'jsx-quotes': [
30
+ 'error',
31
+ 'prefer-single'
32
+ ],
33
+ 'react/jsx-indent': [
34
+ 'error',
35
+ 2,
36
+ {
37
+ checkAttributes: true,
38
+ indentLogicalExpressions: true
39
+ }
40
+ ]
41
+ }
42
+
43
+ const reactSettings = {
44
+ react: {
45
+ version: 'detect'
46
+ }
47
+ }
48
+
49
+ export default [
50
+ {
51
+ ignores: [
52
+ 'coverage'
53
+ ]
54
+ },
55
+ /**
56
+ * React config for all `jsx` files
57
+ */
58
+ {
59
+ ...reactPlugin.configs.flat.recommended,
60
+ settings: {
61
+ ...reactSettings
62
+ }
63
+ },
64
+ /**
65
+ * Standard config
66
+ */
67
+ standard({
68
+ files: [
69
+ '**/*.{mjs,cjs,mts,cts}'
70
+ ],
71
+ ignores: [
72
+ 'src',
73
+ 'test'
74
+ ],
75
+ languageOptions: {
76
+ globals: {
77
+ ...globals.node
78
+ }
79
+ }
80
+ }),
81
+ standard({
82
+ files: [
83
+ 'src/**/*.{mjs,cjs,mts,cts}'
84
+ ],
85
+ languageOptions: {
86
+ globals: {
87
+ ...globals.node
88
+ }
89
+ }
90
+ }),
91
+ standard({
92
+ files: [
93
+ 'test/**/*.{mjs,cjs,mts,cts}'
94
+ ],
95
+ languageOptions: {
96
+ globals: {
97
+ ...globals.mocha
98
+ }
99
+ }
100
+ }),
101
+ /**
102
+ * Standard config for all `jsx` files
103
+ */
104
+ standard({
105
+ files: [
106
+ 'src/**/*.jsx'
107
+ ],
108
+ languageOptions: {
109
+ parser: babelParser,
110
+ parserOptions: {
111
+ ...reactParserOptions,
112
+ project: null
113
+ },
114
+ globals: {
115
+ ...globals.browser
116
+ }
117
+ },
118
+ plugins: {
119
+ ...reactPlugins
120
+ }, // @ts-expect-error Storybook
121
+ rules: {
122
+ ...reactRules
123
+ },
124
+ settings: {
125
+ ...reactSettings
126
+ }
127
+ }),
128
+ /**
129
+ * TypeScript config
130
+ */
131
+ typescript({
132
+ files: [
133
+ '**/*.{mts,cts}'
134
+ ],
135
+ languageOptions: {
136
+ parser: typescriptParser,
137
+ parserOptions: {
138
+ projectService: true,
139
+ project: 'tsconfig.json'
140
+ },
141
+ globals: {
142
+ ...globals.node,
143
+ ReactRenderTypes: 'readonly'
144
+ }
145
+ }
146
+ })
147
+ ]
package/index.d.mts ADDED
@@ -0,0 +1,10 @@
1
+ import type React from 'react'
2
+
3
+ declare global {
4
+ namespace ReactRenderTypes {
5
+ export type ComponentType = () => React.JSX.Element
6
+ export type PropsType = Record<string, unknown>
7
+ }
8
+ }
9
+
10
+ export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/react-render",
3
- "version": "2.3.51",
3
+ "version": "2.4.1",
4
4
  "description": "React Render",
5
5
  "keywords": [
6
6
  "React",
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "main": "./src/index.mjs",
13
13
  "type": "module",
14
+ "types": "./index.d.mts",
14
15
  "author": {
15
16
  "name": "Jonathan Perry for Sequence Media Limited",
16
17
  "email": "jonathanperry@sequencemedia.net",
@@ -25,7 +26,7 @@
25
26
  "url": "git://github.com/sequencemedia/react-render.git"
26
27
  },
27
28
  "scripts": {
28
- "lint": "eslint . --ext .mjs,.cjs,.jsx",
29
+ "lint": "eslint",
29
30
  "lint:fix": "npm run lint -- --fix",
30
31
  "prepare": "husky",
31
32
  "test": "NODE_ENV=test mocha test --recursive --verbose"
@@ -35,17 +36,26 @@
35
36
  "debug": "^4.4.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@babel/core": "^7.26.9",
39
- "@babel/eslint-parser": "^7.26.8",
39
+ "@babel/core": "^7.26.10",
40
+ "@babel/eslint-parser": "^7.26.10",
40
41
  "@babel/preset-env": "^7.26.9",
41
42
  "@babel/preset-react": "^7.26.3",
42
43
  "@babel/register": "^7.25.9",
44
+ "@sequencemedia/eslint-config-standard": "^0.2.42",
45
+ "@sequencemedia/eslint-config-typescript": "^0.1.60",
43
46
  "@sequencemedia/sinon-chai": "^0.0.131",
47
+ "@types/babel__register": "^7.17.3",
48
+ "@types/debug": "^4.1.12",
49
+ "@types/prop-types": "^15.7.14",
50
+ "@types/react": "^19.0.10",
51
+ "@types/react-dom": "^19.0.4",
52
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
53
+ "@typescript-eslint/parser": "^8.26.1",
44
54
  "chai": "^5.2.0",
45
55
  "core-js": "^3.41.0",
46
- "eslint": "8.57.1",
47
- "eslint-config-standard": "^17.1.0",
56
+ "eslint": "^9.22.0",
48
57
  "eslint-plugin-react": "^7.37.4",
58
+ "globals": "^16.0.0",
49
59
  "husky": "^9.1.7",
50
60
  "mocha": "^11.1.0",
51
61
  "prop-types": "^15.8.1",
@@ -0,0 +1,5 @@
1
+ export {
2
+ renderToString,
3
+ renderToStaticMarkup,
4
+ render
5
+ } from '#react-render'
@@ -0,0 +1,5 @@
1
+ export {
2
+ renderToString,
3
+ renderToStaticMarkup,
4
+ render
5
+ } from '#react-render'
package/src/index.mjs CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @typedef {ReactRenderTypes.ComponentType} ComponentType
3
+ * @typedef {ReactRenderTypes.PropsType} PropsType
4
+ */
5
+
1
6
  import debug from 'debug'
2
7
 
3
8
  import {
@@ -10,22 +15,34 @@ const log = debug('@sequencemedia/react-render')
10
15
  log('`react-render` is awake')
11
16
 
12
17
  /**
13
- * @param {React.ReactElement} Component
14
- * @param {Object.<string, any>} props
15
- * @returns {string}
18
+ * @param {ComponentType} Component
19
+ * @param {PropsType} props
20
+ * @returns {string}
16
21
  */
17
- export const renderToString = (Component, props = {}) => getReactDOMServerRenderToString(Component, props)
22
+ export function renderToString (Component, props = {}) {
23
+ return (
24
+ getReactDOMServerRenderToString(Component, props)
25
+ )
26
+ }
18
27
 
19
28
  /**
20
- * @param {React.ReactElement} Component
21
- * @param {Object.<string, any>} props
22
- * @returns {string}
29
+ * @param {ComponentType} Component
30
+ * @param {PropsType} props
31
+ * @returns {string}
23
32
  */
24
- export const renderToStaticMarkup = (Component, props = {}) => getReactDOMServerRenderToStaticMarkup(Component, props)
33
+ export function renderToStaticMarkup (Component, props = {}) {
34
+ return (
35
+ getReactDOMServerRenderToStaticMarkup(Component, props)
36
+ )
37
+ }
25
38
 
26
39
  /**
27
- * @param {React.ReactElement} Component
28
- * @param {Object.<string, any>} props
29
- * @returns {Promise<string>}
40
+ * @param {ComponentType} Component
41
+ * @param {PropsType} props
42
+ * @returns {string}
30
43
  */
31
- export const render = async (Component, props = {}) => getReactDOMServerRenderToString(Component, props)
44
+ export function render (Component, props = {}) {
45
+ return (
46
+ getReactDOMServerRenderToString(Component, props)
47
+ )
48
+ }
@@ -1,5 +1,7 @@
1
1
  require('@babel/register')({
2
- ignore: [/node_modules\/(?!@sequencemedia\/react-render)/]
2
+ ignore: [
3
+ /node_modules\/(?!@sequencemedia\/react-render)/
4
+ ]
3
5
  })
4
6
 
5
7
  const {
@@ -0,0 +1,4 @@
1
+ export {
2
+ getReactDOMServerRenderToString,
3
+ getReactDOMServerRenderToStaticMarkup
4
+ } from '#react-render/react-dom-server'
@@ -0,0 +1,8 @@
1
+ declare module '#react-render/react-dom-server' {
2
+ type ComponentType = ReactRenderTypes.ComponentType
3
+ type PropsType = ReactRenderTypes.PropsType
4
+
5
+ export function getReactDOMServerRenderToString (Component: ComponentType, props: PropsType): string
6
+
7
+ export function getReactDOMServerRenderToStaticMarkup (Component: ComponentType, props: PropsType): string
8
+ }
@@ -1,3 +1,16 @@
1
+ /**
2
+ * @typedef {ReactRenderTypes.ComponentType} ComponentType
3
+ * @typedef {ReactRenderTypes.PropsType} PropsType
4
+ *
5
+ * @typedef {{
6
+ * props: PropsType
7
+ * }} PropsException
8
+ *
9
+ * @typedef {{
10
+ * e: unknown
11
+ * }} Exception
12
+ */
13
+
1
14
  import debug from 'debug'
2
15
  import React from 'react'
3
16
  import ReactDOMServer from 'react-dom/server'
@@ -8,16 +21,20 @@ const log = debug('@sequencemedia/react-render')
8
21
  log('`react-render` is awake')
9
22
 
10
23
  /**
11
- * @param {Error} e
12
- * @param {{props: Object.<string, any>}} data
13
- * @returns A boom object
24
+ * @param {Error} e
25
+ * @param {PropsException | Exception} data
26
+ * @returns A boom object
14
27
  */
15
- const badImplementation = (e, data) => Boom.boomify(e, { statusCode: 500, message: 'Rendering exception', data })
28
+ function badImplementation (e, data) {
29
+ return (
30
+ Boom.boomify(e, { statusCode: 500, message: 'Rendering exception', data })
31
+ )
32
+ }
16
33
 
17
34
  /**
18
- * @param {React.ReactElement} Component
19
- * @param {Object.<string, any>} props
20
- * @returns {string}
35
+ * @param {ComponentType} Component
36
+ * @param {PropsType} props
37
+ * @returns {string}
21
38
  */
22
39
  export function getReactDOMServerRenderToString (Component, props) {
23
40
  try {
@@ -27,16 +44,15 @@ export function getReactDOMServerRenderToString (Component, props) {
27
44
  />
28
45
  )
29
46
  } catch (e) {
30
- log(e)
31
-
32
- throw badImplementation(e, { props })
47
+ if (e instanceof Error) throw badImplementation(e, { props })
48
+ throw badImplementation(new Error('Exception'), { e })
33
49
  }
34
50
  }
35
51
 
36
52
  /**
37
- * @param {React.ReactElement} Component
38
- * @param {Object.<string, any>} props
39
- * @returns {string}
53
+ * @param {ComponentType} Component
54
+ * @param {PropsType} props
55
+ * @returns {string}
40
56
  */
41
57
  export function getReactDOMServerRenderToStaticMarkup (Component, props) {
42
58
  try {
@@ -46,8 +62,7 @@ export function getReactDOMServerRenderToStaticMarkup (Component, props) {
46
62
  />
47
63
  )
48
64
  } catch (e) {
49
- log(e)
50
-
51
- throw badImplementation(e, { props })
65
+ if (e instanceof Error) throw badImplementation(e, { props })
66
+ throw badImplementation(new Error('Exception'), { e })
52
67
  }
53
68
  }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "NodeNext",
4
+ "target": "ESNext",
5
+ "allowJs": true,
6
+ "checkJs": true,
7
+ "noEmit": true,
8
+ "strict": true,
9
+ "jsx": "react",
10
+ "paths": {
11
+ "#react-render": [
12
+ "./src/index.mjs"
13
+ ],
14
+ "#react-render/react-dom-server": [
15
+ "./src/react-dom-server.cjs"
16
+ ]
17
+ }
18
+ },
19
+ "include": [
20
+ "."
21
+ ],
22
+ "exclude": [
23
+ "test"
24
+ ]
25
+ }