@serwist/next 9.4.4 → 9.5.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.
@@ -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,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AC,CAAC;CAC5B;AAED,eAAO,MAAM,OAAO,EAAE,OA4ErB,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;
@@ -171,11 +171,12 @@ const serwist = async (options, nextConfig)=>{
171
171
  }
172
172
  };
173
173
  };
174
- serwist.withNextConfig = async (optionsFunction)=>{
175
- const cwd = process.cwd();
176
- const isDev = process.env.NODE_ENV === "development";
174
+ serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {})=>{
177
175
  const nextConfig = await loadNextConfig(cwd, isDev);
178
- return serwist(await optionsFunction(nextConfig), nextConfig);
176
+ return serwist(await optionsFunction(nextConfig), nextConfig, {
177
+ cwd,
178
+ isDev
179
+ });
179
180
  };
180
181
 
181
182
  export { generateGlobPatterns, serwist };
@@ -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.0",
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.5",
84
+ "@serwist/build": "9.5.0",
85
+ "@serwist/utils": "9.5.0",
86
+ "@serwist/webpack-plugin": "9.5.0",
87
+ "@serwist/window": "9.5.0",
88
+ "serwist": "9.5.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@types/node": "25.0.3",
92
92
  "@types/react": "19.2.7",
93
93
  "@types/semver": "7.7.1",
94
- "next": "16.1.0",
94
+ "next": "16.1.1",
95
95
  "react": "19.2.3",
96
96
  "react-dom": "19.2.3",
97
- "rollup": "4.54.0",
97
+ "rollup": "4.55.1",
98
98
  "type-fest": "5.3.1",
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.0",
102
+ "@serwist/configs": "9.5.0"
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.0"
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;
@@ -91,18 +120,9 @@ export const serwist = async (options: SerwistOptions, nextConfig?: NextConfigCo
91
120
  };
92
121
  };
93
122
 
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";
123
+ serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {}) => {
104
124
  const nextConfig = await loadNextConfig(cwd, isDev);
105
- return serwist(await optionsFunction(nextConfig), nextConfig);
125
+ return serwist(await optionsFunction(nextConfig), nextConfig, { cwd, isDev });
106
126
  };
107
127
 
108
128
  export { generateGlobPatterns };