Skip to content

Commit efef1c4

Browse files
committed
fix: chokidar does not built-in glob support
1 parent 4f8b980 commit efef1c4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

builder/source/build.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ export type BuildOptions = {
1313
Minify: boolean
1414
UseCache: boolean
1515
BuildType: 'production' | 'development',
16-
SubscriptionUrl: string
16+
SubscriptionUrl: string,
17+
Version?: string
1718
}
1819

1920
export async function Build(OptionsParam?: BuildOptions): Promise<void> {
2021
const Options = await Zod.strictObject({
2122
Minify: Zod.boolean(),
2223
UseCache: Zod.boolean(),
2324
BuildType: Zod.enum(['production', 'development']),
24-
SubscriptionUrl: Zod.string().transform(Value => new URL(Value)).default(new URL('https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@latest/dist/tinyShield.user.js'))
25+
SubscriptionUrl: Zod.string().transform(Value => new URL(Value)).default(new URL('https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@latest/dist/tinyShield.user.js')),
26+
Version: Zod.string().optional()
2527
}).parseAsync(OptionsParam)
2628

2729
let MatchingDomains: Set<string> = new Set<string>()
@@ -46,7 +48,7 @@ export async function Build(OptionsParam?: BuildOptions): Promise<void> {
4648
}
4749

4850
const Banner = CreateBanner({
49-
Version: (await PackageJson.load(ProjectRoot)).content.version ?? '0.0.0',
51+
Version: Options.Version ?? (await PackageJson.load(ProjectRoot)).content.version ?? '0.0.0',
5052
BuildType: Options.BuildType ?? 'production',
5153
Domains: MatchingDomains,
5254
Name: 'tinyShield',

builder/source/debug.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as Chokidar from 'chokidar'
33
import * as Process from 'node:process'
44
import * as Crypto from 'node:crypto'
5+
import * as Fs from 'node:fs'
56
import { RunDebugServer } from './utils/http-server.js'
67
import { Build } from './build.js'
78

@@ -11,31 +12,28 @@ if (Process.cwd().endsWith('/builder')) {
1112
}
1213
const WatchingGlob = [];
1314
['builder/', 'userscript/', ''].forEach(Dir => {
14-
WatchingGlob.push(`${ProjectRoot}/${Dir}sources/**/*.ts`)
15-
WatchingGlob.push(`${ProjectRoot}/${Dir}sources/**/*.json`)
16-
WatchingGlob.push(`${ProjectRoot}/${Dir}sources/**/*.txt`)
15+
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.ts`))
16+
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.json`))
17+
WatchingGlob.push(...Fs.globSync(`${ProjectRoot}/${Dir}source/**/*.txt`))
1718
})
18-
const Watcher = Chokidar.watch([
19-
`${ProjectRoot}/sources/**/*.ts`,
20-
`${ProjectRoot}/sources/**/*.json`
21-
], {
22-
cwd: ProjectRoot,
19+
const Watcher = Chokidar.watch([...WatchingGlob], {
2320
ignored: '**/node_modules/**',
2421
})
2522

2623
let BuildCooldownTimer: NodeJS.Timeout = null
2724
let ShouldPreventHTTPResponse = false
28-
Watcher.on('all', (WatcherEvent, WatcherPath) => {
25+
let Version: number = 0
26+
Watcher.on('all', async (WatcherEvent, WatcherPath) => {
2927
clearTimeout(BuildCooldownTimer)
3028
BuildCooldownTimer = setTimeout(async () => {
3129
console.log(`Detected file change (${WatcherEvent}):`, WatcherPath)
3230
ShouldPreventHTTPResponse = true
33-
await Build({ Minify: false, UseCache: true, BuildType: 'development', SubscriptionUrl: `http://localhost:${RandomPort}/tinyShield.dev.user.js` })
31+
await Build({ Version: `0.0.${Version}`, Minify: false, UseCache: true, BuildType: 'development', SubscriptionUrl: `http://localhost:${RandomPort}/tinyShield.dev.user.js` })
32+
Version++
3433
ShouldPreventHTTPResponse = false
3534
}, 1500)
3635
})
3736

3837
let RandomPort = Crypto.randomInt(8000, 8999)
39-
await Build({ Minify: false, UseCache: true, BuildType: 'development', SubscriptionUrl: `http://localhost:${RandomPort}/tinyShield.dev.user.js` })
4038
RunDebugServer(RandomPort, ['tinyShield.dev.user.js'], ShouldPreventHTTPResponse)
4139
console.log(`Debug HTTP server running on http://localhost:${RandomPort}/tinyShield.dev.user.js`)

0 commit comments

Comments
 (0)