diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bd5408..eeb847c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Changed + +- Revert back to [jsdom](https://www.npmjs.com/package/jsdom) for parsing in Node.js. + ## v3.1.0 - 2024-03-04 ### Changed diff --git a/README.md b/README.md index 6a38d34..1226ed1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Parse a string of HTML or XML (including MathML, SVG, XHTML) into a document object. -Uses the [HTML template element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template) in browsers and [Happy DOM](https://github.com/capricorn86/happy-dom) in Node.js. +Uses the [HTML template element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template) in browsers and [jsdom](https://github.com/jsdom/jsdom) in Node.js. ## Usage diff --git a/package.json b/package.json index fde9c75..04b6f24 100644 --- a/package.json +++ b/package.json @@ -53,9 +53,10 @@ }, "homepage": "https://github.com/jacobbuck/dom-parse", "dependencies": { - "happy-dom": "*" + "jsdom": "^24.0.0" }, "devDependencies": { + "@vitest/coverage-v8": "^1.3.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", diff --git a/src/__tests__/browser.test.js b/src/__tests__/browser.test.js index 18f354b..50a3589 100644 --- a/src/__tests__/browser.test.js +++ b/src/__tests__/browser.test.js @@ -1,4 +1,4 @@ -// @vitest-environment happy-dom +// @vitest-environment jsdom import { expect, test } from 'vitest'; import { parse } from '../browser'; diff --git a/src/node.js b/src/node.js index 905d5f8..b77920a 100644 --- a/src/node.js +++ b/src/node.js @@ -1,10 +1,8 @@ -import { Window, XMLParser } from 'happy-dom'; - -const { document } = new Window(); +import { JSDOM } from 'jsdom'; /** * Parse a string of HTML or XML to a DOM tree. * @param {string} [html] String containing HTML or XML to be parsed. * @returns {DocumentFragment} Object containing Node structure of HTML/XML parsed. */ -export const parse = (html) => XMLParser.parse(document, html); +export const parse = (html) => JSDOM.fragment(html); diff --git a/vite.config.js b/vite.config.js index ec648e7..cac7480 100644 --- a/vite.config.js +++ b/vite.config.js @@ -10,7 +10,7 @@ export default defineConfig({ ], }, rollupOptions: { - external: ['happy-dom'], + external: ['jsdom'], }, sourcemap: true, },