cindel 1.0.3 → 1.0.4

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/dist/client.js CHANGED
@@ -1748,7 +1748,8 @@ var HMRClient = class {
1748
1748
  * @param {function(string): boolean} [options.filterCold] - Custom cold file logic. Receives `(filePath)`. Combined with `cold` via OR.
1749
1749
  * @param {function(string, string[]): string|null} [options.getOverrideTarget] - Given a changed file, return the path of the original it replaces, or `null`. Receives `(filePath, allFiles)`. When matched, the original is unloaded before the override loads.
1750
1750
  * @param {function(string): void} [options.onFileLoaded] - Called after each file loads or reloads. Receives `(filePath)`.
1751
- * @param {function(string[]): string[]} [options.sortFiles] - Custom sort for the initial file load order. Default sorts CSS before JS, cold files first.
1751
+ * @param {function(string[]): string[]} [options.sortFiles] - Custom sort for the initial file load order. When provided, replaces `defaultSortFiles` entirely and `loadOrder` is ignored.
1752
+ * @param {Array<Function>} [options.loadOrder] - Stages prepended before the built-in sort (CSS-first, cold-first, alphabetical). One argument: return true to load that file first. Two arguments: works like a normal sort callback.
1752
1753
  */
1753
1754
  constructor(options) {
1754
1755
  const opts = typeof options === "object" && !Array.isArray(options) ? options : {};
@@ -1769,6 +1770,7 @@ var HMRClient = class {
1769
1770
  this.allFiles = [];
1770
1771
  this.getOverrideTarget = opts.getOverrideTarget || null;
1771
1772
  this.onFileLoaded = opts.onFileLoaded || null;
1773
+ this.loadOrder = opts.loadOrder || [];
1772
1774
  this.sortFiles = opts.sortFiles || this.defaultSortFiles.bind(this);
1773
1775
  this.socket = null;
1774
1776
  this.reconnectAttempts = 0;
@@ -1796,16 +1798,18 @@ var HMRClient = class {
1796
1798
  }
1797
1799
  defaultSortFiles(files) {
1798
1800
  const coldSet = new Set(files.filter((f) => this.isColdFile(f)));
1801
+ const builtinStages = [
1802
+ (f) => f.endsWith(".css"),
1803
+ (f) => coldSet.has(f),
1804
+ (a, b) => a.localeCompare(b)
1805
+ ];
1806
+ const stages = [...this.loadOrder, ...builtinStages];
1799
1807
  return [...files].sort((a, b) => {
1800
- const aIsCSS = a.endsWith(".css");
1801
- const bIsCSS = b.endsWith(".css");
1802
- if (aIsCSS && !bIsCSS) return -1;
1803
- if (!aIsCSS && bIsCSS) return 1;
1804
- const coldA = coldSet.has(a);
1805
- const coldB = coldSet.has(b);
1806
- if (coldA && !coldB) return -1;
1807
- if (!coldA && coldB) return 1;
1808
- return a.localeCompare(b);
1808
+ for (const stage of stages) {
1809
+ const result = stage.length === 2 ? stage(a, b) : stage(b) - stage(a);
1810
+ if (result !== 0) return result;
1811
+ }
1812
+ return 0;
1809
1813
  });
1810
1814
  }
1811
1815
  makeFilter(patterns, callback) {