@serwist/turbopack 10.0.0-preview.12 → 10.0.0-preview.14
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.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.schema.d.ts +24 -8
- package/dist/index.schema.d.ts.map +1 -1
- package/dist/index.schema.js +21 -7
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +12 -9
- package/dist/lib/constants.d.ts +0 -1
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/types.d.ts +38 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/index.schema.ts +17 -3
- package/src/index.ts +8 -4
- package/src/index.worker.ts +14 -18
- package/src/lib/constants.ts +0 -5
- package/src/lib/utils.ts +4 -0
- package/src/types.ts +42 -5
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;;;;;;;
|
|
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
CHANGED
|
@@ -104,8 +104,12 @@ const createSerwistRoute = (options)=>{
|
|
|
104
104
|
...config.manifestTransforms ?? [],
|
|
105
105
|
(manifestEntries)=>{
|
|
106
106
|
const manifest = manifestEntries.map((m)=>{
|
|
107
|
-
if (m.url.startsWith(
|
|
108
|
-
|
|
107
|
+
if (m.url.startsWith(config.nextConfig.distDir)) {
|
|
108
|
+
m.url = `${config.nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(config.nextConfig.distDir.length)}`;
|
|
109
|
+
}
|
|
110
|
+
if (m.url.startsWith("public/")) {
|
|
111
|
+
m.url = path.posix.join(config.nextConfig.basePath, m.url.slice(7));
|
|
112
|
+
}
|
|
109
113
|
return m;
|
|
110
114
|
});
|
|
111
115
|
return {
|
|
@@ -120,7 +124,7 @@ const createSerwistRoute = (options)=>{
|
|
|
120
124
|
const loadMap = async (filePath)=>{
|
|
121
125
|
const config = await validation;
|
|
122
126
|
const { count, size, manifestEntries, warnings } = await getFileManifestEntries(config);
|
|
123
|
-
const injectionPoint = config.injectionPoint
|
|
127
|
+
const injectionPoint = config.injectionPoint || "";
|
|
124
128
|
const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries, null, 2);
|
|
125
129
|
logSerwistResult(filePath, {
|
|
126
130
|
count,
|
package/dist/index.schema.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
export declare const turboPartial: z.ZodObject<{
|
|
3
3
|
cwd: z.ZodPrefault<z.ZodString>;
|
|
4
|
-
|
|
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>;
|
|
5
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>>;
|
|
6
10
|
}, z.z.core.$strict>;
|
|
7
11
|
export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
|
|
8
12
|
cwd: z.ZodPrefault<z.ZodString>;
|
|
9
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>>;
|
|
10
|
-
|
|
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>;
|
|
11
19
|
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
20
|
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
13
21
|
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>>>>;
|
|
@@ -15,7 +23,7 @@ export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
|
|
|
15
23
|
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
16
24
|
globFollow: z.ZodDefault<z.ZodBoolean>;
|
|
17
25
|
globIgnores: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
18
|
-
globPatterns: z.
|
|
26
|
+
globPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
27
|
globStrict: z.ZodDefault<z.ZodBoolean>;
|
|
20
28
|
templatedURLs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
|
|
21
29
|
injectionPoint: z.ZodPrefault<z.ZodString>;
|
|
@@ -23,29 +31,36 @@ export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
|
|
|
23
31
|
globDirectory: z.ZodOptional<z.ZodString>;
|
|
24
32
|
}, z.z.core.$strict>, z.ZodTransform<{
|
|
25
33
|
swSrc: string;
|
|
34
|
+
globPatterns: string[];
|
|
26
35
|
globDirectory: string;
|
|
36
|
+
dontCacheBustURLsMatching: RegExp;
|
|
37
|
+
nextConfig: {
|
|
38
|
+
distDir: string;
|
|
39
|
+
basePath: string;
|
|
40
|
+
assetPrefix?: string | undefined;
|
|
41
|
+
};
|
|
27
42
|
cwd: string;
|
|
28
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>>;
|
|
29
|
-
basePath: string;
|
|
30
44
|
maximumFileSizeToCacheInBytes: number;
|
|
31
45
|
globFollow: boolean;
|
|
32
46
|
globIgnores: string[];
|
|
33
|
-
globPatterns: string[];
|
|
34
47
|
globStrict: boolean;
|
|
35
48
|
injectionPoint: string;
|
|
36
49
|
additionalPrecacheEntries?: (string | import("@serwist/build").ManifestEntry)[] | undefined;
|
|
37
|
-
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
38
50
|
manifestTransforms?: import("@serwist/build").ManifestTransform[] | undefined;
|
|
39
51
|
modifyURLPrefix?: Record<string, string> | undefined;
|
|
40
52
|
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
41
53
|
}, {
|
|
42
54
|
cwd: string;
|
|
43
55
|
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>>;
|
|
44
|
-
|
|
56
|
+
nextConfig: {
|
|
57
|
+
basePath: string;
|
|
58
|
+
distDir: string;
|
|
59
|
+
assetPrefix?: string | undefined;
|
|
60
|
+
};
|
|
45
61
|
maximumFileSizeToCacheInBytes: number;
|
|
46
62
|
globFollow: boolean;
|
|
47
63
|
globIgnores: string[];
|
|
48
|
-
globPatterns: string[];
|
|
49
64
|
globStrict: boolean;
|
|
50
65
|
injectionPoint: string;
|
|
51
66
|
swSrc: string;
|
|
@@ -53,6 +68,7 @@ export declare const injectManifestOptions: z.ZodPipe<z.ZodObject<{
|
|
|
53
68
|
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
54
69
|
manifestTransforms?: import("@serwist/build").ManifestTransform[] | undefined;
|
|
55
70
|
modifyURLPrefix?: Record<string, string> | undefined;
|
|
71
|
+
globPatterns?: string[] | undefined;
|
|
56
72
|
templatedURLs?: Record<string, string | string[]> | undefined;
|
|
57
73
|
globDirectory?: string | undefined;
|
|
58
74
|
}>>;
|
|
@@ -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;AAKpB,eAAO,MAAM,YAAY;;;;;;;;oBAQvB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyB9B,CAAC"}
|
package/dist/index.schema.js
CHANGED
|
@@ -2,10 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import { injectPartial, globPartial, basePartial, assertType } from '@serwist/build/schema';
|
|
3
3
|
import z from 'zod';
|
|
4
4
|
|
|
5
|
-
const DEFAULT_GLOB_PATTERNS = [
|
|
6
|
-
".next/static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}",
|
|
7
|
-
"public/**/*"
|
|
8
|
-
];
|
|
9
5
|
const SUPPORTED_ESBUILD_OPTIONS = [
|
|
10
6
|
"sourcemap",
|
|
11
7
|
"legalComments",
|
|
@@ -64,9 +60,18 @@ const SUPPORTED_ESBUILD_OPTIONS = [
|
|
|
64
60
|
"plugins"
|
|
65
61
|
];
|
|
66
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
|
+
|
|
67
68
|
const turboPartial = z.strictObject({
|
|
68
69
|
cwd: z.string().prefault(process.cwd()),
|
|
69
|
-
|
|
70
|
+
nextConfig: z.strictObject({
|
|
71
|
+
assetPrefix: z.string().optional(),
|
|
72
|
+
basePath: z.string().prefault("/"),
|
|
73
|
+
distDir: z.string().prefault(".next")
|
|
74
|
+
}),
|
|
70
75
|
esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({})
|
|
71
76
|
});
|
|
72
77
|
const injectManifestOptions = z.strictObject({
|
|
@@ -74,15 +79,24 @@ const injectManifestOptions = z.strictObject({
|
|
|
74
79
|
...globPartial.shape,
|
|
75
80
|
...injectPartial.shape,
|
|
76
81
|
...turboPartial.shape,
|
|
77
|
-
globPatterns: z.array(z.string()).
|
|
82
|
+
globPatterns: z.array(z.string()).optional(),
|
|
78
83
|
globDirectory: z.string().optional()
|
|
79
84
|
}).omit({
|
|
80
85
|
disablePrecacheManifest: true
|
|
81
86
|
}).transform((input)=>{
|
|
87
|
+
let distDir = input.nextConfig.distDir;
|
|
88
|
+
if (distDir[0] === "/") distDir = distDir.slice(1);
|
|
89
|
+
if (distDir[distDir.length - 1] !== "/") distDir += "/";
|
|
82
90
|
return {
|
|
83
91
|
...input,
|
|
84
92
|
swSrc: path.isAbsolute(input.swSrc) ? input.swSrc : path.join(input.cwd, input.swSrc),
|
|
85
|
-
|
|
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
|
+
}
|
|
86
100
|
};
|
|
87
101
|
});
|
|
88
102
|
assertType();
|
|
@@ -1 +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,
|
|
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"}
|
package/dist/index.worker.js
CHANGED
|
@@ -170,15 +170,13 @@ const defaultCache = process.env.NODE_ENV !== "production" ? [
|
|
|
170
170
|
})
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
|
-
matcher:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return false;
|
|
181
|
-
},
|
|
173
|
+
matcher: /\/api\/auth\/.*/,
|
|
174
|
+
handler: new NetworkOnly({
|
|
175
|
+
networkTimeoutSeconds: 10
|
|
176
|
+
})
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
matcher: ({ sameOrigin, url: { pathname } })=>sameOrigin && pathname.startsWith("/api/"),
|
|
182
180
|
method: "GET",
|
|
183
181
|
handler: new NetworkFirst({
|
|
184
182
|
cacheName: "apis",
|
|
@@ -252,6 +250,11 @@ const defaultCache = process.env.NODE_ENV !== "production" ? [
|
|
|
252
250
|
],
|
|
253
251
|
networkTimeoutSeconds: 10
|
|
254
252
|
})
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
matcher: /.*/i,
|
|
256
|
+
method: "GET",
|
|
257
|
+
handler: new NetworkOnly()
|
|
255
258
|
}
|
|
256
259
|
];
|
|
257
260
|
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_GLOB_PATTERNS: string[];
|
|
2
1
|
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"];
|
|
3
2
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,ovBA0Dc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,aAGnD,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,8 +2,31 @@ import type { BasePartial, BaseResolved, GlobPartial, GlobResolved, InjectPartia
|
|
|
2
2
|
import type { Prettify, Require } from "@serwist/utils";
|
|
3
3
|
import type { BuildOptions } from "esbuild-wasm";
|
|
4
4
|
import type { SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
5
|
+
import type { NextConfig as CompleteNextConfig } from "next";
|
|
5
6
|
export type EsbuildSupportedOptions = (typeof SUPPORTED_ESBUILD_OPTIONS)[number];
|
|
6
7
|
export type EsbuildOptions = Pick<BuildOptions, EsbuildSupportedOptions>;
|
|
8
|
+
export interface NextConfig extends Pick<CompleteNextConfig, "basePath" | "distDir"> {
|
|
9
|
+
/**
|
|
10
|
+
* The Next.js `assetPrefix` config option.
|
|
11
|
+
*
|
|
12
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix
|
|
13
|
+
*/
|
|
14
|
+
assetPrefix?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The Next.js `basePath` config option.
|
|
17
|
+
*
|
|
18
|
+
* @default "/"
|
|
19
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
|
|
20
|
+
*/
|
|
21
|
+
basePath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The Next.js `distDir` config option.
|
|
24
|
+
*
|
|
25
|
+
* @default ".next"
|
|
26
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/distDir
|
|
27
|
+
*/
|
|
28
|
+
distDir?: string;
|
|
29
|
+
}
|
|
7
30
|
export interface TurboPartial {
|
|
8
31
|
/**
|
|
9
32
|
* The path to your working directory.
|
|
@@ -12,13 +35,23 @@ export interface TurboPartial {
|
|
|
12
35
|
*/
|
|
13
36
|
cwd?: string;
|
|
14
37
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
38
|
+
* A copy of your Next.js configuration. You must check
|
|
39
|
+
* if any option you've configured is needed by Serwist
|
|
40
|
+
* to ensure expected behavior.
|
|
41
|
+
*
|
|
42
|
+
* The following options are currently needed: `assetPrefix`,
|
|
43
|
+
* `basePath`, `distDir`.
|
|
44
|
+
*/
|
|
45
|
+
nextConfig: Prettify<NextConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Options to configure the esbuild instance used to bundle
|
|
48
|
+
* the service worker.
|
|
17
49
|
*/
|
|
18
|
-
basePath: string;
|
|
19
50
|
esbuildOptions?: EsbuildOptions;
|
|
20
51
|
}
|
|
21
|
-
export
|
|
52
|
+
export interface TurboResolved extends Require<TurboPartial, "cwd" | "esbuildOptions"> {
|
|
53
|
+
nextConfig: Require<NextConfig, "basePath" | "distDir">;
|
|
54
|
+
}
|
|
22
55
|
export type InjectManifestOptions = Prettify<Omit<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial, "disablePrecacheManifest">>;
|
|
23
|
-
export type InjectManifestOptionsComplete = Prettify<Omit<BaseResolved & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved, "disablePrecacheManifest">>;
|
|
56
|
+
export type InjectManifestOptionsComplete = Prettify<Omit<Require<BaseResolved, "dontCacheBustURLsMatching"> & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved, "disablePrecacheManifest">>;
|
|
24
57
|
//# 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;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;
|
|
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;AACpE,OAAO,KAAK,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAE7D,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,UAAW,SAAQ,IAAI,CAAC,kBAAkB,EAAE,UAAU,GAAG,SAAS,CAAC;IAClF;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,YAAY,EAAE,KAAK,GAAG,gBAAgB,CAAC;IACpF,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC;CACzD;AAED,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,CACF,OAAO,CAAC,YAAY,EAAE,2BAA2B,CAAC,GAAG,YAAY,GAAG,cAAc,GAAG,6BAA6B,GAAG,aAAa,EAClI,yBAAyB,CAC1B,CACF,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.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "A module that integrates Serwist into your Next.js / Turbopack application.",
|
|
@@ -63,30 +63,31 @@
|
|
|
63
63
|
"./package.json": "./package.json"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@swc/core": "1.
|
|
67
|
-
"esbuild-wasm": "0.25.8",
|
|
66
|
+
"@swc/core": "1.13.5",
|
|
68
67
|
"kolorist": "1.8.0",
|
|
69
|
-
"zod": "4.
|
|
70
|
-
"@serwist/build": "10.0.0-preview.
|
|
71
|
-
"@serwist/window": "10.0.0-preview.
|
|
72
|
-
"serwist": "10.0.0-preview.
|
|
68
|
+
"zod": "4.1.5",
|
|
69
|
+
"@serwist/build": "10.0.0-preview.14",
|
|
70
|
+
"@serwist/window": "10.0.0-preview.14",
|
|
71
|
+
"serwist": "10.0.0-preview.14"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
|
-
"@types/node": "24.0
|
|
76
|
-
"@types/react": "19.1.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"react
|
|
80
|
-
"
|
|
74
|
+
"@types/node": "24.3.0",
|
|
75
|
+
"@types/react": "19.1.12",
|
|
76
|
+
"esbuild-wasm": "0.25.9",
|
|
77
|
+
"next": "15.5.2",
|
|
78
|
+
"react": "19.1.1",
|
|
79
|
+
"react-dom": "19.1.1",
|
|
80
|
+
"rollup": "4.49.0",
|
|
81
81
|
"type-fest": "4.41.0",
|
|
82
|
-
"typescript": "5.
|
|
83
|
-
"@serwist/configs": "10.0.0-preview.
|
|
84
|
-
"@serwist/utils": "10.0.0-preview.
|
|
82
|
+
"typescript": "5.9.2",
|
|
83
|
+
"@serwist/configs": "10.0.0-preview.14",
|
|
84
|
+
"@serwist/utils": "10.0.0-preview.14"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"next": ">=14.0.0",
|
|
88
88
|
"react": ">=18.0.0",
|
|
89
|
-
"typescript": ">=5.0.0"
|
|
89
|
+
"typescript": ">=5.0.0",
|
|
90
|
+
"esbuild-wasm": "^0.25.0"
|
|
90
91
|
},
|
|
91
92
|
"peerDependenciesMeta": {
|
|
92
93
|
"typescript": {
|
package/src/index.schema.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { assertType, type Equals, basePartial, globPartial, injectPartial } from "@serwist/build/schema";
|
|
3
3
|
import z from "zod";
|
|
4
|
-
import {
|
|
4
|
+
import { SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
5
|
+
import { generateGlobPatterns } from "./lib/utils.js";
|
|
5
6
|
import type { InjectManifestOptions, InjectManifestOptionsComplete, TurboPartial, TurboResolved } from "./types.js";
|
|
6
7
|
|
|
7
8
|
export const turboPartial = z.strictObject({
|
|
8
9
|
cwd: z.string().prefault(process.cwd()),
|
|
9
|
-
|
|
10
|
+
nextConfig: z.strictObject({
|
|
11
|
+
assetPrefix: z.string().optional(),
|
|
12
|
+
basePath: z.string().prefault("/"),
|
|
13
|
+
distDir: z.string().prefault(".next"),
|
|
14
|
+
}),
|
|
10
15
|
esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({}),
|
|
11
16
|
});
|
|
12
17
|
|
|
@@ -16,15 +21,24 @@ export const injectManifestOptions = z
|
|
|
16
21
|
...globPartial.shape,
|
|
17
22
|
...injectPartial.shape,
|
|
18
23
|
...turboPartial.shape,
|
|
19
|
-
globPatterns: z.array(z.string()).
|
|
24
|
+
globPatterns: z.array(z.string()).optional(),
|
|
20
25
|
globDirectory: z.string().optional(),
|
|
21
26
|
})
|
|
22
27
|
.omit({ disablePrecacheManifest: true })
|
|
23
28
|
.transform((input) => {
|
|
29
|
+
let distDir = input.nextConfig.distDir;
|
|
30
|
+
if (distDir[0] === "/") distDir = distDir.slice(1);
|
|
31
|
+
if (distDir[distDir.length - 1] !== "/") distDir += "/";
|
|
24
32
|
return {
|
|
25
33
|
...input,
|
|
26
34
|
swSrc: path.isAbsolute(input.swSrc) ? input.swSrc : path.join(input.cwd, input.swSrc),
|
|
35
|
+
globPatterns: input.globPatterns ?? generateGlobPatterns(distDir),
|
|
27
36
|
globDirectory: input.globDirectory ?? input.cwd,
|
|
37
|
+
dontCacheBustURLsMatching: input.dontCacheBustURLsMatching ?? new RegExp(`^${distDir}static/`),
|
|
38
|
+
nextConfig: {
|
|
39
|
+
...input.nextConfig,
|
|
40
|
+
distDir,
|
|
41
|
+
},
|
|
28
42
|
};
|
|
29
43
|
});
|
|
30
44
|
|
package/src/index.ts
CHANGED
|
@@ -73,10 +73,14 @@ export const createSerwistRoute = (options: InjectManifestOptions) => {
|
|
|
73
73
|
...(config.manifestTransforms ?? []),
|
|
74
74
|
(manifestEntries) => {
|
|
75
75
|
const manifest = manifestEntries.map((m) => {
|
|
76
|
-
// Replace all references to
|
|
77
|
-
if (m.url.startsWith(
|
|
76
|
+
// Replace all references to "$(distDir)" with "$(assetPrefix)/_next/".
|
|
77
|
+
if (m.url.startsWith(config.nextConfig.distDir)) {
|
|
78
|
+
m.url = `${config.nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(config.nextConfig.distDir.length)}`;
|
|
79
|
+
}
|
|
78
80
|
// Replace all references to public/ with "$(basePath)/".
|
|
79
|
-
if (m.url.startsWith("public/"))
|
|
81
|
+
if (m.url.startsWith("public/")) {
|
|
82
|
+
m.url = path.posix.join(config.nextConfig.basePath, m.url.slice(7));
|
|
83
|
+
}
|
|
80
84
|
return m;
|
|
81
85
|
});
|
|
82
86
|
return { manifest, warnings: [] };
|
|
@@ -92,7 +96,7 @@ export const createSerwistRoute = (options: InjectManifestOptions) => {
|
|
|
92
96
|
const config = await validation;
|
|
93
97
|
const { count, size, manifestEntries, warnings } = await getFileManifestEntries(config);
|
|
94
98
|
// See https://github.com/GoogleChrome/workbox/issues/2230
|
|
95
|
-
const injectionPoint = config.injectionPoint
|
|
99
|
+
const injectionPoint = config.injectionPoint || "";
|
|
96
100
|
const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries, null, 2);
|
|
97
101
|
logSerwistResult(filePath, { count, size, warnings });
|
|
98
102
|
const result = await (await esbuild).build({
|
package/src/index.worker.ts
CHANGED
|
@@ -181,24 +181,15 @@ export const defaultCache: RuntimeCaching[] =
|
|
|
181
181
|
}),
|
|
182
182
|
},
|
|
183
183
|
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (pathname.startsWith("/api/")) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return false;
|
|
201
|
-
},
|
|
184
|
+
// Exclude /api/auth/* to fix auth callback
|
|
185
|
+
// https://github.com/serwist/serwist/discussions/28
|
|
186
|
+
matcher: /\/api\/auth\/.*/,
|
|
187
|
+
handler: new NetworkOnly({
|
|
188
|
+
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith("/api/"),
|
|
202
193
|
method: "GET",
|
|
203
194
|
handler: new NetworkFirst({
|
|
204
195
|
cacheName: "apis",
|
|
@@ -275,4 +266,9 @@ export const defaultCache: RuntimeCaching[] =
|
|
|
275
266
|
networkTimeoutSeconds: 10,
|
|
276
267
|
}),
|
|
277
268
|
},
|
|
269
|
+
{
|
|
270
|
+
matcher: /.*/i,
|
|
271
|
+
method: "GET",
|
|
272
|
+
handler: new NetworkOnly(),
|
|
273
|
+
},
|
|
278
274
|
];
|
package/src/lib/constants.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { BuildOptions } from "esbuild-wasm";
|
|
2
2
|
|
|
3
|
-
export const DEFAULT_GLOB_PATTERNS = [
|
|
4
|
-
".next/static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}",
|
|
5
|
-
"public/**/*",
|
|
6
|
-
];
|
|
7
|
-
|
|
8
3
|
export const SUPPORTED_ESBUILD_OPTIONS = [
|
|
9
4
|
// CommonOptions
|
|
10
5
|
"sourcemap",
|
package/src/lib/utils.ts
ADDED
package/src/types.ts
CHANGED
|
@@ -11,11 +11,35 @@ import type {
|
|
|
11
11
|
import type { Prettify, Require } from "@serwist/utils";
|
|
12
12
|
import type { BuildOptions } from "esbuild-wasm";
|
|
13
13
|
import type { SUPPORTED_ESBUILD_OPTIONS } from "./lib/constants.js";
|
|
14
|
+
import type { NextConfig as CompleteNextConfig } from "next";
|
|
14
15
|
|
|
15
16
|
export type EsbuildSupportedOptions = (typeof SUPPORTED_ESBUILD_OPTIONS)[number];
|
|
16
17
|
|
|
17
18
|
export type EsbuildOptions = Pick<BuildOptions, EsbuildSupportedOptions>;
|
|
18
19
|
|
|
20
|
+
export interface NextConfig extends Pick<CompleteNextConfig, "basePath" | "distDir"> {
|
|
21
|
+
/**
|
|
22
|
+
* The Next.js `assetPrefix` config option.
|
|
23
|
+
*
|
|
24
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix
|
|
25
|
+
*/
|
|
26
|
+
assetPrefix?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The Next.js `basePath` config option.
|
|
29
|
+
*
|
|
30
|
+
* @default "/"
|
|
31
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath
|
|
32
|
+
*/
|
|
33
|
+
basePath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The Next.js `distDir` config option.
|
|
36
|
+
*
|
|
37
|
+
* @default ".next"
|
|
38
|
+
* @see https://nextjs.org/docs/app/api-reference/config/next-config-js/distDir
|
|
39
|
+
*/
|
|
40
|
+
distDir?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
19
43
|
export interface TurboPartial {
|
|
20
44
|
/**
|
|
21
45
|
* The path to your working directory.
|
|
@@ -24,19 +48,32 @@ export interface TurboPartial {
|
|
|
24
48
|
*/
|
|
25
49
|
cwd?: string;
|
|
26
50
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
51
|
+
* A copy of your Next.js configuration. You must check
|
|
52
|
+
* if any option you've configured is needed by Serwist
|
|
53
|
+
* to ensure expected behavior.
|
|
54
|
+
*
|
|
55
|
+
* The following options are currently needed: `assetPrefix`,
|
|
56
|
+
* `basePath`, `distDir`.
|
|
57
|
+
*/
|
|
58
|
+
nextConfig: Prettify<NextConfig>;
|
|
59
|
+
/**
|
|
60
|
+
* Options to configure the esbuild instance used to bundle
|
|
61
|
+
* the service worker.
|
|
29
62
|
*/
|
|
30
|
-
basePath: string;
|
|
31
63
|
esbuildOptions?: EsbuildOptions;
|
|
32
64
|
}
|
|
33
65
|
|
|
34
|
-
export
|
|
66
|
+
export interface TurboResolved extends Require<TurboPartial, "cwd" | "esbuildOptions"> {
|
|
67
|
+
nextConfig: Require<NextConfig, "basePath" | "distDir">;
|
|
68
|
+
}
|
|
35
69
|
|
|
36
70
|
export type InjectManifestOptions = Prettify<
|
|
37
71
|
Omit<BasePartial & GlobPartial & InjectPartial & OptionalGlobDirectoryPartial & TurboPartial, "disablePrecacheManifest">
|
|
38
72
|
>;
|
|
39
73
|
|
|
40
74
|
export type InjectManifestOptionsComplete = Prettify<
|
|
41
|
-
Omit<
|
|
75
|
+
Omit<
|
|
76
|
+
Require<BaseResolved, "dontCacheBustURLsMatching"> & GlobResolved & InjectResolved & RequiredGlobDirectoryResolved & TurboResolved,
|
|
77
|
+
"disablePrecacheManifest"
|
|
78
|
+
>
|
|
42
79
|
>;
|