happy-dom 10.1.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (41) hide show
  1. package/cjs/nodes/document/Document.cjs +1 -0
  2. package/cjs/nodes/document/Document.cjs.map +1 -1
  3. package/cjs/nodes/document/Document.d.ts.map +1 -1
  4. package/cjs/window/GlobalWindow.cjs +0 -3
  5. package/cjs/window/GlobalWindow.cjs.map +1 -1
  6. package/cjs/window/GlobalWindow.d.ts +0 -3
  7. package/cjs/window/GlobalWindow.d.ts.map +1 -1
  8. package/cjs/window/INodeJSGlobal.d.ts +6 -8
  9. package/cjs/window/INodeJSGlobal.d.ts.map +1 -1
  10. package/cjs/window/VMGlobalPropertyScript.cjs +0 -3
  11. package/cjs/window/VMGlobalPropertyScript.cjs.map +1 -1
  12. package/cjs/window/VMGlobalPropertyScript.d.ts +1 -1
  13. package/cjs/window/VMGlobalPropertyScript.d.ts.map +1 -1
  14. package/cjs/window/Window.cjs +17 -0
  15. package/cjs/window/Window.cjs.map +1 -1
  16. package/cjs/window/Window.d.ts +7 -3
  17. package/cjs/window/Window.d.ts.map +1 -1
  18. package/lib/nodes/document/Document.d.ts.map +1 -1
  19. package/lib/nodes/document/Document.js +1 -0
  20. package/lib/nodes/document/Document.js.map +1 -1
  21. package/lib/window/GlobalWindow.d.ts +0 -3
  22. package/lib/window/GlobalWindow.d.ts.map +1 -1
  23. package/lib/window/GlobalWindow.js +0 -3
  24. package/lib/window/GlobalWindow.js.map +1 -1
  25. package/lib/window/INodeJSGlobal.d.ts +6 -8
  26. package/lib/window/INodeJSGlobal.d.ts.map +1 -1
  27. package/lib/window/VMGlobalPropertyScript.d.ts +1 -1
  28. package/lib/window/VMGlobalPropertyScript.d.ts.map +1 -1
  29. package/lib/window/VMGlobalPropertyScript.js +0 -3
  30. package/lib/window/VMGlobalPropertyScript.js.map +1 -1
  31. package/lib/window/Window.d.ts +7 -3
  32. package/lib/window/Window.d.ts.map +1 -1
  33. package/lib/window/Window.js +17 -0
  34. package/lib/window/Window.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/nodes/document/Document.ts +1 -0
  37. package/src/window/GlobalWindow.ts +0 -6
  38. package/src/window/INodeJSGlobal.ts +12 -8
  39. package/src/window/VMGlobalPropertyScript.ts +0 -3
  40. package/src/window/Window.ts +23 -10
  41. package/bin/change-file-extension.cjs +0 -101
@@ -140,6 +140,7 @@ const ORIGINAL_SET_TIMEOUT = setTimeout;
140
140
  const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
141
141
  const ORIGINAL_SET_INTERVAL = setInterval;
142
142
  const ORIGINAL_CLEAR_INTERVAL = clearInterval;
143
+ const ORIGINAL_QUEUE_MICROTASK = queueMicrotask;
143
144
 
144
145
  /**
145
146
  * Browser window.
@@ -390,7 +391,6 @@ export default class Window extends EventTarget implements IWindow {
390
391
  public Uint8ClampedArray: typeof Uint8ClampedArray;
391
392
  public WeakMap: WeakMapConstructor;
392
393
  public WeakSet: WeakSetConstructor;
393
- public clearImmediate: (immediateId: NodeJS.Immediate) => void;
394
394
  public decodeURI: typeof decodeURI;
395
395
  public decodeURIComponent: typeof decodeURIComponent;
396
396
  public encodeURI: typeof encodeURI;
@@ -404,11 +404,6 @@ export default class Window extends EventTarget implements IWindow {
404
404
  public isNaN: typeof isNaN;
405
405
  public parseFloat: typeof parseFloat;
406
406
  public parseInt: typeof parseInt;
407
- public setImmediate: (
408
- callback: (...args: unknown[]) => void,
409
- ...args: unknown[]
410
- ) => NodeJS.Immediate;
411
- public queueMicrotask: typeof queueMicrotask;
412
407
  public undefined: typeof undefined;
413
408
  /**
414
409
  * @deprecated
@@ -424,10 +419,11 @@ export default class Window extends EventTarget implements IWindow {
424
419
  public _captureEventListenerCount: { [eventType: string]: number } = {};
425
420
 
426
421
  // Private properties
427
- private _setTimeout;
428
- private _clearTimeout;
429
- private _setInterval;
430
- private _clearInterval;
422
+ private _setTimeout: (callback: Function, delay?: number, ...args: unknown[]) => NodeJS.Timeout;
423
+ private _clearTimeout: (id: NodeJS.Timeout) => void;
424
+ private _setInterval: (callback: Function, delay?: number, ...args: unknown[]) => NodeJS.Timeout;
425
+ private _clearInterval: (id: NodeJS.Timeout) => void;
426
+ private _queueMicrotask: (callback: Function) => void;
431
427
 
432
428
  /**
433
429
  * Constructor.
@@ -492,6 +488,7 @@ export default class Window extends EventTarget implements IWindow {
492
488
  this._clearTimeout = ORIGINAL_CLEAR_TIMEOUT;
493
489
  this._setInterval = ORIGINAL_SET_INTERVAL;
494
490
  this._clearInterval = ORIGINAL_CLEAR_INTERVAL;
491
+ this._queueMicrotask = ORIGINAL_QUEUE_MICROTASK;
495
492
 
496
493
  // Non-implemented event types
497
494
  for (const eventType of NonImplementedEventTypes) {
@@ -784,6 +781,22 @@ export default class Window extends EventTarget implements IWindow {
784
781
  this.clearTimeout(id);
785
782
  }
786
783
 
784
+ /**
785
+ * Queues a microtask to be executed at a safe time prior to control returning to the browser's event loop.
786
+ *
787
+ * @param callback Function to be executed.
788
+ */
789
+ public queueMicrotask(callback: Function): void {
790
+ let isAborted = false;
791
+ const taskId = this.happyDOM.asyncTaskManager.startTask(() => (isAborted = true));
792
+ this._queueMicrotask(() => {
793
+ if (!isAborted) {
794
+ this.happyDOM.asyncTaskManager.endTask(taskId);
795
+ callback();
796
+ }
797
+ });
798
+ }
799
+
787
800
  /**
788
801
  * This method provides an easy, logical way to fetch resources asynchronously across the network.
789
802
  *
@@ -1,101 +0,0 @@
1
- /* eslint-disable no-console*/
2
- /* eslint-disable @typescript-eslint/no-var-requires*/
3
-
4
- const Path = require('path');
5
- const FS = require('fs');
6
-
7
- process.on('unhandledRejection', (reason) => {
8
- console.error(reason);
9
- process.exit(1);
10
- });
11
-
12
- main();
13
-
14
- function getArguments() {
15
- const args = {
16
- dir: null,
17
- fromExt: null,
18
- toExt: null
19
- };
20
-
21
- for (const arg of process.argv) {
22
- if (arg.startsWith('--dir=')) {
23
- args.dir = arg.split('=')[1];
24
- } else if (arg.startsWith('--fromExt=')) {
25
- args.fromExt = arg.split('=')[1];
26
- } else if (arg.startsWith('--toExt=')) {
27
- args.toExt = arg.split('=')[1];
28
- }
29
- }
30
-
31
- return args;
32
- }
33
-
34
- async function readDirectory(directory) {
35
- const resolvedDirectory = Path.resolve(directory);
36
- const files = await FS.promises.readdir(resolvedDirectory);
37
- const statsPromises = [];
38
- let allFiles = [];
39
-
40
- for (const file of files) {
41
- const filePath = Path.join(resolvedDirectory, file);
42
- statsPromises.push(
43
- FS.promises.stat(filePath).then((stats) => {
44
- if (stats.isDirectory()) {
45
- return readDirectory(filePath).then((files) => (allFiles = allFiles.concat(files)));
46
- }
47
- allFiles.push(filePath);
48
- })
49
- );
50
- }
51
-
52
- await Promise.all(statsPromises);
53
-
54
- return allFiles;
55
- }
56
-
57
- async function renameFiles(files, args) {
58
- const newFiles = files.map((file) => ({
59
- oldPath: file,
60
- newPath: file.replace(args.fromExt, args.toExt)
61
- }));
62
- const writePromises = [];
63
-
64
- for (const file of newFiles) {
65
- writePromises.push(
66
- FS.promises.readFile(file.oldPath).then((content) => {
67
- debugger;
68
- return FS.promises
69
- .writeFile(
70
- file.newPath,
71
- content
72
- .toString()
73
- .replace(
74
- new RegExp(`${args.fromExt.replace('.', '\\.')}\\.map`, 'g'),
75
- `${args.toExt}.map`
76
- )
77
- .replace(
78
- new RegExp(`${args.fromExt.replace('.', '\\.')}(["'])`, 'g'),
79
- `${args.toExt}$1`
80
- )
81
- )
82
- .then(() => {
83
- if (file.oldPath !== file.newPath) {
84
- return FS.promises.unlink(file.oldPath);
85
- }
86
- });
87
- })
88
- );
89
- }
90
-
91
- await Promise.all(writePromises);
92
- }
93
-
94
- async function main() {
95
- const args = getArguments();
96
- if (!args.dir || !args.fromExt || !args.toExt) {
97
- throw new Error('Invalid arguments');
98
- }
99
- const files = await readDirectory(args.dir);
100
- await renameFiles(files, args);
101
- }