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.js CHANGED
@@ -1242,7 +1242,7 @@ ${finalCode}`;
1242
1242
 
1243
1243
  // src/cli/index.ts
1244
1244
  import fs5 from "fs";
1245
- var VERSION = "1.2.0";
1245
+ var VERSION = "1.4.0";
1246
1246
  function getPackageVersion() {
1247
1247
  try {
1248
1248
  const pkgUrl = new URL("../../package.json", import.meta.url);
@@ -1254,25 +1254,52 @@ function getPackageVersion() {
1254
1254
  }
1255
1255
  }
1256
1256
  var RUNTIME_VERSION = getPackageVersion();
1257
+ var MARK_TOP = " \u259B\u2580\u2580\u259C";
1258
+ var MARK_BOTTOM = " \u2599\u2584\u2584\u259F";
1259
+ var RULE = "\u2500";
1260
+ var LABEL_WIDTH = 19;
1261
+ function colorEnabled() {
1262
+ if (process.env.NO_COLOR) return false;
1263
+ if (process.env.TERM === "dumb") return false;
1264
+ return Boolean(process.stdout.isTTY);
1265
+ }
1266
+ function paint(code, text) {
1267
+ return colorEnabled() ? `\x1B[${code}m${text}\x1B[0m` : text;
1268
+ }
1269
+ function dim(text) {
1270
+ return paint("2", text);
1271
+ }
1272
+ function brandBlock() {
1273
+ return [
1274
+ `${MARK_TOP} ${paint("1", `unpeek ${RUNTIME_VERSION}`)}`,
1275
+ `${MARK_BOTTOM} ${dim("client bundle protection")}`
1276
+ ].join("\n");
1277
+ }
1278
+ function sectionBlock(title, rows) {
1279
+ const fill = Math.max(2, 46 - title.length);
1280
+ const header = ` ${dim(title)} ${dim(RULE.repeat(fill))}`;
1281
+ const body = rows.map(([label, value]) => ` ${dim(label.padEnd(LABEL_WIDTH))} ${value}`);
1282
+ return [header, ...body].join("\n");
1283
+ }
1257
1284
  function printHelp() {
1258
- const helpText = `
1259
- unpeek v${VERSION} \u2014 Call-graph-aware polymorphic AST obfuscation & runtime shield
1260
-
1261
- Usage:
1262
- unpeek init [--dry-run] Configure postbuild hook & .unpeek-maps/ vault
1263
- unpeek protect [options] Protect client bundles in-place
1264
-
1265
- Options:
1266
- --out-dir <dir> Explicit client output directory
1267
- --seed <number> Deterministic polymorphic seed
1268
- --passive Use passive deterrent mode instead of gradual
1269
- --no-maps Delete .map files instead of vaulting to .unpeek-maps/
1270
- --min-string-length <num> Minimum string length for encryption vault (default: 4)
1271
- --private-maps-dir <dir> Directory to store vaulted source maps (default: .unpeek-maps)
1272
- --no-shield Do not inject runtime anti-tamper deterrent shield
1273
- -h, --help Show help message
1274
- -v, --version Show version number
1275
- `.trim();
1285
+ const helpText = [
1286
+ brandBlock(),
1287
+ "",
1288
+ " Usage:",
1289
+ " unpeek init [--dry-run] wire postbuild and the .unpeek-maps/ vault",
1290
+ " unpeek protect [options] protect client bundles in place",
1291
+ "",
1292
+ " Options:",
1293
+ " --out-dir <dir> explicit client output directory",
1294
+ " --seed <number> deterministic polymorphic seed",
1295
+ " --passive passive deterrent mode instead of gradual",
1296
+ " --no-maps delete .map files instead of vaulting them",
1297
+ " --min-string-length <num> minimum string length for the vault (default: 4)",
1298
+ " --private-maps-dir <dir> vault directory (default: .unpeek-maps)",
1299
+ " --no-shield skip the runtime anti-tamper shield",
1300
+ " -h, --help show help",
1301
+ " -v, --version show version"
1302
+ ].join("\n");
1276
1303
  console.log(helpText);
1277
1304
  }
1278
1305
  function formatBytes(bytes) {
@@ -1281,30 +1308,66 @@ function formatBytes(bytes) {
1281
1308
  }
1282
1309
  function printSummaryTable(summary) {
1283
1310
  const sign = summary.gzipDeltaPercent > 0 ? "+" : "";
1284
- const rows = [
1285
- ["Framework", summary.framework],
1286
- ["Client OutDir", summary.outDir],
1287
- ["Processed Bundles", String(summary.processedFiles)],
1288
- ["Vaulted Source Maps", String(summary.movedSourceMaps)],
1289
- ["Cold Functions Protected", String(summary.totalColdFunctionsProtected)],
1290
- ["Hot Functions Skipped (0% Tax)", String(summary.totalHotFunctionsSkipped)],
1291
- ["Encrypted Strings", String(summary.totalEncryptedStrings)],
1292
- ["Mangled Symbols", String(summary.totalMangledSymbols)],
1293
- [
1294
- "Gzip Bundle Size",
1295
- `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} (${sign}${summary.gzipDeltaPercent}%)`
1296
- ],
1297
- ["Elapsed Time", `${summary.elapsedMs} ms`]
1298
- ];
1299
- const col1Width = Math.max(...rows.map(([k]) => k.length), 16);
1300
- const col2Width = Math.max(...rows.map(([, v]) => v.length), 20);
1301
- const divider = `+-${"-".repeat(col1Width)}-+-${"-".repeat(col2Width)}-+`;
1302
- console.log("\n[unpeek] Protection Complete");
1303
- console.log(divider);
1304
- for (const [label, value] of rows) {
1305
- console.log(`| ${label.padEnd(col1Width)} | ${value.padEnd(col2Width)} |`);
1311
+ const gzip = `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} ${sign}${summary.gzipDeltaPercent}%`;
1312
+ console.log("");
1313
+ console.log(brandBlock());
1314
+ console.log("");
1315
+ console.log(
1316
+ sectionBlock("PROJECT", [
1317
+ ["framework", summary.framework],
1318
+ ["output", summary.outDir],
1319
+ ["bundles", String(summary.processedFiles)]
1320
+ ])
1321
+ );
1322
+ console.log("");
1323
+ console.log(
1324
+ sectionBlock("CALL GRAPH", [
1325
+ ["hot path exempt", `${summary.totalHotFunctionsSkipped} ${dim("0% tax")}`],
1326
+ ["cold path protected", String(summary.totalColdFunctionsProtected)]
1327
+ ])
1328
+ );
1329
+ console.log("");
1330
+ console.log(
1331
+ sectionBlock("TRANSFORM", [
1332
+ ["string vault", `${summary.totalEncryptedStrings} literals ${dim("O(1) memo")}`],
1333
+ ["symbol mangling", `${summary.totalMangledSymbols} bindings`]
1334
+ ])
1335
+ );
1336
+ console.log("");
1337
+ console.log(
1338
+ sectionBlock("OUTPUT", [
1339
+ ["source maps", `${summary.movedSourceMaps} moved -> .unpeek-maps/`],
1340
+ ["gzip", gzip],
1341
+ ["elapsed", `${summary.elapsedMs} ms`]
1342
+ ])
1343
+ );
1344
+ console.log("");
1345
+ console.log(` ${dim("done. maps are private. hot path untouched.")}`);
1346
+ }
1347
+ function printInitResult(result, dryRun) {
1348
+ const postbuild = result.updatedPackageJson ? dryRun ? "would be added" : "unpeek protect (added)" : "already configured";
1349
+ const vault = result.updatedGitignore ? dryRun ? "would be ignored" : ".unpeek-maps/ (added)" : "already ignored";
1350
+ console.log("");
1351
+ console.log(brandBlock());
1352
+ console.log("");
1353
+ console.log(
1354
+ sectionBlock("PROJECT", [
1355
+ ["framework", result.framework ?? "unknown"],
1356
+ ["postbuild", postbuild],
1357
+ ["vault", vault]
1358
+ ])
1359
+ );
1360
+ console.log("");
1361
+ if (dryRun) {
1362
+ console.log(` ${dim(result.message)}`);
1363
+ } else if (result.updatedPackageJson || result.updatedGitignore) {
1364
+ console.log(` ${dim("postbuild wired. maps stay private from the first build.")}`);
1365
+ } else {
1366
+ console.log(` ${dim(result.message)}`);
1367
+ }
1368
+ if (!dryRun) {
1369
+ console.log(` ${dim("run your build to protect the first bundle.")}`);
1306
1370
  }
1307
- console.log(divider);
1308
1371
  }
1309
1372
  async function runCli(args) {
1310
1373
  if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
@@ -1319,7 +1382,7 @@ async function runCli(args) {
1319
1382
  if (command === "init") {
1320
1383
  const dryRun = args.includes("--dry-run");
1321
1384
  const res = initProject(process.cwd(), { dryRun });
1322
- console.log(`[unpeek] ${res.message}`);
1385
+ printInitResult(res, dryRun);
1323
1386
  return;
1324
1387
  }
1325
1388
  if (command === "protect" || args.length > 0 && args[0].startsWith("-")) {