ts-service-worker 1.1.1 → 1.1.2

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/cli.mjs CHANGED
@@ -6449,8 +6449,8 @@ var glob = Object.assign(glob_, {
6449
6449
  });
6450
6450
  glob.glob = glob;
6451
6451
 
6452
- // src/fileSpecsToPaths.mts
6453
- function fileSpecsToPaths(files) {
6452
+ // src/filesSpecToPaths.mts
6453
+ function filesSpecToPaths(files) {
6454
6454
  let prefix = "";
6455
6455
  let dir = "";
6456
6456
  let globs;
@@ -6488,7 +6488,7 @@ function isCachePathOnInstall(s) {
6488
6488
  return s.strategy === "cache-on-install" && "paths" in s;
6489
6489
  }
6490
6490
  function isStaticOfflineBackup(s) {
6491
- return s.strategy === "staticOfflineBackup";
6491
+ return s.strategy === "staticOfflineBackup" && !!s.paths && !!s.backup;
6492
6492
  }
6493
6493
  var OriginAndBelow = Symbol.for("origin-and-below");
6494
6494
  var ScopeAndBelow = Symbol.for("scope-and-below");
@@ -6496,7 +6496,7 @@ function isRoutableStrategy(x) {
6496
6496
  return x.strategy === "cacheFirst" || x.strategy === "networkFirst" || x.strategy === "networkOnly" || x.strategy === "staleWhileRevalidate" || x.strategy === "staticOfflineBackup";
6497
6497
  }
6498
6498
  function convertPreloadFilesToPaths(strategy) {
6499
- const paths = fileSpecsToPaths(strategy.files);
6499
+ const paths = filesSpecToPaths(strategy.files);
6500
6500
  return {
6501
6501
  strategy: "cache-on-install",
6502
6502
  paths
@@ -6651,6 +6651,28 @@ function regexEscape(s) {
6651
6651
  }
6652
6652
  `;
6653
6653
 
6654
+ // src/utils.mts
6655
+ function deDup(paths) {
6656
+ if (!Array.isArray(paths))
6657
+ return paths;
6658
+ return [...new Set(paths)].sort();
6659
+ }
6660
+
6661
+ // src/organizeStrategies.mts
6662
+ function organizeStrategies(inputPlan) {
6663
+ const spec = convertAllFilesToPaths(inputPlan);
6664
+ const preloadPaths = deDup(extractAllPreloadPaths(spec));
6665
+ const specWithoutPreloads = convertPreloadPathsToCacheFirst(spec);
6666
+ const routable = removeDuplicatePaths(specWithoutPreloads);
6667
+ return { preloadPaths, routable };
6668
+ }
6669
+ function removeDuplicatePaths(specs) {
6670
+ return specs.map((spec) => ({
6671
+ ...spec,
6672
+ paths: deDup(spec.paths)
6673
+ }));
6674
+ }
6675
+
6654
6676
  // src/generate.mts
6655
6677
  var defaultOptions = {
6656
6678
  version: "0.0",
@@ -6662,9 +6684,7 @@ function generateServiceWorker(inputSpec, optionsIn = {}) {
6662
6684
  ...defaultOptions,
6663
6685
  ...optionsIn
6664
6686
  };
6665
- const spec = convertAllFilesToPaths(inputSpec);
6666
- const preloadPaths = extractAllPreloadPaths(spec);
6667
- const routable = convertPreloadPathsToCacheFirst(spec);
6687
+ const { preloadPaths, routable } = organizeStrategies(inputSpec);
6668
6688
  const varsBlock = generateFlag("DEBUG", options.debug) + generateFlag("SKIP_WAITING", options.skipWaiting) + generateVersion(options.version) + generatePreloadCode(preloadPaths) + generateRoutes(routable);
6669
6689
  return evalTemplate(varsBlock);
6670
6690
  }
package/dist/index.js CHANGED
@@ -6461,8 +6461,8 @@ var glob = Object.assign(glob_, {
6461
6461
  });
6462
6462
  glob.glob = glob;
6463
6463
 
6464
- // src/fileSpecsToPaths.mts
6465
- function fileSpecsToPaths(files) {
6464
+ // src/filesSpecToPaths.mts
6465
+ function filesSpecToPaths(files) {
6466
6466
  let prefix = "";
6467
6467
  let dir = "";
6468
6468
  let globs;
@@ -6500,7 +6500,7 @@ function isCachePathOnInstall(s) {
6500
6500
  return s.strategy === "cache-on-install" && "paths" in s;
6501
6501
  }
6502
6502
  function isStaticOfflineBackup(s) {
6503
- return s.strategy === "staticOfflineBackup";
6503
+ return s.strategy === "staticOfflineBackup" && !!s.paths && !!s.backup;
6504
6504
  }
6505
6505
  var OriginAndBelow = Symbol.for("origin-and-below");
6506
6506
  var ScopeAndBelow = Symbol.for("scope-and-below");
@@ -6508,7 +6508,7 @@ function isRoutableStrategy(x) {
6508
6508
  return x.strategy === "cacheFirst" || x.strategy === "networkFirst" || x.strategy === "networkOnly" || x.strategy === "staleWhileRevalidate" || x.strategy === "staticOfflineBackup";
6509
6509
  }
6510
6510
  function convertPreloadFilesToPaths(strategy) {
6511
- const paths = fileSpecsToPaths(strategy.files);
6511
+ const paths = filesSpecToPaths(strategy.files);
6512
6512
  return {
6513
6513
  strategy: "cache-on-install",
6514
6514
  paths
@@ -6663,6 +6663,28 @@ function regexEscape(s) {
6663
6663
  }
6664
6664
  `;
6665
6665
 
6666
+ // src/utils.mts
6667
+ function deDup(paths) {
6668
+ if (!Array.isArray(paths))
6669
+ return paths;
6670
+ return [...new Set(paths)].sort();
6671
+ }
6672
+
6673
+ // src/organizeStrategies.mts
6674
+ function organizeStrategies(inputPlan) {
6675
+ const spec = convertAllFilesToPaths(inputPlan);
6676
+ const preloadPaths = deDup(extractAllPreloadPaths(spec));
6677
+ const specWithoutPreloads = convertPreloadPathsToCacheFirst(spec);
6678
+ const routable = removeDuplicatePaths(specWithoutPreloads);
6679
+ return { preloadPaths, routable };
6680
+ }
6681
+ function removeDuplicatePaths(specs) {
6682
+ return specs.map((spec) => ({
6683
+ ...spec,
6684
+ paths: deDup(spec.paths)
6685
+ }));
6686
+ }
6687
+
6666
6688
  // src/generate.mts
6667
6689
  var defaultOptions = {
6668
6690
  version: "0.0",
@@ -6674,9 +6696,7 @@ function generateServiceWorker(inputSpec, optionsIn = {}) {
6674
6696
  ...defaultOptions,
6675
6697
  ...optionsIn
6676
6698
  };
6677
- const spec = convertAllFilesToPaths(inputSpec);
6678
- const preloadPaths = extractAllPreloadPaths(spec);
6679
- const routable = convertPreloadPathsToCacheFirst(spec);
6699
+ const { preloadPaths, routable } = organizeStrategies(inputSpec);
6680
6700
  const varsBlock = generateFlag("DEBUG", options.debug) + generateFlag("SKIP_WAITING", options.skipWaiting) + generateVersion(options.version) + generatePreloadCode(preloadPaths) + generateRoutes(routable);
6681
6701
  return evalTemplate(varsBlock);
6682
6702
  }