unpeek 3.0.0 → 4.0.1

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 (69) hide show
  1. package/README.md +31 -16
  2. package/README.tr.md +41 -26
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.d.cts +3 -1
  5. package/dist/adapters/esbuild.d.ts +2 -2
  6. package/dist/adapters/esbuild.js +5 -3
  7. package/dist/adapters/next/adapter.cjs +7 -6
  8. package/dist/adapters/next/adapter.d.cts +1 -1
  9. package/dist/adapters/next/adapter.d.ts +1 -1
  10. package/dist/adapters/next/adapter.js +6 -5
  11. package/dist/adapters/next/index.cjs +7 -6
  12. package/dist/adapters/next/index.js +6 -5
  13. package/dist/adapters/rollup.cjs +5 -5
  14. package/dist/adapters/rollup.d.cts +3 -1
  15. package/dist/adapters/rollup.d.ts +2 -2
  16. package/dist/adapters/rollup.js +5 -3
  17. package/dist/adapters/rspack.cjs +5 -4
  18. package/dist/adapters/rspack.d.cts +1 -1
  19. package/dist/adapters/rspack.d.ts +1 -1
  20. package/dist/adapters/rspack.js +3 -2
  21. package/dist/adapters/vite.cjs +5 -5
  22. package/dist/adapters/vite.d.cts +3 -1
  23. package/dist/adapters/vite.d.ts +2 -2
  24. package/dist/adapters/vite.js +5 -3
  25. package/dist/adapters/webpack.cjs +5 -5
  26. package/dist/adapters/webpack.d.cts +3 -1
  27. package/dist/adapters/webpack.d.ts +2 -2
  28. package/dist/adapters/webpack.js +5 -3
  29. package/dist/browser.cjs +3 -3
  30. package/dist/browser.d.cts +20 -17
  31. package/dist/browser.d.ts +20 -17
  32. package/dist/browser.js +2 -2
  33. package/dist/chunk-3GDHYBVH.cjs +1092 -0
  34. package/dist/chunk-4G2HCME5.js +429 -0
  35. package/dist/{chunk-BPRSCRUZ.js → chunk-4SOS3LRV.js} +53 -9
  36. package/dist/chunk-7ZEVJ4OR.cjs +595 -0
  37. package/dist/{chunk-FCF2EGPM.js → chunk-EN6QVR6P.js} +12 -3
  38. package/dist/{chunk-IZIWDJRF.js → chunk-LGTXAAZH.js} +3338 -972
  39. package/dist/chunk-M46SFJE7.cjs +7733 -0
  40. package/dist/{chunk-6TDCSIRZ.cjs → chunk-NNAAPDUS.cjs} +60 -16
  41. package/dist/chunk-OTA75YI6.cjs +429 -0
  42. package/dist/chunk-TYL32LUK.js +1092 -0
  43. package/dist/{chunk-IEBVL5BT.cjs → chunk-URPPSTHZ.cjs} +12 -3
  44. package/dist/{chunk-IICVBTR2.js → chunk-W77DAC3H.js} +22 -3
  45. package/dist/{chunk-ONM2CSTU.cjs → chunk-X6EETCO6.cjs} +64 -45
  46. package/dist/chunk-XYN5NYSD.js +595 -0
  47. package/dist/cli/index.js +4543 -1442
  48. package/dist/{config-CfXY_iDD.d.ts → config-Y6JwVGwX.d.cts} +15 -1
  49. package/dist/{config-CfXY_iDD.d.cts → config-Y6JwVGwX.d.ts} +15 -1
  50. package/dist/config.cjs +3 -3
  51. package/dist/config.d.cts +1 -1
  52. package/dist/config.d.ts +1 -1
  53. package/dist/config.js +2 -2
  54. package/dist/{index-CjRTNPlj.d.cts → index-0O1WSfVP.d.ts} +7 -1
  55. package/dist/{index-Cm1IloVm.d.ts → index-COVHErnx.d.cts} +7 -1
  56. package/dist/index.cjs +231 -291
  57. package/dist/index.d.cts +4 -4
  58. package/dist/index.d.ts +4 -4
  59. package/dist/index.js +225 -285
  60. package/dist/plugins/unplugin.cjs +4 -3
  61. package/dist/plugins/unplugin.js +3 -2
  62. package/dist/{types-DYQIzGf6.d.cts → types-CMtZnV8C.d.ts} +3 -3
  63. package/dist/{types-ZHAFdOd3.d.ts → types-D93PuOOl.d.cts} +3 -3
  64. package/package.json +1 -1
  65. package/dist/chunk-APWMNVAZ.js +0 -764
  66. package/dist/chunk-DUK2SECY.js +0 -83
  67. package/dist/chunk-I6GXEHFR.cjs +0 -764
  68. package/dist/chunk-IAD5DV3D.cjs +0 -5367
  69. package/dist/chunk-RXUY3MPH.cjs +0 -83
package/dist/index.cjs CHANGED
@@ -1,22 +1,29 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
3
 
4
+ var _chunk7ZEVJ4ORcjs = require('./chunk-7ZEVJ4OR.cjs');
4
5
 
5
6
 
6
7
 
8
+ var _chunkX6EETCO6cjs = require('./chunk-X6EETCO6.cjs');
7
9
 
8
10
 
9
- var _chunkI6GXEHFRcjs = require('./chunk-I6GXEHFR.cjs');
11
+ var _chunkURPPSTHZcjs = require('./chunk-URPPSTHZ.cjs');
10
12
 
11
13
 
12
14
 
13
- var _chunkONM2CSTUcjs = require('./chunk-ONM2CSTU.cjs');
14
15
 
15
16
 
16
- var _chunkIEBVL5BTcjs = require('./chunk-IEBVL5BT.cjs');
17
17
 
18
18
 
19
- var _chunkIAD5DV3Dcjs = require('./chunk-IAD5DV3D.cjs');
19
+
20
+
21
+
22
+
23
+ var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
24
+
25
+
26
+ var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
20
27
 
21
28
 
22
29
 
@@ -91,7 +98,7 @@ export default withUnpeek(nextConfig);
91
98
  function initProject(cwd = process.cwd(), options = {}) {
92
99
  const dryRun = typeof options === "boolean" ? options : _nullishCoalesce(options.dryRun, () => ( false));
93
100
  const rootDir = _path2.default.resolve(cwd);
94
- const { framework } = _chunkI6GXEHFRcjs.detectTargetFramework.call(void 0, rootDir);
101
+ const { framework } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, rootDir);
95
102
  const pkgPath = _path2.default.join(rootDir, "package.json");
96
103
  let updatedPackageJson = false;
97
104
  let updatedGitignore = false;
@@ -124,7 +131,7 @@ function initProject(cwd = process.cwd(), options = {}) {
124
131
  const rawNext = _nullishCoalesce(_optionalChain([deps, 'optionalAccess', _ => _.next]), () => ( _optionalChain([devDeps, 'optionalAccess', _2 => _2.next])));
125
132
  nextVersion = typeof rawNext === "string" ? rawNext : void 0;
126
133
  }
127
- if (framework === "nextjs" && _chunkI6GXEHFRcjs.isNext16OrAbove.call(void 0, nextVersion)) {
134
+ if (framework === "nextjs" && _chunk7ZEVJ4ORcjs.isNext16OrAbove.call(void 0, nextVersion)) {
128
135
  isNext16 = true;
129
136
  const configRes = wireNextConfig(rootDir, dryRun);
130
137
  updatedNextConfig = configRes.updated;
@@ -197,7 +204,7 @@ function initProject(cwd = process.cwd(), options = {}) {
197
204
  var _acorn = require('acorn'); var acorn = _interopRequireWildcard(_acorn);
198
205
  var _acornwalk = require('acorn-walk');
199
206
  function walkPublicMaps(currentDir, rootOutDir, found) {
200
- if (_chunkI6GXEHFRcjs.hasNextServerSegment.call(void 0, currentDir, rootOutDir)) {
207
+ if (_chunk3GDHYBVHcjs.hasNextServerSegment.call(void 0, currentDir, rootOutDir)) {
201
208
  return;
202
209
  }
203
210
  let entries;
@@ -212,7 +219,7 @@ function walkPublicMaps(currentDir, rootOutDir, found) {
212
219
  if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
213
220
  continue;
214
221
  }
215
- if (_chunkI6GXEHFRcjs.hasNextServerSegment.call(void 0, fullPath, rootOutDir)) {
222
+ if (_chunk3GDHYBVHcjs.hasNextServerSegment.call(void 0, fullPath, rootOutDir)) {
216
223
  continue;
217
224
  }
218
225
  walkPublicMaps(fullPath, rootOutDir, found);
@@ -232,6 +239,45 @@ function hasIgnoreEntry(filePath, ignoreEntry) {
232
239
  return false;
233
240
  }
234
241
  }
242
+ function isEs5GlobalThisIdiom(args) {
243
+ if (args.length !== 1) return false;
244
+ const arg = args[0];
245
+ if (arg.type === "Literal" && typeof arg.value === "string") {
246
+ const trimmed = arg.value.trim().replace(/;+$/, "").trim();
247
+ return trimmed === "return this";
248
+ }
249
+ return false;
250
+ }
251
+ function isNodeModulesSource(sourcePath) {
252
+ if (!sourcePath) return false;
253
+ const normalized = sourcePath.replace(/\\/g, "/").toLowerCase();
254
+ return /(?:^|\/)node_modules\//.test(normalized);
255
+ }
256
+ function mapHasOnlyNodeModulesSources(map) {
257
+ if (!map) return false;
258
+ const flat = Array.isArray(map.sections) ? _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, map) : map;
259
+ const sources = Array.isArray(flat.sources) ? flat.sources : [];
260
+ if (sources.length === 0) return false;
261
+ const root = flat.sourceRoot;
262
+ return sources.every((src) => {
263
+ const combined = root && src && !src.startsWith(root) ? `${root.replace(/\/$/, "")}/${src.replace(/^\//, "")}` : src;
264
+ return isNodeModulesSource(combined);
265
+ });
266
+ }
267
+ function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
268
+ if (!map) return false;
269
+ const pos = _chunk3GDHYBVHcjs.resolvePosition.call(void 0, map, hit.line, hit.column);
270
+ if (pos.source) {
271
+ return isNodeModulesSource(pos.source);
272
+ }
273
+ if (hit.calleeLine !== hit.line || hit.calleeColumn !== hit.column) {
274
+ const calleePos = _chunk3GDHYBVHcjs.resolvePosition.call(void 0, map, hit.calleeLine, hit.calleeColumn);
275
+ if (calleePos.source) {
276
+ return isNodeModulesSource(calleePos.source);
277
+ }
278
+ }
279
+ return allSourcesNodeModules;
280
+ }
235
281
  function findEvalOrFunctionCalls(code) {
236
282
  const hits = [];
237
283
  let ast;
@@ -239,14 +285,16 @@ function findEvalOrFunctionCalls(code) {
239
285
  ast = acorn.parse(code, {
240
286
  ecmaVersion: "latest",
241
287
  sourceType: "module",
242
- allowReturnOutsideFunction: true
288
+ allowReturnOutsideFunction: true,
289
+ locations: true
243
290
  });
244
291
  } catch (e3) {
245
292
  try {
246
293
  ast = acorn.parse(code, {
247
294
  ecmaVersion: "latest",
248
295
  sourceType: "script",
249
- allowReturnOutsideFunction: true
296
+ allowReturnOutsideFunction: true,
297
+ locations: true
250
298
  });
251
299
  } catch (e4) {
252
300
  return hits;
@@ -255,25 +303,54 @@ function findEvalOrFunctionCalls(code) {
255
303
  _acornwalk.simple.call(void 0, ast, {
256
304
  CallExpression(node) {
257
305
  if (node.callee.type === "Identifier") {
306
+ const line = node.loc ? node.loc.start.line : 1;
307
+ const column = node.loc ? node.loc.start.column + 1 : 1;
308
+ const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
309
+ const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
258
310
  if (node.callee.name === "eval") {
259
- hits.push("eval(...)");
311
+ hits.push({
312
+ kind: "eval(...)",
313
+ line,
314
+ column,
315
+ calleeLine,
316
+ calleeColumn,
317
+ vendorIdiom: false
318
+ });
260
319
  } else if (node.callee.name === "Function") {
261
- hits.push("Function(...)");
320
+ hits.push({
321
+ kind: "Function(...)",
322
+ line,
323
+ column,
324
+ calleeLine,
325
+ calleeColumn,
326
+ vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
327
+ });
262
328
  }
263
329
  }
264
330
  },
265
331
  NewExpression(node) {
266
332
  if (node.callee.type === "Identifier" && node.callee.name === "Function") {
267
- hits.push("new Function(...)");
333
+ const line = node.loc ? node.loc.start.line : 1;
334
+ const column = node.loc ? node.loc.start.column + 1 : 1;
335
+ const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
336
+ const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
337
+ hits.push({
338
+ kind: "new Function(...)",
339
+ line,
340
+ column,
341
+ calleeLine,
342
+ calleeColumn,
343
+ vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
344
+ });
268
345
  }
269
346
  }
270
347
  });
271
- return Array.from(new Set(hits));
348
+ return hits;
272
349
  }
273
350
  async function checkProject(options = {}) {
274
351
  const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
275
- const config = await _chunkONM2CSTUcjs.loadUnpeekConfig.call(void 0, cwd);
276
- const { outDir } = _chunkI6GXEHFRcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
352
+ const config = await _chunkX6EETCO6cjs.loadUnpeekConfig.call(void 0, cwd);
353
+ const { outDir } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
277
354
  const resolvedOutDir = _path2.default.resolve(outDir);
278
355
  const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _3 => _3.sourcemaps, 'optionalAccess', _4 => _4.vaultDir]))), () => ( ".unpeek-maps"));
279
356
  const maxGzipDelta = _nullishCoalesce(options.maxGzipDelta, () => ( 15));
@@ -293,17 +370,30 @@ async function checkProject(options = {}) {
293
370
  file: rel
294
371
  });
295
372
  }
296
- const clientFiles = _chunkI6GXEHFRcjs.scanClientBundles.call(void 0, resolvedOutDir, config);
373
+ const vaultDir = _path2.default.resolve(cwd, privateMapsDir);
374
+ const manifestPath = _path2.default.join(vaultDir, "manifest.json");
375
+ let manifest;
376
+ if (_fs2.default.existsSync(manifestPath)) {
377
+ try {
378
+ const parsed = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
379
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
380
+ manifest = parsed;
381
+ }
382
+ } catch (e5) {
383
+ }
384
+ }
385
+ const clientFiles = _chunk3GDHYBVHcjs.scanClientBundles.call(void 0, resolvedOutDir, config);
297
386
  for (const filePath of clientFiles) {
298
387
  const rel = _path2.default.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
388
+ const relFromManifest = typeof _optionalChain([manifest, 'optionalAccess', _5 => _5.outDir]) === "string" ? _path2.default.relative(_path2.default.resolve(cwd, manifest.outDir), filePath).replace(/\\/g, "/") : void 0;
299
389
  let content;
300
390
  try {
301
391
  content = _fs2.default.readFileSync(filePath, "utf8");
302
- } catch (e5) {
392
+ } catch (e6) {
303
393
  continue;
304
394
  }
305
- _chunkI6GXEHFRcjs.SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
306
- if (_chunkI6GXEHFRcjs.SOURCE_MAP_COMMENT_REGEX.test(content)) {
395
+ _chunk3GDHYBVHcjs.SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
396
+ if (_chunk3GDHYBVHcjs.SOURCE_MAP_COMMENT_REGEX.test(content)) {
307
397
  violations.push({
308
398
  rule: "sourcemap-comment",
309
399
  severity: "error",
@@ -311,25 +401,120 @@ async function checkProject(options = {}) {
311
401
  file: rel
312
402
  });
313
403
  }
404
+ const jsDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, content);
405
+ const decodedRel = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, rel);
406
+ const decodedManifestRel = relFromManifest ? _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relFromManifest) : void 0;
407
+ const mapCandidates = [
408
+ _path2.default.join(vaultDir, `${rel}.map`),
409
+ ...decodedRel !== rel ? [_path2.default.join(vaultDir, `${decodedRel}.map`)] : [],
410
+ ...relFromManifest && relFromManifest !== rel ? [_path2.default.join(vaultDir, `${relFromManifest}.map`)] : [],
411
+ ...decodedManifestRel && decodedManifestRel !== relFromManifest ? [_path2.default.join(vaultDir, `${decodedManifestRel}.map`)] : []
412
+ ];
413
+ const vaultedMapPath = mapCandidates.find((p) => _fs2.default.existsSync(p));
414
+ let vaultedMap;
415
+ if (vaultedMapPath) {
416
+ try {
417
+ const mapJson = JSON.parse(_fs2.default.readFileSync(vaultedMapPath, "utf8"));
418
+ vaultedMap = mapJson;
419
+ const rawMapDebugId = typeof mapJson.debugId === "string" ? mapJson.debugId : typeof mapJson.debug_id === "string" ? mapJson.debug_id : void 0;
420
+ if (jsDebugId && rawMapDebugId && jsDebugId !== rawMapDebugId) {
421
+ violations.push({
422
+ rule: "debugid-mismatch",
423
+ severity: "error",
424
+ message: `debugId mismatch for "${rel}": JS has "${jsDebugId}" while vaulted map has "${rawMapDebugId}".`,
425
+ file: rel
426
+ });
427
+ } else if (jsDebugId && !rawMapDebugId) {
428
+ warnings.push({
429
+ rule: "debugid-mismatch",
430
+ severity: "warning",
431
+ message: `JS bundle "${rel}" has debugId "${jsDebugId}" but vaulted source map is missing debugId.`,
432
+ file: rel
433
+ });
434
+ } else if (!jsDebugId && rawMapDebugId) {
435
+ warnings.push({
436
+ rule: "debugid-mismatch",
437
+ severity: "warning",
438
+ message: `Vaulted source map for "${rel}" has debugId "${rawMapDebugId}" but JS bundle is missing //# debugId=.`,
439
+ file: rel
440
+ });
441
+ }
442
+ } catch (e7) {
443
+ }
444
+ } else if (jsDebugId) {
445
+ warnings.push({
446
+ rule: "debugid-mismatch",
447
+ severity: "warning",
448
+ message: `JS bundle "${rel}" has debugId "${jsDebugId}" but no vaulted source map found at "${rel}.map".`,
449
+ file: rel
450
+ });
451
+ }
314
452
  const evalHits = findEvalOrFunctionCalls(content);
315
453
  if (evalHits.length > 0) {
316
- const violation = {
317
- rule: "eval-csp",
318
- severity: requireZeroEval ? "error" : "warning",
319
- message: `Dynamic code evaluation (${evalHits.join(", ")}) detected in "${rel}".`,
320
- file: rel
321
- };
322
- if (requireZeroEval) {
323
- violations.push(violation);
454
+ if (!requireZeroEval) {
455
+ const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
456
+ warnings.push({
457
+ rule: "eval-csp",
458
+ severity: "warning",
459
+ message: `Dynamic code evaluation (${kinds.join(", ")}) detected in "${rel}".`,
460
+ file: rel
461
+ });
324
462
  } else {
325
- warnings.push(violation);
463
+ const allNodeModules = mapHasOnlyNodeModulesSources(vaultedMap);
464
+ const baselineList = _nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _6 => _6.preExistingEvalFiles, 'optionalAccess', _7 => _7[rel]]), () => ( (relFromManifest ? _optionalChain([manifest, 'optionalAccess', _8 => _8.preExistingEvalFiles, 'optionalAccess', _9 => _9[relFromManifest]]) : void 0)));
465
+ const remainingBaseline = /* @__PURE__ */ new Map();
466
+ if (Array.isArray(baselineList)) {
467
+ for (const entry of baselineList) {
468
+ remainingBaseline.set(entry, (_nullishCoalesce(remainingBaseline.get(entry), () => ( 0))) + 1);
469
+ }
470
+ }
471
+ const warningHits = [];
472
+ const unattributedHits = [];
473
+ for (const hit of evalHits) {
474
+ if (hit.vendorIdiom || isHitFromNodeModules(hit, vaultedMap, allNodeModules)) {
475
+ warningHits.push(hit);
476
+ const rem = _nullishCoalesce(remainingBaseline.get(hit.kind), () => ( 0));
477
+ if (rem > 0) {
478
+ remainingBaseline.set(hit.kind, rem - 1);
479
+ }
480
+ } else {
481
+ unattributedHits.push(hit);
482
+ }
483
+ }
484
+ const errorHits = [];
485
+ for (const hit of unattributedHits) {
486
+ const rem = _nullishCoalesce(remainingBaseline.get(hit.kind), () => ( 0));
487
+ if (rem > 0) {
488
+ remainingBaseline.set(hit.kind, rem - 1);
489
+ warningHits.push(hit);
490
+ } else {
491
+ errorHits.push(hit);
492
+ }
493
+ }
494
+ if (warningHits.length > 0) {
495
+ const warningKinds = Array.from(new Set(warningHits.map((h) => h.kind)));
496
+ warnings.push({
497
+ rule: "eval-csp",
498
+ severity: "warning",
499
+ message: `Pre-existing or vendor dynamic code evaluation (${warningKinds.join(", ")}) detected in "${rel}".`,
500
+ file: rel
501
+ });
502
+ }
503
+ if (errorHits.length > 0) {
504
+ const errorKinds = Array.from(new Set(errorHits.map((h) => h.kind)));
505
+ violations.push({
506
+ rule: "eval-csp",
507
+ severity: "error",
508
+ message: `Dynamic code evaluation (${errorKinds.join(", ")}) detected in "${rel}".`,
509
+ file: rel
510
+ });
511
+ }
326
512
  }
327
513
  }
328
514
  }
329
- const vaultDir = _path2.default.resolve(cwd, privateMapsDir);
330
515
  const relVault = _path2.default.relative(cwd, vaultDir).replace(/\\/g, "/");
331
516
  const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
332
- const roots = _chunkI6GXEHFRcjs.findMonorepoRoots.call(void 0, cwd);
517
+ const roots = _chunk3GDHYBVHcjs.findMonorepoRoots.call(void 0, cwd);
333
518
  let foundGitignore = false;
334
519
  let gitignoreProtected = false;
335
520
  let foundDockerignore = false;
@@ -370,18 +555,20 @@ async function checkProject(options = {}) {
370
555
  message: `.dockerignore is missing "${ignoreEntry}". Private source maps may leak into Docker images.`
371
556
  });
372
557
  }
373
- const manifestPath = _path2.default.join(vaultDir, "manifest.json");
374
- if (_fs2.default.existsSync(manifestPath)) {
375
- try {
376
- const manifest = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
377
- if (typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
378
- violations.push({
379
- rule: "gzip-budget",
380
- severity: "error",
381
- message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
382
- });
383
- }
384
- } catch (e6) {
558
+ if (manifest && typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
559
+ const isTinyBundleBaseline = options.maxGzipDelta === void 0 && typeof manifest.originalGzipBytes === "number" && manifest.originalGzipBytes < 16384;
560
+ if (isTinyBundleBaseline) {
561
+ warnings.push({
562
+ rule: "gzip-budget",
563
+ severity: "warning",
564
+ message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds default ${maxGzipDelta}% threshold on small bundle (${manifest.originalGzipBytes} B original gzip).`
565
+ });
566
+ } else {
567
+ violations.push({
568
+ rule: "gzip-budget",
569
+ severity: "error",
570
+ message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
571
+ });
385
572
  }
386
573
  }
387
574
  return {
@@ -393,253 +580,6 @@ async function checkProject(options = {}) {
393
580
  };
394
581
  }
395
582
 
396
- // src/core/vlq.ts
397
-
398
-
399
- var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
400
- var BASE64_MAP = /* @__PURE__ */ new Map();
401
- for (let i = 0; i < BASE64_CHARS.length; i++) {
402
- BASE64_MAP.set(BASE64_CHARS[i], i);
403
- }
404
- var VLQ_BASE_SHIFT = 5;
405
- var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
406
- var VLQ_BASE_MASK = VLQ_BASE - 1;
407
- var VLQ_CONTINUATION_BIT = VLQ_BASE;
408
- function decodeVlq(segment, startIndex) {
409
- let result = 0;
410
- let shift = 0;
411
- let index = startIndex;
412
- while (index < segment.length) {
413
- const digit = BASE64_MAP.get(segment[index]);
414
- if (digit === void 0) {
415
- return null;
416
- }
417
- index++;
418
- const continuation = (digit & VLQ_CONTINUATION_BIT) !== 0;
419
- result += (digit & VLQ_BASE_MASK) << shift;
420
- shift += VLQ_BASE_SHIFT;
421
- if (!continuation) {
422
- const isNegative = (result & 1) === 1;
423
- const shifted = result >> 1;
424
- return {
425
- value: isNegative ? -shifted : shifted,
426
- nextIndex: index
427
- };
428
- }
429
- if (shift > 30) {
430
- return null;
431
- }
432
- }
433
- return null;
434
- }
435
- function decodeMappings(mappingsStr) {
436
- const mappings = [];
437
- let malformedCount = 0;
438
- if (!mappingsStr) {
439
- return { mappings, malformedCount };
440
- }
441
- let sourceIndex = 0;
442
- let originalLine = 0;
443
- let originalColumn = 0;
444
- let nameIndex = 0;
445
- const lines = mappingsStr.split(";");
446
- for (let genLine = 0; genLine < lines.length; genLine++) {
447
- const lineStr = lines[genLine];
448
- if (!lineStr) continue;
449
- let genCol = 0;
450
- const segments = lineStr.split(",");
451
- for (const seg of segments) {
452
- if (!seg) continue;
453
- const values = [];
454
- let idx = 0;
455
- let valid = true;
456
- while (idx < seg.length) {
457
- const decoded = decodeVlq(seg, idx);
458
- if (!decoded) {
459
- valid = false;
460
- break;
461
- }
462
- values.push(decoded.value);
463
- idx = decoded.nextIndex;
464
- }
465
- if (!valid || values.length !== 1 && values.length !== 4 && values.length !== 5) {
466
- malformedCount++;
467
- continue;
468
- }
469
- genCol += values[0];
470
- if (values.length >= 4) {
471
- sourceIndex += values[1];
472
- originalLine += values[2];
473
- originalColumn += values[3];
474
- const mapping = {
475
- generatedLine: genLine,
476
- generatedColumn: genCol,
477
- sourceIndex,
478
- originalLine,
479
- originalColumn
480
- };
481
- if (values.length === 5) {
482
- nameIndex += values[4];
483
- mapping.nameIndex = nameIndex;
484
- }
485
- mappings.push(mapping);
486
- }
487
- }
488
- }
489
- return { mappings, malformedCount };
490
- }
491
- function findMappingAt(mappings, line0, col0) {
492
- let lo = 0;
493
- let hi = mappings.length - 1;
494
- let best;
495
- while (lo <= hi) {
496
- const mid = lo + hi >> 1;
497
- const m = mappings[mid];
498
- if (m.generatedLine < line0 || m.generatedLine === line0 && m.generatedColumn <= col0) {
499
- if (m.generatedLine === line0) {
500
- best = m;
501
- }
502
- lo = mid + 1;
503
- } else {
504
- hi = mid - 1;
505
- }
506
- }
507
- return best;
508
- }
509
- function resolvePosition(map, line1Based, column1Based) {
510
- const { mappings, malformedCount } = decodeMappings(map.mappings);
511
- const match = findMappingAt(mappings, Math.max(0, line1Based - 1), Math.max(0, column1Based - 1));
512
- if (!match) {
513
- return { malformedCount };
514
- }
515
- const rawSource = map.sources[match.sourceIndex];
516
- const source = map.sourceRoot && rawSource && !rawSource.startsWith(map.sourceRoot) ? `${map.sourceRoot.replace(/\/$/, "")}/${rawSource.replace(/^\//, "")}` : rawSource;
517
- return {
518
- source,
519
- line: match.originalLine + 1,
520
- column: match.originalColumn + 1,
521
- name: match.nameIndex !== void 0 ? map.names[match.nameIndex] : void 0,
522
- malformedCount
523
- };
524
- }
525
- function collectMapFiles(mapsDir) {
526
- if (!_fs2.default.existsSync(mapsDir)) return [];
527
- const results = [];
528
- const walk = (dir) => {
529
- let entries;
530
- try {
531
- entries = _fs2.default.readdirSync(dir, { withFileTypes: true });
532
- } catch (e7) {
533
- return;
534
- }
535
- for (const entry of entries) {
536
- const fullPath = _path2.default.join(dir, entry.name);
537
- if (entry.isDirectory()) {
538
- walk(fullPath);
539
- } else if (entry.isFile() && entry.name.endsWith(".map")) {
540
- results.push(fullPath);
541
- }
542
- }
543
- };
544
- walk(mapsDir);
545
- return results;
546
- }
547
- function findMatchingMapFile(fileRef, mapsDir, allMaps) {
548
- let cleanRef = fileRef.trim();
549
- try {
550
- if (/^https?:\/\//i.test(cleanRef)) {
551
- cleanRef = new URL(cleanRef).pathname;
552
- }
553
- } catch (e8) {
554
- }
555
- cleanRef = cleanRef.split("?")[0].split("#")[0].replace(/\\/g, "/").replace(/^\/+/, "");
556
- const targetMapName = `${_path2.default.posix.basename(cleanRef)}.map`;
557
- const exactCandidate = _path2.default.join(mapsDir, `${cleanRef}.map`);
558
- if (_fs2.default.existsSync(exactCandidate)) {
559
- return exactCandidate;
560
- }
561
- for (const mapPath of allMaps) {
562
- const rel = _path2.default.relative(mapsDir, mapPath).replace(/\\/g, "/");
563
- if (rel === `${cleanRef}.map` || rel.endsWith(`/${cleanRef}.map`) || cleanRef.endsWith(`/${rel.slice(0, -4)}`)) {
564
- return mapPath;
565
- }
566
- }
567
- return allMaps.find((m) => _path2.default.basename(m) === targetMapName);
568
- }
569
- var STACK_FRAME_REGEX = /(?:at\s+(?:[^(]+\s+\()?|\@)([^\s()]+?):(\d+):(\d+)\)?/;
570
- async function symbolicateStackTrace(options) {
571
- const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
572
- const mapsDir = _path2.default.resolve(cwd, _nullishCoalesce(options.mapsDir, () => ( ".unpeek-maps")));
573
- const allMaps = collectMapFiles(mapsDir);
574
- const warnings = [];
575
- const mapCache = /* @__PURE__ */ new Map();
576
- if (allMaps.length === 0) {
577
- warnings.push(`No .map files found in "${mapsDir}".`);
578
- }
579
- const lines = options.stackTrace.split(/\r?\n/);
580
- const frames = [];
581
- const outputLines = [];
582
- for (const rawLine of lines) {
583
- const match = rawLine.match(STACK_FRAME_REGEX);
584
- if (!match) {
585
- frames.push({ raw: rawLine, resolved: false });
586
- outputLines.push(rawLine);
587
- continue;
588
- }
589
- const fileRef = match[1];
590
- const lineNum = Number(match[2]);
591
- const colNum = Number(match[3]);
592
- const mapPath = findMatchingMapFile(fileRef, mapsDir, allMaps);
593
- if (!mapPath) {
594
- frames.push({ raw: rawLine, file: fileRef, line: lineNum, column: colNum, resolved: false });
595
- outputLines.push(rawLine);
596
- continue;
597
- }
598
- let parsedMap = mapCache.get(mapPath);
599
- if (parsedMap === void 0) {
600
- try {
601
- parsedMap = JSON.parse(_fs2.default.readFileSync(mapPath, "utf8"));
602
- } catch (e9) {
603
- parsedMap = null;
604
- warnings.push(`Failed to parse source map "${mapPath}".`);
605
- }
606
- mapCache.set(mapPath, parsedMap);
607
- }
608
- if (!parsedMap || typeof parsedMap.mappings !== "string" || !Array.isArray(parsedMap.sources)) {
609
- frames.push({ raw: rawLine, file: fileRef, line: lineNum, column: colNum, resolved: false });
610
- outputLines.push(rawLine);
611
- continue;
612
- }
613
- const pos = resolvePosition(parsedMap, lineNum, colNum);
614
- if (pos.malformedCount > 0) {
615
- warnings.push(`Skipped ${pos.malformedCount} malformed VLQ segment(s) in "${_path2.default.basename(mapPath)}".`);
616
- }
617
- if (!pos.source || pos.line === void 0 || pos.column === void 0) {
618
- frames.push({ raw: rawLine, file: fileRef, line: lineNum, column: colNum, resolved: false });
619
- outputLines.push(rawLine);
620
- continue;
621
- }
622
- frames.push({
623
- raw: rawLine,
624
- file: fileRef,
625
- line: lineNum,
626
- column: colNum,
627
- originalSource: pos.source,
628
- originalLine: pos.line,
629
- originalColumn: pos.column,
630
- originalName: pos.name,
631
- resolved: true
632
- });
633
- const fnPrefix = pos.name ? `${pos.name} ` : "";
634
- outputLines.push(` at ${fnPrefix}(${pos.source}:${pos.line}:${pos.column})`);
635
- }
636
- return {
637
- stackTrace: outputLines.join("\n"),
638
- frames,
639
- warnings: Array.from(new Set(warnings))
640
- };
641
- }
642
-
643
583
 
644
584
 
645
585
 
@@ -650,4 +590,4 @@ async function symbolicateStackTrace(options) {
650
590
 
651
591
 
652
592
 
653
- exports.PRESETS = _chunkIEBVL5BTcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkONM2CSTUcjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkONM2CSTUcjs.loadUnpeekConfig; exports.protectProject = _chunkI6GXEHFRcjs.protectProject; exports.symbolicateStackTrace = symbolicateStackTrace; exports.transformJavaScript = _chunkIAD5DV3Dcjs.transformJavaScript;
593
+ exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkX6EETCO6cjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkX6EETCO6cjs.loadUnpeekConfig; exports.protectProject = _chunk7ZEVJ4ORcjs.protectProject; exports.symbolicateStackTrace = _chunk3GDHYBVHcjs.symbolicateStackTrace; exports.transformJavaScript = _chunkM46SFJE7cjs.transformJavaScript;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-CfXY_iDD.cjs';
2
- export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-CjRTNPlj.cjs';
3
- import { I as InitOptions, b as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, c as CheckResult, S as SymbolicateOptions, d as SymbolicateResult } from './types-DYQIzGf6.cjs';
4
- export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-DYQIzGf6.cjs';
1
+ export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-Y6JwVGwX.cjs';
2
+ export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-COVHErnx.cjs';
3
+ import { I as InitOptions, b as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, c as CheckResult, S as SymbolicateOptions, d as SymbolicateResult } from './types-D93PuOOl.cjs';
4
+ export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-D93PuOOl.cjs';
5
5
 
6
6
  declare function initProject(cwd?: string, options?: InitOptions): InitResult;
7
7
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-CfXY_iDD.js';
2
- export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-Cm1IloVm.js';
3
- import { I as InitOptions, b as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, c as CheckResult, S as SymbolicateOptions, d as SymbolicateResult } from './types-ZHAFdOd3.js';
4
- export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-ZHAFdOd3.js';
1
+ export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-Y6JwVGwX.js';
2
+ export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-0O1WSfVP.js';
3
+ import { I as InitOptions, b as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, c as CheckResult, S as SymbolicateOptions, d as SymbolicateResult } from './types-CMtZnV8C.js';
4
+ export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-CMtZnV8C.js';
5
5
 
6
6
  declare function initProject(cwd?: string, options?: InitOptions): InitResult;
7
7
  /**