unpeek 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1299,7 +1299,7 @@ ${finalCode}`;
1299
1299
 
1300
1300
  // src/cli/index.ts
1301
1301
  var import_node_fs5 = __toESM(require("fs"), 1);
1302
- var VERSION = "1.2.0";
1302
+ var VERSION = "1.4.0";
1303
1303
  function getPackageVersion() {
1304
1304
  try {
1305
1305
  const pkgUrl = new URL("../../package.json", importMetaUrl);
@@ -1311,25 +1311,52 @@ function getPackageVersion() {
1311
1311
  }
1312
1312
  }
1313
1313
  var RUNTIME_VERSION = getPackageVersion();
1314
+ var MARK_TOP = " \u259B\u2580\u2580\u259C";
1315
+ var MARK_BOTTOM = " \u2599\u2584\u2584\u259F";
1316
+ var RULE = "\u2500";
1317
+ var LABEL_WIDTH = 19;
1318
+ function colorEnabled() {
1319
+ if (process.env.NO_COLOR) return false;
1320
+ if (process.env.TERM === "dumb") return false;
1321
+ return Boolean(process.stdout.isTTY);
1322
+ }
1323
+ function paint(code, text) {
1324
+ return colorEnabled() ? `\x1B[${code}m${text}\x1B[0m` : text;
1325
+ }
1326
+ function dim(text) {
1327
+ return paint("2", text);
1328
+ }
1329
+ function brandBlock() {
1330
+ return [
1331
+ `${MARK_TOP} ${paint("1", `unpeek ${RUNTIME_VERSION}`)}`,
1332
+ `${MARK_BOTTOM} ${dim("client bundle protection")}`
1333
+ ].join("\n");
1334
+ }
1335
+ function sectionBlock(title, rows) {
1336
+ const fill = Math.max(2, 46 - title.length);
1337
+ const header = ` ${dim(title)} ${dim(RULE.repeat(fill))}`;
1338
+ const body = rows.map(([label, value]) => ` ${dim(label.padEnd(LABEL_WIDTH))} ${value}`);
1339
+ return [header, ...body].join("\n");
1340
+ }
1314
1341
  function printHelp() {
1315
- const helpText = `
1316
- unpeek v${VERSION} \u2014 Call-graph-aware polymorphic AST obfuscation & runtime shield
1317
-
1318
- Usage:
1319
- unpeek init [--dry-run] Configure postbuild hook & .unpeek-maps/ vault
1320
- unpeek protect [options] Protect client bundles in-place
1321
-
1322
- Options:
1323
- --out-dir <dir> Explicit client output directory
1324
- --seed <number> Deterministic polymorphic seed
1325
- --passive Use passive deterrent mode instead of gradual
1326
- --no-maps Delete .map files instead of vaulting to .unpeek-maps/
1327
- --min-string-length <num> Minimum string length for encryption vault (default: 4)
1328
- --private-maps-dir <dir> Directory to store vaulted source maps (default: .unpeek-maps)
1329
- --no-shield Do not inject runtime anti-tamper deterrent shield
1330
- -h, --help Show help message
1331
- -v, --version Show version number
1332
- `.trim();
1342
+ const helpText = [
1343
+ brandBlock(),
1344
+ "",
1345
+ " Usage:",
1346
+ " unpeek init [--dry-run] wire postbuild and the .unpeek-maps/ vault",
1347
+ " unpeek protect [options] protect client bundles in place",
1348
+ "",
1349
+ " Options:",
1350
+ " --out-dir <dir> explicit client output directory",
1351
+ " --seed <number> deterministic polymorphic seed",
1352
+ " --passive passive deterrent mode instead of gradual",
1353
+ " --no-maps delete .map files instead of vaulting them",
1354
+ " --min-string-length <num> minimum string length for the vault (default: 4)",
1355
+ " --private-maps-dir <dir> vault directory (default: .unpeek-maps)",
1356
+ " --no-shield skip the runtime anti-tamper shield",
1357
+ " -h, --help show help",
1358
+ " -v, --version show version"
1359
+ ].join("\n");
1333
1360
  console.log(helpText);
1334
1361
  }
1335
1362
  function formatBytes(bytes) {
@@ -1338,30 +1365,66 @@ function formatBytes(bytes) {
1338
1365
  }
1339
1366
  function printSummaryTable(summary) {
1340
1367
  const sign = summary.gzipDeltaPercent > 0 ? "+" : "";
1341
- const rows = [
1342
- ["Framework", summary.framework],
1343
- ["Client OutDir", summary.outDir],
1344
- ["Processed Bundles", String(summary.processedFiles)],
1345
- ["Vaulted Source Maps", String(summary.movedSourceMaps)],
1346
- ["Cold Functions Protected", String(summary.totalColdFunctionsProtected)],
1347
- ["Hot Functions Skipped (0% Tax)", String(summary.totalHotFunctionsSkipped)],
1348
- ["Encrypted Strings", String(summary.totalEncryptedStrings)],
1349
- ["Mangled Symbols", String(summary.totalMangledSymbols)],
1350
- [
1351
- "Gzip Bundle Size",
1352
- `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} (${sign}${summary.gzipDeltaPercent}%)`
1353
- ],
1354
- ["Elapsed Time", `${summary.elapsedMs} ms`]
1355
- ];
1356
- const col1Width = Math.max(...rows.map(([k]) => k.length), 16);
1357
- const col2Width = Math.max(...rows.map(([, v]) => v.length), 20);
1358
- const divider = `+-${"-".repeat(col1Width)}-+-${"-".repeat(col2Width)}-+`;
1359
- console.log("\n[unpeek] Protection Complete");
1360
- console.log(divider);
1361
- for (const [label, value] of rows) {
1362
- console.log(`| ${label.padEnd(col1Width)} | ${value.padEnd(col2Width)} |`);
1368
+ const gzip = `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} ${sign}${summary.gzipDeltaPercent}%`;
1369
+ console.log("");
1370
+ console.log(brandBlock());
1371
+ console.log("");
1372
+ console.log(
1373
+ sectionBlock("PROJECT", [
1374
+ ["framework", summary.framework],
1375
+ ["output", summary.outDir],
1376
+ ["bundles", String(summary.processedFiles)]
1377
+ ])
1378
+ );
1379
+ console.log("");
1380
+ console.log(
1381
+ sectionBlock("CALL GRAPH", [
1382
+ ["hot path exempt", `${summary.totalHotFunctionsSkipped} ${dim("0% tax")}`],
1383
+ ["cold path protected", String(summary.totalColdFunctionsProtected)]
1384
+ ])
1385
+ );
1386
+ console.log("");
1387
+ console.log(
1388
+ sectionBlock("TRANSFORM", [
1389
+ ["string vault", `${summary.totalEncryptedStrings} literals ${dim("O(1) memo")}`],
1390
+ ["symbol mangling", `${summary.totalMangledSymbols} bindings`]
1391
+ ])
1392
+ );
1393
+ console.log("");
1394
+ console.log(
1395
+ sectionBlock("OUTPUT", [
1396
+ ["source maps", `${summary.movedSourceMaps} moved -> .unpeek-maps/`],
1397
+ ["gzip", gzip],
1398
+ ["elapsed", `${summary.elapsedMs} ms`]
1399
+ ])
1400
+ );
1401
+ console.log("");
1402
+ console.log(` ${dim("done. maps are private. hot path untouched.")}`);
1403
+ }
1404
+ function printInitResult(result, dryRun) {
1405
+ const postbuild = result.updatedPackageJson ? dryRun ? "would be added" : "unpeek protect (added)" : "already configured";
1406
+ const vault = result.updatedGitignore ? dryRun ? "would be ignored" : ".unpeek-maps/ (added)" : "already ignored";
1407
+ console.log("");
1408
+ console.log(brandBlock());
1409
+ console.log("");
1410
+ console.log(
1411
+ sectionBlock("PROJECT", [
1412
+ ["framework", result.framework ?? "unknown"],
1413
+ ["postbuild", postbuild],
1414
+ ["vault", vault]
1415
+ ])
1416
+ );
1417
+ console.log("");
1418
+ if (dryRun) {
1419
+ console.log(` ${dim(result.message)}`);
1420
+ } else if (result.updatedPackageJson || result.updatedGitignore) {
1421
+ console.log(` ${dim("postbuild wired. maps stay private from the first build.")}`);
1422
+ } else {
1423
+ console.log(` ${dim(result.message)}`);
1424
+ }
1425
+ if (!dryRun) {
1426
+ console.log(` ${dim("run your build to protect the first bundle.")}`);
1363
1427
  }
1364
- console.log(divider);
1365
1428
  }
1366
1429
  async function runCli(args) {
1367
1430
  if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
@@ -1376,7 +1439,7 @@ async function runCli(args) {
1376
1439
  if (command === "init") {
1377
1440
  const dryRun = args.includes("--dry-run");
1378
1441
  const res = initProject(process.cwd(), { dryRun });
1379
- console.log(`[unpeek] ${res.message}`);
1442
+ printInitResult(res, dryRun);
1380
1443
  return;
1381
1444
  }
1382
1445
  if (command === "protect" || args.length > 0 && args[0].startsWith("-")) {