Skip to content

Commit

Permalink
build: upgrade domhandler to 5.0.3 and htmlparser2 to 8.0.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
remarkablemark committed Jul 5, 2022
1 parent 165405a commit e80a69c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 76 deletions.
18 changes: 5 additions & 13 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,22 @@ module.exports = config => {

// list of files / patterns to load in the browser
files: [
'dist/htmlparser2.js',
'lib/**/*.js',
'node_modules/domelementtype/**/*.js',
'node_modules/domelementtype/**/*.json',
'node_modules/domhandler/lib/node.js',
'dist/*.js',
'lib/client/constants.js',
'lib/server/utilities.js',
'test/cases/html.js',
'test/client/*.js',
'test/helpers/*.js'
],

// list of files / patterns to exclude
exclude: [
'lib/server/html-to-dom.js',
'node_modules/domelementtype/lib/esm/*.js'
],
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'dist/**/*.js': ['commonjs'],
'dist/*.js': ['commonjs'],
'lib/**/*.js': ['commonjs'],
'node_modules/domelementtype/**/*.js': ['commonjs'],
'node_modules/domelementtype/**/*.json': ['commonjs'],
'node_modules/domhandler/lib/node.js': ['commonjs'],
'test/**/*.js': ['commonjs']
},

Expand Down
8 changes: 2 additions & 6 deletions lib/client/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* SVG elements are case-sensitive.
*
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z}
*/
var CASE_SENSITIVE_TAG_NAMES = [
exports.CASE_SENSITIVE_TAG_NAMES = [
'animateMotion',
'animateTransform',
'clipPath',
Expand Down Expand Up @@ -36,7 +36,3 @@ var CASE_SENSITIVE_TAG_NAMES = [
'radialGradient',
'textPath'
];

module.exports = {
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
};
28 changes: 13 additions & 15 deletions lib/client/utilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var domhandler = require('domhandler');
var constants = require('./constants');
var domhandler = require('domhandler/lib/node');

var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;

Expand All @@ -19,8 +19,8 @@ for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
/**
* Gets case-sensitive tag name.
*
* @param {string} tagName - Tag name in lowercase.
* @return {string|undefined} - Case-sensitive tag name.
* @param {string} tagName - Tag name in lowercase.
* @returns {string|undefined} - Case-sensitive tag name.
*/
function getCaseSensitiveTagName(tagName) {
return caseSensitiveTagNamesMap[tagName];
Expand All @@ -29,8 +29,8 @@ function getCaseSensitiveTagName(tagName) {
/**
* Formats DOM attributes to a hash map.
*
* @param {NamedNodeMap} attributes - List of attributes.
* @return {object} - Map of attribute name to value.
* @param {NamedNodeMap} attributes - List of attributes.
* @returns {object} - Map of attribute name to value.
*/
function formatAttributes(attributes) {
var result = {};
Expand All @@ -47,8 +47,8 @@ function formatAttributes(attributes) {
* Corrects the tag name if it is case-sensitive (SVG).
* Otherwise, returns the lowercase tag name (HTML).
*
* @param {string} tagName - Lowercase tag name.
* @return {string} - Formatted tag name.
* @param {string} tagName - Lowercase tag name.
* @returns {string} - Formatted tag name.
*/
function formatTagName(tagName) {
tagName = tagName.toLowerCase();
Expand All @@ -62,10 +62,10 @@ function formatTagName(tagName) {
/**
* Transforms DOM nodes to `domhandler` nodes.
*
* @param {NodeList} nodes - DOM nodes.
* @param {Element|null} [parent=null] - Parent node.
* @param {string} [directive] - Directive.
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
* @param {NodeList} nodes - DOM nodes.
* @param {Element|null} [parent=null] - Parent node.
* @param {string} [directive] - Directive.
* @returns {Array<Comment|Element|ProcessingInstruction|Text>}
*/
function formatDOM(nodes, parent, directive) {
parent = parent || null;
Expand Down Expand Up @@ -129,7 +129,5 @@ function formatDOM(nodes, parent, directive) {
return result;
}

module.exports = {
formatAttributes: formatAttributes,
formatDOM: formatDOM
};
exports.formatAttributes = formatAttributes;
exports.formatDOM = formatDOM;
2 changes: 1 addition & 1 deletion lib/server/html-to-dom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Parser = require('htmlparser2/lib/Parser').Parser;
var Parser = require('htmlparser2').Parser;
var DomHandler = require('domhandler').DomHandler;

var unsetRootParent = require('./utilities').unsetRootParent;
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"size-limit": "size-limit",
"test": "run-s test:server test:client",
"test:client": "npm run test:client:watch -- --single-run",
"test:client:build": "webpack --config webpack.test.config.js",
"test:client:build": "NODE_ENV=test npm run build",
"test:client:watch": "npm run test:client:build && karma start",
"test:module": "node --experimental-modules test/module/index.mjs",
"test:server": "nyc mocha test/server"
Expand All @@ -42,8 +42,8 @@
"pojo"
],
"dependencies": {
"domhandler": "4.3.1",
"htmlparser2": "7.2.0"
"domhandler": "5.0.3",
"htmlparser2": "8.0.1"
},
"devDependencies": {
"@commitlint/cli": "17.0.3",
Expand Down Expand Up @@ -76,9 +76,7 @@
"rollup-plugin-terser": "7.0.2",
"sinon": "14.0.0",
"size-limit": "7.0.8",
"typescript": "4.7.4",
"webpack": "5.73.0",
"webpack-cli": "4.10.0"
"typescript": "4.7.4"
},
"files": [
"/dist",
Expand Down
22 changes: 18 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';

/**
* Build rollup config for development (default) or production (minify = true).
* Build rollup config for development, test, or production.
*
* @param {Boolean} [minify=false]
* @return {Object}
* @param {boolean} [minify=false]
*/
const getConfig = (minify = false) => ({
input: 'index.js',
Expand All @@ -19,4 +18,19 @@ const getConfig = (minify = false) => ({
plugins: [commonjs(), resolve({ browser: true }), minify && terser()]
});

export default [getConfig(), getConfig(true)];
const configs = [getConfig(), getConfig(true)];

if (process.env.NODE_ENV === 'test') {
configs.push({
input: 'node_modules/htmlparser2',
output: {
file: 'dist/htmlparser2.js',
format: 'umd',
name: 'htmlparser2',
sourcemap: true
},
plugins: [commonjs(), resolve({ browser: true })]
});
}

export default configs;
5 changes: 3 additions & 2 deletions test/client/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var assert = window.chai.assert;
var htmlCases = require('../cases/html');
var serverParser = require('../../dist/htmlparser2').parseDOM;
var clientParser = require('../../lib/client/html-to-dom');
var clientParser = require('../../dist/html-dom-parser');
var helpers = require('../helpers');

var assert = window.assert;

describe('client parser', function () {
helpers.throwErrors(assert, clientParser);
helpers.runTests(assert, clientParser, serverParser, htmlCases);
Expand Down
12 changes: 0 additions & 12 deletions test/client/utilities.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/server/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { expect } = require('chai');
const utilities = require('../../lib/client/utilities');

describe('client utilities', function () {
describe('formatDOM', function () {
it('continues loop when nodeType is undefined', function () {
expect(utilities.formatDOM([{ nodeType: undefined }])).to.deep.equal([]);
});
});
});
2 changes: 1 addition & 1 deletion test/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const html = '<html>';

describe('server parser', () => {
// before
mock('htmlparser2/lib/Parser', { Parser });
mock('htmlparser2', { Parser });
mock('domhandler', { DomHandler });
const parse = require('../..');

Expand Down
16 changes: 0 additions & 16 deletions webpack.test.config.js

This file was deleted.

0 comments on commit e80a69c

Please sign in to comment.