unpeek 3.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.
Files changed (69) hide show
  1. package/README.md +31 -16
  2. package/README.tr.md +41 -26
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.d.cts +3 -1
  5. package/dist/adapters/esbuild.d.ts +2 -2
  6. package/dist/adapters/esbuild.js +5 -3
  7. package/dist/adapters/next/adapter.cjs +7 -6
  8. package/dist/adapters/next/adapter.d.cts +1 -1
  9. package/dist/adapters/next/adapter.d.ts +1 -1
  10. package/dist/adapters/next/adapter.js +6 -5
  11. package/dist/adapters/next/index.cjs +7 -6
  12. package/dist/adapters/next/index.js +6 -5
  13. package/dist/adapters/rollup.cjs +5 -5
  14. package/dist/adapters/rollup.d.cts +3 -1
  15. package/dist/adapters/rollup.d.ts +2 -2
  16. package/dist/adapters/rollup.js +5 -3
  17. package/dist/adapters/rspack.cjs +5 -4
  18. package/dist/adapters/rspack.d.cts +1 -1
  19. package/dist/adapters/rspack.d.ts +1 -1
  20. package/dist/adapters/rspack.js +3 -2
  21. package/dist/adapters/vite.cjs +5 -5
  22. package/dist/adapters/vite.d.cts +3 -1
  23. package/dist/adapters/vite.d.ts +2 -2
  24. package/dist/adapters/vite.js +5 -3
  25. package/dist/adapters/webpack.cjs +5 -5
  26. package/dist/adapters/webpack.d.cts +3 -1
  27. package/dist/adapters/webpack.d.ts +2 -2
  28. package/dist/adapters/webpack.js +5 -3
  29. package/dist/browser.cjs +3 -3
  30. package/dist/browser.d.cts +20 -17
  31. package/dist/browser.d.ts +20 -17
  32. package/dist/browser.js +2 -2
  33. package/dist/chunk-3GDHYBVH.cjs +1092 -0
  34. package/dist/chunk-4G2HCME5.js +429 -0
  35. package/dist/{chunk-BPRSCRUZ.js → chunk-4SOS3LRV.js} +53 -9
  36. package/dist/chunk-7ZEVJ4OR.cjs +595 -0
  37. package/dist/{chunk-FCF2EGPM.js → chunk-EN6QVR6P.js} +12 -3
  38. package/dist/{chunk-IZIWDJRF.js → chunk-LGTXAAZH.js} +3338 -972
  39. package/dist/chunk-M46SFJE7.cjs +7733 -0
  40. package/dist/{chunk-6TDCSIRZ.cjs → chunk-NNAAPDUS.cjs} +60 -16
  41. package/dist/chunk-OTA75YI6.cjs +429 -0
  42. package/dist/chunk-TYL32LUK.js +1092 -0
  43. package/dist/{chunk-IEBVL5BT.cjs → chunk-URPPSTHZ.cjs} +12 -3
  44. package/dist/{chunk-IICVBTR2.js → chunk-W77DAC3H.js} +22 -3
  45. package/dist/{chunk-ONM2CSTU.cjs → chunk-X6EETCO6.cjs} +64 -45
  46. package/dist/chunk-XYN5NYSD.js +595 -0
  47. package/dist/cli/index.js +4543 -1442
  48. package/dist/{config-CfXY_iDD.d.ts → config-Y6JwVGwX.d.cts} +15 -1
  49. package/dist/{config-CfXY_iDD.d.cts → config-Y6JwVGwX.d.ts} +15 -1
  50. package/dist/config.cjs +3 -3
  51. package/dist/config.d.cts +1 -1
  52. package/dist/config.d.ts +1 -1
  53. package/dist/config.js +2 -2
  54. package/dist/{index-CjRTNPlj.d.cts → index-0O1WSfVP.d.ts} +7 -1
  55. package/dist/{index-Cm1IloVm.d.ts → index-COVHErnx.d.cts} +7 -1
  56. package/dist/index.cjs +231 -291
  57. package/dist/index.d.cts +4 -4
  58. package/dist/index.d.ts +4 -4
  59. package/dist/index.js +225 -285
  60. package/dist/plugins/unplugin.cjs +4 -3
  61. package/dist/plugins/unplugin.js +3 -2
  62. package/dist/{types-DYQIzGf6.d.cts → types-CMtZnV8C.d.ts} +3 -3
  63. package/dist/{types-ZHAFdOd3.d.ts → types-D93PuOOl.d.cts} +3 -3
  64. package/package.json +1 -1
  65. package/dist/chunk-APWMNVAZ.js +0 -764
  66. package/dist/chunk-DUK2SECY.js +0 -83
  67. package/dist/chunk-I6GXEHFR.cjs +0 -764
  68. package/dist/chunk-IAD5DV3D.cjs +0 -5367
  69. package/dist/chunk-RXUY3MPH.cjs +0 -83
@@ -1,10 +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 _chunkI6GXEHFRcjs = require('./chunk-I6GXEHFR.cjs');
4
+ var _chunk7ZEVJ4ORcjs = require('./chunk-7ZEVJ4OR.cjs');
5
5
 
6
6
 
7
- var _chunkIAD5DV3Dcjs = require('./chunk-IAD5DV3D.cjs');
7
+
8
+ var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
9
+
10
+
11
+ var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
8
12
 
9
13
 
10
14
 
@@ -37,6 +41,26 @@ function recomputeHash(content, existingHash) {
37
41
  function isNonProductionPhase(phase) {
38
42
  return phase !== void 0 && phase !== "phase-production-build" && phase !== "phase-export";
39
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
+ }
40
64
  async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
41
65
  if (!upstreamPath) return;
42
66
  try {
@@ -51,7 +75,9 @@ async function delegateToUpstreamOnBuildComplete(upstreamPath, context) {
51
75
  }
52
76
  }
53
77
  function createUnpeekNextAdapter(options = {}) {
54
- const upstreamPath = options.upstreamAdapterPath || process.env.UNPEEK_UPSTREAM_ADAPTER_PATH || process.env.NEXT_ADAPTER_PATH;
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;
55
81
  let recordedPhase;
56
82
  return {
57
83
  name: "unpeek",
@@ -69,13 +95,26 @@ function createUnpeekNextAdapter(options = {}) {
69
95
  console.warn("[unpeek:next] Failed to invoke upstream modifyConfig:", err);
70
96
  }
71
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
+ }
72
109
  return config;
73
110
  },
74
111
  async onBuildComplete(context) {
75
112
  const cwd = _nullishCoalesce(options.cwd, () => ( process.cwd()));
76
- const distDir = _path2.default.resolve(cwd, context.distDir || ".next");
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);
77
115
  const staticDir = _path2.default.join(distDir, "static");
78
- const targetDir = _fs2.default.existsSync(staticDir) ? staticDir : distDir;
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;
79
118
  const phase = _nullishCoalesce(context.phase, () => ( recordedPhase));
80
119
  if (isNonProductionPhase(phase)) {
81
120
  await delegateToUpstreamOnBuildComplete(upstreamPath, context);
@@ -96,14 +135,14 @@ function createUnpeekNextAdapter(options = {}) {
96
135
  elapsedMs: 0
97
136
  };
98
137
  }
99
- const deterministicSeed = typeof options.seed === "number" ? options.seed : context.buildId ? _chunkIAD5DV3Dcjs.computeFnv1aHash.call(void 0, context.buildId, 1597463007) : 1597463007;
100
- const summary = await _chunkI6GXEHFRcjs.protectProject.call(void 0, {
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, {
101
140
  ...options,
102
141
  cwd,
103
142
  outDir: targetDir,
104
143
  seed: deterministicSeed
105
144
  });
106
- if (_optionalChain([context, 'access', _2 => _2.outputs, 'optionalAccess', _3 => _3.staticFiles])) {
145
+ if (_optionalChain([context, 'access', _6 => _6.outputs, 'optionalAccess', _7 => _7.staticFiles])) {
107
146
  const rawStatic = context.outputs.staticFiles;
108
147
  const fileList = Array.isArray(rawStatic) ? rawStatic : rawStatic instanceof Map ? Array.from(rawStatic.values()) : typeof rawStatic === "object" ? Object.values(rawStatic) : [];
109
148
  for (const item of fileList) {
@@ -112,7 +151,7 @@ function createUnpeekNextAdapter(options = {}) {
112
151
  if (!rawFilePath) continue;
113
152
  let absPath = _path2.default.isAbsolute(rawFilePath) ? rawFilePath : _path2.default.resolve(cwd, rawFilePath);
114
153
  if (!_fs2.default.existsSync(absPath)) {
115
- const relClean = rawFilePath.replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
154
+ const relClean = _chunk3GDHYBVHcjs.safeDecodeURIComponent.call(void 0, rawFilePath).replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
116
155
  const fromDist = _path2.default.resolve(distDir, relClean);
117
156
  if (_fs2.default.existsSync(fromDist)) {
118
157
  absPath = fromDist;
@@ -121,6 +160,11 @@ function createUnpeekNextAdapter(options = {}) {
121
160
  const fromStatic = _path2.default.resolve(distDir, "static", staticClean);
122
161
  if (_fs2.default.existsSync(fromStatic)) {
123
162
  absPath = fromStatic;
163
+ } else {
164
+ const fromVercelStatic = _path2.default.resolve(vercelStaticDir, staticClean);
165
+ if (_fs2.default.existsSync(fromVercelStatic)) {
166
+ absPath = fromVercelStatic;
167
+ }
124
168
  }
125
169
  }
126
170
  }
@@ -135,7 +179,7 @@ function createUnpeekNextAdapter(options = {}) {
135
179
  if (typeof item.size === "number") {
136
180
  item.size = buf.byteLength;
137
181
  }
138
- } catch (e2) {
182
+ } catch (e3) {
139
183
  }
140
184
  }
141
185
  }
@@ -154,7 +198,7 @@ function getUnpeekAdapterPath() {
154
198
  if (_fs2.default.existsSync(resolved)) {
155
199
  return resolved;
156
200
  }
157
- } catch (e3) {
201
+ } catch (e4) {
158
202
  }
159
203
  const isCjs = typeof __dirname !== "undefined";
160
204
  const currentDir = isCjs ? __dirname : _path2.default.dirname(_url.fileURLToPath.call(void 0, _chunkL6BOM5VScjs.importMetaUrl));
@@ -174,20 +218,21 @@ function getUnpeekAdapterPath() {
174
218
  }
175
219
  }
176
220
  return candidates[0];
177
- } catch (e4) {
221
+ } catch (e5) {
178
222
  return _path2.default.resolve(process.cwd(), "node_modules/unpeek/dist/adapters/next/adapter.js");
179
223
  }
180
224
  }
181
225
  function applyWithUnpeek(config = {}, options) {
226
+ const adapterPath = getUnpeekAdapterPath();
182
227
  const existingAdapter = config.adapterPath || process.env.NEXT_ADAPTER_PATH;
183
- if (existingAdapter && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
228
+ if (existingAdapter && !isSameAdapterPath(existingAdapter, adapterPath) && !process.env.UNPEEK_UPSTREAM_ADAPTER_PATH) {
184
229
  process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = existingAdapter;
185
230
  }
186
- if (_optionalChain([options, 'optionalAccess', _4 => _4.upstreamAdapterPath])) {
231
+ if (_optionalChain([options, 'optionalAccess', _8 => _8.upstreamAdapterPath]) && !isSameAdapterPath(options.upstreamAdapterPath, adapterPath)) {
187
232
  process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = options.upstreamAdapterPath;
188
233
  }
189
234
  if (options) {
190
- const serialized = _chunkI6GXEHFRcjs.serializeNextOptions.call(void 0, options);
235
+ const serialized = _chunk7ZEVJ4ORcjs.serializeNextOptions.call(void 0, options);
191
236
  const byteLength = Buffer.byteLength(serialized, "utf8");
192
237
  if (byteLength > MAX_NEXT_OPTIONS_ENV_BYTES) {
193
238
  throw new (0, _chunkL6BOM5VScjs.UnpeekError)(
@@ -199,7 +244,6 @@ function applyWithUnpeek(config = {}, options) {
199
244
  } else {
200
245
  delete process.env.UNPEEK_NEXT_OPTIONS;
201
246
  }
202
- const adapterPath = getUnpeekAdapterPath();
203
247
  return {
204
248
  ...config,
205
249
  adapterPath
@@ -0,0 +1,429 @@
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
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _chunk3GDHYBVHcjs = require('./chunk-3GDHYBVH.cjs');
11
+
12
+
13
+
14
+
15
+
16
+ var _chunkM46SFJE7cjs = require('./chunk-M46SFJE7.cjs');
17
+
18
+ // src/plugins/unplugin.ts
19
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
20
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
21
+ var _unplugin = require('unplugin');
22
+ var ENTRY_CHUNK_PATTERN = /(?:^|\/)(?:webpack|main|index|runtime|turbopack|pages\/_app|pages\/index)(?:[-._/]|$)/i;
23
+ var SW_OR_WORKBOX_PATTERN = /(?:^|\/)(?:sw|service-worker|workbox-[^/]+)\.(?:js|mjs|cjs)$|\.worker\.min\.(?:js|mjs|cjs)$/i;
24
+ function isSupportedJsAsset(fileName) {
25
+ const clean = fileName.replace(/\\/g, "/").split("?")[0].split("#")[0].toLowerCase();
26
+ return clean.endsWith(".js") || clean.endsWith(".mjs") || clean.endsWith(".cjs");
27
+ }
28
+ function isExcludedClientAsset(fileName, config) {
29
+ const norm = fileName.replace(/\\/g, "/").split("?")[0].split("#")[0];
30
+ if (norm.includes("server/") || norm.includes("ssr/") || norm.includes("node_modules/")) {
31
+ return true;
32
+ }
33
+ if (_optionalChain([config, 'optionalAccess', _ => _.target]) !== "worker" && SW_OR_WORKBOX_PATTERN.test(norm)) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }
38
+ function createWebpackRawSource(sources, content) {
39
+ if (sources && typeof sources.RawSource === "function") {
40
+ return new sources.RawSource(content);
41
+ }
42
+ return {
43
+ source: () => content,
44
+ buffer: () => Buffer.from(content, "utf8"),
45
+ size: () => Buffer.byteLength(content, "utf8"),
46
+ map: () => null,
47
+ sourceAndMap: () => ({ source: content, map: null }),
48
+ updateHash: (hash) => {
49
+ hash.update(content);
50
+ }
51
+ };
52
+ }
53
+ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
54
+ const config = options.config;
55
+ const baseSeed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 322420463;
56
+ const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'optionalAccess', _2 => _2.shield, 'optionalAccess', _3 => _3.deterrentMode]))), () => ( "passive"));
57
+ const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'optionalAccess', _4 => _4.shield, 'optionalAccess', _5 => _5.detectHeadless]))), () => ( false));
58
+ const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( true));
59
+ const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'optionalAccess', _6 => _6.vault, 'optionalAccess', _7 => _7.minStringLength]))), () => ( 4));
60
+ const aggressive = _nullishCoalesce(options.aggressive, () => ( false));
61
+ const masterSym = _chunkM46SFJE7cjs.deriveWindowKeySymbol.call(void 0, baseSeed);
62
+ const masterShield = injectRuntimeShield ? _chunkM46SFJE7cjs.generateRuntimeShield.call(void 0, {
63
+ seed: baseSeed,
64
+ deterrentMode,
65
+ detectHeadless,
66
+ windowKeySymbol: masterSym
67
+ }) : void 0;
68
+ const transformChunk = (rawCode, fileName, isEntry, inputMap, requestMap = false) => {
69
+ const normalizedFileName = fileName.replace(/\\/g, "/").split("?")[0].split("#")[0];
70
+ if (!isSupportedJsAsset(normalizedFileName) || isExcludedClientAsset(normalizedFileName, config)) {
71
+ return null;
72
+ }
73
+ const fileDebugId = _chunk3GDHYBVHcjs.extractDebugId.call(void 0, rawCode);
74
+ const shouldStripComments = _optionalChain([config, 'optionalAccess', _8 => _8.sourcemaps, 'optionalAccess', _9 => _9.stripComments]) !== false;
75
+ let codeToTransform = rawCode;
76
+ if (shouldStripComments && rawCode.includes("sourceMappingURL=")) {
77
+ codeToTransform = _chunk3GDHYBVHcjs.stripSourceMapComments.call(void 0, rawCode).code;
78
+ }
79
+ const shouldInjectShield = injectRuntimeShield && isEntry;
80
+ const chunkSeed = _chunkM46SFJE7cjs.computeFnv1aHash.call(void 0, fileName, baseSeed);
81
+ const transformOptions = {
82
+ seed: chunkSeed,
83
+ minStringLength,
84
+ filename: fileName,
85
+ injectRuntimeShield: shouldInjectShield,
86
+ skipShieldPreamble: true,
87
+ shieldCoupled: injectRuntimeShield,
88
+ windowKeySymbol: masterSym,
89
+ expectedDelta: _optionalChain([masterShield, 'optionalAccess', _10 => _10.expectedDelta]),
90
+ deterrentMode,
91
+ detectHeadless,
92
+ aggressive,
93
+ config
94
+ };
95
+ transformOptions.generateMap = requestMap || Boolean(inputMap);
96
+ transformOptions.rootDir = process.cwd();
97
+ const result = _chunkM46SFJE7cjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
98
+ let finalCode = result.code;
99
+ let preambleLineOffset = 0;
100
+ const integrityCheckFnName = masterShield && "integrityCheckFnName" in masterShield ? masterShield.integrityCheckFnName : void 0;
101
+ if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _11 => _11.preambleCode]) && !finalCode.includes("(function _u$") && (!integrityCheckFnName || !finalCode.includes(integrityCheckFnName)) && !finalCode.startsWith(masterShield.preambleCode)) {
102
+ const prefix = `${masterShield.preambleCode}
103
+ `;
104
+ preambleLineOffset = (_nullishCoalesce(prefix.match(/\n/g), () => ( []))).length;
105
+ finalCode = `${prefix}${finalCode}`;
106
+ }
107
+ const rawTransformMap = result.sourceMap;
108
+ const shiftedTransformMap = rawTransformMap ? _chunk3GDHYBVHcjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
109
+ let composedMap = null;
110
+ if (shiftedTransformMap && inputMap) {
111
+ composedMap = _chunk3GDHYBVHcjs.chainSourceMaps.call(void 0, shiftedTransformMap, inputMap);
112
+ } else if (shiftedTransformMap) {
113
+ composedMap = shiftedTransformMap;
114
+ } else if (inputMap) {
115
+ composedMap = _chunk3GDHYBVHcjs.flattenSourceMapSections.call(void 0, inputMap);
116
+ }
117
+ const inputMapDebugId = _nullishCoalesce(_optionalChain([inputMap, 'optionalAccess', _12 => _12.debugId]), () => ( _optionalChain([inputMap, 'optionalAccess', _13 => _13.debug_id])));
118
+ const hadDebugId = Boolean(fileDebugId || inputMapDebugId || result.debugId);
119
+ if (hadDebugId) {
120
+ const codeWithoutDebugId = _chunk3GDHYBVHcjs.stripDebugIdComments.call(void 0, finalCode);
121
+ const mintedDebugId = _chunk3GDHYBVHcjs.computeDeterministicDebugId.call(void 0,
122
+ codeWithoutDebugId,
123
+ _nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _14 => _14.mappings]), () => ( ""))
124
+ );
125
+ finalCode = _chunk3GDHYBVHcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
126
+ if (composedMap) {
127
+ composedMap.debugId = mintedDebugId;
128
+ delete composedMap.debug_id;
129
+ }
130
+ }
131
+ if (composedMap) {
132
+ if (!Object.prototype.hasOwnProperty.call(composedMap, "toString")) {
133
+ Object.defineProperty(composedMap, "toString", {
134
+ enumerable: false,
135
+ configurable: true,
136
+ value() {
137
+ return JSON.stringify(this);
138
+ }
139
+ });
140
+ }
141
+ }
142
+ return {
143
+ code: finalCode,
144
+ map: composedMap
145
+ };
146
+ };
147
+ const renderChunkHandler = (code, chunk) => {
148
+ const normalizedFileName = chunk.fileName.replace(/\\/g, "/").split("?")[0].split("#")[0];
149
+ const isEntry = chunk.isEntry !== void 0 ? chunk.isEntry : ENTRY_CHUNK_PATTERN.test(normalizedFileName);
150
+ const res = transformChunk(code, chunk.fileName, isEntry, void 0, true);
151
+ if (!res) {
152
+ return null;
153
+ }
154
+ return {
155
+ code: res.code,
156
+ map: _nullishCoalesce(res.map, () => ( null))
157
+ };
158
+ };
159
+ const attachWebpackLikeProcessAssets = (compiler, framework) => {
160
+ compiler.hooks.thisCompilation.tap("unpeek", (compilation) => {
161
+ const stage = _nullishCoalesce((framework === "rspack" ? _optionalChain([compiler, 'access', _15 => _15.rspack, 'optionalAccess', _16 => _16.Compilation, 'optionalAccess', _17 => _17.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE]) : _optionalChain([compiler, 'access', _18 => _18.webpack, 'optionalAccess', _19 => _19.Compilation, 'optionalAccess', _20 => _20.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE])), () => ( 700));
162
+ compilation.hooks.processAssets.tap(
163
+ { name: "unpeek", stage },
164
+ (assets) => {
165
+ const entryFiles = /* @__PURE__ */ new Set();
166
+ if (compilation.entrypoints && typeof compilation.entrypoints.values === "function") {
167
+ for (const ep of compilation.entrypoints.values()) {
168
+ if (ep && typeof ep.getFiles === "function") {
169
+ for (const f of ep.getFiles()) {
170
+ entryFiles.add(String(f).replace(/\\/g, "/").split("?")[0]);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ if (compilation.chunks) {
176
+ for (const chunk of compilation.chunks) {
177
+ const chunkIsEntry = typeof chunk.hasRuntime === "function" && chunk.hasRuntime() || typeof chunk.canBeInitial === "function" && chunk.canBeInitial();
178
+ if (chunkIsEntry && chunk.files) {
179
+ for (const f of chunk.files) {
180
+ entryFiles.add(String(f).replace(/\\/g, "/").split("?")[0]);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ const sources = _nullishCoalesce(_nullishCoalesce((framework === "rspack" ? _optionalChain([compiler, 'access', _21 => _21.rspack, 'optionalAccess', _22 => _22.sources]) : _optionalChain([compiler, 'access', _23 => _23.webpack, 'optionalAccess', _24 => _24.sources])), () => ( _optionalChain([compiler, 'access', _25 => _25.webpack, 'optionalAccess', _26 => _26.sources]))), () => ( _optionalChain([compiler, 'access', _27 => _27.rspack, 'optionalAccess', _28 => _28.sources])));
186
+ for (const assetName of Object.keys(assets)) {
187
+ const normalizedName = assetName.replace(/\\/g, "/").split("?")[0];
188
+ if (!isSupportedJsAsset(normalizedName) || isExcludedClientAsset(normalizedName, config)) {
189
+ continue;
190
+ }
191
+ const existingAsset = typeof compilation.getAsset === "function" ? compilation.getAsset(assetName) : { source: assets[assetName] };
192
+ const sourceObj = _nullishCoalesce(_optionalChain([existingAsset, 'optionalAccess', _29 => _29.source]), () => ( assets[assetName]));
193
+ if (!sourceObj) continue;
194
+ const rawContent = typeof sourceObj.source === "function" ? sourceObj.source() : sourceObj;
195
+ const code = Buffer.isBuffer(rawContent) ? rawContent.toString("utf8") : String(rawContent);
196
+ const mapAssetName = `${assetName}.map`;
197
+ const mapSourceObj = assets[mapAssetName];
198
+ let inputMap;
199
+ if (mapSourceObj) {
200
+ try {
201
+ const rawMap = typeof mapSourceObj.source === "function" ? mapSourceObj.source() : mapSourceObj;
202
+ const mapStr = Buffer.isBuffer(rawMap) ? rawMap.toString("utf8") : String(rawMap);
203
+ inputMap = JSON.parse(mapStr);
204
+ } catch (e) {
205
+ }
206
+ } else if (typeof sourceObj.map === "function") {
207
+ try {
208
+ const m = sourceObj.map();
209
+ if (m && typeof m === "object") {
210
+ inputMap = m;
211
+ }
212
+ } catch (e2) {
213
+ }
214
+ }
215
+ const isEntry = entryFiles.size > 0 ? entryFiles.has(normalizedName) || ENTRY_CHUNK_PATTERN.test(normalizedName) : ENTRY_CHUNK_PATTERN.test(normalizedName);
216
+ const res = transformChunk(code, assetName, isEntry, inputMap, Boolean(inputMap));
217
+ if (!res) continue;
218
+ const newSource = createWebpackRawSource(sources, res.code);
219
+ if (typeof compilation.updateAsset === "function") {
220
+ compilation.updateAsset(assetName, newSource);
221
+ } else {
222
+ assets[assetName] = newSource;
223
+ }
224
+ if (res.map && mapSourceObj) {
225
+ const newMapSource = createWebpackRawSource(sources, JSON.stringify(res.map));
226
+ if (typeof compilation.updateAsset === "function") {
227
+ compilation.updateAsset(mapAssetName, newMapSource);
228
+ } else {
229
+ assets[mapAssetName] = newMapSource;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ );
235
+ });
236
+ };
237
+ return {
238
+ name: "unpeek",
239
+ enforce: "post",
240
+ // Preserved at top-level for direct unpeekPlugin.raw() unit test compatibility and Rollup
241
+ renderChunk: renderChunkHandler,
242
+ rollup: {
243
+ renderChunk: renderChunkHandler
244
+ },
245
+ vite: {
246
+ enforce: "post",
247
+ apply: "build",
248
+ renderChunk: void 0,
249
+ config(userConfig) {
250
+ if (_optionalChain([config, 'optionalAccess', _30 => _30.target]) === "worker") {
251
+ return void 0;
252
+ }
253
+ const existingWorkerPlugins = _optionalChain([userConfig, 'optionalAccess', _31 => _31.worker, 'optionalAccess', _32 => _32.plugins]);
254
+ return {
255
+ worker: {
256
+ plugins: () => {
257
+ const resolved = typeof existingWorkerPlugins === "function" ? existingWorkerPlugins() : Array.isArray(existingWorkerPlugins) ? existingWorkerPlugins : [];
258
+ const flat = (Array.isArray(resolved) ? resolved : [resolved]).flat(Infinity).filter(Boolean);
259
+ if (flat.some((p) => p && p.name === "unpeek")) {
260
+ return flat;
261
+ }
262
+ return [
263
+ ...flat,
264
+ vitePlugin({
265
+ ...options,
266
+ seed: baseSeed,
267
+ config: {
268
+ ..._nullishCoalesce(config, () => ( {})),
269
+ target: "worker"
270
+ }
271
+ })
272
+ ];
273
+ }
274
+ }
275
+ };
276
+ },
277
+ generateBundle(_outputOptions, bundle) {
278
+ for (const [fileName, item] of Object.entries(bundle)) {
279
+ if (!item || item.type !== "chunk") continue;
280
+ const normalizedFileName = fileName.replace(/\\/g, "/").split("?")[0].split("#")[0];
281
+ if (!isSupportedJsAsset(normalizedFileName) || isExcludedClientAsset(normalizedFileName, config)) {
282
+ continue;
283
+ }
284
+ const mapAssetKey = `${fileName}.map`;
285
+ const mapAsset = bundle[mapAssetKey];
286
+ let inputMap = item.map && typeof item.map === "object" ? item.map : void 0;
287
+ if (!inputMap && mapAsset && mapAsset.type === "asset") {
288
+ try {
289
+ const rawMapStr = typeof mapAsset.source === "string" ? mapAsset.source : Buffer.from(mapAsset.source).toString("utf8");
290
+ inputMap = JSON.parse(rawMapStr);
291
+ } catch (e3) {
292
+ }
293
+ }
294
+ const isEntry = typeof item.isEntry === "boolean" ? item.isEntry : ENTRY_CHUNK_PATTERN.test(normalizedFileName);
295
+ const res = transformChunk(item.code, fileName, isEntry, inputMap, Boolean(inputMap));
296
+ if (!res) continue;
297
+ item.code = res.code;
298
+ if (res.map) {
299
+ item.map = res.map;
300
+ if (mapAsset && mapAsset.type === "asset") {
301
+ mapAsset.source = JSON.stringify(res.map);
302
+ }
303
+ }
304
+ }
305
+ }
306
+ },
307
+ webpack(compiler) {
308
+ attachWebpackLikeProcessAssets(compiler, "webpack");
309
+ },
310
+ rspack(compiler) {
311
+ attachWebpackLikeProcessAssets(compiler, "rspack");
312
+ },
313
+ esbuild: {
314
+ config(buildOptions) {
315
+ buildOptions.metafile = true;
316
+ },
317
+ setup(build) {
318
+ build.onEnd(async (result) => {
319
+ const workDir = _nullishCoalesce(build.initialOptions.absWorkingDir, () => ( process.cwd()));
320
+ const entryOutputs = /* @__PURE__ */ new Set();
321
+ if (_optionalChain([result, 'access', _33 => _33.metafile, 'optionalAccess', _34 => _34.outputs])) {
322
+ for (const [outKey, meta] of Object.entries(result.metafile.outputs)) {
323
+ if (meta && meta.entryPoint) {
324
+ entryOutputs.add(_path2.default.resolve(workDir, outKey));
325
+ entryOutputs.add(outKey.replace(/\\/g, "/"));
326
+ }
327
+ }
328
+ }
329
+ if (Array.isArray(result.outputFiles) && result.outputFiles.length > 0) {
330
+ const mapFilesByPath = /* @__PURE__ */ new Map();
331
+ for (const outFile of result.outputFiles) {
332
+ if (outFile.path.endsWith(".map")) {
333
+ mapFilesByPath.set(outFile.path, outFile);
334
+ }
335
+ }
336
+ const jsOutCount = result.outputFiles.filter((f) => isSupportedJsAsset(f.path)).length;
337
+ for (const outFile of result.outputFiles) {
338
+ const normPath = outFile.path.replace(/\\/g, "/");
339
+ if (!isSupportedJsAsset(normPath) || isExcludedClientAsset(normPath, config)) {
340
+ continue;
341
+ }
342
+ const mapFile = mapFilesByPath.get(`${outFile.path}.map`);
343
+ let inputMap;
344
+ if (mapFile) {
345
+ try {
346
+ inputMap = JSON.parse(mapFile.text);
347
+ } catch (e4) {
348
+ }
349
+ }
350
+ const relFromWork = _path2.default.relative(workDir, outFile.path).replace(/\\/g, "/");
351
+ const isEntry = entryOutputs.size > 0 ? entryOutputs.has(outFile.path) || entryOutputs.has(relFromWork) || ENTRY_CHUNK_PATTERN.test(relFromWork) : ENTRY_CHUNK_PATTERN.test(relFromWork) || jsOutCount === 1;
352
+ const res = transformChunk(
353
+ outFile.text,
354
+ relFromWork || _path2.default.basename(outFile.path),
355
+ isEntry,
356
+ inputMap,
357
+ Boolean(inputMap)
358
+ );
359
+ if (!res) continue;
360
+ outFile.contents = Buffer.from(res.code, "utf8");
361
+ if (res.map && mapFile) {
362
+ mapFile.contents = Buffer.from(JSON.stringify(res.map), "utf8");
363
+ }
364
+ }
365
+ return;
366
+ }
367
+ const diskOutputs = /* @__PURE__ */ new Set();
368
+ if (_optionalChain([result, 'access', _35 => _35.metafile, 'optionalAccess', _36 => _36.outputs])) {
369
+ for (const outKey of Object.keys(result.metafile.outputs)) {
370
+ const abs = _path2.default.resolve(workDir, outKey);
371
+ if (isSupportedJsAsset(abs)) {
372
+ diskOutputs.add(abs);
373
+ }
374
+ }
375
+ } else if (build.initialOptions.outfile) {
376
+ const abs = _path2.default.resolve(workDir, build.initialOptions.outfile);
377
+ if (isSupportedJsAsset(abs)) {
378
+ diskOutputs.add(abs);
379
+ }
380
+ }
381
+ const diskArr = Array.from(diskOutputs);
382
+ for (const absPath of diskArr) {
383
+ const relFromWork = _path2.default.relative(workDir, absPath).replace(/\\/g, "/");
384
+ if (isExcludedClientAsset(relFromWork, config)) continue;
385
+ if (!_fs2.default.existsSync(absPath)) continue;
386
+ const code = _fs2.default.readFileSync(absPath, "utf8");
387
+ const mapPath = `${absPath}.map`;
388
+ let inputMap;
389
+ if (_fs2.default.existsSync(mapPath)) {
390
+ try {
391
+ inputMap = JSON.parse(_fs2.default.readFileSync(mapPath, "utf8"));
392
+ } catch (e5) {
393
+ }
394
+ }
395
+ const isEntry = entryOutputs.size > 0 ? entryOutputs.has(absPath) || entryOutputs.has(relFromWork) || ENTRY_CHUNK_PATTERN.test(relFromWork) : ENTRY_CHUNK_PATTERN.test(relFromWork) || diskArr.length === 1;
396
+ const res = transformChunk(
397
+ code,
398
+ relFromWork || _path2.default.basename(absPath),
399
+ isEntry,
400
+ inputMap,
401
+ Boolean(inputMap)
402
+ );
403
+ if (!res) continue;
404
+ _fs2.default.writeFileSync(absPath, res.code, "utf8");
405
+ if (res.map && _fs2.default.existsSync(mapPath)) {
406
+ _fs2.default.writeFileSync(mapPath, JSON.stringify(res.map), "utf8");
407
+ }
408
+ }
409
+ });
410
+ }
411
+ }
412
+ };
413
+ });
414
+ var vitePlugin = unpeekPlugin.vite;
415
+ var webpackPlugin = unpeekPlugin.webpack;
416
+ var rollupPlugin = unpeekPlugin.rollup;
417
+ var esbuildPlugin = unpeekPlugin.esbuild;
418
+ var rspackPlugin = unpeekPlugin.rspack;
419
+ var unplugin_default = unpeekPlugin;
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+ exports.unpeekPlugin = unpeekPlugin; exports.vitePlugin = vitePlugin; exports.webpackPlugin = webpackPlugin; exports.rollupPlugin = rollupPlugin; exports.esbuildPlugin = esbuildPlugin; exports.rspackPlugin = rspackPlugin; exports.unplugin_default = unplugin_default;