rune-grab 0.1.11 → 0.1.13

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.
@@ -272,6 +272,9 @@ function isSourceFile(filePath) {
272
272
  if (!filePath) return false;
273
273
  if (isLibraryFile(filePath)) return false;
274
274
  if (filePath.startsWith("webpack-internal:///node_modules/")) return false;
275
+ if (filePath.includes("_next/static/")) return false;
276
+ if (filePath.includes(".vite/deps/")) return false;
277
+ if (/^webpack[\w-]*\.js$/.test(filePath) || /[\\/]webpack[\w-]*\.js$/.test(filePath)) return false;
275
278
  return true;
276
279
  }
277
280
  var STYLE_PROPS = [
@@ -1009,6 +1012,19 @@ function isUsefulName(name, filePath, customSkip) {
1009
1012
  if (filePath && !isSourceFile(filePath)) return false;
1010
1013
  return true;
1011
1014
  }
1015
+ function isCleanComponentName(name, customSkip) {
1016
+ if (!name || name.length <= 1) return false;
1017
+ if (customSkip?.has(name)) return false;
1018
+ if (name[0] !== name[0].toUpperCase()) return false;
1019
+ for (const pfx of SKIP_PREFIXES) {
1020
+ if (name.startsWith(pfx)) return false;
1021
+ }
1022
+ if (/^[A-Z][a-zA-Z]+\d+$/.test(name)) return false;
1023
+ return true;
1024
+ }
1025
+ function isInfraName(name) {
1026
+ return /(?:Provider|Context|Consumer|Boundary|Wrapper|Root|Layout|Suspense)$/i.test(name);
1027
+ }
1012
1028
  function cleanFilePath(raw) {
1013
1029
  return raw.replace(/^https?:\/\/[^/]+\//, "").replace(/^rsc:\/\/[^/]+\/[^/]+\//, "").replace(/^webpack-internal:\/\/\//, "").replace(/^\([\w-]+\)\//, "").replace(/\?.*$/, "").replace(/^\/app\//, "").replace(/^\.\//, "");
1014
1030
  }
@@ -1093,13 +1109,24 @@ function getReactComponentInfo(el, customSkip) {
1093
1109
  if (!fiber) return null;
1094
1110
  const elementSrc = getSourceFromFiber(fiber);
1095
1111
  let isFirst = true;
1112
+ let fallback = null;
1096
1113
  let cur = fiber;
1097
1114
  while (cur) {
1115
+ let name = null;
1116
+ let src = null;
1098
1117
  if (cur.type && typeof cur.type === "function") {
1099
- const name = cur.type.displayName || cur.type.name;
1100
- const src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1118
+ name = cur.type.displayName || cur.type.name;
1119
+ src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1120
+ } else if (cur.type?.$$typeof) {
1121
+ const inner = cur.type.render || cur.type.type;
1122
+ name = cur.type.displayName || (inner && typeof inner === "function" ? inner.displayName || inner.name : null) || null;
1123
+ if (name) {
1124
+ src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1125
+ }
1126
+ }
1127
+ if (name) {
1101
1128
  const filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1102
- if (name && filePath && isUsefulName(name, filePath, customSkip)) {
1129
+ if (filePath && isUsefulName(name, filePath, customSkip)) {
1103
1130
  const info = {
1104
1131
  name,
1105
1132
  filePath,
@@ -1109,29 +1136,21 @@ function getReactComponentInfo(el, customSkip) {
1109
1136
  if (src) storePendingResolution(info, src);
1110
1137
  return info;
1111
1138
  }
1112
- isFirst = false;
1113
- }
1114
- if (cur.type?.$$typeof) {
1115
- const inner = cur.type.render || cur.type.type;
1116
- if (inner && typeof inner === "function") {
1117
- const name = inner.displayName || inner.name;
1118
- const src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1119
- const filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1120
- if (name && filePath && isUsefulName(name, filePath, customSkip)) {
1121
- const info = {
1122
- name,
1123
- filePath,
1124
- line: src?.lineNumber ?? null,
1125
- column: src?.columnNumber ?? null
1126
- };
1127
- if (src) storePendingResolution(info, src);
1128
- return info;
1129
- }
1130
- isFirst = false;
1139
+ if (!fallback && isCleanComponentName(name, customSkip) && !isInfraName(name)) {
1140
+ const validPath = filePath && isSourceFile(filePath) ? filePath : null;
1141
+ fallback = {
1142
+ info: { name, filePath: validPath, line: validPath ? src?.lineNumber ?? null : null, column: validPath ? src?.columnNumber ?? null : null },
1143
+ src: src || null
1144
+ };
1131
1145
  }
1146
+ isFirst = false;
1132
1147
  }
1133
1148
  cur = cur.return;
1134
1149
  }
1150
+ if (fallback) {
1151
+ if (fallback.src) storePendingResolution(fallback.info, fallback.src);
1152
+ return fallback.info;
1153
+ }
1135
1154
  return null;
1136
1155
  }
1137
1156
  function getReactComponentStack(el, maxDepth = 6, customSkip) {
@@ -1139,7 +1158,9 @@ function getReactComponentStack(el, maxDepth = 6, customSkip) {
1139
1158
  if (!fiber) return [];
1140
1159
  const elementSrc = getSourceFromFiber(fiber);
1141
1160
  const stack = [];
1161
+ const fallbackStack = [];
1142
1162
  const seen = /* @__PURE__ */ new Set();
1163
+ const fallbackSeen = /* @__PURE__ */ new Set();
1143
1164
  let cur = fiber;
1144
1165
  let isFirst = true;
1145
1166
  while (cur && stack.length < maxDepth) {
@@ -1150,22 +1171,30 @@ function getReactComponentStack(el, maxDepth = 6, customSkip) {
1150
1171
  src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1151
1172
  } else if (cur.type?.$$typeof) {
1152
1173
  const inner = cur.type.render || cur.type.type;
1153
- if (inner && typeof inner === "function") {
1154
- name = inner.displayName || inner.name;
1174
+ name = cur.type.displayName || (inner && typeof inner === "function" ? inner.displayName || inner.name : null) || null;
1175
+ if (name) {
1155
1176
  src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1156
1177
  }
1157
1178
  }
1158
- let filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1159
- if (name && filePath && isUsefulName(name, filePath, customSkip) && !seen.has(name)) {
1160
- seen.add(name);
1161
- const frame = { name, filePath, line: src?.lineNumber ?? null };
1162
- if (src) storePendingResolution(frame, src);
1163
- stack.push(frame);
1164
- isFirst = false;
1179
+ if (name) {
1180
+ let filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1181
+ if (filePath && isUsefulName(name, filePath, customSkip) && !seen.has(name)) {
1182
+ seen.add(name);
1183
+ const frame = { name, filePath, line: src?.lineNumber ?? null };
1184
+ if (src) storePendingResolution(frame, src);
1185
+ stack.push(frame);
1186
+ isFirst = false;
1187
+ } else if (fallbackStack.length < maxDepth && isCleanComponentName(name, customSkip) && !isInfraName(name) && !fallbackSeen.has(name)) {
1188
+ fallbackSeen.add(name);
1189
+ const validPath = filePath && isSourceFile(filePath) ? filePath : null;
1190
+ const frame = { name, filePath: validPath, line: validPath ? src?.lineNumber ?? null : null };
1191
+ if (src) storePendingResolution(frame, src);
1192
+ fallbackStack.push(frame);
1193
+ }
1165
1194
  }
1166
1195
  cur = cur.return;
1167
1196
  }
1168
- return stack;
1197
+ return stack.length > 0 ? stack : fallbackStack;
1169
1198
  }
1170
1199
  function getVueComponentInfo(el) {
1171
1200
  let cur = el;