unpeek 4.0.0 → 4.1.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 +21 -12
- package/README.tr.md +20 -11
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.d.cts +1 -1
- package/dist/adapters/esbuild.d.ts +1 -1
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +6 -6
- package/dist/adapters/next/adapter.d.cts +1 -1
- package/dist/adapters/next/adapter.d.ts +1 -1
- package/dist/adapters/next/adapter.js +5 -5
- package/dist/adapters/next/index.cjs +6 -6
- package/dist/adapters/next/index.js +5 -5
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.d.cts +1 -1
- package/dist/adapters/rollup.d.ts +1 -1
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.d.cts +1 -1
- package/dist/adapters/rspack.d.ts +1 -1
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.d.cts +1 -1
- package/dist/adapters/vite.d.ts +1 -1
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.d.cts +1 -1
- package/dist/adapters/webpack.d.ts +1 -1
- package/dist/adapters/webpack.js +3 -3
- package/dist/browser.cjs +2 -2
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +1 -1
- package/dist/chunk-32GLSJAW.js +614 -0
- package/dist/{chunk-W77DAC3H.js → chunk-6EWFL4LQ.js} +16 -0
- package/dist/{chunk-4FNZNIBW.js → chunk-6KLUNEKE.js} +2538 -547
- package/dist/chunk-AD6UFBPA.cjs +614 -0
- package/dist/{chunk-X6EETCO6.cjs → chunk-BQ2O6HM5.cjs} +16 -0
- package/dist/{chunk-ZG7BIAUI.cjs → chunk-FLZ4FSP5.cjs} +58 -17
- package/dist/{chunk-2JU3V7HW.js → chunk-HV47WJIR.js} +52 -11
- package/dist/{chunk-VG4Y26ZN.cjs → chunk-Q4DFRMAV.cjs} +53 -36
- package/dist/{chunk-HHC7BUCK.js → chunk-STTUFUDC.js} +114 -16
- package/dist/{chunk-YCRMTXOE.js → chunk-TOUYQ4N5.js} +30 -13
- package/dist/{chunk-KLYFNMKS.cjs → chunk-VLL4THTG.cjs} +2727 -736
- package/dist/{chunk-7HXLHLLQ.cjs → chunk-WYW5UOBE.cjs} +136 -38
- package/dist/cli/index.js +2240 -572
- package/dist/{config-Y6JwVGwX.d.cts → config-BFAZrfjQ.d.cts} +2 -0
- package/dist/{config-Y6JwVGwX.d.ts → config-BFAZrfjQ.d.ts} +2 -0
- package/dist/config.cjs +2 -2
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/{index-COVHErnx.d.cts → index-Bo4S_VVM.d.cts} +1 -1
- package/dist/{index-0O1WSfVP.d.ts → index-CKdYVt_L.d.ts} +1 -1
- package/dist/index.cjs +186 -47
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +174 -35
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/dist/{types-CMtZnV8C.d.ts → types-BZqvBhBI.d.ts} +4 -2
- package/dist/{types-D93PuOOl.d.cts → types-E4ugA4Oz.d.cts} +4 -2
- package/package.json +1 -1
- package/dist/chunk-3LWXEJU6.cjs +0 -1054
- package/dist/chunk-ADKRENAP.js +0 -1054
package/dist/browser.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var _chunkURPPSTHZcjs = require('./chunk-URPPSTHZ.cjs');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkVLL4THTGcjs = require('./chunk-VLL4THTG.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -25,4 +25,4 @@ var _chunkL6BOM5VScjs = require('./chunk-L6BOM5VS.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.computeFnv1aHash =
|
|
28
|
+
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.computeFnv1aHash = _chunkVLL4THTGcjs.computeFnv1aHash; exports.computeIntegrityHash = _chunkVLL4THTGcjs.computeIntegrityHash; exports.createDeterrentSnippet = _chunkVLL4THTGcjs.createDeterrentSnippet; exports.detectHotPaths = _chunkVLL4THTGcjs.detectHotPaths; exports.generateRuntimeShield = _chunkVLL4THTGcjs.generateRuntimeShield; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.transformJavaScript = _chunkVLL4THTGcjs.transformJavaScript; exports.verifyCodeIntegrity = _chunkVLL4THTGcjs.verifyCodeIntegrity;
|
package/dist/browser.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UnpeekConfig, S as ShieldConfig, a as ShieldPayload } from './config-
|
|
2
|
-
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, d as ShieldOptionsConfig, e as SourcemapsConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions } from './config-
|
|
3
|
-
import { H as HotPathReport } from './index-
|
|
4
|
-
export { S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-
|
|
1
|
+
import { U as UnpeekConfig, S as ShieldConfig, a as ShieldPayload } from './config-BFAZrfjQ.cjs';
|
|
2
|
+
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, d as ShieldOptionsConfig, e as SourcemapsConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions } from './config-BFAZrfjQ.cjs';
|
|
3
|
+
import { H as HotPathReport } from './index-Bo4S_VVM.cjs';
|
|
4
|
+
export { S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-Bo4S_VVM.cjs';
|
|
5
5
|
|
|
6
6
|
declare function computeFnv1aHash(input: string, seed?: number): number;
|
|
7
7
|
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UnpeekConfig, S as ShieldConfig, a as ShieldPayload } from './config-
|
|
2
|
-
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, d as ShieldOptionsConfig, e as SourcemapsConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions } from './config-
|
|
3
|
-
import { H as HotPathReport } from './index-
|
|
4
|
-
export { S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-
|
|
1
|
+
import { U as UnpeekConfig, S as ShieldConfig, a as ShieldPayload } from './config-BFAZrfjQ.js';
|
|
2
|
+
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, d as ShieldOptionsConfig, e as SourcemapsConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions } from './config-BFAZrfjQ.js';
|
|
3
|
+
import { H as HotPathReport } from './index-CKdYVt_L.js';
|
|
4
|
+
export { S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-CKdYVt_L.js';
|
|
5
5
|
|
|
6
6
|
declare function computeFnv1aHash(input: string, seed?: number): number;
|
|
7
7
|
|
package/dist/browser.js
CHANGED
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnpeekError
|
|
3
|
+
} from "./chunk-LA6J3BT3.js";
|
|
4
|
+
|
|
5
|
+
// src/core/detector.ts
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
9
|
+
var EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
10
|
+
"node_modules",
|
|
11
|
+
".unpeek-maps"
|
|
12
|
+
]);
|
|
13
|
+
var WORKER_OR_SW_BASENAME_REGEX = /^(?:sw|service-worker|workbox-[^/]+)\.(?:js|mjs|cjs)$|\.worker(?:[.-][^/]+)*\.(?:js|mjs|cjs)$/i;
|
|
14
|
+
function isWorkerOrServiceWorkerFile(filePath, rootDir) {
|
|
15
|
+
const normalized = filePath.replace(/\\/g, "/").split("?")[0];
|
|
16
|
+
const baseName = path.posix.basename(normalized);
|
|
17
|
+
if (WORKER_OR_SW_BASENAME_REGEX.test(baseName)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (rootDir) {
|
|
21
|
+
const rel = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
22
|
+
const relBase = path.posix.basename(rel);
|
|
23
|
+
if (WORKER_OR_SW_BASENAME_REGEX.test(relBase)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
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 = path.join(rootDir, filename);
|
|
37
|
+
if (fs.existsSync(filePath)) {
|
|
38
|
+
try {
|
|
39
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
40
|
+
const match = content.match(pattern);
|
|
41
|
+
if (match && match[1]) {
|
|
42
|
+
return match[1].trim();
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
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 = path.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 hasJsBundleFiles(dir) {
|
|
79
|
+
if (!fs.existsSync(dir)) return false;
|
|
80
|
+
let entries;
|
|
81
|
+
try {
|
|
82
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
if (entry.isDirectory()) {
|
|
88
|
+
if (EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (hasJsBundleFiles(path.join(dir, entry.name))) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
} else if (entry.isFile() && SUPPORTED_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
101
|
+
let config = explicitConfig;
|
|
102
|
+
let outDirOverride;
|
|
103
|
+
if (typeof explicitOutDir === "object" && explicitOutDir !== null) {
|
|
104
|
+
config = explicitOutDir;
|
|
105
|
+
outDirOverride = config.outDir;
|
|
106
|
+
} else if (typeof explicitOutDir === "string") {
|
|
107
|
+
outDirOverride = explicitOutDir;
|
|
108
|
+
}
|
|
109
|
+
const rootDir = path.resolve(cwd);
|
|
110
|
+
let framework = config?.framework;
|
|
111
|
+
const discoveredNextDist = extractConfigValue(
|
|
112
|
+
rootDir,
|
|
113
|
+
NEXT_CONFIG_FILES,
|
|
114
|
+
/(?:["']?distDir["']?\s*:\s*["']([^"']+)["'])/
|
|
115
|
+
);
|
|
116
|
+
const discoveredViteOut = extractConfigValue(
|
|
117
|
+
rootDir,
|
|
118
|
+
VITE_CONFIG_FILES,
|
|
119
|
+
/(?:["']?outDir["']?\s*:\s*["']([^"']+)["'])/
|
|
120
|
+
);
|
|
121
|
+
const discoveredViteAssets = extractConfigValue(
|
|
122
|
+
rootDir,
|
|
123
|
+
VITE_CONFIG_FILES,
|
|
124
|
+
/(?:["']?assetsDir["']?\s*:\s*["']([^"']+)["'])/
|
|
125
|
+
);
|
|
126
|
+
const nextDist = config?.next?.distDir ?? discoveredNextDist ?? ".next";
|
|
127
|
+
const viteOut = config?.vite?.outDir ?? discoveredViteOut ?? "dist";
|
|
128
|
+
const viteAssets = config?.vite?.assetsDir ?? discoveredViteAssets ?? "assets";
|
|
129
|
+
if (!framework) {
|
|
130
|
+
const pkgPath = path.join(rootDir, "package.json");
|
|
131
|
+
if (fs.existsSync(pkgPath)) {
|
|
132
|
+
try {
|
|
133
|
+
const pkgRaw = fs.readFileSync(pkgPath, "utf8");
|
|
134
|
+
const pkg = JSON.parse(pkgRaw);
|
|
135
|
+
const allDeps = {
|
|
136
|
+
...pkg.dependencies ?? {},
|
|
137
|
+
...pkg.devDependencies ?? {}
|
|
138
|
+
};
|
|
139
|
+
if ("next" in allDeps) {
|
|
140
|
+
framework = "nextjs";
|
|
141
|
+
} else if ("vite" in allDeps) {
|
|
142
|
+
framework = "vite";
|
|
143
|
+
} else if ("webpack" in allDeps || "react-scripts" in allDeps || "@rspack/core" in allDeps) {
|
|
144
|
+
framework = "webpack";
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const nextStaticDir = path.join(rootDir, nextDist, "static");
|
|
151
|
+
const nextChunksDir = path.join(nextStaticDir, "chunks");
|
|
152
|
+
const nextExportChunksDir = path.join(rootDir, "out", "_next", "static", "chunks");
|
|
153
|
+
const nextExportDir = path.join(rootDir, "out");
|
|
154
|
+
const nextDistDir = path.join(rootDir, nextDist);
|
|
155
|
+
const vercelNextStaticDir = path.join(rootDir, ".vercel", "output", "static", "_next", "static");
|
|
156
|
+
const distAssetsDir = path.join(rootDir, viteOut, viteAssets);
|
|
157
|
+
const distDir = path.join(rootDir, viteOut);
|
|
158
|
+
const buildDir = path.join(rootDir, "build");
|
|
159
|
+
const publicDir = path.join(rootDir, "public");
|
|
160
|
+
if (!framework) {
|
|
161
|
+
if (fs.existsSync(nextChunksDir) || fs.existsSync(nextDistDir) || fs.existsSync(nextExportChunksDir) || fs.existsSync(vercelNextStaticDir) || discoveredNextDist !== void 0) {
|
|
162
|
+
framework = "nextjs";
|
|
163
|
+
} else if (fs.existsSync(distAssetsDir) || discoveredViteOut !== void 0) {
|
|
164
|
+
framework = "vite";
|
|
165
|
+
} else if (fs.existsSync(buildDir)) {
|
|
166
|
+
framework = "webpack";
|
|
167
|
+
} else if (outDirOverride) {
|
|
168
|
+
const normExplicit = outDirOverride.replace(/\\/g, "/");
|
|
169
|
+
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next") || normExplicit.includes("_next/static")) {
|
|
170
|
+
framework = "nextjs";
|
|
171
|
+
} else if (normExplicit.includes(`${viteOut}/${viteAssets}`) || normExplicit.includes("dist/assets")) {
|
|
172
|
+
framework = "vite";
|
|
173
|
+
} else if (normExplicit.includes("build")) {
|
|
174
|
+
framework = "webpack";
|
|
175
|
+
} else {
|
|
176
|
+
framework = "vanilla";
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
framework = "vanilla";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (outDirOverride) {
|
|
183
|
+
return {
|
|
184
|
+
framework,
|
|
185
|
+
outDir: path.resolve(rootDir, outDirOverride)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let outDir;
|
|
189
|
+
if (framework === "nextjs") {
|
|
190
|
+
if (fs.existsSync(nextExportChunksDir)) {
|
|
191
|
+
outDir = nextExportChunksDir;
|
|
192
|
+
} else if (fs.existsSync(nextChunksDir) && hasJsBundleFiles(nextChunksDir)) {
|
|
193
|
+
outDir = nextChunksDir;
|
|
194
|
+
} else if (fs.existsSync(nextStaticDir) && hasJsBundleFiles(nextStaticDir)) {
|
|
195
|
+
outDir = nextStaticDir;
|
|
196
|
+
} else if (fs.existsSync(vercelNextStaticDir)) {
|
|
197
|
+
outDir = vercelNextStaticDir;
|
|
198
|
+
} else if (fs.existsSync(nextChunksDir)) {
|
|
199
|
+
outDir = nextChunksDir;
|
|
200
|
+
} else if (fs.existsSync(nextExportDir)) {
|
|
201
|
+
outDir = nextExportDir;
|
|
202
|
+
} else if (fs.existsSync(nextDistDir)) {
|
|
203
|
+
outDir = nextChunksDir;
|
|
204
|
+
} else {
|
|
205
|
+
outDir = nextChunksDir;
|
|
206
|
+
}
|
|
207
|
+
} else if (framework === "vite") {
|
|
208
|
+
outDir = fs.existsSync(distAssetsDir) ? distAssetsDir : distDir;
|
|
209
|
+
} else if (framework === "webpack") {
|
|
210
|
+
if (fs.existsSync(distDir)) {
|
|
211
|
+
outDir = distDir;
|
|
212
|
+
} else if (fs.existsSync(buildDir)) {
|
|
213
|
+
outDir = buildDir;
|
|
214
|
+
} else {
|
|
215
|
+
outDir = distDir;
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
const candidates = [
|
|
219
|
+
nextExportChunksDir,
|
|
220
|
+
nextChunksDir,
|
|
221
|
+
vercelNextStaticDir,
|
|
222
|
+
distAssetsDir,
|
|
223
|
+
distDir,
|
|
224
|
+
buildDir,
|
|
225
|
+
publicDir
|
|
226
|
+
];
|
|
227
|
+
const existing = candidates.find((candidate) => fs.existsSync(candidate));
|
|
228
|
+
outDir = existing ?? distDir;
|
|
229
|
+
}
|
|
230
|
+
return { framework, outDir };
|
|
231
|
+
}
|
|
232
|
+
function globBodyToRegex(pat) {
|
|
233
|
+
let out = "";
|
|
234
|
+
let i = 0;
|
|
235
|
+
while (i < pat.length) {
|
|
236
|
+
const ch = pat[i];
|
|
237
|
+
if (ch === "/" && pat.slice(i, i + 4) === "/**/") {
|
|
238
|
+
out += "(?:/.+/|/)";
|
|
239
|
+
i += 4;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (ch === "/" && pat.slice(i) === "/**") {
|
|
243
|
+
out += "/.*";
|
|
244
|
+
i = pat.length;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (ch === "*" && pat[i + 1] === "*") {
|
|
248
|
+
if ((i === 0 || pat[i - 1] === "/") && pat[i + 2] === "/") {
|
|
249
|
+
out += "(?:.*/)?";
|
|
250
|
+
i += 3;
|
|
251
|
+
} else {
|
|
252
|
+
out += ".*";
|
|
253
|
+
i += 2;
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (ch === "*") {
|
|
258
|
+
out += "[^/]*";
|
|
259
|
+
i += 1;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (ch === "?") {
|
|
263
|
+
out += "[^/]";
|
|
264
|
+
i += 1;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (ch === "{") {
|
|
268
|
+
let depth = 1;
|
|
269
|
+
let j = i + 1;
|
|
270
|
+
const alts = [];
|
|
271
|
+
let segStart = j;
|
|
272
|
+
while (j < pat.length && depth > 0) {
|
|
273
|
+
if (pat[j] === "{") depth++;
|
|
274
|
+
else if (pat[j] === "}") {
|
|
275
|
+
depth--;
|
|
276
|
+
if (depth === 0) {
|
|
277
|
+
alts.push(pat.slice(segStart, j));
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
} else if (pat[j] === "," && depth === 1) {
|
|
281
|
+
alts.push(pat.slice(segStart, j));
|
|
282
|
+
segStart = j + 1;
|
|
283
|
+
}
|
|
284
|
+
j++;
|
|
285
|
+
}
|
|
286
|
+
if (depth === 0 && alts.length > 0) {
|
|
287
|
+
out += `(?:${alts.map(globBodyToRegex).join("|")})`;
|
|
288
|
+
i = j + 1;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
293
|
+
i += 1;
|
|
294
|
+
}
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
function matchesGlobPattern(relPath, pattern) {
|
|
298
|
+
const normPattern = pattern.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "").trim();
|
|
299
|
+
if (!normPattern) return false;
|
|
300
|
+
const normPath = relPath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "");
|
|
301
|
+
const regex = new RegExp(`^${globBodyToRegex(normPattern)}$`);
|
|
302
|
+
if (regex.test(normPath)) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
if (!normPattern.includes("/")) {
|
|
306
|
+
return regex.test(path.posix.basename(normPath));
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
function scanClientBundles(outDir, config) {
|
|
311
|
+
const resolvedOutDir = path.resolve(outDir);
|
|
312
|
+
if (!fs.existsSync(resolvedOutDir)) {
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
const results = [];
|
|
316
|
+
const serverDirPrefixes = [];
|
|
317
|
+
if (config?.next?.distDir) {
|
|
318
|
+
serverDirPrefixes.push(
|
|
319
|
+
path.join(config.next.distDir, "server"),
|
|
320
|
+
path.join(config.next.distDir, "ssr")
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
if (config?.vite?.outDir) {
|
|
324
|
+
serverDirPrefixes.push(path.join(config.vite.outDir, "server"));
|
|
325
|
+
}
|
|
326
|
+
const allowedExtensions = config?.extensions && config.extensions.length > 0 ? new Set(config.extensions.map((e) => e.startsWith(".") ? e.toLowerCase() : `.${e.toLowerCase()}`)) : SUPPORTED_EXTENSIONS;
|
|
327
|
+
function walk(currentDir) {
|
|
328
|
+
if (hasNextServerSegment(currentDir, resolvedOutDir, serverDirPrefixes)) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
let entries;
|
|
332
|
+
try {
|
|
333
|
+
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
334
|
+
} catch {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
for (const entry of entries) {
|
|
338
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
339
|
+
if (entry.isDirectory()) {
|
|
340
|
+
if (EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
walk(fullPath);
|
|
347
|
+
} else if (entry.isFile()) {
|
|
348
|
+
if (hasNextServerSegment(fullPath, resolvedOutDir, serverDirPrefixes)) {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
352
|
+
if (allowedExtensions.has(ext)) {
|
|
353
|
+
if (config?.target !== "worker" && isWorkerOrServiceWorkerFile(fullPath, resolvedOutDir)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const relPath = path.relative(resolvedOutDir, fullPath).replace(/\\/g, "/");
|
|
357
|
+
if (config?.filter?.include && config.filter.include.length > 0) {
|
|
358
|
+
if (!config.filter.include.some((pattern) => matchesGlobPattern(relPath, pattern))) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (config?.filter?.exclude && config.filter.exclude.length > 0) {
|
|
363
|
+
if (config.filter.exclude.some((pattern) => matchesGlobPattern(relPath, pattern))) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
results.push(fullPath);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
walk(resolvedOutDir);
|
|
373
|
+
return results.sort();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/core/sourcemap-vault.ts
|
|
377
|
+
import fs2 from "fs";
|
|
378
|
+
import path2 from "path";
|
|
379
|
+
var SOURCE_MAP_COMMENT_REGEX = /[ \t]*(?:\/\/[#@]\s*sourceMappingURL=[^\r\n]*|\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/)[ \t]*(?:\r?\n)?/g;
|
|
380
|
+
var DEBUG_ID_COMMENT_REGEX = /(?:\/\/[#@]\s*debugId=([^\s*]+)|\/\*[#@]\s*debugId=([^\s*]+)\s*\*\/)/;
|
|
381
|
+
var DEBUG_ID_LINE_REGEX = /[ \t]*(?:\/\/[#@]\s*debugId=[^\r\n]*|\/\*[#@]\s*debugId=[\s\S]*?\*\/)[ \t]*(?:\r?\n)?/g;
|
|
382
|
+
function extractDebugId(code) {
|
|
383
|
+
const match = code.match(DEBUG_ID_COMMENT_REGEX);
|
|
384
|
+
const id = match?.[1] ?? match?.[2];
|
|
385
|
+
return id ? id.trim() : void 0;
|
|
386
|
+
}
|
|
387
|
+
function stripDebugIdComments(code) {
|
|
388
|
+
DEBUG_ID_LINE_REGEX.lastIndex = 0;
|
|
389
|
+
return code.replace(DEBUG_ID_LINE_REGEX, "");
|
|
390
|
+
}
|
|
391
|
+
function replaceOrAppendDebugId(code, debugId) {
|
|
392
|
+
const cleaned = stripDebugIdComments(code);
|
|
393
|
+
const suffix = cleaned.length > 0 && !cleaned.endsWith("\n") ? "\n" : "";
|
|
394
|
+
return `${cleaned}${suffix}//# debugId=${debugId}
|
|
395
|
+
`;
|
|
396
|
+
}
|
|
397
|
+
function stripSourceMapComments(code) {
|
|
398
|
+
const debugId = extractDebugId(code);
|
|
399
|
+
SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
|
|
400
|
+
let next = code.replace(SOURCE_MAP_COMMENT_REGEX, "");
|
|
401
|
+
const stripped = next !== code;
|
|
402
|
+
if (debugId && !DEBUG_ID_COMMENT_REGEX.test(next)) {
|
|
403
|
+
const suffix = next.length > 0 && !next.endsWith("\n") ? "\n" : "";
|
|
404
|
+
next = `${next}${suffix}//# debugId=${debugId}
|
|
405
|
+
`;
|
|
406
|
+
}
|
|
407
|
+
return { code: next, stripped, debugId };
|
|
408
|
+
}
|
|
409
|
+
function ensureIgnoreEntry(dir, fileName, entryName) {
|
|
410
|
+
const filePath = path2.join(path2.resolve(dir), fileName);
|
|
411
|
+
if (!fs2.existsSync(filePath)) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const content = fs2.readFileSync(filePath, "utf8");
|
|
415
|
+
const normalizedEntry = entryName.endsWith("/") ? entryName : `${entryName}/`;
|
|
416
|
+
const bareEntry = normalizedEntry.slice(0, -1);
|
|
417
|
+
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
418
|
+
if (!lines.includes(normalizedEntry) && !lines.includes(bareEntry) && !lines.includes(".unpeek-maps") && !lines.includes(".unpeek-maps/")) {
|
|
419
|
+
const prefix = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
420
|
+
fs2.writeFileSync(filePath, `${content}${prefix}${normalizedEntry}
|
|
421
|
+
`, "utf8");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function isSubdirectoryOrSame(parent, child) {
|
|
425
|
+
const rel = path2.relative(parent, child);
|
|
426
|
+
return rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel);
|
|
427
|
+
}
|
|
428
|
+
function findMonorepoRoots(cwd) {
|
|
429
|
+
const resolved = path2.resolve(cwd);
|
|
430
|
+
const dirs = [resolved];
|
|
431
|
+
let curr = resolved;
|
|
432
|
+
while (true) {
|
|
433
|
+
const parent = path2.dirname(curr);
|
|
434
|
+
if (!parent || parent === curr) {
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
const hasGit = fs2.existsSync(path2.join(parent, ".git"));
|
|
438
|
+
const hasWorkspace = fs2.existsSync(path2.join(parent, "pnpm-workspace.yaml"));
|
|
439
|
+
const hasGitIgnore = fs2.existsSync(path2.join(parent, ".gitignore"));
|
|
440
|
+
const hasDockerIgnore = fs2.existsSync(path2.join(parent, ".dockerignore"));
|
|
441
|
+
const hasPkgJson = fs2.existsSync(path2.join(parent, "package.json"));
|
|
442
|
+
if (hasGit || hasWorkspace || hasGitIgnore || hasDockerIgnore || hasPkgJson) {
|
|
443
|
+
dirs.push(parent);
|
|
444
|
+
}
|
|
445
|
+
if (hasGit || hasWorkspace) {
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
curr = parent;
|
|
449
|
+
}
|
|
450
|
+
return dirs;
|
|
451
|
+
}
|
|
452
|
+
function checkDockerIgnoreMissing(cwd, ignoreEntry) {
|
|
453
|
+
const candidateDirs = findMonorepoRoots(cwd);
|
|
454
|
+
let foundAnyDockerIgnore = false;
|
|
455
|
+
for (const dir of candidateDirs) {
|
|
456
|
+
const filePath = path2.join(dir, ".dockerignore");
|
|
457
|
+
if (fs2.existsSync(filePath)) {
|
|
458
|
+
foundAnyDockerIgnore = true;
|
|
459
|
+
const content = fs2.readFileSync(filePath, "utf8");
|
|
460
|
+
const normalizedEntry = ignoreEntry.endsWith("/") ? ignoreEntry : `${ignoreEntry}/`;
|
|
461
|
+
const bareEntry = normalizedEntry.slice(0, -1);
|
|
462
|
+
const lines = content.split(/\r?\n/).map((line) => line.trim());
|
|
463
|
+
if (lines.includes(normalizedEntry) || lines.includes(bareEntry) || lines.includes(".unpeek-maps") || lines.includes(".unpeek-maps/")) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
function updateAllIgnoreFiles(cwd, vaultDir) {
|
|
471
|
+
const candidateDirs = findMonorepoRoots(cwd);
|
|
472
|
+
for (const dir of candidateDirs) {
|
|
473
|
+
const relFromDir = path2.relative(dir, vaultDir).replace(/\\/g, "/");
|
|
474
|
+
const entry = relFromDir && !relFromDir.startsWith("..") ? `${relFromDir}/` : ".unpeek-maps/";
|
|
475
|
+
ensureIgnoreEntry(dir, ".gitignore", entry);
|
|
476
|
+
ensureIgnoreEntry(dir, ".dockerignore", entry);
|
|
477
|
+
ensureIgnoreEntry(dir, ".npmignore", entry);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir = ".unpeek-maps", stripComments = true, config, options) {
|
|
481
|
+
const resolvedOutDir = path2.resolve(outDir);
|
|
482
|
+
const resolvedCwd = path2.resolve(cwd);
|
|
483
|
+
const effectiveVaultDirName = config?.sourcemaps?.vaultDir ?? privateMapsDir ?? ".unpeek-maps";
|
|
484
|
+
const effectiveKeepPrivate = config?.sourcemaps?.keepPrivate ?? keepPrivateMaps;
|
|
485
|
+
const effectiveStripComments = config?.sourcemaps?.stripComments ?? stripComments;
|
|
486
|
+
const updateIgnoreFiles = typeof options === "boolean" ? options : options?.updateIgnoreFiles ?? true;
|
|
487
|
+
const dryRun = typeof options === "object" && options !== null ? options.dryRun ?? false : false;
|
|
488
|
+
const vaultDir = path2.resolve(resolvedCwd, effectiveVaultDirName);
|
|
489
|
+
const publicDirsToCheck = /* @__PURE__ */ new Set();
|
|
490
|
+
if (config?.publicDirs && config.publicDirs.length > 0) {
|
|
491
|
+
for (const d of config.publicDirs) {
|
|
492
|
+
publicDirsToCheck.add(d);
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
publicDirsToCheck.add("public");
|
|
496
|
+
publicDirsToCheck.add("static");
|
|
497
|
+
publicDirsToCheck.add("assets");
|
|
498
|
+
}
|
|
499
|
+
if (effectiveKeepPrivate !== false) {
|
|
500
|
+
if (!isSubdirectoryOrSame(resolvedCwd, vaultDir)) {
|
|
501
|
+
throw new UnpeekError(
|
|
502
|
+
"ERR_SECURITY_PATH_TRAVERSAL",
|
|
503
|
+
`[unpeek] Security Error: privateMapsDir (${vaultDir}) cannot traverse outside cwd (${resolvedCwd}).`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
if (isSubdirectoryOrSame(resolvedOutDir, vaultDir)) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`[unpeek] Security Error: privateMapsDir cannot be located inside outDir (${resolvedOutDir}). This would expose private source maps to the web server.`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
for (const pubDir of publicDirsToCheck) {
|
|
512
|
+
const resolvedPublicDir = path2.resolve(resolvedCwd, pubDir);
|
|
513
|
+
if (isSubdirectoryOrSame(resolvedPublicDir, vaultDir)) {
|
|
514
|
+
throw new Error(
|
|
515
|
+
`[unpeek] Security Error: privateMapsDir cannot be located inside publicDir (${resolvedPublicDir}). This would expose private source maps to the web server.`
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const relVault = path2.relative(resolvedCwd, vaultDir).replace(/\\/g, "/");
|
|
521
|
+
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
522
|
+
const dockerIgnoreMissing = checkDockerIgnoreMissing(resolvedCwd, ignoreEntry);
|
|
523
|
+
const movedFiles = [];
|
|
524
|
+
let movedMapsCount = 0;
|
|
525
|
+
let strippedFilesCount = 0;
|
|
526
|
+
if (!fs2.existsSync(resolvedOutDir)) {
|
|
527
|
+
return {
|
|
528
|
+
movedMapsCount: 0,
|
|
529
|
+
strippedFilesCount: 0,
|
|
530
|
+
vaultDir,
|
|
531
|
+
movedFiles: [],
|
|
532
|
+
dockerIgnoreMissing
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
function walkForMaps(currentDir) {
|
|
536
|
+
if (hasNextServerSegment(currentDir, resolvedOutDir)) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
let entries;
|
|
540
|
+
try {
|
|
541
|
+
entries = fs2.readdirSync(currentDir, { withFileTypes: true });
|
|
542
|
+
} catch {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
for (const entry of entries) {
|
|
546
|
+
const fullPath = path2.join(currentDir, entry.name);
|
|
547
|
+
if (entry.isDirectory()) {
|
|
548
|
+
if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (hasNextServerSegment(fullPath, resolvedOutDir)) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
walkForMaps(fullPath);
|
|
555
|
+
} else if (entry.isFile() && entry.name.endsWith(".map")) {
|
|
556
|
+
if (effectiveKeepPrivate !== false) {
|
|
557
|
+
const relPath = path2.relative(resolvedOutDir, fullPath);
|
|
558
|
+
const targetPath = path2.join(vaultDir, relPath);
|
|
559
|
+
if (!dryRun) {
|
|
560
|
+
fs2.mkdirSync(path2.dirname(targetPath), { recursive: true });
|
|
561
|
+
fs2.copyFileSync(fullPath, targetPath);
|
|
562
|
+
fs2.unlinkSync(fullPath);
|
|
563
|
+
}
|
|
564
|
+
movedFiles.push(targetPath);
|
|
565
|
+
} else if (!dryRun) {
|
|
566
|
+
fs2.unlinkSync(fullPath);
|
|
567
|
+
}
|
|
568
|
+
movedMapsCount++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
walkForMaps(resolvedOutDir);
|
|
573
|
+
if (!dryRun && updateIgnoreFiles && effectiveKeepPrivate !== false && movedMapsCount > 0) {
|
|
574
|
+
updateAllIgnoreFiles(resolvedCwd, vaultDir);
|
|
575
|
+
}
|
|
576
|
+
if (effectiveStripComments) {
|
|
577
|
+
const clientFiles = scanClientBundles(resolvedOutDir, config);
|
|
578
|
+
for (const filePath of clientFiles) {
|
|
579
|
+
const original = fs2.readFileSync(filePath, "utf8");
|
|
580
|
+
if (original.includes("sourceMappingURL=")) {
|
|
581
|
+
const { code: strippedCode, stripped } = stripSourceMapComments(original);
|
|
582
|
+
if (stripped) {
|
|
583
|
+
if (!dryRun) {
|
|
584
|
+
fs2.writeFileSync(filePath, strippedCode, "utf8");
|
|
585
|
+
}
|
|
586
|
+
strippedFilesCount++;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
movedMapsCount,
|
|
593
|
+
strippedFilesCount,
|
|
594
|
+
vaultDir,
|
|
595
|
+
movedFiles,
|
|
596
|
+
dockerIgnoreMissing
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export {
|
|
601
|
+
isWorkerOrServiceWorkerFile,
|
|
602
|
+
hasNextServerSegment,
|
|
603
|
+
hasJsBundleFiles,
|
|
604
|
+
detectTargetFramework,
|
|
605
|
+
matchesGlobPattern,
|
|
606
|
+
scanClientBundles,
|
|
607
|
+
SOURCE_MAP_COMMENT_REGEX,
|
|
608
|
+
extractDebugId,
|
|
609
|
+
stripDebugIdComments,
|
|
610
|
+
replaceOrAppendDebugId,
|
|
611
|
+
stripSourceMapComments,
|
|
612
|
+
findMonorepoRoots,
|
|
613
|
+
relocateSourceMaps
|
|
614
|
+
};
|