Skip to content

Commit 1c57e01

Browse files
committed
feat: add support for invalidating controllers
1 parent df149cb commit 1c57e01

File tree

3 files changed

+582
-8
lines changed

3 files changed

+582
-8
lines changed

src/code_scanners/routes_scanner/main.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,32 @@ export class RoutesScanner {
384384
return this
385385
}
386386

387+
/**
388+
* Returns the scanned routes
389+
*/
390+
getScannedRoutes() {
391+
return this.#scannedRoutes
392+
}
393+
394+
/**
395+
* Invalidating a controller will trigger computing the validators,
396+
* request types and the response types.
397+
*/
398+
async invalidate(controllerPath: string) {
399+
const controllerRoutes = this.#controllerRoutes[controllerPath]
400+
if (!controllerRoutes) {
401+
return
402+
}
403+
404+
this.astFileSystem.clear(controllerPath)
405+
for (let scannedRoute of controllerRoutes) {
406+
if (scannedRoute.controller) {
407+
await this.#setResponse(scannedRoute, scannedRoute.controller)
408+
await this.#setRequest(scannedRoute, scannedRoute.controller)
409+
}
410+
}
411+
}
412+
387413
/**
388414
* Scans an array of Route list items and fetches their validators,
389415
* controllers, and request/response types.
@@ -394,6 +420,5 @@ export class RoutesScanner {
394420
}
395421

396422
this.astFileSystem.clear()
397-
return this.#scannedRoutes
398423
}
399424
}

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { copyFile, mkdir } from 'node:fs/promises'
2121
import { EnvLoader, EnvParser } from '@adonisjs/env'
2222
import chokidar, { type ChokidarOptions } from 'chokidar'
2323
import { type UnWrapLazyImport } from '@poppinss/utils/types'
24-
import path, { basename, dirname, isAbsolute, join, relative } from 'node:path'
24+
import { basename, dirname, isAbsolute, join, relative } from 'node:path'
2525

2626
import debug from './debug.ts'
2727
import type { RunScriptOptions } from './types/common.ts'

0 commit comments

Comments
 (0)