@adonisjs/assembler 8.0.0-next.0 → 8.0.0-next.1

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
@@ -331,6 +331,7 @@ var Bundler = class {
331
331
  };
332
332
 
333
333
  // src/dev_server.ts
334
+ import { relative as relative4 } from "path";
334
335
  import { cliui as cliui2 } from "@poppinss/cliui";
335
336
  import prettyHrtime from "pretty-hrtime";
336
337
  import { fileURLToPath as fileURLToPath4 } from "url";
@@ -564,7 +565,12 @@ var DevServer = class {
564
565
  constructor(cwd, options) {
565
566
  this.cwd = cwd;
566
567
  this.options = options;
568
+ this.#cwdPath = fileURLToPath4(this.cwd);
567
569
  }
570
+ /**
571
+ * File path computed from the cwd
572
+ */
573
+ #cwdPath;
568
574
  /**
569
575
  * External listeners that are invoked when child process
570
576
  * gets an error or closes
@@ -663,15 +669,24 @@ var DevServer = class {
663
669
  /**
664
670
  * Handles file change event
665
671
  */
666
- #handleFileChange(filePath, action, hotReplaced) {
667
- const file = this.#fileSystem.inspect(filePath);
668
- if (!file) {
672
+ #handleFileChange(filePath, action, info) {
673
+ if ((action === "add" || action === "delete") && this.mode === "hmr") {
674
+ debug_default("ignoring add and delete actions in HMR mode %s", filePath);
669
675
  return;
670
676
  }
671
- if (hotReplaced) {
677
+ if (info && info.source === "hot-hook" && info.hotReloaded) {
678
+ debug_default("hot reloading %s, info %O", filePath, info);
672
679
  this.ui.logger.log(`${this.ui.colors.green("invalidated")} ${filePath}`);
673
680
  return;
674
681
  }
682
+ if (info && !info.fullReload) {
683
+ debug_default("ignoring full reload", filePath, info);
684
+ return;
685
+ }
686
+ const file = this.#fileSystem.inspect(filePath);
687
+ if (!file) {
688
+ return;
689
+ }
675
690
  if (file.reloadServer) {
676
691
  this.#clearScreen();
677
692
  this.ui.logger.log(`${this.ui.colors.green(action)} ${filePath}`);
@@ -688,7 +703,7 @@ var DevServer = class {
688
703
  this.#hooks.add("fileAdded", (filePath) => this.#handleFileChange(filePath, "add"));
689
704
  this.#hooks.add(
690
705
  "fileChanged",
691
- (filePath, hotReplaced) => this.#handleFileChange(filePath, "update", hotReplaced)
706
+ (filePath, info) => this.#handleFileChange(filePath, "update", info)
692
707
  );
693
708
  this.#hooks.add("fileRemoved", (filePath) => this.#handleFileChange(filePath, "delete"));
694
709
  }
@@ -708,24 +723,50 @@ var DevServer = class {
708
723
  });
709
724
  this.#httpServer.on("message", async (message) => {
710
725
  if (this.#isAdonisJSReadyMessage(message)) {
726
+ debug_default("received http server ready message %O", message);
711
727
  await this.#postServerReady(message);
712
728
  resolve();
713
729
  } else if (this.#mode === "hmr" && this.#isHotHookMessage(message)) {
730
+ debug_default("received hot-hook message %O", message);
714
731
  if (message.type === "hot-hook:file-changed") {
715
732
  switch (message.action) {
716
733
  case "add":
717
- this.#hooks.runner("fileAdded").run(string3.toUnixSlash(message.path), this);
734
+ this.#hooks.runner("fileAdded").run(string3.toUnixSlash(relative4(this.#cwdPath, message.path)), this);
718
735
  break;
719
736
  case "change":
720
- this.#hooks.runner("fileChanged").run(string3.toUnixSlash(message.path), false, this);
737
+ this.#hooks.runner("fileChanged").run(
738
+ string3.toUnixSlash(relative4(this.#cwdPath, message.path)),
739
+ {
740
+ source: "hot-hook",
741
+ fullReload: false,
742
+ hotReloaded: false
743
+ },
744
+ this
745
+ );
721
746
  break;
722
747
  case "unlink":
723
- this.#hooks.runner("fileRemoved").run(string3.toUnixSlash(message.path), this);
748
+ this.#hooks.runner("fileRemoved").run(string3.toUnixSlash(relative4(this.#cwdPath, message.path)), this);
724
749
  }
725
750
  } else if (message.type === "hot-hook:full-reload") {
726
- this.#hooks.runner("fileChanged").run(string3.toUnixSlash(message.path), false, this);
751
+ this.#hooks.runner("fileChanged").run(
752
+ string3.toUnixSlash(relative4(this.#cwdPath, message.path)),
753
+ {
754
+ source: "hot-hook",
755
+ fullReload: true,
756
+ hotReloaded: false
757
+ },
758
+ this
759
+ );
727
760
  } else if (message.type === "hot-hook:invalidated") {
728
- this.#hooks.runner("fileChanged").run(string3.toUnixSlash(message.path), true, this);
761
+ this.#hooks.runner("fileChanged").run(
762
+ string3.toUnixSlash(relative4(this.#cwdPath, message.path)),
763
+ {
764
+ source: "hot-hook",
765
+ fullReload: false,
766
+ hotReloaded: true
767
+ },
768
+ this
769
+ );
729
770
  }
730
771
  }
731
772
  });
@@ -742,7 +783,6 @@ var DevServer = class {
742
783
  this.ui.logger.info("Underlying HTTP server died. Still watching for changes");
743
784
  }
744
785
  }).finally(() => {
745
- console.log("ere>>");
746
786
  resolve();
747
787
  });
748
788
  });
@@ -798,7 +838,7 @@ var DevServer = class {
798
838
  ...this.options.env,
799
839
  HOT_HOOK_INCLUDE: this.#fileSystem.includes.join(","),
800
840
  HOT_HOOK_IGNORE: this.#fileSystem.excludes.join(","),
801
- HOT_HOOK_RESTART: (this.options.metaFiles ?? []).map(({ pattern }) => pattern).join(",")
841
+ HOT_HOOK_RESTART: (this.options.metaFiles ?? []).filter(({ reloadServer }) => !!reloadServer).map(({ pattern }) => pattern).join(",")
802
842
  };
803
843
  }
804
844
  this.#clearScreen();
@@ -829,7 +869,7 @@ var DevServer = class {
829
869
  await this.#startHTTPServer(this.#stickyPort);
830
870
  this.#watcher = watch({
831
871
  usePolling: options?.poll ?? false,
832
- cwd: fileURLToPath4(this.cwd),
872
+ cwd: this.#cwdPath,
833
873
  ignoreInitial: true,
834
874
  ignored: (file, stats) => {
835
875
  if (!stats) {
@@ -856,7 +896,15 @@ var DevServer = class {
856
896
  );
857
897
  this.#watcher.on(
858
898
  "change",
859
- (filePath) => this.#hooks.runner("fileChanged").run(string3.toUnixSlash(filePath), false, this)
899
+ (filePath) => this.#hooks.runner("fileChanged").run(
900
+ string3.toUnixSlash(filePath),
901
+ {
902
+ source: "watcher",
903
+ fullReload: true,
904
+ hotReloaded: false
905
+ },
906
+ this
907
+ )
860
908
  );
861
909
  this.#watcher.on(
862
910
  "unlink",
@@ -1142,7 +1190,15 @@ var TestRunner = class {
1142
1190
  );
1143
1191
  this.#watcher.on(
1144
1192
  "change",
1145
- (filePath) => this.#hooks.runner("fileChanged").run(string4.toUnixSlash(filePath), false, this)
1193
+ (filePath) => this.#hooks.runner("fileChanged").run(
1194
+ string4.toUnixSlash(filePath),
1195
+ {
1196
+ source: "watcher",
1197
+ fullReload: true,
1198
+ hotReloaded: false
1199
+ },
1200
+ this
1201
+ )
1146
1202
  );
1147
1203
  this.#watcher.on(
1148
1204
  "unlink",
@@ -13,7 +13,11 @@ export type WatcherHooks = {
13
13
  /**
14
14
  * The hook is executed after a file has been changed in the watch mode.
15
15
  */
16
- fileChanged: LazyImport<(filePath: string, hotReplaced: boolean, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
16
+ fileChanged: LazyImport<(filePath: string, info: {
17
+ source: 'hot-hook' | 'watcher';
18
+ hotReloaded: boolean;
19
+ fullReload: boolean;
20
+ }, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
17
21
  /**
18
22
  * The hook is executed after a file has been added.
19
23
  */
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.0",
4
+ "version": "8.0.0-next.1",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -30,7 +30,7 @@
30
30
  "release": "release-it",
31
31
  "version": "npm run build",
32
32
  "prepublishOnly": "npm run build",
33
- "quick:test": "node --enable-source-maps --import=@poppinss/ts-exec bin/test.ts"
33
+ "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --import=@poppinss/ts-exec bin/test.ts"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@adonisjs/eslint-config": "^3.0.0-next.0",
@@ -46,6 +46,7 @@
46
46
  "@types/picomatch": "^4.0.0",
47
47
  "@types/pretty-hrtime": "^1.0.3",
48
48
  "c8": "^10.1.3",
49
+ "cross-env": "^7.0.3",
49
50
  "del-cli": "^6.0.0",
50
51
  "eslint": "^9.28.0",
51
52
  "hot-hook": "^0.4.1-next.0",