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

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.
@@ -10,7 +10,7 @@ import {
10
10
  VirtualFileSystem,
11
11
  debug_default,
12
12
  isRelative
13
- } from "./chunk-HRE5L24F.js";
13
+ } from "./chunk-OHOSIKRT.js";
14
14
 
15
15
  // src/code_scanners/routes_scanner/main.ts
16
16
  import { cliui } from "@poppinss/cliui";
@@ -64,7 +64,7 @@ var PathsResolver = class {
64
64
  * const path = resolver.resolve('#app/models/user')
65
65
  * const path2 = resolver.resolve('@/utils/helper')
66
66
  */
67
- resolve(specifier) {
67
+ resolve(specifier, rewriteAliasImportExtension = false) {
68
68
  if (isRelative(specifier)) {
69
69
  throw new Error("Cannot resolve relative paths using PathsResolver");
70
70
  }
@@ -73,7 +73,11 @@ var PathsResolver = class {
73
73
  if (cached) {
74
74
  return cached;
75
75
  }
76
- this.#resolvedPaths[cacheKey] = fileURLToPath(this.#resolver(specifier, this.#appRoot));
76
+ let resolvedPath = fileURLToPath(this.#resolver(specifier, this.#appRoot));
77
+ if (rewriteAliasImportExtension && specifier.startsWith("#") && resolvedPath.endsWith(".js")) {
78
+ resolvedPath = resolvedPath.replace(/\.js$/, ".ts");
79
+ }
80
+ this.#resolvedPaths[cacheKey] = resolvedPath;
77
81
  return this.#resolvedPaths[cacheKey];
78
82
  }
79
83
  };
@@ -264,7 +268,7 @@ var RoutesScanner = class {
264
268
  return {
265
269
  name,
266
270
  method: method ?? "handle",
267
- path: string2.toUnixSlash(this.pathsResolver.resolve(specifier)),
271
+ path: string2.toUnixSlash(this.pathsResolver.resolve(specifier, true)),
268
272
  import: {
269
273
  specifier,
270
274
  type: "default",
@@ -297,7 +301,7 @@ var RoutesScanner = class {
297
301
  */
298
302
  #processRouteWithoutController(route) {
299
303
  if (!route.name) {
300
- debug_default(`skipping route "%s" as it does not have a name`, route.name);
304
+ debug_default(`skipping route "%s" as it does not have a name`, route.pattern);
301
305
  return;
302
306
  }
303
307
  const scannedRoute = {
@@ -316,7 +320,7 @@ var RoutesScanner = class {
316
320
  * Scans a route that is using a controller reference
317
321
  */
318
322
  async #processRouteWithController(route, vfs) {
319
- if (!route.handler.importExpression) {
323
+ if (!route.handler || !route.handler.importExpression) {
320
324
  return this.#processRouteWithoutController(route);
321
325
  }
322
326
  const controller = await this.#inspectControllerSpecifier(
@@ -268,30 +268,6 @@ var VirtualFileSystem = class {
268
268
  };
269
269
  this.#matcher = picomatch(this.#options.glob ?? DEFAULT_GLOB, this.#picoMatchOptions);
270
270
  }
271
- /**
272
- * Currently the PathsResolver relies on a non-standard way of resolving
273
- * absolute paths or paths with subpath imports. Because of which, the
274
- * on-disk file could be TypeScript, while the resolved filepath is
275
- * JavaScript.
276
- *
277
- * To overcome this limitation, we start by first looking for a `.ts` file
278
- * (because of high probability) and then look for `.js` file
279
- */
280
- async #readTSOrJSFile(filePath) {
281
- if (filePath.endsWith(".js")) {
282
- try {
283
- const contents = await readFile(filePath.replace(/\.js$/, ".ts"), "utf-8");
284
- debug_default('read as TypeScript file "%s"', filePath);
285
- return contents;
286
- } catch (error) {
287
- if (error.code === "ENOENT") {
288
- return readFile(filePath, "utf-8");
289
- }
290
- throw error;
291
- }
292
- }
293
- return readFile(filePath, "utf-8");
294
- }
295
271
  /**
296
272
  * Scans the filesystem to collect the files. Newly files must
297
273
  * be added via the ".add" method.
@@ -406,7 +382,7 @@ var VirtualFileSystem = class {
406
382
  debug_default('returning AST nodes from cache "%s"', filePath);
407
383
  return cached;
408
384
  }
409
- const fileContents = await this.#readTSOrJSFile(filePath);
385
+ const fileContents = await readFile(filePath, "utf-8");
410
386
  debug_default('parsing "%s" file to AST', filePath);
411
387
  this.#astCache.set(filePath, parse(Lang.TypeScript, fileContents).root());
412
388
  return this.#astCache.get(filePath);
@@ -3,7 +3,7 @@ import {
3
3
  debug_default,
4
4
  removeExtension,
5
5
  throttle
6
- } from "./chunk-HRE5L24F.js";
6
+ } from "./chunk-OHOSIKRT.js";
7
7
 
8
8
  // src/index_generator/source.ts
9
9
  import string from "@poppinss/utils/string";
package/build/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  FileBuffer,
3
3
  IndexGenerator
4
- } from "./chunk-YFDLKKOA.js";
4
+ } from "./chunk-RIQD2IFD.js";
5
5
  import {
6
6
  RoutesScanner
7
- } from "./chunk-WG7JQZUU.js";
7
+ } from "./chunk-5AU4VKV7.js";
8
8
  import "./chunk-TIKQQRMX.js";
9
9
  import {
10
10
  VirtualFileSystem,
@@ -19,7 +19,7 @@ import {
19
19
  runNode,
20
20
  throttle,
21
21
  watch
22
- } from "./chunk-HRE5L24F.js";
22
+ } from "./chunk-OHOSIKRT.js";
23
23
 
24
24
  // src/bundler.ts
25
25
  import dedent from "dedent";
@@ -931,9 +931,14 @@ var DevServer = class _DevServer {
931
931
  if (!this.#routesScanner) {
932
932
  return;
933
933
  }
934
- const invalidated = await this.#routesScanner.invalidate(filePath);
935
- if (invalidated) {
936
- await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
934
+ try {
935
+ const invalidated = await this.#routesScanner.invalidate(filePath);
936
+ if (invalidated) {
937
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
938
+ }
939
+ } catch (error) {
940
+ this.ui.logger.error("Unable to rescan routes because of the following error");
941
+ this.ui.logger.fatal(error);
937
942
  }
938
943
  }
939
944
  /**
@@ -953,27 +958,32 @@ var DevServer = class _DevServer {
953
958
  * })
954
959
  */
955
960
  #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) {
961
+ try {
962
+ const scanRoutes = this.#hooks.has("routesScanning") || this.#hooks.has("routesScanned");
963
+ const shareRoutes = this.#hooks.has("routesCommitted");
964
+ if (!scanRoutes && !shareRoutes) {
965
+ unlink(routesFileLocation).catch(() => {
966
+ });
967
+ return;
968
+ }
969
+ const routesJSON = await readFile(routesFileLocation, "utf-8");
970
+ const routesList = JSON.parse(routesJSON);
959
971
  unlink(routesFileLocation).catch(() => {
960
972
  });
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]);
973
+ if (shareRoutes) {
974
+ await this.#hooks.runner("routesCommitted").run(this, routesList);
975
975
  }
976
- await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
976
+ if (scanRoutes) {
977
+ this.#routesScanner = new RoutesScanner(this.cwdPath, []);
978
+ await this.#hooks.runner("routesScanning").run(this, this.#routesScanner);
979
+ for (const domain of Object.keys(routesList)) {
980
+ await this.#routesScanner.scan(routesList[domain]);
981
+ }
982
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
983
+ }
984
+ } catch (error) {
985
+ this.ui.logger.error("Unable to process and scan routes because of the following error");
986
+ this.ui.logger.fatal(error);
977
987
  }
978
988
  }, "processRoutes");
979
989
  /**
@@ -1081,20 +1091,23 @@ var DevServer = class _DevServer {
1081
1091
  await this.#processRoutes(message.routesFileLocation);
1082
1092
  } else if (this.#mode === "hmr" && this.#isHotHookMessage(message)) {
1083
1093
  debug_default("received hot-hook message %O", message);
1084
- const absolutePath = message.path ? string3.toUnixSlash(message.path) : "";
1085
- const relativePath = relative3(this.cwdPath, absolutePath);
1086
1094
  if (message.type === "hot-hook:file-changed") {
1087
- const { action } = message;
1088
- if (action === "add") {
1095
+ const absolutePath = message.path ? string3.toUnixSlash(message.path) : "";
1096
+ const relativePath = relative3(this.cwdPath, absolutePath);
1097
+ if (message.action === "add") {
1089
1098
  this.#hooks.runner("fileAdded").run(relativePath, absolutePath, this);
1090
- } else if (action === "change") {
1099
+ } else if (message.action === "change") {
1091
1100
  this.#hooks.runner("fileChanged").run(relativePath, absolutePath, _DevServer.#HOT_HOOK_CHANGE_INFO, this);
1092
- } else if (action === "unlink") {
1101
+ } else if (message.action === "unlink") {
1093
1102
  this.#hooks.runner("fileRemoved").run(relativePath, absolutePath, this);
1094
1103
  }
1095
1104
  } else if (message.type === "hot-hook:full-reload") {
1105
+ const absolutePath = message.path ? string3.toUnixSlash(message.path) : "";
1106
+ const relativePath = relative3(this.cwdPath, absolutePath);
1096
1107
  this.#hooks.runner("fileChanged").run(relativePath, absolutePath, _DevServer.#HOT_HOOK_FULL_RELOAD_INFO, this);
1097
1108
  } else if (message.type === "hot-hook:invalidated") {
1109
+ const absolutePath = message.paths[0] ? string3.toUnixSlash(message.paths[0]) : "";
1110
+ const relativePath = relative3(this.cwdPath, absolutePath);
1098
1111
  this.#hooks.runner("fileChanged").run(relativePath, absolutePath, _DevServer.#HOT_HOOK_INVALIDATED_INFO, this);
1099
1112
  }
1100
1113
  }
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  RoutesScanner
3
- } from "../../../chunk-WG7JQZUU.js";
3
+ } from "../../../chunk-5AU4VKV7.js";
4
4
  import "../../../chunk-TIKQQRMX.js";
5
- import "../../../chunk-HRE5L24F.js";
5
+ import "../../../chunk-OHOSIKRT.js";
6
6
  export {
7
7
  RoutesScanner
8
8
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  IndexGenerator
3
- } from "../../chunk-YFDLKKOA.js";
4
- import "../../chunk-HRE5L24F.js";
3
+ } from "../../chunk-RIQD2IFD.js";
4
+ import "../../chunk-OHOSIKRT.js";
5
5
  export {
6
6
  IndexGenerator
7
7
  };
@@ -37,5 +37,5 @@ export declare class PathsResolver {
37
37
  * const path = resolver.resolve('#app/models/user')
38
38
  * const path2 = resolver.resolve('@/utils/helper')
39
39
  */
40
- resolve(specifier: string): string;
40
+ resolve(specifier: string, rewriteAliasImportExtension?: boolean): string;
41
41
  }
@@ -174,7 +174,7 @@ export type RoutesListItem = {
174
174
  domain: string;
175
175
  /** HTTP methods accepted by this route */
176
176
  methods: string[];
177
- handler: Function | {
177
+ handler?: {
178
178
  method: string;
179
179
  importExpression: string | null;
180
180
  };
@@ -343,3 +343,26 @@ export interface ShortcutsManagerOptions {
343
343
  /** Callback functions for different shortcut actions */
344
344
  callbacks: KeyboardShortcutsCallbacks;
345
345
  }
346
+ export type AdonisJSServerReadyMessage = {
347
+ isAdonisJS: true;
348
+ environment: 'web';
349
+ port: number;
350
+ host: string;
351
+ duration?: [number, number];
352
+ };
353
+ export type AdonisJSRoutesSharedMessage = {
354
+ isAdonisJS: true;
355
+ routesFileLocation: string;
356
+ };
357
+ export type HotHookMessage = {
358
+ type: 'hot-hook:full-reload';
359
+ path: string;
360
+ shouldBeReloadable?: boolean;
361
+ } | {
362
+ type: 'hot-hook:invalidated';
363
+ paths: string[];
364
+ } | {
365
+ type: 'hot-hook:file-changed';
366
+ path: string;
367
+ action: 'change' | 'add' | 'unlink';
368
+ };
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.16",
4
+ "version": "8.0.0-next.18",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },