unpeek 2.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -21
- package/README.tr.md +65 -29
- package/dist/adapters/esbuild.cjs +13 -0
- package/dist/adapters/esbuild.d.cts +13 -0
- package/dist/adapters/esbuild.d.ts +11 -0
- package/dist/adapters/esbuild.js +13 -0
- package/dist/adapters/next/adapter.cjs +43 -0
- package/dist/{next → adapters/next}/adapter.d.cts +4 -4
- package/dist/{next → adapters/next}/adapter.d.ts +4 -4
- package/dist/adapters/next/adapter.js +43 -0
- package/dist/adapters/next/index.cjs +16 -0
- package/dist/adapters/next/index.d.cts +53 -0
- package/dist/adapters/next/index.d.ts +53 -0
- package/dist/adapters/next/index.js +16 -0
- package/dist/adapters/rollup.cjs +13 -0
- package/dist/adapters/rollup.d.cts +13 -0
- package/dist/adapters/rollup.d.ts +11 -0
- package/dist/adapters/rollup.js +13 -0
- package/dist/adapters/rspack.cjs +13 -0
- package/dist/adapters/rspack.d.cts +13 -0
- package/dist/adapters/rspack.d.ts +11 -0
- package/dist/adapters/rspack.js +13 -0
- package/dist/adapters/vite.cjs +13 -0
- package/dist/adapters/vite.d.cts +13 -0
- package/dist/adapters/vite.d.ts +11 -0
- package/dist/adapters/vite.js +13 -0
- package/dist/adapters/webpack.cjs +13 -0
- package/dist/adapters/webpack.d.cts +13 -0
- package/dist/adapters/webpack.d.ts +11 -0
- package/dist/adapters/webpack.js +13 -0
- package/dist/browser.cjs +8 -5
- package/dist/browser.d.cts +44 -3
- package/dist/browser.d.ts +44 -3
- package/dist/browser.js +10 -7
- package/dist/{chunk-5QD6FZPB.js → chunk-2JU3V7HW.js} +75 -43
- package/dist/chunk-3LWXEJU6.cjs +1054 -0
- package/dist/chunk-4FNZNIBW.js +7391 -0
- package/dist/chunk-7HXLHLLQ.cjs +503 -0
- package/dist/chunk-ADKRENAP.js +1054 -0
- package/dist/chunk-EN6QVR6P.js +89 -0
- package/dist/chunk-HHC7BUCK.js +503 -0
- package/dist/chunk-KLYFNMKS.cjs +7391 -0
- package/dist/chunk-L6BOM5VS.cjs +40 -0
- package/dist/{chunk-OOXSZTRV.js → chunk-LA6J3BT3.js} +26 -1
- package/dist/chunk-URPPSTHZ.cjs +89 -0
- package/dist/chunk-VG4Y26ZN.cjs +429 -0
- package/dist/{chunk-GZB7PFLY.js → chunk-W77DAC3H.js} +46 -64
- package/dist/chunk-X6EETCO6.cjs +352 -0
- package/dist/chunk-YCRMTXOE.js +429 -0
- package/dist/{chunk-GAVI2C44.cjs → chunk-ZG7BIAUI.cjs} +80 -48
- package/dist/cli/index.js +9861 -32
- package/dist/{types-BBSRUEab.d.cts → config-Y6JwVGwX.d.cts} +58 -86
- package/dist/{types-BBSRUEab.d.ts → config-Y6JwVGwX.d.ts} +58 -86
- package/dist/config.cjs +4 -16
- package/dist/config.d.cts +1 -12
- package/dist/config.d.ts +1 -12
- package/dist/config.js +5 -17
- package/dist/index-0O1WSfVP.d.ts +52 -0
- package/dist/index-COVHErnx.d.cts +52 -0
- package/dist/index.cjs +437 -9
- package/dist/index.d.cts +9 -17
- package/dist/index.d.ts +9 -17
- package/dist/index.js +438 -10
- package/dist/plugins/unplugin.cjs +21 -0
- package/dist/plugins/unplugin.d.cts +17 -0
- package/dist/plugins/unplugin.d.ts +15 -0
- package/dist/{bundler → plugins}/unplugin.js +6 -5
- package/dist/types-CMtZnV8C.d.ts +112 -0
- package/dist/types-D93PuOOl.d.cts +112 -0
- package/package.json +48 -52
- package/dist/ast/index.cjs +0 -17
- package/dist/ast/index.d.cts +0 -18
- package/dist/ast/index.d.ts +0 -18
- package/dist/ast/index.js +0 -17
- package/dist/bundler/unplugin.cjs +0 -20
- package/dist/bundler/unplugin.d.cts +0 -16
- package/dist/bundler/unplugin.d.ts +0 -14
- package/dist/chunk-24K5NDXH.cjs +0 -370
- package/dist/chunk-27HR647Q.js +0 -190
- package/dist/chunk-4TDLLEEU.cjs +0 -15
- package/dist/chunk-5LCMI2TL.js +0 -575
- package/dist/chunk-5M6Z7ZFT.cjs +0 -83
- package/dist/chunk-6N6S6WTQ.cjs +0 -423
- package/dist/chunk-7YVEHJVM.cjs +0 -575
- package/dist/chunk-J5CGNZDM.cjs +0 -190
- package/dist/chunk-KQWNFKT2.js +0 -423
- package/dist/chunk-LXP73HJC.cjs +0 -4532
- package/dist/chunk-R6EBIR3T.cjs +0 -14
- package/dist/chunk-S4S2WXGC.js +0 -14
- package/dist/chunk-UMPUYLLZ.js +0 -4532
- package/dist/chunk-X5MKMFMX.js +0 -83
- package/dist/cli/index.cjs +0 -324
- package/dist/cli/index.d.cts +0 -22
- package/dist/cli/index.d.ts +0 -22
- package/dist/esbuild.cjs +0 -15
- package/dist/esbuild.d.cts +0 -11
- package/dist/esbuild.d.ts +0 -11
- package/dist/esbuild.js +0 -13
- package/dist/next/adapter.cjs +0 -31
- package/dist/next/adapter.js +0 -31
- package/dist/next/index.cjs +0 -18
- package/dist/next/index.d.cts +0 -42
- package/dist/next/index.d.ts +0 -42
- package/dist/next/index.js +0 -18
- package/dist/rollup.cjs +0 -15
- package/dist/rollup.d.cts +0 -11
- package/dist/rollup.d.ts +0 -11
- package/dist/rollup.js +0 -13
- package/dist/runtime/index.cjs +0 -17
- package/dist/runtime/index.d.cts +0 -36
- package/dist/runtime/index.d.ts +0 -36
- package/dist/runtime/index.js +0 -17
- package/dist/vite.cjs +0 -15
- package/dist/vite.d.cts +0 -11
- package/dist/vite.d.ts +0 -11
- package/dist/vite.js +0 -13
- package/dist/webpack.cjs +0 -15
- package/dist/webpack.d.cts +0 -11
- package/dist/webpack.d.ts +0 -11
- package/dist/webpack.js +0 -13
package/dist/chunk-7YVEHJVM.cjs
DELETED
|
@@ -1,575 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunk24K5NDXHcjs = require('./chunk-24K5NDXH.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkLXP73HJCcjs = require('./chunk-LXP73HJC.cjs');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunk6N6S6WTQcjs = require('./chunk-6N6S6WTQ.cjs');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _chunkR6EBIR3Tcjs = require('./chunk-R6EBIR3T.cjs');
|
|
15
|
-
|
|
16
|
-
// src/core/protect.ts
|
|
17
|
-
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
18
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
19
|
-
var _zlib = require('zlib'); var _zlib2 = _interopRequireDefault(_zlib);
|
|
20
|
-
|
|
21
|
-
// src/bundler/detector.ts
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
25
|
-
var EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
26
|
-
"node_modules",
|
|
27
|
-
".unpeek-maps"
|
|
28
|
-
]);
|
|
29
|
-
var NEXT_CONFIG_FILES = ["next.config.ts", "next.config.js", "next.config.mjs", "next.config.cjs"];
|
|
30
|
-
var VITE_CONFIG_FILES = ["vite.config.ts", "vite.config.js", "vite.config.mjs", "vite.config.cjs"];
|
|
31
|
-
function escapeRegex(str) {
|
|
32
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
|
-
}
|
|
34
|
-
function extractConfigValue(rootDir, filenames, pattern) {
|
|
35
|
-
for (const filename of filenames) {
|
|
36
|
-
const filePath = _path2.default.join(rootDir, filename);
|
|
37
|
-
if (_fs2.default.existsSync(filePath)) {
|
|
38
|
-
try {
|
|
39
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
40
|
-
const match = content.match(pattern);
|
|
41
|
-
if (match && match[1]) {
|
|
42
|
-
return match[1].trim();
|
|
43
|
-
}
|
|
44
|
-
} catch (e2) {
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
|
-
function hasNextServerSegment(fullPath, rootDir, serverDirPrefixes) {
|
|
51
|
-
const normalized = fullPath.replace(/\\/g, "/");
|
|
52
|
-
if (normalized.includes("/node_modules/") || normalized.endsWith("/node_modules") || normalized.includes("/.unpeek-maps/") || normalized.endsWith("/.unpeek-maps")) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
if (/(?:^|\/)\.next\/(?:server|ssr)(?:\/|$)/i.test(normalized)) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
if (serverDirPrefixes && serverDirPrefixes.length > 0) {
|
|
59
|
-
for (const prefix of serverDirPrefixes) {
|
|
60
|
-
const normPrefix = prefix.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
61
|
-
if (normPrefix) {
|
|
62
|
-
const regex = new RegExp(`(?:^|\\/)${escapeRegex(normPrefix)}(?:\\/|$)`, "i");
|
|
63
|
-
if (regex.test(normalized)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (rootDir) {
|
|
70
|
-
const rel = _path2.default.relative(rootDir, fullPath).replace(/\\/g, "/");
|
|
71
|
-
const segments = rel.split("/").filter(Boolean);
|
|
72
|
-
if (segments.length > 0 && (segments[0].toLowerCase() === "server" || segments[0].toLowerCase() === "ssr")) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
79
|
-
let config = explicitConfig;
|
|
80
|
-
let outDirOverride;
|
|
81
|
-
if (typeof explicitOutDir === "object" && explicitOutDir !== null) {
|
|
82
|
-
config = explicitOutDir;
|
|
83
|
-
outDirOverride = config.outDir;
|
|
84
|
-
} else if (typeof explicitOutDir === "string") {
|
|
85
|
-
outDirOverride = explicitOutDir;
|
|
86
|
-
}
|
|
87
|
-
const rootDir = _path2.default.resolve(cwd);
|
|
88
|
-
let framework = _optionalChain([config, 'optionalAccess', _ => _.framework]);
|
|
89
|
-
const discoveredNextDist = extractConfigValue(
|
|
90
|
-
rootDir,
|
|
91
|
-
NEXT_CONFIG_FILES,
|
|
92
|
-
/(?:["']?distDir["']?\s*:\s*["']([^"']+)["'])/
|
|
93
|
-
);
|
|
94
|
-
const discoveredViteOut = extractConfigValue(
|
|
95
|
-
rootDir,
|
|
96
|
-
VITE_CONFIG_FILES,
|
|
97
|
-
/(?:["']?outDir["']?\s*:\s*["']([^"']+)["'])/
|
|
98
|
-
);
|
|
99
|
-
const discoveredViteAssets = extractConfigValue(
|
|
100
|
-
rootDir,
|
|
101
|
-
VITE_CONFIG_FILES,
|
|
102
|
-
/(?:["']?assetsDir["']?\s*:\s*["']([^"']+)["'])/
|
|
103
|
-
);
|
|
104
|
-
const nextDist = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _2 => _2.next, 'optionalAccess', _3 => _3.distDir]), () => ( discoveredNextDist)), () => ( ".next"));
|
|
105
|
-
const viteOut = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _4 => _4.vite, 'optionalAccess', _5 => _5.outDir]), () => ( discoveredViteOut)), () => ( "dist"));
|
|
106
|
-
const viteAssets = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _6 => _6.vite, 'optionalAccess', _7 => _7.assetsDir]), () => ( discoveredViteAssets)), () => ( "assets"));
|
|
107
|
-
if (!framework) {
|
|
108
|
-
const pkgPath = _path2.default.join(rootDir, "package.json");
|
|
109
|
-
if (_fs2.default.existsSync(pkgPath)) {
|
|
110
|
-
try {
|
|
111
|
-
const pkgRaw = _fs2.default.readFileSync(pkgPath, "utf8");
|
|
112
|
-
const pkg = JSON.parse(pkgRaw);
|
|
113
|
-
const allDeps = {
|
|
114
|
-
..._nullishCoalesce(pkg.dependencies, () => ( {})),
|
|
115
|
-
..._nullishCoalesce(pkg.devDependencies, () => ( {}))
|
|
116
|
-
};
|
|
117
|
-
if ("next" in allDeps) {
|
|
118
|
-
framework = "nextjs";
|
|
119
|
-
} else if ("vite" in allDeps) {
|
|
120
|
-
framework = "vite";
|
|
121
|
-
} else if ("webpack" in allDeps || "react-scripts" in allDeps || "@rspack/core" in allDeps) {
|
|
122
|
-
framework = "webpack";
|
|
123
|
-
}
|
|
124
|
-
} catch (e3) {
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const nextChunksDir = _path2.default.join(rootDir, nextDist, "static", "chunks");
|
|
129
|
-
const nextExportChunksDir = _path2.default.join(rootDir, "out", "_next", "static", "chunks");
|
|
130
|
-
const nextExportDir = _path2.default.join(rootDir, "out");
|
|
131
|
-
const nextDistDir = _path2.default.join(rootDir, nextDist);
|
|
132
|
-
const distAssetsDir = _path2.default.join(rootDir, viteOut, viteAssets);
|
|
133
|
-
const distDir = _path2.default.join(rootDir, viteOut);
|
|
134
|
-
const buildDir = _path2.default.join(rootDir, "build");
|
|
135
|
-
const publicDir = _path2.default.join(rootDir, "public");
|
|
136
|
-
if (!framework) {
|
|
137
|
-
if (_fs2.default.existsSync(nextChunksDir) || _fs2.default.existsSync(nextDistDir) || _fs2.default.existsSync(nextExportChunksDir) || discoveredNextDist !== void 0) {
|
|
138
|
-
framework = "nextjs";
|
|
139
|
-
} else if (_fs2.default.existsSync(distAssetsDir) || discoveredViteOut !== void 0) {
|
|
140
|
-
framework = "vite";
|
|
141
|
-
} else if (_fs2.default.existsSync(buildDir)) {
|
|
142
|
-
framework = "webpack";
|
|
143
|
-
} else if (outDirOverride) {
|
|
144
|
-
const normExplicit = outDirOverride.replace(/\\/g, "/");
|
|
145
|
-
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next")) {
|
|
146
|
-
framework = "nextjs";
|
|
147
|
-
} else if (normExplicit.includes(`${viteOut}/${viteAssets}`) || normExplicit.includes("dist/assets")) {
|
|
148
|
-
framework = "vite";
|
|
149
|
-
} else if (normExplicit.includes("build")) {
|
|
150
|
-
framework = "webpack";
|
|
151
|
-
} else {
|
|
152
|
-
framework = "vanilla";
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
framework = "vanilla";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (outDirOverride) {
|
|
159
|
-
return {
|
|
160
|
-
framework,
|
|
161
|
-
outDir: _path2.default.resolve(rootDir, outDirOverride)
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
let outDir;
|
|
165
|
-
if (framework === "nextjs") {
|
|
166
|
-
if (_fs2.default.existsSync(nextExportChunksDir)) {
|
|
167
|
-
outDir = nextExportChunksDir;
|
|
168
|
-
} else if (_fs2.default.existsSync(nextChunksDir)) {
|
|
169
|
-
outDir = nextChunksDir;
|
|
170
|
-
} else if (_fs2.default.existsSync(nextExportDir)) {
|
|
171
|
-
outDir = nextExportDir;
|
|
172
|
-
} else if (_fs2.default.existsSync(nextDistDir)) {
|
|
173
|
-
outDir = nextChunksDir;
|
|
174
|
-
} else {
|
|
175
|
-
outDir = nextChunksDir;
|
|
176
|
-
}
|
|
177
|
-
} else if (framework === "vite") {
|
|
178
|
-
outDir = _fs2.default.existsSync(distAssetsDir) ? distAssetsDir : distDir;
|
|
179
|
-
} else if (framework === "webpack") {
|
|
180
|
-
if (_fs2.default.existsSync(distDir)) {
|
|
181
|
-
outDir = distDir;
|
|
182
|
-
} else if (_fs2.default.existsSync(buildDir)) {
|
|
183
|
-
outDir = buildDir;
|
|
184
|
-
} else {
|
|
185
|
-
outDir = distDir;
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
const candidates = [nextExportChunksDir, nextChunksDir, distAssetsDir, distDir, buildDir, publicDir];
|
|
189
|
-
const existing = candidates.find((candidate) => _fs2.default.existsSync(candidate));
|
|
190
|
-
outDir = _nullishCoalesce(existing, () => ( distDir));
|
|
191
|
-
}
|
|
192
|
-
return { framework, outDir };
|
|
193
|
-
}
|
|
194
|
-
function scanClientBundles(outDir, config) {
|
|
195
|
-
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
196
|
-
if (!_fs2.default.existsSync(resolvedOutDir)) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
const results = [];
|
|
200
|
-
const serverDirPrefixes = [];
|
|
201
|
-
if (_optionalChain([config, 'optionalAccess', _8 => _8.next, 'optionalAccess', _9 => _9.distDir])) {
|
|
202
|
-
serverDirPrefixes.push(
|
|
203
|
-
_path2.default.join(config.next.distDir, "server"),
|
|
204
|
-
_path2.default.join(config.next.distDir, "ssr")
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (_optionalChain([config, 'optionalAccess', _10 => _10.vite, 'optionalAccess', _11 => _11.outDir])) {
|
|
208
|
-
serverDirPrefixes.push(_path2.default.join(config.vite.outDir, "server"));
|
|
209
|
-
}
|
|
210
|
-
const allowedExtensions = _optionalChain([config, 'optionalAccess', _12 => _12.extensions]) && config.extensions.length > 0 ? new Set(config.extensions.map((e) => e.startsWith(".") ? e.toLowerCase() : `.${e.toLowerCase()}`)) : SUPPORTED_EXTENSIONS;
|
|
211
|
-
function walk(currentDir) {
|
|
212
|
-
if (hasNextServerSegment(currentDir, resolvedOutDir, serverDirPrefixes)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
let entries;
|
|
216
|
-
try {
|
|
217
|
-
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
218
|
-
} catch (e4) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
for (const entry of entries) {
|
|
222
|
-
const fullPath = _path2.default.join(currentDir, entry.name);
|
|
223
|
-
if (entry.isDirectory()) {
|
|
224
|
-
if (EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
walk(fullPath);
|
|
231
|
-
} else if (entry.isFile()) {
|
|
232
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
const ext = _path2.default.extname(entry.name).toLowerCase();
|
|
236
|
-
if (allowedExtensions.has(ext)) {
|
|
237
|
-
results.push(fullPath);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
walk(resolvedOutDir);
|
|
243
|
-
return results.sort();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/bundler/sourcemap-vault.ts
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var SOURCE_MAP_COMMENT_REGEX = /(?:^\s*\/\/[#@]\s*sourceMappingURL=.*$|\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/)\s*/gm;
|
|
250
|
-
function ensureIgnoreEntry(dir, fileName, entryName) {
|
|
251
|
-
const filePath = _path2.default.join(_path2.default.resolve(dir), fileName);
|
|
252
|
-
if (!_fs2.default.existsSync(filePath)) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
256
|
-
const normalizedEntry = entryName.endsWith("/") ? entryName : `${entryName}/`;
|
|
257
|
-
const bareEntry = normalizedEntry.slice(0, -1);
|
|
258
|
-
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
259
|
-
if (!lines.includes(normalizedEntry) && !lines.includes(bareEntry) && !lines.includes(".unpeek-maps") && !lines.includes(".unpeek-maps/")) {
|
|
260
|
-
const prefix = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
261
|
-
_fs2.default.writeFileSync(filePath, `${content}${prefix}${normalizedEntry}
|
|
262
|
-
`, "utf8");
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function isSubdirectoryOrSame(parent, child) {
|
|
266
|
-
const rel = _path2.default.relative(parent, child);
|
|
267
|
-
return rel === "" || !rel.startsWith("..") && !_path2.default.isAbsolute(rel);
|
|
268
|
-
}
|
|
269
|
-
function findMonorepoRoots(cwd) {
|
|
270
|
-
const resolved = _path2.default.resolve(cwd);
|
|
271
|
-
const dirs = [resolved];
|
|
272
|
-
let curr = resolved;
|
|
273
|
-
while (true) {
|
|
274
|
-
const parent = _path2.default.dirname(curr);
|
|
275
|
-
if (!parent || parent === curr) {
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
const hasGit = _fs2.default.existsSync(_path2.default.join(parent, ".git"));
|
|
279
|
-
const hasWorkspace = _fs2.default.existsSync(_path2.default.join(parent, "pnpm-workspace.yaml"));
|
|
280
|
-
const hasGitIgnore = _fs2.default.existsSync(_path2.default.join(parent, ".gitignore"));
|
|
281
|
-
const hasDockerIgnore = _fs2.default.existsSync(_path2.default.join(parent, ".dockerignore"));
|
|
282
|
-
const hasPkgJson = _fs2.default.existsSync(_path2.default.join(parent, "package.json"));
|
|
283
|
-
if (hasGit || hasWorkspace || hasGitIgnore || hasDockerIgnore || hasPkgJson) {
|
|
284
|
-
dirs.push(parent);
|
|
285
|
-
}
|
|
286
|
-
if (hasGit || hasWorkspace) {
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
curr = parent;
|
|
290
|
-
}
|
|
291
|
-
return dirs;
|
|
292
|
-
}
|
|
293
|
-
function checkDockerIgnoreMissing(cwd, ignoreEntry) {
|
|
294
|
-
const candidateDirs = findMonorepoRoots(cwd);
|
|
295
|
-
let foundAnyDockerIgnore = false;
|
|
296
|
-
for (const dir of candidateDirs) {
|
|
297
|
-
const filePath = _path2.default.join(dir, ".dockerignore");
|
|
298
|
-
if (_fs2.default.existsSync(filePath)) {
|
|
299
|
-
foundAnyDockerIgnore = true;
|
|
300
|
-
const content = _fs2.default.readFileSync(filePath, "utf8");
|
|
301
|
-
const normalizedEntry = ignoreEntry.endsWith("/") ? ignoreEntry : `${ignoreEntry}/`;
|
|
302
|
-
const bareEntry = normalizedEntry.slice(0, -1);
|
|
303
|
-
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
304
|
-
if (lines.includes(normalizedEntry) || lines.includes(bareEntry) || lines.includes(".unpeek-maps") || lines.includes(".unpeek-maps/")) {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
function updateAllIgnoreFiles(cwd, vaultDir) {
|
|
312
|
-
const candidateDirs = findMonorepoRoots(cwd);
|
|
313
|
-
for (const dir of candidateDirs) {
|
|
314
|
-
const relFromDir = _path2.default.relative(dir, vaultDir).replace(/\\/g, "/");
|
|
315
|
-
const entry = relFromDir && !relFromDir.startsWith("..") ? `${relFromDir}/` : ".unpeek-maps/";
|
|
316
|
-
ensureIgnoreEntry(dir, ".gitignore", entry);
|
|
317
|
-
ensureIgnoreEntry(dir, ".dockerignore", entry);
|
|
318
|
-
ensureIgnoreEntry(dir, ".npmignore", entry);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir = ".unpeek-maps", stripComments = true, config, options) {
|
|
322
|
-
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
323
|
-
const resolvedCwd = _path2.default.resolve(cwd);
|
|
324
|
-
const effectiveVaultDirName = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _13 => _13.sourcemaps, 'optionalAccess', _14 => _14.vaultDir]), () => ( privateMapsDir)), () => ( ".unpeek-maps"));
|
|
325
|
-
const effectiveKeepPrivate = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _15 => _15.sourcemaps, 'optionalAccess', _16 => _16.keepPrivate]), () => ( keepPrivateMaps));
|
|
326
|
-
const effectiveStripComments = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _17 => _17.sourcemaps, 'optionalAccess', _18 => _18.stripComments]), () => ( stripComments));
|
|
327
|
-
const updateIgnoreFiles = typeof options === "boolean" ? options : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.updateIgnoreFiles]), () => ( true));
|
|
328
|
-
const vaultDir = _path2.default.resolve(resolvedCwd, effectiveVaultDirName);
|
|
329
|
-
const publicDirsToCheck = /* @__PURE__ */ new Set();
|
|
330
|
-
if (_optionalChain([config, 'optionalAccess', _20 => _20.publicDirs]) && config.publicDirs.length > 0) {
|
|
331
|
-
for (const d of config.publicDirs) {
|
|
332
|
-
publicDirsToCheck.add(d);
|
|
333
|
-
}
|
|
334
|
-
} else {
|
|
335
|
-
publicDirsToCheck.add("public");
|
|
336
|
-
publicDirsToCheck.add("static");
|
|
337
|
-
publicDirsToCheck.add("assets");
|
|
338
|
-
}
|
|
339
|
-
if (effectiveKeepPrivate !== false) {
|
|
340
|
-
if (!isSubdirectoryOrSame(resolvedCwd, vaultDir)) {
|
|
341
|
-
throw new (0, _chunkR6EBIR3Tcjs.UnpeekError)(
|
|
342
|
-
"ERR_SECURITY_PATH_TRAVERSAL",
|
|
343
|
-
`[unpeek] Security Error: privateMapsDir (${vaultDir}) cannot traverse outside cwd (${resolvedCwd}).`
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
if (isSubdirectoryOrSame(resolvedOutDir, vaultDir)) {
|
|
347
|
-
throw new Error(
|
|
348
|
-
`[unpeek] Security Error: privateMapsDir cannot be located inside outDir (${resolvedOutDir}). This would expose private source maps to the web server.`
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
for (const pubDir of publicDirsToCheck) {
|
|
352
|
-
const resolvedPublicDir = _path2.default.resolve(resolvedCwd, pubDir);
|
|
353
|
-
if (isSubdirectoryOrSame(resolvedPublicDir, vaultDir)) {
|
|
354
|
-
throw new Error(
|
|
355
|
-
`[unpeek] Security Error: privateMapsDir cannot be located inside publicDir (${resolvedPublicDir}). This would expose private source maps to the web server.`
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const relVault = _path2.default.relative(resolvedCwd, vaultDir).replace(/\\/g, "/");
|
|
361
|
-
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
362
|
-
const dockerIgnoreMissing = checkDockerIgnoreMissing(resolvedCwd, ignoreEntry);
|
|
363
|
-
const movedFiles = [];
|
|
364
|
-
let movedMapsCount = 0;
|
|
365
|
-
let strippedFilesCount = 0;
|
|
366
|
-
if (!_fs2.default.existsSync(resolvedOutDir)) {
|
|
367
|
-
return {
|
|
368
|
-
movedMapsCount: 0,
|
|
369
|
-
strippedFilesCount: 0,
|
|
370
|
-
vaultDir,
|
|
371
|
-
movedFiles: [],
|
|
372
|
-
dockerIgnoreMissing
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
function walkForMaps(currentDir) {
|
|
376
|
-
if (hasNextServerSegment(currentDir, resolvedOutDir)) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
let entries;
|
|
380
|
-
try {
|
|
381
|
-
entries = _fs2.default.readdirSync(currentDir, { withFileTypes: true });
|
|
382
|
-
} catch (e5) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
for (const entry of entries) {
|
|
386
|
-
const fullPath = _path2.default.join(currentDir, entry.name);
|
|
387
|
-
if (entry.isDirectory()) {
|
|
388
|
-
if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (hasNextServerSegment(fullPath, resolvedOutDir)) {
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
walkForMaps(fullPath);
|
|
395
|
-
} else if (entry.isFile() && entry.name.endsWith(".map")) {
|
|
396
|
-
if (effectiveKeepPrivate !== false) {
|
|
397
|
-
const relPath = _path2.default.relative(resolvedOutDir, fullPath);
|
|
398
|
-
const targetPath = _path2.default.join(vaultDir, relPath);
|
|
399
|
-
_fs2.default.mkdirSync(_path2.default.dirname(targetPath), { recursive: true });
|
|
400
|
-
_fs2.default.copyFileSync(fullPath, targetPath);
|
|
401
|
-
_fs2.default.unlinkSync(fullPath);
|
|
402
|
-
movedFiles.push(targetPath);
|
|
403
|
-
} else {
|
|
404
|
-
_fs2.default.unlinkSync(fullPath);
|
|
405
|
-
}
|
|
406
|
-
movedMapsCount++;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
walkForMaps(resolvedOutDir);
|
|
411
|
-
if (updateIgnoreFiles && effectiveKeepPrivate !== false && movedMapsCount > 0) {
|
|
412
|
-
updateAllIgnoreFiles(resolvedCwd, vaultDir);
|
|
413
|
-
}
|
|
414
|
-
if (effectiveStripComments) {
|
|
415
|
-
const clientFiles = scanClientBundles(resolvedOutDir, config);
|
|
416
|
-
for (const filePath of clientFiles) {
|
|
417
|
-
const original = _fs2.default.readFileSync(filePath, "utf8");
|
|
418
|
-
if (original.includes("sourceMappingURL=")) {
|
|
419
|
-
const stripped = original.replace(SOURCE_MAP_COMMENT_REGEX, "");
|
|
420
|
-
if (stripped !== original) {
|
|
421
|
-
_fs2.default.writeFileSync(filePath, stripped, "utf8");
|
|
422
|
-
strippedFilesCount++;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return {
|
|
428
|
-
movedMapsCount,
|
|
429
|
-
strippedFilesCount,
|
|
430
|
-
vaultDir,
|
|
431
|
-
movedFiles,
|
|
432
|
-
dockerIgnoreMissing
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// src/core/protect.ts
|
|
437
|
-
var ENTRY_PATTERN = /^(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
|
|
438
|
-
function isEntryChunk(relPath, index, allRelPaths) {
|
|
439
|
-
const norm = relPath.replace(/\\/g, "/");
|
|
440
|
-
const base = _path2.default.basename(norm);
|
|
441
|
-
if (ENTRY_PATTERN.test(norm) || ENTRY_PATTERN.test(base)) {
|
|
442
|
-
return true;
|
|
443
|
-
}
|
|
444
|
-
const hasAnyPatternMatch = allRelPaths.some((p) => {
|
|
445
|
-
const n = p.replace(/\\/g, "/");
|
|
446
|
-
return ENTRY_PATTERN.test(n) || ENTRY_PATTERN.test(_path2.default.basename(n));
|
|
447
|
-
});
|
|
448
|
-
if (!hasAnyPatternMatch && index === 0) {
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
async function protectProject(options = {}) {
|
|
454
|
-
const startTime = performance.now();
|
|
455
|
-
const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
456
|
-
const config = await _chunk24K5NDXHcjs.loadUnpeekConfig.call(void 0, cwd, options.config);
|
|
457
|
-
const { framework, outDir } = detectTargetFramework(cwd, options.outDir, config);
|
|
458
|
-
const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
459
|
-
const keepPrivateMaps = _nullishCoalesce(_nullishCoalesce(options.keepPrivateMaps, () => ( _optionalChain([config, 'access', _21 => _21.sourcemaps, 'optionalAccess', _22 => _22.keepPrivate]))), () => ( true));
|
|
460
|
-
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _23 => _23.sourcemaps, 'optionalAccess', _24 => _24.vaultDir]))), () => ( ".unpeek-maps"));
|
|
461
|
-
const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'access', _25 => _25.shield, 'optionalAccess', _26 => _26.deterrentMode]))), () => ( "passive"));
|
|
462
|
-
const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'access', _27 => _27.shield, 'optionalAccess', _28 => _28.detectHeadless]))), () => ( false));
|
|
463
|
-
const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( true));
|
|
464
|
-
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'access', _29 => _29.vault, 'optionalAccess', _30 => _30.minStringLength]))), () => ( 4));
|
|
465
|
-
const aggressive = _nullishCoalesce(options.aggressive, () => ( false));
|
|
466
|
-
const masterSym = _chunk6N6S6WTQcjs.deriveWindowKeySymbol.call(void 0, seed);
|
|
467
|
-
const masterShield = injectRuntimeShield ? _chunk6N6S6WTQcjs.generateRuntimeShield.call(void 0, {
|
|
468
|
-
seed,
|
|
469
|
-
deterrentMode,
|
|
470
|
-
detectHeadless,
|
|
471
|
-
windowKeySymbol: masterSym
|
|
472
|
-
}) : void 0;
|
|
473
|
-
const vaultResult = relocateSourceMaps(outDir, cwd, keepPrivateMaps, privateMapsDir, false, config);
|
|
474
|
-
const clientFiles = scanClientBundles(outDir, config);
|
|
475
|
-
const allRelPaths = clientFiles.map((f) => _path2.default.relative(outDir, f).replace(/\\/g, "/"));
|
|
476
|
-
let originalBytes = 0;
|
|
477
|
-
let protectedBytes = 0;
|
|
478
|
-
let totalHotFunctionsSkipped = 0;
|
|
479
|
-
let totalColdFunctionsProtected = 0;
|
|
480
|
-
let totalEncryptedStrings = 0;
|
|
481
|
-
let totalMangledSymbols = 0;
|
|
482
|
-
let processedFiles = 0;
|
|
483
|
-
const allOrigBufs = [];
|
|
484
|
-
const allProtBufs = [];
|
|
485
|
-
const stagedFiles = [];
|
|
486
|
-
try {
|
|
487
|
-
for (let i = 0; i < clientFiles.length; i++) {
|
|
488
|
-
const filePath = clientFiles[i];
|
|
489
|
-
let codeToTransform = _fs2.default.readFileSync(filePath, "utf8");
|
|
490
|
-
if (codeToTransform.includes("sourceMappingURL=")) {
|
|
491
|
-
codeToTransform = codeToTransform.replace(SOURCE_MAP_COMMENT_REGEX, "");
|
|
492
|
-
vaultResult.strippedFilesCount++;
|
|
493
|
-
}
|
|
494
|
-
const origBuf = Buffer.from(codeToTransform, "utf8");
|
|
495
|
-
originalBytes += origBuf.byteLength;
|
|
496
|
-
allOrigBufs.push(origBuf);
|
|
497
|
-
const relPath = allRelPaths[i];
|
|
498
|
-
const isEntry = isEntryChunk(relPath, i, allRelPaths);
|
|
499
|
-
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
500
|
-
const fileSeed = _chunk6N6S6WTQcjs.computeFnv1aHash.call(void 0, `${relPath}:${i}`, seed);
|
|
501
|
-
const transformOptions = {
|
|
502
|
-
seed: fileSeed,
|
|
503
|
-
minStringLength,
|
|
504
|
-
filename: _path2.default.basename(filePath),
|
|
505
|
-
injectRuntimeShield: shouldInjectShield,
|
|
506
|
-
skipShieldPreamble: true,
|
|
507
|
-
shieldCoupled: injectRuntimeShield,
|
|
508
|
-
windowKeySymbol: masterSym,
|
|
509
|
-
expectedDelta: _optionalChain([masterShield, 'optionalAccess', _31 => _31.expectedDelta]),
|
|
510
|
-
deterrentMode,
|
|
511
|
-
detectHeadless,
|
|
512
|
-
aggressive,
|
|
513
|
-
config
|
|
514
|
-
};
|
|
515
|
-
const result = _chunkLXP73HJCcjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
|
|
516
|
-
let finalCode = result.code;
|
|
517
|
-
if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _32 => _32.preambleCode]) && !finalCode.includes("__unpeek_tampered") && !finalCode.includes(masterShield.integrityCheckFnName) && !finalCode.startsWith(masterShield.preambleCode)) {
|
|
518
|
-
finalCode = `${masterShield.preambleCode}
|
|
519
|
-
${finalCode}`;
|
|
520
|
-
}
|
|
521
|
-
const tmpPath = `${filePath}.unpeek.tmp`;
|
|
522
|
-
_fs2.default.writeFileSync(tmpPath, finalCode, "utf8");
|
|
523
|
-
stagedFiles.push({ tmpPath, finalPath: filePath });
|
|
524
|
-
const protBuf = Buffer.from(finalCode, "utf8");
|
|
525
|
-
protectedBytes += protBuf.byteLength;
|
|
526
|
-
allProtBufs.push(protBuf);
|
|
527
|
-
totalHotFunctionsSkipped += result.hotPathReport.hotFunctionsSkipped.length;
|
|
528
|
-
totalColdFunctionsProtected += result.hotPathReport.coldFunctionsProtected.length;
|
|
529
|
-
totalEncryptedStrings += result.encryptedStringsCount;
|
|
530
|
-
totalMangledSymbols += result.mangledSymbolsCount;
|
|
531
|
-
processedFiles++;
|
|
532
|
-
}
|
|
533
|
-
for (const { tmpPath, finalPath } of stagedFiles) {
|
|
534
|
-
_fs2.default.renameSync(tmpPath, finalPath);
|
|
535
|
-
}
|
|
536
|
-
} catch (error) {
|
|
537
|
-
for (const { tmpPath } of stagedFiles) {
|
|
538
|
-
if (_fs2.default.existsSync(tmpPath)) {
|
|
539
|
-
try {
|
|
540
|
-
_fs2.default.unlinkSync(tmpPath);
|
|
541
|
-
} catch (e6) {
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
throw error;
|
|
546
|
-
}
|
|
547
|
-
const originalGzipBytes = allOrigBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allOrigBufs)).byteLength : 0;
|
|
548
|
-
const protectedGzipBytes = allProtBufs.length > 0 ? _zlib2.default.gzipSync(Buffer.concat(allProtBufs)).byteLength : 0;
|
|
549
|
-
const gzipDeltaPercent = originalGzipBytes > 0 ? Number(((protectedGzipBytes - originalGzipBytes) / originalGzipBytes * 100).toFixed(2)) : 0;
|
|
550
|
-
const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
|
|
551
|
-
return {
|
|
552
|
-
framework,
|
|
553
|
-
outDir,
|
|
554
|
-
processedFiles,
|
|
555
|
-
movedSourceMaps: vaultResult.movedMapsCount,
|
|
556
|
-
originalBytes,
|
|
557
|
-
protectedBytes,
|
|
558
|
-
originalGzipBytes,
|
|
559
|
-
protectedGzipBytes,
|
|
560
|
-
gzipDeltaPercent,
|
|
561
|
-
totalHotFunctionsSkipped,
|
|
562
|
-
totalColdFunctionsProtected,
|
|
563
|
-
totalEncryptedStrings,
|
|
564
|
-
totalMangledSymbols,
|
|
565
|
-
elapsedMs,
|
|
566
|
-
tier: aggressive ? "Tier 2" : "Tier 1",
|
|
567
|
-
aggressive,
|
|
568
|
-
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
exports.detectTargetFramework = detectTargetFramework; exports.protectProject = protectProject;
|