unpeek 3.0.0 → 4.0.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/README.md +27 -13
- package/README.tr.md +37 -23
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.d.cts +3 -1
- package/dist/adapters/esbuild.d.ts +2 -2
- package/dist/adapters/esbuild.js +5 -3
- package/dist/adapters/next/adapter.cjs +7 -6
- package/dist/adapters/next/adapter.d.cts +1 -1
- package/dist/adapters/next/adapter.d.ts +1 -1
- package/dist/adapters/next/adapter.js +6 -5
- package/dist/adapters/next/index.cjs +7 -6
- package/dist/adapters/next/index.js +6 -5
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.d.cts +3 -1
- package/dist/adapters/rollup.d.ts +2 -2
- package/dist/adapters/rollup.js +5 -3
- package/dist/adapters/rspack.cjs +5 -4
- package/dist/adapters/rspack.d.cts +1 -1
- package/dist/adapters/rspack.d.ts +1 -1
- package/dist/adapters/rspack.js +3 -2
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.d.cts +3 -1
- package/dist/adapters/vite.d.ts +2 -2
- package/dist/adapters/vite.js +5 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.d.cts +3 -1
- package/dist/adapters/webpack.d.ts +2 -2
- package/dist/adapters/webpack.js +5 -3
- package/dist/browser.cjs +3 -3
- package/dist/browser.d.cts +20 -17
- package/dist/browser.d.ts +20 -17
- package/dist/browser.js +2 -2
- package/dist/{chunk-BPRSCRUZ.js → chunk-2JU3V7HW.js} +6 -3
- package/dist/chunk-3LWXEJU6.cjs +1054 -0
- package/dist/{chunk-IZIWDJRF.js → chunk-4FNZNIBW.js} +2675 -651
- package/dist/chunk-7HXLHLLQ.cjs +503 -0
- package/dist/chunk-ADKRENAP.js +1054 -0
- package/dist/{chunk-FCF2EGPM.js → chunk-EN6QVR6P.js} +12 -3
- package/dist/chunk-HHC7BUCK.js +503 -0
- package/dist/{chunk-IAD5DV3D.cjs → chunk-KLYFNMKS.cjs} +2812 -788
- package/dist/{chunk-IEBVL5BT.cjs → chunk-URPPSTHZ.cjs} +12 -3
- package/dist/chunk-VG4Y26ZN.cjs +429 -0
- package/dist/{chunk-IICVBTR2.js → chunk-W77DAC3H.js} +22 -3
- package/dist/{chunk-ONM2CSTU.cjs → chunk-X6EETCO6.cjs} +64 -45
- package/dist/chunk-YCRMTXOE.js +429 -0
- package/dist/{chunk-6TDCSIRZ.cjs → chunk-ZG7BIAUI.cjs} +9 -6
- package/dist/cli/index.js +3693 -1141
- package/dist/{config-CfXY_iDD.d.ts → config-Y6JwVGwX.d.cts} +15 -1
- package/dist/{config-CfXY_iDD.d.cts → config-Y6JwVGwX.d.ts} +15 -1
- package/dist/config.cjs +3 -3
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/{index-CjRTNPlj.d.cts → index-0O1WSfVP.d.ts} +7 -1
- package/dist/{index-Cm1IloVm.d.ts → index-COVHErnx.d.cts} +7 -1
- package/dist/index.cjs +65 -264
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +59 -258
- package/dist/plugins/unplugin.cjs +4 -3
- package/dist/plugins/unplugin.js +3 -2
- package/dist/{types-DYQIzGf6.d.cts → types-CMtZnV8C.d.ts} +3 -3
- package/dist/{types-ZHAFdOd3.d.ts → types-D93PuOOl.d.cts} +3 -3
- package/package.json +1 -1
- package/dist/chunk-APWMNVAZ.js +0 -764
- package/dist/chunk-DUK2SECY.js +0 -83
- package/dist/chunk-I6GXEHFR.cjs +0 -764
- package/dist/chunk-RXUY3MPH.cjs +0 -83
package/dist/chunk-I6GXEHFR.cjs
DELETED
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkONM2CSTUcjs = require('./chunk-ONM2CSTU.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkIAD5DV3Dcjs = require('./chunk-IAD5DV3D.cjs');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
|
|
13
|
-
|
|
14
|
-
// src/internal/next.ts
|
|
15
|
-
function isNext16OrAbove(versionStr) {
|
|
16
|
-
if (!versionStr) return false;
|
|
17
|
-
const clean = versionStr.replace(/^[^\d]*/, "");
|
|
18
|
-
const match = clean.match(/^(\d+)\.(\d+)/);
|
|
19
|
-
if (!match) return false;
|
|
20
|
-
const major = parseInt(match[1], 10);
|
|
21
|
-
const minor = parseInt(match[2], 10);
|
|
22
|
-
if (major > 16) return true;
|
|
23
|
-
if (major === 16 && minor >= 2) return true;
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
function isSerializedRegExp(val) {
|
|
27
|
-
if (typeof val !== "object" || val === null) return false;
|
|
28
|
-
const record = val;
|
|
29
|
-
return record.__unpeekRegExp === true && typeof record.source === "string" && typeof record.flags === "string";
|
|
30
|
-
}
|
|
31
|
-
function serializeNextOptions(options) {
|
|
32
|
-
return JSON.stringify(options, (_key, value) => {
|
|
33
|
-
if (value instanceof RegExp) {
|
|
34
|
-
return {
|
|
35
|
-
__unpeekRegExp: true,
|
|
36
|
-
source: value.source,
|
|
37
|
-
flags: value.flags
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function parseNextOptions(raw) {
|
|
44
|
-
return JSON.parse(raw, (_key, value) => {
|
|
45
|
-
if (isSerializedRegExp(value)) {
|
|
46
|
-
try {
|
|
47
|
-
return new RegExp(value.source, value.flags);
|
|
48
|
-
} catch (e2) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function readUnpeekNextOptionsFromEnv() {
|
|
56
|
-
const raw = process.env.UNPEEK_NEXT_OPTIONS;
|
|
57
|
-
if (!raw) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const parsed = parseNextOptions(raw);
|
|
62
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
63
|
-
return parsed;
|
|
64
|
-
}
|
|
65
|
-
} catch (e3) {
|
|
66
|
-
}
|
|
67
|
-
return void 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/core/protect.ts
|
|
71
|
-
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
72
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
73
|
-
var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib);
|
|
74
|
-
|
|
75
|
-
// src/core/detector.ts
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
79
|
-
var EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
80
|
-
"node_modules",
|
|
81
|
-
".unpeek-maps"
|
|
82
|
-
]);
|
|
83
|
-
var NEXT_CONFIG_FILES = ["next.config.ts", "next.config.js", "next.config.mjs", "next.config.cjs"];
|
|
84
|
-
var VITE_CONFIG_FILES = ["vite.config.ts", "vite.config.js", "vite.config.mjs", "vite.config.cjs"];
|
|
85
|
-
function escapeRegex(str) {
|
|
86
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
87
|
-
}
|
|
88
|
-
function extractConfigValue(rootDir, filenames, pattern) {
|
|
89
|
-
for (const filename of filenames) {
|
|
90
|
-
const filePath = _path2.default.join(rootDir, filename);
|
|
91
|
-
if (_fs2.default.existsSync(filePath)) {
|
|
92
|
-
try {
|
|
93
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
94
|
-
const match = content.match(pattern);
|
|
95
|
-
if (match && match[1]) {
|
|
96
|
-
return match[1].trim();
|
|
97
|
-
}
|
|
98
|
-
} catch (e4) {
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return void 0;
|
|
103
|
-
}
|
|
104
|
-
function hasNextServerSegment(fullPath, rootDir, serverDirPrefixes) {
|
|
105
|
-
const normalized = fullPath.replace(/\\/g, "/");
|
|
106
|
-
if (normalized.includes("/node_modules/") || normalized.endsWith("/node_modules") || normalized.includes("/.unpeek-maps/") || normalized.endsWith("/.unpeek-maps")) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
if (/(?:^|\/)\.next\/(?:server|ssr)(?:\/|$)/i.test(normalized)) {
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
if (serverDirPrefixes && serverDirPrefixes.length > 0) {
|
|
113
|
-
for (const prefix of serverDirPrefixes) {
|
|
114
|
-
const normPrefix = prefix.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
115
|
-
if (normPrefix) {
|
|
116
|
-
const regex = new RegExp(`(?:^|\\/)${escapeRegex(normPrefix)}(?:\\/|$)`, "i");
|
|
117
|
-
if (regex.test(normalized)) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (rootDir) {
|
|
124
|
-
const rel = _path2.default.relative(rootDir, fullPath).replace(/\\/g, "/");
|
|
125
|
-
const segments = rel.split("/").filter(Boolean);
|
|
126
|
-
if (segments.length > 0 && (segments[0].toLowerCase() === "server" || segments[0].toLowerCase() === "ssr")) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
133
|
-
let config = explicitConfig;
|
|
134
|
-
let outDirOverride;
|
|
135
|
-
if (typeof explicitOutDir === "object" && explicitOutDir !== null) {
|
|
136
|
-
config = explicitOutDir;
|
|
137
|
-
outDirOverride = config.outDir;
|
|
138
|
-
} else if (typeof explicitOutDir === "string") {
|
|
139
|
-
outDirOverride = explicitOutDir;
|
|
140
|
-
}
|
|
141
|
-
const rootDir = _path2.default.resolve(cwd);
|
|
142
|
-
let framework = _optionalChain([config, 'optionalAccess', _ => _.framework]);
|
|
143
|
-
const discoveredNextDist = extractConfigValue(
|
|
144
|
-
rootDir,
|
|
145
|
-
NEXT_CONFIG_FILES,
|
|
146
|
-
/(?:["']?distDir["']?\s*:\s*["']([^"']+)["'])/
|
|
147
|
-
);
|
|
148
|
-
const discoveredViteOut = extractConfigValue(
|
|
149
|
-
rootDir,
|
|
150
|
-
VITE_CONFIG_FILES,
|
|
151
|
-
/(?:["']?outDir["']?\s*:\s*["']([^"']+)["'])/
|
|
152
|
-
);
|
|
153
|
-
const discoveredViteAssets = extractConfigValue(
|
|
154
|
-
rootDir,
|
|
155
|
-
VITE_CONFIG_FILES,
|
|
156
|
-
/(?:["']?assetsDir["']?\s*:\s*["']([^"']+)["'])/
|
|
157
|
-
);
|
|
158
|
-
const nextDist = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _2 => _2.next, 'optionalAccess', _3 => _3.distDir]), () => ( discoveredNextDist)), () => ( ".next"));
|
|
159
|
-
const viteOut = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _4 => _4.vite, 'optionalAccess', _5 => _5.outDir]), () => ( discoveredViteOut)), () => ( "dist"));
|
|
160
|
-
const viteAssets = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _6 => _6.vite, 'optionalAccess', _7 => _7.assetsDir]), () => ( discoveredViteAssets)), () => ( "assets"));
|
|
161
|
-
if (!framework) {
|
|
162
|
-
const pkgPath = _path2.default.join(rootDir, "package.json");
|
|
163
|
-
if (_fs2.default.existsSync(pkgPath)) {
|
|
164
|
-
try {
|
|
165
|
-
const pkgRaw = _fs2.default.readFileSync(pkgPath, "utf8");
|
|
166
|
-
const pkg = JSON.parse(pkgRaw);
|
|
167
|
-
const allDeps = {
|
|
168
|
-
..._nullishCoalesce(pkg.dependencies, () => ( {})),
|
|
169
|
-
..._nullishCoalesce(pkg.devDependencies, () => ( {}))
|
|
170
|
-
};
|
|
171
|
-
if ("next" in allDeps) {
|
|
172
|
-
framework = "nextjs";
|
|
173
|
-
} else if ("vite" in allDeps) {
|
|
174
|
-
framework = "vite";
|
|
175
|
-
} else if ("webpack" in allDeps || "react-scripts" in allDeps || "@rspack/core" in allDeps) {
|
|
176
|
-
framework = "webpack";
|
|
177
|
-
}
|
|
178
|
-
} catch (e5) {
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const nextChunksDir = _path2.default.join(rootDir, nextDist, "static", "chunks");
|
|
183
|
-
const nextExportChunksDir = _path2.default.join(rootDir, "out", "_next", "static", "chunks");
|
|
184
|
-
const nextExportDir = _path2.default.join(rootDir, "out");
|
|
185
|
-
const nextDistDir = _path2.default.join(rootDir, nextDist);
|
|
186
|
-
const distAssetsDir = _path2.default.join(rootDir, viteOut, viteAssets);
|
|
187
|
-
const distDir = _path2.default.join(rootDir, viteOut);
|
|
188
|
-
const buildDir = _path2.default.join(rootDir, "build");
|
|
189
|
-
const publicDir = _path2.default.join(rootDir, "public");
|
|
190
|
-
if (!framework) {
|
|
191
|
-
if (_fs2.default.existsSync(nextChunksDir) || _fs2.default.existsSync(nextDistDir) || _fs2.default.existsSync(nextExportChunksDir) || discoveredNextDist !== void 0) {
|
|
192
|
-
framework = "nextjs";
|
|
193
|
-
} else if (_fs2.default.existsSync(distAssetsDir) || discoveredViteOut !== void 0) {
|
|
194
|
-
framework = "vite";
|
|
195
|
-
} else if (_fs2.default.existsSync(buildDir)) {
|
|
196
|
-
framework = "webpack";
|
|
197
|
-
} else if (outDirOverride) {
|
|
198
|
-
const normExplicit = outDirOverride.replace(/\\/g, "/");
|
|
199
|
-
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next")) {
|
|
200
|
-
framework = "nextjs";
|
|
201
|
-
} else if (normExplicit.includes(`${viteOut}/${viteAssets}`) || normExplicit.includes("dist/assets")) {
|
|
202
|
-
framework = "vite";
|
|
203
|
-
} else if (normExplicit.includes("build")) {
|
|
204
|
-
framework = "webpack";
|
|
205
|
-
} else {
|
|
206
|
-
framework = "vanilla";
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
framework = "vanilla";
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (outDirOverride) {
|
|
213
|
-
return {
|
|
214
|
-
framework,
|
|
215
|
-
outDir: _path2.default.resolve(rootDir, outDirOverride)
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
let outDir;
|
|
219
|
-
if (framework === "nextjs") {
|
|
220
|
-
if (_fs2.default.existsSync(nextExportChunksDir)) {
|
|
221
|
-
outDir = nextExportChunksDir;
|
|
222
|
-
} else if (_fs2.default.existsSync(nextChunksDir)) {
|
|
223
|
-
outDir = nextChunksDir;
|
|
224
|
-
} else if (_fs2.default.existsSync(nextExportDir)) {
|
|
225
|
-
outDir = nextExportDir;
|
|
226
|
-
} else if (_fs2.default.existsSync(nextDistDir)) {
|
|
227
|
-
outDir = nextChunksDir;
|
|
228
|
-
} else {
|
|
229
|
-
outDir = nextChunksDir;
|
|
230
|
-
}
|
|
231
|
-
} else if (framework === "vite") {
|
|
232
|
-
outDir = _fs2.default.existsSync(distAssetsDir) ? distAssetsDir : distDir;
|
|
233
|
-
} else if (framework === "webpack") {
|
|
234
|
-
if (_fs2.default.existsSync(distDir)) {
|
|
235
|
-
outDir = distDir;
|
|
236
|
-
} else if (_fs2.default.existsSync(buildDir)) {
|
|
237
|
-
outDir = buildDir;
|
|
238
|
-
} else {
|
|
239
|
-
outDir = distDir;
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
const candidates = [nextExportChunksDir, nextChunksDir, distAssetsDir, distDir, buildDir, publicDir];
|
|
243
|
-
const existing = candidates.find((candidate) => _fs2.default.existsSync(candidate));
|
|
244
|
-
outDir = _nullishCoalesce(existing, () => ( distDir));
|
|
245
|
-
}
|
|
246
|
-
return { framework, outDir };
|
|
247
|
-
}
|
|
248
|
-
function scanClientBundles(outDir, config) {
|
|
249
|
-
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
250
|
-
if (!_fs2.default.existsSync(resolvedOutDir)) {
|
|
251
|
-
return [];
|
|
252
|
-
}
|
|
253
|
-
const results = [];
|
|
254
|
-
const serverDirPrefixes = [];
|
|
255
|
-
if (_optionalChain([config, 'optionalAccess', _8 => _8.next, 'optionalAccess', _9 => _9.distDir])) {
|
|
256
|
-
serverDirPrefixes.push(
|
|
257
|
-
_path2.default.join(config.next.distDir, "server"),
|
|
258
|
-
_path2.default.join(config.next.distDir, "ssr")
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
if (_optionalChain([config, 'optionalAccess', _10 => _10.vite, 'optionalAccess', _11 => _11.outDir])) {
|
|
262
|
-
serverDirPrefixes.push(_path2.default.join(config.vite.outDir, "server"));
|
|
263
|
-
}
|
|
264
|
-
const allowedExtensions = _optionalChain([config, 'optionalAccess', _12 => _12.extensions]) && config.extensions.length > 0 ? new Set(config.extensions.map((e) => e.startsWith(".") ? e.toLowerCase() : `.${e.toLowerCase()}`)) : SUPPORTED_EXTENSIONS;
|
|
265
|
-
function walk(currentDir) {
|
|
266
|
-
if (hasNextServerSegment(currentDir, resolvedOutDir, serverDirPrefixes)) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
let entries;
|
|
270
|
-
try {
|
|
271
|
-
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
272
|
-
} catch (e6) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
for (const entry of entries) {
|
|
276
|
-
const fullPath = _path2.default.join(currentDir, entry.name);
|
|
277
|
-
if (entry.isDirectory()) {
|
|
278
|
-
if (EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) {
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
walk(fullPath);
|
|
285
|
-
} else if (entry.isFile()) {
|
|
286
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
const ext = _path2.default.extname(entry.name).toLowerCase();
|
|
290
|
-
if (allowedExtensions.has(ext)) {
|
|
291
|
-
results.push(fullPath);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
walk(resolvedOutDir);
|
|
297
|
-
return results.sort();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// src/core/sourcemap-vault.ts
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
var SOURCE_MAP_COMMENT_REGEX = /(?:^\s*\/\/[#@]\s*sourceMappingURL=.*$|\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/)\s*/gm;
|
|
304
|
-
var DEBUG_ID_COMMENT_REGEX = /(?:\/\/[#@]\s*debugId=([^\s*]+)|\/\*[#@]\s*debugId=([^\s*]+)\s*\*\/)/;
|
|
305
|
-
function extractDebugId(code) {
|
|
306
|
-
const match = code.match(DEBUG_ID_COMMENT_REGEX);
|
|
307
|
-
const id = _nullishCoalesce(_optionalChain([match, 'optionalAccess', _13 => _13[1]]), () => ( _optionalChain([match, 'optionalAccess', _14 => _14[2]])));
|
|
308
|
-
return id ? id.trim() : void 0;
|
|
309
|
-
}
|
|
310
|
-
function stripSourceMapComments(code) {
|
|
311
|
-
const debugId = extractDebugId(code);
|
|
312
|
-
SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
|
|
313
|
-
let next = code.replace(SOURCE_MAP_COMMENT_REGEX, "");
|
|
314
|
-
const stripped = next !== code;
|
|
315
|
-
if (debugId && !DEBUG_ID_COMMENT_REGEX.test(next)) {
|
|
316
|
-
const suffix = next.length > 0 && !next.endsWith("\n") ? "\n" : "";
|
|
317
|
-
next = `${next}${suffix}//# debugId=${debugId}
|
|
318
|
-
`;
|
|
319
|
-
}
|
|
320
|
-
return { code: next, stripped, debugId };
|
|
321
|
-
}
|
|
322
|
-
function ensureIgnoreEntry(dir, fileName, entryName) {
|
|
323
|
-
const filePath = _path2.default.join(_path2.default.resolve(dir), fileName);
|
|
324
|
-
if (!_fs2.default.existsSync(filePath)) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
328
|
-
const normalizedEntry = entryName.endsWith("/") ? entryName : `${entryName}/`;
|
|
329
|
-
const bareEntry = normalizedEntry.slice(0, -1);
|
|
330
|
-
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
331
|
-
if (!lines.includes(normalizedEntry) && !lines.includes(bareEntry) && !lines.includes(".unpeek-maps") && !lines.includes(".unpeek-maps/")) {
|
|
332
|
-
const prefix = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
333
|
-
_fs2.default.writeFileSync(filePath, `${content}${prefix}${normalizedEntry}
|
|
334
|
-
`, "utf8");
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function isSubdirectoryOrSame(parent, child) {
|
|
338
|
-
const rel = _path2.default.relative(parent, child);
|
|
339
|
-
return rel === "" || !rel.startsWith("..") && !_path2.default.isAbsolute(rel);
|
|
340
|
-
}
|
|
341
|
-
function findMonorepoRoots(cwd) {
|
|
342
|
-
const resolved = _path2.default.resolve(cwd);
|
|
343
|
-
const dirs = [resolved];
|
|
344
|
-
let curr = resolved;
|
|
345
|
-
while (true) {
|
|
346
|
-
const parent = _path2.default.dirname(curr);
|
|
347
|
-
if (!parent || parent === curr) {
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
const hasGit = _fs2.default.existsSync(_path2.default.join(parent, ".git"));
|
|
351
|
-
const hasWorkspace = _fs2.default.existsSync(_path2.default.join(parent, "pnpm-workspace.yaml"));
|
|
352
|
-
const hasGitIgnore = _fs2.default.existsSync(_path2.default.join(parent, ".gitignore"));
|
|
353
|
-
const hasDockerIgnore = _fs2.default.existsSync(_path2.default.join(parent, ".dockerignore"));
|
|
354
|
-
const hasPkgJson = _fs2.default.existsSync(_path2.default.join(parent, "package.json"));
|
|
355
|
-
if (hasGit || hasWorkspace || hasGitIgnore || hasDockerIgnore || hasPkgJson) {
|
|
356
|
-
dirs.push(parent);
|
|
357
|
-
}
|
|
358
|
-
if (hasGit || hasWorkspace) {
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
curr = parent;
|
|
362
|
-
}
|
|
363
|
-
return dirs;
|
|
364
|
-
}
|
|
365
|
-
function checkDockerIgnoreMissing(cwd, ignoreEntry) {
|
|
366
|
-
const candidateDirs = findMonorepoRoots(cwd);
|
|
367
|
-
let foundAnyDockerIgnore = false;
|
|
368
|
-
for (const dir of candidateDirs) {
|
|
369
|
-
const filePath = _path2.default.join(dir, ".dockerignore");
|
|
370
|
-
if (_fs2.default.existsSync(filePath)) {
|
|
371
|
-
foundAnyDockerIgnore = true;
|
|
372
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
373
|
-
const normalizedEntry = ignoreEntry.endsWith("/") ? ignoreEntry : `${ignoreEntry}/`;
|
|
374
|
-
const bareEntry = normalizedEntry.slice(0, -1);
|
|
375
|
-
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
376
|
-
if (lines.includes(normalizedEntry) || lines.includes(bareEntry) || lines.includes(".unpeek-maps") || lines.includes(".unpeek-maps/")) {
|
|
377
|
-
return false;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
function updateAllIgnoreFiles(cwd, vaultDir) {
|
|
384
|
-
const candidateDirs = findMonorepoRoots(cwd);
|
|
385
|
-
for (const dir of candidateDirs) {
|
|
386
|
-
const relFromDir = _path2.default.relative(dir, vaultDir).replace(/\\/g, "/");
|
|
387
|
-
const entry = relFromDir && !relFromDir.startsWith("..") ? `${relFromDir}/` : ".unpeek-maps/";
|
|
388
|
-
ensureIgnoreEntry(dir, ".gitignore", entry);
|
|
389
|
-
ensureIgnoreEntry(dir, ".dockerignore", entry);
|
|
390
|
-
ensureIgnoreEntry(dir, ".npmignore", entry);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir = ".unpeek-maps", stripComments = true, config, options) {
|
|
394
|
-
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
395
|
-
const resolvedCwd = _path2.default.resolve(cwd);
|
|
396
|
-
const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _15 => _15.sourcemaps, 'optionalAccess', _16 => _16.vaultDir]), () => ( privateMapsDir)), () => ( ".unpeek-maps"));
|
|
397
|
-
const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _17 => _17.sourcemaps, 'optionalAccess', _18 => _18.keepPrivate]), () => ( keepPrivateMaps));
|
|
398
|
-
const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _19 => _19.sourcemaps, 'optionalAccess', _20 => _20.stripComments]), () => ( stripComments));
|
|
399
|
-
const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.updateIgnoreFiles]), () => ( true));
|
|
400
|
-
const dryRun = typeof options === "object" && options !== null ? _nullishCoalesce(options.dryRun, () => ( false)) : false;
|
|
401
|
-
const vaultDir = _path2.default.resolve(resolvedCwd, effectiveVaultDirName);
|
|
402
|
-
const publicDirsToCheck = /* @__PURE__ */ new Set();
|
|
403
|
-
if (_optionalChain([config, 'optionalAccess', _22 => _22.publicDirs]) && config.publicDirs.length > 0) {
|
|
404
|
-
for (const d of config.publicDirs) {
|
|
405
|
-
publicDirsToCheck.add(d);
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
publicDirsToCheck.add("public");
|
|
409
|
-
publicDirsToCheck.add("static");
|
|
410
|
-
publicDirsToCheck.add("assets");
|
|
411
|
-
}
|
|
412
|
-
if (effectiveKeepPrivate !== false) {
|
|
413
|
-
if (!isSubdirectoryOrSame(resolvedCwd, vaultDir)) {
|
|
414
|
-
throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
|
|
415
|
-
"ERR_SECURITY_PATH_TRAVERSAL",
|
|
416
|
-
`[unpeek] Security Error: privateMapsDir (${vaultDir}) cannot traverse outside cwd (${resolvedCwd}).`
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
if (isSubdirectoryOrSame(resolvedOutDir, vaultDir)) {
|
|
420
|
-
throw new Error(
|
|
421
|
-
`[unpeek] Security Error: privateMapsDir cannot be located inside outDir (${resolvedOutDir}). This would expose private source maps to the web server.`
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
for (const pubDir of publicDirsToCheck) {
|
|
425
|
-
const resolvedPublicDir = _path2.default.resolve(resolvedCwd, pubDir);
|
|
426
|
-
if (isSubdirectoryOrSame(resolvedPublicDir, vaultDir)) {
|
|
427
|
-
throw new Error(
|
|
428
|
-
`[unpeek] Security Error: privateMapsDir cannot be located inside publicDir (${resolvedPublicDir}). This would expose private source maps to the web server.`
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
const relVault = _path2.default.relative(resolvedCwd, vaultDir).replace(/\\/g, "/");
|
|
434
|
-
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
435
|
-
const dockerIgnoreMissing = checkDockerIgnoreMissing(resolvedCwd, ignoreEntry);
|
|
436
|
-
const movedFiles = [];
|
|
437
|
-
let movedMapsCount = 0;
|
|
438
|
-
let strippedFilesCount = 0;
|
|
439
|
-
if (!_fs2.default.existsSync(resolvedOutDir)) {
|
|
440
|
-
return {
|
|
441
|
-
movedMapsCount: 0,
|
|
442
|
-
strippedFilesCount: 0,
|
|
443
|
-
vaultDir,
|
|
444
|
-
movedFiles: [],
|
|
445
|
-
dockerIgnoreMissing
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
function walkForMaps(currentDir) {
|
|
449
|
-
if (hasNextServerSegment(currentDir, resolvedOutDir)) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
let entries;
|
|
453
|
-
try {
|
|
454
|
-
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
455
|
-
} catch (e7) {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
for (const entry of entries) {
|
|
459
|
-
const fullPath = _path2.default.join(currentDir, entry.name);
|
|
460
|
-
if (entry.isDirectory()) {
|
|
461
|
-
if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir)) {
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
walkForMaps(fullPath);
|
|
468
|
-
} else if (entry.isFile() && entry.name.endsWith(".map")) {
|
|
469
|
-
if (effectiveKeepPrivate !== false) {
|
|
470
|
-
const relPath = _path2.default.relative(resolvedOutDir, fullPath);
|
|
471
|
-
const targetPath = _path2.default.join(vaultDir, relPath);
|
|
472
|
-
if (!dryRun) {
|
|
473
|
-
_fs2.default.mkdirSync(_path2.default.dirname(targetPath), { recursive: true });
|
|
474
|
-
_fs2.default.copyFileSync(fullPath, targetPath);
|
|
475
|
-
_fs2.default.unlinkSync(fullPath);
|
|
476
|
-
}
|
|
477
|
-
movedFiles.push(targetPath);
|
|
478
|
-
} else if (!dryRun) {
|
|
479
|
-
_fs2.default.unlinkSync(fullPath);
|
|
480
|
-
}
|
|
481
|
-
movedMapsCount++;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
walkForMaps(resolvedOutDir);
|
|
486
|
-
if (!dryRun && updateIgnoreFiles && effectiveKeepPrivate !== false && movedMapsCount > 0) {
|
|
487
|
-
updateAllIgnoreFiles(resolvedCwd, vaultDir);
|
|
488
|
-
}
|
|
489
|
-
if (effectiveStripComments) {
|
|
490
|
-
const clientFiles = scanClientBundles(resolvedOutDir, config);
|
|
491
|
-
for (const filePath of clientFiles) {
|
|
492
|
-
const original = _fs2.default.readFileSync(filePath, "utf8");
|
|
493
|
-
if (original.includes("sourceMappingURL=")) {
|
|
494
|
-
const { code: strippedCode, stripped } = stripSourceMapComments(original);
|
|
495
|
-
if (stripped) {
|
|
496
|
-
if (!dryRun) {
|
|
497
|
-
_fs2.default.writeFileSync(filePath, strippedCode, "utf8");
|
|
498
|
-
}
|
|
499
|
-
strippedFilesCount++;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return {
|
|
505
|
-
movedMapsCount,
|
|
506
|
-
strippedFilesCount,
|
|
507
|
-
vaultDir,
|
|
508
|
-
movedFiles,
|
|
509
|
-
dockerIgnoreMissing
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// src/core/protect.ts
|
|
514
|
-
var ENTRY_PATTERN = /^(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
|
|
515
|
-
function isEntryChunk(relPath, index, allRelPaths) {
|
|
516
|
-
const norm = relPath.replace(/\\/g, "/");
|
|
517
|
-
const base = _path2.default.basename(norm);
|
|
518
|
-
if (ENTRY_PATTERN.test(norm) || ENTRY_PATTERN.test(base)) {
|
|
519
|
-
return true;
|
|
520
|
-
}
|
|
521
|
-
const hasAnyPatternMatch = allRelPaths.some((p) => {
|
|
522
|
-
const n = p.replace(/\\/g, "/");
|
|
523
|
-
return ENTRY_PATTERN.test(n) || ENTRY_PATTERN.test(_path2.default.basename(n));
|
|
524
|
-
});
|
|
525
|
-
if (!hasAnyPatternMatch && index === 0) {
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
return false;
|
|
529
|
-
}
|
|
530
|
-
async function protectProject(options = {}) {
|
|
531
|
-
const startTime = performance.now();
|
|
532
|
-
const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
533
|
-
const effectiveConfigInput = options.profile ? { ..._nullishCoalesce(options.config, () => ( {})), profile: options.profile } : options.config;
|
|
534
|
-
const config = await _chunkONM2CSTUcjs.loadUnpeekConfig.call(void 0, cwd, effectiveConfigInput);
|
|
535
|
-
const effectiveProfile = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( config.profile)), () => ( "recommended"));
|
|
536
|
-
const { framework, outDir } = detectTargetFramework(cwd, options.outDir, config);
|
|
537
|
-
const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
538
|
-
const dryRun = Boolean(options.dryRun);
|
|
539
|
-
const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _23 => _23.sourcemaps, 'optionalAccess', _24 => _24.keepPrivate]))), () => ( true));
|
|
540
|
-
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _25 => _25.sourcemaps, 'optionalAccess', _26 => _26.vaultDir]))), () => ( ".unpeek-maps"));
|
|
541
|
-
const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _27 => _27.shield, 'optionalAccess', _28 => _28.deterrentMode]))), () => ( "passive"));
|
|
542
|
-
const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _29 => _29.shield, 'optionalAccess', _30 => _30.detectHeadless]))), () => ( false));
|
|
543
|
-
const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( (effectiveProfile === "minimal" ? false : true)));
|
|
544
|
-
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _31 => _31.vault, 'optionalAccess', _32 => _32.minStringLength]))), () => ( 4));
|
|
545
|
-
const aggressive = _nullishCoalesce(options.aggressive, () => ( (effectiveProfile === "strict" ? true : false)));
|
|
546
|
-
const scrubPaths = _nullishCoalesce(_nullishCoalesce(options.scrubPaths, () => ( config.scrubPaths)), () => ( (effectiveProfile === "strict" ? true : false)));
|
|
547
|
-
const masterSym = _chunkIAD5DV3Dcjs.deriveWindowKeySymbol.call(void 0, seed);
|
|
548
|
-
const masterShield = injectRuntimeShield ? _chunkIAD5DV3Dcjs.generateRuntimeShield.call(void 0, {
|
|
549
|
-
seed,
|
|
550
|
-
deterrentMode,
|
|
551
|
-
detectHeadless,
|
|
552
|
-
windowKeySymbol: masterSym
|
|
553
|
-
}) : void 0;
|
|
554
|
-
const deferVaultWrites = dryRun || typeof options.maxGzipDelta === "number";
|
|
555
|
-
const vaultResult = relocateSourceMaps(outDir, cwd, keepPrivateMaps, privateMapsDir, false, config, {
|
|
556
|
-
dryRun: deferVaultWrites
|
|
557
|
-
});
|
|
558
|
-
const clientFiles = scanClientBundles(outDir, config);
|
|
559
|
-
const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
|
|
560
|
-
let originalBytes = 0;
|
|
561
|
-
let protectedBytes = 0;
|
|
562
|
-
let totalHotFunctionsSkipped = 0;
|
|
563
|
-
let totalColdFunctionsProtected = 0;
|
|
564
|
-
let totalEncryptedStrings = 0;
|
|
565
|
-
let totalMangledSymbols = 0;
|
|
566
|
-
let processedFiles = 0;
|
|
567
|
-
let debugIdsPreserved = 0;
|
|
568
|
-
const diagnostics = [];
|
|
569
|
-
if (vaultResult.dockerIgnoreMissing) {
|
|
570
|
-
diagnostics.push({
|
|
571
|
-
code: "DOCKERIGNORE_MISSING",
|
|
572
|
-
severity: "warning",
|
|
573
|
-
message: ".dockerignore is missing .unpeek-maps/. Private maps may leak into Docker image during 'COPY . .'."
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
const allOrigBufs = [];
|
|
577
|
-
const allProtBufs = [];
|
|
578
|
-
const stagedFiles = [];
|
|
579
|
-
const pendingDebugIds = [];
|
|
580
|
-
let originalGzipBytes = 0;
|
|
581
|
-
let protectedGzipBytes = 0;
|
|
582
|
-
let gzipDeltaPercent = 0;
|
|
583
|
-
let budgetExceeded = false;
|
|
584
|
-
try {
|
|
585
|
-
for (let i = 0; i < clientFiles.length; i++) {
|
|
586
|
-
const filePath = clientFiles[i];
|
|
587
|
-
let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
|
|
588
|
-
const fileDebugId = extractDebugId(codeToTransform);
|
|
589
|
-
if (codeToTransform.includes("sourceMappingURL=")) {
|
|
590
|
-
const strippedRes = stripSourceMapComments(codeToTransform);
|
|
591
|
-
codeToTransform = strippedRes.code;
|
|
592
|
-
if (strippedRes.stripped) {
|
|
593
|
-
vaultResult.strippedFilesCount++;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
const origBuf = Buffer.from(codeToTransform, "utf8");
|
|
597
|
-
originalBytes += origBuf.byteLength;
|
|
598
|
-
allOrigBufs.push(origBuf);
|
|
599
|
-
const relPath = allRelPaths[i];
|
|
600
|
-
const isEntry = isEntryChunk(relPath, i, allRelPaths);
|
|
601
|
-
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
602
|
-
const fileSeed = _chunkIAD5DV3Dcjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
|
|
603
|
-
const transformOptions = {
|
|
604
|
-
seed: fileSeed,
|
|
605
|
-
minStringLength,
|
|
606
|
-
filename: _path2.default.basename(filePath),
|
|
607
|
-
injectRuntimeShield: shouldInjectShield,
|
|
608
|
-
skipShieldPreamble: true,
|
|
609
|
-
shieldCoupled: injectRuntimeShield,
|
|
610
|
-
windowKeySymbol: masterSym,
|
|
611
|
-
expectedDelta: _optionalChain([masterShield, 'optionalAccess', _33 => _33.expectedDelta]),
|
|
612
|
-
deterrentMode,
|
|
613
|
-
detectHeadless,
|
|
614
|
-
aggressive,
|
|
615
|
-
scrubPaths,
|
|
616
|
-
config
|
|
617
|
-
};
|
|
618
|
-
const result = _chunkIAD5DV3Dcjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
|
|
619
|
-
if (result.skippedReason === "parse-error") {
|
|
620
|
-
diagnostics.push({
|
|
621
|
-
code: "PARSE_FALLBACK",
|
|
622
|
-
severity: "warning",
|
|
623
|
-
message: `Skipped AST transform due to parse error in "${relPath}".`,
|
|
624
|
-
file: relPath
|
|
625
|
-
});
|
|
626
|
-
} else if (result.skippedReason === "already-protected") {
|
|
627
|
-
diagnostics.push({
|
|
628
|
-
code: "ALREADY_PROTECTED",
|
|
629
|
-
severity: "info",
|
|
630
|
-
message: `File "${relPath}" is already protected.`,
|
|
631
|
-
file: relPath
|
|
632
|
-
});
|
|
633
|
-
} else if (result.skippedReason === "empty") {
|
|
634
|
-
diagnostics.push({
|
|
635
|
-
code: "EMPTY_INPUT",
|
|
636
|
-
severity: "info",
|
|
637
|
-
message: `File "${relPath}" is empty.`,
|
|
638
|
-
file: relPath
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
let finalCode = result.code;
|
|
642
|
-
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _34 => _34.preambleCode]) && !finalCode.includes("__unpeek_tampered") && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
|
|
643
|
-
finalCode = `${masterShield.preambleCode}
|
|
644
|
-
${finalCode}`;
|
|
645
|
-
}
|
|
646
|
-
const effectiveDebugId = _nullishCoalesce(result.debugId, () => ( fileDebugId));
|
|
647
|
-
if (effectiveDebugId) {
|
|
648
|
-
if (!DEBUG_ID_COMMENT_REGEX.test(finalCode)) {
|
|
649
|
-
const suffix = finalCode.length > 0 && !finalCode.endsWith("\n") ? "\n" : "";
|
|
650
|
-
finalCode = `${finalCode}${suffix}//# debugId=${effectiveDebugId}
|
|
651
|
-
`;
|
|
652
|
-
}
|
|
653
|
-
debugIdsPreserved++;
|
|
654
|
-
if (!dryRun && keepPrivateMaps) {
|
|
655
|
-
pendingDebugIds.push({ relPath, debugId: effectiveDebugId });
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
if (!dryRun) {
|
|
659
|
-
const tmpPath = `${filePath}.unpeek.tmp`;
|
|
660
|
-
_fs2.default.writeFileSync(tmpPath, finalCode, "utf8");
|
|
661
|
-
stagedFiles.push({ tmpPath, finalPath: filePath });
|
|
662
|
-
}
|
|
663
|
-
const protBuf = Buffer.from(finalCode, "utf8");
|
|
664
|
-
protectedBytes += protBuf.byteLength;
|
|
665
|
-
allProtBufs.push(protBuf);
|
|
666
|
-
totalHotFunctionsSkipped += result.hotPathReport.hotFunctionsSkipped.length;
|
|
667
|
-
totalColdFunctionsProtected += result.hotPathReport.coldFunctionsProtected.length;
|
|
668
|
-
totalEncryptedStrings += result.encryptedStringsCount;
|
|
669
|
-
totalMangledSymbols += result.mangledSymbolsCount;
|
|
670
|
-
processedFiles++;
|
|
671
|
-
}
|
|
672
|
-
originalGzipBytes = allOrigBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allOrigBufs)).byteLength : 0;
|
|
673
|
-
protectedGzipBytes = allProtBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allProtBufs)).byteLength : 0;
|
|
674
|
-
gzipDeltaPercent = originalGzipBytes > 0 ? Number(((protectedGzipBytes - originalGzipBytes) / originalGzipBytes * 100).toFixed(2)) : 0;
|
|
675
|
-
budgetExceeded = typeof options.maxGzipDelta === "number" && gzipDeltaPercent > options.maxGzipDelta;
|
|
676
|
-
if (budgetExceeded && !dryRun) {
|
|
677
|
-
throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
|
|
678
|
-
"ERR_BUDGET_EXCEEDED",
|
|
679
|
-
`Protected bundle Gzip delta (${gzipDeltaPercent}%) exceeded maxGzipDelta (${options.maxGzipDelta}%).`
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
if (!dryRun) {
|
|
683
|
-
if (deferVaultWrites) {
|
|
684
|
-
const finalVaultResult = relocateSourceMaps(
|
|
685
|
-
outDir,
|
|
686
|
-
cwd,
|
|
687
|
-
keepPrivateMaps,
|
|
688
|
-
privateMapsDir,
|
|
689
|
-
false,
|
|
690
|
-
config,
|
|
691
|
-
{ dryRun: false }
|
|
692
|
-
);
|
|
693
|
-
vaultResult.movedMapsCount = finalVaultResult.movedMapsCount;
|
|
694
|
-
vaultResult.vaultDir = finalVaultResult.vaultDir;
|
|
695
|
-
vaultResult.movedFiles = finalVaultResult.movedFiles;
|
|
696
|
-
vaultResult.dockerIgnoreMissing = finalVaultResult.dockerIgnoreMissing;
|
|
697
|
-
}
|
|
698
|
-
for (const { relPath, debugId } of pendingDebugIds) {
|
|
699
|
-
const vaultedMapPath = _path2.default.join(vaultResult.vaultDir, `${relPath}.map`);
|
|
700
|
-
if (_fs2.default.existsSync(vaultedMapPath)) {
|
|
701
|
-
try {
|
|
702
|
-
const mapJson = JSON.parse(_fs2.default.readFileSync(vaultedMapPath, "utf8"));
|
|
703
|
-
if (!mapJson.debugId) {
|
|
704
|
-
mapJson.debugId = debugId;
|
|
705
|
-
_fs2.default.writeFileSync(vaultedMapPath, JSON.stringify(mapJson), "utf8");
|
|
706
|
-
}
|
|
707
|
-
} catch (e8) {
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
for (const { tmpPath, finalPath } of stagedFiles) {
|
|
712
|
-
_fs2.default.renameSync(tmpPath, finalPath);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
} catch (error) {
|
|
716
|
-
for (const { tmpPath } of stagedFiles) {
|
|
717
|
-
if (_fs2.default.existsSync(tmpPath)) {
|
|
718
|
-
try {
|
|
719
|
-
_fs2.default.unlinkSync(tmpPath);
|
|
720
|
-
} catch (e9) {
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
throw error;
|
|
725
|
-
}
|
|
726
|
-
const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
|
|
727
|
-
return {
|
|
728
|
-
framework,
|
|
729
|
-
outDir,
|
|
730
|
-
processedFiles,
|
|
731
|
-
movedSourceMaps: vaultResult.movedMapsCount,
|
|
732
|
-
originalBytes,
|
|
733
|
-
protectedBytes,
|
|
734
|
-
originalGzipBytes,
|
|
735
|
-
protectedGzipBytes,
|
|
736
|
-
gzipDeltaPercent,
|
|
737
|
-
totalHotFunctionsSkipped,
|
|
738
|
-
totalColdFunctionsProtected,
|
|
739
|
-
totalEncryptedStrings,
|
|
740
|
-
totalMangledSymbols,
|
|
741
|
-
elapsedMs,
|
|
742
|
-
seed,
|
|
743
|
-
tier: aggressive ? "Tier 2" : "Tier 1",
|
|
744
|
-
aggressive,
|
|
745
|
-
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
|
|
746
|
-
dryRun,
|
|
747
|
-
profile: effectiveProfile,
|
|
748
|
-
budgetExceeded,
|
|
749
|
-
debugIdsPreserved,
|
|
750
|
-
diagnostics
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
exports.hasNextServerSegment = hasNextServerSegment; exports.detectTargetFramework = detectTargetFramework; exports.scanClientBundles = scanClientBundles; exports.isNext16OrAbove = isNext16OrAbove; exports.serializeNextOptions = serializeNextOptions; exports.readUnpeekNextOptionsFromEnv = readUnpeekNextOptionsFromEnv; exports.SOURCE_MAP_COMMENT_REGEX = SOURCE_MAP_COMMENT_REGEX; exports.findMonorepoRoots = findMonorepoRoots; exports.protectProject = protectProject;
|