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.
Files changed (64) hide show
  1. package/README.md +21 -12
  2. package/README.tr.md +20 -11
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.d.cts +1 -1
  5. package/dist/adapters/esbuild.d.ts +1 -1
  6. package/dist/adapters/esbuild.js +3 -3
  7. package/dist/adapters/next/adapter.cjs +6 -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 +5 -5
  11. package/dist/adapters/next/index.cjs +6 -6
  12. package/dist/adapters/next/index.js +5 -5
  13. package/dist/adapters/rollup.cjs +5 -5
  14. package/dist/adapters/rollup.d.cts +1 -1
  15. package/dist/adapters/rollup.d.ts +1 -1
  16. package/dist/adapters/rollup.js +3 -3
  17. package/dist/adapters/rspack.cjs +5 -5
  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 -3
  21. package/dist/adapters/vite.cjs +5 -5
  22. package/dist/adapters/vite.d.cts +1 -1
  23. package/dist/adapters/vite.d.ts +1 -1
  24. package/dist/adapters/vite.js +3 -3
  25. package/dist/adapters/webpack.cjs +5 -5
  26. package/dist/adapters/webpack.d.cts +1 -1
  27. package/dist/adapters/webpack.d.ts +1 -1
  28. package/dist/adapters/webpack.js +3 -3
  29. package/dist/browser.cjs +2 -2
  30. package/dist/browser.d.cts +4 -4
  31. package/dist/browser.d.ts +4 -4
  32. package/dist/browser.js +1 -1
  33. package/dist/chunk-32GLSJAW.js +614 -0
  34. package/dist/{chunk-W77DAC3H.js → chunk-6EWFL4LQ.js} +16 -0
  35. package/dist/{chunk-4FNZNIBW.js → chunk-6KLUNEKE.js} +2538 -547
  36. package/dist/chunk-AD6UFBPA.cjs +614 -0
  37. package/dist/{chunk-X6EETCO6.cjs → chunk-BQ2O6HM5.cjs} +16 -0
  38. package/dist/{chunk-ZG7BIAUI.cjs → chunk-FLZ4FSP5.cjs} +58 -17
  39. package/dist/{chunk-2JU3V7HW.js → chunk-HV47WJIR.js} +52 -11
  40. package/dist/{chunk-VG4Y26ZN.cjs → chunk-Q4DFRMAV.cjs} +53 -36
  41. package/dist/{chunk-HHC7BUCK.js → chunk-STTUFUDC.js} +114 -16
  42. package/dist/{chunk-YCRMTXOE.js → chunk-TOUYQ4N5.js} +30 -13
  43. package/dist/{chunk-KLYFNMKS.cjs → chunk-VLL4THTG.cjs} +2727 -736
  44. package/dist/{chunk-7HXLHLLQ.cjs → chunk-WYW5UOBE.cjs} +136 -38
  45. package/dist/cli/index.js +2240 -572
  46. package/dist/{config-Y6JwVGwX.d.cts → config-BFAZrfjQ.d.cts} +2 -0
  47. package/dist/{config-Y6JwVGwX.d.ts → config-BFAZrfjQ.d.ts} +2 -0
  48. package/dist/config.cjs +2 -2
  49. package/dist/config.d.cts +1 -1
  50. package/dist/config.d.ts +1 -1
  51. package/dist/config.js +1 -1
  52. package/dist/{index-COVHErnx.d.cts → index-Bo4S_VVM.d.cts} +1 -1
  53. package/dist/{index-0O1WSfVP.d.ts → index-CKdYVt_L.d.ts} +1 -1
  54. package/dist/index.cjs +186 -47
  55. package/dist/index.d.cts +6 -6
  56. package/dist/index.d.ts +6 -6
  57. package/dist/index.js +174 -35
  58. package/dist/plugins/unplugin.cjs +4 -4
  59. package/dist/plugins/unplugin.js +3 -3
  60. package/dist/{types-CMtZnV8C.d.ts → types-BZqvBhBI.d.ts} +4 -2
  61. package/dist/{types-D93PuOOl.d.cts → types-E4ugA4Oz.d.cts} +4 -2
  62. package/package.json +1 -1
  63. package/dist/chunk-3LWXEJU6.cjs +0 -1054
  64. package/dist/chunk-ADKRENAP.js +0 -1054
@@ -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 _chunk7HXLHLLQcjs = require('./chunk-7HXLHLLQ.cjs');
4
+ var _chunkWYW5UOBEcjs = require('./chunk-WYW5UOBE.cjs');
5
5
 
6
6
 
7
- var _chunk3LWXEJU6cjs = require('./chunk-3LWXEJU6.cjs');
7
+ var _chunkAD6UFBPAcjs = require('./chunk-AD6UFBPA.cjs');
8
8
 
9
9
 
10
- var _chunkKLYFNMKScjs = require('./chunk-KLYFNMKS.cjs');
10
+
11
+ var _chunkVLL4THTGcjs = require('./chunk-VLL4THTG.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 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;
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 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);
80
115
  const staticDir = _path2.default.join(distDir, "static");
81
- 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) && (_chunkAD6UFBPAcjs.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 ? _chunkKLYFNMKScjs.computeFnv1aHash.call(void 0, context.buildId, 1597463007) : 1597463007;
103
- const summary = await _chunk7HXLHLLQcjs.protectProject.call(void 0, {
138
+ const deterministicSeed = typeof options.seed === "number" ? options.seed : context.buildId ? _chunkVLL4THTGcjs.computeFnv1aHash.call(void 0, context.buildId, 1597463007) : 1597463007;
139
+ const summary = await _chunkWYW5UOBEcjs.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', _2 => _2.outputs, 'optionalAccess', _3 => _3.staticFiles])) {
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 = _chunk3LWXEJU6cjs.safeDecodeURIComponent.call(void 0, rawFilePath).replace(/\\/g, "/").replace(/^\/?(?:_next\/|\.next\/)/, "");
154
+ const relClean = _chunkVLL4THTGcjs.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 (e2) {
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 (e3) {
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 (e4) {
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', _4 => _4.upstreamAdapterPath])) {
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 = _chunk7HXLHLLQcjs.serializeNextOptions.call(void 0, options);
235
+ const serialized = _chunkWYW5UOBEcjs.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
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  protectProject,
3
3
  serializeNextOptions
4
- } from "./chunk-HHC7BUCK.js";
4
+ } from "./chunk-STTUFUDC.js";
5
5
  import {
6
- safeDecodeURIComponent
7
- } from "./chunk-ADKRENAP.js";
6
+ hasJsBundleFiles
7
+ } from "./chunk-32GLSJAW.js";
8
8
  import {
9
- computeFnv1aHash
10
- } from "./chunk-4FNZNIBW.js";
9
+ computeFnv1aHash,
10
+ safeDecodeURIComponent
11
+ } from "./chunk-6KLUNEKE.js";
11
12
  import {
12
13
  UnpeekError,
13
14
  __dirname,
@@ -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 = options.profile ?? options.config?.profile ?? "recommended";
46
+ const isAggressive = 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 path.resolve(candidate) === path.resolve(selfPath);
60
+ } catch {
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 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;
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 = options.cwd ?? process.cwd();
79
- const distDir = path.resolve(cwd, context.distDir || ".next");
113
+ const configuredDistDir = context.distDir || (typeof context.config?.distDir === "string" ? context.config.distDir : void 0) || ".next";
114
+ const distDir = path.resolve(cwd, configuredDistDir);
80
115
  const staticDir = path.join(distDir, "static");
81
- const targetDir = fs.existsSync(staticDir) ? staticDir : distDir;
116
+ const vercelStaticDir = path.join(cwd, ".vercel", "output", "static", "_next", "static");
117
+ const targetDir = fs.existsSync(staticDir) && (hasJsBundleFiles(staticDir) || !fs.existsSync(vercelStaticDir)) ? staticDir : fs.existsSync(vercelStaticDir) ? vercelStaticDir : fs.existsSync(staticDir) ? staticDir : distDir;
82
118
  const phase = context.phase ?? recordedPhase;
83
119
  if (isNonProductionPhase(phase)) {
84
120
  await delegateToUpstreamOnBuildComplete(upstreamPath, context);
@@ -124,6 +160,11 @@ function createUnpeekNextAdapter(options = {}) {
124
160
  const fromStatic = path.resolve(distDir, "static", staticClean);
125
161
  if (fs.existsSync(fromStatic)) {
126
162
  absPath = fromStatic;
163
+ } else {
164
+ const fromVercelStatic = path.resolve(vercelStaticDir, staticClean);
165
+ if (fs.existsSync(fromVercelStatic)) {
166
+ absPath = fromVercelStatic;
167
+ }
127
168
  }
128
169
  }
129
170
  }
@@ -182,11 +223,12 @@ function getUnpeekAdapterPath() {
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 (options?.upstreamAdapterPath) {
231
+ if (options?.upstreamAdapterPath && !isSameAdapterPath(options.upstreamAdapterPath, adapterPath)) {
190
232
  process.env.UNPEEK_UPSTREAM_ADAPTER_PATH = options.upstreamAdapterPath;
191
233
  }
192
234
  if (options) {
@@ -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
@@ -4,16 +4,17 @@
4
4
 
5
5
 
6
6
 
7
+ var _chunkAD6UFBPAcjs = require('./chunk-AD6UFBPA.cjs');
7
8
 
8
9
 
9
10
 
10
- var _chunk3LWXEJU6cjs = require('./chunk-3LWXEJU6.cjs');
11
11
 
12
12
 
13
13
 
14
14
 
15
15
 
16
- var _chunkKLYFNMKScjs = require('./chunk-KLYFNMKS.cjs');
16
+
17
+ var _chunkVLL4THTGcjs = require('./chunk-VLL4THTG.cjs');
17
18
 
18
19
  // src/plugins/unplugin.ts
19
20
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
@@ -33,6 +34,17 @@ function isExcludedClientAsset(fileName, config) {
33
34
  if (_optionalChain([config, 'optionalAccess', _ => _.target]) !== "worker" && SW_OR_WORKBOX_PATTERN.test(norm)) {
34
35
  return true;
35
36
  }
37
+ const cleanRel = norm.replace(/^\/+/, "");
38
+ if (_optionalChain([config, 'optionalAccess', _2 => _2.filter, 'optionalAccess', _3 => _3.include]) && config.filter.include.length > 0) {
39
+ if (!config.filter.include.some((pattern) => _chunkAD6UFBPAcjs.matchesGlobPattern.call(void 0, cleanRel, pattern))) {
40
+ return true;
41
+ }
42
+ }
43
+ if (_optionalChain([config, 'optionalAccess', _4 => _4.filter, 'optionalAccess', _5 => _5.exclude]) && config.filter.exclude.length > 0) {
44
+ if (config.filter.exclude.some((pattern) => _chunkAD6UFBPAcjs.matchesGlobPattern.call(void 0, cleanRel, pattern))) {
45
+ return true;
46
+ }
47
+ }
36
48
  return false;
37
49
  }
38
50
  function createWebpackRawSource(sources, content) {
@@ -52,14 +64,14 @@ function createWebpackRawSource(sources, content) {
52
64
  }
53
65
  var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
54
66
  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));
67
+ const baseSeed = typeof options.seed === "number" && Number.isFinite(options.seed) ? options.seed : typeof _optionalChain([config, 'optionalAccess', _6 => _6.seed]) === "number" && Number.isFinite(config.seed) ? config.seed : Math.floor(Math.random() * 2147483647) || 322420463;
68
+ const deterrentMode = _nullishCoalesce(_nullishCoalesce(options.deterrentMode, () => ( _optionalChain([config, 'optionalAccess', _7 => _7.shield, 'optionalAccess', _8 => _8.deterrentMode]))), () => ( "passive"));
69
+ const detectHeadless = _nullishCoalesce(_nullishCoalesce(options.detectHeadless, () => ( _optionalChain([config, 'optionalAccess', _9 => _9.shield, 'optionalAccess', _10 => _10.detectHeadless]))), () => ( false));
58
70
  const injectRuntimeShield = _nullishCoalesce(options.injectRuntimeShield, () => ( true));
59
- const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'optionalAccess', _6 => _6.vault, 'optionalAccess', _7 => _7.minStringLength]))), () => ( 4));
71
+ const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([config, 'optionalAccess', _11 => _11.vault, 'optionalAccess', _12 => _12.minStringLength]))), () => ( 4));
60
72
  const aggressive = _nullishCoalesce(options.aggressive, () => ( false));
61
- const masterSym = _chunkKLYFNMKScjs.deriveWindowKeySymbol.call(void 0, baseSeed);
62
- const masterShield = injectRuntimeShield ? _chunkKLYFNMKScjs.generateRuntimeShield.call(void 0, {
73
+ const masterSym = _chunkVLL4THTGcjs.deriveWindowKeySymbol.call(void 0, baseSeed);
74
+ const masterShield = injectRuntimeShield ? _chunkVLL4THTGcjs.generateRuntimeShield.call(void 0, {
63
75
  seed: baseSeed,
64
76
  deterrentMode,
65
77
  detectHeadless,
@@ -70,14 +82,15 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
70
82
  if (!isSupportedJsAsset(normalizedFileName) || isExcludedClientAsset(normalizedFileName, config)) {
71
83
  return null;
72
84
  }
73
- const fileDebugId = _chunk3LWXEJU6cjs.extractDebugId.call(void 0, rawCode);
74
- const shouldStripComments = _optionalChain([config, 'optionalAccess', _8 => _8.sourcemaps, 'optionalAccess', _9 => _9.stripComments]) !== false;
85
+ const fileDebugId = _chunkAD6UFBPAcjs.extractDebugId.call(void 0, rawCode);
86
+ const shouldStripComments = _optionalChain([config, 'optionalAccess', _13 => _13.sourcemaps, 'optionalAccess', _14 => _14.stripComments]) !== false;
75
87
  let codeToTransform = rawCode;
76
88
  if (shouldStripComments && rawCode.includes("sourceMappingURL=")) {
77
- codeToTransform = _chunk3LWXEJU6cjs.stripSourceMapComments.call(void 0, rawCode).code;
89
+ codeToTransform = _chunkAD6UFBPAcjs.stripSourceMapComments.call(void 0, rawCode).code;
78
90
  }
79
91
  const shouldInjectShield = injectRuntimeShield && isEntry;
80
- const chunkSeed = _chunkKLYFNMKScjs.computeFnv1aHash.call(void 0, fileName, baseSeed);
92
+ const shouldGenerateMap = requestMap || Boolean(inputMap);
93
+ const chunkSeed = _chunkVLL4THTGcjs.computeFnv1aHash.call(void 0, fileName, baseSeed);
81
94
  const transformOptions = {
82
95
  seed: chunkSeed,
83
96
  minStringLength,
@@ -86,43 +99,46 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
86
99
  skipShieldPreamble: true,
87
100
  shieldCoupled: injectRuntimeShield,
88
101
  windowKeySymbol: masterSym,
89
- expectedDelta: _optionalChain([masterShield, 'optionalAccess', _10 => _10.expectedDelta]),
102
+ expectedDelta: _optionalChain([masterShield, 'optionalAccess', _15 => _15.expectedDelta]),
103
+ expectedStateHash: _optionalChain([masterShield, 'optionalAccess', _16 => _16.expectedStateHash]),
104
+ originalSourceMap: inputMap,
90
105
  deterrentMode,
91
106
  detectHeadless,
92
107
  aggressive,
93
- config
108
+ config,
109
+ generateMap: shouldGenerateMap,
110
+ rootDir: process.cwd()
94
111
  };
95
- transformOptions.generateMap = requestMap || Boolean(inputMap);
96
- transformOptions.rootDir = process.cwd();
97
- const result = _chunkKLYFNMKScjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
112
+ const result = _chunkVLL4THTGcjs.transformJavaScript.call(void 0, codeToTransform, transformOptions);
98
113
  let finalCode = result.code;
99
114
  let preambleLineOffset = 0;
100
115
  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)) {
116
+ if (shouldInjectShield && _optionalChain([masterShield, 'optionalAccess', _17 => _17.preambleCode]) && !finalCode.includes("(function _u$") && (!integrityCheckFnName || !finalCode.includes(integrityCheckFnName)) && !finalCode.startsWith(masterShield.preambleCode)) {
102
117
  const prefix = `${masterShield.preambleCode}
103
118
  `;
104
119
  preambleLineOffset = (_nullishCoalesce(prefix.match(/\n/g), () => ( []))).length;
105
120
  finalCode = `${prefix}${finalCode}`;
106
121
  }
107
122
  const rawTransformMap = result.sourceMap;
108
- const shiftedTransformMap = rawTransformMap ? _chunk3LWXEJU6cjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
123
+ const shiftedTransformMap = rawTransformMap ? _chunkVLL4THTGcjs.shiftSourceMapLines.call(void 0, rawTransformMap, preambleLineOffset) : void 0;
109
124
  let composedMap = null;
110
125
  if (shiftedTransformMap && inputMap) {
111
- composedMap = _chunk3LWXEJU6cjs.chainSourceMaps.call(void 0, shiftedTransformMap, inputMap);
126
+ composedMap = _chunkVLL4THTGcjs.chainSourceMaps.call(void 0, shiftedTransformMap, inputMap);
112
127
  } else if (shiftedTransformMap) {
113
128
  composedMap = shiftedTransformMap;
114
129
  } else if (inputMap) {
115
- composedMap = _chunk3LWXEJU6cjs.flattenSourceMapSections.call(void 0, inputMap);
130
+ composedMap = _chunkVLL4THTGcjs.flattenSourceMapSections.call(void 0, inputMap);
116
131
  }
117
- const inputMapDebugId = _nullishCoalesce(_optionalChain([inputMap, 'optionalAccess', _12 => _12.debugId]), () => ( _optionalChain([inputMap, 'optionalAccess', _13 => _13.debug_id])));
132
+ const inputMapDebugId = _nullishCoalesce(_optionalChain([inputMap, 'optionalAccess', _18 => _18.debugId]), () => ( _optionalChain([inputMap, 'optionalAccess', _19 => _19.debug_id])));
118
133
  const hadDebugId = Boolean(fileDebugId || inputMapDebugId || result.debugId);
119
- if (hadDebugId) {
120
- const codeWithoutDebugId = _chunk3LWXEJU6cjs.stripDebugIdComments.call(void 0, finalCode);
121
- const mintedDebugId = _chunk3LWXEJU6cjs.computeDeterministicDebugId.call(void 0,
134
+ const shouldMintDebugId = hadDebugId || shouldGenerateMap && !result.skippedReason && Boolean(composedMap || inputMap);
135
+ if (shouldMintDebugId) {
136
+ const codeWithoutDebugId = _chunkAD6UFBPAcjs.stripDebugIdComments.call(void 0, finalCode);
137
+ const mintedDebugId = _chunkVLL4THTGcjs.computeDeterministicDebugId.call(void 0,
122
138
  codeWithoutDebugId,
123
- _nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _14 => _14.mappings]), () => ( ""))
139
+ _nullishCoalesce(_optionalChain([composedMap, 'optionalAccess', _20 => _20.mappings]), () => ( ""))
124
140
  );
125
- finalCode = _chunk3LWXEJU6cjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
141
+ finalCode = _chunkAD6UFBPAcjs.replaceOrAppendDebugId.call(void 0, codeWithoutDebugId, mintedDebugId);
126
142
  if (composedMap) {
127
143
  composedMap.debugId = mintedDebugId;
128
144
  delete composedMap.debug_id;
@@ -158,7 +174,7 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
158
174
  };
159
175
  const attachWebpackLikeProcessAssets = (compiler, framework) => {
160
176
  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));
177
+ const stage = _nullishCoalesce((framework === "rspack" ? _optionalChain([compiler, 'access', _21 => _21.rspack, 'optionalAccess', _22 => _22.Compilation, 'optionalAccess', _23 => _23.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE]) : _optionalChain([compiler, 'access', _24 => _24.webpack, 'optionalAccess', _25 => _25.Compilation, 'optionalAccess', _26 => _26.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE])), () => ( 700));
162
178
  compilation.hooks.processAssets.tap(
163
179
  { name: "unpeek", stage },
164
180
  (assets) => {
@@ -182,14 +198,14 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
182
198
  }
183
199
  }
184
200
  }
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])));
201
+ const sources = _nullishCoalesce(_nullishCoalesce((framework === "rspack" ? _optionalChain([compiler, 'access', _27 => _27.rspack, 'optionalAccess', _28 => _28.sources]) : _optionalChain([compiler, 'access', _29 => _29.webpack, 'optionalAccess', _30 => _30.sources])), () => ( _optionalChain([compiler, 'access', _31 => _31.webpack, 'optionalAccess', _32 => _32.sources]))), () => ( _optionalChain([compiler, 'access', _33 => _33.rspack, 'optionalAccess', _34 => _34.sources])));
186
202
  for (const assetName of Object.keys(assets)) {
187
203
  const normalizedName = assetName.replace(/\\/g, "/").split("?")[0];
188
204
  if (!isSupportedJsAsset(normalizedName) || isExcludedClientAsset(normalizedName, config)) {
189
205
  continue;
190
206
  }
191
207
  const existingAsset = typeof compilation.getAsset === "function" ? compilation.getAsset(assetName) : { source: assets[assetName] };
192
- const sourceObj = _nullishCoalesce(_optionalChain([existingAsset, 'optionalAccess', _29 => _29.source]), () => ( assets[assetName]));
208
+ const sourceObj = _nullishCoalesce(_optionalChain([existingAsset, 'optionalAccess', _35 => _35.source]), () => ( assets[assetName]));
193
209
  if (!sourceObj) continue;
194
210
  const rawContent = typeof sourceObj.source === "function" ? sourceObj.source() : sourceObj;
195
211
  const code = Buffer.isBuffer(rawContent) ? rawContent.toString("utf8") : String(rawContent);
@@ -247,10 +263,10 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
247
263
  apply: "build",
248
264
  renderChunk: void 0,
249
265
  config(userConfig) {
250
- if (_optionalChain([config, 'optionalAccess', _30 => _30.target]) === "worker") {
266
+ if (_optionalChain([config, 'optionalAccess', _36 => _36.target]) === "worker") {
251
267
  return void 0;
252
268
  }
253
- const existingWorkerPlugins = _optionalChain([userConfig, 'optionalAccess', _31 => _31.worker, 'optionalAccess', _32 => _32.plugins]);
269
+ const existingWorkerPlugins = _optionalChain([userConfig, 'optionalAccess', _37 => _37.worker, 'optionalAccess', _38 => _38.plugins]);
254
270
  return {
255
271
  worker: {
256
272
  plugins: () => {
@@ -318,7 +334,7 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
318
334
  build.onEnd(async (result) => {
319
335
  const workDir = _nullishCoalesce(build.initialOptions.absWorkingDir, () => ( process.cwd()));
320
336
  const entryOutputs = /* @__PURE__ */ new Set();
321
- if (_optionalChain([result, 'access', _33 => _33.metafile, 'optionalAccess', _34 => _34.outputs])) {
337
+ if (_optionalChain([result, 'access', _39 => _39.metafile, 'optionalAccess', _40 => _40.outputs])) {
322
338
  for (const [outKey, meta] of Object.entries(result.metafile.outputs)) {
323
339
  if (meta && meta.entryPoint) {
324
340
  entryOutputs.add(_path2.default.resolve(workDir, outKey));
@@ -336,7 +352,9 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
336
352
  const jsOutCount = result.outputFiles.filter((f) => isSupportedJsAsset(f.path)).length;
337
353
  for (const outFile of result.outputFiles) {
338
354
  const normPath = outFile.path.replace(/\\/g, "/");
339
- if (!isSupportedJsAsset(normPath) || isExcludedClientAsset(normPath, config)) {
355
+ const relFromWork = _path2.default.relative(workDir, outFile.path).replace(/\\/g, "/");
356
+ const filterPath = relFromWork && !relFromWork.startsWith("..") && !_path2.default.isAbsolute(relFromWork) ? relFromWork : normPath;
357
+ if (!isSupportedJsAsset(normPath) || isExcludedClientAsset(filterPath, config)) {
340
358
  continue;
341
359
  }
342
360
  const mapFile = mapFilesByPath.get(`${outFile.path}.map`);
@@ -347,7 +365,6 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
347
365
  } catch (e4) {
348
366
  }
349
367
  }
350
- const relFromWork = _path2.default.relative(workDir, outFile.path).replace(/\\/g, "/");
351
368
  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
369
  const res = transformChunk(
353
370
  outFile.text,
@@ -365,7 +382,7 @@ var unpeekPlugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
365
382
  return;
366
383
  }
367
384
  const diskOutputs = /* @__PURE__ */ new Set();
368
- if (_optionalChain([result, 'access', _35 => _35.metafile, 'optionalAccess', _36 => _36.outputs])) {
385
+ if (_optionalChain([result, 'access', _41 => _41.metafile, 'optionalAccess', _42 => _42.outputs])) {
369
386
  for (const outKey of Object.keys(result.metafile.outputs)) {
370
387
  const abs = _path2.default.resolve(workDir, outKey);
371
388
  if (isSupportedJsAsset(abs)) {