@sequencemedia/react-router-render 2.4.56 → 2.5.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-router-render)/]
15
+ ignore: [
16
+ /node_modules\/(?!@sequencemedia\/react-router-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
+ ReactRouterRenderTypes: 'readonly'
144
+ }
145
+ }
146
+ })
147
+ ]
package/index.d.mts ADDED
@@ -0,0 +1,13 @@
1
+ import type React from 'react'
2
+ import type {
3
+ StaticRouterProps
4
+ } from 'react-router'
5
+
6
+ declare global {
7
+ namespace ReactRouterRenderTypes {
8
+ export type RouterPropsType = StaticRouterProps
9
+ export type RoutesType = React.ReactNode
10
+ }
11
+ }
12
+
13
+ export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/react-router-render",
3
- "version": "2.4.56",
3
+ "version": "2.5.1",
4
4
  "description": "Sync/async isomorphic render of React apps with React Router",
5
5
  "keywords": [
6
6
  "React",
@@ -13,6 +13,7 @@
13
13
  ],
14
14
  "main": "./src/index.mjs",
15
15
  "type": "module",
16
+ "types": "./index.d.mts",
16
17
  "author": {
17
18
  "name": "Jonathan Perry for Sequence Media Limited",
18
19
  "email": "jonathanperry@sequencemedia.net",
@@ -27,7 +28,7 @@
27
28
  "url": "git://github.com/sequencemedia/react-router-render.git"
28
29
  },
29
30
  "scripts": {
30
- "lint": "eslint . --ext .mjs,.cjs,.jsx",
31
+ "lint": "eslint",
31
32
  "lint:fix": "npm run lint -- --fix",
32
33
  "prepare": "husky",
33
34
  "test": "NODE_ENV=test mocha test --recursive --verbose"
@@ -37,17 +38,29 @@
37
38
  "debug": "^4.4.0"
38
39
  },
39
40
  "devDependencies": {
40
- "@babel/core": "^7.26.9",
41
- "@babel/eslint-parser": "^7.26.8",
41
+ "@babel/core": "^7.26.10",
42
+ "@babel/eslint-parser": "^7.26.10",
42
43
  "@babel/preset-env": "^7.26.9",
43
44
  "@babel/preset-react": "^7.26.3",
44
45
  "@babel/register": "^7.25.9",
46
+ "@sequencemedia/eslint-config-standard": "^0.2.42",
47
+ "@sequencemedia/eslint-config-typescript": "^0.1.60",
45
48
  "@sequencemedia/sinon-chai": "^0.0.131",
49
+ "@types/babel__register": "^7.17.3",
50
+ "@types/debug": "^4.1.12",
51
+ "@types/prop-types": "^15.7.14",
52
+ "@types/react": "^19.0.10",
53
+ "@types/react-dom": "^19.0.4",
54
+ "@types/react-redux": "^7.1.34",
55
+ "@types/react-router": "^5.1.20",
56
+ "@types/redux": "^3.6.0",
57
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
58
+ "@typescript-eslint/parser": "^8.26.1",
46
59
  "chai": "^5.2.0",
47
60
  "core-js": "^3.41.0",
48
- "eslint": "8.57.1",
49
- "eslint-config-standard": "^17.1.0",
61
+ "eslint": "^9.22.0",
50
62
  "eslint-plugin-react": "^7.37.4",
63
+ "globals": "^16.0.0",
51
64
  "husky": "^9.1.7",
52
65
  "mocha": "^11.1.0",
53
66
  "prop-types": "^15.8.1",
@@ -0,0 +1,5 @@
1
+ export {
2
+ renderToString,
3
+ renderToStaticMarkup,
4
+ render
5
+ } from '#react-router-render'
@@ -0,0 +1,5 @@
1
+ export {
2
+ renderToString,
3
+ renderToStaticMarkup,
4
+ render
5
+ } from '#react-router-render'
package/src/index.mjs CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @typedef {ReactRouterRenderTypes.RouterPropsType} RouterPropsType
3
+ * @typedef {ReactRouterRenderTypes.RoutesType} RoutesType
4
+ */
5
+
1
6
  import debug from 'debug'
2
7
 
3
8
  import Boom from '@hapi/boom'
@@ -12,17 +17,21 @@ const log = debug('@sequencemedia/react-redux-render')
12
17
  log('`react-redux-render` is awake')
13
18
 
14
19
  /**
15
- * @param {Object.<string, any>} data
16
- * @returns A boom object
20
+ * @param {RouterPropsType} data
21
+ * @returns A boom object
17
22
  */
18
- const notFound = (data) => Boom.notFound('Routing exception', data)
23
+ function notFound (data) {
24
+ return (
25
+ Boom.notFound('Routing exception', data)
26
+ )
27
+ }
19
28
 
20
29
  /**
21
- * @param {Object.<string, any>} routerProps
22
- * @param {Object.<string, any>} routes
23
- * @returns {string}
30
+ * @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
31
+ * @param {RoutesType} routes
32
+ * @returns {string}
24
33
  */
25
- export function renderToString ({ location, context = {}, ...router } = {}, routes = {}) {
34
+ export function renderToString ({ location, context = {}, ...router }, routes) {
26
35
  const routerProps = { ...router, location, context }
27
36
  const string = getReactDOMServerRenderToString(routerProps, routes)
28
37
  if (string) return string
@@ -30,11 +39,11 @@ export function renderToString ({ location, context = {}, ...router } = {}, rout
30
39
  }
31
40
 
32
41
  /**
33
- * @param {Object.<string, any>} routerProps
34
- * @param {Object.<string, any>} routes
35
- * @returns {string}
42
+ * @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
43
+ * @param {RoutesType} routes
44
+ * @returns {string}
36
45
  */
37
- export function renderToStaticMarkup ({ location, context = {}, ...router } = {}, routes = {}) {
46
+ export function renderToStaticMarkup ({ location, context = {}, ...router }, routes) {
38
47
  const routerProps = { ...router, location, context }
39
48
  const string = getReactDOMServerRenderToStaticMarkup(routerProps, routes)
40
49
  if (string) return string
@@ -42,11 +51,11 @@ export function renderToStaticMarkup ({ location, context = {}, ...router } = {}
42
51
  }
43
52
 
44
53
  /**
45
- * @param {Object.<string, any>} routerProps
46
- * @param {Object.<string, any>} routes
47
- * @returns {Promise<string>}
54
+ * @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
55
+ * @param {RoutesType} routes
56
+ * @returns {string}
48
57
  */
49
- export async function render ({ location, context = {}, ...router } = {}, routes = {}) {
58
+ export function render ({ location, context = {}, ...router }, routes) {
50
59
  const routerProps = { ...router, location, context }
51
60
  const string = getReactDOMServerRenderToString(routerProps, routes)
52
61
  if (string) return string
@@ -1,5 +1,7 @@
1
1
  require('@babel/register')({
2
- ignore: [/node_modules\/(?!@sequencemedia\/react-router-render)/]
2
+ ignore: [
3
+ /node_modules\/(?!@sequencemedia\/react-router-render)/
4
+ ]
3
5
  })
4
6
 
5
7
  const {
@@ -0,0 +1,4 @@
1
+ export {
2
+ getReactDOMServerRenderToString,
3
+ getReactDOMServerRenderToStaticMarkup
4
+ } from '#react-router-render/react-dom-server'
@@ -0,0 +1,8 @@
1
+ declare module '#react-router-render/react-dom-server' {
2
+ type RouterPropsType = ReactRouterRenderTypes.RouterPropsType
3
+ type RoutesType = ReactRouterRenderTypes.RoutesType
4
+
5
+ export function getReactDOMServerRenderToString (routerProps: RouterPropsType, routes: RoutesType): string
6
+
7
+ export function getReactDOMServerRenderToStaticMarkup (routerProps: RouterPropsType, routes: RoutesType): string
8
+ }
@@ -1,3 +1,16 @@
1
+ /**
2
+ * @typedef {ReactRouterRenderTypes.RouterPropsType} RouterPropsType
3
+ * @typedef {ReactRouterRenderTypes.RoutesType} RoutesType
4
+ *
5
+ * @typedef {{
6
+ * props: RouterPropsType
7
+ * }} RouterPropsException
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'
@@ -11,16 +24,20 @@ const log = debug('@sequencemedia/react-redux-render')
11
24
  log('`react-redux-render` is awake')
12
25
 
13
26
  /**
14
- * @param {Error} e
15
- * @param {{props: Object.<string, any>}} data
16
- * @returns A boom object
27
+ * @param {Error} e
28
+ * @param {RouterPropsException | Exception} data
29
+ * @returns A boom object
17
30
  */
18
- const badImplementation = (e, data) => Boom.boomify(e, { statusCode: 500, message: 'Rendering exception', data })
31
+ function badImplementation (e, data) {
32
+ return (
33
+ Boom.boomify(e, { statusCode: 500, message: 'Rendering exception', data })
34
+ )
35
+ }
19
36
 
20
37
  /**
21
- * @param {Object.<string, any>} routerProps
22
- * @param {Object.<string, any>} routes
23
- * @returns {string}
38
+ * @param {RouterPropsType} routerProps
39
+ * @param {RoutesType} routes
40
+ * @returns {string}
24
41
  */
25
42
  export function getReactDOMServerRenderToString (routerProps, routes) {
26
43
  try {
@@ -30,16 +47,15 @@ export function getReactDOMServerRenderToString (routerProps, routes) {
30
47
  </Router>
31
48
  )
32
49
  } catch (e) {
33
- log(e)
34
-
35
- throw badImplementation(e, routerProps)
50
+ if (e instanceof Error) throw badImplementation(e, { props: routerProps })
51
+ throw badImplementation(new Error('Exception'), { e })
36
52
  }
37
53
  }
38
54
 
39
55
  /**
40
- * @param {Object.<string, any>} routerProps
41
- * @param {Object.<string, any>} routes
42
- * @returns {string}
56
+ * @param {RouterPropsType} routerProps
57
+ * @param {RoutesType} routes
58
+ * @returns {string}
43
59
  */
44
60
  export function getReactDOMServerRenderToStaticMarkup (routerProps, routes) {
45
61
  try {
@@ -49,8 +65,7 @@ export function getReactDOMServerRenderToStaticMarkup (routerProps, routes) {
49
65
  </Router>
50
66
  )
51
67
  } catch (e) {
52
- log(e)
53
-
54
- throw badImplementation(e, routerProps)
68
+ if (e instanceof Error) throw badImplementation(e, { props: routerProps })
69
+ throw badImplementation(new Error('Exception'), { e })
55
70
  }
56
71
  }
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-router-render": [
12
+ "./src/index.mjs"
13
+ ],
14
+ "#react-router-render/react-dom-server": [
15
+ "./src/react-dom-server.cjs"
16
+ ]
17
+ }
18
+ },
19
+ "include": [
20
+ "."
21
+ ],
22
+ "exclude": [
23
+ "test"
24
+ ]
25
+ }