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
@@ -0,0 +1,595 @@
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
+
3
+ var _chunkX6EETCO6cjs = require('./chunk-X6EETCO6.cjs');
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
19
+
20
+
21
+
22
+
23
+
24
+ var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
25
+
26
+
27
+ var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
28
+
29
+ // src/internal/next.ts
30
+ function isNext16OrAbove(versionStr) {
31
+ if (!versionStr) return false;
32
+ const clean = versionStr.replace(/^[^\d]*/, "");
33
+ const match = clean.match(/^(\d+)\.(\d+)/);
34
+ if (!match) return false;
35
+ const major = parseInt(match[1], 10);
36
+ const minor = parseInt(match[2], 10);
37
+ if (major > 16) return true;
38
+ if (major === 16 && minor >= 2) return true;
39
+ return false;
40
+ }
41
+ function isSerializedRegExp(val) {
42
+ if (typeof val !== "object" || val === null) return false;
43
+ const record = val;
44
+ return record.__unpeekRegExp === true && typeof record.source === "string" && typeof record.flags === "string";
45
+ }
46
+ function serializeNextOptions(options) {
47
+ return JSON.stringify(options, (_key, value) => {
48
+ if (value instanceof RegExp) {
49
+ return {
50
+ __unpeekRegExp: true,
51
+ source: value.source,
52
+ flags: value.flags
53
+ };
54
+ }
55
+ return value;
56
+ });
57
+ }
58
+ function parseNextOptions(raw) {
59
+ return JSON.parse(raw, (_key, value) => {
60
+ if (isSerializedRegExp(value)) {
61
+ try {
62
+ return new RegExp(value.source, value.flags);
63
+ } catch (e) {
64
+ return void 0;
65
+ }
66
+ }
67
+ return value;
68
+ });
69
+ }
70
+ function readUnpeekNextOptionsFromEnv() {
71
+ const raw = process.env.UNPEEK_NEXT_OPTIONS;
72
+ if (!raw) {
73
+ return void 0;
74
+ }
75
+ try {
76
+ const parsed = parseNextOptions(raw);
77
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
78
+ return parsed;
79
+ }
80
+ } catch (e2) {
81
+ }
82
+ return void 0;
83
+ }
84
+
85
+ // src/core/protect.ts
86
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
87
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
88
+ var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib);
89
+ var _acorn = require('acorn'); var acorn = _interopRequireWildcard(_acorn);
90
+ var _acornwalk = require('acorn-walk');
91
+ var ENTRY_PATTERN = /^(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
92
+ function normalizeManifestRel(fileRef) {
93
+ const clean = fileRef.replace(/\\/g, "/").split("?")[0].split("#")[0].replace(/^\/+/, "");
94
+ const stripped = clean.replace(
95
+ /^(?:_next\/static\/chunks\/|_next\/static\/|_next\/|static\/chunks\/|static\/|assets\/)/,
96
+ ""
97
+ );
98
+ return stripped && stripped !== clean ? [clean, stripped] : [clean];
99
+ }
100
+ function addManifestEntryCandidates(outDir, manifestRootDir, fileRef, target) {
101
+ const clean = fileRef.replace(/\\/g, "/").split("?")[0].split("#")[0].replace(/^\/+/, "");
102
+ if (!clean) return;
103
+ const absFromRoot = _path2.default.resolve(manifestRootDir, clean);
104
+ const relFromOut = _path2.default.relative(outDir, absFromRoot).replace(/\\/g, "/");
105
+ if (relFromOut && !relFromOut.startsWith("..") && !_path2.default.isAbsolute(relFromOut)) {
106
+ target.add(relFromOut);
107
+ }
108
+ for (const variant of normalizeManifestRel(clean)) {
109
+ target.add(variant);
110
+ }
111
+ }
112
+ function collectManifestEntryFiles(outDir, cwd, config) {
113
+ const entries = /* @__PURE__ */ new Set();
114
+ const nextDist = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _ => _.next, 'optionalAccess', _2 => _2.distDir]), () => ( ".next"));
115
+ const viteOut = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _3 => _3.vite, 'optionalAccess', _4 => _4.outDir]), () => ( "dist"));
116
+ const nextManifestCandidates = Array.from(
117
+ /* @__PURE__ */ new Set([
118
+ _path2.default.join(outDir, "build-manifest.json"),
119
+ _path2.default.join(outDir, "..", "build-manifest.json"),
120
+ _path2.default.join(outDir, "..", "..", "build-manifest.json"),
121
+ _path2.default.join(cwd, nextDist, "build-manifest.json")
122
+ ])
123
+ );
124
+ for (const manifestPath of nextManifestCandidates) {
125
+ if (!_fs2.default.existsSync(manifestPath)) continue;
126
+ try {
127
+ const parsed = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
128
+ const manifestDir = _path2.default.dirname(manifestPath);
129
+ const hasRootMain = Array.isArray(parsed.rootMainFiles) && parsed.rootMainFiles.length > 0;
130
+ if (Array.isArray(parsed.rootMainFiles)) {
131
+ for (const item of parsed.rootMainFiles) {
132
+ if (typeof item === "string") {
133
+ addManifestEntryCandidates(outDir, manifestDir, item, entries);
134
+ }
135
+ }
136
+ }
137
+ if (parsed.pages && typeof parsed.pages === "object") {
138
+ const priorityKeys = ["/_app", "/", "/index"].filter(
139
+ (k) => Array.isArray(_optionalChain([parsed, 'access', _5 => _5.pages, 'optionalAccess', _6 => _6[k]]))
140
+ );
141
+ const pageLists = priorityKeys.length > 0 ? priorityKeys.map((k) => parsed.pages[k]) : !hasRootMain ? Object.values(parsed.pages) : [];
142
+ for (const list of pageLists) {
143
+ if (!Array.isArray(list)) continue;
144
+ for (const item of list) {
145
+ if (typeof item === "string") {
146
+ addManifestEntryCandidates(outDir, manifestDir, item, entries);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ break;
152
+ } catch (e3) {
153
+ }
154
+ }
155
+ const viteManifestCandidates = Array.from(
156
+ /* @__PURE__ */ new Set([
157
+ _path2.default.join(outDir, ".vite", "manifest.json"),
158
+ _path2.default.join(outDir, "..", ".vite", "manifest.json"),
159
+ _path2.default.join(cwd, viteOut, ".vite", "manifest.json"),
160
+ _path2.default.join(outDir, "manifest.json"),
161
+ _path2.default.join(outDir, "..", "manifest.json")
162
+ ])
163
+ );
164
+ for (const manifestPath of viteManifestCandidates) {
165
+ if (!_fs2.default.existsSync(manifestPath)) continue;
166
+ try {
167
+ const parsed = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
168
+ if (!parsed || typeof parsed !== "object") continue;
169
+ const manifestDir = _path2.default.basename(_path2.default.dirname(manifestPath)) === ".vite" ? _path2.default.dirname(_path2.default.dirname(manifestPath)) : _path2.default.dirname(manifestPath);
170
+ let matchedViteShape = false;
171
+ for (const val of Object.values(parsed)) {
172
+ if (val && typeof val === "object" && "file" in val && typeof val.file === "string") {
173
+ matchedViteShape = true;
174
+ if (val.isEntry) {
175
+ addManifestEntryCandidates(
176
+ outDir,
177
+ manifestDir,
178
+ val.file,
179
+ entries
180
+ );
181
+ }
182
+ }
183
+ }
184
+ if (matchedViteShape) break;
185
+ } catch (e4) {
186
+ }
187
+ }
188
+ return entries;
189
+ }
190
+ function matchesManifestEntry(relPath, manifestEntries) {
191
+ if (manifestEntries.size === 0) return false;
192
+ for (const candidate of normalizeManifestRel(relPath)) {
193
+ if (manifestEntries.has(candidate)) {
194
+ return true;
195
+ }
196
+ }
197
+ return false;
198
+ }
199
+ function isEntryChunk(relPath, index, allRelPaths, manifestEntries, isWorkerTarget) {
200
+ const norm = relPath.replace(/\\/g, "/");
201
+ const base = _path2.default.basename(norm);
202
+ if (isWorkerTarget && _chunk3GDHYBVHcjs.isWorkerOrServiceWorkerFile.call(void 0, norm)) {
203
+ return true;
204
+ }
205
+ if (matchesManifestEntry(norm, manifestEntries)) {
206
+ return true;
207
+ }
208
+ if (ENTRY_PATTERN.test(norm) || ENTRY_PATTERN.test(base)) {
209
+ return true;
210
+ }
211
+ const hasAnyKnownEntry = allRelPaths.some((p) => {
212
+ const n = p.replace(/\\/g, "/");
213
+ return matchesManifestEntry(n, manifestEntries) || ENTRY_PATTERN.test(n) || ENTRY_PATTERN.test(_path2.default.basename(n));
214
+ });
215
+ if (!hasAnyKnownEntry && index === 0) {
216
+ return true;
217
+ }
218
+ return false;
219
+ }
220
+ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWrites) {
221
+ const candidates = [];
222
+ if (deferVaultWrites) {
223
+ candidates.push(`${filePath}.map`);
224
+ }
225
+ candidates.push(_path2.default.join(vaultDir, `${relPath}.map`));
226
+ const decodedRel = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relPath);
227
+ if (decodedRel !== relPath) {
228
+ candidates.push(_path2.default.join(vaultDir, `${decodedRel}.map`));
229
+ }
230
+ for (const cand of candidates) {
231
+ if (!_fs2.default.existsSync(cand)) continue;
232
+ try {
233
+ const parsed = JSON.parse(_fs2.default.readFileSync(cand, "utf8"));
234
+ if (parsed && typeof parsed === "object") {
235
+ return parsed;
236
+ }
237
+ } catch (e5) {
238
+ }
239
+ }
240
+ return void 0;
241
+ }
242
+ function countPreExistingEvalCalls(code) {
243
+ const hits = [];
244
+ let ast;
245
+ try {
246
+ ast = acorn.parse(code, {
247
+ ecmaVersion: "latest",
248
+ sourceType: "module",
249
+ allowReturnOutsideFunction: true
250
+ });
251
+ } catch (e6) {
252
+ try {
253
+ ast = acorn.parse(code, {
254
+ ecmaVersion: "latest",
255
+ sourceType: "script",
256
+ allowReturnOutsideFunction: true
257
+ });
258
+ } catch (e7) {
259
+ return hits;
260
+ }
261
+ }
262
+ _acornwalk.simple.call(void 0, ast, {
263
+ CallExpression(node) {
264
+ if (node.callee.type === "Identifier") {
265
+ if (node.callee.name === "eval") {
266
+ hits.push("eval(...)");
267
+ } else if (node.callee.name === "Function") {
268
+ hits.push("Function(...)");
269
+ }
270
+ }
271
+ },
272
+ NewExpression(node) {
273
+ if (node.callee.type === "Identifier" && node.callee.name === "Function") {
274
+ hits.push("new Function(...)");
275
+ }
276
+ }
277
+ });
278
+ return hits;
279
+ }
280
+ async function protectProject(options = {}) {
281
+ const startTime = performance.now();
282
+ const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
283
+ const effectiveConfigInput = options.profile ? { ..._nullishCoalesce(options.config, () => ( {})), profile: options.profile } : options.config;
284
+ const config = await _chunkX6EETCO6cjs.loadUnpeekConfig.call(void 0, cwd, effectiveConfigInput);
285
+ const effectiveProfile = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( config.profile)), () => ( "recommended"));
286
+ const { framework, outDir } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
287
+ const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
288
+ const dryRun = Boolean(options.dryRun);
289
+ const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _7 => _7.sourcemaps, 'optionalAccess', _8 => _8.keepPrivate]))), () => ( true));
290
+ const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _9 => _9.sourcemaps, 'optionalAccess', _10 => _10.vaultDir]))), () => ( ".unpeek-maps"));
291
+ const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _11 => _11.shield, 'optionalAccess', _12 => _12.deterrentMode]))), () => ( "passive"));
292
+ const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _13 => _13.shield, 'optionalAccess', _14 => _14.detectHeadless]))), () => ( false));
293
+ const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( (effectiveProfile === "minimal" ? false : true)));
294
+ const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _15 => _15.vault, 'optionalAccess', _16 => _16.minStringLength]))), () => ( 4));
295
+ const aggressive = _nullishCoalesce(options.aggressive, () => ( (effectiveProfile === "strict" ? true : false)));
296
+ const scrubPaths = _nullishCoalesce(_nullishCoalesce(options.scrubPaths, () => ( config.scrubPaths)), () => ( (effectiveProfile === "strict" ? true : false)));
297
+ const masterSym = _chunkM46SFJE7cjs.deriveWindowKeySymbol.call(void 0, seed);
298
+ const masterShield = injectRuntimeShield ? _chunkM46SFJE7cjs.generateRuntimeShield.call(void 0, {
299
+ seed,
300
+ deterrentMode,
301
+ detectHeadless,
302
+ windowKeySymbol: masterSym
303
+ }) : void 0;
304
+ const deferVaultWrites = dryRun || typeof options.maxGzipDelta === "number";
305
+ const vaultResult = _chunk3GDHYBVHcjs.relocateSourceMaps.call(void 0, outDir, cwd, keepPrivateMaps, privateMapsDir, false, config, {
306
+ dryRun: deferVaultWrites
307
+ });
308
+ const clientFiles = _chunk3GDHYBVHcjs.scanClientBundles.call(void 0, outDir, config);
309
+ const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
310
+ const manifestEntries = collectManifestEntryFiles(outDir, cwd, config);
311
+ const isWorkerTarget = config.target === "worker";
312
+ let originalBytes = 0;
313
+ let protectedBytes = 0;
314
+ let totalHotFunctionsSkipped = 0;
315
+ let totalColdFunctionsProtected = 0;
316
+ let totalEncryptedStrings = 0;
317
+ let totalMangledSymbols = 0;
318
+ let processedFiles = 0;
319
+ let debugIdsPreserved = 0;
320
+ const diagnostics = [];
321
+ if (vaultResult.dockerIgnoreMissing) {
322
+ diagnostics.push({
323
+ code: "DOCKERIGNORE_MISSING",
324
+ severity: "warning",
325
+ message: ".dockerignore is missing .unpeek-maps/. Private maps may leak into Docker image during 'COPY . .'."
326
+ });
327
+ }
328
+ const allOrigBufs = [];
329
+ const allProtBufs = [];
330
+ const stagedFiles = [];
331
+ const pendingVaultMaps = [];
332
+ const preExistingEvalFiles = {};
333
+ let alreadyProtectedCount = 0;
334
+ const manifestPath = _path2.default.join(vaultResult.vaultDir, "manifest.json");
335
+ let existingManifest;
336
+ if (!dryRun && _fs2.default.existsSync(manifestPath)) {
337
+ try {
338
+ const parsed = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
339
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
340
+ existingManifest = parsed;
341
+ }
342
+ } catch (e8) {
343
+ }
344
+ }
345
+ let originalGzipBytes = 0;
346
+ let protectedGzipBytes = 0;
347
+ let gzipDeltaPercent = 0;
348
+ let budgetExceeded = false;
349
+ try {
350
+ for (let i = 0; i < clientFiles.length; i++) {
351
+ const filePath = clientFiles[i];
352
+ let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
353
+ const fileDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, codeToTransform);
354
+ if (codeToTransform.includes("sourceMappingURL=")) {
355
+ const strippedRes = _chunk3GDHYBVHcjs.stripSourceMapComments.call(void 0, codeToTransform);
356
+ codeToTransform = strippedRes.code;
357
+ if (strippedRes.stripped) {
358
+ vaultResult.strippedFilesCount++;
359
+ }
360
+ }
361
+ const origBuf = Buffer.from(codeToTransform, "utf8");
362
+ originalBytes += origBuf.byteLength;
363
+ allOrigBufs.push(origBuf);
364
+ const relPath = allRelPaths[i];
365
+ const preExistingHits = countPreExistingEvalCalls(codeToTransform);
366
+ const isEntry = isEntryChunk(relPath, i, allRelPaths, manifestEntries, isWorkerTarget);
367
+ const shouldInjectShield = injectRuntimeShield && isEntry;
368
+ const fileSeed = _chunkM46SFJE7cjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
369
+ const transformOptions = {
370
+ seed: fileSeed,
371
+ minStringLength,
372
+ filename: _path2.default.basename(filePath),
373
+ injectRuntimeShield: shouldInjectShield,
374
+ skipShieldPreamble: true,
375
+ shieldCoupled: injectRuntimeShield,
376
+ windowKeySymbol: masterSym,
377
+ expectedDelta: _optionalChain([masterShield, 'optionalAccess', _17 => _17.expectedDelta]),
378
+ deterrentMode,
379
+ detectHeadless,
380
+ aggressive,
381
+ scrubPaths,
382
+ config
383
+ };
384
+ transformOptions.generateMap = keepPrivateMaps;
385
+ transformOptions.rootDir = cwd;
386
+ const result = _chunkM46SFJE7cjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
387
+ if (result.skippedReason === "parse-error") {
388
+ diagnostics.push({
389
+ code: "PARSE_FALLBACK",
390
+ severity: "warning",
391
+ message: `Skipped AST transform due to parse error in "${relPath}".`,
392
+ file: relPath
393
+ });
394
+ } else if (result.skippedReason === "already-protected") {
395
+ alreadyProtectedCount++;
396
+ const prevHits = _optionalChain([existingManifest, 'optionalAccess', _18 => _18.preExistingEvalFiles, 'optionalAccess', _19 => _19[relPath]]);
397
+ if (Array.isArray(prevHits) && prevHits.length > 0) {
398
+ preExistingEvalFiles[relPath] = prevHits;
399
+ } else if (preExistingHits.length > 0) {
400
+ preExistingEvalFiles[relPath] = preExistingHits;
401
+ }
402
+ diagnostics.push({
403
+ code: "ALREADY_PROTECTED",
404
+ severity: "info",
405
+ message: `File "${relPath}" is already protected.`,
406
+ file: relPath
407
+ });
408
+ } else if (result.skippedReason === "empty") {
409
+ diagnostics.push({
410
+ code: "EMPTY_INPUT",
411
+ severity: "info",
412
+ message: `File "${relPath}" is empty.`,
413
+ file: relPath
414
+ });
415
+ } else if (preExistingHits.length > 0) {
416
+ preExistingEvalFiles[relPath] = preExistingHits;
417
+ }
418
+ let finalCode = result.code;
419
+ let preambleLineOffset = 0;
420
+ if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _20 => _20.preambleCode]) && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
421
+ const prefix = `${masterShield.preambleCode}
422
+ `;
423
+ preambleLineOffset = (_nullishCoalesce(prefix.match(/\n/g), () => ( []))).length;
424
+ finalCode = `${prefix}${finalCode}`;
425
+ }
426
+ const originalMap = keepPrivateMaps ? readOriginalSourceMapForFile(filePath, relPath, vaultResult.vaultDir, deferVaultWrites) : void 0;
427
+ const rawTransformMap = result.sourceMap;
428
+ const shiftedTransformMap = rawTransformMap ? _chunk3GDHYBVHcjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
429
+ let composedMap;
430
+ if (shiftedTransformMap && originalMap) {
431
+ composedMap = _chunk3GDHYBVHcjs.chainSourceMaps.call(void 0, shiftedTransformMap, originalMap);
432
+ } else if (originalMap) {
433
+ composedMap = _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, originalMap);
434
+ } else if (shiftedTransformMap) {
435
+ composedMap = shiftedTransformMap;
436
+ }
437
+ const originalMapDebugId = _nullishCoalesce(_optionalChain([originalMap, 'optionalAccess', _21 => _21.debugId]), () => ( _optionalChain([originalMap, 'optionalAccess', _22 => _22.debug_id])));
438
+ const hadDebugId = Boolean(fileDebugId || originalMapDebugId || result.debugId);
439
+ let mintedDebugId;
440
+ if (hadDebugId) {
441
+ const codeWithoutDebugId = _chunk3GDHYBVHcjs.stripDebugIdComments.call(void 0, finalCode);
442
+ mintedDebugId = _chunk3GDHYBVHcjs.computeDeterministicDebugId.call(void 0,
443
+ codeWithoutDebugId,
444
+ _nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _23 => _23.mappings]), () => ( ""))
445
+ );
446
+ finalCode = _chunk3GDHYBVHcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
447
+ if (composedMap) {
448
+ composedMap.debugId = mintedDebugId;
449
+ delete composedMap.debug_id;
450
+ }
451
+ debugIdsPreserved++;
452
+ }
453
+ if (!dryRun && keepPrivateMaps && (composedMap || mintedDebugId)) {
454
+ pendingVaultMaps.push({ relPath, map: composedMap, debugId: mintedDebugId });
455
+ }
456
+ if (!dryRun) {
457
+ const tmpPath = `${filePath}.unpeek.tmp`;
458
+ _fs2.default.writeFileSync(tmpPath, finalCode, "utf8");
459
+ stagedFiles.push({ tmpPath, finalPath: filePath });
460
+ }
461
+ const protBuf = Buffer.from(finalCode, "utf8");
462
+ protectedBytes += protBuf.byteLength;
463
+ allProtBufs.push(protBuf);
464
+ totalHotFunctionsSkipped += result.hotPathReport.hotFunctionsSkipped.length;
465
+ totalColdFunctionsProtected += result.hotPathReport.coldFunctionsProtected.length;
466
+ totalEncryptedStrings += result.encryptedStringsCount;
467
+ totalMangledSymbols += result.mangledSymbolsCount;
468
+ processedFiles++;
469
+ }
470
+ originalGzipBytes = allOrigBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allOrigBufs)).byteLength : 0;
471
+ protectedGzipBytes = allProtBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allProtBufs)).byteLength : 0;
472
+ gzipDeltaPercent = originalGzipBytes > 0 ? Number(((protectedGzipBytes - originalGzipBytes) / originalGzipBytes * 100).toFixed(2)) : 0;
473
+ budgetExceeded = typeof options.maxGzipDelta === "number" && gzipDeltaPercent > options.maxGzipDelta;
474
+ if (budgetExceeded && !dryRun) {
475
+ throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
476
+ "ERR_BUDGET_EXCEEDED",
477
+ `Protected bundle Gzip delta (${gzipDeltaPercent}%) exceeded maxGzipDelta (${options.maxGzipDelta}%).`
478
+ );
479
+ }
480
+ if (!dryRun) {
481
+ if (deferVaultWrites) {
482
+ const finalVaultResult = _chunk3GDHYBVHcjs.relocateSourceMaps.call(void 0,
483
+ outDir,
484
+ cwd,
485
+ keepPrivateMaps,
486
+ privateMapsDir,
487
+ false,
488
+ config,
489
+ { dryRun: false }
490
+ );
491
+ vaultResult.movedMapsCount = finalVaultResult.movedMapsCount;
492
+ vaultResult.vaultDir = finalVaultResult.vaultDir;
493
+ vaultResult.movedFiles = finalVaultResult.movedFiles;
494
+ vaultResult.dockerIgnoreMissing = finalVaultResult.dockerIgnoreMissing;
495
+ }
496
+ for (const { relPath, map, debugId } of pendingVaultMaps) {
497
+ const vaultedMapPath = _path2.default.join(vaultResult.vaultDir, `${relPath}.map`);
498
+ const decodedMapPath = _path2.default.join(
499
+ vaultResult.vaultDir,
500
+ `${_chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relPath)}.map`
501
+ );
502
+ const targetMapPath = _fs2.default.existsSync(vaultedMapPath) ? vaultedMapPath : _fs2.default.existsSync(decodedMapPath) ? decodedMapPath : vaultedMapPath;
503
+ if (map && _fs2.default.existsSync(targetMapPath)) {
504
+ try {
505
+ _fs2.default.writeFileSync(targetMapPath, JSON.stringify(map), "utf8");
506
+ } catch (e9) {
507
+ }
508
+ } else if (debugId && _fs2.default.existsSync(targetMapPath)) {
509
+ try {
510
+ const mapJson = JSON.parse(_fs2.default.readFileSync(targetMapPath, "utf8"));
511
+ mapJson.debugId = debugId;
512
+ delete mapJson.debug_id;
513
+ _fs2.default.writeFileSync(targetMapPath, JSON.stringify(mapJson), "utf8");
514
+ } catch (e10) {
515
+ }
516
+ }
517
+ }
518
+ for (const { tmpPath, finalPath } of stagedFiles) {
519
+ _fs2.default.renameSync(tmpPath, finalPath);
520
+ }
521
+ const relVault = _path2.default.relative(cwd, vaultResult.vaultDir);
522
+ const isSafeVaultDir = relVault === "" || !relVault.startsWith("..") && !_path2.default.isAbsolute(relVault);
523
+ if (isSafeVaultDir) {
524
+ const relOutDir = _path2.default.relative(cwd, outDir).replace(/\\/g, "/") || ".";
525
+ const manifestPayload = processedFiles > 0 && alreadyProtectedCount === processedFiles && existingManifest ? {
526
+ version: 1,
527
+ outDir: _nullishCoalesce(existingManifest.outDir, () => ( relOutDir)),
528
+ originalGzipBytes: _nullishCoalesce(existingManifest.originalGzipBytes, () => ( originalGzipBytes)),
529
+ protectedGzipBytes: _nullishCoalesce(existingManifest.protectedGzipBytes, () => ( protectedGzipBytes)),
530
+ gzipDeltaPercent: _nullishCoalesce(existingManifest.gzipDeltaPercent, () => ( gzipDeltaPercent)),
531
+ preExistingEvalFiles: {
532
+ ..._nullishCoalesce(existingManifest.preExistingEvalFiles, () => ( {})),
533
+ ...preExistingEvalFiles
534
+ }
535
+ } : {
536
+ version: 1,
537
+ outDir: relOutDir,
538
+ originalGzipBytes,
539
+ protectedGzipBytes,
540
+ gzipDeltaPercent,
541
+ preExistingEvalFiles
542
+ };
543
+ try {
544
+ _fs2.default.mkdirSync(vaultResult.vaultDir, { recursive: true });
545
+ _fs2.default.writeFileSync(manifestPath, JSON.stringify(manifestPayload, null, 2), "utf8");
546
+ } catch (e11) {
547
+ }
548
+ }
549
+ }
550
+ } catch (error) {
551
+ for (const { tmpPath } of stagedFiles) {
552
+ if (_fs2.default.existsSync(tmpPath)) {
553
+ try {
554
+ _fs2.default.unlinkSync(tmpPath);
555
+ } catch (e12) {
556
+ }
557
+ }
558
+ }
559
+ throw error;
560
+ }
561
+ const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
562
+ const resolvedTier = _nullishCoalesce(options.tier, () => ( (effectiveProfile === "strict" || aggressive ? "Tier 3" : effectiveProfile === "minimal" ? "Tier 1" : _nullishCoalesce(config.tier, () => ( "Tier 2")))));
563
+ return {
564
+ framework,
565
+ outDir,
566
+ processedFiles,
567
+ movedSourceMaps: vaultResult.movedMapsCount,
568
+ originalBytes,
569
+ protectedBytes,
570
+ originalGzipBytes,
571
+ protectedGzipBytes,
572
+ gzipDeltaPercent,
573
+ totalHotFunctionsSkipped,
574
+ totalColdFunctionsProtected,
575
+ totalEncryptedStrings,
576
+ totalMangledSymbols,
577
+ elapsedMs,
578
+ seed,
579
+ tier: resolvedTier,
580
+ aggressive,
581
+ dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
582
+ dryRun,
583
+ profile: effectiveProfile,
584
+ budgetExceeded,
585
+ debugIdsPreserved,
586
+ diagnostics
587
+ };
588
+ }
589
+
590
+
591
+
592
+
593
+
594
+
595
+ exports.isNext16OrAbove = isNext16OrAbove; exports.serializeNextOptions = serializeNextOptions; exports.readUnpeekNextOptionsFromEnv = readUnpeekNextOptionsFromEnv; exports.protectProject = protectProject;
@@ -2,13 +2,15 @@
2
2
  var PRESETS = {
3
3
  minimal: {
4
4
  profile: "minimal",
5
+ tier: "Tier 1",
5
6
  target: "browser",
7
+ coldFlow: false,
6
8
  vault: {
7
9
  minStringLength: Number.MAX_SAFE_INTEGER,
8
10
  polymorphicDecoys: false
9
11
  },
10
12
  mangler: {
11
- minLength: 3
13
+ minLength: 1
12
14
  },
13
15
  shield: {
14
16
  detectHeadless: false,
@@ -23,7 +25,9 @@ var PRESETS = {
23
25
  },
24
26
  recommended: {
25
27
  profile: "recommended",
28
+ tier: "Tier 2",
26
29
  target: "browser",
30
+ coldFlow: true,
27
31
  vault: {
28
32
  minStringLength: 4,
29
33
  cssFramework: "tailwind",
@@ -33,7 +37,7 @@ var PRESETS = {
33
37
  polymorphicDecoys: true
34
38
  },
35
39
  mangler: {
36
- minLength: 3
40
+ minLength: 1
37
41
  },
38
42
  shield: {
39
43
  detectHeadless: false,
@@ -48,7 +52,12 @@ var PRESETS = {
48
52
  },
49
53
  strict: {
50
54
  profile: "strict",
55
+ tier: "Tier 3",
51
56
  target: "browser",
57
+ coldFlow: true,
58
+ critical: {
59
+ annotation: "@unpeek-critical"
60
+ },
52
61
  vault: {
53
62
  minStringLength: 4,
54
63
  cssFramework: "tailwind",
@@ -60,7 +69,7 @@ var PRESETS = {
60
69
  fragmentCount: 4
61
70
  },
62
71
  mangler: {
63
- minLength: 3
72
+ minLength: 1
64
73
  },
65
74
  shield: {
66
75
  detectHeadless: true,