@serwist/turbopack 9.5.7 → 9.5.8
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/chunks/index.schema-RVDaKxz4.js +189 -0
- package/dist/chunks/index.schema-RVDaKxz4.js.map +1 -0
- package/dist/index.d.mts +96 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +166 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.react.d.mts +42 -0
- package/dist/index.react.d.mts.map +1 -0
- package/dist/index.react.mjs +73 -0
- package/dist/index.react.mjs.map +1 -0
- package/dist/index.schema.d.mts +311 -0
- package/dist/index.schema.d.mts.map +1 -0
- package/dist/index.schema.mjs +2 -0
- package/dist/index.worker.d.mts +18 -0
- package/dist/index.worker.d.mts.map +1 -0
- package/dist/index.worker.mjs +227 -0
- package/dist/index.worker.mjs.map +1 -0
- package/package.json +31 -32
- package/dist/chunks/index.schema.js +0 -185
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -190
- package/dist/index.react.d.ts +0 -25
- package/dist/index.react.d.ts.map +0 -1
- package/dist/index.react.js +0 -88
- package/dist/index.schema.d.ts +0 -301
- package/dist/index.schema.d.ts.map +0 -1
- package/dist/index.schema.js +0 -8
- package/dist/index.worker.d.ts +0 -14
- package/dist/index.worker.d.ts.map +0 -1
- package/dist/index.worker.js +0 -261
- package/dist/lib/constants.d.ts +0 -2
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -7
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/logger.d.ts +0 -8
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/utils.d.ts +0 -3
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/types.d.ts +0 -72
- package/dist/types.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/turbopack",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "A module that integrates Serwist into your Next.js / Turbopack application.",
|
|
@@ -31,64 +31,63 @@
|
|
|
31
31
|
"repository": "https://github.com/serwist/serwist",
|
|
32
32
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
33
33
|
"homepage": "https://serwist.pages.dev",
|
|
34
|
-
"main": "./dist/index.
|
|
35
|
-
"types": "./dist/index.d.
|
|
34
|
+
"main": "./dist/index.mjs",
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
36
36
|
"typesVersions": {
|
|
37
37
|
"*": {
|
|
38
38
|
"react": [
|
|
39
|
-
"./dist/index.react.d.
|
|
39
|
+
"./dist/index.react.d.mts"
|
|
40
40
|
],
|
|
41
41
|
"worker": [
|
|
42
|
-
"./dist/index.worker.d.
|
|
42
|
+
"./dist/index.worker.d.mts"
|
|
43
43
|
],
|
|
44
44
|
"schema": [
|
|
45
|
-
"./dist/index.schema.d.
|
|
45
|
+
"./dist/index.schema.d.mts"
|
|
46
46
|
]
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"exports": {
|
|
50
50
|
".": {
|
|
51
|
-
"types": "./dist/index.d.
|
|
52
|
-
"default": "./dist/index.
|
|
51
|
+
"types": "./dist/index.d.mts",
|
|
52
|
+
"default": "./dist/index.mjs"
|
|
53
53
|
},
|
|
54
54
|
"./react": {
|
|
55
|
-
"types": "./dist/index.react.d.
|
|
56
|
-
"default": "./dist/index.react.
|
|
55
|
+
"types": "./dist/index.react.d.mts",
|
|
56
|
+
"default": "./dist/index.react.mjs"
|
|
57
57
|
},
|
|
58
58
|
"./worker": {
|
|
59
|
-
"types": "./dist/index.worker.d.
|
|
60
|
-
"default": "./dist/index.worker.
|
|
59
|
+
"types": "./dist/index.worker.d.mts",
|
|
60
|
+
"default": "./dist/index.worker.mjs"
|
|
61
61
|
},
|
|
62
62
|
"./schema": {
|
|
63
|
-
"types": "./dist/index.schema.d.
|
|
64
|
-
"default": "./dist/index.schema.
|
|
63
|
+
"types": "./dist/index.schema.d.mts",
|
|
64
|
+
"default": "./dist/index.schema.mjs"
|
|
65
65
|
},
|
|
66
66
|
"./package.json": "./package.json"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@swc/core": "1.15.
|
|
70
|
-
"browserslist": "4.28.
|
|
69
|
+
"@swc/core": "1.15.32",
|
|
70
|
+
"browserslist": "4.28.2",
|
|
71
71
|
"kolorist": "1.8.0",
|
|
72
72
|
"semver": "7.7.4",
|
|
73
73
|
"zod": "4.3.6",
|
|
74
|
-
"@serwist/
|
|
75
|
-
"
|
|
76
|
-
"@serwist/window": "9.5.
|
|
77
|
-
"serwist": "9.5.
|
|
74
|
+
"@serwist/build": "9.5.8",
|
|
75
|
+
"serwist": "9.5.8",
|
|
76
|
+
"@serwist/window": "9.5.8",
|
|
77
|
+
"@serwist/utils": "9.5.8"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@types/node": "25.
|
|
80
|
+
"@types/node": "25.6.0",
|
|
81
81
|
"@types/react": "19.2.14",
|
|
82
82
|
"@types/semver": "7.7.1",
|
|
83
|
-
"esbuild": "0.
|
|
84
|
-
"esbuild-wasm": "0.
|
|
85
|
-
"next": "16.
|
|
86
|
-
"react": "19.2.
|
|
87
|
-
"react-dom": "19.2.
|
|
88
|
-
"
|
|
89
|
-
"type-fest": "5.
|
|
90
|
-
"typescript": "
|
|
91
|
-
"@serwist/configs": "9.5.7"
|
|
83
|
+
"esbuild": "0.28.0",
|
|
84
|
+
"esbuild-wasm": "0.28.0",
|
|
85
|
+
"next": "16.2.4",
|
|
86
|
+
"react": "19.2.5",
|
|
87
|
+
"react-dom": "19.2.5",
|
|
88
|
+
"tsdown": "0.21.10",
|
|
89
|
+
"type-fest": "5.6.0",
|
|
90
|
+
"typescript": "6.0.3"
|
|
92
91
|
},
|
|
93
92
|
"peerDependencies": {
|
|
94
93
|
"esbuild": ">=0.25.0 <1.0.0",
|
|
@@ -109,8 +108,8 @@
|
|
|
109
108
|
}
|
|
110
109
|
},
|
|
111
110
|
"scripts": {
|
|
112
|
-
"build": "rimraf dist && NODE_ENV=production
|
|
113
|
-
"dev": "
|
|
111
|
+
"build": "rimraf dist && NODE_ENV=production tsdown",
|
|
112
|
+
"dev": "tsdown --watch",
|
|
114
113
|
"lint": "biome lint ./src",
|
|
115
114
|
"qcheck": "biome check ./src",
|
|
116
115
|
"typecheck": "tsc"
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { injectPartial, globPartial, basePartial, assertType } from '@serwist/build/schema';
|
|
3
|
-
import semver from 'semver';
|
|
4
|
-
import z from 'zod';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import { green, bold, white, yellow, red } from 'kolorist';
|
|
7
|
-
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from 'next/constants.js';
|
|
8
|
-
|
|
9
|
-
const SUPPORTED_ESBUILD_OPTIONS = [
|
|
10
|
-
"sourcemap",
|
|
11
|
-
"legalComments",
|
|
12
|
-
"sourceRoot",
|
|
13
|
-
"sourcesContent",
|
|
14
|
-
"format",
|
|
15
|
-
"globalName",
|
|
16
|
-
"target",
|
|
17
|
-
"supported",
|
|
18
|
-
"define",
|
|
19
|
-
"treeShaking",
|
|
20
|
-
"minify",
|
|
21
|
-
"mangleProps",
|
|
22
|
-
"reserveProps",
|
|
23
|
-
"mangleQuoted",
|
|
24
|
-
"mangleCache",
|
|
25
|
-
"drop",
|
|
26
|
-
"dropLabels",
|
|
27
|
-
"minifyWhitespace",
|
|
28
|
-
"minifyIdentifiers",
|
|
29
|
-
"minifySyntax",
|
|
30
|
-
"lineLimit",
|
|
31
|
-
"charset",
|
|
32
|
-
"ignoreAnnotations",
|
|
33
|
-
"jsx",
|
|
34
|
-
"jsxFactory",
|
|
35
|
-
"jsxFragment",
|
|
36
|
-
"jsxImportSource",
|
|
37
|
-
"jsxDev",
|
|
38
|
-
"jsxSideEffects",
|
|
39
|
-
"pure",
|
|
40
|
-
"keepNames",
|
|
41
|
-
"absPaths",
|
|
42
|
-
"color",
|
|
43
|
-
"logLevel",
|
|
44
|
-
"logLimit",
|
|
45
|
-
"logOverride",
|
|
46
|
-
"tsconfigRaw",
|
|
47
|
-
"bundle",
|
|
48
|
-
"splitting",
|
|
49
|
-
"preserveSymlinks",
|
|
50
|
-
"external",
|
|
51
|
-
"packages",
|
|
52
|
-
"alias",
|
|
53
|
-
"loader",
|
|
54
|
-
"resolveExtensions",
|
|
55
|
-
"mainFields",
|
|
56
|
-
"conditions",
|
|
57
|
-
"allowOverwrite",
|
|
58
|
-
"tsconfig",
|
|
59
|
-
"outExtension",
|
|
60
|
-
"publicPath",
|
|
61
|
-
"inject",
|
|
62
|
-
"banner",
|
|
63
|
-
"footer",
|
|
64
|
-
"plugins"
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
const require$1 = createRequire(import.meta.url);
|
|
68
|
-
const NEXT_VERSION = require$1("next/package.json").version;
|
|
69
|
-
const LOGGING_SPACE_PREFIX = semver.gte(NEXT_VERSION, "16.0.0") ? "" : " ";
|
|
70
|
-
const prefixedLog = (prefixType, ...message)=>{
|
|
71
|
-
let prefix;
|
|
72
|
-
let consoleMethod;
|
|
73
|
-
switch(prefixType){
|
|
74
|
-
case "wait":
|
|
75
|
-
prefix = `${white(bold("○"))} (serwist)`;
|
|
76
|
-
consoleMethod = "log";
|
|
77
|
-
break;
|
|
78
|
-
case "error":
|
|
79
|
-
prefix = `${red(bold("X"))} (serwist)`;
|
|
80
|
-
consoleMethod = "error";
|
|
81
|
-
break;
|
|
82
|
-
case "warn":
|
|
83
|
-
prefix = `${yellow(bold("⚠"))} (serwist)`;
|
|
84
|
-
consoleMethod = "warn";
|
|
85
|
-
break;
|
|
86
|
-
case "info":
|
|
87
|
-
prefix = `${white(bold("○"))} (serwist)`;
|
|
88
|
-
consoleMethod = "log";
|
|
89
|
-
break;
|
|
90
|
-
case "event":
|
|
91
|
-
prefix = `${green(bold("✓"))} (serwist)`;
|
|
92
|
-
consoleMethod = "log";
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if ((message[0] === "" || message[0] === undefined) && message.length === 1) {
|
|
96
|
-
message.shift();
|
|
97
|
-
}
|
|
98
|
-
if (message.length === 0) {
|
|
99
|
-
console[consoleMethod]("");
|
|
100
|
-
} else {
|
|
101
|
-
console[consoleMethod](`${LOGGING_SPACE_PREFIX}${prefix}`, ...message);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const wait = (...message)=>prefixedLog("wait", ...message);
|
|
105
|
-
const error = (...message)=>prefixedLog("error", ...message);
|
|
106
|
-
const warn = (...message)=>prefixedLog("warn", ...message);
|
|
107
|
-
const info = (...message)=>prefixedLog("info", ...message);
|
|
108
|
-
const event = (...message)=>prefixedLog("event", ...message);
|
|
109
|
-
|
|
110
|
-
var logger = /*#__PURE__*/Object.freeze({
|
|
111
|
-
__proto__: null,
|
|
112
|
-
NEXT_VERSION: NEXT_VERSION,
|
|
113
|
-
error: error,
|
|
114
|
-
event: event,
|
|
115
|
-
info: info,
|
|
116
|
-
wait: wait,
|
|
117
|
-
warn: warn
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const loadNextConfig = async (cwd, isDev)=>{
|
|
121
|
-
const nextPhase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD;
|
|
122
|
-
// webpackIgnore is only supported by Next.js 15 and above, but it is necessary
|
|
123
|
-
const nextConfig = await import(/* webpackIgnore: true */ 'next/dist/server/config.js');
|
|
124
|
-
const loadConfig = typeof nextConfig.default === "function" ? nextConfig.default : nextConfig.default.default;
|
|
125
|
-
return loadConfig(nextPhase, cwd, {
|
|
126
|
-
silent: false
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
const generateGlobPatterns = (distDir)=>[
|
|
130
|
-
`${distDir}static/**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}`,
|
|
131
|
-
"public/**/*"
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
const turboPartial = z.strictObject({
|
|
135
|
-
cwd: z.string().prefault(process.cwd()),
|
|
136
|
-
nextConfig: z.object({
|
|
137
|
-
assetPrefix: z.string().optional(),
|
|
138
|
-
basePath: z.string().optional(),
|
|
139
|
-
distDir: z.string().optional()
|
|
140
|
-
}).optional(),
|
|
141
|
-
useNativeEsbuild: z.boolean().prefault(process.platform === "win32"),
|
|
142
|
-
rebuildOnChange: z.boolean().prefault(true),
|
|
143
|
-
esbuildOptions: z.partialRecord(z.literal(SUPPORTED_ESBUILD_OPTIONS), z.any()).prefault({})
|
|
144
|
-
});
|
|
145
|
-
const injectManifestOptions = z.strictObject({
|
|
146
|
-
...basePartial.shape,
|
|
147
|
-
...globPartial.shape,
|
|
148
|
-
...injectPartial.shape,
|
|
149
|
-
...turboPartial.shape,
|
|
150
|
-
globPatterns: z.array(z.string()).optional(),
|
|
151
|
-
globDirectory: z.string().optional()
|
|
152
|
-
}).omit({
|
|
153
|
-
disablePrecacheManifest: true
|
|
154
|
-
}).transform(async (input)=>{
|
|
155
|
-
// webpackIgnore is only supported by Next.js 15 and above, but it is necessary
|
|
156
|
-
const nextConfig = semver.gte(NEXT_VERSION, "15.0.0") ? {
|
|
157
|
-
...await loadNextConfig(input.cwd, process.env.NODE_ENV === "development"),
|
|
158
|
-
...input.nextConfig
|
|
159
|
-
} : {
|
|
160
|
-
distDir: input.nextConfig?.distDir ?? ".next",
|
|
161
|
-
basePath: input.nextConfig?.basePath ?? "/",
|
|
162
|
-
assetPrefix: input.nextConfig?.assetPrefix ?? input.nextConfig?.basePath ?? ""
|
|
163
|
-
};
|
|
164
|
-
let distDir = nextConfig.distDir;
|
|
165
|
-
if (distDir[0] === "/") distDir = distDir.slice(1);
|
|
166
|
-
if (distDir[distDir.length - 1] !== "/") distDir += "/";
|
|
167
|
-
return {
|
|
168
|
-
...input,
|
|
169
|
-
swSrc: path.isAbsolute(input.swSrc) ? input.swSrc : path.join(input.cwd, input.swSrc),
|
|
170
|
-
globPatterns: input.globPatterns ?? generateGlobPatterns(distDir),
|
|
171
|
-
globDirectory: input.globDirectory ?? input.cwd,
|
|
172
|
-
dontCacheBustURLsMatching: input.dontCacheBustURLsMatching ?? new RegExp(`^${distDir}static/`),
|
|
173
|
-
nextConfig: {
|
|
174
|
-
...nextConfig,
|
|
175
|
-
distDir,
|
|
176
|
-
basePath: nextConfig.basePath || "/"
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
});
|
|
180
|
-
assertType();
|
|
181
|
-
assertType();
|
|
182
|
-
assertType();
|
|
183
|
-
assertType();
|
|
184
|
-
|
|
185
|
-
export { injectManifestOptions as i, logger as l, turboPartial as t };
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NextConfig } from "next";
|
|
2
|
-
import { NextResponse } from "next/server.js";
|
|
3
|
-
import type { InjectManifestOptions } from "./types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a Route Handler for Serwist files.
|
|
6
|
-
* @param options Options for {@linkcode getFileManifestEntries}.
|
|
7
|
-
*/
|
|
8
|
-
export declare const createSerwistRoute: (options: InjectManifestOptions) => {
|
|
9
|
-
dynamic: "force-static";
|
|
10
|
-
dynamicParams: false;
|
|
11
|
-
revalidate: false;
|
|
12
|
-
generateStaticParams: () => Promise<{
|
|
13
|
-
path: string;
|
|
14
|
-
}[]>;
|
|
15
|
-
GET: (_: Request, { params }: {
|
|
16
|
-
params: Promise<{
|
|
17
|
-
path: string;
|
|
18
|
-
}>;
|
|
19
|
-
}) => Promise<NextResponse<unknown>>;
|
|
20
|
-
};
|
|
21
|
-
export declare const withSerwist: (nextConfig?: NextConfig) => NextConfig;
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK9C,OAAO,KAAK,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAC;AAuCvF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,qBAAqB;;;;;;;aAoGzC,OAAO,cAAc;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;CAmBjF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,aAAY,UAAe,KAAG,UAGxD,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { rebasePath, getFileManifestEntries } from '@serwist/build';
|
|
5
|
-
import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
|
|
6
|
-
import { browserslistToEsbuild } from '@serwist/utils';
|
|
7
|
-
import browserslist from 'browserslist';
|
|
8
|
-
import { cyan, dim, yellow } from 'kolorist';
|
|
9
|
-
import { MODERN_BROWSERSLIST_TARGET } from 'next/constants.js';
|
|
10
|
-
import { NextResponse } from 'next/server.js';
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
import { i as injectManifestOptions, l as logger } from './chunks/index.schema.js';
|
|
13
|
-
import 'semver';
|
|
14
|
-
import 'node:module';
|
|
15
|
-
|
|
16
|
-
let esbuildWasm = null;
|
|
17
|
-
let esbuildNative = null;
|
|
18
|
-
const logSerwistResult = (filePath, buildResult)=>{
|
|
19
|
-
const { count, size, warnings } = buildResult;
|
|
20
|
-
const hasWarnings = warnings && warnings.length > 0;
|
|
21
|
-
if (filePath === "sw.js" && (hasWarnings || count > 0)) {
|
|
22
|
-
logger[hasWarnings ? "warn" : "event"](`${cyan(count)} precache entries ${dim(`(${(size / 1024).toFixed(2)} KiB)`)}${hasWarnings ? `\n${yellow([
|
|
23
|
-
"⚠ warnings",
|
|
24
|
-
...warnings.map((w)=>` ${w}`),
|
|
25
|
-
""
|
|
26
|
-
].join("\n"))}` : ""}`);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const validateGetManifestOptions = async (input)=>{
|
|
30
|
-
const result = await injectManifestOptions.spa(input, {
|
|
31
|
-
error: validationErrorMap
|
|
32
|
-
});
|
|
33
|
-
if (!result.success) {
|
|
34
|
-
throw new SerwistConfigError({
|
|
35
|
-
moduleName: "@serwist/turbopack",
|
|
36
|
-
message: z.prettifyError(result.error)
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return result.data;
|
|
40
|
-
};
|
|
41
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
42
|
-
const contentTypeMap = {
|
|
43
|
-
".js": "application/javascript",
|
|
44
|
-
".map": "application/json; charset=UTF-8"
|
|
45
|
-
};
|
|
46
|
-
const createSerwistRoute = (options)=>{
|
|
47
|
-
const dynamic = "force-static", dynamicParams = false, revalidate = false;
|
|
48
|
-
const validation = validateGetManifestOptions(options).then((config)=>{
|
|
49
|
-
return {
|
|
50
|
-
...config,
|
|
51
|
-
disablePrecacheManifest: isDev,
|
|
52
|
-
additionalPrecacheEntries: isDev ? [] : config.additionalPrecacheEntries,
|
|
53
|
-
globIgnores: [
|
|
54
|
-
...config.globIgnores,
|
|
55
|
-
rebasePath({
|
|
56
|
-
file: config.swSrc,
|
|
57
|
-
baseDirectory: config.globDirectory
|
|
58
|
-
})
|
|
59
|
-
],
|
|
60
|
-
manifestTransforms: [
|
|
61
|
-
...config.manifestTransforms ?? [],
|
|
62
|
-
async (manifestEntries)=>{
|
|
63
|
-
const manifest = manifestEntries.map((m)=>{
|
|
64
|
-
if (m.url.startsWith(config.nextConfig.distDir)) {
|
|
65
|
-
m.url = `${config.nextConfig.assetPrefix}/_next/${m.url.slice(config.nextConfig.distDir.length)}`;
|
|
66
|
-
}
|
|
67
|
-
if (m.url.startsWith("public/")) {
|
|
68
|
-
m.url = path.posix.join(config.nextConfig.basePath, m.url.slice(7));
|
|
69
|
-
}
|
|
70
|
-
return m;
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
manifest,
|
|
74
|
-
warnings: []
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
let lastHash = null;
|
|
81
|
-
let map = null;
|
|
82
|
-
const loadMap = async (filePath)=>{
|
|
83
|
-
const config = await validation;
|
|
84
|
-
const { count, size, manifestEntries, warnings } = await getFileManifestEntries(config);
|
|
85
|
-
const injectionPoint = config.injectionPoint || "";
|
|
86
|
-
const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries, null, 2);
|
|
87
|
-
const log = (type, ...message)=>{
|
|
88
|
-
if (filePath === "sw.js") {
|
|
89
|
-
logger[type](...message);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
let esbuild;
|
|
93
|
-
if (config.useNativeEsbuild) {
|
|
94
|
-
log("info", "Using esbuild to bundle the service worker.");
|
|
95
|
-
if (!esbuildNative) esbuildNative = import(/* webpackIgnore: true */ 'esbuild');
|
|
96
|
-
esbuild = await esbuildNative;
|
|
97
|
-
} else {
|
|
98
|
-
log("info", "Using esbuild-wasm to bundle the service worker.");
|
|
99
|
-
if (!esbuildWasm) esbuildWasm = import(/* webpackIgnore: true */ 'esbuild-wasm');
|
|
100
|
-
esbuild = await esbuildWasm;
|
|
101
|
-
}
|
|
102
|
-
logSerwistResult(filePath, {
|
|
103
|
-
count,
|
|
104
|
-
size,
|
|
105
|
-
warnings
|
|
106
|
-
});
|
|
107
|
-
const result = await esbuild.build({
|
|
108
|
-
sourcemap: true,
|
|
109
|
-
format: "esm",
|
|
110
|
-
treeShaking: true,
|
|
111
|
-
minify: !isDev,
|
|
112
|
-
bundle: true,
|
|
113
|
-
...config.esbuildOptions,
|
|
114
|
-
target: config.esbuildOptions?.target ?? browserslistToEsbuild(browserslist, config.cwd, MODERN_BROWSERSLIST_TARGET),
|
|
115
|
-
platform: "browser",
|
|
116
|
-
define: {
|
|
117
|
-
...config.esbuildOptions.define,
|
|
118
|
-
...injectionPoint ? {
|
|
119
|
-
[injectionPoint]: manifestString
|
|
120
|
-
} : {}
|
|
121
|
-
},
|
|
122
|
-
outdir: config.cwd,
|
|
123
|
-
write: false,
|
|
124
|
-
entryNames: "[name]",
|
|
125
|
-
assetNames: "[name]-[hash]",
|
|
126
|
-
chunkNames: "[name]-[hash]",
|
|
127
|
-
entryPoints: [
|
|
128
|
-
{
|
|
129
|
-
in: config.swSrc,
|
|
130
|
-
out: "sw"
|
|
131
|
-
}
|
|
132
|
-
]
|
|
133
|
-
});
|
|
134
|
-
if (result.errors.length) {
|
|
135
|
-
console.error("Failed to build the service worker.", result.errors);
|
|
136
|
-
throw new Error();
|
|
137
|
-
}
|
|
138
|
-
if (result.warnings.length) {
|
|
139
|
-
console.warn(result.warnings);
|
|
140
|
-
}
|
|
141
|
-
return new Map(result.outputFiles.map((e)=>[
|
|
142
|
-
e.path,
|
|
143
|
-
e.text
|
|
144
|
-
]));
|
|
145
|
-
};
|
|
146
|
-
const generateStaticParams = async ()=>{
|
|
147
|
-
const config = await validation;
|
|
148
|
-
if (!map) map = await loadMap("root");
|
|
149
|
-
return [
|
|
150
|
-
...map.keys()
|
|
151
|
-
].map((e)=>({
|
|
152
|
-
path: path.relative(config.cwd, e)
|
|
153
|
-
}));
|
|
154
|
-
};
|
|
155
|
-
const GET = async (_, { params })=>{
|
|
156
|
-
const { path: filePath } = await params;
|
|
157
|
-
const config = await validation;
|
|
158
|
-
if (isDev && config.rebuildOnChange) {
|
|
159
|
-
const swContent = fs.readFileSync(config.swSrc, "utf-8");
|
|
160
|
-
const currentHash = crypto.createHash("sha256").update(swContent).digest("hex");
|
|
161
|
-
if (!map || lastHash !== currentHash) {
|
|
162
|
-
map = await loadMap(filePath);
|
|
163
|
-
lastHash = currentHash;
|
|
164
|
-
}
|
|
165
|
-
} else if (!map) map = await loadMap(filePath);
|
|
166
|
-
return new NextResponse(map.get(path.join(config.cwd, filePath)), {
|
|
167
|
-
headers: {
|
|
168
|
-
"Content-Type": contentTypeMap[path.extname(filePath)] || "text/plain",
|
|
169
|
-
"Service-Worker-Allowed": "/"
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
return {
|
|
174
|
-
dynamic,
|
|
175
|
-
dynamicParams,
|
|
176
|
-
revalidate,
|
|
177
|
-
generateStaticParams,
|
|
178
|
-
GET
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
const withSerwist = (nextConfig = {})=>({
|
|
182
|
-
...nextConfig,
|
|
183
|
-
serverExternalPackages: [
|
|
184
|
-
...nextConfig.serverExternalPackages ?? [],
|
|
185
|
-
"esbuild",
|
|
186
|
-
"esbuild-wasm"
|
|
187
|
-
]
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
export { createSerwistRoute, withSerwist };
|
package/dist/index.react.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Serwist } from "@serwist/window";
|
|
2
|
-
import { type ReactNode } from "react";
|
|
3
|
-
import { useSerwist } from "./lib/context.js";
|
|
4
|
-
export interface SerwistProviderProps {
|
|
5
|
-
swUrl: string;
|
|
6
|
-
disable?: boolean;
|
|
7
|
-
register?: boolean;
|
|
8
|
-
cacheOnNavigation?: boolean;
|
|
9
|
-
reloadOnOnline?: boolean;
|
|
10
|
-
options?: RegistrationOptions;
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
}
|
|
13
|
-
declare global {
|
|
14
|
-
interface Window {
|
|
15
|
-
serwist: Serwist;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* `@serwist/window` provider for Next.js apps.
|
|
20
|
-
* @param options
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export declare function SerwistProvider({ swUrl, disable, register, cacheOnNavigation, reloadOnOnline, options, children, }: SerwistProviderProps): import("react").JSX.Element;
|
|
24
|
-
export { useSerwist };
|
|
25
|
-
//# sourceMappingURL=index.react.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAe,EACf,QAAe,EACf,iBAAwB,EACxB,cAAqB,EACrB,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,+BAuDtB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/index.react.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { Serwist } from '@serwist/window';
|
|
3
|
-
import { isCurrentPageOutOfScope } from '@serwist/window/internal';
|
|
4
|
-
import { createContext, useContext, useState, useEffect } from 'react';
|
|
5
|
-
|
|
6
|
-
const SerwistContext = createContext(null);
|
|
7
|
-
const useSerwist = ()=>{
|
|
8
|
-
const context = useContext(SerwistContext);
|
|
9
|
-
if (!context) {
|
|
10
|
-
throw new Error("[useSerwist]: 'SerwistContext' is not available.");
|
|
11
|
-
}
|
|
12
|
-
return context;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function SerwistProvider({ swUrl, disable = false, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
16
|
-
const [serwist] = useState(()=>{
|
|
17
|
-
if (typeof window === "undefined") return null;
|
|
18
|
-
if (disable) return null;
|
|
19
|
-
const scope = options?.scope || "/";
|
|
20
|
-
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
21
|
-
window.serwist = new Serwist(swUrl, {
|
|
22
|
-
...options,
|
|
23
|
-
scope,
|
|
24
|
-
type: options?.type || "module"
|
|
25
|
-
});
|
|
26
|
-
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
27
|
-
void window.serwist.register();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return window.serwist ?? null;
|
|
31
|
-
});
|
|
32
|
-
useEffect(()=>{
|
|
33
|
-
const cacheUrls = async (url)=>{
|
|
34
|
-
if (!window.navigator.onLine || !url) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
serwist?.messageSW({
|
|
38
|
-
type: "CACHE_URLS",
|
|
39
|
-
payload: {
|
|
40
|
-
urlsToCache: [
|
|
41
|
-
url
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const cacheCurrentPathname = ()=>cacheUrls(window.location.pathname);
|
|
47
|
-
const pushState = history.pushState;
|
|
48
|
-
const replaceState = history.replaceState;
|
|
49
|
-
if (cacheOnNavigation) {
|
|
50
|
-
history.pushState = (...args)=>{
|
|
51
|
-
pushState.apply(history, args);
|
|
52
|
-
cacheUrls(args[2]);
|
|
53
|
-
};
|
|
54
|
-
history.replaceState = (...args)=>{
|
|
55
|
-
replaceState.apply(history, args);
|
|
56
|
-
cacheUrls(args[2]);
|
|
57
|
-
};
|
|
58
|
-
window.addEventListener("online", cacheCurrentPathname);
|
|
59
|
-
}
|
|
60
|
-
return ()=>{
|
|
61
|
-
history.pushState = pushState;
|
|
62
|
-
history.replaceState = replaceState;
|
|
63
|
-
window.removeEventListener("online", cacheCurrentPathname);
|
|
64
|
-
};
|
|
65
|
-
}, [
|
|
66
|
-
serwist,
|
|
67
|
-
cacheOnNavigation
|
|
68
|
-
]);
|
|
69
|
-
useEffect(()=>{
|
|
70
|
-
const reload = ()=>location.reload();
|
|
71
|
-
if (reloadOnOnline) {
|
|
72
|
-
window.addEventListener("online", reload);
|
|
73
|
-
}
|
|
74
|
-
return ()=>{
|
|
75
|
-
window.removeEventListener("online", reload);
|
|
76
|
-
};
|
|
77
|
-
}, [
|
|
78
|
-
reloadOnOnline
|
|
79
|
-
]);
|
|
80
|
-
return jsx(SerwistContext.Provider, {
|
|
81
|
-
value: {
|
|
82
|
-
serwist
|
|
83
|
-
},
|
|
84
|
-
children: children
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { SerwistProvider, useSerwist };
|