unpeek 2.0.0 → 3.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 (103) hide show
  1. package/README.md +30 -8
  2. package/README.tr.md +30 -8
  3. package/dist/adapters/esbuild.cjs +13 -0
  4. package/dist/{esbuild.d.cts → adapters/esbuild.d.cts} +2 -2
  5. package/dist/{esbuild.d.ts → adapters/esbuild.d.ts} +2 -2
  6. package/dist/adapters/esbuild.js +11 -0
  7. package/dist/adapters/next/adapter.cjs +42 -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 +42 -0
  11. package/dist/adapters/next/index.cjs +15 -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 +15 -0
  15. package/dist/adapters/rollup.cjs +13 -0
  16. package/dist/{rollup.d.cts → adapters/rollup.d.cts} +2 -2
  17. package/dist/{rollup.d.ts → adapters/rollup.d.ts} +2 -2
  18. package/dist/adapters/rollup.js +11 -0
  19. package/dist/adapters/rspack.cjs +12 -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 +12 -0
  23. package/dist/adapters/vite.cjs +13 -0
  24. package/dist/{vite.d.cts → adapters/vite.d.cts} +2 -2
  25. package/dist/{vite.d.ts → adapters/vite.d.ts} +2 -2
  26. package/dist/adapters/vite.js +11 -0
  27. package/dist/adapters/webpack.cjs +13 -0
  28. package/dist/{webpack.d.cts → adapters/webpack.d.cts} +2 -2
  29. package/dist/{webpack.d.ts → adapters/webpack.d.ts} +2 -2
  30. package/dist/adapters/webpack.js +11 -0
  31. package/dist/browser.cjs +8 -5
  32. package/dist/browser.d.cts +41 -3
  33. package/dist/browser.d.ts +41 -3
  34. package/dist/browser.js +10 -7
  35. package/dist/{chunk-GAVI2C44.cjs → chunk-6TDCSIRZ.cjs} +76 -47
  36. package/dist/{chunk-5LCMI2TL.js → chunk-APWMNVAZ.js} +221 -32
  37. package/dist/{chunk-5QD6FZPB.js → chunk-BPRSCRUZ.js} +71 -42
  38. package/dist/{chunk-X5MKMFMX.js → chunk-DUK2SECY.js} +7 -7
  39. package/dist/chunk-FCF2EGPM.js +80 -0
  40. package/dist/{chunk-7YVEHJVM.cjs → chunk-I6GXEHFR.cjs} +241 -52
  41. package/dist/{chunk-LXP73HJC.cjs → chunk-IAD5DV3D.cjs} +1048 -213
  42. package/dist/chunk-IEBVL5BT.cjs +80 -0
  43. package/dist/{chunk-GZB7PFLY.js → chunk-IICVBTR2.js} +25 -62
  44. package/dist/{chunk-UMPUYLLZ.js → chunk-IZIWDJRF.js} +936 -101
  45. package/dist/chunk-L6BOM5VS.cjs +40 -0
  46. package/dist/{chunk-OOXSZTRV.js → chunk-LA6J3BT3.js} +26 -1
  47. package/dist/{chunk-24K5NDXH.cjs → chunk-ONM2CSTU.cjs} +45 -82
  48. package/dist/{chunk-5M6Z7ZFT.cjs → chunk-RXUY3MPH.cjs} +10 -10
  49. package/dist/cli/index.js +7309 -32
  50. package/dist/{types-BBSRUEab.d.cts → config-CfXY_iDD.d.cts} +44 -86
  51. package/dist/{types-BBSRUEab.d.ts → config-CfXY_iDD.d.ts} +44 -86
  52. package/dist/config.cjs +4 -16
  53. package/dist/config.d.cts +1 -12
  54. package/dist/config.d.ts +1 -12
  55. package/dist/config.js +5 -17
  56. package/dist/index-CjRTNPlj.d.cts +46 -0
  57. package/dist/index-Cm1IloVm.d.ts +46 -0
  58. package/dist/index.cjs +636 -9
  59. package/dist/index.d.cts +9 -17
  60. package/dist/index.d.ts +9 -17
  61. package/dist/index.js +638 -11
  62. package/dist/plugins/unplugin.cjs +20 -0
  63. package/dist/plugins/unplugin.d.cts +17 -0
  64. package/dist/plugins/unplugin.d.ts +15 -0
  65. package/dist/{bundler → plugins}/unplugin.js +5 -5
  66. package/dist/types-DYQIzGf6.d.cts +112 -0
  67. package/dist/types-ZHAFdOd3.d.ts +112 -0
  68. package/package.json +48 -52
  69. package/dist/ast/index.cjs +0 -17
  70. package/dist/ast/index.d.cts +0 -18
  71. package/dist/ast/index.d.ts +0 -18
  72. package/dist/ast/index.js +0 -17
  73. package/dist/bundler/unplugin.cjs +0 -20
  74. package/dist/bundler/unplugin.d.cts +0 -16
  75. package/dist/bundler/unplugin.d.ts +0 -14
  76. package/dist/chunk-27HR647Q.js +0 -190
  77. package/dist/chunk-4TDLLEEU.cjs +0 -15
  78. package/dist/chunk-6N6S6WTQ.cjs +0 -423
  79. package/dist/chunk-J5CGNZDM.cjs +0 -190
  80. package/dist/chunk-KQWNFKT2.js +0 -423
  81. package/dist/chunk-R6EBIR3T.cjs +0 -14
  82. package/dist/chunk-S4S2WXGC.js +0 -14
  83. package/dist/cli/index.cjs +0 -324
  84. package/dist/cli/index.d.cts +0 -22
  85. package/dist/cli/index.d.ts +0 -22
  86. package/dist/esbuild.cjs +0 -15
  87. package/dist/esbuild.js +0 -13
  88. package/dist/next/adapter.cjs +0 -31
  89. package/dist/next/adapter.js +0 -31
  90. package/dist/next/index.cjs +0 -18
  91. package/dist/next/index.d.cts +0 -42
  92. package/dist/next/index.d.ts +0 -42
  93. package/dist/next/index.js +0 -18
  94. package/dist/rollup.cjs +0 -15
  95. package/dist/rollup.js +0 -13
  96. package/dist/runtime/index.cjs +0 -17
  97. package/dist/runtime/index.d.cts +0 -36
  98. package/dist/runtime/index.d.ts +0 -36
  99. package/dist/runtime/index.js +0 -17
  100. package/dist/vite.cjs +0 -15
  101. package/dist/vite.js +0 -13
  102. package/dist/webpack.cjs +0 -15
  103. package/dist/webpack.js +0 -13
@@ -0,0 +1,80 @@
1
+ // src/presets.ts
2
+ var PRESETS = {
3
+ minimal: {
4
+ profile: "minimal",
5
+ target: "browser",
6
+ vault: {
7
+ minStringLength: Number.MAX_SAFE_INTEGER,
8
+ polymorphicDecoys: false
9
+ },
10
+ mangler: {
11
+ minLength: 3
12
+ },
13
+ shield: {
14
+ detectHeadless: false,
15
+ deterrentMode: "passive"
16
+ },
17
+ sourcemaps: {
18
+ keepPrivate: true,
19
+ vaultDir: ".unpeek-maps",
20
+ stripComments: true
21
+ },
22
+ scrubPaths: false
23
+ },
24
+ recommended: {
25
+ profile: "recommended",
26
+ target: "browser",
27
+ vault: {
28
+ minStringLength: 4,
29
+ cssFramework: "tailwind",
30
+ semanticAnchors: {
31
+ excludeUiClasses: true
32
+ },
33
+ polymorphicDecoys: true
34
+ },
35
+ mangler: {
36
+ minLength: 3
37
+ },
38
+ shield: {
39
+ detectHeadless: false,
40
+ deterrentMode: "passive"
41
+ },
42
+ sourcemaps: {
43
+ keepPrivate: true,
44
+ vaultDir: ".unpeek-maps",
45
+ stripComments: true
46
+ },
47
+ scrubPaths: false
48
+ },
49
+ strict: {
50
+ profile: "strict",
51
+ target: "browser",
52
+ vault: {
53
+ minStringLength: 4,
54
+ cssFramework: "tailwind",
55
+ semanticAnchors: {
56
+ excludeUiClasses: true
57
+ },
58
+ polymorphicDecoys: true,
59
+ fragmented: true,
60
+ fragmentCount: 4
61
+ },
62
+ mangler: {
63
+ minLength: 3
64
+ },
65
+ shield: {
66
+ detectHeadless: true,
67
+ deterrentMode: "gradual"
68
+ },
69
+ sourcemaps: {
70
+ keepPrivate: true,
71
+ vaultDir: ".unpeek-maps",
72
+ stripComments: true
73
+ },
74
+ scrubPaths: true
75
+ }
76
+ };
77
+
78
+ export {
79
+ PRESETS
80
+ };
@@ -1,24 +1,78 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunk24K5NDXHcjs = require('./chunk-24K5NDXH.cjs');
3
+ var _chunkONM2CSTUcjs = require('./chunk-ONM2CSTU.cjs');
4
4
 
5
5
 
6
- var _chunkLXP73HJCcjs = require('./chunk-LXP73HJC.cjs');
7
6
 
8
7
 
9
8
 
9
+ var _chunkIAD5DV3Dcjs = require('./chunk-IAD5DV3D.cjs');
10
10
 
11
- var _chunk6N6S6WTQcjs = require('./chunk-6N6S6WTQ.cjs');
12
11
 
12
+ var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
13
13
 
14
- var _chunkR6EBIR3Tcjs = require('./chunk-R6EBIR3T.cjs');
14
+ // src/internal/next.ts
15
+ function isNext16OrAbove(versionStr) {
16
+ if (!versionStr) return false;
17
+ const clean = versionStr.replace(/^[^\d]*/, "");
18
+ const match = clean.match(/^(\d+)\.(\d+)/);
19
+ if (!match) return false;
20
+ const major = parseInt(match[1], 10);
21
+ const minor = parseInt(match[2], 10);
22
+ if (major > 16) return true;
23
+ if (major === 16 && minor >= 2) return true;
24
+ return false;
25
+ }
26
+ function isSerializedRegExp(val) {
27
+ if (typeof val !== "object" || val === null) return false;
28
+ const record = val;
29
+ return record.__unpeekRegExp === true && typeof record.source === "string" && typeof record.flags === "string";
30
+ }
31
+ function serializeNextOptions(options) {
32
+ return JSON.stringify(options, (_key, value) => {
33
+ if (value instanceof RegExp) {
34
+ return {
35
+ __unpeekRegExp: true,
36
+ source: value.source,
37
+ flags: value.flags
38
+ };
39
+ }
40
+ return value;
41
+ });
42
+ }
43
+ function parseNextOptions(raw) {
44
+ return JSON.parse(raw, (_key, value) => {
45
+ if (isSerializedRegExp(value)) {
46
+ try {
47
+ return new RegExp(value.source, value.flags);
48
+ } catch (e2) {
49
+ return void 0;
50
+ }
51
+ }
52
+ return value;
53
+ });
54
+ }
55
+ function readUnpeekNextOptionsFromEnv() {
56
+ const raw = process.env.UNPEEK_NEXT_OPTIONS;
57
+ if (!raw) {
58
+ return void 0;
59
+ }
60
+ try {
61
+ const parsed = parseNextOptions(raw);
62
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
63
+ return parsed;
64
+ }
65
+ } catch (e3) {
66
+ }
67
+ return void 0;
68
+ }
15
69
 
16
70
  // src/core/protect.ts
17
71
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
18
72
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
19
73
  var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib);
20
74
 
21
- // src/bundler/detector.ts
75
+ // src/core/detector.ts
22
76
 
23
77
 
24
78
  var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
@@ -41,7 +95,7 @@ function extractConfigValue(rootDir, filenames, pattern) {
41
95
  if (match && match[1]) {
42
96
  return match[1].trim();
43
97
  }
44
- } catch (e2) {
98
+ } catch (e4) {
45
99
  }
46
100
  }
47
101
  }
@@ -121,7 +175,7 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
121
175
  } else if ("webpack" in allDeps || "react-scripts" in allDeps || "@rspack/core" in allDeps) {
122
176
  framework = "webpack";
123
177
  }
124
- } catch (e3) {
178
+ } catch (e5) {
125
179
  }
126
180
  }
127
181
  }
@@ -215,7 +269,7 @@ function scanClientBundles(outDir, config) {
215
269
  let entries;
216
270
  try {
217
271
  entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
218
- } catch (e4) {
272
+ } catch (e6) {
219
273
  return;
220
274
  }
221
275
  for (const entry of entries) {
@@ -243,10 +297,28 @@ function scanClientBundles(outDir, config) {
243
297
  return results.sort();
244
298
  }
245
299
 
246
- // src/bundler/sourcemap-vault.ts
300
+ // src/core/sourcemap-vault.ts
247
301
 
248
302
 
249
303
  var SOURCE_MAP_COMMENT_REGEX = /(?:^\s*\/\/[#@]\s*sourceMappingURL=.*$|\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/)\s*/gm;
304
+ var DEBUG_ID_COMMENT_REGEX = /(?:\/\/[#@]\s*debugId=([^\s*]+)|\/\*[#@]\s*debugId=([^\s*]+)\s*\*\/)/;
305
+ function extractDebugId(code) {
306
+ const match = code.match(DEBUG_ID_COMMENT_REGEX);
307
+ const id = _nullishCoalesce(_optionalChain([match, 'optionalAccess', _13 => _13[1]]), () => ( _optionalChain([match, 'optionalAccess', _14 => _14[2]])));
308
+ return id ? id.trim() : void 0;
309
+ }
310
+ function stripSourceMapComments(code) {
311
+ const debugId = extractDebugId(code);
312
+ SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
313
+ let next = code.replace(SOURCE_MAP_COMMENT_REGEX, "");
314
+ const stripped = next !== code;
315
+ if (debugId && !DEBUG_ID_COMMENT_REGEX.test(next)) {
316
+ const suffix = next.length > 0 && !next.endsWith("\n") ? "\n" : "";
317
+ next = `${next}${suffix}//# debugId=${debugId}
318
+ `;
319
+ }
320
+ return { code: next, stripped, debugId };
321
+ }
250
322
  function ensureIgnoreEntry(dir, fileName, entryName) {
251
323
  const filePath = _path2.default.join(_path2.default.resolve(dir), fileName);
252
324
  if (!_fs2.default.existsSync(filePath)) {
@@ -321,13 +393,14 @@ function updateAllIgnoreFiles(cwd, vaultDir) {
321
393
  function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir = ".unpeek-maps", stripComments = true, config, options) {
322
394
  const resolvedOutDir = _path2.default.resolve(outDir);
323
395
  const resolvedCwd = _path2.default.resolve(cwd);
324
- const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _13 => _13.sourcemaps, 'optionalAccess', _14 => _14.vaultDir]), () => ( privateMapsDir)), () => ( ".unpeek-maps"));
325
- const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _15 => _15.sourcemaps, 'optionalAccess', _16 => _16.keepPrivate]), () => ( keepPrivateMaps));
326
- const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _17 => _17.sourcemaps, 'optionalAccess', _18 => _18.stripComments]), () => ( stripComments));
327
- const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.updateIgnoreFiles]), () => ( true));
396
+ const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _15 => _15.sourcemaps, 'optionalAccess', _16 => _16.vaultDir]), () => ( privateMapsDir)), () => ( ".unpeek-maps"));
397
+ const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _17 => _17.sourcemaps, 'optionalAccess', _18 => _18.keepPrivate]), () => ( keepPrivateMaps));
398
+ const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _19 => _19.sourcemaps, 'optionalAccess', _20 => _20.stripComments]), () => ( stripComments));
399
+ const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.updateIgnoreFiles]), () => ( true));
400
+ const dryRun = typeof options === "object" && options !== null ? _nullishCoalesce(options.dryRun, () => ( false)) : false;
328
401
  const vaultDir = _path2.default.resolve(resolvedCwd, effectiveVaultDirName);
329
402
  const publicDirsToCheck = /* @__PURE__ */ new Set();
330
- if (_optionalChain([config, 'optionalAccess', _20 => _20.publicDirs]) && config.publicDirs.length > 0) {
403
+ if (_optionalChain([config, 'optionalAccess', _22 => _22.publicDirs]) && config.publicDirs.length > 0) {
331
404
  for (const d of config.publicDirs) {
332
405
  publicDirsToCheck.add(d);
333
406
  }
@@ -338,7 +411,7 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
338
411
  }
339
412
  if (effectiveKeepPrivate !== false) {
340
413
  if (!isSubdirectoryOrSame(resolvedCwd, vaultDir)) {
341
- throw new (0, _chunkR6EBIR3Tcjs.UnpeekError)(
414
+ throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
342
415
  "ERR_SECURITY_PATH_TRAVERSAL",
343
416
  `[unpeek] Security Error: privateMapsDir (${vaultDir}) cannot traverse outside cwd (${resolvedCwd}).`
344
417
  );
@@ -379,7 +452,7 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
379
452
  let entries;
380
453
  try {
381
454
  entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
382
- } catch (e5) {
455
+ } catch (e7) {
383
456
  return;
384
457
  }
385
458
  for (const entry of entries) {
@@ -396,11 +469,13 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
396
469
  if (effectiveKeepPrivate !== false) {
397
470
  const relPath = _path2.default.relative(resolvedOutDir, fullPath);
398
471
  const targetPath = _path2.default.join(vaultDir, relPath);
399
- _fs2.default.mkdirSync(_path2.default.dirname(targetPath), { recursive: true });
400
- _fs2.default.copyFileSync(fullPath, targetPath);
401
- _fs2.default.unlinkSync(fullPath);
472
+ if (!dryRun) {
473
+ _fs2.default.mkdirSync(_path2.default.dirname(targetPath), { recursive: true });
474
+ _fs2.default.copyFileSync(fullPath, targetPath);
475
+ _fs2.default.unlinkSync(fullPath);
476
+ }
402
477
  movedFiles.push(targetPath);
403
- } else {
478
+ } else if (!dryRun) {
404
479
  _fs2.default.unlinkSync(fullPath);
405
480
  }
406
481
  movedMapsCount++;
@@ -408,7 +483,7 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
408
483
  }
409
484
  }
410
485
  walkForMaps(resolvedOutDir);
411
- if (updateIgnoreFiles && effectiveKeepPrivate !== false && movedMapsCount > 0) {
486
+ if (!dryRun && updateIgnoreFiles && effectiveKeepPrivate !== false && movedMapsCount > 0) {
412
487
  updateAllIgnoreFiles(resolvedCwd, vaultDir);
413
488
  }
414
489
  if (effectiveStripComments) {
@@ -416,9 +491,11 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
416
491
  for (const filePath of clientFiles) {
417
492
  const original = _fs2.default.readFileSync(filePath, "utf8");
418
493
  if (original.includes("sourceMappingURL=")) {
419
- const stripped = original.replace(SOURCE_MAP_COMMENT_REGEX, "");
420
- if (stripped !== original) {
421
- _fs2.default.writeFileSync(filePath, stripped, "utf8");
494
+ const { code: strippedCode, stripped } = stripSourceMapComments(original);
495
+ if (stripped) {
496
+ if (!dryRun) {
497
+ _fs2.default.writeFileSync(filePath, strippedCode, "utf8");
498
+ }
422
499
  strippedFilesCount++;
423
500
  }
424
501
  }
@@ -453,24 +530,31 @@ function isEntryChunk(relPath, index, allRelPaths) {
453
530
  async function protectProject(options = {}) {
454
531
  const startTime = performance.now();
455
532
  const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
456
- const config = await _chunk24K5NDXHcjs.loadUnpeekConfig.call(void 0, cwd, options.config);
533
+ const effectiveConfigInput = options.profile ? { ..._nullishCoalesce(options.config, () => ( {})), profile: options.profile } : options.config;
534
+ const config = await _chunkONM2CSTUcjs.loadUnpeekConfig.call(void 0, cwd, effectiveConfigInput);
535
+ const effectiveProfile = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( config.profile)), () => ( "recommended"));
457
536
  const { framework, outDir } = detectTargetFramework(cwd, options.outDir, config);
458
537
  const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
459
- const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _21 => _21.sourcemaps, 'optionalAccess', _22 => _22.keepPrivate]))), () => ( true));
460
- const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _23 => _23.sourcemaps, 'optionalAccess', _24 => _24.vaultDir]))), () => ( ".unpeek-maps"));
461
- const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _25 => _25.shield, 'optionalAccess', _26 => _26.deterrentMode]))), () => ( "passive"));
462
- const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _27 => _27.shield, 'optionalAccess', _28 => _28.detectHeadless]))), () => ( false));
463
- const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( true));
464
- const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _29 => _29.vault, 'optionalAccess', _30 => _30.minStringLength]))), () => ( 4));
465
- const aggressive = _nullishCoalesce(options.aggressive, () => ( false));
466
- const masterSym = _chunk6N6S6WTQcjs.deriveWindowKeySymbol.call(void 0, seed);
467
- const masterShield = injectRuntimeShield ? _chunk6N6S6WTQcjs.generateRuntimeShield.call(void 0, {
538
+ const dryRun = Boolean(options.dryRun);
539
+ const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _23 => _23.sourcemaps, 'optionalAccess', _24 => _24.keepPrivate]))), () => ( true));
540
+ const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _25 => _25.sourcemaps, 'optionalAccess', _26 => _26.vaultDir]))), () => ( ".unpeek-maps"));
541
+ const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _27 => _27.shield, 'optionalAccess', _28 => _28.deterrentMode]))), () => ( "passive"));
542
+ const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _29 => _29.shield, 'optionalAccess', _30 => _30.detectHeadless]))), () => ( false));
543
+ const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( (effectiveProfile === "minimal" ? false : true)));
544
+ const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _31 => _31.vault, 'optionalAccess', _32 => _32.minStringLength]))), () => ( 4));
545
+ const aggressive = _nullishCoalesce(options.aggressive, () => ( (effectiveProfile === "strict" ? true : false)));
546
+ const scrubPaths = _nullishCoalesce(_nullishCoalesce(options.scrubPaths, () => ( config.scrubPaths)), () => ( (effectiveProfile === "strict" ? true : false)));
547
+ const masterSym = _chunkIAD5DV3Dcjs.deriveWindowKeySymbol.call(void 0, seed);
548
+ const masterShield = injectRuntimeShield ? _chunkIAD5DV3Dcjs.generateRuntimeShield.call(void 0, {
468
549
  seed,
469
550
  deterrentMode,
470
551
  detectHeadless,
471
552
  windowKeySymbol: masterSym
472
553
  }) : void 0;
473
- const vaultResult = relocateSourceMaps(outDir, cwd, keepPrivateMaps, privateMapsDir, false, config);
554
+ const deferVaultWrites = dryRun || typeof options.maxGzipDelta === "number";
555
+ const vaultResult = relocateSourceMaps(outDir, cwd, keepPrivateMaps, privateMapsDir, false, config, {
556
+ dryRun: deferVaultWrites
557
+ });
474
558
  const clientFiles = scanClientBundles(outDir, config);
475
559
  const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
476
560
  let originalBytes = 0;
@@ -480,16 +564,34 @@ async function protectProject(options = {}) {
480
564
  let totalEncryptedStrings = 0;
481
565
  let totalMangledSymbols = 0;
482
566
  let processedFiles = 0;
567
+ let debugIdsPreserved = 0;
568
+ const diagnostics = [];
569
+ if (vaultResult.dockerIgnoreMissing) {
570
+ diagnostics.push({
571
+ code: "DOCKERIGNORE_MISSING",
572
+ severity: "warning",
573
+ message: ".dockerignore is missing .unpeek-maps/. Private maps may leak into Docker image during 'COPY . .'."
574
+ });
575
+ }
483
576
  const allOrigBufs = [];
484
577
  const allProtBufs = [];
485
578
  const stagedFiles = [];
579
+ const pendingDebugIds = [];
580
+ let originalGzipBytes = 0;
581
+ let protectedGzipBytes = 0;
582
+ let gzipDeltaPercent = 0;
583
+ let budgetExceeded = false;
486
584
  try {
487
585
  for (let i = 0; i < clientFiles.length; i++) {
488
586
  const filePath = clientFiles[i];
489
587
  let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
588
+ const fileDebugId = extractDebugId(codeToTransform);
490
589
  if (codeToTransform.includes("sourceMappingURL=")) {
491
- codeToTransform = codeToTransform.replace(SOURCE_MAP_COMMENT_REGEX, "");
492
- vaultResult.strippedFilesCount++;
590
+ const strippedRes = stripSourceMapComments(codeToTransform);
591
+ codeToTransform = strippedRes.code;
592
+ if (strippedRes.stripped) {
593
+ vaultResult.strippedFilesCount++;
594
+ }
493
595
  }
494
596
  const origBuf = Buffer.from(codeToTransform, "utf8");
495
597
  originalBytes += origBuf.byteLength;
@@ -497,7 +599,7 @@ async function protectProject(options = {}) {
497
599
  const relPath = allRelPaths[i];
498
600
  const isEntry = isEntryChunk(relPath, i, allRelPaths);
499
601
  const shouldInjectShield = injectRuntimeShield && isEntry;
500
- const fileSeed = _chunk6N6S6WTQcjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
602
+ const fileSeed = _chunkIAD5DV3Dcjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
501
603
  const transformOptions = {
502
604
  seed: fileSeed,
503
605
  minStringLength,
@@ -506,21 +608,58 @@ async function protectProject(options = {}) {
506
608
  skipShieldPreamble: true,
507
609
  shieldCoupled: injectRuntimeShield,
508
610
  windowKeySymbol: masterSym,
509
- expectedDelta: _optionalChain([masterShield, 'optionalAccess', _31 => _31.expectedDelta]),
611
+ expectedDelta: _optionalChain([masterShield, 'optionalAccess', _33 => _33.expectedDelta]),
510
612
  deterrentMode,
511
613
  detectHeadless,
512
614
  aggressive,
615
+ scrubPaths,
513
616
  config
514
617
  };
515
- const result = _chunkLXP73HJCcjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
618
+ const result = _chunkIAD5DV3Dcjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
619
+ if (result.skippedReason === "parse-error") {
620
+ diagnostics.push({
621
+ code: "PARSE_FALLBACK",
622
+ severity: "warning",
623
+ message: `Skipped AST transform due to parse error in "${relPath}".`,
624
+ file: relPath
625
+ });
626
+ } else if (result.skippedReason === "already-protected") {
627
+ diagnostics.push({
628
+ code: "ALREADY_PROTECTED",
629
+ severity: "info",
630
+ message: `File "${relPath}" is already protected.`,
631
+ file: relPath
632
+ });
633
+ } else if (result.skippedReason === "empty") {
634
+ diagnostics.push({
635
+ code: "EMPTY_INPUT",
636
+ severity: "info",
637
+ message: `File "${relPath}" is empty.`,
638
+ file: relPath
639
+ });
640
+ }
516
641
  let finalCode = result.code;
517
- if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _32 => _32.preambleCode]) && !finalCode.includes("__unpeek_tampered") && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
642
+ if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _34 => _34.preambleCode]) && !finalCode.includes("__unpeek_tampered") && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
518
643
  finalCode = `${masterShield.preambleCode}
519
644
  ${finalCode}`;
520
645
  }
521
- const tmpPath = `${filePath}.unpeek.tmp`;
522
- _fs2.default.writeFileSync(tmpPath, finalCode, "utf8");
523
- stagedFiles.push({ tmpPath, finalPath: filePath });
646
+ const effectiveDebugId = _nullishCoalesce(result.debugId, () => ( fileDebugId));
647
+ if (effectiveDebugId) {
648
+ if (!DEBUG_ID_COMMENT_REGEX.test(finalCode)) {
649
+ const suffix = finalCode.length > 0 && !finalCode.endsWith("\n") ? "\n" : "";
650
+ finalCode = `${finalCode}${suffix}//# debugId=${effectiveDebugId}
651
+ `;
652
+ }
653
+ debugIdsPreserved++;
654
+ if (!dryRun && keepPrivateMaps) {
655
+ pendingDebugIds.push({ relPath, debugId: effectiveDebugId });
656
+ }
657
+ }
658
+ if (!dryRun) {
659
+ const tmpPath = `${filePath}.unpeek.tmp`;
660
+ _fs2.default.writeFileSync(tmpPath, finalCode, "utf8");
661
+ stagedFiles.push({ tmpPath, finalPath: filePath });
662
+ }
524
663
  const protBuf = Buffer.from(finalCode, "utf8");
525
664
  protectedBytes += protBuf.byteLength;
526
665
  allProtBufs.push(protBuf);
@@ -530,23 +669,60 @@ ${finalCode}`;
530
669
  totalMangledSymbols += result.mangledSymbolsCount;
531
670
  processedFiles++;
532
671
  }
533
- for (const { tmpPath, finalPath } of stagedFiles) {
534
- _fs2.default.renameSync(tmpPath, finalPath);
672
+ originalGzipBytes = allOrigBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allOrigBufs)).byteLength : 0;
673
+ protectedGzipBytes = allProtBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allProtBufs)).byteLength : 0;
674
+ gzipDeltaPercent = originalGzipBytes > 0 ? Number(((protectedGzipBytes - originalGzipBytes) / originalGzipBytes * 100).toFixed(2)) : 0;
675
+ budgetExceeded = typeof options.maxGzipDelta === "number" && gzipDeltaPercent > options.maxGzipDelta;
676
+ if (budgetExceeded && !dryRun) {
677
+ throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
678
+ "ERR_BUDGET_EXCEEDED",
679
+ `Protected bundle Gzip delta (${gzipDeltaPercent}%) exceeded maxGzipDelta (${options.maxGzipDelta}%).`
680
+ );
681
+ }
682
+ if (!dryRun) {
683
+ if (deferVaultWrites) {
684
+ const finalVaultResult = relocateSourceMaps(
685
+ outDir,
686
+ cwd,
687
+ keepPrivateMaps,
688
+ privateMapsDir,
689
+ false,
690
+ config,
691
+ { dryRun: false }
692
+ );
693
+ vaultResult.movedMapsCount = finalVaultResult.movedMapsCount;
694
+ vaultResult.vaultDir = finalVaultResult.vaultDir;
695
+ vaultResult.movedFiles = finalVaultResult.movedFiles;
696
+ vaultResult.dockerIgnoreMissing = finalVaultResult.dockerIgnoreMissing;
697
+ }
698
+ for (const { relPath, debugId } of pendingDebugIds) {
699
+ const vaultedMapPath = _path2.default.join(vaultResult.vaultDir, `${relPath}.map`);
700
+ if (_fs2.default.existsSync(vaultedMapPath)) {
701
+ try {
702
+ const mapJson = JSON.parse(_fs2.default.readFileSync(vaultedMapPath, "utf8"));
703
+ if (!mapJson.debugId) {
704
+ mapJson.debugId = debugId;
705
+ _fs2.default.writeFileSync(vaultedMapPath, JSON.stringify(mapJson), "utf8");
706
+ }
707
+ } catch (e8) {
708
+ }
709
+ }
710
+ }
711
+ for (const { tmpPath, finalPath } of stagedFiles) {
712
+ _fs2.default.renameSync(tmpPath, finalPath);
713
+ }
535
714
  }
536
715
  } catch (error) {
537
716
  for (const { tmpPath } of stagedFiles) {
538
717
  if (_fs2.default.existsSync(tmpPath)) {
539
718
  try {
540
719
  _fs2.default.unlinkSync(tmpPath);
541
- } catch (e6) {
720
+ } catch (e9) {
542
721
  }
543
722
  }
544
723
  }
545
724
  throw error;
546
725
  }
547
- const originalGzipBytes = allOrigBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allOrigBufs)).byteLength : 0;
548
- const protectedGzipBytes = allProtBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allProtBufs)).byteLength : 0;
549
- const gzipDeltaPercent = originalGzipBytes > 0 ? Number(((protectedGzipBytes - originalGzipBytes) / originalGzipBytes * 100).toFixed(2)) : 0;
550
726
  const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
551
727
  return {
552
728
  framework,
@@ -563,13 +739,26 @@ ${finalCode}`;
563
739
  totalEncryptedStrings,
564
740
  totalMangledSymbols,
565
741
  elapsedMs,
742
+ seed,
566
743
  tier: aggressive ? "Tier 2" : "Tier 1",
567
744
  aggressive,
568
- dockerIgnoreMissing: vaultResult.dockerIgnoreMissing
745
+ dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
746
+ dryRun,
747
+ profile: effectiveProfile,
748
+ budgetExceeded,
749
+ debugIdsPreserved,
750
+ diagnostics
569
751
  };
570
752
  }
571
753
 
572
754
 
573
755
 
574
756
 
575
- exports.detectTargetFramework = detectTargetFramework; exports.protectProject = protectProject;
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+ exports.hasNextServerSegment = hasNextServerSegment; exports.detectTargetFramework = detectTargetFramework; exports.scanClientBundles = scanClientBundles; exports.isNext16OrAbove = isNext16OrAbove; exports.serializeNextOptions = serializeNextOptions; exports.readUnpeekNextOptionsFromEnv = readUnpeekNextOptionsFromEnv; exports.SOURCE_MAP_COMMENT_REGEX = SOURCE_MAP_COMMENT_REGEX; exports.findMonorepoRoots = findMonorepoRoots; exports.protectProject = protectProject;