unpeek 4.2.0 → 4.3.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 +2 -2
- package/README.tr.md +2 -2
- 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-UUJLTW7O.cjs → chunk-4IRIMLT3.cjs} +16 -16
- package/dist/{chunk-AD6UFBPA.cjs → chunk-4XSFPX2Z.cjs} +367 -8
- package/dist/{chunk-KIAYVIC5.cjs → chunk-7F75S3GQ.cjs} +60 -36
- package/dist/{chunk-K77WRITN.js → chunk-EASD7C2B.js} +3 -3
- package/dist/{chunk-APQOBFRO.js → chunk-GKWTP4Z5.js} +30 -6
- package/dist/{chunk-MSECP2P4.cjs → chunk-OR5M3SN2.cjs} +1199 -428
- package/dist/{chunk-32GLSJAW.js → chunk-RDP4MTHK.js} +359 -0
- package/dist/{chunk-BL2UXZGD.js → chunk-RM3V7KJA.js} +1040 -269
- package/dist/{chunk-SJK45WAU.cjs → chunk-SBRU7GSX.cjs} +8 -8
- package/dist/{chunk-GCWXTWTN.js → chunk-XEYMZUP5.js} +2 -2
- package/dist/cli/index.js +1425 -274
- package/dist/index.cjs +21 -21
- package/dist/index.js +3 -3
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/package.json +1 -1
|
@@ -6,10 +6,18 @@ var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
|
|
|
6
6
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
7
7
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
8
|
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
9
|
+
var MAX_HTML_FILES = 64;
|
|
10
|
+
var MAX_SCAN_BYTES = 512 * 1024;
|
|
11
|
+
var MAX_JS_GRAPH_FILES = 1024;
|
|
9
12
|
var EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
10
13
|
"node_modules",
|
|
11
14
|
".unpeek-maps"
|
|
12
15
|
]);
|
|
16
|
+
var HTML_WALK_EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
17
|
+
"node_modules",
|
|
18
|
+
".unpeek-maps",
|
|
19
|
+
".git"
|
|
20
|
+
]);
|
|
13
21
|
var WORKER_OR_SW_BASENAME_REGEX = /^(?:sw|service-worker|workbox-[^/]+)\.(?:js|mjs|cjs)$|\.worker(?:[.-][^/]+)*\.(?:js|mjs|cjs)$/i;
|
|
14
22
|
function isWorkerOrServiceWorkerFile(filePath, rootDir) {
|
|
15
23
|
const normalized = filePath.replace(/\\/g, "/").split("?")[0];
|
|
@@ -372,6 +380,356 @@ function scanClientBundles(outDir, config) {
|
|
|
372
380
|
walk(resolvedOutDir);
|
|
373
381
|
return results.sort();
|
|
374
382
|
}
|
|
383
|
+
var SCRIPT_TAG_REGEX = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
384
|
+
var LINK_TAG_REGEX = /<link\b([^>]*)>/gi;
|
|
385
|
+
var HTML_COMMENT_REGEX = /<!--[\s\S]*?-->/g;
|
|
386
|
+
var ATTR_SRC_REGEX = /\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
|
|
387
|
+
var ATTR_HREF_REGEX = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
|
|
388
|
+
var ATTR_REL_REGEX = /\brel\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
|
|
389
|
+
var ATTR_AS_REGEX = /\bas\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
|
|
390
|
+
var ATTR_TYPE_REGEX = /\btype\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
|
|
391
|
+
var STATIC_FROM_IMPORT_REGEX = /\bfrom\s*(['"`])([^'"`\r\n${}]+)\1/g;
|
|
392
|
+
var SIDE_EFFECT_IMPORT_REGEX = /(?:^|[;}\n])\s*import\s*(['"`])([^'"`\r\n${}]+)\1/g;
|
|
393
|
+
var DYNAMIC_IMPORT_REGEX = /\bimport\s*\(\s*(?:\/\*[^*]{0,120}\*\/\s*)?(['"`])([^'"`\r\n${}]+)\1/g;
|
|
394
|
+
var WORKER_META_URL_REGEX = /\bnew\s+(?:(?:window|self|globalThis)\s*\.\s*)?(?:Shared)?Worker\s*\(\s*new\s+URL\s*\(\s*(['"`])([^'"`\r\n${}]+)\1\s*,\s*import\.meta\.url\s*\)/g;
|
|
395
|
+
var WORKER_DIRECT_URL_REGEX = /\bnew\s+(?:(?:window|self|globalThis)\s*\.\s*)?(?:Shared)?Worker\s*\(\s*(['"`])([^'"`\r\n${}]+)\1/g;
|
|
396
|
+
function getHtmlAttr(attrs, regex) {
|
|
397
|
+
const match = attrs.match(regex);
|
|
398
|
+
if (!match) return void 0;
|
|
399
|
+
return (_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(match[1], () => ( match[2])), () => ( match[3])), () => ( ""))).trim();
|
|
400
|
+
}
|
|
401
|
+
function readBoundedText(filePath, maxBytes) {
|
|
402
|
+
let fd;
|
|
403
|
+
try {
|
|
404
|
+
fd = _fs2.default.openSync(filePath, "r");
|
|
405
|
+
const stat = _fs2.default.fstatSync(fd);
|
|
406
|
+
const toRead = Math.min(stat.size, maxBytes);
|
|
407
|
+
if (toRead <= 0) return "";
|
|
408
|
+
const buf = Buffer.allocUnsafe(toRead);
|
|
409
|
+
let offset = 0;
|
|
410
|
+
while (offset < toRead) {
|
|
411
|
+
const bytesRead = _fs2.default.readSync(fd, buf, offset, toRead - offset, offset);
|
|
412
|
+
if (bytesRead <= 0) break;
|
|
413
|
+
offset += bytesRead;
|
|
414
|
+
}
|
|
415
|
+
return buf.subarray(0, offset).toString("utf8");
|
|
416
|
+
} catch (e6) {
|
|
417
|
+
return "";
|
|
418
|
+
} finally {
|
|
419
|
+
if (fd !== void 0) {
|
|
420
|
+
try {
|
|
421
|
+
_fs2.default.closeSync(fd);
|
|
422
|
+
} catch (e7) {
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function buildServerDirPrefixes(config) {
|
|
428
|
+
const prefixes = [];
|
|
429
|
+
if (_optionalChain([config, 'optionalAccess', _18 => _18.next, 'optionalAccess', _19 => _19.distDir])) {
|
|
430
|
+
prefixes.push(
|
|
431
|
+
_path2.default.join(config.next.distDir, "server"),
|
|
432
|
+
_path2.default.join(config.next.distDir, "ssr")
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
if (_optionalChain([config, 'optionalAccess', _20 => _20.vite, 'optionalAccess', _21 => _21.outDir])) {
|
|
436
|
+
prefixes.push(_path2.default.join(config.vite.outDir, "server"));
|
|
437
|
+
}
|
|
438
|
+
return prefixes;
|
|
439
|
+
}
|
|
440
|
+
function getAllowedExtensions(config) {
|
|
441
|
+
return _optionalChain([config, 'optionalAccess', _22 => _22.extensions]) && config.extensions.length > 0 ? new Set(
|
|
442
|
+
config.extensions.map((e) => e.startsWith(".") ? e.toLowerCase() : `.${e.toLowerCase()}`)
|
|
443
|
+
) : SUPPORTED_EXTENSIONS;
|
|
444
|
+
}
|
|
445
|
+
function isExcludedPathSegment(fullPath) {
|
|
446
|
+
const normalized = fullPath.replace(/\\/g, "/");
|
|
447
|
+
return normalized.includes("/.git/") || normalized.endsWith("/.git") || normalized.includes("/node_modules/") || normalized.endsWith("/node_modules") || normalized.includes("/.unpeek-maps/") || normalized.endsWith("/.unpeek-maps");
|
|
448
|
+
}
|
|
449
|
+
function resolveOutDirJsTarget(rawSpecifier, baseDir, resolvedOutDir, allowedExtensions, serverDirPrefixes, fallbackRootDir) {
|
|
450
|
+
const trimmed = rawSpecifier.trim();
|
|
451
|
+
if (!trimmed || trimmed.startsWith("#") || /^(?:https?:|data:|blob:|javascript:|mailto:|\/\/)/i.test(trimmed)) {
|
|
452
|
+
return void 0;
|
|
453
|
+
}
|
|
454
|
+
const withoutQuery = trimmed.split("?")[0].split("#")[0];
|
|
455
|
+
let cleanSpec = withoutQuery;
|
|
456
|
+
try {
|
|
457
|
+
cleanSpec = decodeURIComponent(withoutQuery);
|
|
458
|
+
} catch (e8) {
|
|
459
|
+
}
|
|
460
|
+
if (!cleanSpec) return void 0;
|
|
461
|
+
const candidates = [];
|
|
462
|
+
if (cleanSpec.startsWith("/")) {
|
|
463
|
+
const stripped = cleanSpec.replace(/^\/+/, "");
|
|
464
|
+
candidates.push(_path2.default.resolve(resolvedOutDir, stripped));
|
|
465
|
+
if (fallbackRootDir && fallbackRootDir !== resolvedOutDir) {
|
|
466
|
+
candidates.push(_path2.default.resolve(fallbackRootDir, stripped));
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
candidates.push(_path2.default.resolve(baseDir, cleanSpec));
|
|
470
|
+
}
|
|
471
|
+
for (const baseCandidate of candidates) {
|
|
472
|
+
const ext = _path2.default.extname(baseCandidate).toLowerCase();
|
|
473
|
+
const withExts = ext ? [baseCandidate] : Array.from(allowedExtensions).map((e) => `${baseCandidate}${e}`);
|
|
474
|
+
for (const candidate of withExts) {
|
|
475
|
+
const candExt = _path2.default.extname(candidate).toLowerCase();
|
|
476
|
+
if (!allowedExtensions.has(candExt)) continue;
|
|
477
|
+
if (isExcludedPathSegment(candidate)) continue;
|
|
478
|
+
if (hasNextServerSegment(candidate, resolvedOutDir, serverDirPrefixes)) continue;
|
|
479
|
+
const rel = _path2.default.relative(resolvedOutDir, candidate).replace(/\\/g, "/");
|
|
480
|
+
if (!rel || rel.startsWith("..") || _path2.default.isAbsolute(rel)) continue;
|
|
481
|
+
try {
|
|
482
|
+
if (_fs2.default.existsSync(candidate) && _fs2.default.statSync(candidate).isFile()) {
|
|
483
|
+
return { absPath: candidate, relPath: rel };
|
|
484
|
+
}
|
|
485
|
+
} catch (e9) {
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
function extractRelativeSpecifiers(jsText, allowBareRelativeFromRoot) {
|
|
492
|
+
const imports = [];
|
|
493
|
+
const workers = [];
|
|
494
|
+
const collectMatches = (regex, target, requireDotPrefix) => {
|
|
495
|
+
regex.lastIndex = 0;
|
|
496
|
+
let m;
|
|
497
|
+
while ((m = regex.exec(jsText)) !== null) {
|
|
498
|
+
const spec = m[2];
|
|
499
|
+
if (!spec) continue;
|
|
500
|
+
if (spec.startsWith("./") || spec.startsWith("../") || !requireDotPrefix && !/^(?:https?:|data:|blob:)/i.test(spec)) {
|
|
501
|
+
target.push(spec);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
collectMatches(STATIC_FROM_IMPORT_REGEX, imports, true);
|
|
506
|
+
collectMatches(SIDE_EFFECT_IMPORT_REGEX, imports, true);
|
|
507
|
+
collectMatches(DYNAMIC_IMPORT_REGEX, imports, true);
|
|
508
|
+
collectMatches(WORKER_META_URL_REGEX, workers, !allowBareRelativeFromRoot);
|
|
509
|
+
collectMatches(WORKER_DIRECT_URL_REGEX, workers, true);
|
|
510
|
+
return { imports, workers };
|
|
511
|
+
}
|
|
512
|
+
function discoverHtmlEntryGraph(outDir, config, extraHtmlDirs = []) {
|
|
513
|
+
const htmlEntryFiles = /* @__PURE__ */ new Set();
|
|
514
|
+
const preloadedFiles = /* @__PURE__ */ new Set();
|
|
515
|
+
const workerEntryFiles = /* @__PURE__ */ new Set();
|
|
516
|
+
const reachableFiles = /* @__PURE__ */ new Set();
|
|
517
|
+
const emptyResult = () => ({
|
|
518
|
+
htmlEntryFiles,
|
|
519
|
+
preloadedFiles,
|
|
520
|
+
workerEntryFiles,
|
|
521
|
+
reachableFiles,
|
|
522
|
+
entryFiles: /* @__PURE__ */ new Set(),
|
|
523
|
+
scannedHtmlFiles: 0,
|
|
524
|
+
scannedJsFiles: 0
|
|
525
|
+
});
|
|
526
|
+
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
527
|
+
if (!_fs2.default.existsSync(resolvedOutDir)) {
|
|
528
|
+
return emptyResult();
|
|
529
|
+
}
|
|
530
|
+
const serverDirPrefixes = buildServerDirPrefixes(config);
|
|
531
|
+
const allowedExtensions = getAllowedExtensions(config);
|
|
532
|
+
const htmlFiles = [];
|
|
533
|
+
function walkHtml(currentDir) {
|
|
534
|
+
if (htmlFiles.length >= MAX_HTML_FILES) return;
|
|
535
|
+
if (hasNextServerSegment(currentDir, resolvedOutDir, serverDirPrefixes)) return;
|
|
536
|
+
let entries;
|
|
537
|
+
try {
|
|
538
|
+
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
539
|
+
} catch (e10) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
543
|
+
for (const entry of entries) {
|
|
544
|
+
if (htmlFiles.length >= MAX_HTML_FILES) break;
|
|
545
|
+
const fullPath = _path2.default.join(currentDir, entry.name);
|
|
546
|
+
if (entry.isDirectory()) {
|
|
547
|
+
if (HTML_WALK_EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) continue;
|
|
548
|
+
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) continue;
|
|
549
|
+
walkHtml(fullPath);
|
|
550
|
+
} else if (entry.isFile()) {
|
|
551
|
+
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) continue;
|
|
552
|
+
if (_path2.default.extname(entry.name).toLowerCase() === ".html") {
|
|
553
|
+
htmlFiles.push({ filePath: fullPath, rootDir: resolvedOutDir });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
walkHtml(resolvedOutDir);
|
|
559
|
+
if (htmlFiles.length === 0 && extraHtmlDirs.length > 0) {
|
|
560
|
+
for (const extraDir of extraHtmlDirs) {
|
|
561
|
+
if (htmlFiles.length >= MAX_HTML_FILES) break;
|
|
562
|
+
const resolvedExtra = _path2.default.resolve(extraDir);
|
|
563
|
+
if (!_fs2.default.existsSync(resolvedExtra) || isExcludedPathSegment(resolvedExtra) || hasNextServerSegment(resolvedExtra, resolvedExtra, serverDirPrefixes)) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
let entries;
|
|
567
|
+
try {
|
|
568
|
+
entries = _fs2.default.readdirSync(resolvedExtra, { withFileTypes: true });
|
|
569
|
+
} catch (e11) {
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
573
|
+
for (const entry of entries) {
|
|
574
|
+
if (htmlFiles.length >= MAX_HTML_FILES) break;
|
|
575
|
+
if (entry.isFile() && _path2.default.extname(entry.name).toLowerCase() === ".html") {
|
|
576
|
+
htmlFiles.push({ filePath: _path2.default.join(resolvedExtra, entry.name), rootDir: resolvedExtra });
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const jsQueue = [];
|
|
582
|
+
const queuedOrVisitedJs = /* @__PURE__ */ new Set();
|
|
583
|
+
const enqueueJs = (resolved) => {
|
|
584
|
+
if (!resolved) return;
|
|
585
|
+
reachableFiles.add(resolved.relPath);
|
|
586
|
+
if (!queuedOrVisitedJs.has(resolved.relPath) && queuedOrVisitedJs.size < MAX_JS_GRAPH_FILES) {
|
|
587
|
+
queuedOrVisitedJs.add(resolved.relPath);
|
|
588
|
+
jsQueue.push(resolved);
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
for (const { filePath: htmlPath, rootDir: htmlRootDir } of htmlFiles) {
|
|
592
|
+
const rawHtml = readBoundedText(htmlPath, MAX_SCAN_BYTES);
|
|
593
|
+
if (!rawHtml) continue;
|
|
594
|
+
const htmlText = rawHtml.replace(HTML_COMMENT_REGEX, "");
|
|
595
|
+
const htmlDir = _path2.default.dirname(htmlPath);
|
|
596
|
+
SCRIPT_TAG_REGEX.lastIndex = 0;
|
|
597
|
+
let scriptMatch;
|
|
598
|
+
while ((scriptMatch = SCRIPT_TAG_REGEX.exec(htmlText)) !== null) {
|
|
599
|
+
const attrs = _nullishCoalesce(scriptMatch[1], () => ( ""));
|
|
600
|
+
const body = _nullishCoalesce(scriptMatch[2], () => ( ""));
|
|
601
|
+
const scriptType = (_nullishCoalesce(getHtmlAttr(attrs, ATTR_TYPE_REGEX), () => ( ""))).toLowerCase();
|
|
602
|
+
const isJsScript = !scriptType || scriptType === "module" || scriptType.includes("javascript") || scriptType.includes("ecmascript");
|
|
603
|
+
if (!isJsScript) continue;
|
|
604
|
+
const src = getHtmlAttr(attrs, ATTR_SRC_REGEX);
|
|
605
|
+
if (src) {
|
|
606
|
+
const resolved = resolveOutDirJsTarget(
|
|
607
|
+
src,
|
|
608
|
+
htmlDir,
|
|
609
|
+
resolvedOutDir,
|
|
610
|
+
allowedExtensions,
|
|
611
|
+
serverDirPrefixes,
|
|
612
|
+
htmlRootDir
|
|
613
|
+
);
|
|
614
|
+
if (resolved) {
|
|
615
|
+
htmlEntryFiles.add(resolved.relPath);
|
|
616
|
+
enqueueJs(resolved);
|
|
617
|
+
}
|
|
618
|
+
} else if (body.trim()) {
|
|
619
|
+
const { imports, workers } = extractRelativeSpecifiers(body, false);
|
|
620
|
+
for (const imp of imports) {
|
|
621
|
+
const resolved = resolveOutDirJsTarget(
|
|
622
|
+
imp,
|
|
623
|
+
htmlDir,
|
|
624
|
+
resolvedOutDir,
|
|
625
|
+
allowedExtensions,
|
|
626
|
+
serverDirPrefixes,
|
|
627
|
+
htmlRootDir
|
|
628
|
+
);
|
|
629
|
+
if (resolved) {
|
|
630
|
+
htmlEntryFiles.add(resolved.relPath);
|
|
631
|
+
enqueueJs(resolved);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
for (const workerSpec of workers) {
|
|
635
|
+
const resolved = resolveOutDirJsTarget(
|
|
636
|
+
workerSpec,
|
|
637
|
+
htmlDir,
|
|
638
|
+
resolvedOutDir,
|
|
639
|
+
allowedExtensions,
|
|
640
|
+
serverDirPrefixes,
|
|
641
|
+
htmlRootDir
|
|
642
|
+
);
|
|
643
|
+
if (resolved) {
|
|
644
|
+
workerEntryFiles.add(resolved.relPath);
|
|
645
|
+
enqueueJs(resolved);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
LINK_TAG_REGEX.lastIndex = 0;
|
|
651
|
+
let linkMatch;
|
|
652
|
+
while ((linkMatch = LINK_TAG_REGEX.exec(htmlText)) !== null) {
|
|
653
|
+
const attrs = _nullishCoalesce(linkMatch[1], () => ( ""));
|
|
654
|
+
const relAttr = (_nullishCoalesce(getHtmlAttr(attrs, ATTR_REL_REGEX), () => ( ""))).toLowerCase();
|
|
655
|
+
if (!relAttr) continue;
|
|
656
|
+
const relTokens = relAttr.split(/\s+/);
|
|
657
|
+
const isModulePreload = relTokens.includes("modulepreload");
|
|
658
|
+
const isPreload = relTokens.includes("preload");
|
|
659
|
+
if (!isModulePreload && !isPreload) continue;
|
|
660
|
+
if (isPreload && !isModulePreload) {
|
|
661
|
+
const asAttr = (_nullishCoalesce(getHtmlAttr(attrs, ATTR_AS_REGEX), () => ( ""))).toLowerCase();
|
|
662
|
+
if (asAttr && asAttr !== "script" && asAttr !== "worker") {
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
const href = getHtmlAttr(attrs, ATTR_HREF_REGEX);
|
|
667
|
+
if (!href) continue;
|
|
668
|
+
const resolved = resolveOutDirJsTarget(
|
|
669
|
+
href,
|
|
670
|
+
htmlDir,
|
|
671
|
+
resolvedOutDir,
|
|
672
|
+
allowedExtensions,
|
|
673
|
+
serverDirPrefixes,
|
|
674
|
+
htmlRootDir
|
|
675
|
+
);
|
|
676
|
+
if (resolved) {
|
|
677
|
+
preloadedFiles.add(resolved.relPath);
|
|
678
|
+
enqueueJs(resolved);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
let scannedJsFiles = 0;
|
|
683
|
+
let head = 0;
|
|
684
|
+
while (head < jsQueue.length && scannedJsFiles < MAX_JS_GRAPH_FILES) {
|
|
685
|
+
const current = jsQueue[head++];
|
|
686
|
+
const jsText = readBoundedText(current.absPath, MAX_SCAN_BYTES);
|
|
687
|
+
scannedJsFiles++;
|
|
688
|
+
if (!jsText) continue;
|
|
689
|
+
const currentDir = _path2.default.dirname(current.absPath);
|
|
690
|
+
const { imports, workers } = extractRelativeSpecifiers(jsText, true);
|
|
691
|
+
for (const imp of imports) {
|
|
692
|
+
const resolved = resolveOutDirJsTarget(
|
|
693
|
+
imp,
|
|
694
|
+
currentDir,
|
|
695
|
+
resolvedOutDir,
|
|
696
|
+
allowedExtensions,
|
|
697
|
+
serverDirPrefixes
|
|
698
|
+
);
|
|
699
|
+
if (resolved) {
|
|
700
|
+
enqueueJs(resolved);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
for (const workerSpec of workers) {
|
|
704
|
+
const resolved = resolveOutDirJsTarget(
|
|
705
|
+
workerSpec,
|
|
706
|
+
currentDir,
|
|
707
|
+
resolvedOutDir,
|
|
708
|
+
allowedExtensions,
|
|
709
|
+
serverDirPrefixes
|
|
710
|
+
);
|
|
711
|
+
if (resolved) {
|
|
712
|
+
workerEntryFiles.add(resolved.relPath);
|
|
713
|
+
enqueueJs(resolved);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const entryFiles = /* @__PURE__ */ new Set([...htmlEntryFiles, ...workerEntryFiles]);
|
|
718
|
+
if (htmlEntryFiles.size === 0 && preloadedFiles.size > 0) {
|
|
719
|
+
for (const preloaded of preloadedFiles) {
|
|
720
|
+
entryFiles.add(preloaded);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
htmlEntryFiles,
|
|
725
|
+
preloadedFiles,
|
|
726
|
+
workerEntryFiles,
|
|
727
|
+
reachableFiles,
|
|
728
|
+
entryFiles,
|
|
729
|
+
scannedHtmlFiles: htmlFiles.length,
|
|
730
|
+
scannedJsFiles
|
|
731
|
+
};
|
|
732
|
+
}
|
|
375
733
|
|
|
376
734
|
// src/core/sourcemap-vault.ts
|
|
377
735
|
|
|
@@ -381,7 +739,7 @@ var DEBUG_ID_COMMENT_REGEX = /(?:\/\/[#@]\s*debugId=([^\s*]+)|\/\*[#@]\s*debugId
|
|
|
381
739
|
var DEBUG_ID_LINE_REGEX = /[ \t]*(?:\/\/[#@]\s*debugId=[^\r\n]*|\/\*[#@]\s*debugId=[\s\S]*?\*\/)[ \t]*(?:\r?\n)?/g;
|
|
382
740
|
function extractDebugId(code) {
|
|
383
741
|
const match = code.match(DEBUG_ID_COMMENT_REGEX);
|
|
384
|
-
const id = _nullishCoalesce(_optionalChain([match, 'optionalAccess',
|
|
742
|
+
const id = _nullishCoalesce(_optionalChain([match, 'optionalAccess', _23 => _23[1]]), () => ( _optionalChain([match, 'optionalAccess', _24 => _24[2]])));
|
|
385
743
|
return id ? id.trim() : void 0;
|
|
386
744
|
}
|
|
387
745
|
function stripDebugIdComments(code) {
|
|
@@ -480,14 +838,14 @@ function updateAllIgnoreFiles(cwd, vaultDir) {
|
|
|
480
838
|
function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir = ".unpeek-maps", stripComments = true, config, options) {
|
|
481
839
|
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
482
840
|
const resolvedCwd = _path2.default.resolve(cwd);
|
|
483
|
-
const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
484
|
-
const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
485
|
-
const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
486
|
-
const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
841
|
+
const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _25 => _25.sourcemaps, 'optionalAccess', _26 => _26.vaultDir]), () => ( privateMapsDir)), () => ( ".unpeek-maps"));
|
|
842
|
+
const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _27 => _27.sourcemaps, 'optionalAccess', _28 => _28.keepPrivate]), () => ( keepPrivateMaps));
|
|
843
|
+
const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _29 => _29.sourcemaps, 'optionalAccess', _30 => _30.stripComments]), () => ( stripComments));
|
|
844
|
+
const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _31 => _31.updateIgnoreFiles]), () => ( true));
|
|
487
845
|
const dryRun = typeof options === "object" && options !== null ? _nullishCoalesce(options.dryRun, () => ( false)) : false;
|
|
488
846
|
const vaultDir = _path2.default.resolve(resolvedCwd, effectiveVaultDirName);
|
|
489
847
|
const publicDirsToCheck = /* @__PURE__ */ new Set();
|
|
490
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
848
|
+
if (_optionalChain([config, 'optionalAccess', _32 => _32.publicDirs]) && config.publicDirs.length > 0) {
|
|
491
849
|
for (const d of config.publicDirs) {
|
|
492
850
|
publicDirsToCheck.add(d);
|
|
493
851
|
}
|
|
@@ -539,7 +897,7 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
|
|
|
539
897
|
let entries;
|
|
540
898
|
try {
|
|
541
899
|
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
542
|
-
} catch (
|
|
900
|
+
} catch (e12) {
|
|
543
901
|
return;
|
|
544
902
|
}
|
|
545
903
|
for (const entry of entries) {
|
|
@@ -611,4 +969,5 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
|
|
|
611
969
|
|
|
612
970
|
|
|
613
971
|
|
|
614
|
-
|
|
972
|
+
|
|
973
|
+
exports.isWorkerOrServiceWorkerFile = isWorkerOrServiceWorkerFile; exports.hasNextServerSegment = hasNextServerSegment; exports.hasJsBundleFiles = hasJsBundleFiles; exports.detectTargetFramework = detectTargetFramework; exports.matchesGlobPattern = matchesGlobPattern; exports.scanClientBundles = scanClientBundles; exports.discoverHtmlEntryGraph = discoverHtmlEntryGraph; exports.SOURCE_MAP_COMMENT_REGEX = SOURCE_MAP_COMMENT_REGEX; exports.extractDebugId = extractDebugId; exports.stripDebugIdComments = stripDebugIdComments; exports.replaceOrAppendDebugId = replaceOrAppendDebugId; exports.stripSourceMapComments = stripSourceMapComments; exports.findMonorepoRoots = findMonorepoRoots; exports.relocateSourceMaps = relocateSourceMaps;
|
|
@@ -10,9 +10,9 @@ var _chunkBQ2O6HM5cjs = require('./chunk-BQ2O6HM5.cjs');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var _chunkAD6UFBPAcjs = require('./chunk-AD6UFBPA.cjs');
|
|
14
13
|
|
|
15
14
|
|
|
15
|
+
var _chunk4XSFPX2Zcjs = require('./chunk-4XSFPX2Z.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -21,7 +21,9 @@ var _chunkAD6UFBPAcjs = require('./chunk-AD6UFBPA.cjs');
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkOR5M3SN2cjs = require('./chunk-OR5M3SN2.cjs');
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
|
|
@@ -196,21 +198,29 @@ function matchesManifestEntry(relPath, manifestEntries) {
|
|
|
196
198
|
}
|
|
197
199
|
return false;
|
|
198
200
|
}
|
|
199
|
-
function isEntryChunk(relPath, index, allRelPaths, manifestEntries, isWorkerTarget) {
|
|
201
|
+
function isEntryChunk(relPath, index, allRelPaths, manifestEntries, isWorkerTarget, htmlGraph) {
|
|
200
202
|
const norm = relPath.replace(/\\/g, "/");
|
|
201
203
|
const base = _path2.default.basename(norm);
|
|
202
|
-
if (isWorkerTarget &&
|
|
204
|
+
if (isWorkerTarget && _chunk4XSFPX2Zcjs.isWorkerOrServiceWorkerFile.call(void 0, norm)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
if (_optionalChain([htmlGraph, 'optionalAccess', _7 => _7.workerEntryFiles, 'access', _8 => _8.has, 'call', _9 => _9(norm)])) {
|
|
203
208
|
return true;
|
|
204
209
|
}
|
|
205
210
|
if (matchesManifestEntry(norm, manifestEntries)) {
|
|
206
211
|
return true;
|
|
207
212
|
}
|
|
213
|
+
const hasKnownManifestEntry = manifestEntries.size > 0 && allRelPaths.some((p) => matchesManifestEntry(p.replace(/\\/g, "/"), manifestEntries));
|
|
214
|
+
const hasKnownHtmlEntry = manifestEntries.size === 0 && Boolean(htmlGraph && allRelPaths.some((p) => htmlGraph.entryFiles.has(p.replace(/\\/g, "/"))));
|
|
215
|
+
if (hasKnownHtmlEntry) {
|
|
216
|
+
return htmlGraph.entryFiles.has(norm);
|
|
217
|
+
}
|
|
208
218
|
if (ENTRY_PATTERN.test(norm) || ENTRY_PATTERN.test(base)) {
|
|
209
219
|
return true;
|
|
210
220
|
}
|
|
211
|
-
const hasAnyKnownEntry = allRelPaths.some((p) => {
|
|
221
|
+
const hasAnyKnownEntry = hasKnownManifestEntry || allRelPaths.some((p) => {
|
|
212
222
|
const n = p.replace(/\\/g, "/");
|
|
213
|
-
return
|
|
223
|
+
return ENTRY_PATTERN.test(n) || ENTRY_PATTERN.test(_path2.default.basename(n));
|
|
214
224
|
});
|
|
215
225
|
if (!hasAnyKnownEntry && index === 0) {
|
|
216
226
|
return true;
|
|
@@ -223,7 +233,7 @@ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWri
|
|
|
223
233
|
candidates.push(`${filePath}.map`);
|
|
224
234
|
}
|
|
225
235
|
candidates.push(_path2.default.join(vaultDir, `${relPath}.map`));
|
|
226
|
-
const decodedRel =
|
|
236
|
+
const decodedRel = _chunkOR5M3SN2cjs.safeDecodeURIComponent.call(void 0, relPath);
|
|
227
237
|
if (decodedRel !== relPath) {
|
|
228
238
|
candidates.push(_path2.default.join(vaultDir, `${decodedRel}.map`));
|
|
229
239
|
}
|
|
@@ -283,32 +293,39 @@ async function protectProject(options = {}) {
|
|
|
283
293
|
const effectiveConfigInput = options.profile ? { ..._nullishCoalesce(options.config, () => ( {})), profile: options.profile } : options.config;
|
|
284
294
|
const config = await _chunkBQ2O6HM5cjs.loadUnpeekConfig.call(void 0, cwd, effectiveConfigInput);
|
|
285
295
|
const effectiveProfile = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( config.profile)), () => ( "recommended"));
|
|
286
|
-
const { framework, outDir } =
|
|
296
|
+
const { framework, outDir } = _chunk4XSFPX2Zcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
|
|
287
297
|
const seed = typeof options.seed === "number" && Number.isFinite(options.seed) ? options.seed : typeof config.seed === "number" && Number.isFinite(config.seed) ? config.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
288
298
|
const dryRun = Boolean(options.dryRun);
|
|
289
|
-
const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access',
|
|
290
|
-
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access',
|
|
291
|
-
const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access',
|
|
292
|
-
const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access',
|
|
299
|
+
const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _10 => _10.sourcemaps, 'optionalAccess', _11 => _11.keepPrivate]))), () => ( true));
|
|
300
|
+
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _12 => _12.sourcemaps, 'optionalAccess', _13 => _13.vaultDir]))), () => ( ".unpeek-maps"));
|
|
301
|
+
const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _14 => _14.shield, 'optionalAccess', _15 => _15.deterrentMode]))), () => ( "passive"));
|
|
302
|
+
const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _16 => _16.shield, 'optionalAccess', _17 => _17.detectHeadless]))), () => ( false));
|
|
293
303
|
const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( (effectiveProfile === "minimal" ? false : true)));
|
|
294
|
-
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access',
|
|
304
|
+
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _18 => _18.vault, 'optionalAccess', _19 => _19.minStringLength]))), () => ( 4));
|
|
295
305
|
const aggressive = _nullishCoalesce(options.aggressive, () => ( (effectiveProfile === "strict" ? true : false)));
|
|
296
306
|
const scrubPaths = _nullishCoalesce(_nullishCoalesce(options.scrubPaths, () => ( config.scrubPaths)), () => ( (effectiveProfile === "strict" ? true : false)));
|
|
297
|
-
const masterSym =
|
|
298
|
-
const masterShield = injectRuntimeShield ?
|
|
307
|
+
const masterSym = _chunkOR5M3SN2cjs.deriveWindowKeySymbol.call(void 0, seed);
|
|
308
|
+
const masterShield = injectRuntimeShield ? _chunkOR5M3SN2cjs.generateRuntimeShield.call(void 0, {
|
|
299
309
|
seed,
|
|
300
310
|
deterrentMode,
|
|
301
311
|
detectHeadless,
|
|
302
312
|
windowKeySymbol: masterSym
|
|
303
313
|
}) : void 0;
|
|
304
314
|
const deferVaultWrites = dryRun || typeof options.maxGzipDelta === "number";
|
|
305
|
-
const vaultResult =
|
|
315
|
+
const vaultResult = _chunk4XSFPX2Zcjs.relocateSourceMaps.call(void 0, outDir, cwd, keepPrivateMaps, privateMapsDir, false, config, {
|
|
306
316
|
dryRun: deferVaultWrites
|
|
307
317
|
});
|
|
308
|
-
const clientFiles =
|
|
318
|
+
const clientFiles = _chunk4XSFPX2Zcjs.scanClientBundles.call(void 0, outDir, config);
|
|
309
319
|
const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
|
|
310
320
|
const manifestEntries = collectManifestEntryFiles(outDir, cwd, config);
|
|
311
321
|
const isWorkerTarget = config.target === "worker";
|
|
322
|
+
const extraHtmlDirs = [];
|
|
323
|
+
const parentOutDir = _path2.default.dirname(outDir);
|
|
324
|
+
const relParent = _path2.default.relative(cwd, parentOutDir);
|
|
325
|
+
if (relParent && !relParent.startsWith("..") && !_path2.default.isAbsolute(relParent) && !_chunk4XSFPX2Zcjs.hasNextServerSegment.call(void 0, parentOutDir, cwd)) {
|
|
326
|
+
extraHtmlDirs.push(parentOutDir);
|
|
327
|
+
}
|
|
328
|
+
const htmlGraph = _chunk4XSFPX2Zcjs.discoverHtmlEntryGraph.call(void 0, outDir, config, extraHtmlDirs);
|
|
312
329
|
let originalBytes = 0;
|
|
313
330
|
let protectedBytes = 0;
|
|
314
331
|
let totalHotFunctionsSkipped = 0;
|
|
@@ -350,9 +367,9 @@ async function protectProject(options = {}) {
|
|
|
350
367
|
for (let i = 0; i < clientFiles.length; i++) {
|
|
351
368
|
const filePath = clientFiles[i];
|
|
352
369
|
let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
|
|
353
|
-
const fileDebugId =
|
|
370
|
+
const fileDebugId = _chunk4XSFPX2Zcjs.extractDebugId.call(void 0, codeToTransform);
|
|
354
371
|
if (codeToTransform.includes("sourceMappingURL=")) {
|
|
355
|
-
const strippedRes =
|
|
372
|
+
const strippedRes = _chunk4XSFPX2Zcjs.stripSourceMapComments.call(void 0, codeToTransform);
|
|
356
373
|
codeToTransform = strippedRes.code;
|
|
357
374
|
if (strippedRes.stripped) {
|
|
358
375
|
vaultResult.strippedFilesCount++;
|
|
@@ -364,9 +381,16 @@ async function protectProject(options = {}) {
|
|
|
364
381
|
const relPath = allRelPaths[i];
|
|
365
382
|
const originalMap = keepPrivateMaps ? readOriginalSourceMapForFile(filePath, relPath, vaultResult.vaultDir, deferVaultWrites) : void 0;
|
|
366
383
|
const preExistingHits = countPreExistingEvalCalls(codeToTransform);
|
|
367
|
-
const isEntry = isEntryChunk(
|
|
384
|
+
const isEntry = isEntryChunk(
|
|
385
|
+
relPath,
|
|
386
|
+
i,
|
|
387
|
+
allRelPaths,
|
|
388
|
+
manifestEntries,
|
|
389
|
+
isWorkerTarget,
|
|
390
|
+
htmlGraph
|
|
391
|
+
);
|
|
368
392
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
369
|
-
const fileSeed =
|
|
393
|
+
const fileSeed = _chunkOR5M3SN2cjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
|
|
370
394
|
const transformOptions = {
|
|
371
395
|
seed: fileSeed,
|
|
372
396
|
minStringLength,
|
|
@@ -375,8 +399,8 @@ async function protectProject(options = {}) {
|
|
|
375
399
|
skipShieldPreamble: true,
|
|
376
400
|
shieldCoupled: injectRuntimeShield,
|
|
377
401
|
windowKeySymbol: masterSym,
|
|
378
|
-
expectedDelta: _optionalChain([masterShield, 'optionalAccess',
|
|
379
|
-
expectedStateHash: _optionalChain([masterShield, 'optionalAccess',
|
|
402
|
+
expectedDelta: _optionalChain([masterShield, 'optionalAccess', _20 => _20.expectedDelta]),
|
|
403
|
+
expectedStateHash: _optionalChain([masterShield, 'optionalAccess', _21 => _21.expectedStateHash]),
|
|
380
404
|
originalSourceMap: originalMap,
|
|
381
405
|
deterrentMode,
|
|
382
406
|
detectHeadless,
|
|
@@ -386,7 +410,7 @@ async function protectProject(options = {}) {
|
|
|
386
410
|
generateMap: keepPrivateMaps,
|
|
387
411
|
rootDir: cwd
|
|
388
412
|
};
|
|
389
|
-
const result =
|
|
413
|
+
const result = _chunkOR5M3SN2cjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
|
|
390
414
|
if (result.skippedReason === "parse-error") {
|
|
391
415
|
diagnostics.push({
|
|
392
416
|
code: "PARSE_FALLBACK",
|
|
@@ -396,7 +420,7 @@ async function protectProject(options = {}) {
|
|
|
396
420
|
});
|
|
397
421
|
} else if (result.skippedReason === "already-protected") {
|
|
398
422
|
alreadyProtectedCount++;
|
|
399
|
-
const prevHits = _optionalChain([existingManifest, 'optionalAccess',
|
|
423
|
+
const prevHits = _optionalChain([existingManifest, 'optionalAccess', _22 => _22.preExistingEvalFiles, 'optionalAccess', _23 => _23[relPath]]);
|
|
400
424
|
if (Array.isArray(prevHits) && prevHits.length > 0) {
|
|
401
425
|
preExistingEvalFiles[relPath] = prevHits;
|
|
402
426
|
} else if (preExistingHits.length > 0) {
|
|
@@ -420,33 +444,33 @@ async function protectProject(options = {}) {
|
|
|
420
444
|
}
|
|
421
445
|
let finalCode = result.code;
|
|
422
446
|
let preambleLineOffset = 0;
|
|
423
|
-
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess',
|
|
447
|
+
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _24 => _24.preambleCode]) && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
|
|
424
448
|
const prefix = `${masterShield.preambleCode}
|
|
425
449
|
`;
|
|
426
450
|
preambleLineOffset = (_nullishCoalesce(prefix.match(/\n/g), () => ( []))).length;
|
|
427
451
|
finalCode = `${prefix}${finalCode}`;
|
|
428
452
|
}
|
|
429
453
|
const rawTransformMap = result.sourceMap;
|
|
430
|
-
const shiftedTransformMap = rawTransformMap ?
|
|
454
|
+
const shiftedTransformMap = rawTransformMap ? _chunkOR5M3SN2cjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
|
|
431
455
|
let composedMap;
|
|
432
456
|
if (shiftedTransformMap && originalMap) {
|
|
433
|
-
composedMap =
|
|
457
|
+
composedMap = _chunkOR5M3SN2cjs.chainSourceMaps.call(void 0, shiftedTransformMap, originalMap);
|
|
434
458
|
} else if (originalMap) {
|
|
435
|
-
composedMap =
|
|
459
|
+
composedMap = _chunkOR5M3SN2cjs.flattenSourceMapSections.call(void 0, originalMap);
|
|
436
460
|
} else if (shiftedTransformMap) {
|
|
437
461
|
composedMap = shiftedTransformMap;
|
|
438
462
|
}
|
|
439
|
-
const originalMapDebugId = _nullishCoalesce(_optionalChain([originalMap, 'optionalAccess',
|
|
463
|
+
const originalMapDebugId = _nullishCoalesce(_optionalChain([originalMap, 'optionalAccess', _25 => _25.debugId]), () => ( _optionalChain([originalMap, 'optionalAccess', _26 => _26.debug_id])));
|
|
440
464
|
const hadDebugId = Boolean(fileDebugId || originalMapDebugId || result.debugId);
|
|
441
465
|
const shouldMintDebugId = hadDebugId || keepPrivateMaps && !result.skippedReason && Boolean(composedMap || originalMap);
|
|
442
466
|
let mintedDebugId;
|
|
443
467
|
if (shouldMintDebugId) {
|
|
444
|
-
const codeWithoutDebugId =
|
|
445
|
-
mintedDebugId =
|
|
468
|
+
const codeWithoutDebugId = _chunk4XSFPX2Zcjs.stripDebugIdComments.call(void 0, finalCode);
|
|
469
|
+
mintedDebugId = _chunkOR5M3SN2cjs.computeDeterministicDebugId.call(void 0,
|
|
446
470
|
codeWithoutDebugId,
|
|
447
|
-
_nullishCoalesce(_optionalChain([composedMap, 'optionalAccess',
|
|
471
|
+
_nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _27 => _27.mappings]), () => ( ""))
|
|
448
472
|
);
|
|
449
|
-
finalCode =
|
|
473
|
+
finalCode = _chunk4XSFPX2Zcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
|
|
450
474
|
if (composedMap) {
|
|
451
475
|
composedMap.debugId = mintedDebugId;
|
|
452
476
|
delete composedMap.debug_id;
|
|
@@ -482,7 +506,7 @@ async function protectProject(options = {}) {
|
|
|
482
506
|
}
|
|
483
507
|
if (!dryRun) {
|
|
484
508
|
if (deferVaultWrites) {
|
|
485
|
-
const finalVaultResult =
|
|
509
|
+
const finalVaultResult = _chunk4XSFPX2Zcjs.relocateSourceMaps.call(void 0,
|
|
486
510
|
outDir,
|
|
487
511
|
cwd,
|
|
488
512
|
keepPrivateMaps,
|
|
@@ -500,7 +524,7 @@ async function protectProject(options = {}) {
|
|
|
500
524
|
const vaultedMapPath = _path2.default.join(vaultResult.vaultDir, `${relPath}.map`);
|
|
501
525
|
const decodedMapPath = _path2.default.join(
|
|
502
526
|
vaultResult.vaultDir,
|
|
503
|
-
`${
|
|
527
|
+
`${_chunkOR5M3SN2cjs.safeDecodeURIComponent.call(void 0, relPath)}.map`
|
|
504
528
|
);
|
|
505
529
|
const targetMapPath = _fs2.default.existsSync(vaultedMapPath) ? vaultedMapPath : _fs2.default.existsSync(decodedMapPath) ? decodedMapPath : vaultedMapPath;
|
|
506
530
|
if (map) {
|