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
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk7ZEVJ4ORcjs = require('./chunk-7ZEVJ4OR.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -18,10 +18,12 @@ var _chunkURPPSTHZcjs = require('./chunk-URPPSTHZ.cjs');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var _chunk3LWXEJU6cjs = require('./chunk-3LWXEJU6.cjs');
|
|
22
21
|
|
|
23
22
|
|
|
24
|
-
var
|
|
23
|
+
var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
|
|
@@ -96,7 +98,7 @@ export default withUnpeek(nextConfig);
|
|
|
96
98
|
function initProject(cwd = process.cwd(), options = {}) {
|
|
97
99
|
const dryRun = typeof options === "boolean" ? options : _nullishCoalesce(options.dryRun, () => ( false));
|
|
98
100
|
const rootDir = _path2.default.resolve(cwd);
|
|
99
|
-
const { framework } =
|
|
101
|
+
const { framework } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, rootDir);
|
|
100
102
|
const pkgPath = _path2.default.join(rootDir, "package.json");
|
|
101
103
|
let updatedPackageJson = false;
|
|
102
104
|
let updatedGitignore = false;
|
|
@@ -129,7 +131,7 @@ function initProject(cwd = process.cwd(), options = {}) {
|
|
|
129
131
|
const rawNext = _nullishCoalesce(_optionalChain([deps, 'optionalAccess', _ => _.next]), () => ( _optionalChain([devDeps, 'optionalAccess', _2 => _2.next])));
|
|
130
132
|
nextVersion = typeof rawNext === "string" ? rawNext : void 0;
|
|
131
133
|
}
|
|
132
|
-
if (framework === "nextjs" &&
|
|
134
|
+
if (framework === "nextjs" && _chunk7ZEVJ4ORcjs.isNext16OrAbove.call(void 0, nextVersion)) {
|
|
133
135
|
isNext16 = true;
|
|
134
136
|
const configRes = wireNextConfig(rootDir, dryRun);
|
|
135
137
|
updatedNextConfig = configRes.updated;
|
|
@@ -202,7 +204,7 @@ function initProject(cwd = process.cwd(), options = {}) {
|
|
|
202
204
|
var _acorn = require('acorn'); var acorn = _interopRequireWildcard(_acorn);
|
|
203
205
|
var _acornwalk = require('acorn-walk');
|
|
204
206
|
function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
205
|
-
if (
|
|
207
|
+
if (_chunk3GDHYBVHcjs.hasNextServerSegment.call(void 0, currentDir, rootOutDir)) {
|
|
206
208
|
return;
|
|
207
209
|
}
|
|
208
210
|
let entries;
|
|
@@ -217,7 +219,7 @@ function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
|
217
219
|
if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
|
|
218
220
|
continue;
|
|
219
221
|
}
|
|
220
|
-
if (
|
|
222
|
+
if (_chunk3GDHYBVHcjs.hasNextServerSegment.call(void 0, fullPath, rootOutDir)) {
|
|
221
223
|
continue;
|
|
222
224
|
}
|
|
223
225
|
walkPublicMaps(fullPath, rootOutDir, found);
|
|
@@ -237,6 +239,45 @@ function hasIgnoreEntry(filePath, ignoreEntry) {
|
|
|
237
239
|
return false;
|
|
238
240
|
}
|
|
239
241
|
}
|
|
242
|
+
function isEs5GlobalThisIdiom(args) {
|
|
243
|
+
if (args.length !== 1) return false;
|
|
244
|
+
const arg = args[0];
|
|
245
|
+
if (arg.type === "Literal" && typeof arg.value === "string") {
|
|
246
|
+
const trimmed = arg.value.trim().replace(/;+$/, "").trim();
|
|
247
|
+
return trimmed === "return this";
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
function isNodeModulesSource(sourcePath) {
|
|
252
|
+
if (!sourcePath) return false;
|
|
253
|
+
const normalized = sourcePath.replace(/\\/g, "/").toLowerCase();
|
|
254
|
+
return /(?:^|\/)node_modules\//.test(normalized);
|
|
255
|
+
}
|
|
256
|
+
function mapHasOnlyNodeModulesSources(map) {
|
|
257
|
+
if (!map) return false;
|
|
258
|
+
const flat = Array.isArray(map.sections) ? _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, map) : map;
|
|
259
|
+
const sources = Array.isArray(flat.sources) ? flat.sources : [];
|
|
260
|
+
if (sources.length === 0) return false;
|
|
261
|
+
const root = flat.sourceRoot;
|
|
262
|
+
return sources.every((src) => {
|
|
263
|
+
const combined = root && src && !src.startsWith(root) ? `${root.replace(/\/$/, "")}/${src.replace(/^\//, "")}` : src;
|
|
264
|
+
return isNodeModulesSource(combined);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
268
|
+
if (!map) return false;
|
|
269
|
+
const pos = _chunk3GDHYBVHcjs.resolvePosition.call(void 0, map, hit.line, hit.column);
|
|
270
|
+
if (pos.source) {
|
|
271
|
+
return isNodeModulesSource(pos.source);
|
|
272
|
+
}
|
|
273
|
+
if (hit.calleeLine !== hit.line || hit.calleeColumn !== hit.column) {
|
|
274
|
+
const calleePos = _chunk3GDHYBVHcjs.resolvePosition.call(void 0, map, hit.calleeLine, hit.calleeColumn);
|
|
275
|
+
if (calleePos.source) {
|
|
276
|
+
return isNodeModulesSource(calleePos.source);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return allSourcesNodeModules;
|
|
280
|
+
}
|
|
240
281
|
function findEvalOrFunctionCalls(code) {
|
|
241
282
|
const hits = [];
|
|
242
283
|
let ast;
|
|
@@ -244,14 +285,16 @@ function findEvalOrFunctionCalls(code) {
|
|
|
244
285
|
ast = acorn.parse(code, {
|
|
245
286
|
ecmaVersion: "latest",
|
|
246
287
|
sourceType: "module",
|
|
247
|
-
allowReturnOutsideFunction: true
|
|
288
|
+
allowReturnOutsideFunction: true,
|
|
289
|
+
locations: true
|
|
248
290
|
});
|
|
249
291
|
} catch (e3) {
|
|
250
292
|
try {
|
|
251
293
|
ast = acorn.parse(code, {
|
|
252
294
|
ecmaVersion: "latest",
|
|
253
295
|
sourceType: "script",
|
|
254
|
-
allowReturnOutsideFunction: true
|
|
296
|
+
allowReturnOutsideFunction: true,
|
|
297
|
+
locations: true
|
|
255
298
|
});
|
|
256
299
|
} catch (e4) {
|
|
257
300
|
return hits;
|
|
@@ -260,25 +303,54 @@ function findEvalOrFunctionCalls(code) {
|
|
|
260
303
|
_acornwalk.simple.call(void 0, ast, {
|
|
261
304
|
CallExpression(node) {
|
|
262
305
|
if (node.callee.type === "Identifier") {
|
|
306
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
307
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
308
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
309
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
263
310
|
if (node.callee.name === "eval") {
|
|
264
|
-
hits.push(
|
|
311
|
+
hits.push({
|
|
312
|
+
kind: "eval(...)",
|
|
313
|
+
line,
|
|
314
|
+
column,
|
|
315
|
+
calleeLine,
|
|
316
|
+
calleeColumn,
|
|
317
|
+
vendorIdiom: false
|
|
318
|
+
});
|
|
265
319
|
} else if (node.callee.name === "Function") {
|
|
266
|
-
hits.push(
|
|
320
|
+
hits.push({
|
|
321
|
+
kind: "Function(...)",
|
|
322
|
+
line,
|
|
323
|
+
column,
|
|
324
|
+
calleeLine,
|
|
325
|
+
calleeColumn,
|
|
326
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
327
|
+
});
|
|
267
328
|
}
|
|
268
329
|
}
|
|
269
330
|
},
|
|
270
331
|
NewExpression(node) {
|
|
271
332
|
if (node.callee.type === "Identifier" && node.callee.name === "Function") {
|
|
272
|
-
|
|
333
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
334
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
335
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
336
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
337
|
+
hits.push({
|
|
338
|
+
kind: "new Function(...)",
|
|
339
|
+
line,
|
|
340
|
+
column,
|
|
341
|
+
calleeLine,
|
|
342
|
+
calleeColumn,
|
|
343
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
344
|
+
});
|
|
273
345
|
}
|
|
274
346
|
}
|
|
275
347
|
});
|
|
276
|
-
return
|
|
348
|
+
return hits;
|
|
277
349
|
}
|
|
278
350
|
async function checkProject(options = {}) {
|
|
279
351
|
const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
280
352
|
const config = await _chunkX6EETCO6cjs.loadUnpeekConfig.call(void 0, cwd);
|
|
281
|
-
const { outDir } =
|
|
353
|
+
const { outDir } = _chunk3GDHYBVHcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
|
|
282
354
|
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
283
355
|
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _3 => _3.sourcemaps, 'optionalAccess', _4 => _4.vaultDir]))), () => ( ".unpeek-maps"));
|
|
284
356
|
const maxGzipDelta = _nullishCoalesce(options.maxGzipDelta, () => ( 15));
|
|
@@ -299,17 +371,29 @@ async function checkProject(options = {}) {
|
|
|
299
371
|
});
|
|
300
372
|
}
|
|
301
373
|
const vaultDir = _path2.default.resolve(cwd, privateMapsDir);
|
|
302
|
-
const
|
|
374
|
+
const manifestPath = _path2.default.join(vaultDir, "manifest.json");
|
|
375
|
+
let manifest;
|
|
376
|
+
if (_fs2.default.existsSync(manifestPath)) {
|
|
377
|
+
try {
|
|
378
|
+
const parsed = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf8"));
|
|
379
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
380
|
+
manifest = parsed;
|
|
381
|
+
}
|
|
382
|
+
} catch (e5) {
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const clientFiles = _chunk3GDHYBVHcjs.scanClientBundles.call(void 0, resolvedOutDir, config);
|
|
303
386
|
for (const filePath of clientFiles) {
|
|
304
387
|
const rel = _path2.default.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
|
|
388
|
+
const relFromManifest = typeof _optionalChain([manifest, 'optionalAccess', _5 => _5.outDir]) === "string" ? _path2.default.relative(_path2.default.resolve(cwd, manifest.outDir), filePath).replace(/\\/g, "/") : void 0;
|
|
305
389
|
let content;
|
|
306
390
|
try {
|
|
307
391
|
content = _fs2.default.readFileSync(filePath, "utf8");
|
|
308
|
-
} catch (
|
|
392
|
+
} catch (e6) {
|
|
309
393
|
continue;
|
|
310
394
|
}
|
|
311
|
-
|
|
312
|
-
if (
|
|
395
|
+
_chunk3GDHYBVHcjs.SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
|
|
396
|
+
if (_chunk3GDHYBVHcjs.SOURCE_MAP_COMMENT_REGEX.test(content)) {
|
|
313
397
|
violations.push({
|
|
314
398
|
rule: "sourcemap-comment",
|
|
315
399
|
severity: "error",
|
|
@@ -317,16 +401,21 @@ async function checkProject(options = {}) {
|
|
|
317
401
|
file: rel
|
|
318
402
|
});
|
|
319
403
|
}
|
|
320
|
-
const jsDebugId =
|
|
321
|
-
const decodedRel =
|
|
404
|
+
const jsDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, content);
|
|
405
|
+
const decodedRel = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, rel);
|
|
406
|
+
const decodedManifestRel = relFromManifest ? _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, relFromManifest) : void 0;
|
|
322
407
|
const mapCandidates = [
|
|
323
408
|
_path2.default.join(vaultDir, `${rel}.map`),
|
|
324
|
-
...decodedRel !== rel ? [_path2.default.join(vaultDir, `${decodedRel}.map`)] : []
|
|
409
|
+
...decodedRel !== rel ? [_path2.default.join(vaultDir, `${decodedRel}.map`)] : [],
|
|
410
|
+
...relFromManifest && relFromManifest !== rel ? [_path2.default.join(vaultDir, `${relFromManifest}.map`)] : [],
|
|
411
|
+
...decodedManifestRel && decodedManifestRel !== relFromManifest ? [_path2.default.join(vaultDir, `${decodedManifestRel}.map`)] : []
|
|
325
412
|
];
|
|
326
413
|
const vaultedMapPath = mapCandidates.find((p) => _fs2.default.existsSync(p));
|
|
414
|
+
let vaultedMap;
|
|
327
415
|
if (vaultedMapPath) {
|
|
328
416
|
try {
|
|
329
417
|
const mapJson = JSON.parse(_fs2.default.readFileSync(vaultedMapPath, "utf8"));
|
|
418
|
+
vaultedMap = mapJson;
|
|
330
419
|
const rawMapDebugId = typeof mapJson.debugId === "string" ? mapJson.debugId : typeof mapJson.debug_id === "string" ? mapJson.debug_id : void 0;
|
|
331
420
|
if (jsDebugId && rawMapDebugId && jsDebugId !== rawMapDebugId) {
|
|
332
421
|
violations.push({
|
|
@@ -350,7 +439,7 @@ async function checkProject(options = {}) {
|
|
|
350
439
|
file: rel
|
|
351
440
|
});
|
|
352
441
|
}
|
|
353
|
-
} catch (
|
|
442
|
+
} catch (e7) {
|
|
354
443
|
}
|
|
355
444
|
} else if (jsDebugId) {
|
|
356
445
|
warnings.push({
|
|
@@ -362,22 +451,70 @@ async function checkProject(options = {}) {
|
|
|
362
451
|
}
|
|
363
452
|
const evalHits = findEvalOrFunctionCalls(content);
|
|
364
453
|
if (evalHits.length > 0) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
454
|
+
if (!requireZeroEval) {
|
|
455
|
+
const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
|
|
456
|
+
warnings.push({
|
|
457
|
+
rule: "eval-csp",
|
|
458
|
+
severity: "warning",
|
|
459
|
+
message: `Dynamic code evaluation (${kinds.join(", ")}) detected in "${rel}".`,
|
|
460
|
+
file: rel
|
|
461
|
+
});
|
|
373
462
|
} else {
|
|
374
|
-
|
|
463
|
+
const allNodeModules = mapHasOnlyNodeModulesSources(vaultedMap);
|
|
464
|
+
const baselineList = _nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _6 => _6.preExistingEvalFiles, 'optionalAccess', _7 => _7[rel]]), () => ( (relFromManifest ? _optionalChain([manifest, 'optionalAccess', _8 => _8.preExistingEvalFiles, 'optionalAccess', _9 => _9[relFromManifest]]) : void 0)));
|
|
465
|
+
const remainingBaseline = /* @__PURE__ */ new Map();
|
|
466
|
+
if (Array.isArray(baselineList)) {
|
|
467
|
+
for (const entry of baselineList) {
|
|
468
|
+
remainingBaseline.set(entry, (_nullishCoalesce(remainingBaseline.get(entry), () => ( 0))) + 1);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const warningHits = [];
|
|
472
|
+
const unattributedHits = [];
|
|
473
|
+
for (const hit of evalHits) {
|
|
474
|
+
if (hit.vendorIdiom || isHitFromNodeModules(hit, vaultedMap, allNodeModules)) {
|
|
475
|
+
warningHits.push(hit);
|
|
476
|
+
const rem = _nullishCoalesce(remainingBaseline.get(hit.kind), () => ( 0));
|
|
477
|
+
if (rem > 0) {
|
|
478
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
479
|
+
}
|
|
480
|
+
} else {
|
|
481
|
+
unattributedHits.push(hit);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const errorHits = [];
|
|
485
|
+
for (const hit of unattributedHits) {
|
|
486
|
+
const rem = _nullishCoalesce(remainingBaseline.get(hit.kind), () => ( 0));
|
|
487
|
+
if (rem > 0) {
|
|
488
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
489
|
+
warningHits.push(hit);
|
|
490
|
+
} else {
|
|
491
|
+
errorHits.push(hit);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (warningHits.length > 0) {
|
|
495
|
+
const warningKinds = Array.from(new Set(warningHits.map((h) => h.kind)));
|
|
496
|
+
warnings.push({
|
|
497
|
+
rule: "eval-csp",
|
|
498
|
+
severity: "warning",
|
|
499
|
+
message: `Pre-existing or vendor dynamic code evaluation (${warningKinds.join(", ")}) detected in "${rel}".`,
|
|
500
|
+
file: rel
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (errorHits.length > 0) {
|
|
504
|
+
const errorKinds = Array.from(new Set(errorHits.map((h) => h.kind)));
|
|
505
|
+
violations.push({
|
|
506
|
+
rule: "eval-csp",
|
|
507
|
+
severity: "error",
|
|
508
|
+
message: `Dynamic code evaluation (${errorKinds.join(", ")}) detected in "${rel}".`,
|
|
509
|
+
file: rel
|
|
510
|
+
});
|
|
511
|
+
}
|
|
375
512
|
}
|
|
376
513
|
}
|
|
377
514
|
}
|
|
378
515
|
const relVault = _path2.default.relative(cwd, vaultDir).replace(/\\/g, "/");
|
|
379
516
|
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
380
|
-
const roots =
|
|
517
|
+
const roots = _chunk3GDHYBVHcjs.findMonorepoRoots.call(void 0, cwd);
|
|
381
518
|
let foundGitignore = false;
|
|
382
519
|
let gitignoreProtected = false;
|
|
383
520
|
let foundDockerignore = false;
|
|
@@ -418,18 +555,20 @@ async function checkProject(options = {}) {
|
|
|
418
555
|
message: `.dockerignore is missing "${ignoreEntry}". Private source maps may leak into Docker images.`
|
|
419
556
|
});
|
|
420
557
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
558
|
+
if (manifest && typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
|
|
559
|
+
const isTinyBundleBaseline = options.maxGzipDelta === void 0 && typeof manifest.originalGzipBytes === "number" && manifest.originalGzipBytes < 16384;
|
|
560
|
+
if (isTinyBundleBaseline) {
|
|
561
|
+
warnings.push({
|
|
562
|
+
rule: "gzip-budget",
|
|
563
|
+
severity: "warning",
|
|
564
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds default ${maxGzipDelta}% threshold on small bundle (${manifest.originalGzipBytes} B original gzip).`
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
violations.push({
|
|
568
|
+
rule: "gzip-budget",
|
|
569
|
+
severity: "error",
|
|
570
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
|
|
571
|
+
});
|
|
433
572
|
}
|
|
434
573
|
}
|
|
435
574
|
return {
|
|
@@ -451,4 +590,4 @@ async function checkProject(options = {}) {
|
|
|
451
590
|
|
|
452
591
|
|
|
453
592
|
|
|
454
|
-
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkX6EETCO6cjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkX6EETCO6cjs.loadUnpeekConfig; exports.protectProject =
|
|
593
|
+
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkX6EETCO6cjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkX6EETCO6cjs.loadUnpeekConfig; exports.protectProject = _chunk7ZEVJ4ORcjs.protectProject; exports.symbolicateStackTrace = _chunk3GDHYBVHcjs.symbolicateStackTrace; exports.transformJavaScript = _chunkM46SFJE7cjs.transformJavaScript;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isNext16OrAbove,
|
|
3
3
|
protectProject
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XYN5NYSD.js";
|
|
5
5
|
import {
|
|
6
6
|
defineConfig,
|
|
7
7
|
loadUnpeekConfig
|
|
@@ -14,14 +14,16 @@ import {
|
|
|
14
14
|
detectTargetFramework,
|
|
15
15
|
extractDebugId,
|
|
16
16
|
findMonorepoRoots,
|
|
17
|
+
flattenSourceMapSections,
|
|
17
18
|
hasNextServerSegment,
|
|
19
|
+
resolvePosition,
|
|
18
20
|
safeDecodeURIComponent,
|
|
19
21
|
scanClientBundles,
|
|
20
22
|
symbolicateStackTrace
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-TYL32LUK.js";
|
|
22
24
|
import {
|
|
23
25
|
transformJavaScript
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-LGTXAAZH.js";
|
|
25
27
|
import {
|
|
26
28
|
UnpeekError,
|
|
27
29
|
isUnpeekError
|
|
@@ -237,6 +239,45 @@ function hasIgnoreEntry(filePath, ignoreEntry) {
|
|
|
237
239
|
return false;
|
|
238
240
|
}
|
|
239
241
|
}
|
|
242
|
+
function isEs5GlobalThisIdiom(args) {
|
|
243
|
+
if (args.length !== 1) return false;
|
|
244
|
+
const arg = args[0];
|
|
245
|
+
if (arg.type === "Literal" && typeof arg.value === "string") {
|
|
246
|
+
const trimmed = arg.value.trim().replace(/;+$/, "").trim();
|
|
247
|
+
return trimmed === "return this";
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
function isNodeModulesSource(sourcePath) {
|
|
252
|
+
if (!sourcePath) return false;
|
|
253
|
+
const normalized = sourcePath.replace(/\\/g, "/").toLowerCase();
|
|
254
|
+
return /(?:^|\/)node_modules\//.test(normalized);
|
|
255
|
+
}
|
|
256
|
+
function mapHasOnlyNodeModulesSources(map) {
|
|
257
|
+
if (!map) return false;
|
|
258
|
+
const flat = Array.isArray(map.sections) ? flattenSourceMapSections(map) : map;
|
|
259
|
+
const sources = Array.isArray(flat.sources) ? flat.sources : [];
|
|
260
|
+
if (sources.length === 0) return false;
|
|
261
|
+
const root = flat.sourceRoot;
|
|
262
|
+
return sources.every((src) => {
|
|
263
|
+
const combined = root && src && !src.startsWith(root) ? `${root.replace(/\/$/, "")}/${src.replace(/^\//, "")}` : src;
|
|
264
|
+
return isNodeModulesSource(combined);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
268
|
+
if (!map) return false;
|
|
269
|
+
const pos = resolvePosition(map, hit.line, hit.column);
|
|
270
|
+
if (pos.source) {
|
|
271
|
+
return isNodeModulesSource(pos.source);
|
|
272
|
+
}
|
|
273
|
+
if (hit.calleeLine !== hit.line || hit.calleeColumn !== hit.column) {
|
|
274
|
+
const calleePos = resolvePosition(map, hit.calleeLine, hit.calleeColumn);
|
|
275
|
+
if (calleePos.source) {
|
|
276
|
+
return isNodeModulesSource(calleePos.source);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return allSourcesNodeModules;
|
|
280
|
+
}
|
|
240
281
|
function findEvalOrFunctionCalls(code) {
|
|
241
282
|
const hits = [];
|
|
242
283
|
let ast;
|
|
@@ -244,14 +285,16 @@ function findEvalOrFunctionCalls(code) {
|
|
|
244
285
|
ast = acorn.parse(code, {
|
|
245
286
|
ecmaVersion: "latest",
|
|
246
287
|
sourceType: "module",
|
|
247
|
-
allowReturnOutsideFunction: true
|
|
288
|
+
allowReturnOutsideFunction: true,
|
|
289
|
+
locations: true
|
|
248
290
|
});
|
|
249
291
|
} catch {
|
|
250
292
|
try {
|
|
251
293
|
ast = acorn.parse(code, {
|
|
252
294
|
ecmaVersion: "latest",
|
|
253
295
|
sourceType: "script",
|
|
254
|
-
allowReturnOutsideFunction: true
|
|
296
|
+
allowReturnOutsideFunction: true,
|
|
297
|
+
locations: true
|
|
255
298
|
});
|
|
256
299
|
} catch {
|
|
257
300
|
return hits;
|
|
@@ -260,20 +303,49 @@ function findEvalOrFunctionCalls(code) {
|
|
|
260
303
|
walkSimple(ast, {
|
|
261
304
|
CallExpression(node) {
|
|
262
305
|
if (node.callee.type === "Identifier") {
|
|
306
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
307
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
308
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
309
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
263
310
|
if (node.callee.name === "eval") {
|
|
264
|
-
hits.push(
|
|
311
|
+
hits.push({
|
|
312
|
+
kind: "eval(...)",
|
|
313
|
+
line,
|
|
314
|
+
column,
|
|
315
|
+
calleeLine,
|
|
316
|
+
calleeColumn,
|
|
317
|
+
vendorIdiom: false
|
|
318
|
+
});
|
|
265
319
|
} else if (node.callee.name === "Function") {
|
|
266
|
-
hits.push(
|
|
320
|
+
hits.push({
|
|
321
|
+
kind: "Function(...)",
|
|
322
|
+
line,
|
|
323
|
+
column,
|
|
324
|
+
calleeLine,
|
|
325
|
+
calleeColumn,
|
|
326
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
327
|
+
});
|
|
267
328
|
}
|
|
268
329
|
}
|
|
269
330
|
},
|
|
270
331
|
NewExpression(node) {
|
|
271
332
|
if (node.callee.type === "Identifier" && node.callee.name === "Function") {
|
|
272
|
-
|
|
333
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
334
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
335
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
336
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
337
|
+
hits.push({
|
|
338
|
+
kind: "new Function(...)",
|
|
339
|
+
line,
|
|
340
|
+
column,
|
|
341
|
+
calleeLine,
|
|
342
|
+
calleeColumn,
|
|
343
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
344
|
+
});
|
|
273
345
|
}
|
|
274
346
|
}
|
|
275
347
|
});
|
|
276
|
-
return
|
|
348
|
+
return hits;
|
|
277
349
|
}
|
|
278
350
|
async function checkProject(options = {}) {
|
|
279
351
|
const cwd = path2.resolve(options.cwd ?? process.cwd());
|
|
@@ -299,9 +371,21 @@ async function checkProject(options = {}) {
|
|
|
299
371
|
});
|
|
300
372
|
}
|
|
301
373
|
const vaultDir = path2.resolve(cwd, privateMapsDir);
|
|
374
|
+
const manifestPath = path2.join(vaultDir, "manifest.json");
|
|
375
|
+
let manifest;
|
|
376
|
+
if (fs2.existsSync(manifestPath)) {
|
|
377
|
+
try {
|
|
378
|
+
const parsed = JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
|
|
379
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
380
|
+
manifest = parsed;
|
|
381
|
+
}
|
|
382
|
+
} catch {
|
|
383
|
+
}
|
|
384
|
+
}
|
|
302
385
|
const clientFiles = scanClientBundles(resolvedOutDir, config);
|
|
303
386
|
for (const filePath of clientFiles) {
|
|
304
387
|
const rel = path2.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
|
|
388
|
+
const relFromManifest = typeof manifest?.outDir === "string" ? path2.relative(path2.resolve(cwd, manifest.outDir), filePath).replace(/\\/g, "/") : void 0;
|
|
305
389
|
let content;
|
|
306
390
|
try {
|
|
307
391
|
content = fs2.readFileSync(filePath, "utf8");
|
|
@@ -319,14 +403,19 @@ async function checkProject(options = {}) {
|
|
|
319
403
|
}
|
|
320
404
|
const jsDebugId = extractDebugId(content);
|
|
321
405
|
const decodedRel = safeDecodeURIComponent(rel);
|
|
406
|
+
const decodedManifestRel = relFromManifest ? safeDecodeURIComponent(relFromManifest) : void 0;
|
|
322
407
|
const mapCandidates = [
|
|
323
408
|
path2.join(vaultDir, `${rel}.map`),
|
|
324
|
-
...decodedRel !== rel ? [path2.join(vaultDir, `${decodedRel}.map`)] : []
|
|
409
|
+
...decodedRel !== rel ? [path2.join(vaultDir, `${decodedRel}.map`)] : [],
|
|
410
|
+
...relFromManifest && relFromManifest !== rel ? [path2.join(vaultDir, `${relFromManifest}.map`)] : [],
|
|
411
|
+
...decodedManifestRel && decodedManifestRel !== relFromManifest ? [path2.join(vaultDir, `${decodedManifestRel}.map`)] : []
|
|
325
412
|
];
|
|
326
413
|
const vaultedMapPath = mapCandidates.find((p) => fs2.existsSync(p));
|
|
414
|
+
let vaultedMap;
|
|
327
415
|
if (vaultedMapPath) {
|
|
328
416
|
try {
|
|
329
417
|
const mapJson = JSON.parse(fs2.readFileSync(vaultedMapPath, "utf8"));
|
|
418
|
+
vaultedMap = mapJson;
|
|
330
419
|
const rawMapDebugId = typeof mapJson.debugId === "string" ? mapJson.debugId : typeof mapJson.debug_id === "string" ? mapJson.debug_id : void 0;
|
|
331
420
|
if (jsDebugId && rawMapDebugId && jsDebugId !== rawMapDebugId) {
|
|
332
421
|
violations.push({
|
|
@@ -362,16 +451,64 @@ async function checkProject(options = {}) {
|
|
|
362
451
|
}
|
|
363
452
|
const evalHits = findEvalOrFunctionCalls(content);
|
|
364
453
|
if (evalHits.length > 0) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
454
|
+
if (!requireZeroEval) {
|
|
455
|
+
const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
|
|
456
|
+
warnings.push({
|
|
457
|
+
rule: "eval-csp",
|
|
458
|
+
severity: "warning",
|
|
459
|
+
message: `Dynamic code evaluation (${kinds.join(", ")}) detected in "${rel}".`,
|
|
460
|
+
file: rel
|
|
461
|
+
});
|
|
373
462
|
} else {
|
|
374
|
-
|
|
463
|
+
const allNodeModules = mapHasOnlyNodeModulesSources(vaultedMap);
|
|
464
|
+
const baselineList = manifest?.preExistingEvalFiles?.[rel] ?? (relFromManifest ? manifest?.preExistingEvalFiles?.[relFromManifest] : void 0);
|
|
465
|
+
const remainingBaseline = /* @__PURE__ */ new Map();
|
|
466
|
+
if (Array.isArray(baselineList)) {
|
|
467
|
+
for (const entry of baselineList) {
|
|
468
|
+
remainingBaseline.set(entry, (remainingBaseline.get(entry) ?? 0) + 1);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const warningHits = [];
|
|
472
|
+
const unattributedHits = [];
|
|
473
|
+
for (const hit of evalHits) {
|
|
474
|
+
if (hit.vendorIdiom || isHitFromNodeModules(hit, vaultedMap, allNodeModules)) {
|
|
475
|
+
warningHits.push(hit);
|
|
476
|
+
const rem = remainingBaseline.get(hit.kind) ?? 0;
|
|
477
|
+
if (rem > 0) {
|
|
478
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
479
|
+
}
|
|
480
|
+
} else {
|
|
481
|
+
unattributedHits.push(hit);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const errorHits = [];
|
|
485
|
+
for (const hit of unattributedHits) {
|
|
486
|
+
const rem = remainingBaseline.get(hit.kind) ?? 0;
|
|
487
|
+
if (rem > 0) {
|
|
488
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
489
|
+
warningHits.push(hit);
|
|
490
|
+
} else {
|
|
491
|
+
errorHits.push(hit);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (warningHits.length > 0) {
|
|
495
|
+
const warningKinds = Array.from(new Set(warningHits.map((h) => h.kind)));
|
|
496
|
+
warnings.push({
|
|
497
|
+
rule: "eval-csp",
|
|
498
|
+
severity: "warning",
|
|
499
|
+
message: `Pre-existing or vendor dynamic code evaluation (${warningKinds.join(", ")}) detected in "${rel}".`,
|
|
500
|
+
file: rel
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (errorHits.length > 0) {
|
|
504
|
+
const errorKinds = Array.from(new Set(errorHits.map((h) => h.kind)));
|
|
505
|
+
violations.push({
|
|
506
|
+
rule: "eval-csp",
|
|
507
|
+
severity: "error",
|
|
508
|
+
message: `Dynamic code evaluation (${errorKinds.join(", ")}) detected in "${rel}".`,
|
|
509
|
+
file: rel
|
|
510
|
+
});
|
|
511
|
+
}
|
|
375
512
|
}
|
|
376
513
|
}
|
|
377
514
|
}
|
|
@@ -418,18 +555,20 @@ async function checkProject(options = {}) {
|
|
|
418
555
|
message: `.dockerignore is missing "${ignoreEntry}". Private source maps may leak into Docker images.`
|
|
419
556
|
});
|
|
420
557
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
558
|
+
if (manifest && typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
|
|
559
|
+
const isTinyBundleBaseline = options.maxGzipDelta === void 0 && typeof manifest.originalGzipBytes === "number" && manifest.originalGzipBytes < 16384;
|
|
560
|
+
if (isTinyBundleBaseline) {
|
|
561
|
+
warnings.push({
|
|
562
|
+
rule: "gzip-budget",
|
|
563
|
+
severity: "warning",
|
|
564
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds default ${maxGzipDelta}% threshold on small bundle (${manifest.originalGzipBytes} B original gzip).`
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
violations.push({
|
|
568
|
+
rule: "gzip-budget",
|
|
569
|
+
severity: "error",
|
|
570
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
|
|
571
|
+
});
|
|
433
572
|
}
|
|
434
573
|
}
|
|
435
574
|
return {
|