unpeek 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/README.tr.md +6 -5
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +5 -5
- package/dist/adapters/next/adapter.js +4 -4
- package/dist/adapters/next/index.cjs +5 -5
- package/dist/adapters/next/index.js +4 -4
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.js +3 -3
- package/dist/browser.cjs +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-3LWXEJU6.cjs → chunk-3GDHYBVH.cjs} +56 -18
- package/dist/{chunk-YCRMTXOE.js → chunk-4G2HCME5.js} +2 -2
- package/dist/{chunk-2JU3V7HW.js → chunk-4SOS3LRV.js} +50 -9
- package/dist/{chunk-7HXLHLLQ.cjs → chunk-7ZEVJ4OR.cjs} +121 -29
- package/dist/{chunk-4FNZNIBW.js → chunk-LGTXAAZH.js} +686 -344
- package/dist/{chunk-KLYFNMKS.cjs → chunk-M46SFJE7.cjs} +813 -471
- package/dist/{chunk-ZG7BIAUI.cjs → chunk-NNAAPDUS.cjs} +58 -17
- package/dist/{chunk-VG4Y26ZN.cjs → chunk-OTA75YI6.cjs} +14 -14
- package/dist/{chunk-ADKRENAP.js → chunk-TYL32LUK.js} +46 -8
- package/dist/{chunk-HHC7BUCK.js → chunk-XYN5NYSD.js} +95 -3
- package/dist/cli/index.js +921 -372
- package/dist/index.cjs +184 -45
- package/dist/index.js +170 -31
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk7ZEVJ4ORcjs = require('./chunk-7ZEVJ4OR.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var _chunk3LWXEJU6cjs = require('./chunk-3LWXEJU6.cjs');
|
|
8
7
|
|
|
8
|
+
var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -40,6 +41,26 @@ function recomputeHash(content, existingHash) {
|
|
|
40
41
|
function isNonProductionPhase(phase) {
|
|
41
42
|
return phase !== void 0 && phase !== "phase-production-build" && phase !== "phase-export";
|
|
42
43
|
}
|
|
44
|
+
function buildUnpeekOutputHashSalt(options) {
|
|
45
|
+
const profileTag = _nullishCoalesce(_nullishCoalesce(options.profile, () => ( _optionalChain([options, 'access', _2 => _2.config, 'optionalAccess', _3 => _3.profile]))), () => ( "recommended"));
|
|
46
|
+
const isAggressive = _nullishCoalesce(options.aggressive, () => ( profileTag === "strict"));
|
|
47
|
+
const envId = process.env.VERCEL_DEPLOYMENT_ID || process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA || "";
|
|
48
|
+
const parts = [
|
|
49
|
+
profileTag,
|
|
50
|
+
...isAggressive ? ["aggressive"] : [],
|
|
51
|
+
...envId ? [envId] : [],
|
|
52
|
+
...typeof options.seed === "number" ? [String(options.seed)] : []
|
|
53
|
+
];
|
|
54
|
+
return `unpeek:${parts.join(":")}`;
|
|
55
|
+
}
|
|
56
|
+
function isSameAdapterPath(candidate, selfPath) {
|
|
57
|
+
if (!candidate) return false;
|
|
58
|
+
try {
|
|
59
|
+
return _path2.default.resolve(candidate) === _path2.default.resolve(selfPath);
|
|
60
|
+
} catch (e2) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
43
64
|
async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
|
|
44
65
|
if (!upstreamPath) return;
|
|
45
66
|
try {
|
|
@@ -54,7 +75,9 @@ async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
|
|
|
54
75
|
}
|
|
55
76
|
}
|
|
56
77
|
function createUnpeekNextAdapter(options = {}) {
|
|
57
|
-
const
|
|
78
|
+
const rawUpstreamPath = options.upstreamAdapterPath || process.env.UNPEEK_UPSTREAM_ADAPTER_PATH || process.env.NEXT_ADAPTER_PATH;
|
|
79
|
+
const selfAdapterPath = getUnpeekAdapterPath();
|
|
80
|
+
const upstreamPath = isSameAdapterPath(rawUpstreamPath, selfAdapterPath) ? void 0 : rawUpstreamPath;
|
|
58
81
|
let recordedPhase;
|
|
59
82
|
return {
|
|
60
83
|
name: "unpeek",
|
|
@@ -72,13 +95,26 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
72
95
|
console.warn("[unpeek:next] Failed to invoke upstream modifyConfig:", err);
|
|
73
96
|
}
|
|
74
97
|
}
|
|
98
|
+
const phase = context && typeof context.phase === "string" ? context.phase : recordedPhase;
|
|
99
|
+
if (!isNonProductionPhase(phase)) {
|
|
100
|
+
const existingSalt = typeof config.outputHashSalt === "string" ? config.outputHashSalt.trim() : "";
|
|
101
|
+
if (!existingSalt.includes("unpeek:")) {
|
|
102
|
+
const unpeekSalt = buildUnpeekOutputHashSalt(options);
|
|
103
|
+
config = {
|
|
104
|
+
...config,
|
|
105
|
+
outputHashSalt: existingSalt ? `${existingSalt}-${unpeekSalt}` : unpeekSalt
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
75
109
|
return config;
|
|
76
110
|
},
|
|
77
111
|
async onBuildComplete(context) {
|
|
78
112
|
const cwd = _nullishCoalesce(options.cwd, () => ( process.cwd()));
|
|
79
|
-
const
|
|
113
|
+
const configuredDistDir = context.distDir || (typeof _optionalChain([context, 'access', _4 => _4.config, 'optionalAccess', _5 => _5.distDir]) === "string" ? context.config.distDir : void 0) || ".next";
|
|
114
|
+
const distDir = _path2.default.resolve(cwd, configuredDistDir);
|
|
80
115
|
const staticDir = _path2.default.join(distDir, "static");
|
|
81
|
-
const
|
|
116
|
+
const vercelStaticDir = _path2.default.join(cwd, ".vercel", "output", "static", "_next", "static");
|
|
117
|
+
const targetDir = _fs2.default.existsSync(staticDir) && (_chunk3GDHYBVHcjs.hasJsBundleFiles.call(void 0, staticDir) || !_fs2.default.existsSync(vercelStaticDir)) ? staticDir : _fs2.default.existsSync(vercelStaticDir) ? vercelStaticDir : _fs2.default.existsSync(staticDir) ? staticDir : distDir;
|
|
82
118
|
const phase = _nullishCoalesce(context.phase, () => ( recordedPhase));
|
|
83
119
|
if (isNonProductionPhase(phase)) {
|
|
84
120
|
await delegateToUpstreamOnBuildComplete(upstreamPath, context);
|
|
@@ -99,14 +135,14 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
99
135
|
elapsedMs: 0
|
|
100
136
|
};
|
|
101
137
|
}
|
|
102
|
-
const deterministicSeed = typeof options.seed === "number" ? options.seed : context.buildId ?
|
|
103
|
-
const summary = await
|
|
138
|
+
const deterministicSeed = typeof options.seed === "number" ? options.seed : context.buildId ? _chunkM46SFJE7cjs.computeFnv1aHash.call(void 0, context.buildId, 1597463007) : 1597463007;
|
|
139
|
+
const summary = await _chunk7ZEVJ4ORcjs.protectProject.call(void 0, {
|
|
104
140
|
...options,
|
|
105
141
|
cwd,
|
|
106
142
|
outDir: targetDir,
|
|
107
143
|
seed: deterministicSeed
|
|
108
144
|
});
|
|
109
|
-
if (_optionalChain([context, 'access',
|
|
145
|
+
if (_optionalChain([context, 'access', _6 => _6.outputs, 'optionalAccess', _7 => _7.staticFiles])) {
|
|
110
146
|
const rawStatic = context.outputs.staticFiles;
|
|
111
147
|
const fileList = Array.isArray(rawStatic) ? rawStatic : rawStatic instanceof Map ? Array.from(rawStatic.values()) : typeof rawStatic === "object" ? Object.values(rawStatic) : [];
|
|
112
148
|
for (const item of fileList) {
|
|
@@ -115,7 +151,7 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
115
151
|
if (!rawFilePath) continue;
|
|
116
152
|
let absPath = _path2.default.isAbsolute(rawFilePath) ? rawFilePath : _path2.default.resolve(cwd, rawFilePath);
|
|
117
153
|
if (!_fs2.default.existsSync(absPath)) {
|
|
118
|
-
const relClean =
|
|
154
|
+
const relClean = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, rawFilePath).replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
|
|
119
155
|
const fromDist = _path2.default.resolve(distDir, relClean);
|
|
120
156
|
if (_fs2.default.existsSync(fromDist)) {
|
|
121
157
|
absPath = fromDist;
|
|
@@ -124,6 +160,11 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
124
160
|
const fromStatic = _path2.default.resolve(distDir, "static", staticClean);
|
|
125
161
|
if (_fs2.default.existsSync(fromStatic)) {
|
|
126
162
|
absPath = fromStatic;
|
|
163
|
+
} else {
|
|
164
|
+
const fromVercelStatic = _path2.default.resolve(vercelStaticDir, staticClean);
|
|
165
|
+
if (_fs2.default.existsSync(fromVercelStatic)) {
|
|
166
|
+
absPath = fromVercelStatic;
|
|
167
|
+
}
|
|
127
168
|
}
|
|
128
169
|
}
|
|
129
170
|
}
|
|
@@ -138,7 +179,7 @@ function createUnpeekNextAdapter(options = {}) {
|
|
|
138
179
|
if (typeof item.size === "number") {
|
|
139
180
|
item.size = buf.byteLength;
|
|
140
181
|
}
|
|
141
|
-
} catch (
|
|
182
|
+
} catch (e3) {
|
|
142
183
|
}
|
|
143
184
|
}
|
|
144
185
|
}
|
|
@@ -157,7 +198,7 @@ function getUnpeekAdapterPath() {
|
|
|
157
198
|
if (_fs2.default.existsSync(resolved)) {
|
|
158
199
|
return resolved;
|
|
159
200
|
}
|
|
160
|
-
} catch (
|
|
201
|
+
} catch (e4) {
|
|
161
202
|
}
|
|
162
203
|
const isCjs = typeof __dirname !== "undefined";
|
|
163
204
|
const currentDir = isCjs ? __dirname : _path2.default.dirname(_url.fileURLToPath.call(void 0, _chunkL6BOM5VScjs.importMetaUrl));
|
|
@@ -177,20 +218,21 @@ function getUnpeekAdapterPath() {
|
|
|
177
218
|
}
|
|
178
219
|
}
|
|
179
220
|
return candidates[0];
|
|
180
|
-
} catch (
|
|
221
|
+
} catch (e5) {
|
|
181
222
|
return _path2.default.resolve(process.cwd(), "node_modules/unpeek/dist/adapters/next/adapter.js");
|
|
182
223
|
}
|
|
183
224
|
}
|
|
184
225
|
function applyWithUnpeek(config = {}, options) {
|
|
226
|
+
const adapterPath = getUnpeekAdapterPath();
|
|
185
227
|
const existingAdapter = config.adapterPath || process.env.NEXT_ADAPTER_PATH;
|
|
186
|
-
if (existingAdapter && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
|
|
228
|
+
if (existingAdapter && !isSameAdapterPath(existingAdapter, adapterPath) && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
|
|
187
229
|
process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = existingAdapter;
|
|
188
230
|
}
|
|
189
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
231
|
+
if (_optionalChain([options, 'optionalAccess', _8 => _8.upstreamAdapterPath]) && !isSameAdapterPath(options.upstreamAdapterPath, adapterPath)) {
|
|
190
232
|
process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = options.upstreamAdapterPath;
|
|
191
233
|
}
|
|
192
234
|
if (options) {
|
|
193
|
-
const serialized =
|
|
235
|
+
const serialized = _chunk7ZEVJ4ORcjs.serializeNextOptions.call(void 0, options);
|
|
194
236
|
const byteLength = Buffer.byteLength(serialized, "utf8");
|
|
195
237
|
if (byteLength > MAX_NEXT_OPTIONS_ENV_BYTES) {
|
|
196
238
|
throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
|
|
@@ -202,7 +244,6 @@ function applyWithUnpeek(config = {}, options) {
|
|
|
202
244
|
} else {
|
|
203
245
|
delete process.env.UNPEEK_NEXT_OPTIONS;
|
|
204
246
|
}
|
|
205
|
-
const adapterPath = getUnpeekAdapterPath();
|
|
206
247
|
return {
|
|
207
248
|
...config,
|
|
208
249
|
adapterPath
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
|
|
17
17
|
|
|
18
18
|
// src/plugins/unplugin.ts
|
|
19
19
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
@@ -58,8 +58,8 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
58
58
|
const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( true));
|
|
59
59
|
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'optionalAccess', _6 => _6.vault, 'optionalAccess', _7 => _7.minStringLength]))), () => ( 4));
|
|
60
60
|
const aggressive = _nullishCoalesce(options.aggressive, () => ( false));
|
|
61
|
-
const masterSym =
|
|
62
|
-
const masterShield = injectRuntimeShield ?
|
|
61
|
+
const masterSym = _chunkM46SFJE7cjs.deriveWindowKeySymbol.call(void 0, baseSeed);
|
|
62
|
+
const masterShield = injectRuntimeShield ? _chunkM46SFJE7cjs.generateRuntimeShield.call(void 0, {
|
|
63
63
|
seed: baseSeed,
|
|
64
64
|
deterrentMode,
|
|
65
65
|
detectHeadless,
|
|
@@ -70,14 +70,14 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
70
70
|
if (!isSupportedJsAsset(normalizedFileName) || isExcludedClientAsset(normalizedFileName, config)) {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
const fileDebugId =
|
|
73
|
+
const fileDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, rawCode);
|
|
74
74
|
const shouldStripComments = _optionalChain([config, 'optionalAccess', _8 => _8.sourcemaps, 'optionalAccess', _9 => _9.stripComments]) !== false;
|
|
75
75
|
let codeToTransform = rawCode;
|
|
76
76
|
if (shouldStripComments && rawCode.includes("sourceMappingURL=")) {
|
|
77
|
-
codeToTransform =
|
|
77
|
+
codeToTransform = _chunk3GDHYBVHcjs.stripSourceMapComments.call(void 0, rawCode).code;
|
|
78
78
|
}
|
|
79
79
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
80
|
-
const chunkSeed =
|
|
80
|
+
const chunkSeed = _chunkM46SFJE7cjs.computeFnv1aHash.call(void 0, fileName, baseSeed);
|
|
81
81
|
const transformOptions = {
|
|
82
82
|
seed: chunkSeed,
|
|
83
83
|
minStringLength,
|
|
@@ -94,7 +94,7 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
94
94
|
};
|
|
95
95
|
transformOptions.generateMap = requestMap || Boolean(inputMap);
|
|
96
96
|
transformOptions.rootDir = process.cwd();
|
|
97
|
-
const result =
|
|
97
|
+
const result = _chunkM46SFJE7cjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
|
|
98
98
|
let finalCode = result.code;
|
|
99
99
|
let preambleLineOffset = 0;
|
|
100
100
|
const integrityCheckFnName = masterShield && "integrityCheckFnName" in masterShield ? masterShield.integrityCheckFnName : void 0;
|
|
@@ -105,24 +105,24 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
|
105
105
|
finalCode = `${prefix}${finalCode}`;
|
|
106
106
|
}
|
|
107
107
|
const rawTransformMap = result.sourceMap;
|
|
108
|
-
const shiftedTransformMap = rawTransformMap ?
|
|
108
|
+
const shiftedTransformMap = rawTransformMap ? _chunk3GDHYBVHcjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
|
|
109
109
|
let composedMap = null;
|
|
110
110
|
if (shiftedTransformMap && inputMap) {
|
|
111
|
-
composedMap =
|
|
111
|
+
composedMap = _chunk3GDHYBVHcjs.chainSourceMaps.call(void 0, shiftedTransformMap, inputMap);
|
|
112
112
|
} else if (shiftedTransformMap) {
|
|
113
113
|
composedMap = shiftedTransformMap;
|
|
114
114
|
} else if (inputMap) {
|
|
115
|
-
composedMap =
|
|
115
|
+
composedMap = _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, inputMap);
|
|
116
116
|
}
|
|
117
117
|
const inputMapDebugId = _nullishCoalesce(_optionalChain([inputMap, 'optionalAccess', _12 => _12.debugId]), () => ( _optionalChain([inputMap, 'optionalAccess', _13 => _13.debug_id])));
|
|
118
118
|
const hadDebugId = Boolean(fileDebugId || inputMapDebugId || result.debugId);
|
|
119
119
|
if (hadDebugId) {
|
|
120
|
-
const codeWithoutDebugId =
|
|
121
|
-
const mintedDebugId =
|
|
120
|
+
const codeWithoutDebugId = _chunk3GDHYBVHcjs.stripDebugIdComments.call(void 0, finalCode);
|
|
121
|
+
const mintedDebugId = _chunk3GDHYBVHcjs.computeDeterministicDebugId.call(void 0,
|
|
122
122
|
codeWithoutDebugId,
|
|
123
123
|
_nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _14 => _14.mappings]), () => ( ""))
|
|
124
124
|
);
|
|
125
|
-
finalCode =
|
|
125
|
+
finalCode = _chunk3GDHYBVHcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
|
|
126
126
|
if (composedMap) {
|
|
127
127
|
composedMap.debugId = mintedDebugId;
|
|
128
128
|
delete composedMap.debug_id;
|
|
@@ -2,10 +2,6 @@ import {
|
|
|
2
2
|
UnpeekError
|
|
3
3
|
} from "./chunk-LA6J3BT3.js";
|
|
4
4
|
|
|
5
|
-
// src/core/sourcemap-vault.ts
|
|
6
|
-
import fs2 from "fs";
|
|
7
|
-
import path2 from "path";
|
|
8
|
-
|
|
9
5
|
// src/core/detector.ts
|
|
10
6
|
import fs from "fs";
|
|
11
7
|
import path from "path";
|
|
@@ -79,6 +75,28 @@ function hasNextServerSegment(fullPath, rootDir, serverDirPrefixes) {
|
|
|
79
75
|
}
|
|
80
76
|
return false;
|
|
81
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
|
+
}
|
|
82
100
|
function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
83
101
|
let config = explicitConfig;
|
|
84
102
|
let outDirOverride;
|
|
@@ -129,16 +147,18 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
}
|
|
132
|
-
const
|
|
150
|
+
const nextStaticDir = path.join(rootDir, nextDist, "static");
|
|
151
|
+
const nextChunksDir = path.join(nextStaticDir, "chunks");
|
|
133
152
|
const nextExportChunksDir = path.join(rootDir, "out", "_next", "static", "chunks");
|
|
134
153
|
const nextExportDir = path.join(rootDir, "out");
|
|
135
154
|
const nextDistDir = path.join(rootDir, nextDist);
|
|
155
|
+
const vercelNextStaticDir = path.join(rootDir, ".vercel", "output", "static", "_next", "static");
|
|
136
156
|
const distAssetsDir = path.join(rootDir, viteOut, viteAssets);
|
|
137
157
|
const distDir = path.join(rootDir, viteOut);
|
|
138
158
|
const buildDir = path.join(rootDir, "build");
|
|
139
159
|
const publicDir = path.join(rootDir, "public");
|
|
140
160
|
if (!framework) {
|
|
141
|
-
if (fs.existsSync(nextChunksDir) || fs.existsSync(nextDistDir) || fs.existsSync(nextExportChunksDir) || discoveredNextDist !== void 0) {
|
|
161
|
+
if (fs.existsSync(nextChunksDir) || fs.existsSync(nextDistDir) || fs.existsSync(nextExportChunksDir) || fs.existsSync(vercelNextStaticDir) || discoveredNextDist !== void 0) {
|
|
142
162
|
framework = "nextjs";
|
|
143
163
|
} else if (fs.existsSync(distAssetsDir) || discoveredViteOut !== void 0) {
|
|
144
164
|
framework = "vite";
|
|
@@ -146,7 +166,7 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
146
166
|
framework = "webpack";
|
|
147
167
|
} else if (outDirOverride) {
|
|
148
168
|
const normExplicit = outDirOverride.replace(/\\/g, "/");
|
|
149
|
-
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next")) {
|
|
169
|
+
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next") || normExplicit.includes("_next/static")) {
|
|
150
170
|
framework = "nextjs";
|
|
151
171
|
} else if (normExplicit.includes(`${viteOut}/${viteAssets}`) || normExplicit.includes("dist/assets")) {
|
|
152
172
|
framework = "vite";
|
|
@@ -169,6 +189,12 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
169
189
|
if (framework === "nextjs") {
|
|
170
190
|
if (fs.existsSync(nextExportChunksDir)) {
|
|
171
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;
|
|
172
198
|
} else if (fs.existsSync(nextChunksDir)) {
|
|
173
199
|
outDir = nextChunksDir;
|
|
174
200
|
} else if (fs.existsSync(nextExportDir)) {
|
|
@@ -189,7 +215,15 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
189
215
|
outDir = distDir;
|
|
190
216
|
}
|
|
191
217
|
} else {
|
|
192
|
-
const candidates = [
|
|
218
|
+
const candidates = [
|
|
219
|
+
nextExportChunksDir,
|
|
220
|
+
nextChunksDir,
|
|
221
|
+
vercelNextStaticDir,
|
|
222
|
+
distAssetsDir,
|
|
223
|
+
distDir,
|
|
224
|
+
buildDir,
|
|
225
|
+
publicDir
|
|
226
|
+
];
|
|
193
227
|
const existing = candidates.find((candidate) => fs.existsSync(candidate));
|
|
194
228
|
outDir = existing ?? distDir;
|
|
195
229
|
}
|
|
@@ -251,6 +285,8 @@ function scanClientBundles(outDir, config) {
|
|
|
251
285
|
}
|
|
252
286
|
|
|
253
287
|
// src/core/sourcemap-vault.ts
|
|
288
|
+
import fs2 from "fs";
|
|
289
|
+
import path2 from "path";
|
|
254
290
|
var SOURCE_MAP_COMMENT_REGEX = /[ \t]*(?:\/\/[#@]\s*sourceMappingURL=[^\r\n]*|\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/)[ \t]*(?:\r?\n)?/g;
|
|
255
291
|
var DEBUG_ID_COMMENT_REGEX = /(?:\/\/[#@]\s*debugId=([^\s*]+)|\/\*[#@]\s*debugId=([^\s*]+)\s*\*\/)/;
|
|
256
292
|
var DEBUG_ID_LINE_REGEX = /[ \t]*(?:\/\/[#@]\s*debugId=[^\r\n]*|\/\*[#@]\s*debugId=[\s\S]*?\*\/)[ \t]*(?:\r?\n)?/g;
|
|
@@ -1036,6 +1072,7 @@ async function symbolicateStackTrace(options) {
|
|
|
1036
1072
|
export {
|
|
1037
1073
|
isWorkerOrServiceWorkerFile,
|
|
1038
1074
|
hasNextServerSegment,
|
|
1075
|
+
hasJsBundleFiles,
|
|
1039
1076
|
detectTargetFramework,
|
|
1040
1077
|
scanClientBundles,
|
|
1041
1078
|
SOURCE_MAP_COMMENT_REGEX,
|
|
@@ -1049,6 +1086,7 @@ export {
|
|
|
1049
1086
|
shiftSourceMapLines,
|
|
1050
1087
|
computeDeterministicDebugId,
|
|
1051
1088
|
chainSourceMaps,
|
|
1089
|
+
resolvePosition,
|
|
1052
1090
|
safeDecodeURIComponent,
|
|
1053
1091
|
symbolicateStackTrace
|
|
1054
1092
|
};
|
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
shiftSourceMapLines,
|
|
16
16
|
stripDebugIdComments,
|
|
17
17
|
stripSourceMapComments
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-TYL32LUK.js";
|
|
19
19
|
import {
|
|
20
20
|
computeFnv1aHash,
|
|
21
21
|
deriveWindowKeySymbol,
|
|
22
22
|
generateRuntimeShield,
|
|
23
23
|
transformJavaScript
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-LGTXAAZH.js";
|
|
25
25
|
import {
|
|
26
26
|
UnpeekError
|
|
27
27
|
} from "./chunk-LA6J3BT3.js";
|
|
@@ -86,6 +86,8 @@ function readUnpeekNextOptionsFromEnv() {
|
|
|
86
86
|
import fs from "fs";
|
|
87
87
|
import path from "path";
|
|
88
88
|
import zlib from "zlib";
|
|
89
|
+
import * as acorn from "acorn";
|
|
90
|
+
import { simple as walkSimple } from "acorn-walk";
|
|
89
91
|
var ENTRY_PATTERN = /^(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
|
|
90
92
|
function normalizeManifestRel(fileRef) {
|
|
91
93
|
const clean = fileRef.replace(/\\/g, "/").split("?")[0].split("#")[0].replace(/^\/+/, "");
|
|
@@ -237,6 +239,44 @@ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWri
|
|
|
237
239
|
}
|
|
238
240
|
return void 0;
|
|
239
241
|
}
|
|
242
|
+
function countPreExistingEvalCalls(code) {
|
|
243
|
+
const hits = [];
|
|
244
|
+
let ast;
|
|
245
|
+
try {
|
|
246
|
+
ast = acorn.parse(code, {
|
|
247
|
+
ecmaVersion: "latest",
|
|
248
|
+
sourceType: "module",
|
|
249
|
+
allowReturnOutsideFunction: true
|
|
250
|
+
});
|
|
251
|
+
} catch {
|
|
252
|
+
try {
|
|
253
|
+
ast = acorn.parse(code, {
|
|
254
|
+
ecmaVersion: "latest",
|
|
255
|
+
sourceType: "script",
|
|
256
|
+
allowReturnOutsideFunction: true
|
|
257
|
+
});
|
|
258
|
+
} catch {
|
|
259
|
+
return hits;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
walkSimple(ast, {
|
|
263
|
+
CallExpression(node) {
|
|
264
|
+
if (node.callee.type === "Identifier") {
|
|
265
|
+
if (node.callee.name === "eval") {
|
|
266
|
+
hits.push("eval(...)");
|
|
267
|
+
} else if (node.callee.name === "Function") {
|
|
268
|
+
hits.push("Function(...)");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
NewExpression(node) {
|
|
273
|
+
if (node.callee.type === "Identifier" && node.callee.name === "Function") {
|
|
274
|
+
hits.push("new Function(...)");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
return hits;
|
|
279
|
+
}
|
|
240
280
|
async function protectProject(options = {}) {
|
|
241
281
|
const startTime = performance.now();
|
|
242
282
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
@@ -289,6 +329,19 @@ async function protectProject(options = {}) {
|
|
|
289
329
|
const allProtBufs = [];
|
|
290
330
|
const stagedFiles = [];
|
|
291
331
|
const pendingVaultMaps = [];
|
|
332
|
+
const preExistingEvalFiles = {};
|
|
333
|
+
let alreadyProtectedCount = 0;
|
|
334
|
+
const manifestPath = path.join(vaultResult.vaultDir, "manifest.json");
|
|
335
|
+
let existingManifest;
|
|
336
|
+
if (!dryRun && fs.existsSync(manifestPath)) {
|
|
337
|
+
try {
|
|
338
|
+
const parsed = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
339
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
340
|
+
existingManifest = parsed;
|
|
341
|
+
}
|
|
342
|
+
} catch {
|
|
343
|
+
}
|
|
344
|
+
}
|
|
292
345
|
let originalGzipBytes = 0;
|
|
293
346
|
let protectedGzipBytes = 0;
|
|
294
347
|
let gzipDeltaPercent = 0;
|
|
@@ -309,6 +362,7 @@ async function protectProject(options = {}) {
|
|
|
309
362
|
originalBytes += origBuf.byteLength;
|
|
310
363
|
allOrigBufs.push(origBuf);
|
|
311
364
|
const relPath = allRelPaths[i];
|
|
365
|
+
const preExistingHits = countPreExistingEvalCalls(codeToTransform);
|
|
312
366
|
const isEntry = isEntryChunk(relPath, i, allRelPaths, manifestEntries, isWorkerTarget);
|
|
313
367
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
314
368
|
const fileSeed = computeFnv1aHash(`${relPath}:${i}`, seed);
|
|
@@ -338,6 +392,13 @@ async function protectProject(options = {}) {
|
|
|
338
392
|
file: relPath
|
|
339
393
|
});
|
|
340
394
|
} else if (result.skippedReason === "already-protected") {
|
|
395
|
+
alreadyProtectedCount++;
|
|
396
|
+
const prevHits = existingManifest?.preExistingEvalFiles?.[relPath];
|
|
397
|
+
if (Array.isArray(prevHits) && prevHits.length > 0) {
|
|
398
|
+
preExistingEvalFiles[relPath] = prevHits;
|
|
399
|
+
} else if (preExistingHits.length > 0) {
|
|
400
|
+
preExistingEvalFiles[relPath] = preExistingHits;
|
|
401
|
+
}
|
|
341
402
|
diagnostics.push({
|
|
342
403
|
code: "ALREADY_PROTECTED",
|
|
343
404
|
severity: "info",
|
|
@@ -351,6 +412,8 @@ async function protectProject(options = {}) {
|
|
|
351
412
|
message: `File "${relPath}" is empty.`,
|
|
352
413
|
file: relPath
|
|
353
414
|
});
|
|
415
|
+
} else if (preExistingHits.length > 0) {
|
|
416
|
+
preExistingEvalFiles[relPath] = preExistingHits;
|
|
354
417
|
}
|
|
355
418
|
let finalCode = result.code;
|
|
356
419
|
let preambleLineOffset = 0;
|
|
@@ -455,6 +518,34 @@ async function protectProject(options = {}) {
|
|
|
455
518
|
for (const { tmpPath, finalPath } of stagedFiles) {
|
|
456
519
|
fs.renameSync(tmpPath, finalPath);
|
|
457
520
|
}
|
|
521
|
+
const relVault = path.relative(cwd, vaultResult.vaultDir);
|
|
522
|
+
const isSafeVaultDir = relVault === "" || !relVault.startsWith("..") && !path.isAbsolute(relVault);
|
|
523
|
+
if (isSafeVaultDir) {
|
|
524
|
+
const relOutDir = path.relative(cwd, outDir).replace(/\\/g, "/") || ".";
|
|
525
|
+
const manifestPayload = processedFiles > 0 && alreadyProtectedCount === processedFiles && existingManifest ? {
|
|
526
|
+
version: 1,
|
|
527
|
+
outDir: existingManifest.outDir ?? relOutDir,
|
|
528
|
+
originalGzipBytes: existingManifest.originalGzipBytes ?? originalGzipBytes,
|
|
529
|
+
protectedGzipBytes: existingManifest.protectedGzipBytes ?? protectedGzipBytes,
|
|
530
|
+
gzipDeltaPercent: existingManifest.gzipDeltaPercent ?? gzipDeltaPercent,
|
|
531
|
+
preExistingEvalFiles: {
|
|
532
|
+
...existingManifest.preExistingEvalFiles ?? {},
|
|
533
|
+
...preExistingEvalFiles
|
|
534
|
+
}
|
|
535
|
+
} : {
|
|
536
|
+
version: 1,
|
|
537
|
+
outDir: relOutDir,
|
|
538
|
+
originalGzipBytes,
|
|
539
|
+
protectedGzipBytes,
|
|
540
|
+
gzipDeltaPercent,
|
|
541
|
+
preExistingEvalFiles
|
|
542
|
+
};
|
|
543
|
+
try {
|
|
544
|
+
fs.mkdirSync(vaultResult.vaultDir, { recursive: true });
|
|
545
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifestPayload, null, 2), "utf8");
|
|
546
|
+
} catch {
|
|
547
|
+
}
|
|
548
|
+
}
|
|
458
549
|
}
|
|
459
550
|
} catch (error) {
|
|
460
551
|
for (const { tmpPath } of stagedFiles) {
|
|
@@ -468,6 +559,7 @@ async function protectProject(options = {}) {
|
|
|
468
559
|
throw error;
|
|
469
560
|
}
|
|
470
561
|
const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
|
|
562
|
+
const resolvedTier = options.tier ?? (effectiveProfile === "strict" || aggressive ? "Tier 3" : effectiveProfile === "minimal" ? "Tier 1" : config.tier ?? "Tier 2");
|
|
471
563
|
return {
|
|
472
564
|
framework,
|
|
473
565
|
outDir,
|
|
@@ -484,7 +576,7 @@ async function protectProject(options = {}) {
|
|
|
484
576
|
totalMangledSymbols,
|
|
485
577
|
elapsedMs,
|
|
486
578
|
seed,
|
|
487
|
-
tier:
|
|
579
|
+
tier: resolvedTier,
|
|
488
580
|
aggressive,
|
|
489
581
|
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
|
|
490
582
|
dryRun,
|