unpeek 4.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.
- package/README.md +7 -6
- package/README.tr.md +6 -5
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +5 -5
- package/dist/adapters/next/adapter.js +4 -4
- package/dist/adapters/next/index.cjs +5 -5
- package/dist/adapters/next/index.js +4 -4
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.js +3 -3
- package/dist/browser.cjs +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-3LWXEJU6.cjs → chunk-3GDHYBVH.cjs} +56 -18
- package/dist/{chunk-YCRMTXOE.js → chunk-4G2HCME5.js} +2 -2
- package/dist/{chunk-2JU3V7HW.js → chunk-4SOS3LRV.js} +50 -9
- package/dist/{chunk-7HXLHLLQ.cjs → chunk-7ZEVJ4OR.cjs} +121 -29
- package/dist/{chunk-4FNZNIBW.js → chunk-LGTXAAZH.js} +686 -344
- package/dist/{chunk-KLYFNMKS.cjs → chunk-M46SFJE7.cjs} +813 -471
- package/dist/{chunk-ZG7BIAUI.cjs → chunk-NNAAPDUS.cjs} +58 -17
- package/dist/{chunk-VG4Y26ZN.cjs → chunk-OTA75YI6.cjs} +14 -14
- package/dist/{chunk-ADKRENAP.js → chunk-TYL32LUK.js} +46 -8
- package/dist/{chunk-HHC7BUCK.js → chunk-XYN5NYSD.js} +95 -3
- package/dist/cli/index.js +921 -372
- package/dist/index.cjs +184 -45
- package/dist/index.js +170 -31
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
protectProject,
|
|
3
3
|
serializeNextOptions
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XYN5NYSD.js";
|
|
5
5
|
import {
|
|
6
|
+
hasJsBundleFiles,
|
|
6
7
|
safeDecodeURIComponent
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TYL32LUK.js";
|
|
8
9
|
import {
|
|
9
10
|
computeFnv1aHash
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-LGTXAAZH.js";
|
|
11
12
|
import {
|
|
12
13
|
UnpeekError,
|
|
13
14
|
__dirname,
|
|
@@ -40,6 +41,26 @@ function recomputeHash(content, existingHash) {
|
|
|
40
41
|
function isNonProductionPhase(phase) {
|
|
41
42
|
return phase !== void 0 && phase !== "phase-production-build" && phase !== "phase-export";
|
|
42
43
|
}
|
|
44
|
+
function buildUnpeekOutputHashSalt(options) {
|
|
45
|
+
const profileTag = options.profile ?? options.config?.profile ?? "recommended";
|
|
46
|
+
const isAggressive = options.aggressive ?? profileTag === "strict";
|
|
47
|
+
const envId = process.env.VERCEL_DEPLOYMENT_ID || process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA || "";
|
|
48
|
+
const parts = [
|
|
49
|
+
profileTag,
|
|
50
|
+
...isAggressive ? ["aggressive"] : [],
|
|
51
|
+
...envId ? [envId] : [],
|
|
52
|
+
...typeof options.seed === "number" ? [String(options.seed)] : []
|
|
53
|
+
];
|
|
54
|
+
return `unpeek:${parts.join(":")}`;
|
|
55
|
+
}
|
|
56
|
+
function isSameAdapterPath(candidate, selfPath) {
|
|
57
|
+
if (!candidate) return false;
|
|
58
|
+
try {
|
|
59
|
+
return path.resolve(candidate) === path.resolve(selfPath);
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
43
64
|
async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
|
|
44
65
|
if (!upstreamPath) return;
|
|
45
66
|
try {
|
|
@@ -54,7 +75,9 @@ async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
|
|
|
54
75
|
}
|
|
55
76
|
}
|
|
56
77
|
function createUnpeekNextAdapter(options = {}) {
|
|
57
|
-
const
|
|
78
|
+
const rawUpstreamPath = options.upstreamAdapterPath || process.env.UNPEEK_UPSTREAM_ADAPTER_PATH || process.env.NEXT_ADAPTER_PATH;
|
|
79
|
+
const selfAdapterPath = getUnpeekAdapterPath();
|
|
80
|
+
const upstreamPath = isSameAdapterPath(rawUpstreamPath, selfAdapterPath) ? void 0 : rawUpstreamPath;
|
|
58
81
|
let recordedPhase;
|
|
59
82
|
return {
|
|
60
83
|
name: "unpeek",
|
|
@@ -72,13 +95,26 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
72
95
|
console.warn("[unpeek:next] Failed to invoke upstream modifyConfig:", err);
|
|
73
96
|
}
|
|
74
97
|
}
|
|
98
|
+
const phase = context && typeof context.phase === "string" ? context.phase : recordedPhase;
|
|
99
|
+
if (!isNonProductionPhase(phase)) {
|
|
100
|
+
const existingSalt = typeof config.outputHashSalt === "string" ? config.outputHashSalt.trim() : "";
|
|
101
|
+
if (!existingSalt.includes("unpeek:")) {
|
|
102
|
+
const unpeekSalt = buildUnpeekOutputHashSalt(options);
|
|
103
|
+
config = {
|
|
104
|
+
...config,
|
|
105
|
+
outputHashSalt: existingSalt ? `${existingSalt}-${unpeekSalt}` : unpeekSalt
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
75
109
|
return config;
|
|
76
110
|
},
|
|
77
111
|
async onBuildComplete(context) {
|
|
78
112
|
const cwd = options.cwd ?? process.cwd();
|
|
79
|
-
const
|
|
113
|
+
const configuredDistDir = context.distDir || (typeof context.config?.distDir === "string" ? context.config.distDir : void 0) || ".next";
|
|
114
|
+
const distDir = path.resolve(cwd, configuredDistDir);
|
|
80
115
|
const staticDir = path.join(distDir, "static");
|
|
81
|
-
const
|
|
116
|
+
const vercelStaticDir = path.join(cwd, ".vercel", "output", "static", "_next", "static");
|
|
117
|
+
const targetDir = fs.existsSync(staticDir) && (hasJsBundleFiles(staticDir) || !fs.existsSync(vercelStaticDir)) ? staticDir : fs.existsSync(vercelStaticDir) ? vercelStaticDir : fs.existsSync(staticDir) ? staticDir : distDir;
|
|
82
118
|
const phase = context.phase ?? recordedPhase;
|
|
83
119
|
if (isNonProductionPhase(phase)) {
|
|
84
120
|
await delegateToUpstreamOnBuildComplete(upstreamPath, context);
|
|
@@ -124,6 +160,11 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
124
160
|
const fromStatic = path.resolve(distDir, "static", staticClean);
|
|
125
161
|
if (fs.existsSync(fromStatic)) {
|
|
126
162
|
absPath = fromStatic;
|
|
163
|
+
} else {
|
|
164
|
+
const fromVercelStatic = path.resolve(vercelStaticDir, staticClean);
|
|
165
|
+
if (fs.existsSync(fromVercelStatic)) {
|
|
166
|
+
absPath = fromVercelStatic;
|
|
167
|
+
}
|
|
127
168
|
}
|
|
128
169
|
}
|
|
129
170
|
}
|
|
@@ -182,11 +223,12 @@ function getUnpeekAdapterPath() {
|
|
|
182
223
|
}
|
|
183
224
|
}
|
|
184
225
|
function applyWithUnpeek(config = {}, options) {
|
|
226
|
+
const adapterPath = getUnpeekAdapterPath();
|
|
185
227
|
const existingAdapter = config.adapterPath || process.env.NEXT_ADAPTER_PATH;
|
|
186
|
-
if (existingAdapter && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
|
|
228
|
+
if (existingAdapter && !isSameAdapterPath(existingAdapter, adapterPath) && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
|
|
187
229
|
process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = existingAdapter;
|
|
188
230
|
}
|
|
189
|
-
if (options?.upstreamAdapterPath) {
|
|
231
|
+
if (options?.upstreamAdapterPath && !isSameAdapterPath(options.upstreamAdapterPath, adapterPath)) {
|
|
190
232
|
process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = options.upstreamAdapterPath;
|
|
191
233
|
}
|
|
192
234
|
if (options) {
|
|
@@ -202,7 +244,6 @@ function applyWithUnpeek(config = {}, options) {
|
|
|
202
244
|
} else {
|
|
203
245
|
delete process.env.UNPEEK_NEXT_OPTIONS;
|
|
204
246
|
}
|
|
205
|
-
const adapterPath = getUnpeekAdapterPath();
|
|
206
247
|
return {
|
|
207
248
|
...config,
|
|
208
249
|
adapterPath
|
|
@@ -1,4 +1,4 @@
|
|
|
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; }
|
|
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
2
|
|
|
3
3
|
var _chunkX6EETCO6cjs = require('./chunk-X6EETCO6.cjs');
|
|
4
4
|
|
|
@@ -15,13 +15,13 @@ var _chunkX6EETCO6cjs = require('./chunk-X6EETCO6.cjs');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
|
|
@@ -86,6 +86,8 @@ function readUnpeekNextOptionsFromEnv() {
|
|
|
86
86
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
87
87
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
88
88
|
var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib);
|
|
89
|
+
var _acorn = require('acorn'); var acorn = _interopRequireWildcard(_acorn);
|
|
90
|
+
var _acornwalk = require('acorn-walk');
|
|
89
91
|
var ENTRY_PATTERN = /^(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
|
|
90
92
|
function normalizeManifestRel(fileRef) {
|
|
91
93
|
const clean = fileRef.replace(/\\/g, "/").split("?")[0].split("#")[0].replace(/^\/+/, "");
|
|
@@ -197,7 +199,7 @@ function matchesManifestEntry(relPath, manifestEntries) {
|
|
|
197
199
|
function isEntryChunk(relPath, index, allRelPaths, manifestEntries, isWorkerTarget) {
|
|
198
200
|
const norm = relPath.replace(/\\/g, "/");
|
|
199
201
|
const base = _path2.default.basename(norm);
|
|
200
|
-
if (isWorkerTarget &&
|
|
202
|
+
if (isWorkerTarget && _chunk3GDHYBVHcjs.isWorkerOrServiceWorkerFile.call(void 0, norm)) {
|
|
201
203
|
return true;
|
|
202
204
|
}
|
|
203
205
|
if (matchesManifestEntry(norm, manifestEntries)) {
|
|
@@ -221,7 +223,7 @@ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWri
|
|
|
221
223
|
candidates.push(`${filePath}.map`);
|
|
222
224
|
}
|
|
223
225
|
candidates.push(_path2.default.join(vaultDir, `${relPath}.map`));
|
|
224
|
-
const decodedRel =
|
|
226
|
+
const decodedRel = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relPath);
|
|
225
227
|
if (decodedRel !== relPath) {
|
|
226
228
|
candidates.push(_path2.default.join(vaultDir, `${decodedRel}.map`));
|
|
227
229
|
}
|
|
@@ -237,13 +239,51 @@ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWri
|
|
|
237
239
|
}
|
|
238
240
|
return void 0;
|
|
239
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
|
+
}
|
|
240
280
|
async function protectProject(options = {}) {
|
|
241
281
|
const startTime = performance.now();
|
|
242
282
|
const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
243
283
|
const effectiveConfigInput = options.profile ? { ..._nullishCoalesce(options.config, () => ( {})), profile: options.profile } : options.config;
|
|
244
284
|
const config = await _chunkX6EETCO6cjs.loadUnpeekConfig.call(void 0, cwd, effectiveConfigInput);
|
|
245
285
|
const effectiveProfile = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( config.profile)), () => ( "recommended"));
|
|
246
|
-
const { framework, outDir } =
|
|
286
|
+
const { framework, outDir } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
|
|
247
287
|
const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
248
288
|
const dryRun = Boolean(options.dryRun);
|
|
249
289
|
const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _7 => _7.sourcemaps, 'optionalAccess', _8 => _8.keepPrivate]))), () => ( true));
|
|
@@ -254,18 +294,18 @@ async function protectProject(options = {}) {
|
|
|
254
294
|
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _15 => _15.vault, 'optionalAccess', _16 => _16.minStringLength]))), () => ( 4));
|
|
255
295
|
const aggressive = _nullishCoalesce(options.aggressive, () => ( (effectiveProfile === "strict" ? true : false)));
|
|
256
296
|
const scrubPaths = _nullishCoalesce(_nullishCoalesce(options.scrubPaths, () => ( config.scrubPaths)), () => ( (effectiveProfile === "strict" ? true : false)));
|
|
257
|
-
const masterSym =
|
|
258
|
-
const masterShield = injectRuntimeShield ?
|
|
297
|
+
const masterSym = _chunkM46SFJE7cjs.deriveWindowKeySymbol.call(void 0, seed);
|
|
298
|
+
const masterShield = injectRuntimeShield ? _chunkM46SFJE7cjs.generateRuntimeShield.call(void 0, {
|
|
259
299
|
seed,
|
|
260
300
|
deterrentMode,
|
|
261
301
|
detectHeadless,
|
|
262
302
|
windowKeySymbol: masterSym
|
|
263
303
|
}) : void 0;
|
|
264
304
|
const deferVaultWrites = dryRun || typeof options.maxGzipDelta === "number";
|
|
265
|
-
const vaultResult =
|
|
305
|
+
const vaultResult = _chunk3GDHYBVHcjs.relocateSourceMaps.call(void 0, outDir, cwd, keepPrivateMaps, privateMapsDir, false, config, {
|
|
266
306
|
dryRun: deferVaultWrites
|
|
267
307
|
});
|
|
268
|
-
const clientFiles =
|
|
308
|
+
const clientFiles = _chunk3GDHYBVHcjs.scanClientBundles.call(void 0, outDir, config);
|
|
269
309
|
const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
|
|
270
310
|
const manifestEntries = collectManifestEntryFiles(outDir, cwd, config);
|
|
271
311
|
const isWorkerTarget = config.target === "worker";
|
|
@@ -289,6 +329,19 @@ async function protectProject(options = {}) {
|
|
|
289
329
|
const allProtBufs = [];
|
|
290
330
|
const stagedFiles = [];
|
|
291
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
|
+
}
|
|
292
345
|
let originalGzipBytes = 0;
|
|
293
346
|
let protectedGzipBytes = 0;
|
|
294
347
|
let gzipDeltaPercent = 0;
|
|
@@ -297,9 +350,9 @@ async function protectProject(options = {}) {
|
|
|
297
350
|
for (let i = 0; i < clientFiles.length; i++) {
|
|
298
351
|
const filePath = clientFiles[i];
|
|
299
352
|
let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
|
|
300
|
-
const fileDebugId =
|
|
353
|
+
const fileDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, codeToTransform);
|
|
301
354
|
if (codeToTransform.includes("sourceMappingURL=")) {
|
|
302
|
-
const strippedRes =
|
|
355
|
+
const strippedRes = _chunk3GDHYBVHcjs.stripSourceMapComments.call(void 0, codeToTransform);
|
|
303
356
|
codeToTransform = strippedRes.code;
|
|
304
357
|
if (strippedRes.stripped) {
|
|
305
358
|
vaultResult.strippedFilesCount++;
|
|
@@ -309,9 +362,10 @@ async function protectProject(options = {}) {
|
|
|
309
362
|
originalBytes += origBuf.byteLength;
|
|
310
363
|
allOrigBufs.push(origBuf);
|
|
311
364
|
const relPath = allRelPaths[i];
|
|
365
|
+
const preExistingHits = countPreExistingEvalCalls(codeToTransform);
|
|
312
366
|
const isEntry = isEntryChunk(relPath, i, allRelPaths, manifestEntries, isWorkerTarget);
|
|
313
367
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
314
|
-
const fileSeed =
|
|
368
|
+
const fileSeed = _chunkM46SFJE7cjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
|
|
315
369
|
const transformOptions = {
|
|
316
370
|
seed: fileSeed,
|
|
317
371
|
minStringLength,
|
|
@@ -329,7 +383,7 @@ async function protectProject(options = {}) {
|
|
|
329
383
|
};
|
|
330
384
|
transformOptions.generateMap = keepPrivateMaps;
|
|
331
385
|
transformOptions.rootDir = cwd;
|
|
332
|
-
const result =
|
|
386
|
+
const result = _chunkM46SFJE7cjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
|
|
333
387
|
if (result.skippedReason === "parse-error") {
|
|
334
388
|
diagnostics.push({
|
|
335
389
|
code: "PARSE_FALLBACK",
|
|
@@ -338,6 +392,13 @@ async function protectProject(options = {}) {
|
|
|
338
392
|
file: relPath
|
|
339
393
|
});
|
|
340
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
|
+
}
|
|
341
402
|
diagnostics.push({
|
|
342
403
|
code: "ALREADY_PROTECTED",
|
|
343
404
|
severity: "info",
|
|
@@ -351,10 +412,12 @@ async function protectProject(options = {}) {
|
|
|
351
412
|
message: `File "${relPath}" is empty.`,
|
|
352
413
|
file: relPath
|
|
353
414
|
});
|
|
415
|
+
} else if (preExistingHits.length > 0) {
|
|
416
|
+
preExistingEvalFiles[relPath] = preExistingHits;
|
|
354
417
|
}
|
|
355
418
|
let finalCode = result.code;
|
|
356
419
|
let preambleLineOffset = 0;
|
|
357
|
-
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess',
|
|
420
|
+
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _20 => _20.preambleCode]) && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
|
|
358
421
|
const prefix = `${masterShield.preambleCode}
|
|
359
422
|
`;
|
|
360
423
|
preambleLineOffset = (_nullishCoalesce(prefix.match(/\n/g), () => ( []))).length;
|
|
@@ -362,25 +425,25 @@ async function protectProject(options = {}) {
|
|
|
362
425
|
}
|
|
363
426
|
const originalMap = keepPrivateMaps ? readOriginalSourceMapForFile(filePath, relPath, vaultResult.vaultDir, deferVaultWrites) : void 0;
|
|
364
427
|
const rawTransformMap = result.sourceMap;
|
|
365
|
-
const shiftedTransformMap = rawTransformMap ?
|
|
428
|
+
const shiftedTransformMap = rawTransformMap ? _chunk3GDHYBVHcjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
|
|
366
429
|
let composedMap;
|
|
367
430
|
if (shiftedTransformMap && originalMap) {
|
|
368
|
-
composedMap =
|
|
431
|
+
composedMap = _chunk3GDHYBVHcjs.chainSourceMaps.call(void 0, shiftedTransformMap, originalMap);
|
|
369
432
|
} else if (originalMap) {
|
|
370
|
-
composedMap =
|
|
433
|
+
composedMap = _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, originalMap);
|
|
371
434
|
} else if (shiftedTransformMap) {
|
|
372
435
|
composedMap = shiftedTransformMap;
|
|
373
436
|
}
|
|
374
|
-
const originalMapDebugId = _nullishCoalesce(_optionalChain([originalMap, 'optionalAccess',
|
|
437
|
+
const originalMapDebugId = _nullishCoalesce(_optionalChain([originalMap, 'optionalAccess', _21 => _21.debugId]), () => ( _optionalChain([originalMap, 'optionalAccess', _22 => _22.debug_id])));
|
|
375
438
|
const hadDebugId = Boolean(fileDebugId || originalMapDebugId || result.debugId);
|
|
376
439
|
let mintedDebugId;
|
|
377
440
|
if (hadDebugId) {
|
|
378
|
-
const codeWithoutDebugId =
|
|
379
|
-
mintedDebugId =
|
|
441
|
+
const codeWithoutDebugId = _chunk3GDHYBVHcjs.stripDebugIdComments.call(void 0, finalCode);
|
|
442
|
+
mintedDebugId = _chunk3GDHYBVHcjs.computeDeterministicDebugId.call(void 0,
|
|
380
443
|
codeWithoutDebugId,
|
|
381
|
-
_nullishCoalesce(_optionalChain([composedMap, 'optionalAccess',
|
|
444
|
+
_nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _23 => _23.mappings]), () => ( ""))
|
|
382
445
|
);
|
|
383
|
-
finalCode =
|
|
446
|
+
finalCode = _chunk3GDHYBVHcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
|
|
384
447
|
if (composedMap) {
|
|
385
448
|
composedMap.debugId = mintedDebugId;
|
|
386
449
|
delete composedMap.debug_id;
|
|
@@ -416,7 +479,7 @@ async function protectProject(options = {}) {
|
|
|
416
479
|
}
|
|
417
480
|
if (!dryRun) {
|
|
418
481
|
if (deferVaultWrites) {
|
|
419
|
-
const finalVaultResult =
|
|
482
|
+
const finalVaultResult = _chunk3GDHYBVHcjs.relocateSourceMaps.call(void 0,
|
|
420
483
|
outDir,
|
|
421
484
|
cwd,
|
|
422
485
|
keepPrivateMaps,
|
|
@@ -434,13 +497,13 @@ async function protectProject(options = {}) {
|
|
|
434
497
|
const vaultedMapPath = _path2.default.join(vaultResult.vaultDir, `${relPath}.map`);
|
|
435
498
|
const decodedMapPath = _path2.default.join(
|
|
436
499
|
vaultResult.vaultDir,
|
|
437
|
-
`${
|
|
500
|
+
`${_chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relPath)}.map`
|
|
438
501
|
);
|
|
439
502
|
const targetMapPath = _fs2.default.existsSync(vaultedMapPath) ? vaultedMapPath : _fs2.default.existsSync(decodedMapPath) ? decodedMapPath : vaultedMapPath;
|
|
440
503
|
if (map && _fs2.default.existsSync(targetMapPath)) {
|
|
441
504
|
try {
|
|
442
505
|
_fs2.default.writeFileSync(targetMapPath, JSON.stringify(map), "utf8");
|
|
443
|
-
} catch (
|
|
506
|
+
} catch (e9) {
|
|
444
507
|
}
|
|
445
508
|
} else if (debugId && _fs2.default.existsSync(targetMapPath)) {
|
|
446
509
|
try {
|
|
@@ -448,26 +511,55 @@ async function protectProject(options = {}) {
|
|
|
448
511
|
mapJson.debugId = debugId;
|
|
449
512
|
delete mapJson.debug_id;
|
|
450
513
|
_fs2.default.writeFileSync(targetMapPath, JSON.stringify(mapJson), "utf8");
|
|
451
|
-
} catch (
|
|
514
|
+
} catch (e10) {
|
|
452
515
|
}
|
|
453
516
|
}
|
|
454
517
|
}
|
|
455
518
|
for (const { tmpPath, finalPath } of stagedFiles) {
|
|
456
519
|
_fs2.default.renameSync(tmpPath, finalPath);
|
|
457
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
|
+
}
|
|
458
549
|
}
|
|
459
550
|
} catch (error) {
|
|
460
551
|
for (const { tmpPath } of stagedFiles) {
|
|
461
552
|
if (_fs2.default.existsSync(tmpPath)) {
|
|
462
553
|
try {
|
|
463
554
|
_fs2.default.unlinkSync(tmpPath);
|
|
464
|
-
} catch (
|
|
555
|
+
} catch (e12) {
|
|
465
556
|
}
|
|
466
557
|
}
|
|
467
558
|
}
|
|
468
559
|
throw error;
|
|
469
560
|
}
|
|
470
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")))));
|
|
471
563
|
return {
|
|
472
564
|
framework,
|
|
473
565
|
outDir,
|
|
@@ -484,7 +576,7 @@ async function protectProject(options = {}) {
|
|
|
484
576
|
totalMangledSymbols,
|
|
485
577
|
elapsedMs,
|
|
486
578
|
seed,
|
|
487
|
-
tier:
|
|
579
|
+
tier: resolvedTier,
|
|
488
580
|
aggressive,
|
|
489
581
|
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
|
|
490
582
|
dryRun,
|