@caboodle-tech/node-simple-server 3.0.1 → 4.0.0

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/README.md CHANGED
@@ -308,7 +308,7 @@ With your new instance of NSS you can call any of the following public methods:
308
308
 
309
309
  ## Changelog
310
310
 
311
- The [current changelog is here](./changelogs/v3.md). All [other changelogs are here](./changelogs).
311
+ The [current changelog is here](./changelogs/v4.md). All [other changelogs are here](./changelogs).
312
312
 
313
313
  ## Contributions
314
314
 
package/bin/nss.js CHANGED
@@ -43,7 +43,7 @@ class NodeSimpleServer {
43
43
  map: {}
44
44
  };
45
45
 
46
- #VERSION = '3.0.1';
46
+ #VERSION = '4.0.0';
47
47
 
48
48
  #watching = [];
49
49
 
@@ -1018,23 +1018,46 @@ class NodeSimpleServer {
1018
1018
  // Start watching the path(s).
1019
1019
  const watcher = Chokidar.watch(paths, options);
1020
1020
  this.#watching.push(watcher);
1021
+ // Prepare to modify some of the standard Chokidar listeners.
1022
+ const alterAddUpdates = ['add', 'addDir', 'change'];
1023
+ const alterCatachAlls = ['all', 'raw'];
1024
+ const alterUnlinks = ['unlink', 'unlinkDir'];
1021
1025
  // Hookup requested listeners; they are case sensitive so type them right in your code!
1022
- const safe = ['all', 'add', 'addDir', 'change', 'unlink', 'unlinkDir', 'ready', 'raw', 'error'];
1023
1026
  Object.keys(options.events).forEach((key) => {
1024
- if (safe.includes(key)) {
1025
- /**
1026
- * NON-STANDARD ALTERATION
1027
- *
1028
- * Chokidar provides paths in the correct OS format but NSS will change
1029
- * all backslashes (\) into forward slashes (/).
1030
- */
1031
- watcher.on(key, (evt, path) => {
1027
+ /**
1028
+ * NON-STANDARD ALTERATIONS!
1029
+ *
1030
+ * Chokidar provides paths in the correct OS format but NSS will change
1031
+ * all backslashes (\) into forward slashes (/).
1032
+ */
1033
+ if (alterCatachAlls.includes(key)) {
1034
+ watcher.on(key, (evt, path, statsOrDetails) => {
1035
+ // Capture the call and alter the path before passing it on.
1036
+ const altPath = path.replace(/\\/g, '/');
1037
+ // Since we're messing with the path already grab the extension for the user.
1038
+ // eslint-disable-next-line no-param-reassign
1039
+ statsOrDetails.ext = Path.extname(altPath).replace('.', '');
1040
+ options.events[key](evt, altPath, statsOrDetails);
1041
+ });
1042
+ } else if (alterAddUpdates.includes(key)) {
1043
+ watcher.on(key, (path, statsOrDetails) => {
1044
+ // Capture the call and alter the path before passing it on.
1045
+ const altPath = path.replace(/\\/g, '/');
1046
+ // Since we're messing with the path already grab the extension for the user.
1047
+ // eslint-disable-next-line no-param-reassign
1048
+ statsOrDetails.ext = Path.extname(altPath).replace('.', '');
1049
+ options.events[key](altPath, statsOrDetails);
1050
+ });
1051
+ } else if (alterUnlinks.includes(key)) {
1052
+ watcher.on(key, (path) => {
1032
1053
  // Capture the call and alter the path before passing it on.
1033
1054
  const altPath = path.replace(/\\/g, '/');
1034
1055
  // Since we're messing with the path already grab the extension for the user.
1035
1056
  const ext = Path.extname(altPath);
1036
- options.events[key](evt, altPath, ext.replace('.', ''));
1057
+ options.events[key](altPath, ext.replace('.', ''));
1037
1058
  });
1059
+ } else {
1060
+ watcher.on(key, options.events[key]);
1038
1061
  }
1039
1062
  });
1040
1063
  } catch (error) {
@@ -0,0 +1,10 @@
1
+ ### NSS 4.0.0 (7 January 2024)
2
+
3
+ - !feat: Correct bug caused by NSS non-standard implementation of Chokidar; see below.
4
+
5
+ BREAKING CHANGES: NSS has always modified the standard callback parameters of Chokidar, version 4 modifies this behavior to use the standard callback parameters with the following changes:
6
+
7
+ 1. Extension without the leading dot is moved into the stats or details object for events: `all`, `add`, `addDir`, `change`, and `raw`. For `unlink` and `unlinkDir` the extension is passed as an additional parameter.
8
+ 2. NSS now follows the same parameters/arguments structure with the exception of the previous addition.
9
+
10
+ This will break all code that relies on NSS's old non-standard implementation of parameters/arguments in callback.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caboodle-tech/node-simple-server",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "Node Simple Server (NSS): A small but effective node based server for development sites, customizable live reloading, and websocket support built-in.",
5
5
  "main": "bin/nss.js",
6
6
  "scripts": {