1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 12:20:04 +02:00

update modules

This commit is contained in:
s2
2020-07-20 16:16:07 +02:00
parent 783511ce12
commit 2b23424b86
785 changed files with 91905 additions and 56057 deletions

64
node_modules/jsdom/lib/api.js generated vendored
View File

@@ -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");
@@ -10,15 +10,12 @@ const { URL } = require("whatwg-url");
const MIMEType = require("whatwg-mimetype");
const idlUtils = require("./jsdom/living/generated/utils.js");
const VirtualConsole = require("./jsdom/virtual-console.js");
const Window = require("./jsdom/browser/Window.js");
const { createWindow } = require("./jsdom/browser/Window.js");
const { parseIntoDocument } = require("./jsdom/browser/parser");
const { fragmentSerialization } = require("./jsdom/living/domparsing/serialization.js");
const ResourceLoader = require("./jsdom/browser/resources/resource-loader.js");
const NoOpResourceLoader = require("./jsdom/browser/resources/no-op-resource-loader.js");
// This symbol allows us to smuggle a non-public option through to the JSDOM constructor, for use by JSDOM.fromURL.
const transportLayerEncodingLabelHiddenOption = Symbol("transportLayerEncodingLabel");
class CookieJar extends toughCookie.CookieJar {
constructor(store, options) {
// jsdom cookie jars must be loose by default
@@ -32,11 +29,11 @@ let sharedFragmentDocument = null;
class JSDOM {
constructor(input, options = {}) {
const mimeType = new MIMEType(options.contentType === undefined ? "text/html" : options.contentType);
const { html, encoding } = normalizeHTML(input, options[transportLayerEncodingLabelHiddenOption], mimeType);
const { html, encoding } = normalizeHTML(input, mimeType);
options = transformOptions(options, encoding, mimeType);
this[window] = new Window(options.windowOptions);
this[window] = createWindow(options.windowOptions);
const documentImpl = idlUtils.implForWrapper(this[window]._document);
@@ -48,8 +45,8 @@ class JSDOM {
}
get window() {
// It's important to grab the global proxy, instead of just the result of `new Window(...)`, since otherwise things
// like `window.eval` don't exist.
// It's important to grab the global proxy, instead of just the result of `createWindow(...)`, since otherwise
// things like `window.eval` don't exist.
return this[window]._globalProxy;
}
@@ -74,13 +71,13 @@ class JSDOM {
return idlUtils.implForWrapper(node).sourceCodeLocation;
}
runVMScript(script, options) {
getInternalVMContext() {
if (!vm.isContext(this[window])) {
throw new TypeError("This jsdom was not configured to allow script running. " +
"Use the runScripts option during creation.");
}
return script.runInContext(this[window], options);
return this[window];
}
reconfigure(settings) {
@@ -97,7 +94,7 @@ class JSDOM {
}
document._URL = url;
document.origin = whatwgURL.serializeURLOrigin(document._URL);
document._origin = whatwgURL.serializeURLOrigin(document._URL);
}
}
@@ -113,8 +110,13 @@ class JSDOM {
static fromURL(url, options = {}) {
return Promise.resolve().then(() => {
// Remove the hash while sending this through the research loader fetch().
// It gets added back a few lines down when constructing the JSDOM object.
const parsedURL = new URL(url);
const originalHash = parsedURL.hash;
parsedURL.hash = "";
url = parsedURL.href;
options = normalizeFromURLOptions(options);
const resourceLoader = resourcesToResourceLoader(options.resources);
@@ -131,17 +133,10 @@ class JSDOM {
return req.then(body => {
const res = req.response;
let transportLayerEncodingLabel;
if ("content-type" in res.headers) {
const mimeType = new MIMEType(res.headers["content-type"]);
transportLayerEncodingLabel = mimeType.parameters.get("charset");
}
options = Object.assign(options, {
url: req.href + parsedURL.hash,
url: req.href + originalHash,
contentType: res.headers["content-type"],
referrer: req.getHeader("referer"),
[transportLayerEncodingLabelHiddenOption]: transportLayerEncodingLabel
referrer: req.getHeader("referer")
});
return new JSDOM(body, options);
@@ -149,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);
}
}
@@ -192,7 +184,7 @@ function normalizeFromFileOptions(filename, options) {
if (normalized.contentType === undefined) {
const extname = path.extname(filename);
if (extname === ".xhtml" || extname === ".xml") {
if (extname === ".xhtml" || extname === ".xht" || extname === ".xml") {
normalized.contentType = "application/xhtml+xml";
}
}
@@ -212,7 +204,10 @@ function transformOptions(options, encoding, mimeType) {
referrer: "",
contentType: "text/html",
parsingMode: "html",
parseOptions: { sourceCodeLocationInfo: false },
parseOptions: {
sourceCodeLocationInfo: false,
scriptingEnabled: false
},
runScripts: undefined,
encoding,
pretendToBeVisual: false,
@@ -268,8 +263,9 @@ function transformOptions(options, encoding, mimeType) {
if (options.runScripts !== undefined) {
transformed.windowOptions.runScripts = String(options.runScripts);
if (transformed.windowOptions.runScripts !== "dangerously" &&
transformed.windowOptions.runScripts !== "outside-only") {
if (transformed.windowOptions.runScripts === "dangerously") {
transformed.windowOptions.parseOptions.scriptingEnabled = true;
} else if (transformed.windowOptions.runScripts !== "outside-only") {
throw new RangeError(`runScripts must be undefined, "dangerously", or "outside-only"`);
}
}
@@ -291,7 +287,7 @@ function transformOptions(options, encoding, mimeType) {
return transformed;
}
function normalizeHTML(html = "", transportLayerEncodingLabel, mimeType) {
function normalizeHTML(html = "", mimeType) {
let encoding = "UTF-8";
if (ArrayBuffer.isView(html)) {
@@ -303,7 +299,7 @@ function normalizeHTML(html = "", transportLayerEncodingLabel, mimeType) {
if (Buffer.isBuffer(html)) {
encoding = sniffHTMLEncoding(html, {
defaultEncoding: mimeType.isXML() ? "UTF-8" : "windows-1252",
transportLayerEncodingLabel
transportLayerEncodingLabel: mimeType.parameters.get("charset")
});
html = whatwgEncoding.decode(html, encoding);
} else {