Skip to content

Commit e80a69c

Browse files
build: upgrade domhandler to 5.0.3 and htmlparser2 to 8.0.1
BREAKING CHANGE: bump domhandler from 4 to 5, htmlparser2 from 7 to 8 domhandler 4.3.1 → 5.0.3 htmlparser2 7.2.0 → 8.0.1
1 parent 165405a commit e80a69c

File tree

11 files changed

+57
-76
lines changed

11 files changed

+57
-76
lines changed

karma.conf.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,22 @@ module.exports = config => {
1111

1212
// list of files / patterns to load in the browser
1313
files: [
14-
'dist/htmlparser2.js',
15-
'lib/**/*.js',
16-
'node_modules/domelementtype/**/*.js',
17-
'node_modules/domelementtype/**/*.json',
18-
'node_modules/domhandler/lib/node.js',
14+
'dist/*.js',
15+
'lib/client/constants.js',
16+
'lib/server/utilities.js',
1917
'test/cases/html.js',
2018
'test/client/*.js',
2119
'test/helpers/*.js'
2220
],
2321

2422
// list of files / patterns to exclude
25-
exclude: [
26-
'lib/server/html-to-dom.js',
27-
'node_modules/domelementtype/lib/esm/*.js'
28-
],
23+
exclude: [],
2924

3025
// preprocess matching files before serving them to the browser
3126
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3227
preprocessors: {
33-
'dist/**/*.js': ['commonjs'],
28+
'dist/*.js': ['commonjs'],
3429
'lib/**/*.js': ['commonjs'],
35-
'node_modules/domelementtype/**/*.js': ['commonjs'],
36-
'node_modules/domelementtype/**/*.json': ['commonjs'],
37-
'node_modules/domhandler/lib/node.js': ['commonjs'],
3830
'test/**/*.js': ['commonjs']
3931
},
4032

lib/client/constants.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* SVG elements are case-sensitive.
33
*
4-
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
4+
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z}
55
*/
6-
var CASE_SENSITIVE_TAG_NAMES = [
6+
exports.CASE_SENSITIVE_TAG_NAMES = [
77
'animateMotion',
88
'animateTransform',
99
'clipPath',
@@ -36,7 +36,3 @@ var CASE_SENSITIVE_TAG_NAMES = [
3636
'radialGradient',
3737
'textPath'
3838
];
39-
40-
module.exports = {
41-
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
42-
};

lib/client/utilities.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
var domhandler = require('domhandler');
12
var constants = require('./constants');
2-
var domhandler = require('domhandler/lib/node');
33

44
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
55

@@ -19,8 +19,8 @@ for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
1919
/**
2020
* Gets case-sensitive tag name.
2121
*
22-
* @param {string} tagName - Tag name in lowercase.
23-
* @return {string|undefined} - Case-sensitive tag name.
22+
* @param {string} tagName - Tag name in lowercase.
23+
* @returns {string|undefined} - Case-sensitive tag name.
2424
*/
2525
function getCaseSensitiveTagName(tagName) {
2626
return caseSensitiveTagNamesMap[tagName];
@@ -29,8 +29,8 @@ function getCaseSensitiveTagName(tagName) {
2929
/**
3030
* Formats DOM attributes to a hash map.
3131
*
32-
* @param {NamedNodeMap} attributes - List of attributes.
33-
* @return {object} - Map of attribute name to value.
32+
* @param {NamedNodeMap} attributes - List of attributes.
33+
* @returns {object} - Map of attribute name to value.
3434
*/
3535
function formatAttributes(attributes) {
3636
var result = {};
@@ -47,8 +47,8 @@ function formatAttributes(attributes) {
4747
* Corrects the tag name if it is case-sensitive (SVG).
4848
* Otherwise, returns the lowercase tag name (HTML).
4949
*
50-
* @param {string} tagName - Lowercase tag name.
51-
* @return {string} - Formatted tag name.
50+
* @param {string} tagName - Lowercase tag name.
51+
* @returns {string} - Formatted tag name.
5252
*/
5353
function formatTagName(tagName) {
5454
tagName = tagName.toLowerCase();
@@ -62,10 +62,10 @@ function formatTagName(tagName) {
6262
/**
6363
* Transforms DOM nodes to `domhandler` nodes.
6464
*
65-
* @param {NodeList} nodes - DOM nodes.
66-
* @param {Element|null} [parent=null] - Parent node.
67-
* @param {string} [directive] - Directive.
68-
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
65+
* @param {NodeList} nodes - DOM nodes.
66+
* @param {Element|null} [parent=null] - Parent node.
67+
* @param {string} [directive] - Directive.
68+
* @returns {Array<Comment|Element|ProcessingInstruction|Text>}
6969
*/
7070
function formatDOM(nodes, parent, directive) {
7171
parent = parent || null;
@@ -129,7 +129,5 @@ function formatDOM(nodes, parent, directive) {
129129
return result;
130130
}
131131

132-
module.exports = {
133-
formatAttributes: formatAttributes,
134-
formatDOM: formatDOM
135-
};
132+
exports.formatAttributes = formatAttributes;
133+
exports.formatDOM = formatDOM;

lib/server/html-to-dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Parser = require('htmlparser2/lib/Parser').Parser;
1+
var Parser = require('htmlparser2').Parser;
22
var DomHandler = require('domhandler').DomHandler;
33

44
var unsetRootParent = require('./utilities').unsetRootParent;

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"size-limit": "size-limit",
2222
"test": "run-s test:server test:client",
2323
"test:client": "npm run test:client:watch -- --single-run",
24-
"test:client:build": "webpack --config webpack.test.config.js",
24+
"test:client:build": "NODE_ENV=test npm run build",
2525
"test:client:watch": "npm run test:client:build && karma start",
2626
"test:module": "node --experimental-modules test/module/index.mjs",
2727
"test:server": "nyc mocha test/server"
@@ -42,8 +42,8 @@
4242
"pojo"
4343
],
4444
"dependencies": {
45-
"domhandler": "4.3.1",
46-
"htmlparser2": "7.2.0"
45+
"domhandler": "5.0.3",
46+
"htmlparser2": "8.0.1"
4747
},
4848
"devDependencies": {
4949
"@commitlint/cli": "17.0.3",
@@ -76,9 +76,7 @@
7676
"rollup-plugin-terser": "7.0.2",
7777
"sinon": "14.0.0",
7878
"size-limit": "7.0.8",
79-
"typescript": "4.7.4",
80-
"webpack": "5.73.0",
81-
"webpack-cli": "4.10.0"
79+
"typescript": "4.7.4"
8280
},
8381
"files": [
8482
"/dist",

rollup.config.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import resolve from '@rollup/plugin-node-resolve';
33
import { terser } from 'rollup-plugin-terser';
44

55
/**
6-
* Build rollup config for development (default) or production (minify = true).
6+
* Build rollup config for development, test, or production.
77
*
8-
* @param {Boolean} [minify=false]
9-
* @return {Object}
8+
* @param {boolean} [minify=false]
109
*/
1110
const getConfig = (minify = false) => ({
1211
input: 'index.js',
@@ -19,4 +18,19 @@ const getConfig = (minify = false) => ({
1918
plugins: [commonjs(), resolve({ browser: true }), minify && terser()]
2019
});
2120

22-
export default [getConfig(), getConfig(true)];
21+
const configs = [getConfig(), getConfig(true)];
22+
23+
if (process.env.NODE_ENV === 'test') {
24+
configs.push({
25+
input: 'node_modules/htmlparser2',
26+
output: {
27+
file: 'dist/htmlparser2.js',
28+
format: 'umd',
29+
name: 'htmlparser2',
30+
sourcemap: true
31+
},
32+
plugins: [commonjs(), resolve({ browser: true })]
33+
});
34+
}
35+
36+
export default configs;

test/client/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
var assert = window.chai.assert;
21
var htmlCases = require('../cases/html');
32
var serverParser = require('../../dist/htmlparser2').parseDOM;
4-
var clientParser = require('../../lib/client/html-to-dom');
3+
var clientParser = require('../../dist/html-dom-parser');
54
var helpers = require('../helpers');
65

6+
var assert = window.assert;
7+
78
describe('client parser', function () {
89
helpers.throwErrors(assert, clientParser);
910
helpers.runTests(assert, clientParser, serverParser, htmlCases);

test/client/utilities.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/server/client.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { expect } = require('chai');
2+
const utilities = require('../../lib/client/utilities');
3+
4+
describe('client utilities', function () {
5+
describe('formatDOM', function () {
6+
it('continues loop when nodeType is undefined', function () {
7+
expect(utilities.formatDOM([{ nodeType: undefined }])).to.deep.equal([]);
8+
});
9+
});
10+
});

test/server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const html = '<html>';
3131

3232
describe('server parser', () => {
3333
// before
34-
mock('htmlparser2/lib/Parser', { Parser });
34+
mock('htmlparser2', { Parser });
3535
mock('domhandler', { DomHandler });
3636
const parse = require('../..');
3737

0 commit comments

Comments
 (0)