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.
package/dist/rune-grab.js CHANGED
@@ -225,6 +225,9 @@ function isSourceFile(filePath) {
225
225
  if (!filePath) return false;
226
226
  if (isLibraryFile(filePath)) return false;
227
227
  if (filePath.startsWith("webpack-internal:///node_modules/")) return false;
228
+ if (filePath.includes("_next/static/")) return false;
229
+ if (filePath.includes(".vite/deps/")) return false;
230
+ if (/^webpack[\w-]*\.js$/.test(filePath) || /[\\/]webpack[\w-]*\.js$/.test(filePath)) return false;
228
231
  return true;
229
232
  }
230
233
  var STYLE_PROPS = [
@@ -962,6 +965,19 @@ function isUsefulName(name, filePath, customSkip) {
962
965
  if (filePath && !isSourceFile(filePath)) return false;
963
966
  return true;
964
967
  }
968
+ function isCleanComponentName(name, customSkip) {
969
+ if (!name || name.length <= 1) return false;
970
+ if (customSkip?.has(name)) return false;
971
+ if (name[0] !== name[0].toUpperCase()) return false;
972
+ for (const pfx of SKIP_PREFIXES) {
973
+ if (name.startsWith(pfx)) return false;
974
+ }
975
+ if (/^[A-Z][a-zA-Z]+\d+$/.test(name)) return false;
976
+ return true;
977
+ }
978
+ function isInfraName(name) {
979
+ return /(?:Provider|Context|Consumer|Boundary|Wrapper|Root|Layout|Suspense)$/i.test(name);
980
+ }
965
981
  function cleanFilePath(raw) {
966
982
  return raw.replace(/^https?:\/\/[^/]+\//, "").replace(/^rsc:\/\/[^/]+\/[^/]+\//, "").replace(/^webpack-internal:\/\/\//, "").replace(/^\([\w-]+\)\//, "").replace(/\?.*$/, "").replace(/^\/app\//, "").replace(/^\.\//, "");
967
983
  }
@@ -1046,13 +1062,24 @@ function getReactComponentInfo(el, customSkip) {
1046
1062
  if (!fiber) return null;
1047
1063
  const elementSrc = getSourceFromFiber(fiber);
1048
1064
  let isFirst = true;
1065
+ let fallback = null;
1049
1066
  let cur = fiber;
1050
1067
  while (cur) {
1068
+ let name = null;
1069
+ let src = null;
1051
1070
  if (cur.type && typeof cur.type === "function") {
1052
- const name = cur.type.displayName || cur.type.name;
1053
- const src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1071
+ name = cur.type.displayName || cur.type.name;
1072
+ src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1073
+ } else if (cur.type?.$$typeof) {
1074
+ const inner = cur.type.render || cur.type.type;
1075
+ name = cur.type.displayName || (inner && typeof inner === "function" ? inner.displayName || inner.name : null) || null;
1076
+ if (name) {
1077
+ src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1078
+ }
1079
+ }
1080
+ if (name) {
1054
1081
  const filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1055
- if (name && filePath && isUsefulName(name, filePath, customSkip)) {
1082
+ if (filePath && isUsefulName(name, filePath, customSkip)) {
1056
1083
  const info = {
1057
1084
  name,
1058
1085
  filePath,
@@ -1062,29 +1089,21 @@ function getReactComponentInfo(el, customSkip) {
1062
1089
  if (src) storePendingResolution(info, src);
1063
1090
  return info;
1064
1091
  }
1065
- isFirst = false;
1066
- }
1067
- if (cur.type?.$$typeof) {
1068
- const inner = cur.type.render || cur.type.type;
1069
- if (inner && typeof inner === "function") {
1070
- const name = inner.displayName || inner.name;
1071
- const src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1072
- const filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1073
- if (name && filePath && isUsefulName(name, filePath, customSkip)) {
1074
- const info = {
1075
- name,
1076
- filePath,
1077
- line: src?.lineNumber ?? null,
1078
- column: src?.columnNumber ?? null
1079
- };
1080
- if (src) storePendingResolution(info, src);
1081
- return info;
1082
- }
1083
- isFirst = false;
1092
+ if (!fallback && isCleanComponentName(name, customSkip) && !isInfraName(name)) {
1093
+ const validPath = filePath && isSourceFile(filePath) ? filePath : null;
1094
+ fallback = {
1095
+ info: { name, filePath: validPath, line: validPath ? src?.lineNumber ?? null : null, column: validPath ? src?.columnNumber ?? null : null },
1096
+ src: src || null
1097
+ };
1084
1098
  }
1099
+ isFirst = false;
1085
1100
  }
1086
1101
  cur = cur.return;
1087
1102
  }
1103
+ if (fallback) {
1104
+ if (fallback.src) storePendingResolution(fallback.info, fallback.src);
1105
+ return fallback.info;
1106
+ }
1088
1107
  return null;
1089
1108
  }
1090
1109
  function getReactComponentStack(el, maxDepth = 6, customSkip) {
@@ -1092,7 +1111,9 @@ function getReactComponentStack(el, maxDepth = 6, customSkip) {
1092
1111
  if (!fiber) return [];
1093
1112
  const elementSrc = getSourceFromFiber(fiber);
1094
1113
  const stack = [];
1114
+ const fallbackStack = [];
1095
1115
  const seen = /* @__PURE__ */ new Set();
1116
+ const fallbackSeen = /* @__PURE__ */ new Set();
1096
1117
  let cur = fiber;
1097
1118
  let isFirst = true;
1098
1119
  while (cur && stack.length < maxDepth) {
@@ -1103,22 +1124,30 @@ function getReactComponentStack(el, maxDepth = 6, customSkip) {
1103
1124
  src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1104
1125
  } else if (cur.type?.$$typeof) {
1105
1126
  const inner = cur.type.render || cur.type.type;
1106
- if (inner && typeof inner === "function") {
1107
- name = inner.displayName || inner.name;
1127
+ name = cur.type.displayName || (inner && typeof inner === "function" ? inner.displayName || inner.name : null) || null;
1128
+ if (name) {
1108
1129
  src = isFirst && elementSrc ? elementSrc : getSourceFromFiber(cur);
1109
1130
  }
1110
1131
  }
1111
- let filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1112
- if (name && filePath && isUsefulName(name, filePath, customSkip) && !seen.has(name)) {
1113
- seen.add(name);
1114
- const frame = { name, filePath, line: src?.lineNumber ?? null };
1115
- if (src) storePendingResolution(frame, src);
1116
- stack.push(frame);
1117
- isFirst = false;
1132
+ if (name) {
1133
+ let filePath = src?.fileName ? cleanFilePath(src.fileName) : null;
1134
+ if (filePath && isUsefulName(name, filePath, customSkip) && !seen.has(name)) {
1135
+ seen.add(name);
1136
+ const frame = { name, filePath, line: src?.lineNumber ?? null };
1137
+ if (src) storePendingResolution(frame, src);
1138
+ stack.push(frame);
1139
+ isFirst = false;
1140
+ } else if (fallbackStack.length < maxDepth && isCleanComponentName(name, customSkip) && !isInfraName(name) && !fallbackSeen.has(name)) {
1141
+ fallbackSeen.add(name);
1142
+ const validPath = filePath && isSourceFile(filePath) ? filePath : null;
1143
+ const frame = { name, filePath: validPath, line: validPath ? src?.lineNumber ?? null : null };
1144
+ if (src) storePendingResolution(frame, src);
1145
+ fallbackStack.push(frame);
1146
+ }
1118
1147
  }
1119
1148
  cur = cur.return;
1120
1149
  }
1121
- return stack;
1150
+ return stack.length > 0 ? stack : fallbackStack;
1122
1151
  }
1123
1152
  function getVueComponentInfo(el) {
1124
1153
  let cur = el;