@financial-times/dotcom-ui-bootstrap 7.3.1 → 7.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-ui-bootstrap",
3
- "version": "7.3.1",
3
+ "version": "7.3.2",
4
4
  "description": "",
5
5
  "main": "component.js",
6
6
  "browser": "browser.js",
@@ -30,7 +30,11 @@
30
30
  "react": "16.x || 17.x"
31
31
  },
32
32
  "files": [
33
- "dist/"
33
+ "dist/",
34
+ "src/",
35
+ "browser.js",
36
+ "component.js",
37
+ "server.js"
34
38
  ],
35
39
  "repository": {
36
40
  "type": "git",
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/node/server/index')
@@ -0,0 +1,16 @@
1
+ import subject from '../../server/formatConfigJSON'
2
+
3
+ describe('dotcom-ui-bootstrap/src/server/formatConfigJSON', () => {
4
+ it('returns a string', () => {
5
+ const result = subject([], [])
6
+ // NOTE: '' !== String('')
7
+ expect(typeof result === 'string').toBeTruthy()
8
+ })
9
+
10
+ it('returns a parseable JSON string', () => {
11
+ const result = JSON.parse(subject([], []))
12
+
13
+ expect(result.core).toBeInstanceOf(Array)
14
+ expect(result.enhanced).toBeInstanceOf(Array)
15
+ })
16
+ })
@@ -0,0 +1,10 @@
1
+ import subject from '../../server/getBootstrapJS'
2
+
3
+ describe('dotcom-ui-bootstrap/src/server/formatConfigJSON', () => {
4
+ it('returns the JS snippet', () => {
5
+ const result = subject()
6
+
7
+ expect(typeof result === 'string').toBeTruthy()
8
+ expect(result).toMatch(/isEnhancedBrowser/)
9
+ })
10
+ })
@@ -0,0 +1,30 @@
1
+ import React from 'react'
2
+ import { formatConfigJSON, getBootstrapJS } from '../server'
3
+
4
+ type TBootstrapProps = {
5
+ trackErrors?: boolean
6
+ coreScripts?: string[]
7
+ enhancedScripts?: string[]
8
+ }
9
+
10
+ function Bootstrap({ coreScripts, enhancedScripts, trackErrors }: TBootstrapProps) {
11
+ return (
12
+ <React.Fragment>
13
+ <script
14
+ type="application/json"
15
+ id="page-kit-bootstrap-config"
16
+ dangerouslySetInnerHTML={{ __html: formatConfigJSON(coreScripts, enhancedScripts, trackErrors) }}
17
+ />
18
+ <script dangerouslySetInnerHTML={{ __html: getBootstrapJS() }} />
19
+ </React.Fragment>
20
+ )
21
+ }
22
+
23
+ Bootstrap.defaultProps = {
24
+ trackErrors: true,
25
+ coreScripts: [],
26
+ enhancedScripts: []
27
+ }
28
+
29
+ export { Bootstrap }
30
+ export type { TBootstrapProps }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './components/Bootstrap'
@@ -0,0 +1,11 @@
1
+ export default function formatConfigJSON(
2
+ coreScripts: string[],
3
+ enhancedScripts: string[],
4
+ trackErrors: boolean = false
5
+ ): string {
6
+ return JSON.stringify({
7
+ trackErrors,
8
+ core: coreScripts,
9
+ enhanced: enhancedScripts
10
+ })
11
+ }
@@ -0,0 +1,8 @@
1
+ import fs from 'fs'
2
+ import findUp from 'find-up'
3
+
4
+ const bootstrapJS = String(fs.readFileSync(findUp.sync('lib/bootstrap.js', { cwd: __dirname })))
5
+
6
+ export default function getBootstrapJS(): string {
7
+ return bootstrapJS
8
+ }
@@ -0,0 +1,4 @@
1
+ import formatConfigJSON from './formatConfigJSON'
2
+ import getBootstrapJS from './getBootstrapJS'
3
+
4
+ export { formatConfigJSON, getBootstrapJS }