ts-service-worker 1.3.2 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-service-worker",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Generate caching service-worker.js using declarative Typescript. Copyright (c) 2023-2025 NDP Software. All Rights Reserved.",
5
5
  "author": {
6
6
  "name": "Andrew Peterson, NDP Software",
@@ -32,9 +32,9 @@
32
32
  "types"
33
33
  ],
34
34
  "scripts": {
35
- "example1": "node --loader tsx example/amp-what-sw.mts",
35
+ "example1": "node --import tsx example/amp-what-sw.mts",
36
36
  "example2": "./dist/cli.mjs example/offline-backup.json",
37
- "test": "node --test --loader tsx src/specs/*.mts",
37
+ "test": "node --test --import tsx src/specs/*.mts",
38
38
  "build": "npm run clean && npm run build-dist && npm run build-bin && npm run build-types",
39
39
  "clean": "rm -fr ./dist/* ./types/*",
40
40
  "build-dist": "./node_modules/.bin/esbuild --target=esnext --outfile=./dist/index.js --bundle --platform=node --sourcemap --format=cjs src/index.mts",
@@ -43,15 +43,15 @@
43
43
  "prepublishOnly": "npm run build"
44
44
  },
45
45
  "engines": {
46
- "node": ">=16"
46
+ "node": ">=22"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "*",
50
- "typescript": "*",
51
50
  "esbuild": "*",
52
- "tsx": "*"
51
+ "tsx": "*",
52
+ "typescript": "*"
53
53
  },
54
54
  "dependencies": {
55
- "glob": "^10.3.10"
55
+ "glob": "*"
56
56
  }
57
57
  }
@@ -5,6 +5,7 @@ export type Options = {
5
5
  version?: Version;
6
6
  debug?: boolean;
7
7
  skipWaiting?: boolean;
8
+ compact?: boolean;
8
9
  };
9
10
  /**
10
11
  * Produce a string that contains Javascript code to implement
@@ -17,13 +18,15 @@ export type Options = {
17
18
  * - `debug`: true will generate `console.log` notices for
18
19
  * all activity in the service worker. It should be turned off in production.
19
20
  * - `skipWaiting`: setting to `true` has the same effect as
20
- * calling the method as described in the service worker documention (but simpler!).
21
+ * calling the method as described in the service worker documention
22
+ * (but simpler!).
23
+ * = `compact`: output with fewer line feeds and spaces
21
24
  */
22
25
  export declare function generateServiceWorker(inputSpec: Plan, optionsIn?: Options): string;
23
26
  export declare function generateVersion(version: Version): string;
24
27
  export declare function cacheName(version: Version): string;
25
28
  export declare function generateCacheName(version: Version): string;
26
29
  export declare function generateFlag(name: string, bool: boolean): string;
27
- export declare function pathsToJS(paths: InputPaths): string;
28
- export declare function pathToJS(path: string | RegExp | symbol): string;
30
+ export declare function pathsToJS(paths: InputPaths | Array<InputPaths>, compact: boolean): string;
31
+ export declare function pathToJS(path: InputPaths): string;
29
32
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { IncomingMessage, ServerResponse } from "http";
3
2
  import { Options, Plan } from "./generate.mjs";
4
3
  export declare const requestHandler: (plan: Plan, options: Options) => (req: IncomingMessage, res: ServerResponse) => void;
@@ -78,6 +78,9 @@ export type NetworkOnlyStrategy<Paths> = {
78
78
  paths: Paths;
79
79
  };
80
80
  export type RoutableStrategy<Paths> = CacheFirstStrategy<Paths> | NetworkFirstStrategy<Paths> | StaleWhileRevalidateStrategy<Paths> | NetworkOnlyStrategy<Paths> | StaticOfflineBackupStrategy<Paths>;
81
+ export declare function isRoutableStrategy<Paths>(x: {
82
+ strategy: string;
83
+ }): x is RoutableStrategy<Paths>;
81
84
  export type CacheOnInstallStrategy = CachePathOnInstall | CacheFileOnInstall;
82
85
  export type InputCacheStrategy = RoutableStrategy<InputPaths> | CacheOnInstallStrategy;
83
86
  export type InputCacheStrategyAsPaths = RoutableStrategy<InputPaths> | CachePathOnInstall;
@@ -92,12 +95,20 @@ export declare const OriginAndBelow: unique symbol;
92
95
  * for completeness.
93
96
  */
94
97
  export declare const ScopeAndBelow: unique symbol;
95
- export type InputPaths = RegExp | string | OutputPaths | typeof OriginAndBelow | typeof ScopeAndBelow;
98
+ export type InputPaths = RegExp | string | typeof OriginAndBelow | typeof ScopeAndBelow | OutputPaths;
96
99
  export type OutputPaths = Array<string | RegExp>;
97
- export declare function isRoutableStrategy<Paths>(x: {
100
+ /**
101
+ * Run through all the strategies in a plan and extract all
102
+ * the paths that should be "preloaded" on service worker
103
+ * installation. This includes explicit preload paths,
104
+ * preload-files (which have been converted to paths before
105
+ * this call), and offline backup paths.
106
+ */
107
+ export declare function extractAllPreloadPaths(plan: Array<{
98
108
  strategy: string;
99
- }): x is RoutableStrategy<Paths>;
100
- export declare function convertPreloadFilesToPaths(strategy: CacheFileOnInstall): CachePathOnInstall;
109
+ }>): OutputPaths;
110
+ export declare function convertPreloadPathsToCacheFirst(spec: Array<InputCacheStrategyAsPaths>): Array<RoutableStrategy<InputPaths>>;
111
+ export declare function convertAllFilesToPaths(spec: Array<InputCacheStrategy>): Array<InputCacheStrategyAsPaths>;
101
112
  /**
102
113
  * Converts paths specified by scanning the disk to the paths
103
114
  * that are the result of that scan.
@@ -112,15 +123,4 @@ export declare function convertPreloadFilesToPaths(strategy: CacheFileOnInstall)
112
123
  * cache created in the browser.
113
124
  */
114
125
  export declare function convertPreloadFiles(strategy: InputCacheStrategy): InputCacheStrategyAsPaths;
115
- /**
116
- * Run through all the strategies in a plan and extract all
117
- * the paths that should be "preloaded" on service worker
118
- * installation. This includes explicit preload paths,
119
- * preload-files (which have been converted to paths before
120
- * this call), and offline backup paths.
121
- */
122
- export declare function extractAllPreloadPaths(plan: Array<{
123
- strategy: string;
124
- }>): OutputPaths;
125
- export declare function convertPreloadPathsToCacheFirst(spec: Array<InputCacheStrategyAsPaths>): Array<RoutableStrategy<InputPaths>>;
126
- export declare function convertAllFilesToPaths(spec: Array<InputCacheStrategy>): Array<InputCacheStrategyAsPaths>;
126
+ export declare function convertPreloadFilesToPaths(strategy: CacheFileOnInstall): CachePathOnInstall;