@serwist/turbopack 10.0.0-preview.10 → 10.0.0-preview.12
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/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -42
- package/dist/index.react.js +1 -0
- package/dist/index.schema.d.ts +31 -116
- package/dist/index.schema.d.ts.map +1 -1
- package/dist/index.schema.js +71 -4
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/types.d.ts +9 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.react.tsx +1 -1
- package/src/index.schema.ts +16 -4
- package/src/index.ts +61 -39
- package/src/lib/constants.ts +62 -0
- package/src/types.ts +15 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { NextResponse } from "next/server.js";
|
|
2
2
|
import type { InjectManifestOptions } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
* Creates a Route Handler
|
|
4
|
+
* Creates a Route Handler for Serwist files.
|
|
5
5
|
* @param options Options for {@linkcode getFileManifestEntries}.
|
|
6
6
|
*/
|
|
7
7
|
export declare const createSerwistRoute: (options: InjectManifestOptions) => {
|
|
8
|
-
dynamic:
|
|
9
|
-
dynamicParams:
|
|
10
|
-
revalidate:
|
|
11
|
-
generateStaticParams: () => {
|
|
8
|
+
dynamic: "force-static";
|
|
9
|
+
dynamicParams: false;
|
|
10
|
+
revalidate: false;
|
|
11
|
+
generateStaticParams: () => Promise<{
|
|
12
12
|
path: string;
|
|
13
|
-
}[]
|
|
13
|
+
}[]>;
|
|
14
14
|
GET: (_: Request, { params }: {
|
|
15
15
|
params: Promise<{
|
|
16
16
|
path: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,OAAO,KAAK,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAC;AAuCvF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,qBAAqB;;;;;;;aAgFzC,OAAO,cAAc;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;CAajF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ const esbuild = import('esbuild-wasm');
|
|
|
61
61
|
const logSerwistResult = (filePath, buildResult)=>{
|
|
62
62
|
const { count, size, warnings } = buildResult;
|
|
63
63
|
const hasWarnings = warnings && warnings.length > 0;
|
|
64
|
-
if (filePath === "sw.js") {
|
|
64
|
+
if (filePath === "sw.js" && (hasWarnings || count > 0)) {
|
|
65
65
|
logger[hasWarnings ? "warn" : "event"](`${cyan(count)} precache entries ${dim(`(${(size / 1024).toFixed(2)} KiB)`)}${hasWarnings ? `\n${yellow([
|
|
66
66
|
"⚠ warnings",
|
|
67
67
|
...warnings.map((w)=>` ${w}`),
|
|
@@ -89,36 +89,33 @@ const contentTypeMap = {
|
|
|
89
89
|
const createSerwistRoute = (options)=>{
|
|
90
90
|
const dynamic = "force-static", dynamicParams = false, revalidate = false;
|
|
91
91
|
const validation = validateGetManifestOptions(options).then((config)=>{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
92
|
+
return {
|
|
93
|
+
...config,
|
|
94
|
+
disablePrecacheManifest: isDev,
|
|
95
|
+
additionalPrecacheEntries: isDev ? [] : config.additionalPrecacheEntries,
|
|
96
|
+
globIgnores: [
|
|
97
|
+
...config.globIgnores,
|
|
98
|
+
rebasePath({
|
|
99
|
+
file: config.swSrc,
|
|
100
|
+
baseDirectory: config.globDirectory
|
|
101
|
+
})
|
|
102
|
+
],
|
|
103
|
+
manifestTransforms: [
|
|
104
|
+
...config.manifestTransforms ?? [],
|
|
105
|
+
(manifestEntries)=>{
|
|
106
|
+
const manifest = manifestEntries.map((m)=>{
|
|
107
|
+
if (m.url.startsWith(".next/")) m.url = `/_next/${m.url.slice(6)}`;
|
|
108
|
+
if (m.url.startsWith("public/")) m.url = path.posix.join(config.basePath, m.url.slice(7));
|
|
109
|
+
return m;
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
manifest,
|
|
113
|
+
warnings: []
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
};
|
|
111
118
|
});
|
|
112
|
-
const generateStaticParams = ()=>{
|
|
113
|
-
return [
|
|
114
|
-
{
|
|
115
|
-
path: "sw.js"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
path: "sw.js.map"
|
|
119
|
-
}
|
|
120
|
-
];
|
|
121
|
-
};
|
|
122
119
|
let map = null;
|
|
123
120
|
const loadMap = async (filePath)=>{
|
|
124
121
|
const config = await validation;
|
|
@@ -131,22 +128,37 @@ const createSerwistRoute = (options)=>{
|
|
|
131
128
|
warnings
|
|
132
129
|
});
|
|
133
130
|
const result = await (await esbuild).build({
|
|
131
|
+
sourcemap: true,
|
|
132
|
+
format: "esm",
|
|
133
|
+
target: [
|
|
134
|
+
"chrome64",
|
|
135
|
+
"edge79",
|
|
136
|
+
"firefox67",
|
|
137
|
+
"opera51",
|
|
138
|
+
"safari12"
|
|
139
|
+
],
|
|
140
|
+
treeShaking: true,
|
|
141
|
+
minify: !isDev,
|
|
142
|
+
bundle: true,
|
|
143
|
+
...config.esbuildOptions,
|
|
144
|
+
platform: "browser",
|
|
145
|
+
define: {
|
|
146
|
+
...config.esbuildOptions.define,
|
|
147
|
+
...injectionPoint ? {
|
|
148
|
+
[injectionPoint]: manifestString
|
|
149
|
+
} : {}
|
|
150
|
+
},
|
|
151
|
+
outdir: config.cwd,
|
|
152
|
+
write: false,
|
|
153
|
+
entryNames: "[name]",
|
|
154
|
+
assetNames: "[name]-[hash]",
|
|
155
|
+
chunkNames: "[name]-[hash]",
|
|
134
156
|
entryPoints: [
|
|
135
157
|
{
|
|
136
158
|
in: config.swSrc,
|
|
137
159
|
out: "sw"
|
|
138
160
|
}
|
|
139
|
-
]
|
|
140
|
-
format: "esm",
|
|
141
|
-
sourcemap: true,
|
|
142
|
-
bundle: true,
|
|
143
|
-
write: false,
|
|
144
|
-
minify: !isDev,
|
|
145
|
-
define: injectionPoint ? {
|
|
146
|
-
[injectionPoint]: manifestString
|
|
147
|
-
} : undefined,
|
|
148
|
-
outdir: process.cwd(),
|
|
149
|
-
entryNames: "[name]"
|
|
161
|
+
]
|
|
150
162
|
});
|
|
151
163
|
if (result.errors.length) {
|
|
152
164
|
console.error("Failed to build the service worker.", result.errors);
|
|
@@ -160,10 +172,20 @@ const createSerwistRoute = (options)=>{
|
|
|
160
172
|
e.text
|
|
161
173
|
]));
|
|
162
174
|
};
|
|
175
|
+
const generateStaticParams = async ()=>{
|
|
176
|
+
const config = await validation;
|
|
177
|
+
if (!map) map = await loadMap("root");
|
|
178
|
+
return [
|
|
179
|
+
...map.keys().map((e)=>({
|
|
180
|
+
path: path.relative(config.cwd, e)
|
|
181
|
+
}))
|
|
182
|
+
];
|
|
183
|
+
};
|
|
163
184
|
const GET = async (_, { params })=>{
|
|
164
185
|
const { path: filePath } = await params;
|
|
186
|
+
const config = await validation;
|
|
165
187
|
if (!map) map = await loadMap(filePath);
|
|
166
|
-
return new NextResponse(map.get(path.join(
|
|
188
|
+
return new NextResponse(map.get(path.join(config.cwd, filePath)), {
|
|
167
189
|
headers: {
|
|
168
190
|
"Content-Type": contentTypeMap[path.extname(filePath)] || "text/plain",
|
|
169
191
|
"Service-Worker-Allowed": "/"
|
package/dist/index.react.js
CHANGED
|
@@ -11,6 +11,7 @@ function SerwistProvider({ swUrl, register = true, reloadOnOnline = true, option
|
|
|
11
11
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
12
12
|
window.serwist = new Serwist(swUrl, {
|
|
13
13
|
...options,
|
|
14
|
+
type: options?.type || "module",
|
|
14
15
|
scope: options?.scope || "/"
|
|
15
16
|
});
|
|
16
17
|
}
|
package/dist/index.schema.d.ts
CHANGED
|
@@ -1,144 +1,59 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
export declare const turboPartial: z.ZodObject<{
|
|
3
|
+
cwd: z.ZodPrefault<z.ZodString>;
|
|
4
|
+
basePath: z.ZodString;
|
|
5
|
+
esbuildOptions: z.ZodPrefault<z.ZodRecord<z.ZodLiteral<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw"> & z.z.core.$partial, z.ZodAny>>;
|
|
6
|
+
}, z.z.core.$strict>;
|
|
2
7
|
export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
|
|
3
8
|
cwd: z.ZodPrefault<z.ZodString>;
|
|
9
|
+
esbuildOptions: z.ZodPrefault<z.ZodRecord<z.ZodLiteral<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw"> & z.z.core.$partial, z.ZodAny>>;
|
|
4
10
|
basePath: z.ZodString;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodType<import("@serwist/build").ManifestEntry, import("@serwist/build").ManifestEntry, z.z.core.$ZodTypeInternals<import("@serwist/build").ManifestEntry, import("@serwist/build").ManifestEntry>>]>>>;
|
|
12
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
13
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodType<import("@serwist/build").ManifestTransform, import("@serwist/build").ManifestTransform, z.z.core.$ZodTypeInternals<import("@serwist/build").ManifestTransform, import("@serwist/build").ManifestTransform>>>>;
|
|
14
|
+
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
9
16
|
globFollow: z.ZodDefault<z.ZodBoolean>;
|
|
10
17
|
globIgnores: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
18
|
+
globPatterns: z.ZodPrefault<z.ZodArray<z.ZodString>>;
|
|
11
19
|
globStrict: z.ZodDefault<z.ZodBoolean>;
|
|
12
20
|
templatedURLs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
url: z.ZodString;
|
|
17
|
-
}, z.z.core.$strict>]>>>;
|
|
18
|
-
disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
|
|
19
|
-
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
20
|
-
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
21
|
-
size: z.ZodNumber;
|
|
22
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
23
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
-
url: z.ZodString;
|
|
25
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
26
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
27
|
-
size: z.ZodNumber;
|
|
28
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
29
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
-
url: z.ZodString;
|
|
31
|
-
}, z.z.core.$strip>>;
|
|
32
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
-
}, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
34
|
-
size: z.ZodNumber;
|
|
35
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
36
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
|
-
url: z.ZodString;
|
|
38
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
39
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
40
|
-
size: z.ZodNumber;
|
|
41
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
42
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
-
url: z.ZodString;
|
|
44
|
-
}, z.z.core.$strip>>;
|
|
45
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
|
-
}, z.z.core.$strict>>>, z.ZodTransform<z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
47
|
-
size: z.ZodNumber;
|
|
48
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
49
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
-
url: z.ZodString;
|
|
51
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
52
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
53
|
-
size: z.ZodNumber;
|
|
54
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
55
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
-
url: z.ZodString;
|
|
57
|
-
}, z.z.core.$strip>>;
|
|
58
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
-
}, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
60
|
-
size: z.ZodNumber;
|
|
61
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
62
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
-
url: z.ZodString;
|
|
64
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
65
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
66
|
-
size: z.ZodNumber;
|
|
67
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
68
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
-
url: z.ZodString;
|
|
70
|
-
}, z.z.core.$strip>>;
|
|
71
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
72
|
-
}, z.z.core.$strict>>>>>>;
|
|
73
|
-
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
74
|
-
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
21
|
+
injectionPoint: z.ZodPrefault<z.ZodString>;
|
|
22
|
+
swSrc: z.ZodString;
|
|
23
|
+
globDirectory: z.ZodOptional<z.ZodString>;
|
|
75
24
|
}, z.z.core.$strict>, z.ZodTransform<{
|
|
76
25
|
swSrc: string;
|
|
77
26
|
globDirectory: string;
|
|
78
27
|
cwd: string;
|
|
28
|
+
esbuildOptions: Partial<Record<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw", any>>;
|
|
79
29
|
basePath: string;
|
|
80
|
-
|
|
81
|
-
injectionPoint: string;
|
|
30
|
+
maximumFileSizeToCacheInBytes: number;
|
|
82
31
|
globFollow: boolean;
|
|
83
32
|
globIgnores: string[];
|
|
33
|
+
globPatterns: string[];
|
|
84
34
|
globStrict: boolean;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
88
|
-
additionalPrecacheEntries?: (string | {
|
|
89
|
-
url: string;
|
|
90
|
-
integrity?: string | undefined;
|
|
91
|
-
revision?: string | null | undefined;
|
|
92
|
-
})[] | undefined;
|
|
35
|
+
injectionPoint: string;
|
|
36
|
+
additionalPrecacheEntries?: (string | import("@serwist/build").ManifestEntry)[] | undefined;
|
|
93
37
|
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
94
|
-
manifestTransforms?:
|
|
95
|
-
size: z.ZodNumber;
|
|
96
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
97
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
-
url: z.ZodString;
|
|
99
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
100
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
101
|
-
size: z.ZodNumber;
|
|
102
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
103
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
-
url: z.ZodString;
|
|
105
|
-
}, z.z.core.$strip>>;
|
|
106
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
107
|
-
}, z.z.core.$strict>>[] | undefined;
|
|
38
|
+
manifestTransforms?: import("@serwist/build").ManifestTransform[] | undefined;
|
|
108
39
|
modifyURLPrefix?: Record<string, string> | undefined;
|
|
40
|
+
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
109
41
|
}, {
|
|
110
42
|
cwd: string;
|
|
43
|
+
esbuildOptions: Partial<Record<"bundle" | "splitting" | "preserveSymlinks" | "external" | "packages" | "alias" | "loader" | "resolveExtensions" | "mainFields" | "conditions" | "allowOverwrite" | "tsconfig" | "outExtension" | "publicPath" | "inject" | "banner" | "footer" | "plugins" | "sourcemap" | "legalComments" | "sourceRoot" | "sourcesContent" | "format" | "globalName" | "target" | "supported" | "mangleProps" | "reserveProps" | "mangleQuoted" | "mangleCache" | "drop" | "dropLabels" | "minify" | "minifyWhitespace" | "minifyIdentifiers" | "minifySyntax" | "lineLimit" | "charset" | "treeShaking" | "ignoreAnnotations" | "jsx" | "jsxFactory" | "jsxFragment" | "jsxImportSource" | "jsxDev" | "jsxSideEffects" | "define" | "pure" | "keepNames" | "absPaths" | "color" | "logLevel" | "logLimit" | "logOverride" | "tsconfigRaw", any>>;
|
|
111
44
|
basePath: string;
|
|
112
|
-
|
|
113
|
-
injectionPoint: string;
|
|
114
|
-
swSrc: string;
|
|
45
|
+
maximumFileSizeToCacheInBytes: number;
|
|
115
46
|
globFollow: boolean;
|
|
116
47
|
globIgnores: string[];
|
|
48
|
+
globPatterns: string[];
|
|
117
49
|
globStrict: boolean;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
122
|
-
additionalPrecacheEntries?: (string | {
|
|
123
|
-
url: string;
|
|
124
|
-
integrity?: string | undefined;
|
|
125
|
-
revision?: string | null | undefined;
|
|
126
|
-
})[] | undefined;
|
|
50
|
+
injectionPoint: string;
|
|
51
|
+
swSrc: string;
|
|
52
|
+
additionalPrecacheEntries?: (string | import("@serwist/build").ManifestEntry)[] | undefined;
|
|
127
53
|
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
128
|
-
manifestTransforms?:
|
|
129
|
-
size: z.ZodNumber;
|
|
130
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
131
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
132
|
-
url: z.ZodString;
|
|
133
|
-
}, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
134
|
-
manifest: z.ZodArray<z.ZodObject<{
|
|
135
|
-
size: z.ZodNumber;
|
|
136
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
137
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
138
|
-
url: z.ZodString;
|
|
139
|
-
}, z.z.core.$strip>>;
|
|
140
|
-
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
141
|
-
}, z.z.core.$strict>>[] | undefined;
|
|
54
|
+
manifestTransforms?: import("@serwist/build").ManifestTransform[] | undefined;
|
|
142
55
|
modifyURLPrefix?: Record<string, string> | undefined;
|
|
56
|
+
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
57
|
+
globDirectory?: string | undefined;
|
|
143
58
|
}>>;
|
|
144
59
|
//# sourceMappingURL=index.schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.schema.d.ts","sourceRoot":"","sources":["../src/index.schema.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.schema.d.ts","sourceRoot":"","sources":["../src/index.schema.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB,eAAO,MAAM,YAAY;;;;oBAIvB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgB9B,CAAC"}
|
package/dist/index.schema.js
CHANGED
|
@@ -1,20 +1,83 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { injectPartial, globPartial, basePartial } from '@serwist/build/schema';
|
|
2
|
+
import { injectPartial, globPartial, basePartial, assertType } from '@serwist/build/schema';
|
|
3
3
|
import z from 'zod';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_GLOB_PATTERNS = [
|
|
6
6
|
".next/static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}",
|
|
7
7
|
"public/**/*"
|
|
8
8
|
];
|
|
9
|
+
const SUPPORTED_ESBUILD_OPTIONS = [
|
|
10
|
+
"sourcemap",
|
|
11
|
+
"legalComments",
|
|
12
|
+
"sourceRoot",
|
|
13
|
+
"sourcesContent",
|
|
14
|
+
"format",
|
|
15
|
+
"globalName",
|
|
16
|
+
"target",
|
|
17
|
+
"supported",
|
|
18
|
+
"define",
|
|
19
|
+
"treeShaking",
|
|
20
|
+
"minify",
|
|
21
|
+
"mangleProps",
|
|
22
|
+
"reserveProps",
|
|
23
|
+
"mangleQuoted",
|
|
24
|
+
"mangleCache",
|
|
25
|
+
"drop",
|
|
26
|
+
"dropLabels",
|
|
27
|
+
"minifyWhitespace",
|
|
28
|
+
"minifyIdentifiers",
|
|
29
|
+
"minifySyntax",
|
|
30
|
+
"lineLimit",
|
|
31
|
+
"charset",
|
|
32
|
+
"ignoreAnnotations",
|
|
33
|
+
"jsx",
|
|
34
|
+
"jsxFactory",
|
|
35
|
+
"jsxFragment",
|
|
36
|
+
"jsxImportSource",
|
|
37
|
+
"jsxDev",
|
|
38
|
+
"jsxSideEffects",
|
|
39
|
+
"pure",
|
|
40
|
+
"keepNames",
|
|
41
|
+
"absPaths",
|
|
42
|
+
"color",
|
|
43
|
+
"logLevel",
|
|
44
|
+
"logLimit",
|
|
45
|
+
"logOverride",
|
|
46
|
+
"tsconfigRaw",
|
|
47
|
+
"bundle",
|
|
48
|
+
"splitting",
|
|
49
|
+
"preserveSymlinks",
|
|
50
|
+
"external",
|
|
51
|
+
"packages",
|
|
52
|
+
"alias",
|
|
53
|
+
"loader",
|
|
54
|
+
"resolveExtensions",
|
|
55
|
+
"mainFields",
|
|
56
|
+
"conditions",
|
|
57
|
+
"allowOverwrite",
|
|
58
|
+
"tsconfig",
|
|
59
|
+
"outExtension",
|
|
60
|
+
"publicPath",
|
|
61
|
+
"inject",
|
|
62
|
+
"banner",
|
|
63
|
+
"footer",
|
|
64
|
+
"plugins"
|
|
65
|
+
];
|
|
9
66
|
|
|
67
|
+
const turboPartial = z.strictObject({
|
|
68
|
+
cwd: z.string().prefault(process.cwd()),
|
|
69
|
+
basePath: z.string(),
|
|
70
|
+
esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({})
|
|
71
|
+
});
|
|
10
72
|
const injectManifestOptions = z.strictObject({
|
|
11
73
|
...basePartial.shape,
|
|
12
74
|
...globPartial.shape,
|
|
13
75
|
...injectPartial.shape,
|
|
14
|
-
|
|
15
|
-
basePath: z.string(),
|
|
76
|
+
...turboPartial.shape,
|
|
16
77
|
globPatterns: z.array(z.string()).prefault(DEFAULT_GLOB_PATTERNS),
|
|
17
78
|
globDirectory: z.string().optional()
|
|
79
|
+
}).omit({
|
|
80
|
+
disablePrecacheManifest: true
|
|
18
81
|
}).transform((input)=>{
|
|
19
82
|
return {
|
|
20
83
|
...input,
|
|
@@ -22,5 +85,9 @@ const injectManifestOptions = z.strictObject({
|
|
|
22
85
|
globDirectory: input.globDirectory ?? input.cwd
|
|
23
86
|
};
|
|
24
87
|
});
|
|
88
|
+
assertType();
|
|
89
|
+
assertType();
|
|
90
|
+
assertType();
|
|
91
|
+
assertType();
|
|
25
92
|
|
|
26
|
-
export { injectManifestOptions };
|
|
93
|
+
export { injectManifestOptions, turboPartial };
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const DEFAULT_GLOB_PATTERNS: string[];
|
|
2
|
+
export declare const SUPPORTED_ESBUILD_OPTIONS: readonly ["sourcemap", "legalComments", "sourceRoot", "sourcesContent", "format", "globalName", "target", "supported", "define", "treeShaking", "minify", "mangleProps", "reserveProps", "mangleQuoted", "mangleCache", "drop", "dropLabels", "minifyWhitespace", "minifyIdentifiers", "minifySyntax", "lineLimit", "charset", "ignoreAnnotations", "jsx", "jsxFactory", "jsxFragment", "jsxImportSource", "jsxDev", "jsxSideEffects", "pure", "keepNames", "absPaths", "color", "logLevel", "logLimit", "logOverride", "tsconfigRaw", "bundle", "splitting", "preserveSymlinks", "external", "packages", "alias", "loader", "resolveExtensions", "mainFields", "conditions", "allowOverwrite", "tsconfig", "outExtension", "publicPath", "inject", "banner", "footer", "plugins"];
|
|
2
3
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,UAGjC,CAAC;AAEF,eAAO,MAAM,yBAAyB,ovBA0Dc,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { BasePartial, BaseResolved, GlobPartial, GlobResolved, InjectPartial, InjectResolved, OptionalGlobDirectoryPartial, RequiredGlobDirectoryResolved } from "@serwist/build";
|
|
2
|
-
import type { Prettify } from "@serwist/utils";
|
|
2
|
+
import type { Prettify, Require } from "@serwist/utils";
|
|
3
|
+
import type { BuildOptions } from "esbuild-wasm";
|
|
4
|
+
import type { SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
5
|
+
export type EsbuildSupportedOptions = (typeof SUPPORTED_ESBUILD_OPTIONS)[number];
|
|
6
|
+
export type EsbuildOptions = Pick<BuildOptions, EsbuildSupportedOptions>;
|
|
3
7
|
export interface TurboPartial {
|
|
4
8
|
/**
|
|
5
9
|
* The path to your working directory.
|
|
@@ -12,8 +16,9 @@ export interface TurboPartial {
|
|
|
12
16
|
* is not configured, set to `/`.
|
|
13
17
|
*/
|
|
14
18
|
basePath: string;
|
|
19
|
+
esbuildOptions?: EsbuildOptions;
|
|
15
20
|
}
|
|
16
|
-
export type TurboResolved =
|
|
17
|
-
export type InjectManifestOptions = Prettify<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial
|
|
18
|
-
export type InjectManifestOptionsComplete = Prettify<BaseResolved & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved
|
|
21
|
+
export type TurboResolved = Require<TurboPartial, "cwd" | "esbuildOptions">;
|
|
22
|
+
export type InjectManifestOptions = Prettify<Omit<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial, "disablePrecacheManifest">>;
|
|
23
|
+
export type InjectManifestOptionsComplete = Prettify<Omit<BaseResolved & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved, "disablePrecacheManifest">>;
|
|
19
24
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEpE,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC;AAEzE,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,KAAK,GAAG,gBAAgB,CAAC,CAAC;AAE5E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAC1C,IAAI,CAAC,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,4BAA4B,GAAG,YAAY,EAAE,yBAAyB,CAAC,CACzH,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAClD,IAAI,CAAC,YAAY,GAAG,YAAY,GAAG,cAAc,GAAG,6BAA6B,GAAG,aAAa,EAAE,yBAAyB,CAAC,CAC9H,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/turbopack",
|
|
3
|
-
"version": "10.0.0-preview.
|
|
3
|
+
"version": "10.0.0-preview.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "A module that integrates Serwist into your Next.js / Turbopack application.",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"esbuild-wasm": "0.25.8",
|
|
68
68
|
"kolorist": "1.8.0",
|
|
69
69
|
"zod": "4.0.5",
|
|
70
|
-
"@serwist/build": "10.0.0-preview.
|
|
71
|
-
"@serwist/window": "10.0.0-preview.
|
|
72
|
-
"serwist": "10.0.0-preview.
|
|
70
|
+
"@serwist/build": "10.0.0-preview.12",
|
|
71
|
+
"@serwist/window": "10.0.0-preview.12",
|
|
72
|
+
"serwist": "10.0.0-preview.12"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "24.0.14",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"rollup": "4.45.1",
|
|
81
81
|
"type-fest": "4.41.0",
|
|
82
82
|
"typescript": "5.8.3",
|
|
83
|
-
"@serwist/configs": "10.0.0-preview.
|
|
84
|
-
"@serwist/utils": "10.0.0-preview.
|
|
83
|
+
"@serwist/configs": "10.0.0-preview.12",
|
|
84
|
+
"@serwist/utils": "10.0.0-preview.12"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"next": ">=14.0.0",
|
package/src/index.react.tsx
CHANGED
|
@@ -21,7 +21,7 @@ export function SerwistProvider({ swUrl, register = true, reloadOnOnline = true,
|
|
|
21
21
|
const [serwist] = useState(() => {
|
|
22
22
|
if (typeof window === "undefined") return null;
|
|
23
23
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
24
|
-
window.serwist = new Serwist(swUrl, { ...options, scope: options?.scope || "/" });
|
|
24
|
+
window.serwist = new Serwist(swUrl, { ...options, type: options?.type || "module", scope: options?.scope || "/" });
|
|
25
25
|
}
|
|
26
26
|
return window.serwist ?? null;
|
|
27
27
|
});
|
package/src/index.schema.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { basePartial, globPartial, injectPartial } from "@serwist/build/schema";
|
|
2
|
+
import { assertType, type Equals, basePartial, globPartial, injectPartial } from "@serwist/build/schema";
|
|
3
3
|
import z from "zod";
|
|
4
|
-
import { DEFAULT_GLOB_PATTERNS } from "./lib/constants.js";
|
|
4
|
+
import { DEFAULT_GLOB_PATTERNS, SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
5
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete, TurboPartial, TurboResolved } from "./types.js";
|
|
6
|
+
|
|
7
|
+
export const turboPartial = z.strictObject({
|
|
8
|
+
cwd: z.string().prefault(process.cwd()),
|
|
9
|
+
basePath: z.string(),
|
|
10
|
+
esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({}),
|
|
11
|
+
});
|
|
5
12
|
|
|
6
13
|
export const injectManifestOptions = z
|
|
7
14
|
.strictObject({
|
|
8
15
|
...basePartial.shape,
|
|
9
16
|
...globPartial.shape,
|
|
10
17
|
...injectPartial.shape,
|
|
11
|
-
|
|
12
|
-
basePath: z.string(),
|
|
18
|
+
...turboPartial.shape,
|
|
13
19
|
globPatterns: z.array(z.string()).prefault(DEFAULT_GLOB_PATTERNS),
|
|
14
20
|
globDirectory: z.string().optional(),
|
|
15
21
|
})
|
|
22
|
+
.omit({ disablePrecacheManifest: true })
|
|
16
23
|
.transform((input) => {
|
|
17
24
|
return {
|
|
18
25
|
...input,
|
|
@@ -20,3 +27,8 @@ export const injectManifestOptions = z
|
|
|
20
27
|
globDirectory: input.globDirectory ?? input.cwd,
|
|
21
28
|
};
|
|
22
29
|
});
|
|
30
|
+
|
|
31
|
+
assertType<Equals<TurboPartial, z.input<typeof turboPartial>>>();
|
|
32
|
+
assertType<Equals<TurboResolved, z.output<typeof turboPartial>>>();
|
|
33
|
+
assertType<Equals<InjectManifestOptions, z.input<typeof injectManifestOptions>>>();
|
|
34
|
+
assertType<Equals<InjectManifestOptionsComplete, z.output<typeof injectManifestOptions>>>();
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Workaround for Next.js + Turbopack, while plugins are still
|
|
2
|
+
// not supported. This relies on Next.js Route Handlers and file
|
|
3
|
+
// name determinism.
|
|
1
4
|
import path from "node:path";
|
|
2
5
|
import { type BuildResult, getFileManifestEntries, rebasePath } from "@serwist/build";
|
|
3
6
|
import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
|
|
@@ -16,7 +19,7 @@ const logSerwistResult = (filePath: string, buildResult: Pick<BuildResult, "coun
|
|
|
16
19
|
const hasWarnings = warnings && warnings.length > 0;
|
|
17
20
|
// The route is reinitiated for each `path` param, so we only log results
|
|
18
21
|
// if we're prerendering for sw.js.
|
|
19
|
-
if (filePath === "sw.js") {
|
|
22
|
+
if (filePath === "sw.js" && (hasWarnings || count > 0)) {
|
|
20
23
|
logger[hasWarnings ? "warn" : "event"](
|
|
21
24
|
`${cyan(count)} precache entries ${dim(`(${(size / 1024).toFixed(2)} KiB)`)}${
|
|
22
25
|
hasWarnings ? `\n${yellow(["⚠ warnings", ...warnings.map((w) => ` ${w}`), ""].join("\n"))}` : ""
|
|
@@ -46,40 +49,45 @@ const contentTypeMap: Record<string, string> = {
|
|
|
46
49
|
};
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
|
-
* Creates a Route Handler
|
|
52
|
+
* Creates a Route Handler for Serwist files.
|
|
50
53
|
* @param options Options for {@linkcode getFileManifestEntries}.
|
|
51
54
|
*/
|
|
52
55
|
export const createSerwistRoute = (options: InjectManifestOptions) => {
|
|
53
|
-
const dynamic = "force-static",
|
|
54
|
-
dynamicParams = false,
|
|
55
|
-
revalidate = false;
|
|
56
|
+
const dynamic = "force-static" as const,
|
|
57
|
+
dynamicParams = false as const,
|
|
58
|
+
revalidate = false as const;
|
|
56
59
|
const validation = validateGetManifestOptions(options).then((config) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
disablePrecacheManifest: isDev,
|
|
63
|
+
additionalPrecacheEntries: isDev ? [] : config.additionalPrecacheEntries,
|
|
64
|
+
globIgnores: [
|
|
65
|
+
...config.globIgnores,
|
|
66
|
+
// Make sure we leave swSrc out of the precache manifest.
|
|
67
|
+
rebasePath({
|
|
68
|
+
file: config.swSrc,
|
|
69
|
+
baseDirectory: config.globDirectory,
|
|
70
|
+
}),
|
|
71
|
+
],
|
|
72
|
+
manifestTransforms: [
|
|
73
|
+
...(config.manifestTransforms ?? []),
|
|
74
|
+
(manifestEntries) => {
|
|
75
|
+
const manifest = manifestEntries.map((m) => {
|
|
76
|
+
// Replace all references to .next/ with "/_next/".
|
|
77
|
+
if (m.url.startsWith(".next/")) m.url = `/_next/${m.url.slice(6)}`;
|
|
78
|
+
// Replace all references to public/ with "$(basePath)/".
|
|
79
|
+
if (m.url.startsWith("public/")) m.url = path.posix.join(config.basePath, m.url.slice(7));
|
|
80
|
+
return m;
|
|
81
|
+
});
|
|
82
|
+
return { manifest, warnings: [] };
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
78
86
|
});
|
|
79
|
-
const generateStaticParams = () => {
|
|
80
|
-
return [{ path: "sw.js" }, { path: "sw.js.map" }];
|
|
81
|
-
};
|
|
82
87
|
let map: Map<string, string> | null = null;
|
|
88
|
+
// NOTE: ALL FILES MUST HAVE DETERMINISTIC NAMES. THIS IS BECAUSE
|
|
89
|
+
// THE FOLLOWING MAP IS LOADED SEPARATELY FOR `generateStaticParams`
|
|
90
|
+
// AND EVERY `GET` REQUEST TO EACH OF THE FILES.
|
|
83
91
|
const loadMap = async (filePath: string) => {
|
|
84
92
|
const config = await validation;
|
|
85
93
|
const { count, size, manifestEntries, warnings } = await getFileManifestEntries(config);
|
|
@@ -88,19 +96,27 @@ export const createSerwistRoute = (options: InjectManifestOptions) => {
|
|
|
88
96
|
const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries, null, 2);
|
|
89
97
|
logSerwistResult(filePath, { count, size, warnings });
|
|
90
98
|
const result = await (await esbuild).build({
|
|
91
|
-
entryPoints: [{ in: config.swSrc, out: "sw" }],
|
|
92
|
-
format: "esm",
|
|
93
99
|
sourcemap: true,
|
|
100
|
+
format: "esm",
|
|
101
|
+
target: ["chrome64", "edge79", "firefox67", "opera51", "safari12"],
|
|
102
|
+
treeShaking: true,
|
|
103
|
+
minify: !isDev,
|
|
94
104
|
bundle: true,
|
|
105
|
+
...config.esbuildOptions,
|
|
106
|
+
platform: "browser",
|
|
107
|
+
define: {
|
|
108
|
+
...config.esbuildOptions.define,
|
|
109
|
+
...(injectionPoint ? { [injectionPoint]: manifestString } : {}),
|
|
110
|
+
},
|
|
111
|
+
outdir: config.cwd,
|
|
95
112
|
write: false,
|
|
96
|
-
minify: !isDev,
|
|
97
|
-
define: injectionPoint
|
|
98
|
-
? {
|
|
99
|
-
[injectionPoint]: manifestString,
|
|
100
|
-
}
|
|
101
|
-
: undefined,
|
|
102
|
-
outdir: process.cwd(),
|
|
103
113
|
entryNames: "[name]",
|
|
114
|
+
// Asset and chunk names must be at the top, as our path is `/serwist/[path]`,
|
|
115
|
+
// not `/serwist/[...path]`, meaning that we can't resolve paths deeper
|
|
116
|
+
// than one level.
|
|
117
|
+
assetNames: "[name]-[hash]",
|
|
118
|
+
chunkNames: "[name]-[hash]",
|
|
119
|
+
entryPoints: [{ in: config.swSrc, out: "sw" }],
|
|
104
120
|
});
|
|
105
121
|
if (result.errors.length) {
|
|
106
122
|
console.error("Failed to build the service worker.", result.errors);
|
|
@@ -111,11 +127,17 @@ export const createSerwistRoute = (options: InjectManifestOptions) => {
|
|
|
111
127
|
}
|
|
112
128
|
return new Map(result.outputFiles.map((e) => [e.path, e.text]));
|
|
113
129
|
};
|
|
130
|
+
const generateStaticParams = async () => {
|
|
131
|
+
const config = await validation;
|
|
132
|
+
if (!map) map = await loadMap("root");
|
|
133
|
+
return [...map.keys().map((e) => ({ path: path.relative(config.cwd, e) }))];
|
|
134
|
+
};
|
|
114
135
|
const GET = async (_: Request, { params }: { params: Promise<{ path: string }> }) => {
|
|
115
136
|
// TODO: obviously, files get stale in development when we pull this off.
|
|
116
137
|
const { path: filePath } = await params;
|
|
138
|
+
const config = await validation;
|
|
117
139
|
if (!map) map = await loadMap(filePath);
|
|
118
|
-
return new NextResponse(map.get(path.join(
|
|
140
|
+
return new NextResponse(map.get(path.join(config.cwd, filePath)), {
|
|
119
141
|
headers: {
|
|
120
142
|
"Content-Type": contentTypeMap[path.extname(filePath)] || "text/plain",
|
|
121
143
|
"Service-Worker-Allowed": "/",
|
package/src/lib/constants.ts
CHANGED
|
@@ -1,4 +1,66 @@
|
|
|
1
|
+
import type { BuildOptions } from "esbuild-wasm";
|
|
2
|
+
|
|
1
3
|
export const DEFAULT_GLOB_PATTERNS = [
|
|
2
4
|
".next/static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}",
|
|
3
5
|
"public/**/*",
|
|
4
6
|
];
|
|
7
|
+
|
|
8
|
+
export const SUPPORTED_ESBUILD_OPTIONS = [
|
|
9
|
+
// CommonOptions
|
|
10
|
+
"sourcemap",
|
|
11
|
+
"legalComments",
|
|
12
|
+
"sourceRoot",
|
|
13
|
+
"sourcesContent",
|
|
14
|
+
"format",
|
|
15
|
+
"globalName",
|
|
16
|
+
"target",
|
|
17
|
+
"supported",
|
|
18
|
+
"define",
|
|
19
|
+
"treeShaking",
|
|
20
|
+
"minify",
|
|
21
|
+
"mangleProps",
|
|
22
|
+
"reserveProps",
|
|
23
|
+
"mangleQuoted",
|
|
24
|
+
"mangleCache",
|
|
25
|
+
"drop",
|
|
26
|
+
"dropLabels",
|
|
27
|
+
"minifyWhitespace",
|
|
28
|
+
"minifyIdentifiers",
|
|
29
|
+
"minifySyntax",
|
|
30
|
+
"lineLimit",
|
|
31
|
+
"charset",
|
|
32
|
+
"ignoreAnnotations",
|
|
33
|
+
"jsx",
|
|
34
|
+
"jsxFactory",
|
|
35
|
+
"jsxFragment",
|
|
36
|
+
"jsxImportSource",
|
|
37
|
+
"jsxDev",
|
|
38
|
+
"jsxSideEffects",
|
|
39
|
+
"pure",
|
|
40
|
+
"keepNames",
|
|
41
|
+
"absPaths",
|
|
42
|
+
"color",
|
|
43
|
+
"logLevel",
|
|
44
|
+
"logLimit",
|
|
45
|
+
"logOverride",
|
|
46
|
+
"tsconfigRaw",
|
|
47
|
+
// BuildOptions
|
|
48
|
+
"bundle",
|
|
49
|
+
"splitting",
|
|
50
|
+
"preserveSymlinks",
|
|
51
|
+
"external",
|
|
52
|
+
"packages",
|
|
53
|
+
"alias",
|
|
54
|
+
"loader",
|
|
55
|
+
"resolveExtensions",
|
|
56
|
+
"mainFields",
|
|
57
|
+
"conditions",
|
|
58
|
+
"allowOverwrite",
|
|
59
|
+
"tsconfig",
|
|
60
|
+
"outExtension",
|
|
61
|
+
"publicPath",
|
|
62
|
+
"inject",
|
|
63
|
+
"banner",
|
|
64
|
+
"footer",
|
|
65
|
+
"plugins",
|
|
66
|
+
] as const satisfies readonly (keyof BuildOptions)[];
|
package/src/types.ts
CHANGED
|
@@ -8,10 +8,13 @@ import type {
|
|
|
8
8
|
OptionalGlobDirectoryPartial,
|
|
9
9
|
RequiredGlobDirectoryResolved,
|
|
10
10
|
} from "@serwist/build";
|
|
11
|
-
import {
|
|
12
|
-
import type {
|
|
13
|
-
import type
|
|
14
|
-
|
|
11
|
+
import type { Prettify, Require } from "@serwist/utils";
|
|
12
|
+
import type { BuildOptions } from "esbuild-wasm";
|
|
13
|
+
import type { SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
14
|
+
|
|
15
|
+
export type EsbuildSupportedOptions = (typeof SUPPORTED_ESBUILD_OPTIONS)[number];
|
|
16
|
+
|
|
17
|
+
export type EsbuildOptions = Pick<BuildOptions, EsbuildSupportedOptions>;
|
|
15
18
|
|
|
16
19
|
export interface TurboPartial {
|
|
17
20
|
/**
|
|
@@ -25,13 +28,15 @@ export interface TurboPartial {
|
|
|
25
28
|
* is not configured, set to `/`.
|
|
26
29
|
*/
|
|
27
30
|
basePath: string;
|
|
31
|
+
esbuildOptions?: EsbuildOptions;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export type TurboResolved =
|
|
31
|
-
|
|
32
|
-
export type InjectManifestOptions = Prettify<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial>;
|
|
34
|
+
export type TurboResolved = Require<TurboPartial, "cwd" | "esbuildOptions">;
|
|
33
35
|
|
|
34
|
-
export type
|
|
36
|
+
export type InjectManifestOptions = Prettify<
|
|
37
|
+
Omit<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial, "disablePrecacheManifest">
|
|
38
|
+
>;
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
export type InjectManifestOptionsComplete = Prettify<
|
|
41
|
+
Omit<BaseResolved & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved, "disablePrecacheManifest">
|
|
42
|
+
>;
|