@adonisjs/assembler 8.0.0-next.24 → 8.0.0-next.26

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.
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as loadHooks, c as readTsConfig, d as runNode, f as throttle, m as debug_default, n as copyFiles, o as memoize, p as watch, r as getPort, s as parseConfig, t as VirtualFileSystem, u as run } from "./virtual_file_system-bGeoWsK-.js";
2
2
  import { n as FileBuffer, t as IndexGenerator } from "./main-XUXlmlEy.js";
3
- import { t as RoutesScanner } from "./main-DcPeMQQd.js";
3
+ import { t as RoutesScanner } from "./main-BSWlOK0F.js";
4
4
  import "./helpers-DDurYRsZ.js";
5
5
  import dedent from "dedent";
6
6
  import fs, { readFile, unlink } from "node:fs/promises";
@@ -108,7 +108,7 @@ var Bundler = class {
108
108
  "buildFinished"
109
109
  ]);
110
110
  this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger);
111
- await this.#hooks.runner("init").run(this, this.#indexGenerator);
111
+ await this.#hooks.runner("init").run(this, this.#hooks, this.#indexGenerator);
112
112
  this.#hooks.clear("init");
113
113
  this.ui.logger.info("generating indexes...");
114
114
  await this.#indexGenerator.generate();
@@ -568,7 +568,7 @@ var DevServer = class DevServer {
568
568
  ]);
569
569
  this.#registerServerRestartHooks();
570
570
  this.#setupKeyboardShortcuts();
571
- await this.#hooks.runner("init").run(this, this.#indexGenerator);
571
+ await this.#hooks.runner("init").run(this, this.#hooks, this.#indexGenerator);
572
572
  this.#hooks.clear("init");
573
573
  this.ui.logger.info("generating indexes...");
574
574
  await this.#indexGenerator.generate();
@@ -855,7 +855,7 @@ var TestRunner = class {
855
855
  "testsStarting",
856
856
  "testsFinished"
857
857
  ]);
858
- await this.#hooks.runner("init").run(this, this.#indexGenerator);
858
+ await this.#hooks.runner("init").run(this, this.#hooks, this.#indexGenerator);
859
859
  this.#hooks.clear("init");
860
860
  this.ui.logger.info("generating indexes...");
861
861
  await this.#indexGenerator.generate();
@@ -888,7 +888,7 @@ var TestRunner = class {
888
888
  "fileRemoved"
889
889
  ]);
890
890
  this.#registerServerRestartHooks();
891
- await this.#hooks.runner("init").run(this, this.#indexGenerator);
891
+ await this.#hooks.runner("init").run(this, this.#hooks, this.#indexGenerator);
892
892
  this.#hooks.clear("init");
893
893
  this.ui.logger.info("generating indexes...");
894
894
  await this.#indexGenerator.generate();
@@ -79,6 +79,7 @@ async function extractValidators(appRoot, vfs, controller) {
79
79
  }))).filter((value) => !!value);
80
80
  }
81
81
  var RoutesScanner = class {
82
+ #filter;
82
83
  #appRoot;
83
84
  #controllerRoutes = {};
84
85
  #scannedRoutes = [];
@@ -88,7 +89,6 @@ var RoutesScanner = class {
88
89
  ui = cliui();
89
90
  pathsResolver;
90
91
  rules = {
91
- skip: [],
92
92
  request: {},
93
93
  response: {}
94
94
  };
@@ -96,11 +96,13 @@ var RoutesScanner = class {
96
96
  this.#appRoot = appRoot;
97
97
  this.pathsResolver = new PathsResolver(appRoot);
98
98
  rulesCollection.forEach((rules) => {
99
- this.rules.skip = this.rules.skip.concat(rules.skip);
100
99
  Object.assign(this.rules.request, rules.request);
101
100
  Object.assign(this.rules.response, rules.response);
102
101
  });
103
- this.rules.skip = Array.from(new Set([...this.rules.skip]));
102
+ }
103
+ #shouldSkipRoute(route) {
104
+ if (this.#filter) return !this.#filter(route);
105
+ return false;
104
106
  }
105
107
  #prepareRequestTypes(route) {
106
108
  if (!route.validators) return;
@@ -166,16 +168,16 @@ var RoutesScanner = class {
166
168
  const controller = await this.#inspectControllerSpecifier(route.handler.importExpression, route.handler.method);
167
169
  if (!controller) return this.#processRouteWithoutController(route);
168
170
  debug_default("processing route \"%s\" with inspected controller %O", route.name, controller);
169
- const routeName = route.name ?? new StringBuilder(controller.name).removeSuffix("Controller").snakeCase().suffix(`.${string.snakeCase(controller.method)}`).toString();
170
- if (this.rules.skip.includes(routeName)) return;
171
+ route.name = route.name ?? new StringBuilder(controller.name).removeSuffix("Controller").snakeCase().suffix(`.${string.snakeCase(controller.method)}`).toString();
172
+ if (this.#shouldSkipRoute(route)) return;
171
173
  const scannedRoute = {
172
- name: routeName,
174
+ name: route.name,
173
175
  domain: route.domain,
174
176
  methods: route.methods,
175
177
  pattern: route.pattern,
176
178
  tokens: route.tokens,
177
- request: this.rules.request[routeName],
178
- response: this.rules.response[routeName],
179
+ request: this.rules.request[route.name],
180
+ response: this.rules.response[route.name],
179
181
  controller
180
182
  };
181
183
  debug_default("scanned route %O", scannedRoute);
@@ -189,7 +191,7 @@ var RoutesScanner = class {
189
191
  }
190
192
  }
191
193
  async #processRoute(route, vfs) {
192
- if (route.name && this.rules.skip.includes(route.name)) {
194
+ if (route.name && this.#shouldSkipRoute(route)) {
193
195
  debug_default("route skipped route: %O, rules: %O", route, this.rules);
194
196
  return;
195
197
  }
@@ -231,6 +233,10 @@ var RoutesScanner = class {
231
233
  }
232
234
  return true;
233
235
  }
236
+ filter(filterFn) {
237
+ this.#filter = filterFn;
238
+ return this;
239
+ }
234
240
  async scan(routes) {
235
241
  const vfs = new VirtualFileSystem(this.#appRoot);
236
242
  for (const route of routes) await this.#processRoute(route, vfs);
@@ -1,6 +1,6 @@
1
1
  import { type AsyncOrSync } from '@poppinss/utils/types';
2
2
  import { PathsResolver } from '../../paths_resolver.ts';
3
- import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules } from '../../types/code_scanners.ts';
3
+ import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules, type RoutesScannerFilterFn } from '../../types/code_scanners.ts';
4
4
  /**
5
5
  * RoutesScanner is responsible for scanning application routes,
6
6
  * extracting their controllers, validators, request and response types.
@@ -106,6 +106,18 @@ export declare class RoutesScanner {
106
106
  * @param controllerPath - Path to the controller file to invalidate
107
107
  */
108
108
  invalidate(controllerPath: string): Promise<boolean>;
109
+ /**
110
+ * Sets a filter function to selectively include routes during scanning.
111
+ *
112
+ * @param filterFn - Function that returns true for routes to include
113
+ * @returns This RoutesScanner instance for method chaining
114
+ *
115
+ * @example
116
+ * scanner.filter((route) => {
117
+ * return route.pattern.startsWith('/api')
118
+ * })
119
+ */
120
+ filter(filterFn: RoutesScannerFilterFn): this;
109
121
  /**
110
122
  * Scans an array of Route list items and fetches their validators,
111
123
  * controllers, and request/response types.
@@ -1,4 +1,4 @@
1
1
  import "../../../virtual_file_system-bGeoWsK-.js";
2
- import { t as RoutesScanner } from "../../../main-DcPeMQQd.js";
2
+ import { t as RoutesScanner } from "../../../main-BSWlOK0F.js";
3
3
  import "../../../helpers-DDurYRsZ.js";
4
4
  export { RoutesScanner };
@@ -174,8 +174,11 @@ export type RoutesListItem = {
174
174
  domain: string;
175
175
  /** HTTP methods accepted by this route */
176
176
  methods: string[];
177
+ /** Handler information for controller-based routes */
177
178
  handler?: {
179
+ /** The method name to be called on the controller */
178
180
  method: string;
181
+ /** Dynamic import expression that loads the controller module */
179
182
  importExpression: string | null;
180
183
  };
181
184
  /** Parsed route tokens for URI construction */
@@ -186,6 +189,27 @@ export type RoutesListItem = {
186
189
  end: string;
187
190
  }[];
188
191
  };
192
+ /**
193
+ * A filter function to exclude routes from being processed by the routes scanner.
194
+ * Return false to filter out (exclude) the route, or true to include it.
195
+ *
196
+ * @example
197
+ * const filterFn: RoutesScannerFilterFn = (route) => {
198
+ * // Exclude all admin routes
199
+ * if (route.pattern.startsWith('/admin')) {
200
+ * return false
201
+ * }
202
+ *
203
+ * // Exclude health check routes
204
+ * if (route.name === 'health.check') {
205
+ * return false
206
+ * }
207
+ *
208
+ * // Include all other routes
209
+ * return true
210
+ * }
211
+ */
212
+ export type RoutesScannerFilterFn = (route: RoutesListItem) => boolean;
189
213
  /**
190
214
  * Configuration rules accepted by the routes scanner to customize
191
215
  * the scanning behavior and override type inference.
@@ -208,11 +232,6 @@ export type RoutesListItem = {
208
232
  * }
209
233
  */
210
234
  export type RoutesScannerRules = {
211
- /**
212
- * An array of route names or controller+method paths to skip from processing.
213
- * Useful for excluding routes that don't need type generation.
214
- */
215
- skip: string[];
216
235
  /**
217
236
  * Define custom response types for specific routes by their name
218
237
  * or controller+method path. Overrides automatic type inference.
@@ -6,6 +6,7 @@ import { type TestRunner } from '../test_runner.ts';
6
6
  import { type RoutesListItem } from './code_scanners.ts';
7
7
  import { type IndexGenerator } from '../index_generator/main.ts';
8
8
  import { type RoutesScanner } from '../code_scanners/routes_scanner/main.ts';
9
+ import type Hooks from '@poppinss/hooks';
9
10
  /**
10
11
  * Defines a hook that can be either a lazy import or an object with a run method.
11
12
  * This type provides flexibility in how hooks are defined and imported, supporting
@@ -45,7 +46,9 @@ export type CommonHooks = {
45
46
  *
46
47
  * @param parent - The parent instance (DevServer, TestRunner, or Bundler)
47
48
  */
48
- init: DefineHook<(parent: DevServer | TestRunner | Bundler, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
49
+ init: DefineHook<(parent: DevServer | TestRunner | Bundler, hooks: Hooks<{
50
+ [P in keyof AllHooks]: [HookParams<P>, HookParams<P>];
51
+ }>, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
49
52
  };
50
53
  /**
51
54
  * Hooks executed by the dev server around the router.
@@ -148,7 +148,9 @@ export declare function isRelative(pathValue: string): boolean;
148
148
  * @param names - Array of hook names to load
149
149
  * @returns Promise resolving to configured Hooks instance
150
150
  */
151
- export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{ [P in K]: [HookParams<P>, HookParams<P>]; }>>;
151
+ export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{
152
+ [P in K]: [HookParams<P>, HookParams<P>];
153
+ }>>;
152
154
  /**
153
155
  * Wraps a function inside another function that throttles the concurrent
154
156
  * executions of a function. If the function is called too quickly, then
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
3
  "description": "Provides utilities to run AdonisJS development server and build project for production",
4
- "version": "8.0.0-next.24",
4
+ "version": "8.0.0-next.26",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },