unpeek 2.0.0 → 4.0.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/README.md +57 -21
- package/README.tr.md +65 -29
- package/dist/adapters/esbuild.cjs +13 -0
- package/dist/adapters/esbuild.d.cts +13 -0
- package/dist/adapters/esbuild.d.ts +11 -0
- package/dist/adapters/esbuild.js +13 -0
- package/dist/adapters/next/adapter.cjs +43 -0
- package/dist/{next → adapters/next}/adapter.d.cts +4 -4
- package/dist/{next → adapters/next}/adapter.d.ts +4 -4
- package/dist/adapters/next/adapter.js +43 -0
- package/dist/adapters/next/index.cjs +16 -0
- package/dist/adapters/next/index.d.cts +53 -0
- package/dist/adapters/next/index.d.ts +53 -0
- package/dist/adapters/next/index.js +16 -0
- package/dist/adapters/rollup.cjs +13 -0
- package/dist/adapters/rollup.d.cts +13 -0
- package/dist/adapters/rollup.d.ts +11 -0
- package/dist/adapters/rollup.js +13 -0
- package/dist/adapters/rspack.cjs +13 -0
- package/dist/adapters/rspack.d.cts +13 -0
- package/dist/adapters/rspack.d.ts +11 -0
- package/dist/adapters/rspack.js +13 -0
- package/dist/adapters/vite.cjs +13 -0
- package/dist/adapters/vite.d.cts +13 -0
- package/dist/adapters/vite.d.ts +11 -0
- package/dist/adapters/vite.js +13 -0
- package/dist/adapters/webpack.cjs +13 -0
- package/dist/adapters/webpack.d.cts +13 -0
- package/dist/adapters/webpack.d.ts +11 -0
- package/dist/adapters/webpack.js +13 -0
- package/dist/browser.cjs +8 -5
- package/dist/browser.d.cts +44 -3
- package/dist/browser.d.ts +44 -3
- package/dist/browser.js +10 -7
- package/dist/{chunk-5QD6FZPB.js → chunk-2JU3V7HW.js} +75 -43
- package/dist/chunk-3LWXEJU6.cjs +1054 -0
- package/dist/chunk-4FNZNIBW.js +7391 -0
- package/dist/chunk-7HXLHLLQ.cjs +503 -0
- package/dist/chunk-ADKRENAP.js +1054 -0
- package/dist/chunk-EN6QVR6P.js +89 -0
- package/dist/chunk-HHC7BUCK.js +503 -0
- package/dist/chunk-KLYFNMKS.cjs +7391 -0
- package/dist/chunk-L6BOM5VS.cjs +40 -0
- package/dist/{chunk-OOXSZTRV.js → chunk-LA6J3BT3.js} +26 -1
- package/dist/chunk-URPPSTHZ.cjs +89 -0
- package/dist/chunk-VG4Y26ZN.cjs +429 -0
- package/dist/{chunk-GZB7PFLY.js → chunk-W77DAC3H.js} +46 -64
- package/dist/chunk-X6EETCO6.cjs +352 -0
- package/dist/chunk-YCRMTXOE.js +429 -0
- package/dist/{chunk-GAVI2C44.cjs → chunk-ZG7BIAUI.cjs} +80 -48
- package/dist/cli/index.js +9861 -32
- package/dist/{types-BBSRUEab.d.cts → config-Y6JwVGwX.d.cts} +58 -86
- package/dist/{types-BBSRUEab.d.ts → config-Y6JwVGwX.d.ts} +58 -86
- package/dist/config.cjs +4 -16
- package/dist/config.d.cts +1 -12
- package/dist/config.d.ts +1 -12
- package/dist/config.js +5 -17
- package/dist/index-0O1WSfVP.d.ts +52 -0
- package/dist/index-COVHErnx.d.cts +52 -0
- package/dist/index.cjs +437 -9
- package/dist/index.d.cts +9 -17
- package/dist/index.d.ts +9 -17
- package/dist/index.js +438 -10
- package/dist/plugins/unplugin.cjs +21 -0
- package/dist/plugins/unplugin.d.cts +17 -0
- package/dist/plugins/unplugin.d.ts +15 -0
- package/dist/{bundler → plugins}/unplugin.js +6 -5
- package/dist/types-CMtZnV8C.d.ts +112 -0
- package/dist/types-D93PuOOl.d.cts +112 -0
- package/package.json +48 -52
- package/dist/ast/index.cjs +0 -17
- package/dist/ast/index.d.cts +0 -18
- package/dist/ast/index.d.ts +0 -18
- package/dist/ast/index.js +0 -17
- package/dist/bundler/unplugin.cjs +0 -20
- package/dist/bundler/unplugin.d.cts +0 -16
- package/dist/bundler/unplugin.d.ts +0 -14
- package/dist/chunk-24K5NDXH.cjs +0 -370
- package/dist/chunk-27HR647Q.js +0 -190
- package/dist/chunk-4TDLLEEU.cjs +0 -15
- package/dist/chunk-5LCMI2TL.js +0 -575
- package/dist/chunk-5M6Z7ZFT.cjs +0 -83
- package/dist/chunk-6N6S6WTQ.cjs +0 -423
- package/dist/chunk-7YVEHJVM.cjs +0 -575
- package/dist/chunk-J5CGNZDM.cjs +0 -190
- package/dist/chunk-KQWNFKT2.js +0 -423
- package/dist/chunk-LXP73HJC.cjs +0 -4532
- package/dist/chunk-R6EBIR3T.cjs +0 -14
- package/dist/chunk-S4S2WXGC.js +0 -14
- package/dist/chunk-UMPUYLLZ.js +0 -4532
- package/dist/chunk-X5MKMFMX.js +0 -83
- package/dist/cli/index.cjs +0 -324
- package/dist/cli/index.d.cts +0 -22
- package/dist/cli/index.d.ts +0 -22
- package/dist/esbuild.cjs +0 -15
- package/dist/esbuild.d.cts +0 -11
- package/dist/esbuild.d.ts +0 -11
- package/dist/esbuild.js +0 -13
- package/dist/next/adapter.cjs +0 -31
- package/dist/next/adapter.js +0 -31
- package/dist/next/index.cjs +0 -18
- package/dist/next/index.d.cts +0 -42
- package/dist/next/index.d.ts +0 -42
- package/dist/next/index.js +0 -18
- package/dist/rollup.cjs +0 -15
- package/dist/rollup.d.cts +0 -11
- package/dist/rollup.d.ts +0 -11
- package/dist/rollup.js +0 -13
- package/dist/runtime/index.cjs +0 -17
- package/dist/runtime/index.d.cts +0 -36
- package/dist/runtime/index.d.ts +0 -36
- package/dist/runtime/index.js +0 -17
- package/dist/vite.cjs +0 -15
- package/dist/vite.d.cts +0 -11
- package/dist/vite.d.ts +0 -11
- package/dist/vite.js +0 -13
- package/dist/webpack.cjs +0 -15
- package/dist/webpack.d.cts +0 -11
- package/dist/webpack.d.ts +0 -11
- package/dist/webpack.js +0 -13
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
protectProject
|
|
3
|
-
|
|
2
|
+
protectProject,
|
|
3
|
+
serializeNextOptions
|
|
4
|
+
} from "./chunk-HHC7BUCK.js";
|
|
5
|
+
import {
|
|
6
|
+
safeDecodeURIComponent
|
|
7
|
+
} from "./chunk-ADKRENAP.js";
|
|
4
8
|
import {
|
|
5
9
|
computeFnv1aHash
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4FNZNIBW.js";
|
|
7
11
|
import {
|
|
12
|
+
UnpeekError,
|
|
8
13
|
__dirname,
|
|
9
14
|
__require
|
|
10
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-LA6J3BT3.js";
|
|
11
16
|
|
|
12
|
-
// src/next/index.ts
|
|
17
|
+
// src/adapters/next/index.ts
|
|
13
18
|
import fs from "fs";
|
|
14
19
|
import path from "path";
|
|
15
20
|
import crypto from "crypto";
|
|
16
21
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
17
22
|
import { createRequire } from "module";
|
|
23
|
+
var MAX_NEXT_OPTIONS_ENV_BYTES = 32767;
|
|
18
24
|
async function loadUpstreamAdapter(adapterPath) {
|
|
19
25
|
const resolved = path.isAbsolute(adapterPath) ? adapterPath : path.resolve(process.cwd(), adapterPath);
|
|
20
26
|
try {
|
|
@@ -31,11 +37,31 @@ function recomputeHash(content, existingHash) {
|
|
|
31
37
|
const algo = len === 64 ? "sha256" : len === 40 ? "sha1" : len === 32 ? "md5" : "sha256";
|
|
32
38
|
return crypto.createHash(algo).update(content).digest("hex");
|
|
33
39
|
}
|
|
40
|
+
function isNonProductionPhase(phase) {
|
|
41
|
+
return phase !== void 0 && phase !== "phase-production-build" && phase !== "phase-export";
|
|
42
|
+
}
|
|
43
|
+
async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
|
|
44
|
+
if (!upstreamPath) return;
|
|
45
|
+
try {
|
|
46
|
+
const upstream = await loadUpstreamAdapter(upstreamPath);
|
|
47
|
+
if (upstream && typeof upstream !== "function" && typeof upstream.onBuildComplete === "function") {
|
|
48
|
+
await upstream.onBuildComplete(context);
|
|
49
|
+
} else if (typeof upstream === "function") {
|
|
50
|
+
await upstream(context);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.warn("[unpeek:next] Failed to delegate to upstream adapter onBuildComplete:", err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
34
56
|
function createUnpeekNextAdapter(options = {}) {
|
|
35
57
|
const upstreamPath = options.upstreamAdapterPath || process.env.UNPEEK_UPSTREAM_ADAPTER_PATH || process.env.NEXT_ADAPTER_PATH;
|
|
58
|
+
let recordedPhase;
|
|
36
59
|
return {
|
|
37
60
|
name: "unpeek",
|
|
38
61
|
async modifyConfig(config, context) {
|
|
62
|
+
if (context && typeof context.phase === "string") {
|
|
63
|
+
recordedPhase = context.phase;
|
|
64
|
+
}
|
|
39
65
|
if (upstreamPath) {
|
|
40
66
|
try {
|
|
41
67
|
const upstream = await loadUpstreamAdapter(upstreamPath);
|
|
@@ -53,6 +79,26 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
53
79
|
const distDir = path.resolve(cwd, context.distDir || ".next");
|
|
54
80
|
const staticDir = path.join(distDir, "static");
|
|
55
81
|
const targetDir = fs.existsSync(staticDir) ? staticDir : distDir;
|
|
82
|
+
const phase = context.phase ?? recordedPhase;
|
|
83
|
+
if (isNonProductionPhase(phase)) {
|
|
84
|
+
await delegateToUpstreamOnBuildComplete(upstreamPath, context);
|
|
85
|
+
return {
|
|
86
|
+
framework: "nextjs",
|
|
87
|
+
outDir: targetDir,
|
|
88
|
+
processedFiles: 0,
|
|
89
|
+
movedSourceMaps: 0,
|
|
90
|
+
originalBytes: 0,
|
|
91
|
+
protectedBytes: 0,
|
|
92
|
+
originalGzipBytes: 0,
|
|
93
|
+
protectedGzipBytes: 0,
|
|
94
|
+
gzipDeltaPercent: 0,
|
|
95
|
+
totalHotFunctionsSkipped: 0,
|
|
96
|
+
totalColdFunctionsProtected: 0,
|
|
97
|
+
totalEncryptedStrings: 0,
|
|
98
|
+
totalMangledSymbols: 0,
|
|
99
|
+
elapsedMs: 0
|
|
100
|
+
};
|
|
101
|
+
}
|
|
56
102
|
const deterministicSeed = typeof options.seed === "number" ? options.seed : context.buildId ? computeFnv1aHash(context.buildId, 1597463007) : 1597463007;
|
|
57
103
|
const summary = await protectProject({
|
|
58
104
|
...options,
|
|
@@ -69,7 +115,7 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
69
115
|
if (!rawFilePath) continue;
|
|
70
116
|
let absPath = path.isAbsolute(rawFilePath) ? rawFilePath : path.resolve(cwd, rawFilePath);
|
|
71
117
|
if (!fs.existsSync(absPath)) {
|
|
72
|
-
const relClean = rawFilePath.replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
|
|
118
|
+
const relClean = safeDecodeURIComponent(rawFilePath).replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
|
|
73
119
|
const fromDist = path.resolve(distDir, relClean);
|
|
74
120
|
if (fs.existsSync(fromDist)) {
|
|
75
121
|
absPath = fromDist;
|
|
@@ -98,18 +144,7 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
98
144
|
}
|
|
99
145
|
}
|
|
100
146
|
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const upstream = await loadUpstreamAdapter(upstreamPath);
|
|
104
|
-
if (upstream && typeof upstream !== "function" && typeof upstream.onBuildComplete === "function") {
|
|
105
|
-
await upstream.onBuildComplete(context);
|
|
106
|
-
} else if (typeof upstream === "function") {
|
|
107
|
-
await upstream(context);
|
|
108
|
-
}
|
|
109
|
-
} catch (err) {
|
|
110
|
-
console.warn("[unpeek:next] Failed to delegate to upstream adapter onBuildComplete:", err);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
147
|
+
await delegateToUpstreamOnBuildComplete(upstreamPath, context);
|
|
113
148
|
return summary;
|
|
114
149
|
}
|
|
115
150
|
};
|
|
@@ -127,14 +162,14 @@ function getUnpeekAdapterPath() {
|
|
|
127
162
|
const isCjs = typeof __dirname !== "undefined";
|
|
128
163
|
const currentDir = isCjs ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
129
164
|
const candidates = [
|
|
130
|
-
path.resolve(currentDir, isCjs ? "next/adapter.cjs" : "next/adapter.js"),
|
|
131
|
-
path.resolve(currentDir, isCjs ? "next/adapter.js" : "next/adapter.cjs"),
|
|
165
|
+
path.resolve(currentDir, isCjs ? "adapters/next/adapter.cjs" : "adapters/next/adapter.js"),
|
|
166
|
+
path.resolve(currentDir, isCjs ? "adapters/next/adapter.js" : "adapters/next/adapter.cjs"),
|
|
132
167
|
path.resolve(currentDir, isCjs ? "adapter.cjs" : "adapter.js"),
|
|
133
168
|
path.resolve(currentDir, isCjs ? "adapter.js" : "adapter.cjs"),
|
|
134
|
-
path.resolve(currentDir, "../dist/next/adapter.cjs"),
|
|
135
|
-
path.resolve(currentDir, "../dist/next/adapter.js"),
|
|
136
|
-
path.resolve(process.cwd(), "node_modules/unpeek/dist/next/adapter.cjs"),
|
|
137
|
-
path.resolve(process.cwd(), "node_modules/unpeek/dist/next/adapter.js")
|
|
169
|
+
path.resolve(currentDir, "../dist/adapters/next/adapter.cjs"),
|
|
170
|
+
path.resolve(currentDir, "../dist/adapters/next/adapter.js"),
|
|
171
|
+
path.resolve(process.cwd(), "node_modules/unpeek/dist/adapters/next/adapter.cjs"),
|
|
172
|
+
path.resolve(process.cwd(), "node_modules/unpeek/dist/adapters/next/adapter.js")
|
|
138
173
|
];
|
|
139
174
|
for (const cand of candidates) {
|
|
140
175
|
if (fs.existsSync(cand)) {
|
|
@@ -143,22 +178,8 @@ function getUnpeekAdapterPath() {
|
|
|
143
178
|
}
|
|
144
179
|
return candidates[0];
|
|
145
180
|
} catch {
|
|
146
|
-
return path.resolve(process.cwd(), "node_modules/unpeek/dist/next/adapter.js");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function readUnpeekNextOptionsFromEnv() {
|
|
150
|
-
const raw = process.env.UNPEEK_NEXT_OPTIONS;
|
|
151
|
-
if (!raw) {
|
|
152
|
-
return void 0;
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
const parsed = JSON.parse(raw);
|
|
156
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
157
|
-
return parsed;
|
|
158
|
-
}
|
|
159
|
-
} catch {
|
|
181
|
+
return path.resolve(process.cwd(), "node_modules/unpeek/dist/adapters/next/adapter.js");
|
|
160
182
|
}
|
|
161
|
-
return void 0;
|
|
162
183
|
}
|
|
163
184
|
function applyWithUnpeek(config = {}, options) {
|
|
164
185
|
const existingAdapter = config.adapterPath || process.env.NEXT_ADAPTER_PATH;
|
|
@@ -169,7 +190,15 @@ function applyWithUnpeek(config = {}, options) {
|
|
|
169
190
|
process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = options.upstreamAdapterPath;
|
|
170
191
|
}
|
|
171
192
|
if (options) {
|
|
172
|
-
|
|
193
|
+
const serialized = serializeNextOptions(options);
|
|
194
|
+
const byteLength = Buffer.byteLength(serialized, "utf8");
|
|
195
|
+
if (byteLength > MAX_NEXT_OPTIONS_ENV_BYTES) {
|
|
196
|
+
throw new UnpeekError(
|
|
197
|
+
"ERR_NEXT_ADAPTER",
|
|
198
|
+
`Serialized UNPEEK_NEXT_OPTIONS (${byteLength} bytes) exceeds the ${MAX_NEXT_OPTIONS_ENV_BYTES}-byte process.env limit.`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
process.env.UNPEEK_NEXT_OPTIONS = serialized;
|
|
173
202
|
} else {
|
|
174
203
|
delete process.env.UNPEEK_NEXT_OPTIONS;
|
|
175
204
|
}
|
|
@@ -181,10 +210,14 @@ function applyWithUnpeek(config = {}, options) {
|
|
|
181
210
|
}
|
|
182
211
|
function withUnpeek(nextConfig = {}, options) {
|
|
183
212
|
if (typeof nextConfig === "function") {
|
|
184
|
-
return
|
|
213
|
+
return async (...args) => {
|
|
185
214
|
const resolved = await nextConfig(...args);
|
|
215
|
+
const phase = typeof args[0] === "string" ? args[0] : void 0;
|
|
216
|
+
if (isNonProductionPhase(phase)) {
|
|
217
|
+
return resolved;
|
|
218
|
+
}
|
|
186
219
|
return applyWithUnpeek(resolved, options);
|
|
187
|
-
}
|
|
220
|
+
};
|
|
188
221
|
}
|
|
189
222
|
return applyWithUnpeek(nextConfig, options);
|
|
190
223
|
}
|
|
@@ -192,6 +225,5 @@ function withUnpeek(nextConfig = {}, options) {
|
|
|
192
225
|
export {
|
|
193
226
|
createUnpeekNextAdapter,
|
|
194
227
|
getUnpeekAdapterPath,
|
|
195
|
-
readUnpeekNextOptionsFromEnv,
|
|
196
228
|
withUnpeek
|
|
197
229
|
};
|