@serwist/next 9.4.2 → 9.4.4

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.
@@ -1,7 +1,16 @@
1
1
  import type { BuildOptions } from "@serwist/cli";
2
+ import type { NextConfigComplete } from "next/dist/server/config-shared.js";
2
3
  import type { SerwistOptions } from "./lib/config/types.js";
3
4
  import { generateGlobPatterns } from "./lib/config/utils.js";
4
- export declare const serwist: (options: SerwistOptions) => Promise<BuildOptions>;
5
+ /**
6
+ * Integrates Serwist into your Next.js app.
7
+ * @param options
8
+ * @returns
9
+ */
10
+ export declare const serwist: {
11
+ (options: SerwistOptions, nextConfig?: NextConfigComplete): Promise<BuildOptions>;
12
+ withNextConfig(optionsFunction: (nextConfig: NextConfigComplete) => Promise<SerwistOptions> | SerwistOptions): Promise<BuildOptions>;
13
+ };
5
14
  export { generateGlobPatterns };
6
15
  export type { SerwistOptions };
7
16
  //# 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;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAoB,MAAM,uBAAuB,CAAC;AAI/E,eAAO,MAAM,OAAO,GAAU,SAAS,cAAc,KAAG,OAAO,CAAC,YAAY,CAiF3E,CAAC;AAEF,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;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,9 +1,9 @@
1
- import { createRequire } from 'module';
2
1
  import fs from 'node:fs';
3
2
  import path from 'node:path';
4
3
  import { rebasePath } from '@serwist/build';
5
- import { MODERN_BROWSERSLIST_TARGET, PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from 'next/constants.js';
4
+ import { createRequire } from 'module';
6
5
  import browserslist from 'browserslist';
6
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD, MODERN_BROWSERSLIST_TARGET } from 'next/constants.js';
7
7
 
8
8
  const SUPPORTED_ESBUILD_TARGETS = [
9
9
  "chrome",
@@ -24,6 +24,14 @@ const UNSUPPORTED_BROWSERLIST_TARGETS = [
24
24
  "android 2"
25
25
  ];
26
26
 
27
+ const __require = createRequire(import.meta.url);
28
+ const nextConfig = __require("next/dist/server/config.js");
29
+ const loadNextConfig = (cwd, isDev)=>{
30
+ const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
31
+ return nextConfig.default(nextPhase, cwd, {
32
+ silent: false
33
+ });
34
+ };
27
35
  const generateGlobPatterns = (distDir)=>[
28
36
  `${distDir}static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}`,
29
37
  "public/**/*"
@@ -76,17 +84,12 @@ const loadBrowserslist = (cwd)=>{
76
84
  }, []).map((split)=>split.join(""));
77
85
  };
78
86
 
79
- const __require = createRequire(import.meta.url);
80
- const loadNextConfig = __require("next/dist/server/config.js");
81
- const serwist = async (options)=>{
87
+ const serwist = async (options, nextConfig)=>{
82
88
  const cwd = process.cwd();
83
89
  const isDev = process.env.NODE_ENV === "development";
84
- const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
85
- const config = await loadNextConfig.default(nextPhase, cwd, {
86
- silent: false
87
- });
88
- const basePath = config.basePath || "/";
89
- let distDir = config.distDir;
90
+ if (!nextConfig) nextConfig = await loadNextConfig(cwd, isDev);
91
+ const basePath = nextConfig.basePath || "/";
92
+ let distDir = nextConfig.distDir;
90
93
  if (distDir[0] === "/") distDir = distDir.slice(1);
91
94
  if (distDir[distDir.length - 1] !== "/") distDir += "/";
92
95
  const distServerDir = `${distDir}server/`;
@@ -149,7 +152,7 @@ const serwist = async (options)=>{
149
152
  m.url = path.posix.join(basePath, m.url);
150
153
  }
151
154
  if (m.url.startsWith(distDir)) {
152
- m.url = `${config.assetPrefix ?? ""}/_next/${m.url.slice(distDir.length)}`;
155
+ m.url = `${nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(distDir.length)}`;
153
156
  }
154
157
  if (m.url.startsWith("public/")) {
155
158
  m.url = path.posix.join(basePath, m.url.slice(7));
@@ -168,5 +171,11 @@ const serwist = async (options)=>{
168
171
  }
169
172
  };
170
173
  };
174
+ serwist.withNextConfig = async (optionsFunction)=>{
175
+ const cwd = process.cwd();
176
+ const isDev = process.env.NODE_ENV === "development";
177
+ const nextConfig = await loadNextConfig(cwd, isDev);
178
+ return serwist(await optionsFunction(nextConfig), nextConfig);
179
+ };
171
180
 
172
181
  export { generateGlobPatterns, serwist };
@@ -1,3 +1,4 @@
1
+ export declare const loadNextConfig: (cwd: string, isDev: boolean) => Promise<import("next/dist/server/config-shared.js").NextConfigComplete>;
1
2
  export declare const generateGlobPatterns: (distDir: string) => string[];
2
3
  /**
3
4
  * Loads and converts Browserslist into esbuild's `target` option.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/config/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,aAGnD,CAAC;AAmBF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,MAAM,EAqDpD,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/config/utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,OAAO,OAAO,4EAKzD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,aAGnD,CAAC;AAmBF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,MAAM,EAqDpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "9.4.2",
3
+ "version": "9.4.4",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -81,10 +81,11 @@
81
81
  "kolorist": "1.8.0",
82
82
  "semver": "7.7.3",
83
83
  "zod": "4.2.1",
84
- "@serwist/build": "9.4.2",
85
- "@serwist/webpack-plugin": "9.4.2",
86
- "@serwist/window": "9.4.2",
87
- "serwist": "9.4.2"
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"
88
89
  },
89
90
  "devDependencies": {
90
91
  "@types/node": "25.0.3",
@@ -97,15 +98,14 @@
97
98
  "type-fest": "5.3.1",
98
99
  "typescript": "5.9.3",
99
100
  "webpack": "5.104.1",
100
- "@serwist/cli": "9.4.2",
101
- "@serwist/configs": "9.4.2",
102
- "@serwist/utils": "9.4.2"
101
+ "@serwist/configs": "9.4.4",
102
+ "@serwist/cli": "9.4.4"
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.2"
108
+ "@serwist/cli": "^9.4.4"
109
109
  },
110
110
  "peerDependenciesMeta": {
111
111
  "@serwist/cli": {
@@ -2,21 +2,21 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { rebasePath } from "@serwist/build";
4
4
  import type { BuildOptions } from "@serwist/cli";
5
- import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "next/constants.js";
5
+ import type { NextConfigComplete } from "next/dist/server/config-shared.js";
6
6
  import type { SerwistOptions } from "./lib/config/types.js";
7
- import { generateGlobPatterns, loadBrowserslist } from "./lib/config/utils.js";
7
+ import { generateGlobPatterns, loadBrowserslist, loadNextConfig } from "./lib/config/utils.js";
8
8
 
9
- import loadNextConfig = require("next/dist/server/config.js");
10
-
11
- export const serwist = async (options: SerwistOptions): Promise<BuildOptions> => {
9
+ /**
10
+ * Integrates Serwist into your Next.js app.
11
+ * @param options
12
+ * @returns
13
+ */
14
+ export const serwist = async (options: SerwistOptions, nextConfig?: NextConfigComplete): Promise<BuildOptions> => {
12
15
  const cwd = process.cwd();
13
16
  const isDev = process.env.NODE_ENV === "development";
14
- const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
15
- const config = await loadNextConfig.default(nextPhase, cwd, {
16
- silent: false,
17
- });
18
- const basePath = config.basePath || "/";
19
- let distDir = config.distDir;
17
+ if (!nextConfig) nextConfig = await loadNextConfig(cwd, isDev);
18
+ const basePath = nextConfig.basePath || "/";
19
+ let distDir = nextConfig.distDir;
20
20
  if (distDir[0] === "/") distDir = distDir.slice(1);
21
21
  if (distDir[distDir.length - 1] !== "/") distDir += "/";
22
22
  const distServerDir = `${distDir}server/`;
@@ -73,7 +73,7 @@ export const serwist = async (options: SerwistOptions): Promise<BuildOptions> =>
73
73
  }
74
74
  // Replace all references to "$(distDir)" with "$(assetPrefix)/_next/".
75
75
  if (m.url.startsWith(distDir)) {
76
- m.url = `${config.assetPrefix ?? ""}/_next/${m.url.slice(distDir.length)}`;
76
+ m.url = `${nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(distDir.length)}`;
77
77
  }
78
78
  // Replace all references to public/ with "$(basePath)/".
79
79
  if (m.url.startsWith("public/")) {
@@ -91,6 +91,20 @@ export const serwist = async (options: SerwistOptions): Promise<BuildOptions> =>
91
91
  };
92
92
  };
93
93
 
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";
104
+ const nextConfig = await loadNextConfig(cwd, isDev);
105
+ return serwist(await optionsFunction(nextConfig), nextConfig);
106
+ };
107
+
94
108
  export { generateGlobPatterns };
95
109
 
96
110
  export type { SerwistOptions };
@@ -1,7 +1,16 @@
1
1
  import browserslist from "browserslist";
2
- import { MODERN_BROWSERSLIST_TARGET } from "next/constants.js";
2
+ import { MODERN_BROWSERSLIST_TARGET, PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "next/constants.js";
3
3
  import { SUPPORTED_ESBUILD_TARGETS, UNSUPPORTED_BROWSERLIST_TARGETS } from "./constants.js";
4
4
 
5
+ import nextConfig = require("next/dist/server/config.js");
6
+
7
+ export const loadNextConfig = (cwd: string, isDev: boolean) => {
8
+ const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
9
+ return nextConfig.default(nextPhase, cwd, {
10
+ silent: false,
11
+ });
12
+ };
13
+
5
14
  export const generateGlobPatterns = (distDir: string) => [
6
15
  `${distDir}static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}`,
7
16
  "public/**/*",