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.
Files changed (120) hide show
  1. package/README.md +57 -21
  2. package/README.tr.md +65 -29
  3. package/dist/adapters/esbuild.cjs +13 -0
  4. package/dist/adapters/esbuild.d.cts +13 -0
  5. package/dist/adapters/esbuild.d.ts +11 -0
  6. package/dist/adapters/esbuild.js +13 -0
  7. package/dist/adapters/next/adapter.cjs +43 -0
  8. package/dist/{next → adapters/next}/adapter.d.cts +4 -4
  9. package/dist/{next → adapters/next}/adapter.d.ts +4 -4
  10. package/dist/adapters/next/adapter.js +43 -0
  11. package/dist/adapters/next/index.cjs +16 -0
  12. package/dist/adapters/next/index.d.cts +53 -0
  13. package/dist/adapters/next/index.d.ts +53 -0
  14. package/dist/adapters/next/index.js +16 -0
  15. package/dist/adapters/rollup.cjs +13 -0
  16. package/dist/adapters/rollup.d.cts +13 -0
  17. package/dist/adapters/rollup.d.ts +11 -0
  18. package/dist/adapters/rollup.js +13 -0
  19. package/dist/adapters/rspack.cjs +13 -0
  20. package/dist/adapters/rspack.d.cts +13 -0
  21. package/dist/adapters/rspack.d.ts +11 -0
  22. package/dist/adapters/rspack.js +13 -0
  23. package/dist/adapters/vite.cjs +13 -0
  24. package/dist/adapters/vite.d.cts +13 -0
  25. package/dist/adapters/vite.d.ts +11 -0
  26. package/dist/adapters/vite.js +13 -0
  27. package/dist/adapters/webpack.cjs +13 -0
  28. package/dist/adapters/webpack.d.cts +13 -0
  29. package/dist/adapters/webpack.d.ts +11 -0
  30. package/dist/adapters/webpack.js +13 -0
  31. package/dist/browser.cjs +8 -5
  32. package/dist/browser.d.cts +44 -3
  33. package/dist/browser.d.ts +44 -3
  34. package/dist/browser.js +10 -7
  35. package/dist/{chunk-5QD6FZPB.js → chunk-2JU3V7HW.js} +75 -43
  36. package/dist/chunk-3LWXEJU6.cjs +1054 -0
  37. package/dist/chunk-4FNZNIBW.js +7391 -0
  38. package/dist/chunk-7HXLHLLQ.cjs +503 -0
  39. package/dist/chunk-ADKRENAP.js +1054 -0
  40. package/dist/chunk-EN6QVR6P.js +89 -0
  41. package/dist/chunk-HHC7BUCK.js +503 -0
  42. package/dist/chunk-KLYFNMKS.cjs +7391 -0
  43. package/dist/chunk-L6BOM5VS.cjs +40 -0
  44. package/dist/{chunk-OOXSZTRV.js → chunk-LA6J3BT3.js} +26 -1
  45. package/dist/chunk-URPPSTHZ.cjs +89 -0
  46. package/dist/chunk-VG4Y26ZN.cjs +429 -0
  47. package/dist/{chunk-GZB7PFLY.js → chunk-W77DAC3H.js} +46 -64
  48. package/dist/chunk-X6EETCO6.cjs +352 -0
  49. package/dist/chunk-YCRMTXOE.js +429 -0
  50. package/dist/{chunk-GAVI2C44.cjs → chunk-ZG7BIAUI.cjs} +80 -48
  51. package/dist/cli/index.js +9861 -32
  52. package/dist/{types-BBSRUEab.d.cts → config-Y6JwVGwX.d.cts} +58 -86
  53. package/dist/{types-BBSRUEab.d.ts → config-Y6JwVGwX.d.ts} +58 -86
  54. package/dist/config.cjs +4 -16
  55. package/dist/config.d.cts +1 -12
  56. package/dist/config.d.ts +1 -12
  57. package/dist/config.js +5 -17
  58. package/dist/index-0O1WSfVP.d.ts +52 -0
  59. package/dist/index-COVHErnx.d.cts +52 -0
  60. package/dist/index.cjs +437 -9
  61. package/dist/index.d.cts +9 -17
  62. package/dist/index.d.ts +9 -17
  63. package/dist/index.js +438 -10
  64. package/dist/plugins/unplugin.cjs +21 -0
  65. package/dist/plugins/unplugin.d.cts +17 -0
  66. package/dist/plugins/unplugin.d.ts +15 -0
  67. package/dist/{bundler → plugins}/unplugin.js +6 -5
  68. package/dist/types-CMtZnV8C.d.ts +112 -0
  69. package/dist/types-D93PuOOl.d.cts +112 -0
  70. package/package.json +48 -52
  71. package/dist/ast/index.cjs +0 -17
  72. package/dist/ast/index.d.cts +0 -18
  73. package/dist/ast/index.d.ts +0 -18
  74. package/dist/ast/index.js +0 -17
  75. package/dist/bundler/unplugin.cjs +0 -20
  76. package/dist/bundler/unplugin.d.cts +0 -16
  77. package/dist/bundler/unplugin.d.ts +0 -14
  78. package/dist/chunk-24K5NDXH.cjs +0 -370
  79. package/dist/chunk-27HR647Q.js +0 -190
  80. package/dist/chunk-4TDLLEEU.cjs +0 -15
  81. package/dist/chunk-5LCMI2TL.js +0 -575
  82. package/dist/chunk-5M6Z7ZFT.cjs +0 -83
  83. package/dist/chunk-6N6S6WTQ.cjs +0 -423
  84. package/dist/chunk-7YVEHJVM.cjs +0 -575
  85. package/dist/chunk-J5CGNZDM.cjs +0 -190
  86. package/dist/chunk-KQWNFKT2.js +0 -423
  87. package/dist/chunk-LXP73HJC.cjs +0 -4532
  88. package/dist/chunk-R6EBIR3T.cjs +0 -14
  89. package/dist/chunk-S4S2WXGC.js +0 -14
  90. package/dist/chunk-UMPUYLLZ.js +0 -4532
  91. package/dist/chunk-X5MKMFMX.js +0 -83
  92. package/dist/cli/index.cjs +0 -324
  93. package/dist/cli/index.d.cts +0 -22
  94. package/dist/cli/index.d.ts +0 -22
  95. package/dist/esbuild.cjs +0 -15
  96. package/dist/esbuild.d.cts +0 -11
  97. package/dist/esbuild.d.ts +0 -11
  98. package/dist/esbuild.js +0 -13
  99. package/dist/next/adapter.cjs +0 -31
  100. package/dist/next/adapter.js +0 -31
  101. package/dist/next/index.cjs +0 -18
  102. package/dist/next/index.d.cts +0 -42
  103. package/dist/next/index.d.ts +0 -42
  104. package/dist/next/index.js +0 -18
  105. package/dist/rollup.cjs +0 -15
  106. package/dist/rollup.d.cts +0 -11
  107. package/dist/rollup.d.ts +0 -11
  108. package/dist/rollup.js +0 -13
  109. package/dist/runtime/index.cjs +0 -17
  110. package/dist/runtime/index.d.cts +0 -36
  111. package/dist/runtime/index.d.ts +0 -36
  112. package/dist/runtime/index.js +0 -17
  113. package/dist/vite.cjs +0 -15
  114. package/dist/vite.d.cts +0 -11
  115. package/dist/vite.d.ts +0 -11
  116. package/dist/vite.js +0 -13
  117. package/dist/webpack.cjs +0 -15
  118. package/dist/webpack.d.cts +0 -11
  119. package/dist/webpack.d.ts +0 -11
  120. package/dist/webpack.js +0 -13
@@ -1,20 +1,26 @@
1
1
  import {
2
- protectProject
3
- } from "./chunk-5LCMI2TL.js";
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-KQWNFKT2.js";
10
+ } from "./chunk-4FNZNIBW.js";
7
11
  import {
12
+ UnpeekError,
8
13
  __dirname,
9
14
  __require
10
- } from "./chunk-OOXSZTRV.js";
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
- if (upstreamPath) {
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
- process.env.UNPEEK_NEXT_OPTIONS = JSON.stringify(options);
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 (async (...args) => {
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
  };