@serwist/next 9.4.4 → 9.5.1

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.
@@ -21,4 +21,4 @@ const injectManifestOptions = z.strictObject({
21
21
  disablePrecacheManifest: true
22
22
  });
23
23
 
24
- export { injectManifestOptions as a, injectPartial as i };
24
+ export { injectPartial as a, injectManifestOptions as i };
@@ -3,14 +3,34 @@ import type { NextConfigComplete } from "next/dist/server/config-shared.js";
3
3
  import type { SerwistOptions } from "./lib/config/types.js";
4
4
  import { generateGlobPatterns } from "./lib/config/utils.js";
5
5
  /**
6
- * Integrates Serwist into your Next.js app.
7
- * @param options
8
- * @returns
6
+ * Additional build context.
9
7
  */
10
- export declare const serwist: {
11
- (options: SerwistOptions, nextConfig?: NextConfigComplete): Promise<BuildOptions>;
12
- withNextConfig(optionsFunction: (nextConfig: NextConfigComplete) => Promise<SerwistOptions> | SerwistOptions): Promise<BuildOptions>;
13
- };
8
+ export interface SerwistContext {
9
+ /**
10
+ * The current working directory.
11
+ */
12
+ cwd?: string;
13
+ /**
14
+ * Whether Serwist is in development mode. This option determines how Next.js configuration
15
+ * is resolved. Note that it doesn't change how the service worker is built.
16
+ */
17
+ isDev?: boolean;
18
+ }
19
+ export interface Serwist {
20
+ /**
21
+ * Integrates Serwist into your Next.js app.
22
+ * @param options
23
+ * @returns
24
+ */
25
+ (options: SerwistOptions, nextConfig?: NextConfigComplete, context?: SerwistContext): Promise<BuildOptions>;
26
+ /**
27
+ * Integrates Serwist into your Next.js app. Allows reading fully resolved Next.js configuration.
28
+ * @param optionsFunction
29
+ * @returns
30
+ */
31
+ withNextConfig: (optionsFunction: (nextConfig: NextConfigComplete) => Promise<SerwistOptions> | SerwistOptions, context?: SerwistContext) => Promise<BuildOptions>;
32
+ }
33
+ export declare const serwist: Serwist;
14
34
  export { generateGlobPatterns };
15
35
  export type { SerwistOptions };
16
36
  //# sourceMappingURL=index.config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.config.d.ts","sourceRoot":"","sources":["../src/index.config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAoC,MAAM,uBAAuB,CAAC;AAE/F;;;;GAIG;AACH,eAAO,MAAM,OAAO;cAAmB,cAAc,eAAe,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;oCAsF3F,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,GAC5F,OAAO,CAAC,YAAY,CAAC;CATvB,CAAC;AAgBF,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,YAAY,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"index.config.d.ts","sourceRoot":"","sources":["../src/index.config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAoC,MAAM,uBAAuB,CAAC;AAK/F;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,CAAC,OAAO,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5G;;;;OAIG;IACH,cAAc,EAAE,CACd,eAAe,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,EAC7F,OAAO,CAAC,EAAE,cAAc,KACrB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,OAAO,EAAE,OA6ErB,CAAC;AAOF,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -84,9 +84,9 @@ const loadBrowserslist = (cwd)=>{
84
84
  }, []).map((split)=>split.join(""));
85
85
  };
86
86
 
87
- const serwist = async (options, nextConfig)=>{
88
- const cwd = process.cwd();
89
- const isDev = process.env.NODE_ENV === "development";
87
+ const _cwd = process.cwd();
88
+ const _isDev = process.env.NODE_ENV === "development";
89
+ const serwist = async (options, nextConfig, { cwd = _cwd, isDev = _isDev } = {})=>{
90
90
  if (!nextConfig) nextConfig = await loadNextConfig(cwd, isDev);
91
91
  const basePath = nextConfig.basePath || "/";
92
92
  let distDir = nextConfig.distDir;
@@ -117,6 +117,7 @@ const serwist = async (options, nextConfig)=>{
117
117
  ],
118
118
  globIgnores: [
119
119
  `${distAppDir}**/_not-found.html`,
120
+ `${distAppDir}_global-error*`,
120
121
  `${distPagesDir}404.html`,
121
122
  `${distPagesDir}500.html`,
122
123
  ...cliOptions.globIgnores ?? [],
@@ -171,11 +172,12 @@ const serwist = async (options, nextConfig)=>{
171
172
  }
172
173
  };
173
174
  };
174
- serwist.withNextConfig = async (optionsFunction)=>{
175
- const cwd = process.cwd();
176
- const isDev = process.env.NODE_ENV === "development";
175
+ serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {})=>{
177
176
  const nextConfig = await loadNextConfig(cwd, isDev);
178
- return serwist(await optionsFunction(nextConfig), nextConfig);
177
+ return serwist(await optionsFunction(nextConfig), nextConfig, {
178
+ cwd,
179
+ isDev
180
+ });
179
181
  };
180
182
 
181
183
  export { generateGlobPatterns, serwist };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { green, bold, white, yellow, red } from 'kolorist';
10
10
  import semver from 'semver';
11
11
  import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
12
12
  import { z } from 'zod';
13
- import { a as injectManifestOptions } from './chunks/schema.js';
13
+ import { i as injectManifestOptions } from './chunks/schema.js';
14
14
  import '@serwist/webpack-plugin/schema';
15
15
 
16
16
  const findFirstTruthy = (arr, fn)=>{
@@ -1,4 +1,4 @@
1
- export { a as injectManifestOptions, i as injectPartial } from './chunks/schema.js';
1
+ export { i as injectManifestOptions, a as injectPartial } from './chunks/schema.js';
2
2
  import '@serwist/build/schema';
3
3
  import '@serwist/webpack-plugin/schema';
4
4
  import 'zod';
@@ -41,7 +41,7 @@ export declare const injectManifestOptions: z.ZodObject<{
41
41
  url: z.ZodString;
42
42
  }, z.core.$strip>>;
43
43
  warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
44
- }, z.core.$strict>>>, z.ZodTransform<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
44
+ }, z.core.$strict>>>, z.ZodTransform<z.core.$InferOuterFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
45
45
  size: z.ZodNumber;
46
46
  integrity: z.ZodOptional<z.ZodString>;
47
47
  revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "9.4.4",
3
+ "version": "9.5.1",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -80,32 +80,32 @@
80
80
  "glob": "10.5.0",
81
81
  "kolorist": "1.8.0",
82
82
  "semver": "7.7.3",
83
- "zod": "4.2.1",
84
- "@serwist/build": "9.4.4",
85
- "@serwist/utils": "9.4.4",
86
- "@serwist/webpack-plugin": "9.4.4",
87
- "@serwist/window": "9.4.4",
88
- "serwist": "9.4.4"
83
+ "zod": "4.3.6",
84
+ "@serwist/build": "9.5.1",
85
+ "@serwist/utils": "9.5.1",
86
+ "@serwist/webpack-plugin": "9.5.1",
87
+ "@serwist/window": "9.5.1",
88
+ "serwist": "9.5.1"
89
89
  },
90
90
  "devDependencies": {
91
- "@types/node": "25.0.3",
92
- "@types/react": "19.2.7",
91
+ "@types/node": "25.1.0",
92
+ "@types/react": "19.2.10",
93
93
  "@types/semver": "7.7.1",
94
- "next": "16.1.0",
95
- "react": "19.2.3",
96
- "react-dom": "19.2.3",
97
- "rollup": "4.54.0",
98
- "type-fest": "5.3.1",
94
+ "next": "16.1.6",
95
+ "react": "19.2.4",
96
+ "react-dom": "19.2.4",
97
+ "rollup": "4.57.0",
98
+ "type-fest": "5.4.2",
99
99
  "typescript": "5.9.3",
100
100
  "webpack": "5.104.1",
101
- "@serwist/configs": "9.4.4",
102
- "@serwist/cli": "9.4.4"
101
+ "@serwist/cli": "9.5.1",
102
+ "@serwist/configs": "9.5.1"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "next": ">=14.0.0",
106
106
  "react": ">=18.0.0",
107
107
  "typescript": ">=5.0.0",
108
- "@serwist/cli": "^9.4.4"
108
+ "@serwist/cli": "^9.5.1"
109
109
  },
110
110
  "peerDependenciesMeta": {
111
111
  "@serwist/cli": {
@@ -6,14 +6,43 @@ import type { NextConfigComplete } from "next/dist/server/config-shared.js";
6
6
  import type { SerwistOptions } from "./lib/config/types.js";
7
7
  import { generateGlobPatterns, loadBrowserslist, loadNextConfig } from "./lib/config/utils.js";
8
8
 
9
+ const _cwd = process.cwd();
10
+ const _isDev = process.env.NODE_ENV === "development";
11
+
9
12
  /**
10
- * Integrates Serwist into your Next.js app.
11
- * @param options
12
- * @returns
13
+ * Additional build context.
13
14
  */
14
- export const serwist = async (options: SerwistOptions, nextConfig?: NextConfigComplete): Promise<BuildOptions> => {
15
- const cwd = process.cwd();
16
- const isDev = process.env.NODE_ENV === "development";
15
+ export interface SerwistContext {
16
+ /**
17
+ * The current working directory.
18
+ */
19
+ cwd?: string;
20
+ /**
21
+ * Whether Serwist is in development mode. This option determines how Next.js configuration
22
+ * is resolved. Note that it doesn't change how the service worker is built.
23
+ */
24
+ isDev?: boolean;
25
+ }
26
+
27
+ export interface Serwist {
28
+ /**
29
+ * Integrates Serwist into your Next.js app.
30
+ * @param options
31
+ * @returns
32
+ */
33
+ (options: SerwistOptions, nextConfig?: NextConfigComplete, context?: SerwistContext): Promise<BuildOptions>;
34
+ /**
35
+ * Integrates Serwist into your Next.js app. Allows reading fully resolved Next.js configuration.
36
+ * @param optionsFunction
37
+ * @returns
38
+ */
39
+ withNextConfig: (
40
+ optionsFunction: (nextConfig: NextConfigComplete) => Promise<SerwistOptions> | SerwistOptions,
41
+ context?: SerwistContext,
42
+ ) => Promise<BuildOptions>;
43
+ }
44
+
45
+ export const serwist: Serwist = async (options, nextConfig, { cwd = _cwd, isDev = _isDev } = {}) => {
17
46
  if (!nextConfig) nextConfig = await loadNextConfig(cwd, isDev);
18
47
  const basePath = nextConfig.basePath || "/";
19
48
  let distDir = nextConfig.distDir;
@@ -37,6 +66,7 @@ export const serwist = async (options: SerwistOptions, nextConfig?: NextConfigCo
37
66
  ],
38
67
  globIgnores: [
39
68
  `${distAppDir}**/_not-found.html`,
69
+ `${distAppDir}_global-error*`,
40
70
  `${distPagesDir}404.html`,
41
71
  `${distPagesDir}500.html`,
42
72
  ...(cliOptions.globIgnores ?? []),
@@ -91,18 +121,9 @@ export const serwist = async (options: SerwistOptions, nextConfig?: NextConfigCo
91
121
  };
92
122
  };
93
123
 
94
- /**
95
- * Integrates Serwist into your Next.js app. Allows reading complete Next.js configuration.
96
- * @param optionsFunction
97
- * @returns
98
- */
99
- serwist.withNextConfig = async (
100
- optionsFunction: (nextConfig: NextConfigComplete) => Promise<SerwistOptions> | SerwistOptions,
101
- ): Promise<BuildOptions> => {
102
- const cwd = process.cwd();
103
- const isDev = process.env.NODE_ENV === "development";
124
+ serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {}) => {
104
125
  const nextConfig = await loadNextConfig(cwd, isDev);
105
- return serwist(await optionsFunction(nextConfig), nextConfig);
126
+ return serwist(await optionsFunction(nextConfig), nextConfig, { cwd, isDev });
106
127
  };
107
128
 
108
129
  export { generateGlobPatterns };