From 08e8cc90f116c36513ab10f18fd596d03a1222a9 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 14:34:29 -0500 Subject: [PATCH 1/6] Move `lib/DOMPropertyConfig.js` to `lib/property-config.js` Tidy and refactor code. --- lib/DOMPropertyConfig.js | 25 ------------------------- lib/attributes-to-props.js | 9 +++++---- lib/property-config.js | 24 +++++++++++++++++++----- 3 files changed, 24 insertions(+), 34 deletions(-) delete mode 100644 lib/DOMPropertyConfig.js diff --git a/lib/DOMPropertyConfig.js b/lib/DOMPropertyConfig.js deleted file mode 100644 index a243b295..00000000 --- a/lib/DOMPropertyConfig.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -/** - * Module dependencies. - */ -var HTMLDOMPropertyConfig; -var SVGDOMPropertyConfig; - -// HTML and SVG DOM Property Config -// moved to `react-dom` in v15.4.x -try { - HTMLDOMPropertyConfig = require('react-dom/lib/HTMLDOMPropertyConfig'); - SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig'); -} catch (error) { - HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); - SVGDOMPropertyConfig = require('react/lib/SVGDOMPropertyConfig'); -} - -/** - * Export config. - */ -module.exports = { - HTMLDOMPropertyConfig: HTMLDOMPropertyConfig, - SVGDOMPropertyConfig: SVGDOMPropertyConfig -}; diff --git a/lib/attributes-to-props.js b/lib/attributes-to-props.js index 36ba9759..d9734570 100644 --- a/lib/attributes-to-props.js +++ b/lib/attributes-to-props.js @@ -3,9 +3,10 @@ /** * Module dependencies. */ -var HTMLDOMPropertyConfig = require('./DOMPropertyConfig').HTMLDOMPropertyConfig; var utilities = require('./utilities'); var propertyConfig = require('./property-config'); +var config = propertyConfig.config; +var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute; /** * Make attributes compatible with React props. @@ -24,20 +25,20 @@ function attributesToProps(attributes) { propertyValue = attributes[propertyName]; // custom attributes (`data-` and `aria-`) - if (HTMLDOMPropertyConfig.isCustomAttribute(propertyName)) { + if (isCustomAttribute(propertyName)) { props[propertyName] = propertyValue; continue; } // make HTML DOM attribute/property consistent with React attribute/property - reactProperty = propertyConfig.html[propertyName.toLowerCase()]; + reactProperty = config.html[propertyName.toLowerCase()]; if (reactProperty) { props[reactProperty] = propertyValue; continue; } // make SVG DOM attribute/property consistent with React attribute/property - reactProperty = propertyConfig.svg[propertyName]; + reactProperty = config.svg[propertyName]; if (reactProperty) { props[reactProperty] = propertyValue; } diff --git a/lib/property-config.js b/lib/property-config.js index df97cdb8..b27168d9 100644 --- a/lib/property-config.js +++ b/lib/property-config.js @@ -4,9 +4,19 @@ * Module dependencies. */ var utilities = require('./utilities'); -var DOMPropertyConfig = require('./DOMPropertyConfig'); -var HTMLDOMPropertyConfig = DOMPropertyConfig.HTMLDOMPropertyConfig; -var SVGDOMPropertyConfig = DOMPropertyConfig.SVGDOMPropertyConfig; + +// HTML and SVG DOM Property Configs +// originally in `react/lib/` but moved to `react-dom/lib/` in 15.4 +var HTMLDOMPropertyConfig; +var SVGDOMPropertyConfig; + +try { + HTMLDOMPropertyConfig = require('react-dom/lib/HTMLDOMPropertyConfig'); + SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig'); +} catch (error) { + HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); + SVGDOMPropertyConfig = require('react/lib/SVGDOMPropertyConfig'); +} var config = { html: {}, @@ -54,6 +64,10 @@ for (propertyName in SVGDOMPropertyConfig.Properties) { } /** - * Export React property config. + * Export React property configs. */ -module.exports = config; +module.exports = { + config: config, + HTMLDOMPropertyConfig: HTMLDOMPropertyConfig, + SVGDOMPropertyConfig: SVGDOMPropertyConfig +}; From 63ef15a0be16629269012dcadef3afbb4a90a607 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 14:54:05 -0500 Subject: [PATCH 2/6] Remove unused property in browser field in package.json `./lib/html-to-dom-server.js` has been replaced with `html-dom-parser` package. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 9aa20ec5..3d95b86c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "react": ">=0.14" }, "browser": { - "./lib/html-to-dom-server.js": false, "htmlparser2/lib/Parser": false, "domhandler": false }, From 3ee6e787b5ef98d7a518c1f74ea3315125f26bd9 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 15:05:52 -0500 Subject: [PATCH 3/6] Resolve webpack error by reverting back to react@15.3 Remove the try-catch and require the DOM property configs from `react/lib/`. > ERROR in ./lib/property-config.js > Module not found: Error: Cannot resolve module > 'react/lib/HTMLDOMPropertyConfig' --- lib/property-config.js | 13 ++----------- package.json | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/property-config.js b/lib/property-config.js index b27168d9..6c180549 100644 --- a/lib/property-config.js +++ b/lib/property-config.js @@ -6,17 +6,8 @@ var utilities = require('./utilities'); // HTML and SVG DOM Property Configs -// originally in `react/lib/` but moved to `react-dom/lib/` in 15.4 -var HTMLDOMPropertyConfig; -var SVGDOMPropertyConfig; - -try { - HTMLDOMPropertyConfig = require('react-dom/lib/HTMLDOMPropertyConfig'); - SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig'); -} catch (error) { - HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); - SVGDOMPropertyConfig = require('react/lib/SVGDOMPropertyConfig'); -} +var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); +var SVGDOMPropertyConfig = require('react/lib/SVGDOMPropertyConfig'); var config = { html: {}, diff --git a/package.json b/package.json index 3d95b86c..66178ed4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "webpack": "^1.13.2" }, "peerDependencies": { - "react": ">=0.14" + "react": "<=15.3" }, "browser": { "htmlparser2/lib/Parser": false, From f6a67343d9fe46c7b29b5e504f916bf808118deb Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 15:23:34 -0500 Subject: [PATCH 4/6] Create npm script `clean` that removes `dist/` directory Rename `build` to `build-unmin` and update `prepublish` to run `clean` before the build scripts. --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 66178ed4..2317f8ca 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ "author": "Mark ", "main": "index.js", "scripts": { - "build": "NODE_ENV=development webpack index.js dist/html-react-parser.js", + "build-unmin": "NODE_ENV=development webpack index.js dist/html-react-parser.js", "build-min": "NODE_ENV=production webpack -p index.js dist/html-react-parser.min.js", - "prepublish": "npm run build && npm run build-min", + "clean": "rm -rf dist", + "prepublish": "npm run clean && npm run build-unmin && npm run build-min", "test": "mocha", "lint": "eslint index.js \"lib/**\" \"test/**\"", "cover": "istanbul cover _mocha -- -R spec \"test/**/*\"", From d490528e588679b2dc54fe611a10372b5135e348 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 15:31:10 -0500 Subject: [PATCH 5/6] Update README installation to account for react <15.4 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 332a607a..22b5f9d6 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ Parser('

Hello, world!

'); $ npm install html-react-parser ``` +Or if you're using react <15.4: + +```sh +$ npm install html-react-parser@0.2 +``` + [CDN](https://unpkg.com/html-react-parser/): ```html From dfb86c20b58c73fee009f7fdbf45a46ce8d20bab Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Nov 2016 15:39:25 -0500 Subject: [PATCH 6/6] Fix travis tests by setting react@15.3 in devDependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2317f8ca..00ec0f16 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "istanbul": "^0.4.5", "jsdomify": "^2.1.0", "mocha": "^3.0.2", - "react": "*", - "react-dom": "*", + "react": "15.3", + "react-dom": "15.3", "webpack": "^1.13.2" }, "peerDependencies": {