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/cli/index.js CHANGED
@@ -1184,7 +1184,7 @@ ${finalCode}`;
1184
1184
  }
1185
1185
 
1186
1186
  // src/cli/index.ts
1187
- var VERSION = "1.2.0";
1187
+ var VERSION = "1.4.0";
1188
1188
  function getPackageVersion() {
1189
1189
  try {
1190
1190
  const pkgUrl = new URL("../../package.json", import.meta.url);
@@ -1196,25 +1196,52 @@ function getPackageVersion() {
1196
1196
  }
1197
1197
  }
1198
1198
  var RUNTIME_VERSION = getPackageVersion();
1199
+ var MARK_TOP = " \u259B\u2580\u2580\u259C";
1200
+ var MARK_BOTTOM = " \u2599\u2584\u2584\u259F";
1201
+ var RULE = "\u2500";
1202
+ var LABEL_WIDTH = 19;
1203
+ function colorEnabled() {
1204
+ if (process.env.NO_COLOR) return false;
1205
+ if (process.env.TERM === "dumb") return false;
1206
+ return Boolean(process.stdout.isTTY);
1207
+ }
1208
+ function paint(code, text) {
1209
+ return colorEnabled() ? `\x1B[${code}m${text}\x1B[0m` : text;
1210
+ }
1211
+ function dim(text) {
1212
+ return paint("2", text);
1213
+ }
1214
+ function brandBlock() {
1215
+ return [
1216
+ `${MARK_TOP} ${paint("1", `unpeek ${RUNTIME_VERSION}`)}`,
1217
+ `${MARK_BOTTOM} ${dim("client bundle protection")}`
1218
+ ].join("\n");
1219
+ }
1220
+ function sectionBlock(title, rows) {
1221
+ const fill = Math.max(2, 46 - title.length);
1222
+ const header = ` ${dim(title)} ${dim(RULE.repeat(fill))}`;
1223
+ const body = rows.map(([label, value]) => ` ${dim(label.padEnd(LABEL_WIDTH))} ${value}`);
1224
+ return [header, ...body].join("\n");
1225
+ }
1199
1226
  function printHelp() {
1200
- const helpText = `
1201
- unpeek v${VERSION} \u2014 Call-graph-aware polymorphic AST obfuscation & runtime shield
1202
-
1203
- Usage:
1204
- unpeek init [--dry-run] Configure postbuild hook & .unpeek-maps/ vault
1205
- unpeek protect [options] Protect client bundles in-place
1206
-
1207
- Options:
1208
- --out-dir <dir> Explicit client output directory
1209
- --seed <number> Deterministic polymorphic seed
1210
- --passive Use passive deterrent mode instead of gradual
1211
- --no-maps Delete .map files instead of vaulting to .unpeek-maps/
1212
- --min-string-length <num> Minimum string length for encryption vault (default: 4)
1213
- --private-maps-dir <dir> Directory to store vaulted source maps (default: .unpeek-maps)
1214
- --no-shield Do not inject runtime anti-tamper deterrent shield
1215
- -h, --help Show help message
1216
- -v, --version Show version number
1217
- `.trim();
1227
+ const helpText = [
1228
+ brandBlock(),
1229
+ "",
1230
+ " Usage:",
1231
+ " unpeek init [--dry-run] wire postbuild and the .unpeek-maps/ vault",
1232
+ " unpeek protect [options] protect client bundles in place",
1233
+ "",
1234
+ " Options:",
1235
+ " --out-dir <dir> explicit client output directory",
1236
+ " --seed <number> deterministic polymorphic seed",
1237
+ " --passive passive deterrent mode instead of gradual",
1238
+ " --no-maps delete .map files instead of vaulting them",
1239
+ " --min-string-length <num> minimum string length for the vault (default: 4)",
1240
+ " --private-maps-dir <dir> vault directory (default: .unpeek-maps)",
1241
+ " --no-shield skip the runtime anti-tamper shield",
1242
+ " -h, --help show help",
1243
+ " -v, --version show version"
1244
+ ].join("\n");
1218
1245
  console.log(helpText);
1219
1246
  }
1220
1247
  function formatBytes(bytes) {
@@ -1223,30 +1250,66 @@ function formatBytes(bytes) {
1223
1250
  }
1224
1251
  function printSummaryTable(summary) {
1225
1252
  const sign = summary.gzipDeltaPercent > 0 ? "+" : "";
1226
- const rows = [
1227
- ["Framework", summary.framework],
1228
- ["Client OutDir", summary.outDir],
1229
- ["Processed Bundles", String(summary.processedFiles)],
1230
- ["Vaulted Source Maps", String(summary.movedSourceMaps)],
1231
- ["Cold Functions Protected", String(summary.totalColdFunctionsProtected)],
1232
- ["Hot Functions Skipped (0% Tax)", String(summary.totalHotFunctionsSkipped)],
1233
- ["Encrypted Strings", String(summary.totalEncryptedStrings)],
1234
- ["Mangled Symbols", String(summary.totalMangledSymbols)],
1235
- [
1236
- "Gzip Bundle Size",
1237
- `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} (${sign}${summary.gzipDeltaPercent}%)`
1238
- ],
1239
- ["Elapsed Time", `${summary.elapsedMs} ms`]
1240
- ];
1241
- const col1Width = Math.max(...rows.map(([k]) => k.length), 16);
1242
- const col2Width = Math.max(...rows.map(([, v]) => v.length), 20);
1243
- const divider = `+-${"-".repeat(col1Width)}-+-${"-".repeat(col2Width)}-+`;
1244
- console.log("\n[unpeek] Protection Complete");
1245
- console.log(divider);
1246
- for (const [label, value] of rows) {
1247
- console.log(`| ${label.padEnd(col1Width)} | ${value.padEnd(col2Width)} |`);
1253
+ const gzip = `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} ${sign}${summary.gzipDeltaPercent}%`;
1254
+ console.log("");
1255
+ console.log(brandBlock());
1256
+ console.log("");
1257
+ console.log(
1258
+ sectionBlock("PROJECT", [
1259
+ ["framework", summary.framework],
1260
+ ["output", summary.outDir],
1261
+ ["bundles", String(summary.processedFiles)]
1262
+ ])
1263
+ );
1264
+ console.log("");
1265
+ console.log(
1266
+ sectionBlock("CALL GRAPH", [
1267
+ ["hot path exempt", `${summary.totalHotFunctionsSkipped} ${dim("0% tax")}`],
1268
+ ["cold path protected", String(summary.totalColdFunctionsProtected)]
1269
+ ])
1270
+ );
1271
+ console.log("");
1272
+ console.log(
1273
+ sectionBlock("TRANSFORM", [
1274
+ ["string vault", `${summary.totalEncryptedStrings} literals ${dim("O(1) memo")}`],
1275
+ ["symbol mangling", `${summary.totalMangledSymbols} bindings`]
1276
+ ])
1277
+ );
1278
+ console.log("");
1279
+ console.log(
1280
+ sectionBlock("OUTPUT", [
1281
+ ["source maps", `${summary.movedSourceMaps} moved -> .unpeek-maps/`],
1282
+ ["gzip", gzip],
1283
+ ["elapsed", `${summary.elapsedMs} ms`]
1284
+ ])
1285
+ );
1286
+ console.log("");
1287
+ console.log(` ${dim("done. maps are private. hot path untouched.")}`);
1288
+ }
1289
+ function printInitResult(result, dryRun) {
1290
+ const postbuild = result.updatedPackageJson ? dryRun ? "would be added" : "unpeek protect (added)" : "already configured";
1291
+ const vault = result.updatedGitignore ? dryRun ? "would be ignored" : ".unpeek-maps/ (added)" : "already ignored";
1292
+ console.log("");
1293
+ console.log(brandBlock());
1294
+ console.log("");
1295
+ console.log(
1296
+ sectionBlock("PROJECT", [
1297
+ ["framework", result.framework ?? "unknown"],
1298
+ ["postbuild", postbuild],
1299
+ ["vault", vault]
1300
+ ])
1301
+ );
1302
+ console.log("");
1303
+ if (dryRun) {
1304
+ console.log(` ${dim(result.message)}`);
1305
+ } else if (result.updatedPackageJson || result.updatedGitignore) {
1306
+ console.log(` ${dim("postbuild wired. maps stay private from the first build.")}`);
1307
+ } else {
1308
+ console.log(` ${dim(result.message)}`);
1309
+ }
1310
+ if (!dryRun) {
1311
+ console.log(` ${dim("run your build to protect the first bundle.")}`);
1248
1312
  }
1249
- console.log(divider);
1250
1313
  }
1251
1314
  async function runCli(args) {
1252
1315
  if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
@@ -1261,7 +1324,7 @@ async function runCli(args) {
1261
1324
  if (command === "init") {
1262
1325
  const dryRun = args.includes("--dry-run");
1263
1326
  const res = initProject(process.cwd(), { dryRun });
1264
- console.log(`[unpeek] ${res.message}`);
1327
+ printInitResult(res, dryRun);
1265
1328
  return;
1266
1329
  }
1267
1330
  if (command === "protect" || args.length > 0 && args[0].startsWith("-")) {