From d240291edbe7d4180a5152993ced7950c834dc57 Mon Sep 17 00:00:00 2001
From: Pierre-Marie Dartus
Date: Sun, 12 Jan 2020 01:57:05 +0100
Subject: [PATCH] Remove unnecessary dependencies
Removes pn and array-equals, as well as the q dev dependency, as we can easily do without them.
---
lib/api.js | 13 +++++--------
lib/jsdom/living/window/navigation.js | 17 ++++-------------
package.json | 3 ---
test/web-platform-tests/start-wpt-server.js | 13 ++++++++-----
yarn.lock | 5 -----
5 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/lib/api.js b/lib/api.js
index c747ab8a75..31772f5923 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -1,6 +1,6 @@
"use strict";
const path = require("path");
-const fs = require("pn/fs");
+const fs = require("fs").promises;
const vm = require("vm");
const toughCookie = require("tough-cookie");
const sniffHTMLEncoding = require("html-encoding-sniffer");
@@ -144,14 +144,11 @@ class JSDOM {
});
}
- static fromFile(filename, options = {}) {
- return Promise.resolve().then(() => {
- options = normalizeFromFileOptions(filename, options);
+ static async fromFile(filename, options = {}) {
+ options = normalizeFromFileOptions(filename, options);
+ const buffer = await fs.readFile(filename);
- return fs.readFile(filename).then(buffer => {
- return new JSDOM(buffer, options);
- });
- });
+ return new JSDOM(buffer, options);
}
}
diff --git a/lib/jsdom/living/window/navigation.js b/lib/jsdom/living/window/navigation.js
index 7f97f00270..b051f2431f 100644
--- a/lib/jsdom/living/window/navigation.js
+++ b/lib/jsdom/living/window/navigation.js
@@ -1,6 +1,5 @@
"use strict";
const whatwgURL = require("whatwg-url");
-const arrayEqual = require("array-equal");
const notImplemented = require("../../browser/not-implemented.js");
const reportException = require("../helpers/runtime-script-errors.js");
const idlUtils = require("../generated/utils.js");
@@ -77,17 +76,9 @@ function navigateFetch(window) {
notImplemented("navigation (except hash changes)", window);
}
+// https://url.spec.whatwg.org/#concept-url-equals
function urlEquals(a, b, flags) {
- if (a.scheme !== b.scheme ||
- a.username !== b.username ||
- a.password !== b.password ||
- a.host !== b.host ||
- a.port !== b.port ||
- !arrayEqual(a.path, b.path) ||
- a.query !== b.query ||
- // Omitted per spec: url.fragment !== this._url.fragment ||
- a.cannotBeABaseURL !== b.cannotBeABaseURL) {
- return false;
- }
- return flags.excludeFragments || a.fragment === b.fragment;
+ const serializedA = whatwgURL.serializeURL(a, flags.excludeFragments);
+ const serializedB = whatwgURL.serializeURL(b, flags.excludeFragments);
+ return serializedA === serializedB;
}
diff --git a/package.json b/package.json
index c10ce1ec5b..d4c8c22008 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,6 @@
"abab": "^2.0.3",
"acorn": "^7.1.0",
"acorn-globals": "^4.3.2",
- "array-equal": "^1.0.0",
"cssom": "^0.4.4",
"cssstyle": "^2.0.0",
"data-urls": "^2.0.0",
@@ -33,7 +32,6 @@
"html-encoding-sniffer": "^2.0.0",
"nwsapi": "^2.2.0",
"parse5": "5.1.1",
- "pn": "^1.1.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.8",
"saxes": "^4.0.2",
@@ -78,7 +76,6 @@
"mocha-sugar-free": "^1.4.0",
"optimist": "0.6.1",
"portfinder": "^1.0.25",
- "q": "^1.5.1",
"rimraf": "^3.0.0",
"server-destroy": "^1.0.1",
"st": "^2.0.0",
diff --git a/test/web-platform-tests/start-wpt-server.js b/test/web-platform-tests/start-wpt-server.js
index 03ac3b9c34..18a7241d06 100644
--- a/test/web-platform-tests/start-wpt-server.js
+++ b/test/web-platform-tests/start-wpt-server.js
@@ -1,12 +1,13 @@
"use strict";
/* eslint-disable no-console, global-require */
-const path = require("path");
const dns = require("dns");
+const path = require("path");
+const util = require("util");
const childProcess = require("child_process");
-const q = require("q");
-const { inBrowserContext } = require("../util.js");
const requestHead = require("request-promise-native").head;
-const dnsLookup = q.denodeify(dns.lookup);
+const { inBrowserContext } = require("../util.js");
+
+const dnsLookup = util.promisify(dns.lookup);
const wptDir = path.resolve(__dirname, "tests");
@@ -72,6 +73,8 @@ function pollForServer(url) {
})
.catch(err => {
console.log(`WPT server at ${url} is not up yet (${err.message}); trying again`);
- return q.delay(500).then(() => pollForServer(url));
+ return new Promise(resolve => {
+ setTimeout(() => resolve(pollForServer(url)), 500);
+ });
});
}
diff --git a/yarn.lock b/yarn.lock
index 0b29fef019..aef92e0032 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -220,11 +220,6 @@ arr-union@^3.1.0:
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4"
integrity sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ=
-array-equal@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93"
- integrity sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=
-
array-unique@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"