8 Commits 7643259e38 ... 1250bf2bc1

Autore SHA1 Messaggio Data
  Sv443 1250bf2bc1 chore: change to alpha version 1 settimana fa
  Sv443 20c82428e3 fix: update vitest config 1 settimana fa
  Sv443 1d473049ae ci: bump pnpm version 1 settimana fa
  Sv443 905881a9d8 docs: coreutils changeset 1 settimana fa
  Sv443 422da75b71 ref!: bump target to es2018 1 settimana fa
  Sv443 fbbd788b4d fix: more small random fixes 1 settimana fa
  Sv443 92103c3758 fix: unit tests & file names 1 settimana fa
  Sv443 dc485d95ee feat: import coreutils 1 settimana fa

+ 7 - 0
.changeset/silly-foxes-melt.md

@@ -0,0 +1,7 @@
+---
+"@sv443-network/userutils": major
+---
+
+**BREAKING:** Moved a majority of the general-purpose code to `@sv443-network/coreutils`  
+The features are still available in the same way, but some of them needed to be modified so they were more generic and consistent with the new package's codebase.  
+TODO: list changes

+ 5 - 0
.changeset/ten-otters-check.md

@@ -0,0 +1,5 @@
+---
+"@sv443-network/userutils": major
+---
+
+Increased library target to ES2018

+ 1 - 1
.github/workflows/build-and-publish-jsr.yml

@@ -21,7 +21,7 @@ jobs:
     env:
       CI: "true"
       STORE_PATH: ""
-      PNPM_VERSION: 9
+      PNPM_VERSION: 10
       RETENTION_DAYS: 2
 
     steps:

+ 1 - 1
.github/workflows/build-and-publish-npm.yml

@@ -27,7 +27,7 @@ jobs:
     env:
       CI: "true"
       STORE_PATH: ""
-      PNPM_VERSION: 9
+      PNPM_VERSION: 10
       RETENTION_DAYS: 2
 
     steps:

+ 1 - 1
.github/workflows/lint-and-test-code.yml

@@ -19,7 +19,7 @@ jobs:
     env:
       CI: "true"
       STORE_PATH: ""
-      PNPM_VERSION: 9
+      PNPM_VERSION: 10
       RETENTION_DAYS: 2
 
     steps:

+ 1 - 1
docs.md

@@ -2335,7 +2335,7 @@ Returns an array of all registered listener functions.
 
 <br>
 
-#### `Debouncer.setTimeout()`  
+#### `Debouncer.setTimeout()`
 Signature: `setTimeout(timeout: number): void`  
 Changes the timeout for the debouncer.
 

+ 15 - 13
jsr.json

@@ -1,21 +1,23 @@
 {
   "$schema": "https://jsr.io/schema/config-file.v1.json",
   "name": "@sv443-network/userutils",
-  "version": "0.0.1-invalid",
-  "exports": "./lib/index.ts",
+  "version": "10.0.0-alpha.0",
+  "exports": {
+    ".": "./lib/index.ts"
+  },
   "publish": {
     "include": [
-      "lib/**/*.ts",
-      "dist/index.js",
-      "dist/index.mjs",
-      "dist/index.cjs",
-      "dist/index.global.js",
-      "dist/index.umd.js",
-      "dist/lib/*.d.ts",
-      "package.json",
-      "README.md",
-      "CHANGELOG.md",
-      "LICENSE.txt"
+      "./dist/index.cjs",
+      "./dist/index.global.js",
+      "./dist/index.js",
+      "./dist/index.mjs",
+      "./dist/index.umd.js",
+      "./dist/lib/*.d.ts",
+      "./lib/**/*.ts",
+      "./CHANGELOG.md",
+      "./LICENSE.txt",
+      "./package.json",
+      "./README.md"
     ],
     "exclude": [
       "**/*.spec.ts"

+ 19 - 0
lib/Errors.spec.ts

@@ -0,0 +1,19 @@
+
+import { describe, expect, it } from "vitest";
+import { PlatformError } from "./Errors.js";
+
+describe("Errors", () => {
+  it("All class instances have the date property", () => {
+    const classes = [
+      ["PlatformError", PlatformError],
+    ] as const;
+
+    for(const [name, Cls] of classes) {
+      const instance = new Cls(`Test ${name}`);
+      expect(instance).toBeInstanceOf(Cls);
+      expect(instance.date).toBeInstanceOf(Date);
+      expect(instance.message).toBe(`Test ${name}`);
+      expect(instance.name).toBe(name);
+    }
+  });
+});

+ 0 - 0
lib/errors.ts → lib/Errors.ts


+ 4 - 4
lib/Mixins.ts

@@ -5,7 +5,7 @@
 
 /* eslint-disable @typescript-eslint/no-explicit-any */
 
-import { purifyObj, type Prettify } from "@sv443-network/coreutils";
+import { pureObj, type Prettify } from "@sv443-network/coreutils";
 
 /** Full mixin object (either sync or async), as it is stored in the instance's mixin array. */
 export type MixinObj<TArg, TCtx> = Prettify<
@@ -121,7 +121,7 @@ export class Mixins<
    * @param config Configuration object to customize the behavior.
    */
   constructor(config: Partial<MixinsConstructorConfig> = {}) {
-    this.defaultMixinCfg = purifyObj({
+    this.defaultMixinCfg = pureObj({
       priority: config.defaultPriority ?? 0,
       stopPropagation: config.defaultStopPropagation ?? false,
       signal: config.defaultSignal,
@@ -146,10 +146,10 @@ export class Mixins<
   >(
     mixinKey: TKey,
     mixinFn: (arg: TArg, ...ctx: TCtx extends undefined ? [void] : [TCtx]) => ReturnType<TMixinMap[TKey]> extends Promise<any> ? ReturnType<TMixinMap[TKey]> | Awaited<ReturnType<TMixinMap[TKey]>> : ReturnType<TMixinMap[TKey]>,
-    config: Partial<MixinConfig> | number = purifyObj({}),
+    config: Partial<MixinConfig> | number = pureObj({}),
   ): () => void {
     const calcPrio = typeof config === "number" ? config : this.calcPriority(mixinKey, config);
-    const mixin = purifyObj({
+    const mixin = pureObj({
       ...this.defaultMixinCfg,
       key: mixinKey as string,
       fn: mixinFn,

+ 1 - 1
lib/dom.spec.ts

@@ -1,6 +1,6 @@
 import { describe, expect, it } from "vitest";
 import { addGlobalStyle, addParent, getSiblingsFrame, getUnsafeWindow, interceptWindowEvent, isDomLoaded, observeElementProp, onDomLoad, openInNewTab, preloadImages, probeElementStyle, setInnerHtmlUnsafe } from "./dom.js";
-import { PlatformError } from "./errors.js";
+import { PlatformError } from "./Errors.js";
 
 //#region getUnsafeWindow
 describe("dom/getUnsafeWindow", () => {

+ 11 - 15
lib/dom.ts

@@ -3,7 +3,7 @@
  * This module contains various functions for working with the DOM - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dom)
  */
 
-import { PlatformError } from "./errors.js";
+import { PlatformError } from "./Errors.js";
 
 //#region unsafeWindow
 
@@ -132,18 +132,16 @@ export function interceptEvent<
   eventName: Parameters<TEvtObj["addEventListener"]>[0],
   predicate: (event: TPredicateEvt) => boolean = () => true,
 ): void {
-  // @ts-ignore
+  // @ts-expect-error
   if(typeof window.GM === "object" && GM?.info?.scriptHandler && GM.info.scriptHandler === "FireMonkey" && (eventObject === window || eventObject === getUnsafeWindow()))
-    throw new PlatformError("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript runs in.");
+    throw new PlatformError("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript is forced to run in.");
 
   // default is 25 on FF so this should hopefully be more than enough
-  // @ts-ignore
-  Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
-  if(isNaN(Error.stackTraceLimit))
+  if(isNaN(Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100)))
     Error.stackTraceLimit = 100;
 
   (function(original: typeof eventObject.addEventListener) {
-    // @ts-ignore
+    // @ts-expect-error
     eventObject.__proto__.addEventListener = function(...args: Parameters<typeof eventObject.addEventListener>) {
       const origListener = typeof args[1] === "function" ? args[1] : args[1]?.handleEvent ?? (() => void 0);
       args[1] = function(...a) {
@@ -154,7 +152,7 @@ export function interceptEvent<
       };
       original.apply(this, args);
     };
-    // @ts-ignore
+    // @ts-expect-error
   })(eventObject.__proto__.addEventListener);
 }
 
@@ -209,20 +207,18 @@ export function observeElementProp<
     const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property);
     Object.defineProperty(element, property, {
       get: function() {
-        // @ts-ignore
+        // @ts-expect-error
         // eslint-disable-next-line prefer-rest-params
         return descriptor?.get?.apply(this, arguments);
       },
       set: function() {
         const oldValue = this[property];
-        // @ts-ignore
+        // @ts-expect-error
         // eslint-disable-next-line prefer-rest-params
         descriptor?.set?.apply(this, arguments);
         const newValue = this[property];
-        if(typeof callback === "function") {
-          // @ts-ignore
+        if(typeof callback === "function")
           callback.bind(this, oldValue, newValue);
-        }
         return newValue;
       }
     });
@@ -292,9 +288,9 @@ let ttPolicy: { createHTML: (html: string) => string } | undefined;
  * - ⚠️ This function does not perform any sanitization and should thus be used with utmost caution, as it can easily lead to XSS vulnerabilities!
  */
 export function setInnerHtmlUnsafe<TElement extends Element = HTMLElement>(element: TElement, html: string): TElement {
-  // @ts-ignore
+  // @ts-expect-error
   if(!ttPolicy && typeof window?.trustedTypes?.createPolicy === "function") {
-    // @ts-ignore
+    // @ts-expect-error
     ttPolicy = window.trustedTypes.createPolicy("_uu_set_innerhtml_unsafe", {
       createHTML: (unsafeHtml: string) => unsafeHtml,
     });

+ 3 - 1
lib/index.ts

@@ -3,8 +3,10 @@
  * UserUtils is a lightweight library with various utilities for userscripts, allowing you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more
  */
 
+export * from "@sv443-network/coreutils";
+
 export * from "./Dialog.js";
 export * from "./dom.js";
-export * from "./errors.js";
+export * from "./Errors.js";
 export * from "./Mixins.js";
 export * from "./SelectorObserver.js";

+ 4 - 3
package.json

@@ -1,7 +1,7 @@
 {
   "name": "@sv443-network/userutils",
   "libName": "UserUtils",
-  "version": "9.4.1",
+  "version": "10.0.0-alpha.0",
   "description": "General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
   "main": "dist/index.js",
   "module": "dist/index.js",
@@ -15,7 +15,7 @@
     }
   },
   "engines": {
-    "pnpm": ">=9",
+    "pnpm": ">=10",
     "npm": "please-use-pnpm",
     "yarn": "please-use-pnpm"
   },
@@ -32,7 +32,7 @@
     "update-jsr-version": "node --import tsx ./tools/update-jsr-version.mts",
     "publish-package": "changeset publish",
     "publish-package-jsr": "pnpm update-jsr-version && npx jsr publish --allow-dirty",
-    "check-jsr": "npx jsr publish --allow-dirty --dry-run",
+    "check-jsr": "pnpm update-jsr-version && npx jsr publish --allow-dirty --dry-run",
     "change": "changeset",
     "test-gm-serve": "node --import tsx ./test/TestPage/server.mts",
     "test-gm-dev": "cd test/TestScript && pnpm dev",
@@ -58,6 +58,7 @@
   },
   "homepage": "https://github.com/Sv443-Network/UserUtils",
   "dependencies": {
+    "@sv443-network/coreutils": "0.0.1",
     "nanoevents": "^9.1.0"
   },
   "devDependencies": {

+ 10 - 0
pnpm-lock.yaml

@@ -8,6 +8,9 @@ importers:
 
   .:
     dependencies:
+      '@sv443-network/coreutils':
+        specifier: 0.0.1
+        version: 0.0.1
       nanoevents:
         specifier: ^9.1.0
         version: 9.1.0
@@ -848,6 +851,9 @@ packages:
     cpu: [x64]
     os: [win32]
 
+  '@sv443-network/[email protected]':
+    resolution: {integrity: sha512-3GHjpr56ui84KQW8IQh4YvBQYkrUVJPnu8vaY3is9l4uAFFgSfn3hxBvZgbkbr5Oj/U9HgiKNVDjJ8JULPwivA==}
+
   '@testing-library/[email protected]':
     resolution: {integrity: sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ==}
     engines: {node: '>=18'}
@@ -3078,6 +3084,10 @@ snapshots:
   '@rollup/[email protected]':
     optional: true
 
+  '@sv443-network/[email protected]':
+    dependencies:
+      nanoevents: 9.1.0
+
   '@testing-library/[email protected]':
     dependencies:
       '@babel/code-frame': 7.26.2

+ 1 - 1
tsconfig.json

@@ -2,7 +2,7 @@
   "compilerOptions": {
     "module": "NodeNext",
     "moduleResolution": "NodeNext",
-    "target": "ES2016",
+    "target": "ES2018",
     "outDir": "dist/out",
     "lib": ["ES2022", "DOM", "DOM.Iterable"],
     "baseUrl": ".",

+ 3 - 2
vitest.config.ts

@@ -8,8 +8,9 @@ export default defineConfig({
       include: ["lib/**/*.ts"],
       exclude: [
         "lib/**/*.spec.ts",
-        "lib/Dialog.ts", // DOM-only features can't be tested for now cause they aren't rendered
-        "lib/SelectorObserver.ts", // ^
+        "lib/dom.ts",              // partially tested, but since some features can just never be tested, exclude the file from report
+        "lib/Dialog.ts",           // DOM-only features can't be tested for now cause they aren't properly rendered, just mounted into a pseudo-DOM
+        "lib/SelectorObserver.ts", // same here ^
         "lib/errors.ts",
         "lib/index.ts",
       ],