Skip to content

Commit

Permalink
Merge pull request capricorn86#1222 from capricorn86/task/1215-add-su…
Browse files Browse the repository at this point in the history
…pport-for-non-nodejs-environments

Task/1215 remove unnecessary dependencies
  • Loading branch information
capricorn86 committed Jan 18, 2024
2 parents 52487a2 + e1271d0 commit e7b526d
Show file tree
Hide file tree
Showing 46 changed files with 838 additions and 3,053 deletions.
3,236 changes: 619 additions & 2,617 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"typescript": "^5.0.4"
},
"engines": {
"node": ">=12.13"
"node": ">=16.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/global-registrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
"typescript": "^5.0.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"engines": {
"node": ">=16.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/happy-dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ npm install happy-dom

# Usage

A simple example of how you can use Happy DOM.
Happy DOM can be used as a simulated [Browser](https://github.com/capricorn86/happy-dom/wiki/Browser) or by using the [Window](https://github.com/capricorn86/happy-dom/wiki/Window) class directly to quickly setup up a DOM.

## Window

Expand Down
30 changes: 0 additions & 30 deletions packages/happy-dom/package-lock.json

This file was deleted.

10 changes: 3 additions & 7 deletions packages/happy-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,19 @@
"test:debug": "vitest run --inspect-brk --threads=false"
},
"dependencies": {
"css.escape": "^1.5.1",
"entities": "^4.5.0",
"iconv-lite": "^0.6.3",
"webidl-conversions": "^7.0.0",
"whatwg-encoding": "^2.0.0",
"whatwg-mimetype": "^3.0.0"
},
"devDependencies": {
"@types/css.escape": "^1.5.0",
"@types/node": "^16.11.7",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@vitest/ui": "^0.33.0",
"@webref/css": "6.6.2",
"prettier": "^2.6.0",
"typescript": "^5.0.4",
"vitest": "^0.32.4"
},
"engines": {
"node": ">=16.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/happy-dom/src/async-task-manager/AsyncTaskManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// We need to set this as a global constant, so that using fake timers in Jest and Vitest won't override this on the global object.
const TIMER = {
setImmediate: setImmediate,
clearImmediate: clearImmediate,
clearTimeout: clearTimeout
setImmediate: globalThis.setImmediate.bind(globalThis),
clearImmediate: globalThis.clearImmediate.bind(globalThis),
clearTimeout: globalThis.clearTimeout.bind(globalThis)
};

/**
Expand Down
7 changes: 3 additions & 4 deletions packages/happy-dom/src/console/VirtualConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import IVirtualConsolePrinter from './types/IVirtualConsolePrinter.js';
import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
import VirtualConsoleLogTypeEnum from './enums/VirtualConsoleLogTypeEnum.js';
import IVirtualConsoleLogGroup from './types/IVirtualConsoleLogGroup.js';
import * as PerfHooks from 'perf_hooks';
import { ConsoleConstructor } from 'console';

/**
Expand Down Expand Up @@ -276,7 +275,7 @@ export default class VirtualConsole implements Console {
* @param [label=default] Label.
*/
public time(label = 'default'): void {
this.#time[label] = PerfHooks.performance.now();
this.#time[label] = performance.now();
}

/**
Expand All @@ -288,7 +287,7 @@ export default class VirtualConsole implements Console {
public timeEnd(label = 'default'): void {
const time = this.#time[label];
if (time) {
const duration = PerfHooks.performance.now() - time;
const duration = performance.now() - time;
this.#printer.print({
type: VirtualConsoleLogTypeEnum.timeEnd,
level: VirtualConsoleLogLevelEnum.info,
Expand All @@ -308,7 +307,7 @@ export default class VirtualConsole implements Console {
public timeLog(label = 'default', ...args: Array<object | string>): void {
const time = this.#time[label];
if (time) {
const duration = PerfHooks.performance.now() - time;
const duration = performance.now() - time;
this.#printer.print({
type: VirtualConsoleLogTypeEnum.timeLog,
level: VirtualConsoleLogLevelEnum.info,
Expand Down
4 changes: 2 additions & 2 deletions packages/happy-dom/src/css/CSS.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CSSEscaper from './utilities/CSSEscaper.js';
import CSSUnitValue from './CSSUnitValue.js';
import CSSUnits from './CSSUnits.js';
import CSSEscape from 'css.escape';

/**
* The CSS interface holds useful CSS-related methods.
Expand Down Expand Up @@ -38,6 +38,6 @@ export default class CSS {
* @returns Escaped string.
*/
public escape(value: string): string {
return CSSEscape(value);
return CSSEscaper.escape(value);
}
}
2 changes: 1 addition & 1 deletion packages/happy-dom/src/css/CSSStyleSheet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DOMException from '../exception/DOMException.js';
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
import CSSParser from './CSSParser.js';
import CSSParser from './utilities/CSSParser.js';
import CSSRule from './CSSRule.js';
import MediaList from './MediaList.js';

Expand Down
87 changes: 87 additions & 0 deletions packages/happy-dom/src/css/utilities/CSSEscaper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* CSS escaper.
*/
export default class CSSEscaper {
/**
* Escapes CSS.
*
* Based on:
* https://github.com/mathiasbynens/CSS.escape
*
* @param cssText CSS.
* @returns Escaped CSS.
*/
public static escape(cssText: string): string {
if (arguments.length == 0) {
throw new TypeError('`CSS.escape` requires an argument.');
}
const returnValue = String(cssText);
const length = returnValue.length;
let index = -1;
let codeUnit;
let result = '';
const firstCodeUnit = returnValue.charCodeAt(0);

if (
// If the character is the first character and is a `-` (U+002D), and
// There is no second character, […]
length == 1 &&
firstCodeUnit == 0x002d
) {
return '\\' + returnValue;
}

while (++index < length) {
codeUnit = returnValue.charCodeAt(index);
// Note: there’s no need to special-case astral symbols, surrogate
// Pairs, or lone surrogates.

// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
// (U+FFFD).
if (codeUnit == 0x0000) {
result += '\uFFFD';
continue;
}

if (
// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
// U+007F, […]
(codeUnit >= 0x0001 && codeUnit <= 0x001f) ||
codeUnit == 0x007f ||
// If the character is the first character and is in the range [0-9]
// (U+0030 to U+0039), […]
(index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
// If the character is the second character and is in the range [0-9]
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
(index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002d)
) {
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
result += '\\' + codeUnit.toString(16) + ' ';
continue;
}

// If the character is not handled by one of the above rules and is
// Greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
// Is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
// U+005A), or [a-z] (U+0061 to U+007A), […]
if (
codeUnit >= 0x0080 ||
codeUnit == 0x002d ||
codeUnit == 0x005f ||
(codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
(codeUnit >= 0x0041 && codeUnit <= 0x005a) ||
(codeUnit >= 0x0061 && codeUnit <= 0x007a)
) {
// The character itself
result += returnValue.charAt(index);
continue;
}

// Otherwise, the escaped character.
// https://drafts.csswg.org/cssom/#escape-a-character
result += '\\' + returnValue.charAt(index);
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import CSSRule from './CSSRule.js';
import * as PropertySymbol from '../PropertySymbol.js';
import CSSStyleSheet from './CSSStyleSheet.js';
import CSSStyleRule from './rules/CSSStyleRule.js';
import CSSKeyframeRule from './rules/CSSKeyframeRule.js';
import CSSKeyframesRule from './rules/CSSKeyframesRule.js';
import CSSMediaRule from './rules/CSSMediaRule.js';
import CSSContainerRule from './rules/CSSContainerRule.js';
import CSSSupportsRule from './rules/CSSSupportsRule.js';
import SelectorParser from '../query-selector/SelectorParser.js';
import CSSRule from '../CSSRule.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import CSSStyleSheet from '../CSSStyleSheet.js';
import CSSStyleRule from '../rules/CSSStyleRule.js';
import CSSKeyframeRule from '../rules/CSSKeyframeRule.js';
import CSSKeyframesRule from '../rules/CSSKeyframesRule.js';
import CSSMediaRule from '../rules/CSSMediaRule.js';
import CSSContainerRule from '../rules/CSSContainerRule.js';
import CSSSupportsRule from '../rules/CSSSupportsRule.js';
import SelectorParser from '../../query-selector/SelectorParser.js';

const COMMENT_REGEXP = /\/\*[\s\S]*?\*\//gm;

Expand Down
1 change: 0 additions & 1 deletion packages/happy-dom/src/event/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import IBrowserWindow from '../window/IBrowserWindow.js';
import IShadowRoot from '../nodes/shadow-root/IShadowRoot.js';
import IEventTarget from './IEventTarget.js';
import NodeTypeEnum from '../nodes/node/NodeTypeEnum.js';
import { performance } from 'perf_hooks';
import EventPhaseEnum from './EventPhaseEnum.js';
import IDocument from '../nodes/document/IDocument.js';

Expand Down
1 change: 0 additions & 1 deletion packages/happy-dom/src/fetch/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FetchBodyUtility from './utilities/FetchBodyUtility.js';
import AbortSignal from './AbortSignal.js';
import Stream from 'stream';
import Blob from '../file/Blob.js';
import { TextDecoder } from 'util';
import FetchRequestValidationUtility from './utilities/FetchRequestValidationUtility.js';
import IRequestReferrerPolicy from './types/IRequestReferrerPolicy.js';
import IRequestRedirect from './types/IRequestRedirect.js';
Expand Down
1 change: 0 additions & 1 deletion packages/happy-dom/src/fetch/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import FormData from '../form-data/FormData.js';
import FetchBodyUtility from './utilities/FetchBodyUtility.js';
import DOMException from '../exception/DOMException.js';
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
import { TextDecoder } from 'util';
import MultipartFormDataParser from './multipart/MultipartFormDataParser.js';
import IBrowserWindow from '../window/IBrowserWindow.js';
import IBrowserFrame from '../browser/types/IBrowserFrame.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/happy-dom/src/fetch/types/IRequestBody.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { URLSearchParams } from 'url';
import FormData from '../../form-data/FormData.js';
import Blob from '../../file/Blob.js';
import Stream from 'stream';

type IRequestBody =
| ArrayBuffer
| ArrayBufferView
| NodeJS.ReadableStream
| Stream.Readable
| string
| URLSearchParams
| Blob
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/fetch/types/IResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import IHeaders from './IHeaders.js';
import IBlob from '../../file/IBlob.js';
import Stream from 'stream';
import { Buffer } from 'buffer';

/**
* Fetch response.
Expand Down
3 changes: 2 additions & 1 deletion packages/happy-dom/src/fetch/types/IResponseBody.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { URLSearchParams } from 'url';
import FormData from '../../form-data/FormData.js';
import Blob from '../../file/Blob.js';
import Stream from 'stream';

type IResponseBody =
| ArrayBuffer
| ArrayBufferView
| NodeJS.ReadableStream
| Stream.Readable
| string
| URLSearchParams
| Blob
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/fetch/utilities/FetchBodyUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DOMException from '../../exception/DOMException.js';
import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum.js';
import IRequestBody from '../types/IRequestBody.js';
import IResponseBody from '../types/IResponseBody.js';
import { Buffer } from 'buffer';

/**
* Fetch body utility.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FetchHTTPSCertificate from '../certificate/FetchHTTPSCertificate.js';
import { Buffer } from 'buffer';

/**
* Synchronous fetch script builder.
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/file/Blob.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import IBlob from './IBlob.js';
import { Buffer } from 'buffer';
import * as PropertySymbol from '../PropertySymbol.js';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/happy-dom/src/file/File.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Blob from './Blob.js';
import { Buffer } from 'buffer';

/**
* Reference:
Expand Down
Loading

0 comments on commit e7b526d

Please sign in to comment.