@serwist/turbopack 9.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2023 Google LLC, 2019-2023 ShadowWalker w@weiw.io https://weiw.io, 2020-2023 Anthony Fu <https://github.com/antfu>, 2023-PRESENT Serwist
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This module's documentation can be found at https://serwist.pages.dev/docs/next/turbo.
@@ -0,0 +1,20 @@
1
+ import { NextResponse } from "next/server.js";
2
+ import type { InjectManifestOptions } from "./types.js";
3
+ /**
4
+ * Creates a Route Handler for Serwist files.
5
+ * @param options Options for {@linkcode getFileManifestEntries}.
6
+ */
7
+ export declare const createSerwistRoute: (options: InjectManifestOptions) => {
8
+ dynamic: "force-static";
9
+ dynamicParams: false;
10
+ revalidate: false;
11
+ generateStaticParams: () => Promise<{
12
+ path: string;
13
+ }[]>;
14
+ GET: (_: Request, { params }: {
15
+ params: Promise<{
16
+ path: string;
17
+ }>;
18
+ }) => Promise<NextResponse<unknown>>;
19
+ };
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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;;;;;;;aAoFzC,OAAO,cAAc;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;CAajF,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,210 @@
1
+ import path from 'node:path';
2
+ import { rebasePath, getFileManifestEntries } from '@serwist/build';
3
+ import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
4
+ import { green, bold, white, yellow, red, cyan, dim } from 'kolorist';
5
+ import { NextResponse } from 'next/server.js';
6
+ import { z } from 'zod';
7
+ import { injectManifestOptions } from './index.schema.js';
8
+ import { createRequire } from 'node:module';
9
+ import semver from 'semver';
10
+
11
+ const require$1 = createRequire(import.meta.url);
12
+ const LOGGING_SPACE_PREFIX = semver.gte(require$1("next/package.json").version, "16.0.0") ? "" : " ";
13
+ const prefixedLog = (prefixType, ...message)=>{
14
+ let prefix;
15
+ let consoleMethod;
16
+ switch(prefixType){
17
+ case "wait":
18
+ prefix = `${white(bold("○"))} (serwist)`;
19
+ consoleMethod = "log";
20
+ break;
21
+ case "error":
22
+ prefix = `${red(bold("X"))} (serwist)`;
23
+ consoleMethod = "error";
24
+ break;
25
+ case "warn":
26
+ prefix = `${yellow(bold("⚠"))} (serwist)`;
27
+ consoleMethod = "warn";
28
+ break;
29
+ case "info":
30
+ prefix = `${white(bold("○"))} (serwist)`;
31
+ consoleMethod = "log";
32
+ break;
33
+ case "event":
34
+ prefix = `${green(bold("✓"))} (serwist)`;
35
+ consoleMethod = "log";
36
+ break;
37
+ }
38
+ if ((message[0] === "" || message[0] === undefined) && message.length === 1) {
39
+ message.shift();
40
+ }
41
+ if (message.length === 0) {
42
+ console[consoleMethod]("");
43
+ } else {
44
+ console[consoleMethod](`${LOGGING_SPACE_PREFIX}${prefix}`, ...message);
45
+ }
46
+ };
47
+ const wait = (...message)=>prefixedLog("wait", ...message);
48
+ const error = (...message)=>prefixedLog("error", ...message);
49
+ const warn = (...message)=>prefixedLog("warn", ...message);
50
+ const info = (...message)=>prefixedLog("info", ...message);
51
+ const event = (...message)=>prefixedLog("event", ...message);
52
+
53
+ var logger = /*#__PURE__*/Object.freeze({
54
+ __proto__: null,
55
+ error: error,
56
+ event: event,
57
+ info: info,
58
+ wait: wait,
59
+ warn: warn
60
+ });
61
+
62
+ const esbuild = import('esbuild-wasm');
63
+ const logSerwistResult = (filePath, buildResult)=>{
64
+ const { count, size, warnings } = buildResult;
65
+ const hasWarnings = warnings && warnings.length > 0;
66
+ if (filePath === "sw.js" && (hasWarnings || count > 0)) {
67
+ logger[hasWarnings ? "warn" : "event"](`${cyan(count)} precache entries ${dim(`(${(size / 1024).toFixed(2)} KiB)`)}${hasWarnings ? `\n${yellow([
68
+ "⚠ warnings",
69
+ ...warnings.map((w)=>` ${w}`),
70
+ ""
71
+ ].join("\n"))}` : ""}`);
72
+ }
73
+ };
74
+ const validateGetManifestOptions = async (input)=>{
75
+ const result = await injectManifestOptions.spa(input, {
76
+ error: validationErrorMap
77
+ });
78
+ if (!result.success) {
79
+ throw new SerwistConfigError({
80
+ moduleName: "@serwist/turbopack",
81
+ message: z.prettifyError(result.error)
82
+ });
83
+ }
84
+ return result.data;
85
+ };
86
+ const isDev = process.env.NODE_ENV === "development";
87
+ const contentTypeMap = {
88
+ ".js": "application/javascript",
89
+ ".map": "application/json; charset=UTF-8"
90
+ };
91
+ const createSerwistRoute = (options)=>{
92
+ const dynamic = "force-static", dynamicParams = false, revalidate = false;
93
+ const validation = validateGetManifestOptions(options).then((config)=>{
94
+ return {
95
+ ...config,
96
+ disablePrecacheManifest: isDev,
97
+ additionalPrecacheEntries: isDev ? [] : config.additionalPrecacheEntries,
98
+ globIgnores: [
99
+ ...config.globIgnores,
100
+ rebasePath({
101
+ file: config.swSrc,
102
+ baseDirectory: config.globDirectory
103
+ })
104
+ ],
105
+ manifestTransforms: [
106
+ ...config.manifestTransforms ?? [],
107
+ (manifestEntries)=>{
108
+ const manifest = manifestEntries.map((m)=>{
109
+ if (m.url.startsWith(config.nextConfig.distDir)) {
110
+ m.url = `${config.nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(config.nextConfig.distDir.length)}`;
111
+ }
112
+ if (m.url.startsWith("public/")) {
113
+ m.url = path.posix.join(config.nextConfig.basePath, m.url.slice(7));
114
+ }
115
+ return m;
116
+ });
117
+ return {
118
+ manifest,
119
+ warnings: []
120
+ };
121
+ }
122
+ ]
123
+ };
124
+ });
125
+ let map = null;
126
+ const loadMap = async (filePath)=>{
127
+ const config = await validation;
128
+ const { count, size, manifestEntries, warnings } = await getFileManifestEntries(config);
129
+ const injectionPoint = config.injectionPoint || "";
130
+ const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries, null, 2);
131
+ logSerwistResult(filePath, {
132
+ count,
133
+ size,
134
+ warnings
135
+ });
136
+ const result = await (await esbuild).build({
137
+ sourcemap: true,
138
+ format: "esm",
139
+ target: [
140
+ "chrome64",
141
+ "edge79",
142
+ "firefox67",
143
+ "opera51",
144
+ "safari12"
145
+ ],
146
+ treeShaking: true,
147
+ minify: !isDev,
148
+ bundle: true,
149
+ ...config.esbuildOptions,
150
+ platform: "browser",
151
+ define: {
152
+ ...config.esbuildOptions.define,
153
+ ...injectionPoint ? {
154
+ [injectionPoint]: manifestString
155
+ } : {}
156
+ },
157
+ outdir: config.cwd,
158
+ write: false,
159
+ entryNames: "[name]",
160
+ assetNames: "[name]-[hash]",
161
+ chunkNames: "[name]-[hash]",
162
+ entryPoints: [
163
+ {
164
+ in: config.swSrc,
165
+ out: "sw"
166
+ }
167
+ ]
168
+ });
169
+ if (result.errors.length) {
170
+ console.error("Failed to build the service worker.", result.errors);
171
+ throw new Error();
172
+ }
173
+ if (result.warnings.length) {
174
+ console.warn(result.warnings);
175
+ }
176
+ return new Map(result.outputFiles.map((e)=>[
177
+ e.path,
178
+ e.text
179
+ ]));
180
+ };
181
+ const generateStaticParams = async ()=>{
182
+ const config = await validation;
183
+ if (!map) map = await loadMap("root");
184
+ return [
185
+ ...map.keys().map((e)=>({
186
+ path: path.relative(config.cwd, e)
187
+ }))
188
+ ];
189
+ };
190
+ const GET = async (_, { params })=>{
191
+ const { path: filePath } = await params;
192
+ const config = await validation;
193
+ if (!map) map = await loadMap(filePath);
194
+ return new NextResponse(map.get(path.join(config.cwd, filePath)), {
195
+ headers: {
196
+ "Content-Type": contentTypeMap[path.extname(filePath)] || "text/plain",
197
+ "Service-Worker-Allowed": "/"
198
+ }
199
+ });
200
+ };
201
+ return {
202
+ dynamic,
203
+ dynamicParams,
204
+ revalidate,
205
+ generateStaticParams,
206
+ GET
207
+ };
208
+ };
209
+
210
+ export { createSerwistRoute };
@@ -0,0 +1,16 @@
1
+ import { Serwist } from "@serwist/window";
2
+ import { type ReactNode } from "react";
3
+ export interface SerwistProviderProps {
4
+ swUrl: string;
5
+ register?: boolean;
6
+ reloadOnOnline?: boolean;
7
+ options?: RegistrationOptions;
8
+ children?: ReactNode;
9
+ }
10
+ declare global {
11
+ interface Window {
12
+ serwist: Serwist;
13
+ }
14
+ }
15
+ export declare function SerwistProvider({ swUrl, register, reloadOnOnline, options, children }: SerwistProviderProps): import("react").JSX.Element;
16
+ //# sourceMappingURL=index.react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG5D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,QAAe,EAAE,cAAqB,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,oBAAoB,+BAwBzH"}
@@ -0,0 +1,49 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Serwist } from '@serwist/window';
3
+ import { isCurrentPageOutOfScope } from '@serwist/window/internal';
4
+ import { createContext, useState, useEffect } from 'react';
5
+
6
+ const SerwistContext = createContext(null);
7
+
8
+ function SerwistProvider({ swUrl, register = true, reloadOnOnline = true, options, children }) {
9
+ const [serwist] = useState(()=>{
10
+ if (typeof window === "undefined") return null;
11
+ if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
12
+ window.serwist = new Serwist(swUrl, {
13
+ ...options,
14
+ type: options?.type || "module",
15
+ scope: options?.scope || "/"
16
+ });
17
+ }
18
+ return window.serwist ?? null;
19
+ });
20
+ useEffect(()=>{
21
+ const scope = options?.scope || "/";
22
+ if (register && !isCurrentPageOutOfScope(scope)) {
23
+ void serwist?.register();
24
+ }
25
+ }, [
26
+ register,
27
+ options?.scope,
28
+ serwist?.register
29
+ ]);
30
+ useEffect(()=>{
31
+ const reload = ()=>location.reload();
32
+ if (reloadOnOnline) {
33
+ window.addEventListener("online", reload);
34
+ }
35
+ return ()=>{
36
+ window.removeEventListener("online", reload);
37
+ };
38
+ }, [
39
+ reloadOnOnline
40
+ ]);
41
+ return jsx(SerwistContext.Provider, {
42
+ value: {
43
+ serwist
44
+ },
45
+ children: children
46
+ });
47
+ }
48
+
49
+ export { SerwistProvider };
@@ -0,0 +1,165 @@
1
+ import z from "zod";
2
+ export declare const turboPartial: z.ZodObject<{
3
+ cwd: z.ZodPrefault<z.ZodString>;
4
+ nextConfig: z.ZodObject<{
5
+ assetPrefix: z.ZodOptional<z.ZodString>;
6
+ basePath: z.ZodPrefault<z.ZodString>;
7
+ distDir: z.ZodPrefault<z.ZodString>;
8
+ }, z.z.core.$strict>;
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>>;
10
+ }, z.z.core.$strict>;
11
+ export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
12
+ cwd: z.ZodPrefault<z.ZodString>;
13
+ 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>>;
14
+ nextConfig: z.ZodObject<{
15
+ assetPrefix: z.ZodOptional<z.ZodString>;
16
+ basePath: z.ZodPrefault<z.ZodString>;
17
+ distDir: z.ZodPrefault<z.ZodString>;
18
+ }, z.z.core.$strict>;
19
+ additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
20
+ integrity: z.ZodOptional<z.ZodString>;
21
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ url: z.ZodString;
23
+ }, z.z.core.$strict>]>>>;
24
+ dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
25
+ manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
26
+ size: z.ZodNumber;
27
+ integrity: z.ZodOptional<z.ZodString>;
28
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
+ url: z.ZodString;
30
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
31
+ manifest: z.ZodArray<z.ZodObject<{
32
+ size: z.ZodNumber;
33
+ integrity: z.ZodOptional<z.ZodString>;
34
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
+ url: z.ZodString;
36
+ }, z.z.core.$strip>>;
37
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
38
+ }, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
39
+ size: z.ZodNumber;
40
+ integrity: z.ZodOptional<z.ZodString>;
41
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ url: z.ZodString;
43
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
44
+ manifest: z.ZodArray<z.ZodObject<{
45
+ size: z.ZodNumber;
46
+ integrity: z.ZodOptional<z.ZodString>;
47
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
48
+ url: z.ZodString;
49
+ }, z.z.core.$strip>>;
50
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
51
+ }, z.z.core.$strict>>>, z.ZodTransform<z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
52
+ size: z.ZodNumber;
53
+ integrity: z.ZodOptional<z.ZodString>;
54
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ url: z.ZodString;
56
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
57
+ manifest: z.ZodArray<z.ZodObject<{
58
+ size: z.ZodNumber;
59
+ integrity: z.ZodOptional<z.ZodString>;
60
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
+ url: z.ZodString;
62
+ }, z.z.core.$strip>>;
63
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
+ }, z.z.core.$strict>>, z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
65
+ size: z.ZodNumber;
66
+ integrity: z.ZodOptional<z.ZodString>;
67
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
+ url: z.ZodString;
69
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
70
+ manifest: z.ZodArray<z.ZodObject<{
71
+ size: z.ZodNumber;
72
+ integrity: z.ZodOptional<z.ZodString>;
73
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
74
+ url: z.ZodString;
75
+ }, z.z.core.$strip>>;
76
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ }, z.z.core.$strict>>>>>>;
78
+ maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
79
+ modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
80
+ globFollow: z.ZodDefault<z.ZodBoolean>;
81
+ globIgnores: z.ZodDefault<z.ZodArray<z.ZodString>>;
82
+ globPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
83
+ globStrict: z.ZodDefault<z.ZodBoolean>;
84
+ templatedURLs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
85
+ injectionPoint: z.ZodDefault<z.ZodString>;
86
+ swSrc: z.ZodString;
87
+ globDirectory: z.ZodOptional<z.ZodString>;
88
+ }, z.z.core.$strict>, z.ZodTransform<{
89
+ swSrc: string;
90
+ globPatterns: string[];
91
+ globDirectory: string;
92
+ dontCacheBustURLsMatching: RegExp;
93
+ nextConfig: {
94
+ distDir: string;
95
+ basePath: string;
96
+ assetPrefix?: string | undefined;
97
+ };
98
+ cwd: string;
99
+ 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>>;
100
+ maximumFileSizeToCacheInBytes: number;
101
+ globFollow: boolean;
102
+ globIgnores: string[];
103
+ globStrict: boolean;
104
+ injectionPoint: string;
105
+ additionalPrecacheEntries?: (string | {
106
+ url: string;
107
+ integrity?: string | undefined;
108
+ revision?: string | null | undefined;
109
+ })[] | undefined;
110
+ manifestTransforms?: z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
111
+ size: z.ZodNumber;
112
+ integrity: z.ZodOptional<z.ZodString>;
113
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
114
+ url: z.ZodString;
115
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
116
+ manifest: z.ZodArray<z.ZodObject<{
117
+ size: z.ZodNumber;
118
+ integrity: z.ZodOptional<z.ZodString>;
119
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
120
+ url: z.ZodString;
121
+ }, z.z.core.$strip>>;
122
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
123
+ }, z.z.core.$strict>>[] | undefined;
124
+ modifyURLPrefix?: Record<string, string> | undefined;
125
+ templatedURLs?: Record<string, string | string[]> | undefined;
126
+ }, {
127
+ cwd: string;
128
+ 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>>;
129
+ nextConfig: {
130
+ basePath: string;
131
+ distDir: string;
132
+ assetPrefix?: string | undefined;
133
+ };
134
+ maximumFileSizeToCacheInBytes: number;
135
+ globFollow: boolean;
136
+ globIgnores: string[];
137
+ globStrict: boolean;
138
+ injectionPoint: string;
139
+ swSrc: string;
140
+ additionalPrecacheEntries?: (string | {
141
+ url: string;
142
+ integrity?: string | undefined;
143
+ revision?: string | null | undefined;
144
+ })[] | undefined;
145
+ dontCacheBustURLsMatching?: RegExp | undefined;
146
+ manifestTransforms?: z.z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
147
+ size: z.ZodNumber;
148
+ integrity: z.ZodOptional<z.ZodString>;
149
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
150
+ url: z.ZodString;
151
+ }, z.z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
152
+ manifest: z.ZodArray<z.ZodObject<{
153
+ size: z.ZodNumber;
154
+ integrity: z.ZodOptional<z.ZodString>;
155
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
156
+ url: z.ZodString;
157
+ }, z.z.core.$strip>>;
158
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
159
+ }, z.z.core.$strict>>[] | undefined;
160
+ modifyURLPrefix?: Record<string, string> | undefined;
161
+ globPatterns?: string[] | undefined;
162
+ templatedURLs?: Record<string, string | string[]> | undefined;
163
+ globDirectory?: string | undefined;
164
+ }>>;
165
+ //# sourceMappingURL=index.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.schema.d.ts","sourceRoot":"","sources":["../src/index.schema.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,YAAY;;;;;;;;oBAQvB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyB9B,CAAC"}
@@ -0,0 +1,107 @@
1
+ import path from 'node:path';
2
+ import { injectPartial, globPartial, basePartial, assertType } from '@serwist/build/schema';
3
+ import z from 'zod';
4
+
5
+ const SUPPORTED_ESBUILD_OPTIONS = [
6
+ "sourcemap",
7
+ "legalComments",
8
+ "sourceRoot",
9
+ "sourcesContent",
10
+ "format",
11
+ "globalName",
12
+ "target",
13
+ "supported",
14
+ "define",
15
+ "treeShaking",
16
+ "minify",
17
+ "mangleProps",
18
+ "reserveProps",
19
+ "mangleQuoted",
20
+ "mangleCache",
21
+ "drop",
22
+ "dropLabels",
23
+ "minifyWhitespace",
24
+ "minifyIdentifiers",
25
+ "minifySyntax",
26
+ "lineLimit",
27
+ "charset",
28
+ "ignoreAnnotations",
29
+ "jsx",
30
+ "jsxFactory",
31
+ "jsxFragment",
32
+ "jsxImportSource",
33
+ "jsxDev",
34
+ "jsxSideEffects",
35
+ "pure",
36
+ "keepNames",
37
+ "absPaths",
38
+ "color",
39
+ "logLevel",
40
+ "logLimit",
41
+ "logOverride",
42
+ "tsconfigRaw",
43
+ "bundle",
44
+ "splitting",
45
+ "preserveSymlinks",
46
+ "external",
47
+ "packages",
48
+ "alias",
49
+ "loader",
50
+ "resolveExtensions",
51
+ "mainFields",
52
+ "conditions",
53
+ "allowOverwrite",
54
+ "tsconfig",
55
+ "outExtension",
56
+ "publicPath",
57
+ "inject",
58
+ "banner",
59
+ "footer",
60
+ "plugins"
61
+ ];
62
+
63
+ const generateGlobPatterns = (distDir)=>[
64
+ `${distDir}static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}`,
65
+ "public/**/*"
66
+ ];
67
+
68
+ const turboPartial = z.strictObject({
69
+ cwd: z.string().prefault(process.cwd()),
70
+ nextConfig: z.strictObject({
71
+ assetPrefix: z.string().optional(),
72
+ basePath: z.string().prefault("/"),
73
+ distDir: z.string().prefault(".next")
74
+ }),
75
+ esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({})
76
+ });
77
+ const injectManifestOptions = z.strictObject({
78
+ ...basePartial.shape,
79
+ ...globPartial.shape,
80
+ ...injectPartial.shape,
81
+ ...turboPartial.shape,
82
+ globPatterns: z.array(z.string()).optional(),
83
+ globDirectory: z.string().optional()
84
+ }).omit({
85
+ disablePrecacheManifest: true
86
+ }).transform((input)=>{
87
+ let distDir = input.nextConfig.distDir;
88
+ if (distDir[0] === "/") distDir = distDir.slice(1);
89
+ if (distDir[distDir.length - 1] !== "/") distDir += "/";
90
+ return {
91
+ ...input,
92
+ swSrc: path.isAbsolute(input.swSrc) ? input.swSrc : path.join(input.cwd, input.swSrc),
93
+ globPatterns: input.globPatterns ?? generateGlobPatterns(distDir),
94
+ globDirectory: input.globDirectory ?? input.cwd,
95
+ dontCacheBustURLsMatching: input.dontCacheBustURLsMatching ?? new RegExp(`^${distDir}static/`),
96
+ nextConfig: {
97
+ ...input.nextConfig,
98
+ distDir
99
+ }
100
+ };
101
+ });
102
+ assertType();
103
+ assertType();
104
+ assertType();
105
+ assertType();
106
+
107
+ export { injectManifestOptions, turboPartial };
@@ -0,0 +1,14 @@
1
+ import type { RuntimeCaching } from "serwist";
2
+ export declare const PAGES_CACHE_NAME: {
3
+ readonly rscPrefetch: "pages-rsc-prefetch";
4
+ readonly rsc: "pages-rsc";
5
+ readonly html: "pages";
6
+ };
7
+ /**
8
+ * The default, recommended list of caching strategies for applications
9
+ * built with Next.js.
10
+ *
11
+ * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
12
+ */
13
+ export declare const defaultCache: RuntimeCaching[];
14
+ //# sourceMappingURL=index.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EAkQlC,CAAC"}