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