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
package/dist/index.js CHANGED
@@ -1,26 +1,454 @@
1
1
  import {
2
- initProject
3
- } from "./chunk-27HR647Q.js";
4
- import {
2
+ isNext16OrAbove,
5
3
  protectProject
6
- } from "./chunk-5LCMI2TL.js";
4
+ } from "./chunk-HHC7BUCK.js";
7
5
  import {
8
6
  defineConfig,
9
7
  loadUnpeekConfig
10
- } from "./chunk-GZB7PFLY.js";
8
+ } from "./chunk-W77DAC3H.js";
9
+ import {
10
+ PRESETS
11
+ } from "./chunk-EN6QVR6P.js";
12
+ import {
13
+ SOURCE_MAP_COMMENT_REGEX,
14
+ detectTargetFramework,
15
+ extractDebugId,
16
+ findMonorepoRoots,
17
+ hasNextServerSegment,
18
+ safeDecodeURIComponent,
19
+ scanClientBundles,
20
+ symbolicateStackTrace
21
+ } from "./chunk-ADKRENAP.js";
11
22
  import {
12
23
  transformJavaScript
13
- } from "./chunk-UMPUYLLZ.js";
14
- import "./chunk-KQWNFKT2.js";
24
+ } from "./chunk-4FNZNIBW.js";
15
25
  import {
16
- UnpeekError
17
- } from "./chunk-S4S2WXGC.js";
18
- import "./chunk-OOXSZTRV.js";
26
+ UnpeekError,
27
+ isUnpeekError
28
+ } from "./chunk-LA6J3BT3.js";
29
+
30
+ // src/core/init.ts
31
+ import fs from "fs";
32
+ import path from "path";
33
+ function isPlainObject(val) {
34
+ return typeof val === "object" && val !== null && !Array.isArray(val);
35
+ }
36
+ function detectIndentation(rawJson) {
37
+ const match = rawJson.match(/^[ \t]+(?=["{\[])/m);
38
+ if (!match) return 2;
39
+ const indent = match[0];
40
+ if (indent.includes(" ")) return " ";
41
+ return indent.length;
42
+ }
43
+ var NEXT_CONFIG_FILES = ["next.config.ts", "next.config.mjs", "next.config.js", "next.config.cjs"];
44
+ function wireNextConfig(rootDir, dryRun) {
45
+ let targetFile;
46
+ for (const f of NEXT_CONFIG_FILES) {
47
+ if (fs.existsSync(path.join(rootDir, f))) {
48
+ targetFile = f;
49
+ break;
50
+ }
51
+ }
52
+ if (!targetFile) {
53
+ const defaultMjs = `import { withUnpeek } from 'unpeek/next';
54
+
55
+ /** @type {import('next').NextConfig} */
56
+ const nextConfig = {};
57
+
58
+ export default withUnpeek(nextConfig);
59
+ `;
60
+ if (!dryRun) {
61
+ fs.writeFileSync(path.join(rootDir, "next.config.mjs"), defaultMjs, "utf8");
62
+ }
63
+ return { updated: true, filename: "next.config.mjs" };
64
+ }
65
+ const filePath = path.join(rootDir, targetFile);
66
+ const content = fs.readFileSync(filePath, "utf8");
67
+ if (content.includes("withUnpeek")) {
68
+ return { updated: false, filename: targetFile };
69
+ }
70
+ const isCjs = targetFile.endsWith(".cjs") || targetFile.endsWith(".js") && !content.includes("import ") && !content.includes("export ");
71
+ let modified = content;
72
+ if (isCjs) {
73
+ const importStmt = `const { withUnpeek } = require('unpeek/next');
74
+ `;
75
+ modified = `${importStmt}${modified}`;
76
+ if (/module\.exports\s*=\s*([a-zA-Z0-9_$]+)\s*;?/.test(modified)) {
77
+ modified = modified.replace(/module\.exports\s*=\s*([a-zA-Z0-9_$]+)\s*;?/, "module.exports = withUnpeek($1);");
78
+ } else if (/module\.exports\s*=\s*/.test(modified)) {
79
+ modified = modified.replace(/module\.exports\s*=\s*([\s\S]+?);?\s*$/, "module.exports = withUnpeek($1);");
80
+ }
81
+ } else {
82
+ const importStmt = `import { withUnpeek } from 'unpeek/next';
83
+ `;
84
+ modified = `${importStmt}${modified}`;
85
+ if (/export\s+default\s+([a-zA-Z0-9_$]+)\s*;?/.test(modified)) {
86
+ modified = modified.replace(/export\s+default\s+([a-zA-Z0-9_$]+)\s*;?/, "export default withUnpeek($1);");
87
+ } else if (/export\s+default\s+/.test(modified)) {
88
+ modified = modified.replace(/export\s+default\s+([\s\S]+?);?\s*$/, "export default withUnpeek($1);");
89
+ }
90
+ }
91
+ if (!dryRun && modified !== content) {
92
+ fs.writeFileSync(filePath, modified, "utf8");
93
+ }
94
+ return { updated: modified !== content, filename: targetFile };
95
+ }
96
+ function initProject(cwd = process.cwd(), options = {}) {
97
+ const dryRun = typeof options === "boolean" ? options : options.dryRun ?? false;
98
+ const rootDir = path.resolve(cwd);
99
+ const { framework } = detectTargetFramework(rootDir);
100
+ const pkgPath = path.join(rootDir, "package.json");
101
+ let updatedPackageJson = false;
102
+ let updatedGitignore = false;
103
+ let updatedNextConfig = false;
104
+ let isNext16 = false;
105
+ let nextVersion;
106
+ let pkg = {};
107
+ let rawPkgContent = "";
108
+ if (fs.existsSync(pkgPath)) {
109
+ rawPkgContent = fs.readFileSync(pkgPath, "utf8");
110
+ let parsed;
111
+ try {
112
+ parsed = JSON.parse(rawPkgContent);
113
+ } catch (err) {
114
+ throw new UnpeekError(
115
+ "ERR_INIT_INVALID_PACKAGE_JSON",
116
+ `Invalid JSON in package.json at "${pkgPath}": ${err instanceof Error ? err.message : String(err)}`,
117
+ { cause: err }
118
+ );
119
+ }
120
+ if (!isPlainObject(parsed)) {
121
+ throw new UnpeekError(
122
+ "ERR_INIT_INVALID_PACKAGE_JSON",
123
+ `package.json at "${pkgPath}" must contain a JSON object.`
124
+ );
125
+ }
126
+ pkg = parsed;
127
+ const deps = isPlainObject(pkg.dependencies) ? pkg.dependencies : void 0;
128
+ const devDeps = isPlainObject(pkg.devDependencies) ? pkg.devDependencies : void 0;
129
+ const rawNext = deps?.next ?? devDeps?.next;
130
+ nextVersion = typeof rawNext === "string" ? rawNext : void 0;
131
+ }
132
+ if (framework === "nextjs" && isNext16OrAbove(nextVersion)) {
133
+ isNext16 = true;
134
+ const configRes = wireNextConfig(rootDir, dryRun);
135
+ updatedNextConfig = configRes.updated;
136
+ } else if (fs.existsSync(pkgPath)) {
137
+ const indent = detectIndentation(rawPkgContent);
138
+ const trailingNewline = rawPkgContent.endsWith("\r\n") ? "\r\n" : rawPkgContent.endsWith("\n") ? "\n" : "";
139
+ const scripts = isPlainObject(pkg.scripts) ? { ...pkg.scripts } : {};
140
+ pkg.scripts = scripts;
141
+ const existingPostbuild = typeof scripts.postbuild === "string" ? scripts.postbuild : void 0;
142
+ if (!existingPostbuild) {
143
+ scripts.postbuild = "unpeek protect";
144
+ updatedPackageJson = true;
145
+ } else if (!existingPostbuild.includes("unpeek protect")) {
146
+ scripts.postbuild = `${existingPostbuild.trim()} && unpeek protect`;
147
+ updatedPackageJson = true;
148
+ }
149
+ if (updatedPackageJson && !dryRun) {
150
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, indent)}${trailingNewline}`, "utf8");
151
+ }
152
+ }
153
+ const gitignorePath = path.join(rootDir, ".gitignore");
154
+ if (fs.existsSync(gitignorePath)) {
155
+ const current = fs.readFileSync(gitignorePath, "utf8");
156
+ const lines = current.split(/\r?\n/).map((line) => line.trim());
157
+ if (!lines.includes(".unpeek-maps/") && !lines.includes(".unpeek-maps")) {
158
+ const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
159
+ if (!dryRun) {
160
+ fs.writeFileSync(gitignorePath, `${current}${prefix}.unpeek-maps/
161
+ `, "utf8");
162
+ }
163
+ updatedGitignore = true;
164
+ }
165
+ } else {
166
+ if (!dryRun) {
167
+ fs.writeFileSync(gitignorePath, ".unpeek-maps/\n", "utf8");
168
+ }
169
+ updatedGitignore = true;
170
+ }
171
+ let message;
172
+ if (isNext16) {
173
+ if (dryRun) {
174
+ message = `[dry-run] Detected Next.js 16.2+ (${nextVersion}). Would configure withUnpeek adapter in next.config and .unpeek-maps/ vault.`;
175
+ } else if (updatedNextConfig || updatedGitignore) {
176
+ message = `Detected Next.js 16.2+ (${nextVersion}). Initialized unpeek: configured withUnpeek adapter in next.config and .unpeek-maps/ vault.`;
177
+ } else {
178
+ message = `Detected Next.js 16.2+ (${nextVersion}). unpeek is already initialized in this project.`;
179
+ }
180
+ } else {
181
+ if (dryRun) {
182
+ message = `[dry-run] Detected framework: ${framework}. Would configure postbuild hook and .unpeek-maps/ vault.`;
183
+ } else if (updatedPackageJson || updatedGitignore) {
184
+ message = `Detected framework: ${framework}. Initialized unpeek: configured postbuild hook and .unpeek-maps/ vault.`;
185
+ } else {
186
+ message = `Detected framework: ${framework}. unpeek is already initialized in this project.`;
187
+ }
188
+ }
189
+ return {
190
+ updatedPackageJson,
191
+ updatedGitignore,
192
+ updatedNextConfig,
193
+ framework,
194
+ isNext162Plus: isNext16,
195
+ message
196
+ };
197
+ }
198
+
199
+ // src/core/check.ts
200
+ import fs2 from "fs";
201
+ import path2 from "path";
202
+ import * as acorn from "acorn";
203
+ import { simple as walkSimple } from "acorn-walk";
204
+ function walkPublicMaps(currentDir, rootOutDir, found) {
205
+ if (hasNextServerSegment(currentDir, rootOutDir)) {
206
+ return;
207
+ }
208
+ let entries;
209
+ try {
210
+ entries = fs2.readdirSync(currentDir, { withFileTypes: true });
211
+ } catch {
212
+ return;
213
+ }
214
+ for (const entry of entries) {
215
+ const fullPath = path2.join(currentDir, entry.name);
216
+ if (entry.isDirectory()) {
217
+ if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
218
+ continue;
219
+ }
220
+ if (hasNextServerSegment(fullPath, rootOutDir)) {
221
+ continue;
222
+ }
223
+ walkPublicMaps(fullPath, rootOutDir, found);
224
+ } else if (entry.isFile() && entry.name.endsWith(".map")) {
225
+ found.push(fullPath);
226
+ }
227
+ }
228
+ }
229
+ function hasIgnoreEntry(filePath, ignoreEntry) {
230
+ try {
231
+ const content = fs2.readFileSync(filePath, "utf8");
232
+ const normalizedEntry = ignoreEntry.endsWith("/") ? ignoreEntry : `${ignoreEntry}/`;
233
+ const bareEntry = normalizedEntry.slice(0, -1);
234
+ const lines = content.split(/\r?\n/).map((line) => line.trim());
235
+ return lines.includes(normalizedEntry) || lines.includes(bareEntry) || lines.includes(".unpeek-maps") || lines.includes(".unpeek-maps/");
236
+ } catch {
237
+ return false;
238
+ }
239
+ }
240
+ function findEvalOrFunctionCalls(code) {
241
+ const hits = [];
242
+ let ast;
243
+ try {
244
+ ast = acorn.parse(code, {
245
+ ecmaVersion: "latest",
246
+ sourceType: "module",
247
+ allowReturnOutsideFunction: true
248
+ });
249
+ } catch {
250
+ try {
251
+ ast = acorn.parse(code, {
252
+ ecmaVersion: "latest",
253
+ sourceType: "script",
254
+ allowReturnOutsideFunction: true
255
+ });
256
+ } catch {
257
+ return hits;
258
+ }
259
+ }
260
+ walkSimple(ast, {
261
+ CallExpression(node) {
262
+ if (node.callee.type === "Identifier") {
263
+ if (node.callee.name === "eval") {
264
+ hits.push("eval(...)");
265
+ } else if (node.callee.name === "Function") {
266
+ hits.push("Function(...)");
267
+ }
268
+ }
269
+ },
270
+ NewExpression(node) {
271
+ if (node.callee.type === "Identifier" && node.callee.name === "Function") {
272
+ hits.push("new Function(...)");
273
+ }
274
+ }
275
+ });
276
+ return Array.from(new Set(hits));
277
+ }
278
+ async function checkProject(options = {}) {
279
+ const cwd = path2.resolve(options.cwd ?? process.cwd());
280
+ const config = await loadUnpeekConfig(cwd);
281
+ const { outDir } = detectTargetFramework(cwd, options.outDir, config);
282
+ const resolvedOutDir = path2.resolve(outDir);
283
+ const privateMapsDir = options.privateMapsDir ?? config.sourcemaps?.vaultDir ?? ".unpeek-maps";
284
+ const maxGzipDelta = options.maxGzipDelta ?? 15;
285
+ const requireZeroEval = Boolean(options.requireZeroEval || options.strictCsp);
286
+ const violations = [];
287
+ const warnings = [];
288
+ const publicMaps = [];
289
+ if (fs2.existsSync(resolvedOutDir)) {
290
+ walkPublicMaps(resolvedOutDir, resolvedOutDir, publicMaps);
291
+ }
292
+ for (const mapFile of publicMaps) {
293
+ const rel = path2.relative(resolvedOutDir, mapFile).replace(/\\/g, "/");
294
+ violations.push({
295
+ rule: "public-map",
296
+ severity: "error",
297
+ message: `Public source map exposed in client output: "${rel}".`,
298
+ file: rel
299
+ });
300
+ }
301
+ const vaultDir = path2.resolve(cwd, privateMapsDir);
302
+ const clientFiles = scanClientBundles(resolvedOutDir, config);
303
+ for (const filePath of clientFiles) {
304
+ const rel = path2.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
305
+ let content;
306
+ try {
307
+ content = fs2.readFileSync(filePath, "utf8");
308
+ } catch {
309
+ continue;
310
+ }
311
+ SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
312
+ if (SOURCE_MAP_COMMENT_REGEX.test(content)) {
313
+ violations.push({
314
+ rule: "sourcemap-comment",
315
+ severity: "error",
316
+ message: `Residual sourceMappingURL comment found in "${rel}".`,
317
+ file: rel
318
+ });
319
+ }
320
+ const jsDebugId = extractDebugId(content);
321
+ const decodedRel = safeDecodeURIComponent(rel);
322
+ const mapCandidates = [
323
+ path2.join(vaultDir, `${rel}.map`),
324
+ ...decodedRel !== rel ? [path2.join(vaultDir, `${decodedRel}.map`)] : []
325
+ ];
326
+ const vaultedMapPath = mapCandidates.find((p) => fs2.existsSync(p));
327
+ if (vaultedMapPath) {
328
+ try {
329
+ const mapJson = JSON.parse(fs2.readFileSync(vaultedMapPath, "utf8"));
330
+ const rawMapDebugId = typeof mapJson.debugId === "string" ? mapJson.debugId : typeof mapJson.debug_id === "string" ? mapJson.debug_id : void 0;
331
+ if (jsDebugId && rawMapDebugId && jsDebugId !== rawMapDebugId) {
332
+ violations.push({
333
+ rule: "debugid-mismatch",
334
+ severity: "error",
335
+ message: `debugId mismatch for "${rel}": JS has "${jsDebugId}" while vaulted map has "${rawMapDebugId}".`,
336
+ file: rel
337
+ });
338
+ } else if (jsDebugId && !rawMapDebugId) {
339
+ warnings.push({
340
+ rule: "debugid-mismatch",
341
+ severity: "warning",
342
+ message: `JS bundle "${rel}" has debugId "${jsDebugId}" but vaulted source map is missing debugId.`,
343
+ file: rel
344
+ });
345
+ } else if (!jsDebugId && rawMapDebugId) {
346
+ warnings.push({
347
+ rule: "debugid-mismatch",
348
+ severity: "warning",
349
+ message: `Vaulted source map for "${rel}" has debugId "${rawMapDebugId}" but JS bundle is missing //# debugId=.`,
350
+ file: rel
351
+ });
352
+ }
353
+ } catch {
354
+ }
355
+ } else if (jsDebugId) {
356
+ warnings.push({
357
+ rule: "debugid-mismatch",
358
+ severity: "warning",
359
+ message: `JS bundle "${rel}" has debugId "${jsDebugId}" but no vaulted source map found at "${rel}.map".`,
360
+ file: rel
361
+ });
362
+ }
363
+ const evalHits = findEvalOrFunctionCalls(content);
364
+ if (evalHits.length > 0) {
365
+ const violation = {
366
+ rule: "eval-csp",
367
+ severity: requireZeroEval ? "error" : "warning",
368
+ message: `Dynamic code evaluation (${evalHits.join(", ")}) detected in "${rel}".`,
369
+ file: rel
370
+ };
371
+ if (requireZeroEval) {
372
+ violations.push(violation);
373
+ } else {
374
+ warnings.push(violation);
375
+ }
376
+ }
377
+ }
378
+ const relVault = path2.relative(cwd, vaultDir).replace(/\\/g, "/");
379
+ const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
380
+ const roots = findMonorepoRoots(cwd);
381
+ let foundGitignore = false;
382
+ let gitignoreProtected = false;
383
+ let foundDockerignore = false;
384
+ let dockerignoreProtected = false;
385
+ for (const root of roots) {
386
+ const gitignorePath = path2.join(root, ".gitignore");
387
+ if (fs2.existsSync(gitignorePath)) {
388
+ foundGitignore = true;
389
+ if (hasIgnoreEntry(gitignorePath, ignoreEntry)) {
390
+ gitignoreProtected = true;
391
+ }
392
+ }
393
+ const dockerignorePath = path2.join(root, ".dockerignore");
394
+ if (fs2.existsSync(dockerignorePath)) {
395
+ foundDockerignore = true;
396
+ if (hasIgnoreEntry(dockerignorePath, ignoreEntry)) {
397
+ dockerignoreProtected = true;
398
+ }
399
+ }
400
+ }
401
+ if (!foundGitignore || !gitignoreProtected) {
402
+ violations.push({
403
+ rule: "ignore-missing",
404
+ severity: "error",
405
+ message: `.gitignore is missing "${ignoreEntry}". Private source maps may be committed to Git.`
406
+ });
407
+ }
408
+ if (!foundDockerignore) {
409
+ warnings.push({
410
+ rule: "ignore-missing",
411
+ severity: "warning",
412
+ message: `.dockerignore not found. If using Docker, ensure "${ignoreEntry}" is excluded.`
413
+ });
414
+ } else if (!dockerignoreProtected) {
415
+ violations.push({
416
+ rule: "ignore-missing",
417
+ severity: "error",
418
+ message: `.dockerignore is missing "${ignoreEntry}". Private source maps may leak into Docker images.`
419
+ });
420
+ }
421
+ const manifestPath = path2.join(vaultDir, "manifest.json");
422
+ if (fs2.existsSync(manifestPath)) {
423
+ try {
424
+ const manifest = JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
425
+ if (typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
426
+ violations.push({
427
+ rule: "gzip-budget",
428
+ severity: "error",
429
+ message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
430
+ });
431
+ }
432
+ } catch {
433
+ }
434
+ }
435
+ return {
436
+ passed: violations.length === 0,
437
+ outDir: resolvedOutDir,
438
+ checkedFiles: clientFiles.length,
439
+ violations,
440
+ warnings
441
+ };
442
+ }
19
443
  export {
444
+ PRESETS,
20
445
  UnpeekError,
446
+ checkProject,
21
447
  defineConfig,
22
448
  initProject,
449
+ isUnpeekError,
23
450
  loadUnpeekConfig,
24
451
  protectProject,
452
+ symbolicateStackTrace,
25
453
  transformJavaScript
26
454
  };
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkVG4Y26ZNcjs = require('../chunk-VG4Y26ZN.cjs');
10
+ require('../chunk-3LWXEJU6.cjs');
11
+ require('../chunk-KLYFNMKS.cjs');
12
+ require('../chunk-L6BOM5VS.cjs');
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ exports.default = _chunkVG4Y26ZNcjs.unplugin_default; exports.esbuildPlugin = _chunkVG4Y26ZNcjs.esbuildPlugin; exports.rollupPlugin = _chunkVG4Y26ZNcjs.rollupPlugin; exports.rspackPlugin = _chunkVG4Y26ZNcjs.rspackPlugin; exports.unpeekPlugin = _chunkVG4Y26ZNcjs.unpeekPlugin; exports.vitePlugin = _chunkVG4Y26ZNcjs.vitePlugin; exports.webpackPlugin = _chunkVG4Y26ZNcjs.webpackPlugin;
@@ -0,0 +1,17 @@
1
+ import * as esbuild from 'esbuild';
2
+ import * as rollup from 'rollup';
3
+ import * as webpack from 'webpack';
4
+ import * as vite from 'vite';
5
+ import * as unplugin from 'unplugin';
6
+ import { UnpeekPluginOptions } from '../browser.cjs';
7
+
8
+ declare const unpeekPlugin: unplugin.UnpluginInstance<UnpeekPluginOptions | undefined, boolean>;
9
+ declare const vitePlugin: (options?: UnpeekPluginOptions | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
10
+ declare const webpackPlugin: (options?: UnpeekPluginOptions | undefined) => webpack.WebpackPluginInstance;
11
+ declare const rollupPlugin: (options?: UnpeekPluginOptions | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
12
+ declare const esbuildPlugin: (options?: UnpeekPluginOptions | undefined) => esbuild.Plugin;
13
+ declare const rspackPlugin: (options?: UnpeekPluginOptions | undefined) => unplugin.RspackPluginInstance;
14
+
15
+ // @ts-ignore
16
+ export = unpeekPlugin;
17
+ export { esbuildPlugin, rollupPlugin, rspackPlugin, unpeekPlugin, vitePlugin, webpackPlugin };
@@ -0,0 +1,15 @@
1
+ import * as esbuild from 'esbuild';
2
+ import * as rollup from 'rollup';
3
+ import * as webpack from 'webpack';
4
+ import * as vite from 'vite';
5
+ import * as unplugin from 'unplugin';
6
+ import { UnpeekPluginOptions } from '../browser.js';
7
+
8
+ declare const unpeekPlugin: unplugin.UnpluginInstance<UnpeekPluginOptions | undefined, boolean>;
9
+ declare const vitePlugin: (options?: UnpeekPluginOptions | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
10
+ declare const webpackPlugin: (options?: UnpeekPluginOptions | undefined) => webpack.WebpackPluginInstance;
11
+ declare const rollupPlugin: (options?: UnpeekPluginOptions | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
12
+ declare const esbuildPlugin: (options?: UnpeekPluginOptions | undefined) => esbuild.Plugin;
13
+ declare const rspackPlugin: (options?: UnpeekPluginOptions | undefined) => unplugin.RspackPluginInstance;
14
+
15
+ export { unpeekPlugin as default, esbuildPlugin, rollupPlugin, rspackPlugin, unpeekPlugin, vitePlugin, webpackPlugin };
@@ -1,19 +1,20 @@
1
1
  import {
2
2
  esbuildPlugin,
3
3
  rollupPlugin,
4
+ rspackPlugin,
4
5
  unpeekPlugin,
5
6
  unplugin_default,
6
7
  vitePlugin,
7
8
  webpackPlugin
8
- } from "../chunk-X5MKMFMX.js";
9
- import "../chunk-UMPUYLLZ.js";
10
- import "../chunk-KQWNFKT2.js";
11
- import "../chunk-S4S2WXGC.js";
12
- import "../chunk-OOXSZTRV.js";
9
+ } from "../chunk-YCRMTXOE.js";
10
+ import "../chunk-ADKRENAP.js";
11
+ import "../chunk-4FNZNIBW.js";
12
+ import "../chunk-LA6J3BT3.js";
13
13
  export {
14
14
  unplugin_default as default,
15
15
  esbuildPlugin,
16
16
  rollupPlugin,
17
+ rspackPlugin,
17
18
  unpeekPlugin,
18
19
  vitePlugin,
19
20
  webpackPlugin
@@ -0,0 +1,112 @@
1
+ import { f as UnpeekFramework, h as UnpeekProfile, B as BaseProtectionOptions } from './config-Y6JwVGwX.js';
2
+
3
+ interface ProtectOptions extends BaseProtectionOptions {
4
+ /** Target project root directory (defaults to process.cwd()) */
5
+ cwd?: string;
6
+ /** Explicit client output directory override */
7
+ outDir?: string;
8
+ /** Move .map files to .unpeek-maps/ instead of permanently deleting (default: true) */
9
+ keepPrivateMaps?: boolean;
10
+ /** Private directory to store extracted source maps (default: '.unpeek-maps') */
11
+ privateMapsDir?: string;
12
+ /** Compute summary and Gzip delta in memory without writing files */
13
+ dryRun?: boolean;
14
+ /** Fail with ERR_BUDGET_EXCEEDED if gzipDeltaPercent exceeds this percentage */
15
+ maxGzipDelta?: number;
16
+ /** Scrub local filesystem paths and residual dev metadata (CWE-540) */
17
+ scrubPaths?: boolean;
18
+ }
19
+ type UnpeekDiagnosticSeverity = 'info' | 'warning';
20
+ interface UnpeekDiagnostic {
21
+ code: 'DOCKERIGNORE_MISSING' | 'PARSE_FALLBACK' | 'ALREADY_PROTECTED' | 'EMPTY_INPUT';
22
+ severity: UnpeekDiagnosticSeverity;
23
+ message: string;
24
+ file?: string;
25
+ }
26
+ interface SourceMapVaultResult {
27
+ movedMapsCount: number;
28
+ strippedFilesCount: number;
29
+ vaultDir: string;
30
+ movedFiles: string[];
31
+ dockerIgnoreMissing?: boolean;
32
+ }
33
+ interface ProtectSummary {
34
+ framework: UnpeekFramework;
35
+ outDir: string;
36
+ processedFiles: number;
37
+ movedSourceMaps: number;
38
+ originalBytes: number;
39
+ protectedBytes: number;
40
+ originalGzipBytes: number;
41
+ protectedGzipBytes: number;
42
+ gzipDeltaPercent: number;
43
+ totalHotFunctionsSkipped: number;
44
+ totalColdFunctionsProtected: number;
45
+ totalEncryptedStrings: number;
46
+ totalMangledSymbols: number;
47
+ elapsedMs: number;
48
+ seed?: number;
49
+ tier?: 'Tier 1' | 'Tier 2' | 'Tier 3';
50
+ aggressive?: boolean;
51
+ dockerIgnoreMissing?: boolean;
52
+ dryRun?: boolean;
53
+ profile?: UnpeekProfile;
54
+ budgetExceeded?: boolean;
55
+ debugIdsPreserved?: number;
56
+ diagnostics?: readonly UnpeekDiagnostic[];
57
+ }
58
+ interface InitOptions {
59
+ dryRun?: boolean;
60
+ }
61
+ interface InitResult {
62
+ updatedPackageJson: boolean;
63
+ updatedGitignore: boolean;
64
+ updatedNextConfig?: boolean;
65
+ framework?: UnpeekFramework;
66
+ isNext162Plus?: boolean;
67
+ message: string;
68
+ }
69
+ interface CheckOptions {
70
+ cwd?: string;
71
+ outDir?: string;
72
+ privateMapsDir?: string;
73
+ maxGzipDelta?: number;
74
+ requireZeroEval?: boolean;
75
+ strictCsp?: boolean;
76
+ }
77
+ interface CheckViolation {
78
+ rule: 'public-map' | 'sourcemap-comment' | 'ignore-missing' | 'gzip-budget' | 'eval-csp' | 'debugid-mismatch';
79
+ severity: 'error' | 'warning';
80
+ message: string;
81
+ file?: string;
82
+ }
83
+ interface CheckResult {
84
+ passed: boolean;
85
+ outDir: string;
86
+ checkedFiles: number;
87
+ violations: CheckViolation[];
88
+ warnings: CheckViolation[];
89
+ }
90
+ interface SymbolicateOptions {
91
+ stackTrace: string;
92
+ mapsDir?: string;
93
+ cwd?: string;
94
+ }
95
+ interface SymbolicateFrame {
96
+ raw: string;
97
+ file?: string;
98
+ line?: number;
99
+ column?: number;
100
+ originalSource?: string;
101
+ originalLine?: number;
102
+ originalColumn?: number;
103
+ originalName?: string;
104
+ resolved: boolean;
105
+ }
106
+ interface SymbolicateResult {
107
+ stackTrace: string;
108
+ frames: SymbolicateFrame[];
109
+ warnings: string[];
110
+ }
111
+
112
+ export type { CheckOptions as C, InitOptions as I, ProtectSummary as P, SymbolicateOptions as S, UnpeekDiagnostic as U, ProtectOptions as a, InitResult as b, CheckResult as c, SymbolicateResult as d, CheckViolation as e, SourceMapVaultResult as f, SymbolicateFrame as g, UnpeekDiagnosticSeverity as h };