spooder 5.1.0 → 5.1.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.
Files changed (3) hide show
  1. package/README.md +16 -2
  2. package/package.json +1 -1
  3. package/src/api.ts +19 -3
package/README.md CHANGED
@@ -531,7 +531,7 @@ Replacements = Record<string, string | Array<string> | object | object[]> | Repl
531
531
  parse_template(template: string, replacements: Replacements, drop_missing?: boolean): Promise<string>;
532
532
 
533
533
  // cache busting
534
- cache_bust(string: path, format: string): string
534
+ cache_bust(string|string[]: path, format: string): string|string[]
535
535
  cache_bust_set_hash_length(length: number): void;
536
536
  cache_bust_set_format(format: string): void;
537
537
  cache_bust_get_hash_table(): Record<string, string>;
@@ -2048,7 +2048,7 @@ await parse_template(..., {
2048
2048
  <a id="api-cache-busting"></a>
2049
2049
  ## API > Cache Busting
2050
2050
 
2051
- ### 🔧 ``cache_bust(string: path, format: string): string``
2051
+ ### 🔧 ``cache_bust(string|string[]: path, format: string): string|string[]``
2052
2052
 
2053
2053
  Appends a hash-suffix to the provided string, formatted by default as a query parameter, for cache-busting purposes.
2054
2054
 
@@ -2056,6 +2056,20 @@ Appends a hash-suffix to the provided string, formatted by default as a query pa
2056
2056
  cache_bust('static/my_image.png'); // > static/my_image.png?v=123fea
2057
2057
  ```
2058
2058
 
2059
+ This works on an array of paths as well.
2060
+
2061
+ ```ts
2062
+ cache_bust([
2063
+ 'static/js/script1.js',
2064
+ 'static/js/script2.js'
2065
+ ]);
2066
+
2067
+ // [
2068
+ // 'static/js/script1.js?v=fffffff',
2069
+ // 'static/js/script2.js?v=fffffff'
2070
+ // ]
2071
+ ```
2072
+
2059
2073
  > ![NOTE]
2060
2074
  > Internally `cache_bust()` uses `git_get_hashes()` to hash paths, requiring the input `path` to be a valid git path. If the path cannot be resolved in git, an empty hash is substituted.
2061
2075
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "5.1.0",
4
+ "version": "5.1.1",
5
5
  "module": "./src/api.ts",
6
6
  "bin": {
7
7
  "spooder": "./src/cli.ts"
package/src/api.ts CHANGED
@@ -570,9 +570,25 @@ export function cache_bust_get_hash_table(): Record<string, string> {
570
570
  return cache_bust_map;
571
571
  }
572
572
 
573
- export function cache_bust(path: string, format = cache_bust_global_format): string {
574
- const hash = cache_bust_get_hash_table()[path] || '';
575
- return format.replace('$file', path).replace('$hash', hash);
573
+ export function cache_bust(paths: string|string[], format = cache_bust_global_format): string|string[] {
574
+ const hash_table = cache_bust_get_hash_table();
575
+
576
+ if (Array.isArray(paths)) {
577
+ const n_paths = paths.length;
578
+ const result = Array<string>(n_paths);
579
+
580
+ for (let i = 0; i < n_paths; i++) {
581
+ const path = paths[i];
582
+ const hash = hash_table[path] ?? '';
583
+
584
+ result[i] = format.replace('$file', path).replace('$hash', hash);
585
+ }
586
+
587
+ return result;
588
+ } else {
589
+ const hash = cache_bust_get_hash_table()[paths] ?? '';
590
+ return format.replace('$file', paths).replace('$hash', hash);
591
+ }
576
592
  }
577
593
 
578
594
  export function cache_bust_set_hash_length(length: number): void {