@serwist/next 9.4.3 → 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.
- package/dist/index.config.d.ts +30 -1
- package/dist/index.config.d.ts.map +1 -1
- package/dist/index.config.js +24 -14
- package/dist/lib/config/utils.d.ts +1 -0
- package/dist/lib/config/utils.d.ts.map +1 -1
- package/dist/lib/schema.d.ts +1 -1
- package/package.json +12 -12
- package/src/index.config.ts +47 -13
- package/src/lib/config/utils.ts +10 -1
package/dist/index.config.d.ts
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
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
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Additional build context.
|
|
7
|
+
*/
|
|
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;
|
|
5
34
|
export { generateGlobPatterns };
|
|
6
35
|
export type { SerwistOptions };
|
|
7
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;
|
|
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,OA4ErB,CAAC;AAOF,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/index.config.js
CHANGED
|
@@ -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 {
|
|
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
|
|
80
|
-
const
|
|
81
|
-
const serwist = async (options)=>{
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const config = await loadNextConfig.default(nextPhase, cwd, {
|
|
86
|
-
silent: false
|
|
87
|
-
});
|
|
88
|
-
const basePath = config.basePath || "/";
|
|
89
|
-
let distDir = config.distDir;
|
|
87
|
+
const _cwd = process.cwd();
|
|
88
|
+
const _isDev = process.env.NODE_ENV === "development";
|
|
89
|
+
const serwist = async (options, nextConfig, { cwd = _cwd, isDev = _isDev } = {})=>{
|
|
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 = `${
|
|
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,12 @@ const serwist = async (options)=>{
|
|
|
168
171
|
}
|
|
169
172
|
};
|
|
170
173
|
};
|
|
174
|
+
serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {})=>{
|
|
175
|
+
const nextConfig = await loadNextConfig(cwd, isDev);
|
|
176
|
+
return serwist(await optionsFunction(nextConfig), nextConfig, {
|
|
177
|
+
cwd,
|
|
178
|
+
isDev
|
|
179
|
+
});
|
|
180
|
+
};
|
|
171
181
|
|
|
172
182
|
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":"
|
|
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/dist/lib/schema.d.ts
CHANGED
|
@@ -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.$
|
|
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.
|
|
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.
|
|
84
|
-
"@serwist/build": "9.
|
|
85
|
-
"@serwist/utils": "9.
|
|
86
|
-
"@serwist/webpack-plugin": "9.
|
|
87
|
-
"@serwist/window": "9.
|
|
88
|
-
"serwist": "9.
|
|
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.
|
|
94
|
+
"next": "16.1.1",
|
|
95
95
|
"react": "19.2.3",
|
|
96
96
|
"react-dom": "19.2.3",
|
|
97
|
-
"rollup": "4.
|
|
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/cli": "9.
|
|
102
|
-
"@serwist/configs": "9.
|
|
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.
|
|
108
|
+
"@serwist/cli": "^9.5.0"
|
|
109
109
|
},
|
|
110
110
|
"peerDependenciesMeta": {
|
|
111
111
|
"@serwist/cli": {
|
package/src/index.config.ts
CHANGED
|
@@ -2,21 +2,50 @@ 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 {
|
|
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
|
-
|
|
9
|
+
const _cwd = process.cwd();
|
|
10
|
+
const _isDev = process.env.NODE_ENV === "development";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Additional build context.
|
|
14
|
+
*/
|
|
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 } = {}) => {
|
|
46
|
+
if (!nextConfig) nextConfig = await loadNextConfig(cwd, isDev);
|
|
47
|
+
const basePath = nextConfig.basePath || "/";
|
|
48
|
+
let distDir = nextConfig.distDir;
|
|
20
49
|
if (distDir[0] === "/") distDir = distDir.slice(1);
|
|
21
50
|
if (distDir[distDir.length - 1] !== "/") distDir += "/";
|
|
22
51
|
const distServerDir = `${distDir}server/`;
|
|
@@ -73,7 +102,7 @@ export const serwist = async (options: SerwistOptions): Promise<BuildOptions> =>
|
|
|
73
102
|
}
|
|
74
103
|
// Replace all references to "$(distDir)" with "$(assetPrefix)/_next/".
|
|
75
104
|
if (m.url.startsWith(distDir)) {
|
|
76
|
-
m.url = `${
|
|
105
|
+
m.url = `${nextConfig.assetPrefix ?? ""}/_next/${m.url.slice(distDir.length)}`;
|
|
77
106
|
}
|
|
78
107
|
// Replace all references to public/ with "$(basePath)/".
|
|
79
108
|
if (m.url.startsWith("public/")) {
|
|
@@ -91,6 +120,11 @@ export const serwist = async (options: SerwistOptions): Promise<BuildOptions> =>
|
|
|
91
120
|
};
|
|
92
121
|
};
|
|
93
122
|
|
|
123
|
+
serwist.withNextConfig = async (optionsFunction, { cwd = _cwd, isDev = _isDev } = {}) => {
|
|
124
|
+
const nextConfig = await loadNextConfig(cwd, isDev);
|
|
125
|
+
return serwist(await optionsFunction(nextConfig), nextConfig, { cwd, isDev });
|
|
126
|
+
};
|
|
127
|
+
|
|
94
128
|
export { generateGlobPatterns };
|
|
95
129
|
|
|
96
130
|
export type { SerwistOptions };
|
package/src/lib/config/utils.ts
CHANGED
|
@@ -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/**/*",
|