made-refine 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/cli.cjs +176 -23
- package/dist/index.js +256 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -3
- package/dist/index.mjs.map +1 -1
- package/dist/utils.js +256 -3
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +256 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -8435,32 +8435,185 @@ function installPackage(cwd) {
|
|
|
8435
8435
|
console.log(import_picocolors.default.dim(` ${cmd}`));
|
|
8436
8436
|
}
|
|
8437
8437
|
}
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8446
|
-
|
|
8438
|
+
var BABEL_JSON_CONFIG_FILES = [".babelrc", ".babelrc.json", "babel.config.json"];
|
|
8439
|
+
var BABEL_JS_CONFIG_FILES = [
|
|
8440
|
+
".babelrc.js",
|
|
8441
|
+
".babelrc.cjs",
|
|
8442
|
+
".babelrc.mjs",
|
|
8443
|
+
"babel.config.js",
|
|
8444
|
+
"babel.config.cjs",
|
|
8445
|
+
"babel.config.mjs"
|
|
8446
|
+
];
|
|
8447
|
+
function findBabelConfigFile(cwd) {
|
|
8448
|
+
for (const file of BABEL_JSON_CONFIG_FILES) {
|
|
8449
|
+
const absolutePath = import_path2.default.join(cwd, file);
|
|
8450
|
+
if (import_fs2.default.existsSync(absolutePath)) {
|
|
8451
|
+
return {
|
|
8452
|
+
absolutePath,
|
|
8453
|
+
relativePath: file,
|
|
8454
|
+
kind: "json"
|
|
8455
|
+
};
|
|
8447
8456
|
}
|
|
8448
|
-
}
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8457
|
+
}
|
|
8458
|
+
for (const file of BABEL_JS_CONFIG_FILES) {
|
|
8459
|
+
const absolutePath = import_path2.default.join(cwd, file);
|
|
8460
|
+
if (import_fs2.default.existsSync(absolutePath)) {
|
|
8461
|
+
return {
|
|
8462
|
+
absolutePath,
|
|
8463
|
+
relativePath: file,
|
|
8464
|
+
kind: "js"
|
|
8465
|
+
};
|
|
8466
|
+
}
|
|
8467
|
+
}
|
|
8468
|
+
const packageJsonPath = import_path2.default.join(cwd, "package.json");
|
|
8469
|
+
if (import_fs2.default.existsSync(packageJsonPath)) {
|
|
8470
|
+
try {
|
|
8471
|
+
const packageJson = JSON.parse(import_fs2.default.readFileSync(packageJsonPath, "utf-8"));
|
|
8472
|
+
if (packageJson.babel !== void 0) {
|
|
8473
|
+
return {
|
|
8474
|
+
absolutePath: packageJsonPath,
|
|
8475
|
+
relativePath: "package.json#babel",
|
|
8476
|
+
kind: "package-json"
|
|
8477
|
+
};
|
|
8478
|
+
}
|
|
8479
|
+
} catch {
|
|
8480
|
+
}
|
|
8481
|
+
}
|
|
8482
|
+
return null;
|
|
8483
|
+
}
|
|
8484
|
+
function isMadeRefinePlugin(plugin) {
|
|
8485
|
+
if (typeof plugin === "string") {
|
|
8486
|
+
return plugin === "made-refine/babel";
|
|
8487
|
+
}
|
|
8488
|
+
if (Array.isArray(plugin) && typeof plugin[0] === "string") {
|
|
8489
|
+
return plugin[0] === "made-refine/babel";
|
|
8490
|
+
}
|
|
8491
|
+
return false;
|
|
8492
|
+
}
|
|
8493
|
+
function hasMadeRefinePlugin(plugins) {
|
|
8494
|
+
if (!Array.isArray(plugins)) return false;
|
|
8495
|
+
return plugins.some((plugin) => isMadeRefinePlugin(plugin));
|
|
8496
|
+
}
|
|
8497
|
+
function ensureMadeRefineInDevelopmentEnv(config) {
|
|
8498
|
+
if (hasMadeRefinePlugin(config.plugins)) {
|
|
8499
|
+
return "already-configured";
|
|
8500
|
+
}
|
|
8501
|
+
const existingEnv = config.env;
|
|
8502
|
+
if (existingEnv !== void 0 && (typeof existingEnv !== "object" || existingEnv === null || Array.isArray(existingEnv))) {
|
|
8503
|
+
return "unsupported-shape";
|
|
8504
|
+
}
|
|
8505
|
+
if (!config.env) {
|
|
8506
|
+
config.env = {};
|
|
8507
|
+
}
|
|
8508
|
+
const env = config.env;
|
|
8509
|
+
const existingDevelopment = env.development;
|
|
8510
|
+
if (existingDevelopment !== void 0 && (typeof existingDevelopment !== "object" || existingDevelopment === null || Array.isArray(existingDevelopment))) {
|
|
8511
|
+
return "unsupported-shape";
|
|
8512
|
+
}
|
|
8513
|
+
if (!env.development) {
|
|
8514
|
+
env.development = {};
|
|
8515
|
+
}
|
|
8516
|
+
const development = env.development;
|
|
8517
|
+
if (hasMadeRefinePlugin(development.plugins)) {
|
|
8518
|
+
return "already-configured";
|
|
8519
|
+
}
|
|
8520
|
+
if (development.plugins === void 0) {
|
|
8521
|
+
development.plugins = ["made-refine/babel"];
|
|
8522
|
+
return "updated";
|
|
8523
|
+
}
|
|
8524
|
+
if (!Array.isArray(development.plugins)) {
|
|
8525
|
+
return "unsupported-shape";
|
|
8526
|
+
}
|
|
8527
|
+
development.plugins = [...development.plugins, "made-refine/babel"];
|
|
8528
|
+
return "updated";
|
|
8529
|
+
}
|
|
8530
|
+
function printManualNextBabelInstructions() {
|
|
8531
|
+
console.log(
|
|
8532
|
+
import_picocolors.default.dim(
|
|
8533
|
+
" env: { development: { plugins: ['made-refine/babel'] } }\n (or add 'made-refine/babel' in your existing Babel plugin list)"
|
|
8534
|
+
)
|
|
8535
|
+
);
|
|
8536
|
+
}
|
|
8537
|
+
function configureNextBabel(cwd) {
|
|
8538
|
+
const configFile = findBabelConfigFile(cwd);
|
|
8539
|
+
if (!configFile) {
|
|
8540
|
+
console.log(
|
|
8541
|
+
import_picocolors.default.yellow(" \u26A0 No existing Babel config found \u2014 skipping Babel config to preserve SWC/Turbopack defaults.")
|
|
8460
8542
|
);
|
|
8461
|
-
console.log(import_picocolors.default.
|
|
8462
|
-
|
|
8543
|
+
console.log(import_picocolors.default.dim(" Source detection will use React fiber fallback (less precise than Babel attributes)."));
|
|
8544
|
+
return;
|
|
8545
|
+
}
|
|
8546
|
+
if (configFile.kind === "js") {
|
|
8547
|
+
console.log(import_picocolors.default.yellow(` \u26A0 Found ${configFile.relativePath} (JS Babel config) \u2014 verify/add plugin manually:`));
|
|
8548
|
+
printManualNextBabelInstructions();
|
|
8549
|
+
return;
|
|
8550
|
+
}
|
|
8551
|
+
if (configFile.kind === "package-json") {
|
|
8552
|
+
let packageJson;
|
|
8553
|
+
try {
|
|
8554
|
+
packageJson = JSON.parse(import_fs2.default.readFileSync(configFile.absolutePath, "utf-8"));
|
|
8555
|
+
} catch {
|
|
8556
|
+
console.log(import_picocolors.default.yellow(" \u26A0 Could not parse package.json \u2014 add plugin manually:"));
|
|
8557
|
+
printManualNextBabelInstructions();
|
|
8558
|
+
return;
|
|
8559
|
+
}
|
|
8560
|
+
if (typeof packageJson !== "object" || packageJson === null || Array.isArray(packageJson)) {
|
|
8561
|
+
console.log(import_picocolors.default.yellow(" \u26A0 package.json has unsupported shape \u2014 add plugin manually:"));
|
|
8562
|
+
printManualNextBabelInstructions();
|
|
8563
|
+
return;
|
|
8564
|
+
}
|
|
8565
|
+
const pkg = packageJson;
|
|
8566
|
+
if (typeof pkg.babel !== "object" || pkg.babel === null || Array.isArray(pkg.babel)) {
|
|
8567
|
+
console.log(import_picocolors.default.yellow(" \u26A0 package.json#babel has unsupported shape \u2014 add plugin manually:"));
|
|
8568
|
+
printManualNextBabelInstructions();
|
|
8569
|
+
return;
|
|
8570
|
+
}
|
|
8571
|
+
const result2 = ensureMadeRefineInDevelopmentEnv(pkg.babel);
|
|
8572
|
+
if (result2 === "already-configured") {
|
|
8573
|
+
console.log(import_picocolors.default.dim(" package.json#babel \u2014 already configured"));
|
|
8574
|
+
return;
|
|
8575
|
+
}
|
|
8576
|
+
if (result2 === "unsupported-shape") {
|
|
8577
|
+
console.log(import_picocolors.default.yellow(" \u26A0 package.json#babel has unsupported shape \u2014 add plugin manually:"));
|
|
8578
|
+
printManualNextBabelInstructions();
|
|
8579
|
+
return;
|
|
8580
|
+
}
|
|
8581
|
+
import_fs2.default.writeFileSync(configFile.absolutePath, `${JSON.stringify(pkg, null, 2)}
|
|
8582
|
+
`, "utf-8");
|
|
8583
|
+
console.log(import_picocolors.default.green(' \u2713 Updated package.json#babel (added "made-refine/babel" in development env)'));
|
|
8584
|
+
return;
|
|
8585
|
+
}
|
|
8586
|
+
const content = import_fs2.default.readFileSync(configFile.absolutePath, "utf-8");
|
|
8587
|
+
let parsed;
|
|
8588
|
+
try {
|
|
8589
|
+
parsed = JSON.parse(content);
|
|
8590
|
+
} catch {
|
|
8591
|
+
console.log(import_picocolors.default.yellow(` \u26A0 Could not parse ${configFile.relativePath} as JSON \u2014 add plugin manually:`));
|
|
8592
|
+
printManualNextBabelInstructions();
|
|
8593
|
+
return;
|
|
8594
|
+
}
|
|
8595
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
8596
|
+
console.log(import_picocolors.default.yellow(` \u26A0 ${configFile.relativePath} has unsupported shape \u2014 add plugin manually:`));
|
|
8597
|
+
printManualNextBabelInstructions();
|
|
8598
|
+
return;
|
|
8463
8599
|
}
|
|
8600
|
+
const result = ensureMadeRefineInDevelopmentEnv(parsed);
|
|
8601
|
+
if (result === "already-configured") {
|
|
8602
|
+
console.log(import_picocolors.default.dim(` ${configFile.relativePath} \u2014 already configured`));
|
|
8603
|
+
return;
|
|
8604
|
+
}
|
|
8605
|
+
if (result === "unsupported-shape") {
|
|
8606
|
+
console.log(import_picocolors.default.yellow(` \u26A0 ${configFile.relativePath} has unsupported shape \u2014 add plugin manually:`));
|
|
8607
|
+
printManualNextBabelInstructions();
|
|
8608
|
+
return;
|
|
8609
|
+
}
|
|
8610
|
+
import_fs2.default.writeFileSync(configFile.absolutePath, `${JSON.stringify(parsed, null, 2)}
|
|
8611
|
+
`, "utf-8");
|
|
8612
|
+
console.log(import_picocolors.default.green(` \u2713 Updated ${configFile.relativePath} (added "made-refine/babel" in development env)`));
|
|
8613
|
+
}
|
|
8614
|
+
async function setupNextJs(cwd) {
|
|
8615
|
+
console.log(import_picocolors.default.bold("\nConfiguring for Next.js...\n"));
|
|
8616
|
+
configureNextBabel(cwd);
|
|
8464
8617
|
const preloadSrc = import_path2.default.join(cwd, "node_modules/made-refine/dist/preload/preload.js");
|
|
8465
8618
|
const publicDir = import_path2.default.join(cwd, "public");
|
|
8466
8619
|
const preloadDest = import_path2.default.join(publicDir, "made-refine-preload.js");
|
package/dist/index.js
CHANGED
|
@@ -1397,6 +1397,253 @@ function getFiberForElement(element) {
|
|
|
1397
1397
|
if (!fiberKey) return null;
|
|
1398
1398
|
return element[fiberKey] || null;
|
|
1399
1399
|
}
|
|
1400
|
+
var STACK_SOURCE_FILE_EXTENSION_REGEX = /\.(jsx|tsx|ts|js)$/;
|
|
1401
|
+
var STACK_BUNDLED_FILE_PATTERN_REGEX = /(\.min|bundle|chunk|vendor|vendors|runtime|polyfill|polyfills)\.(js|mjs|cjs)$|(chunk|bundle|vendor|vendors|runtime|polyfill|polyfills|framework|app|main|index)[-_.][A-Za-z0-9_-]{4,}\.(js|mjs|cjs)$|[\da-f]{8,}\.(js|mjs|cjs)$|[-_.][\da-f]{20,}\.(js|mjs|cjs)$|\/dist\/|\/build\/|\/.next\/|\/out\/|\/node_modules\/|\.webpack\.|\.vite\.|\.turbopack\./i;
|
|
1402
|
+
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
|
|
1403
|
+
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/;
|
|
1404
|
+
var SERVER_FRAME_MARKER = "(at Server)";
|
|
1405
|
+
var STACK_INTERNAL_SCHEME_PREFIXES = [
|
|
1406
|
+
"rsc://",
|
|
1407
|
+
"about://React/",
|
|
1408
|
+
"React/Server/",
|
|
1409
|
+
"file:///",
|
|
1410
|
+
"webpack://",
|
|
1411
|
+
"webpack-internal://",
|
|
1412
|
+
"node:",
|
|
1413
|
+
"turbopack://",
|
|
1414
|
+
"/app-pages-browser/"
|
|
1415
|
+
];
|
|
1416
|
+
function formatOwnerDebugStack(stack) {
|
|
1417
|
+
if (!stack) return "";
|
|
1418
|
+
const lines = stack.split("\n");
|
|
1419
|
+
const filtered = [];
|
|
1420
|
+
for (const line of lines) {
|
|
1421
|
+
const trimmed = line.trim();
|
|
1422
|
+
if (!trimmed) continue;
|
|
1423
|
+
if (trimmed === "Error: react-stack-top-frame") continue;
|
|
1424
|
+
if (trimmed.includes("react_stack_bottom_frame") || trimmed.includes("react-stack-bottom-frame")) {
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
filtered.push(line);
|
|
1428
|
+
}
|
|
1429
|
+
if (filtered.length > 0 && filtered[0].includes("fakeJSXCallSite")) {
|
|
1430
|
+
filtered.shift();
|
|
1431
|
+
}
|
|
1432
|
+
return filtered.join("\n");
|
|
1433
|
+
}
|
|
1434
|
+
function extractStackLocation(urlLike) {
|
|
1435
|
+
if (!urlLike.includes(":")) return [urlLike, void 0, void 0];
|
|
1436
|
+
const isWrappedLocation = urlLike.startsWith("(") && /:\d+\)$/.test(urlLike);
|
|
1437
|
+
const sanitizedResult = isWrappedLocation ? urlLike.slice(1, -1) : urlLike;
|
|
1438
|
+
const parts = /(.+?)(?::(\d+))?(?::(\d+))?$/.exec(sanitizedResult);
|
|
1439
|
+
if (!parts) return [sanitizedResult, void 0, void 0];
|
|
1440
|
+
return [
|
|
1441
|
+
parts[1],
|
|
1442
|
+
parts[2] !== void 0 ? Number(parts[2]) : void 0,
|
|
1443
|
+
parts[3] !== void 0 ? Number(parts[3]) : void 0
|
|
1444
|
+
];
|
|
1445
|
+
}
|
|
1446
|
+
function parseV8StackLine(line) {
|
|
1447
|
+
let currentLine = line;
|
|
1448
|
+
if (currentLine.includes("(eval ")) {
|
|
1449
|
+
currentLine = currentLine.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
1450
|
+
}
|
|
1451
|
+
let sanitizedLine = currentLine.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
1452
|
+
const locationMatch = sanitizedLine.match(/ (\(.+\)$)/);
|
|
1453
|
+
if (locationMatch) {
|
|
1454
|
+
sanitizedLine = sanitizedLine.replace(locationMatch[0], "");
|
|
1455
|
+
}
|
|
1456
|
+
const [fileName, lineNumber, columnNumber] = extractStackLocation(
|
|
1457
|
+
locationMatch ? locationMatch[1] : sanitizedLine
|
|
1458
|
+
);
|
|
1459
|
+
const functionName = locationMatch && sanitizedLine ? sanitizedLine : void 0;
|
|
1460
|
+
if (fileName === "eval" || fileName === "<anonymous>") {
|
|
1461
|
+
return {
|
|
1462
|
+
functionName
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
return {
|
|
1466
|
+
functionName,
|
|
1467
|
+
fileName,
|
|
1468
|
+
lineNumber,
|
|
1469
|
+
columnNumber,
|
|
1470
|
+
source: currentLine,
|
|
1471
|
+
isServer: currentLine.includes(SERVER_FRAME_MARKER) || fileName.startsWith("rsc://")
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
function parseFFOrSafariStackLine(line) {
|
|
1475
|
+
let currentLine = line;
|
|
1476
|
+
if (currentLine.includes(" > eval")) {
|
|
1477
|
+
currentLine = currentLine.replace(
|
|
1478
|
+
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
|
|
1479
|
+
":$1"
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
const trimmed = currentLine.trim();
|
|
1483
|
+
if (!trimmed || SAFARI_NATIVE_CODE_REGEXP.test(trimmed)) {
|
|
1484
|
+
return null;
|
|
1485
|
+
}
|
|
1486
|
+
if (!trimmed.includes("@") && !trimmed.includes(":")) {
|
|
1487
|
+
return {
|
|
1488
|
+
functionName: trimmed,
|
|
1489
|
+
source: currentLine,
|
|
1490
|
+
isServer: trimmed.includes(SERVER_FRAME_MARKER)
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
const atIndex = trimmed.lastIndexOf("@");
|
|
1494
|
+
if (atIndex === -1) {
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
const maybeFunctionName = trimmed.slice(0, atIndex);
|
|
1498
|
+
const location = trimmed.slice(atIndex + 1);
|
|
1499
|
+
const [fileName, lineNumber, columnNumber] = extractStackLocation(location);
|
|
1500
|
+
return {
|
|
1501
|
+
functionName: maybeFunctionName || void 0,
|
|
1502
|
+
fileName,
|
|
1503
|
+
lineNumber,
|
|
1504
|
+
columnNumber,
|
|
1505
|
+
source: currentLine,
|
|
1506
|
+
isServer: currentLine.includes(SERVER_FRAME_MARKER) || fileName.startsWith("rsc://")
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
function parseInStackLine(line) {
|
|
1510
|
+
const functionName = line.replace(/^\s*in\s+/, "").replace(/\s*\(at .*\)$/, "").trim();
|
|
1511
|
+
if (!functionName) return null;
|
|
1512
|
+
return {
|
|
1513
|
+
functionName,
|
|
1514
|
+
source: line,
|
|
1515
|
+
isServer: line.includes(SERVER_FRAME_MARKER)
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
function parseDebugStack(stack) {
|
|
1519
|
+
const frames = [];
|
|
1520
|
+
for (const rawLine of stack.split("\n")) {
|
|
1521
|
+
if (FIREFOX_SAFARI_STACK_REGEXP.test(rawLine)) {
|
|
1522
|
+
const parsed = parseFFOrSafariStackLine(rawLine);
|
|
1523
|
+
if (parsed) frames.push(parsed);
|
|
1524
|
+
continue;
|
|
1525
|
+
}
|
|
1526
|
+
if (/^\s*at\s+/.test(rawLine)) {
|
|
1527
|
+
const parsed = parseV8StackLine(rawLine);
|
|
1528
|
+
if (parsed) frames.push(parsed);
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
if (/^\s*in\s+/.test(rawLine)) {
|
|
1532
|
+
const parsed = parseInStackLine(rawLine);
|
|
1533
|
+
if (parsed) frames.push(parsed);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
return frames;
|
|
1537
|
+
}
|
|
1538
|
+
function normalizeStackFileName(fileName) {
|
|
1539
|
+
if (!fileName) return "";
|
|
1540
|
+
let normalized = fileName;
|
|
1541
|
+
const isHttpUrl = normalized.startsWith("http://") || normalized.startsWith("https://");
|
|
1542
|
+
if (isHttpUrl) {
|
|
1543
|
+
try {
|
|
1544
|
+
normalized = new URL(normalized).pathname;
|
|
1545
|
+
} catch {
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
let didStripPrefix = true;
|
|
1549
|
+
while (didStripPrefix) {
|
|
1550
|
+
didStripPrefix = false;
|
|
1551
|
+
for (const prefix of STACK_INTERNAL_SCHEME_PREFIXES) {
|
|
1552
|
+
if (normalized.startsWith(prefix)) {
|
|
1553
|
+
normalized = normalized.slice(prefix.length);
|
|
1554
|
+
if (prefix === "file:///") {
|
|
1555
|
+
normalized = `/${normalized.replace(/^\/+/, "")}`;
|
|
1556
|
+
}
|
|
1557
|
+
didStripPrefix = true;
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
normalized = normalized.replace(/^\/\(app-pages-browser\)\//, "/").replace(/^\/\.\//, "/").replace(/^\.\//, "");
|
|
1563
|
+
const queryIndex = normalized.indexOf("?");
|
|
1564
|
+
if (queryIndex !== -1) {
|
|
1565
|
+
normalized = normalized.slice(0, queryIndex);
|
|
1566
|
+
}
|
|
1567
|
+
return normalized;
|
|
1568
|
+
}
|
|
1569
|
+
function isSourceStackFile(fileName) {
|
|
1570
|
+
const normalizedFileName = normalizeStackFileName(fileName);
|
|
1571
|
+
if (!normalizedFileName) return false;
|
|
1572
|
+
if (!STACK_SOURCE_FILE_EXTENSION_REGEX.test(normalizedFileName)) return false;
|
|
1573
|
+
return !STACK_BUNDLED_FILE_PATTERN_REGEX.test(normalizedFileName);
|
|
1574
|
+
}
|
|
1575
|
+
function buildFunctionNameToRscFramesMap(fiber) {
|
|
1576
|
+
const functionNameToRscFrames = /* @__PURE__ */ new Map();
|
|
1577
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1578
|
+
let current = fiber;
|
|
1579
|
+
while (current && !visited.has(current)) {
|
|
1580
|
+
visited.add(current);
|
|
1581
|
+
const rawStack = current?._debugStack?.stack;
|
|
1582
|
+
const stack = typeof rawStack === "string" ? formatOwnerDebugStack(rawStack) : "";
|
|
1583
|
+
if (stack) {
|
|
1584
|
+
const frames = parseDebugStack(stack);
|
|
1585
|
+
for (const frame of frames) {
|
|
1586
|
+
if (!frame.functionName || !frame.fileName) continue;
|
|
1587
|
+
if (!frame.fileName.startsWith("rsc://")) continue;
|
|
1588
|
+
const normalized = normalizeStackFileName(frame.fileName);
|
|
1589
|
+
if (!normalized) continue;
|
|
1590
|
+
const existing = functionNameToRscFrames.get(frame.functionName) ?? [];
|
|
1591
|
+
const duplicate = existing.some(
|
|
1592
|
+
(candidate) => candidate.fileName === normalized && candidate.lineNumber === frame.lineNumber && candidate.columnNumber === frame.columnNumber
|
|
1593
|
+
);
|
|
1594
|
+
if (!duplicate) {
|
|
1595
|
+
existing.push({
|
|
1596
|
+
fileName: normalized,
|
|
1597
|
+
lineNumber: frame.lineNumber,
|
|
1598
|
+
columnNumber: frame.columnNumber
|
|
1599
|
+
});
|
|
1600
|
+
functionNameToRscFrames.set(frame.functionName, existing);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
current = current._debugOwner ?? current.return ?? null;
|
|
1605
|
+
}
|
|
1606
|
+
return functionNameToRscFrames;
|
|
1607
|
+
}
|
|
1608
|
+
function enrichServerFrame(frame, functionNameToRscFrames, functionNameToUsageIndex) {
|
|
1609
|
+
if (!frame.functionName) return frame;
|
|
1610
|
+
const available = functionNameToRscFrames.get(frame.functionName);
|
|
1611
|
+
if (!available) return frame;
|
|
1612
|
+
const usageIndex = functionNameToUsageIndex.get(frame.functionName) ?? 0;
|
|
1613
|
+
const resolved = available[usageIndex % available.length];
|
|
1614
|
+
functionNameToUsageIndex.set(frame.functionName, usageIndex + 1);
|
|
1615
|
+
return {
|
|
1616
|
+
...frame,
|
|
1617
|
+
fileName: resolved.fileName,
|
|
1618
|
+
lineNumber: resolved.lineNumber,
|
|
1619
|
+
columnNumber: resolved.columnNumber
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
function getSourceFromDebugStack(fiber) {
|
|
1623
|
+
const rawStack = fiber?._debugStack?.stack;
|
|
1624
|
+
if (typeof rawStack !== "string" || rawStack.length === 0) {
|
|
1625
|
+
return null;
|
|
1626
|
+
}
|
|
1627
|
+
const formattedStack = formatOwnerDebugStack(rawStack);
|
|
1628
|
+
if (!formattedStack) return null;
|
|
1629
|
+
const stackFrames = parseDebugStack(formattedStack);
|
|
1630
|
+
const functionNameToRscFrames = buildFunctionNameToRscFramesMap(fiber);
|
|
1631
|
+
const functionNameToUsageIndex = /* @__PURE__ */ new Map();
|
|
1632
|
+
for (const frame of stackFrames) {
|
|
1633
|
+
const maybeEnriched = frame.isServer ? enrichServerFrame(frame, functionNameToRscFrames, functionNameToUsageIndex) : frame;
|
|
1634
|
+
if (!maybeEnriched.fileName) continue;
|
|
1635
|
+
const normalizedFileName = normalizeStackFileName(maybeEnriched.fileName);
|
|
1636
|
+
if (!normalizedFileName) continue;
|
|
1637
|
+
if (isSourceStackFile(normalizedFileName)) {
|
|
1638
|
+
return {
|
|
1639
|
+
fileName: normalizedFileName,
|
|
1640
|
+
lineNumber: maybeEnriched.lineNumber,
|
|
1641
|
+
columnNumber: maybeEnriched.columnNumber
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
return null;
|
|
1646
|
+
}
|
|
1400
1647
|
function getSourceFromFiber(fiber) {
|
|
1401
1648
|
const debugSource = fiber?._debugSource;
|
|
1402
1649
|
if (debugSource?.fileName) return debugSource;
|
|
@@ -1409,6 +1656,8 @@ function getSourceFromFiber(fiber) {
|
|
|
1409
1656
|
if (pending?.fileName) return pending;
|
|
1410
1657
|
const memo = fiber?.memoizedProps?.__source;
|
|
1411
1658
|
if (memo?.fileName) return memo;
|
|
1659
|
+
const fromDebugStack = getSourceFromDebugStack(fiber);
|
|
1660
|
+
if (fromDebugStack?.fileName) return fromDebugStack;
|
|
1412
1661
|
return null;
|
|
1413
1662
|
}
|
|
1414
1663
|
function buildFrame(fiber) {
|
|
@@ -1624,7 +1873,7 @@ function buildTargetHtml(element) {
|
|
|
1624
1873
|
return `<${tagName}${attrString}></${tagName}>`;
|
|
1625
1874
|
}
|
|
1626
1875
|
function formatSourcePath(file) {
|
|
1627
|
-
const normalized = file.replace(/\\/g, "/").replace(/^webpack:\/\/\//, "").replace(/^webpack:\/\//, "").replace(/^file:\/\//, "").replace(/^_N_E\//, "").replace(/^\.\/+/, "");
|
|
1876
|
+
const normalized = file.replace(/\\/g, "/").replace(/^webpack:\/\/\//, "").replace(/^webpack:\/\//, "").replace(/^webpack-internal:\/\//, "").replace(/^rsc:\/\/React\/Server\//, "").replace(/^about:\/\/React\//, "").replace(/^file:\/\//, "").replace(/^\/\(app-pages-browser\)\//, "/").replace(/^\/app-pages-browser\//, "/").replace(/^_N_E\//, "").replace(/^\.\/+/, "");
|
|
1628
1877
|
const packagesIndex = normalized.indexOf("/packages/");
|
|
1629
1878
|
if (packagesIndex !== -1) {
|
|
1630
1879
|
return `/[project]${normalized.slice(packagesIndex)}`;
|
|
@@ -1769,8 +2018,10 @@ function getElementLocator(element) {
|
|
|
1769
2018
|
const elementInfo = getElementInfo(element);
|
|
1770
2019
|
let domSource = parseDomSource(element);
|
|
1771
2020
|
if (!domSource) {
|
|
1772
|
-
const
|
|
1773
|
-
|
|
2021
|
+
const seenFibers = /* @__PURE__ */ new Set();
|
|
2022
|
+
let fiber = getFiberForElement(element);
|
|
2023
|
+
while (fiber && !seenFibers.has(fiber)) {
|
|
2024
|
+
seenFibers.add(fiber);
|
|
1774
2025
|
const fiberSource = getSourceFromFiber(fiber);
|
|
1775
2026
|
if (fiberSource?.fileName) {
|
|
1776
2027
|
domSource = {
|
|
@@ -1778,7 +2029,9 @@ function getElementLocator(element) {
|
|
|
1778
2029
|
line: fiberSource.lineNumber,
|
|
1779
2030
|
column: fiberSource.columnNumber
|
|
1780
2031
|
};
|
|
2032
|
+
break;
|
|
1781
2033
|
}
|
|
2034
|
+
fiber = fiber._debugOwner ?? fiber.return ?? null;
|
|
1782
2035
|
}
|
|
1783
2036
|
}
|
|
1784
2037
|
return {
|