@adonisjs/assembler 8.0.0-next.14 → 8.0.0-next.16

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,7 +1,11 @@
1
1
  import {
2
2
  FileBuffer,
3
3
  IndexGenerator
4
- } from "./chunk-TWCIFDZF.js";
4
+ } from "./chunk-YFDLKKOA.js";
5
+ import {
6
+ RoutesScanner
7
+ } from "./chunk-WG7JQZUU.js";
8
+ import "./chunk-TIKQQRMX.js";
5
9
  import {
6
10
  VirtualFileSystem,
7
11
  copyFiles,
@@ -10,11 +14,12 @@ import {
10
14
  loadHooks,
11
15
  memoize,
12
16
  parseConfig,
17
+ readTsConfig,
13
18
  run,
14
19
  runNode,
15
20
  throttle,
16
21
  watch
17
- } from "./chunk-7ANGUQDV.js";
22
+ } from "./chunk-HRE5L24F.js";
18
23
 
19
24
  // src/bundler.ts
20
25
  import dedent from "dedent";
@@ -223,6 +228,7 @@ import prettyHrtime from "pretty-hrtime";
223
228
  import { fileURLToPath as fileURLToPath2 } from "url";
224
229
  import string3 from "@poppinss/utils/string";
225
230
  import { join as join2, relative as relative3 } from "path/posix";
231
+ import { readFile, unlink } from "fs/promises";
226
232
  import { RuntimeException } from "@poppinss/utils/exception";
227
233
 
228
234
  // src/file_system.ts
@@ -388,16 +394,16 @@ var FileSystem = class {
388
394
  constructor(cwd, tsConfig, rcFile) {
389
395
  this.#cwd = cwd;
390
396
  this.#tsConfig = tsConfig;
391
- const files = tsConfig.fileNames;
397
+ const files = tsConfig.config.files ?? [];
392
398
  const metaFiles = rcFile.metaFiles ?? [];
393
399
  const testSuites = rcFile.suites ?? [];
394
- const outDir = tsConfig.raw.compilerOptions?.outDir;
400
+ const outDir = tsConfig.config.compilerOptions?.outDir;
395
401
  for (const file of files) {
396
402
  this.#scannedTypeScriptFiles.add(string2.toUnixSlash(file));
397
403
  }
398
- this.#includes = tsConfig.raw.include || DEFAULT_INCLUDES;
404
+ this.#includes = tsConfig.config.include || DEFAULT_INCLUDES;
399
405
  this.#excludes = ALWAYS_EXCLUDE.concat(
400
- tsConfig.raw.exclude || (outDir ? DEFAULT_EXCLUDES.concat(outDir) : DEFAULT_EXCLUDES)
406
+ tsConfig.config.exclude || (outDir ? DEFAULT_EXCLUDES.concat(outDir) : DEFAULT_EXCLUDES)
401
407
  );
402
408
  const metaFilesWithReloads = [];
403
409
  const metaFilesWithoutReloads = [];
@@ -439,10 +445,10 @@ var FileSystem = class {
439
445
  if ((relativePath.endsWith(".ts") || relativePath.endsWith(".tsx")) && !relativePath.endsWith(".d.ts")) {
440
446
  return true;
441
447
  }
442
- if (this.#tsConfig.options.allowJs && relativePath.endsWith(".js")) {
448
+ if (this.#tsConfig.config.compilerOptions?.allowJs && relativePath.endsWith(".js")) {
443
449
  return true;
444
450
  }
445
- if (this.#tsConfig.options.resolveJsonModule && relativePath.endsWith(".json")) {
451
+ if (this.#tsConfig.config.compilerOptions?.resolveJsonModule && relativePath.endsWith(".json")) {
446
452
  return true;
447
453
  }
448
454
  return false;
@@ -697,6 +703,11 @@ var DevServer = class _DevServer {
697
703
  * Index generator for managing auto-generated index files
698
704
  */
699
705
  #indexGenerator;
706
+ /**
707
+ * Routes scanner to scan routes and infer route request and
708
+ * response data
709
+ */
710
+ #routesScanner;
700
711
  /**
701
712
  * Hooks to execute custom actions during the dev server lifecycle
702
713
  */
@@ -743,7 +754,12 @@ var DevServer = class _DevServer {
743
754
  this.#shortcutsManager?.cleanup();
744
755
  }
745
756
  /**
746
- * The mode in which the DevServer is running.
757
+ * The mode in which the DevServer is running
758
+ *
759
+ * Returns the current operating mode of the development server:
760
+ * - 'hmr': Hot Module Reloading enabled
761
+ * - 'watch': File system watching with full restarts
762
+ * - 'static': No file watching or hot reloading
747
763
  */
748
764
  get mode() {
749
765
  return this.#mode;
@@ -787,6 +803,18 @@ var DevServer = class _DevServer {
787
803
  #isAdonisJSReadyMessage(message) {
788
804
  return message !== null && typeof message === "object" && "isAdonisJS" in message && "environment" in message && message.environment === "web";
789
805
  }
806
+ /**
807
+ * Type guard to check if child process message contains routes information
808
+ *
809
+ * Validates that a message from the child process contains the expected
810
+ * structure with routes file location from the AdonisJS server.
811
+ *
812
+ * @param message - Unknown message from child process
813
+ * @returns True if message contains routes file location
814
+ */
815
+ #isAdonisJSRoutesMessage(message) {
816
+ return message !== null && typeof message === "object" && "routesFileLocation" in message;
817
+ }
790
818
  /**
791
819
  * Displays server information and executes hooks after server startup
792
820
  *
@@ -888,6 +916,66 @@ var DevServer = class _DevServer {
888
916
  }
889
917
  return this.#indexGenerator.removeFile(filePath);
890
918
  }
919
+ /**
920
+ * Re-scans routes when a file is modified during hot reloading
921
+ *
922
+ * Invalidates the routes cache for the given file and triggers route
923
+ * scanning hooks if the invalidation was successful.
924
+ *
925
+ * @param filePath - Absolute path to the file that was modified
926
+ *
927
+ * @example
928
+ * await devServer.#reScanRoutes('/path/to/routes.ts')
929
+ */
930
+ async #reScanRoutes(filePath) {
931
+ if (!this.#routesScanner) {
932
+ return;
933
+ }
934
+ const invalidated = await this.#routesScanner.invalidate(filePath);
935
+ if (invalidated) {
936
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
937
+ }
938
+ }
939
+ /**
940
+ * Processes routes received from the AdonisJS server
941
+ *
942
+ * Executes routesCommitted hooks and optionally scans routes if scanning
943
+ * hooks are registered. Creates a routes scanner instance if needed and
944
+ * processes routes for each domain.
945
+ *
946
+ * @param routesList - Routes organized by domain
947
+ *
948
+ * @example
949
+ * await devServer.#processRoutes({
950
+ * 'example.com': [
951
+ * { pattern: '/', handler: 'HomeController.index' }
952
+ * ]
953
+ * })
954
+ */
955
+ #processRoutes = throttle(async (routesFileLocation) => {
956
+ const scanRoutes = this.#hooks.has("routesScanning") || this.#hooks.has("routesScanned");
957
+ const shareRoutes = this.#hooks.has("routesCommitted");
958
+ if (!scanRoutes && !shareRoutes) {
959
+ unlink(routesFileLocation).catch(() => {
960
+ });
961
+ return;
962
+ }
963
+ const routesJSON = await readFile(routesFileLocation, "utf-8");
964
+ const routesList = JSON.parse(routesJSON);
965
+ unlink(routesFileLocation).catch(() => {
966
+ });
967
+ if (shareRoutes) {
968
+ await this.#hooks.runner("routesCommitted").run(this, routesList);
969
+ }
970
+ if (scanRoutes) {
971
+ this.#routesScanner = new RoutesScanner(this.cwdPath, []);
972
+ await this.#hooks.runner("routesScanning").run(this, this.#routesScanner);
973
+ for (const domain of Object.keys(routesList)) {
974
+ await this.#routesScanner.scan(routesList[domain]);
975
+ }
976
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
977
+ }
978
+ }, "processRoutes");
891
979
  /**
892
980
  * Registers hooks for file system events and server restart triggers
893
981
  *
@@ -899,20 +987,36 @@ var DevServer = class _DevServer {
899
987
  this.#regenerateIndex(absolutePath, "add");
900
988
  this.#handleFileChange(relativePath, absolutePath, "add");
901
989
  });
902
- this.#hooks.add(
903
- "fileChanged",
904
- (relativePath, absolutePath, info) => this.#handleFileChange(relativePath, absolutePath, "update", info)
905
- );
990
+ this.#hooks.add("fileChanged", (relativePath, absolutePath, info) => {
991
+ if (info.hotReloaded) {
992
+ this.#reScanRoutes(absolutePath);
993
+ }
994
+ this.#handleFileChange(relativePath, absolutePath, "update", info);
995
+ });
906
996
  this.#hooks.add("fileRemoved", (relativePath, absolutePath) => {
907
997
  this.#regenerateIndex(absolutePath, "delete");
908
998
  this.#handleFileChange(relativePath, absolutePath, "delete");
909
999
  });
910
1000
  }
911
1001
  /**
912
- * Initiate the state for DevServer and executes the init hooks
1002
+ * Initializes the development server state and executes init hooks
1003
+ *
1004
+ * Parses TypeScript configuration, sets up file system, loads hooks,
1005
+ * initializes the index generator, and prepares the server for the
1006
+ * specified mode (HMR, watch, or static).
1007
+ *
1008
+ * @param ts - TypeScript module reference
1009
+ * @param mode - Server mode (hmr, watch, or static)
1010
+ * @returns True if initialization succeeds, false if tsconfig parsing fails
1011
+ *
1012
+ * @example
1013
+ * const success = await devServer.#init(ts, 'hmr')
1014
+ * if (!success) {
1015
+ * console.error('Failed to initialize dev server')
1016
+ * }
913
1017
  */
914
- async #init(ts, mode) {
915
- const tsConfig = parseConfig(this.cwd, ts);
1018
+ async #init(mode) {
1019
+ const tsConfig = readTsConfig(this.cwdPath);
916
1020
  if (!tsConfig) {
917
1021
  this.#onError?.(new RuntimeException("Unable to parse tsconfig file"));
918
1022
  return false;
@@ -948,9 +1052,13 @@ var DevServer = class _DevServer {
948
1052
  *
949
1053
  * Creates a new Node.js child process to run the server script with the
950
1054
  * specified port and configuration. Sets up message handlers for server
951
- * ready notifications and hot-hook events.
1055
+ * ready notifications, routes sharing, and hot-hook events. Executes
1056
+ * devServerStarting hooks before spawning the process.
952
1057
  *
953
1058
  * @param port - Port number for the server to listen on
1059
+ *
1060
+ * @example
1061
+ * await devServer.#startHTTPServer('3333')
954
1062
  */
955
1063
  async #startHTTPServer(port) {
956
1064
  await this.#hooks.runner("devServerStarting").run(this);
@@ -968,6 +1076,9 @@ var DevServer = class _DevServer {
968
1076
  debug_default("received http server ready message %O", message);
969
1077
  await this.#postServerReady(message);
970
1078
  resolve();
1079
+ } else if (this.#isAdonisJSRoutesMessage(message)) {
1080
+ debug_default("received routes location from the server %O", message);
1081
+ await this.#processRoutes(message.routesFileLocation);
971
1082
  } else if (this.#mode === "hmr" && this.#isHotHookMessage(message)) {
972
1083
  debug_default("received hot-hook message %O", message);
973
1084
  const absolutePath = message.path ? string3.toUnixSlash(message.path) : "";
@@ -1006,27 +1117,50 @@ var DevServer = class _DevServer {
1006
1117
  });
1007
1118
  }
1008
1119
  /**
1009
- * Add listener to get notified when dev server is closed
1120
+ * Adds listener to get notified when dev server is closed
1121
+ *
1122
+ * Registers a callback function that will be invoked when the development
1123
+ * server's child process exits. The callback receives the exit code.
1010
1124
  *
1011
1125
  * @param callback - Function to call when dev server closes
1012
1126
  * @returns This DevServer instance for method chaining
1127
+ *
1128
+ * @example
1129
+ * devServer.onClose((exitCode) => {
1130
+ * console.log(`Server closed with exit code: ${exitCode}`)
1131
+ * })
1013
1132
  */
1014
1133
  onClose(callback) {
1015
1134
  this.#onClose = callback;
1016
1135
  return this;
1017
1136
  }
1018
1137
  /**
1019
- * Add listener to get notified when dev server encounters an error
1138
+ * Adds listener to get notified when dev server encounters an error
1139
+ *
1140
+ * Registers a callback function that will be invoked when the development
1141
+ * server's child process encounters an error or fails to start.
1020
1142
  *
1021
1143
  * @param callback - Function to call when dev server encounters an error
1022
1144
  * @returns This DevServer instance for method chaining
1145
+ *
1146
+ * @example
1147
+ * devServer.onError((error) => {
1148
+ * console.error('Dev server error:', error.message)
1149
+ * })
1023
1150
  */
1024
1151
  onError(callback) {
1025
1152
  this.#onError = callback;
1026
1153
  return this;
1027
1154
  }
1028
1155
  /**
1029
- * Close watchers and the running child process
1156
+ * Closes watchers and terminates the running child process
1157
+ *
1158
+ * Cleans up keyboard shortcuts, stops file system watchers, and kills
1159
+ * the HTTP server child process. This should be called when shutting down
1160
+ * the development server.
1161
+ *
1162
+ * @example
1163
+ * await devServer.close()
1030
1164
  */
1031
1165
  async close() {
1032
1166
  this.#cleanupKeyboardShortcuts();
@@ -1037,12 +1171,20 @@ var DevServer = class _DevServer {
1037
1171
  }
1038
1172
  }
1039
1173
  /**
1040
- * Start the development server in static or HMR mode
1174
+ * Starts the development server in static or HMR mode
1175
+ *
1176
+ * Initializes the server and starts the HTTP server. The mode is determined
1177
+ * by the `hmr` option in DevServerOptions. In HMR mode, hot-hook is configured
1178
+ * to enable hot module reloading.
1041
1179
  *
1042
1180
  * @param ts - TypeScript module reference
1181
+ *
1182
+ * @example
1183
+ * const devServer = new DevServer(cwd, { hmr: true, hooks: [] })
1184
+ * await devServer.start(ts)
1043
1185
  */
1044
- async start(ts) {
1045
- const initiated = await this.#init(ts, this.options.hmr ? "hmr" : "static");
1186
+ async start() {
1187
+ const initiated = await this.#init(this.options.hmr ? "hmr" : "static");
1046
1188
  if (!initiated) {
1047
1189
  return;
1048
1190
  }
@@ -1059,13 +1201,22 @@ var DevServer = class _DevServer {
1059
1201
  await this.#startHTTPServer(this.#stickyPort);
1060
1202
  }
1061
1203
  /**
1062
- * Start the development server in watch mode and restart on file changes
1204
+ * Starts the development server in watch mode and restarts on file changes
1205
+ *
1206
+ * Initializes the server, starts the HTTP server, and sets up a file system
1207
+ * watcher that monitors for changes. When files are added, modified, or deleted,
1208
+ * the server automatically restarts. The watcher respects TypeScript project
1209
+ * configuration and metaFiles settings.
1063
1210
  *
1064
1211
  * @param ts - TypeScript module reference
1065
1212
  * @param options - Watch options including polling mode
1213
+ *
1214
+ * @example
1215
+ * const devServer = new DevServer(cwd, { hooks: [] })
1216
+ * await devServer.startAndWatch(ts, { poll: false })
1066
1217
  */
1067
- async startAndWatch(ts, options) {
1068
- const initiated = await this.#init(ts, "watch");
1218
+ async startAndWatch(options) {
1219
+ const initiated = await this.#init("watch");
1069
1220
  if (!initiated) {
1070
1221
  return;
1071
1222
  }
@@ -1429,8 +1580,8 @@ var TestRunner = class {
1429
1580
  * @param ts - TypeScript module reference for parsing configuration
1430
1581
  * @param options - Watch options including polling mode for file system monitoring
1431
1582
  */
1432
- async runAndWatch(ts, options) {
1433
- const tsConfig = parseConfig(this.cwd, ts);
1583
+ async runAndWatch(options) {
1584
+ const tsConfig = readTsConfig(this.cwdPath);
1434
1585
  if (!tsConfig) {
1435
1586
  this.#onError?.(new RuntimeException2("Unable to parse tsconfig file"));
1436
1587
  return;
@@ -105,7 +105,7 @@ export declare class RoutesScanner {
105
105
  *
106
106
  * @param controllerPath - Path to the controller file to invalidate
107
107
  */
108
- invalidate(controllerPath: string): Promise<void>;
108
+ invalidate(controllerPath: string): Promise<boolean>;
109
109
  /**
110
110
  * Scans an array of Route list items and fetches their validators,
111
111
  * controllers, and request/response types.