Skip to content

Commit 0c69c91

Browse files
committed
feat: Implement Ad-Shield domain filtering and wildcard handling
- Add SafeArrayToString utility for safe array string conversion. - Introduce custom-defined matches and exclusion sets for domain filtering. - Create functions to fetch Ad-Shield domains from AdGuard and uBlock Origin filter lists. - Implement logic to parse and filter Ad-Shield domains, including CDN checks. - Add IAB sellers fetching functionality with validation. - Develop utility functions for domain wildcard handling and grouping by TLD. - Enhance testing suite with comprehensive tests for new functionalities. - Update TypeScript configuration for libraries and userscript. - Modify package.json scripts for improved build processes and workspace management.
1 parent a88809c commit 0c69c91

30 files changed

Lines changed: 709 additions & 224 deletions

.github/workflows/npm.yml

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: 'Publish to npm'
1+
name: "Publish to npm"
22
on:
33
release:
44
types: [published]
55
push:
66
tags:
7-
- '*.*.*-build.*'
7+
- "*.*.*-build.*"
88

99
jobs:
1010
release:
@@ -17,8 +17,8 @@ jobs:
1717
- name: Set up NodeJS LTS
1818
uses: actions/setup-node@v6
1919
with:
20-
node-version: 'lts/*'
21-
registry-url: 'https://registry.npmjs.org'
20+
node-version: "lts/*"
21+
registry-url: "https://registry.npmjs.org"
2222
- name: Update npm package manager
2323
run: npm install -g npm@latest
2424
- name: Checkout
@@ -29,11 +29,17 @@ jobs:
2929
run: mkdir -p ~/.pnpm-store && pnpm config set store-dir ~/.pnpm-store
3030
- name: Install dependencies
3131
run: pnpm install --no-lockfile
32-
- name: Bump package.json version from tag
32+
- name: Bump @filteringdev/tinyshield package.json version from tag
3333
uses: TypescriptPrime/bump-packagejson-version@72720c4d073ed0c5b9e9393d7334abfe3fabb47c
34+
- name: Bump @filteringdev/tinyshield-lib package.json version from tag
35+
run: npm pkg set version="${GITHUB_REF_NAME#v}" -w libs
3436
- name: Build
3537
run: npm run build
36-
- name : Publish to npm
38+
- name: Publish @filteringdev/tinyshield to npm
39+
working-directory: .
40+
run: npm publish --access public
41+
- name: Publish @filteringdev/tinyshield-lib to npm
42+
working-directory: libs
3743
run: npm publish --access public
3844
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
3945
beta-release:
@@ -46,8 +52,8 @@ jobs:
4652
- name: Set up NodeJS LTS
4753
uses: actions/setup-node@v6
4854
with:
49-
node-version: 'lts/*'
50-
registry-url: 'https://registry.npmjs.org'
55+
node-version: "lts/*"
56+
registry-url: "https://registry.npmjs.org"
5157
- name: Update npm package manager
5258
run: npm install -g npm@latest
5359
- name: Checkout
@@ -58,11 +64,17 @@ jobs:
5864
run: mkdir -p ~/.pnpm-store && pnpm config set store-dir ~/.pnpm-store
5965
- name: Install dependencies
6066
run: pnpm install --no-lockfile
61-
- name: Bump package.json version from tag
67+
- name: Bump @filteringdev/tinyshield package.json version from tag
6268
uses: TypescriptPrime/bump-packagejson-version@72720c4d073ed0c5b9e9393d7334abfe3fabb47c
69+
- name: Bump @filteringdev/tinyshield-lib package.json version from tag
70+
run: npm pkg set version="${GITHUB_REF_NAME#v}" -w libs
6371
- name: Build
6472
run: npm run build
65-
- name : Publish to npm
73+
- name: Publish @filteringdev/tinyshield to npm
74+
working-directory: .
75+
run: npm publish --tag beta --access public
76+
- name: Publish @filteringdev/tinyshield-lib to npm
77+
working-directory: libs
6678
run: npm publish --tag beta --access public
6779
if: ${{ github.event_name == 'release' && github.event.release.prerelease == true && contains(github.event.release.tag_name, '-beta.') }}
6880
build-release:
@@ -75,8 +87,8 @@ jobs:
7587
- name: Set up NodeJS LTS
7688
uses: actions/setup-node@v6
7789
with:
78-
node-version: 'lts/*'
79-
registry-url: 'https://registry.npmjs.org'
90+
node-version: "lts/*"
91+
registry-url: "https://registry.npmjs.org"
8092
- name: Update npm package manager
8193
run: npm install -g npm@latest
8294
- name: Checkout
@@ -87,11 +99,17 @@ jobs:
8799
run: mkdir -p ~/.pnpm-store && pnpm config set store-dir ~/.pnpm-store
88100
- name: Install dependencies
89101
run: pnpm install --no-lockfile
90-
- name: Bump package.json version from tag
102+
- name: Bump @filteringdev/tinyshield package.json version from tag
91103
uses: TypescriptPrime/bump-packagejson-version@72720c4d073ed0c5b9e9393d7334abfe3fabb47c
104+
- name: Bump @filteringdev/tinyshield-lib package.json version from tag
105+
run: npm pkg set version="${GITHUB_REF_NAME#v}" -w libs
92106
- name: Build
93107
run: npm run build
94-
- name : Publish to npm
108+
- name: Publish @filteringdev/tinyshield to npm
109+
working-directory: .
110+
run: npm publish --tag build --access public
111+
- name: Publish @filteringdev/tinyshield-lib to npm
112+
working-directory: libs
95113
run: npm publish --tag build --access public
96114
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-build.') }}
97115
purge:
@@ -104,10 +122,10 @@ jobs:
104122
- name: Set up NodeJS LTS
105123
uses: actions/setup-node@v6
106124
with:
107-
node-version: 'lts/*'
125+
node-version: "lts/*"
108126
- name: Purge jsdelivr cache
109127
uses: FilteringDev/jsdelivr-purge-npm@0bee790e911f359243cd8d98cd87f6bbbc879e80
110128
with:
111-
package: '@filteringdev/tinyshield'
112-
disttag: 'latest'
113-
needs: [release]
129+
package: "@filteringdev/tinyshield"
130+
disttag: "latest"
131+
needs: [release]

builder/package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"lint": "tsc --noEmit && eslint **/*.ts",
77
"build": "tsx source/buildci.ts",
88
"debug": "tsx source/debug.ts",
9-
"test": "npm run test:utils",
10-
"test:utils": "ava test/utils/**/*.test.ts"
9+
"test": "echo \"Builder tests moved to @filteringdev/tinyshield-lib.\"",
10+
"test:utils": "echo \"Builder utility tests moved to @filteringdev/tinyshield-lib.\""
1111
},
1212
"dependencies": {
13-
"@types/node": "^24.12.2"
13+
"@types/node": "^24.12.2",
14+
"@filteringdev/tinyshield-lib": "workspace:*"
1415
},
1516
"ava": {
1617
"files": [
@@ -28,20 +29,15 @@
2829
}
2930
},
3031
"devDependencies": {
31-
"@adguard/agtree": "^4.1.1",
32-
"@ava/typescript": "^7.0.0",
3332
"@npmcli/package-json": "^8.0.0",
3433
"@types/npmcli__package-json": "^4.0.4",
3534
"@typescript-eslint/eslint-plugin": "^8.59.2",
3635
"@typescript-eslint/parser": "^8.59.2",
3736
"@typescriptprime/parsing": "^2.0.1",
38-
"@typescriptprime/securereq": "^2.0.0",
39-
"ava": "^8.0.0",
4037
"chokidar": "^5.0.0",
4138
"esbuild": "^0.28.0",
4239
"eslint": "^10.3.0",
4340
"piscina": "^5.1.4",
44-
"tldts": "^7.0.30",
4541
"tsx": "^4.21.0",
4642
"typescript": "^6.0.3",
4743
"typescript-eslint": "^8.59.2",

builder/source/build-core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Zod from 'zod'
22
import * as Process from 'node:process'
3-
import { FetchAdShieldDomains, type TASDomainContainer } from './references/index.js'
3+
import { FetchAdShieldDomains, type TASDomainContainer } from '@filteringdev/tinyshield-lib/references'
44
import { SafeInitCwd } from './utils/safe-init-cwd.js'
55

66
export type BuildOptions = {

builder/source/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Build } from './build-core.js'
99

1010
let ProjectRoot = SafeInitCwd({ Cwd: Process.cwd(), InitCwd: Process.env.INIT_CWD })
1111
const WatchingGlob: string[] = []
12-
for (const Dir of ['builder/', 'userscript/', '']) {
12+
for (const Dir of ['builder/', 'userscript/', 'libs/', '']) {
1313
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.ts`))
1414
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.json`))
1515
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.txt`))

libs/package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@filteringdev/tinyshield-lib",
3+
"version": "0.0.0",
4+
"description": "Library APIs for tinyShield userscript monkey patches and reference domain loading.",
5+
"type": "module",
6+
"files": [
7+
"dist/**/*"
8+
],
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.js"
13+
},
14+
"./monkey-patches": {
15+
"types": "./dist/monkey-patches/index.d.ts",
16+
"import": "./dist/monkey-patches/index.js"
17+
},
18+
"./references": {
19+
"types": "./dist/references/index.d.ts",
20+
"import": "./dist/references/index.js"
21+
}
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/FilteringDev/tinyShield.git"
26+
},
27+
"types": "./dist/index.d.ts",
28+
"scripts": {
29+
"build": "tsc -p tsconfig.json",
30+
"lint": "tsc --noEmit && eslint source/**/*.ts test/**/*.ts",
31+
"test": "npm run build && ava test/**/*.test.ts"
32+
},
33+
"dependencies": {
34+
"@adguard/agtree": "^4.1.1",
35+
"@typescriptprime/securereq": "^2.0.0",
36+
"tldts": "^7.0.30",
37+
"zod": "^4.4.3"
38+
},
39+
"devDependencies": {
40+
"@ava/typescript": "^7.0.0",
41+
"@types/node": "^24.12.2",
42+
"@types/web": "^0.0.349",
43+
"@typescript-eslint/eslint-plugin": "^8.59.2",
44+
"@typescript-eslint/parser": "^8.59.2",
45+
"ava": "^8.0.0",
46+
"eslint": "^10.3.0",
47+
"tsx": "^4.21.0",
48+
"typescript": "^6.0.3",
49+
"typescript-eslint": "^8.59.2"
50+
},
51+
"ava": {
52+
"files": [
53+
"test/**/*.test.ts"
54+
],
55+
"nodeArguments": [
56+
"--import=tsx"
57+
],
58+
"workerThreads": false,
59+
"typescript": {
60+
"compile": false,
61+
"rewritePaths": {
62+
"source/": "dist/"
63+
}
64+
}
65+
}
66+
}

libs/source/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export {
2+
CreateTinyShieldController,
3+
EnableTinyShield,
4+
TinyShieldPatchIds,
5+
type TinyShieldController,
6+
type TinyShieldControllerOptions,
7+
type TinyShieldPatchController,
8+
type TinyShieldPatchId,
9+
type TinyShieldWindow
10+
} from './monkey-patches/index.js'
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
* - See Git history at https://github.com/FilteringDev/tinyShield for detailed authorship information.
99
*/
1010

11-
import { OriginalRegExpTest } from './index.js'
12-
13-
type CheckDepthResult = { Status: 'matched' } | { Status: 'not-matched' } | { Status: 'too-expensive' } | { Status: 'unsafe-object'; Reason: unknown }
14-
15-
type CheckBudget = {
16-
MaxTopLevelKeys: number;
17-
MaxArrayItems: number;
18-
MaxInnerKeysPerObject: number;
19-
MaxOperations: number;
20-
};
11+
export type CheckDepthResult =
12+
{ Status: 'matched' } |
13+
{ Status: 'not-matched' } |
14+
{ Status: 'too-expensive' } |
15+
{ Status: 'unsafe-object'; Reason: unknown }
16+
17+
export type CheckBudget = {
18+
MaxTopLevelKeys: number
19+
MaxArrayItems: number
20+
MaxInnerKeysPerObject: number
21+
MaxOperations: number
22+
}
2123

2224
const DefaultBudget: CheckBudget = {
2325
MaxTopLevelKeys: 300,
@@ -48,6 +50,7 @@ function CountCommonKnownKeys(Obj: object): number {
4850
export function CheckDepthInASWeakMapBudgeted(
4951
Args: [object, unknown],
5052
Budget: CheckBudget = DefaultBudget,
53+
OriginalRegExpTest: typeof RegExp.prototype.test = RegExp.prototype.test,
5154
): CheckDepthResult {
5255
let Operations = 0
5356

@@ -133,7 +136,7 @@ export function CheckDepthInASWeakMapBudgeted(
133136
}
134137

135138
return { Status: 'not-matched' }
136-
} catch (error) {
137-
return { Status: 'unsafe-object', Reason: error }
139+
} catch (Error) {
140+
return { Status: 'unsafe-object', Reason: Error }
138141
}
139-
}
142+
}

0 commit comments

Comments
 (0)