react-code-locator 0.1.12 → 0.1.14

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 (52) hide show
  1. package/README.md +9 -0
  2. package/dist/babel.cjs +6 -5
  3. package/dist/babel.cjs.map +1 -1
  4. package/dist/babel.d.cts +2 -2
  5. package/dist/babel.d.ts +2 -2
  6. package/dist/babel.js +6 -5
  7. package/dist/babel.js.map +1 -1
  8. package/dist/babelInjectComponentSource.cjs +0 -3
  9. package/dist/babelInjectComponentSource.cjs.map +1 -1
  10. package/dist/babelInjectComponentSource.d.cts +1 -1
  11. package/dist/babelInjectComponentSource.d.ts +1 -1
  12. package/dist/babelInjectComponentSource.js +0 -3
  13. package/dist/babelInjectComponentSource.js.map +1 -1
  14. package/dist/client.cjs +0 -3
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.cts +15 -1
  17. package/dist/client.d.ts +15 -1
  18. package/dist/client.js +0 -3
  19. package/dist/client.js.map +1 -1
  20. package/dist/esbuild.cjs +8 -7
  21. package/dist/esbuild.cjs.map +1 -1
  22. package/dist/esbuild.d.cts +1 -1
  23. package/dist/esbuild.d.ts +1 -1
  24. package/dist/esbuild.js +8 -7
  25. package/dist/esbuild.js.map +1 -1
  26. package/dist/index.cjs +2 -670
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +1 -9
  29. package/dist/index.d.ts +1 -9
  30. package/dist/index.js +1 -657
  31. package/dist/index.js.map +1 -1
  32. package/dist/{sourceAdapter-DLWo_ABo.d.cts → sourceAdapter-dPr5CgLi.d.cts} +1 -2
  33. package/dist/{sourceAdapter-DLWo_ABo.d.ts → sourceAdapter-dPr5CgLi.d.ts} +1 -2
  34. package/dist/swc.cjs +8 -7
  35. package/dist/swc.cjs.map +1 -1
  36. package/dist/swc.d.cts +1 -1
  37. package/dist/swc.d.ts +1 -1
  38. package/dist/swc.js +8 -7
  39. package/dist/swc.js.map +1 -1
  40. package/dist/vite.cjs +11 -7
  41. package/dist/vite.cjs.map +1 -1
  42. package/dist/vite.d.cts +3 -3
  43. package/dist/vite.d.ts +3 -3
  44. package/dist/vite.js +11 -7
  45. package/dist/vite.js.map +1 -1
  46. package/dist/webpackRuntimeEntry.cjs +0 -3
  47. package/dist/webpackRuntimeEntry.cjs.map +1 -1
  48. package/dist/webpackRuntimeEntry.js +0 -3
  49. package/dist/webpackRuntimeEntry.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/client-sm5wi0uT.d.cts +0 -15
  52. package/dist/client-sm5wi0uT.d.ts +0 -15
package/dist/index.js CHANGED
@@ -29,20 +29,8 @@ function normalizeProjectRoot(projectRoot) {
29
29
  if (projectRoot) {
30
30
  return trimTrailingSlash(normalizeSlashes(projectRoot));
31
31
  }
32
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
33
- return trimTrailingSlash(normalizeSlashes(process.cwd()));
34
- }
35
32
  return "";
36
33
  }
37
- function toRelativeSource(filename, loc, projectRoot) {
38
- if (!filename || !loc) {
39
- return null;
40
- }
41
- const root = normalizeProjectRoot(projectRoot);
42
- const normalizedFilename = normalizeSlashes(filename);
43
- const relPath = root && normalizedFilename.startsWith(`${root}/`) ? normalizedFilename.slice(root.length + 1) : root ? computeRelativePath(root, normalizedFilename) : normalizedFilename;
44
- return `${relPath}:${loc.line}:${loc.column + 1}`;
45
- }
46
34
  function getSourceFile(source) {
47
35
  if (!source) {
48
36
  return null;
@@ -65,9 +53,6 @@ function isProjectLocalFile(filename, projectRoot) {
65
53
  const relativePath = computeRelativePath(root, normalizedFilename);
66
54
  return !relativePath.startsWith("../");
67
55
  }
68
- function isExternalToProjectRoot(filename, projectRoot) {
69
- return !isProjectLocalFile(filename, projectRoot);
70
- }
71
56
  function isProjectLocalSource(source, projectRoot) {
72
57
  const file = getSourceFile(source);
73
58
  return isProjectLocalFile(file ?? void 0, projectRoot);
@@ -380,649 +365,8 @@ function enableReactComponentJump(options = {}) {
380
365
  overlay?.remove();
381
366
  };
382
367
  }
383
-
384
- // src/sourceAdapter.ts
385
- function defineSourceAdapter(descriptor) {
386
- return descriptor;
387
- }
388
-
389
- // src/babelInjectComponentSource.ts
390
- import { types as t } from "@babel/core";
391
- var SOURCE_PROP_LOCAL = "_componentSourceLoc";
392
- var SOURCE_PROPS_REST = "__reactCodeLocatorProps";
393
- function isComponentName(name) {
394
- return /^[A-Z]/.test(name);
395
- }
396
- function isCustomComponentTag(name) {
397
- if (t.isJSXIdentifier(name)) {
398
- return isComponentName(name.name);
399
- }
400
- if (t.isJSXMemberExpression(name)) {
401
- return true;
402
- }
403
- return false;
404
- }
405
- function isIntrinsicElementTag(name) {
406
- return t.isJSXIdentifier(name) && /^[a-z]/.test(name.name);
407
- }
408
- function isElementFactoryIdentifier(name) {
409
- return name === "jsx" || name === "jsxs" || name === "jsxDEV" || name === "_jsx" || name === "_jsxs" || name === "_jsxDEV" || name === "createElement";
410
- }
411
- function isReactElementFactoryCall(pathNode) {
412
- const callee = pathNode.node.callee;
413
- if (t.isIdentifier(callee)) {
414
- return isElementFactoryIdentifier(callee.name);
415
- }
416
- return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "React" }) && t.isIdentifier(callee.property, { name: "createElement" });
417
- }
418
- function getRootJsxIdentifierName(name) {
419
- if (t.isJSXIdentifier(name)) {
420
- return name.name;
421
- }
422
- if (t.isJSXMemberExpression(name)) {
423
- return getRootJsxIdentifierName(name.object);
424
- }
425
- return null;
426
- }
427
- function isStyledModuleImport(binding) {
428
- if (!binding) {
429
- return false;
430
- }
431
- if (!binding.path.isImportSpecifier() && !binding.path.isImportDefaultSpecifier() && !binding.path.isImportNamespaceSpecifier()) {
432
- return false;
433
- }
434
- const source = binding.path.parentPath.isImportDeclaration() ? binding.path.parentPath.node.source.value : null;
435
- if (typeof source !== "string") {
436
- return false;
437
- }
438
- const normalized = source.replace(/\\/g, "/");
439
- return normalized === "./styled" || normalized === "../styled" || normalized.endsWith("/styled");
440
- }
441
- function isSupportedComponentInit(node) {
442
- if (!node) {
443
- return false;
444
- }
445
- if (t.isArrowFunctionExpression(node) || t.isFunctionExpression(node)) {
446
- return true;
447
- }
448
- if (!t.isCallExpression(node)) {
449
- return false;
450
- }
451
- if (t.isIdentifier(node.callee) && (node.callee.name === "memo" || node.callee.name === "forwardRef")) {
452
- return true;
453
- }
454
- return t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object, { name: "React" }) && t.isIdentifier(node.callee.property) && (node.callee.property.name === "memo" || node.callee.property.name === "forwardRef");
455
- }
456
- function hasSourcePropBinding(pattern) {
457
- return pattern.properties.some((property) => {
458
- if (!t.isObjectProperty(property)) {
459
- return false;
460
- }
461
- return t.isIdentifier(property.key) && property.key.name === JSX_SOURCE_PROP;
462
- });
463
- }
464
- function injectSourcePropBinding(pattern) {
465
- if (hasSourcePropBinding(pattern)) {
466
- return;
467
- }
468
- const sourceBinding = t.objectProperty(
469
- t.identifier(JSX_SOURCE_PROP),
470
- t.identifier(SOURCE_PROP_LOCAL),
471
- false,
472
- false
473
- );
474
- const restIndex = pattern.properties.findIndex(
475
- (property) => t.isRestElement(property)
476
- );
477
- if (restIndex === -1) {
478
- pattern.properties.push(sourceBinding);
479
- return;
480
- }
481
- pattern.properties.splice(restIndex, 0, sourceBinding);
482
- }
483
- function injectSourcePropIntoIdentifierParam(node, param) {
484
- if (!t.isBlockStatement(node.body)) {
485
- node.body = t.blockStatement([t.returnStatement(node.body)]);
486
- }
487
- const alreadyInjected = node.body.body.some(
488
- (statement) => t.isVariableDeclaration(statement) && statement.declarations.some(
489
- (declaration) => t.isIdentifier(declaration.id) && declaration.id.name === SOURCE_PROPS_REST
490
- )
491
- );
492
- if (alreadyInjected) {
493
- return;
494
- }
495
- node.body.body.unshift(
496
- t.variableDeclaration("const", [
497
- t.variableDeclarator(
498
- t.objectPattern([
499
- t.objectProperty(
500
- t.identifier(JSX_SOURCE_PROP),
501
- t.identifier(SOURCE_PROP_LOCAL),
502
- false,
503
- false
504
- ),
505
- t.restElement(t.identifier(SOURCE_PROPS_REST))
506
- ]),
507
- param
508
- )
509
- ]),
510
- t.expressionStatement(
511
- t.assignmentExpression(
512
- "=",
513
- t.identifier(param.name),
514
- t.identifier(SOURCE_PROPS_REST)
515
- )
516
- )
517
- );
518
- }
519
- function injectSourcePropIntoFunctionParams(node) {
520
- const firstParam = node.params[0];
521
- if (!firstParam) {
522
- return;
523
- }
524
- if (t.isObjectPattern(firstParam)) {
525
- injectSourcePropBinding(firstParam);
526
- return;
527
- }
528
- if (t.isIdentifier(firstParam)) {
529
- injectSourcePropIntoIdentifierParam(node, firstParam);
530
- }
531
- }
532
- function injectSourcePropIntoExpression(node) {
533
- if (!node) {
534
- return;
535
- }
536
- if (t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) {
537
- injectSourcePropIntoFunctionParams(node);
538
- return;
539
- }
540
- if (!t.isCallExpression(node)) {
541
- return;
542
- }
543
- const firstArg = node.arguments[0];
544
- if (firstArg && !t.isSpreadElement(firstArg) && (t.isFunctionExpression(firstArg) || t.isArrowFunctionExpression(firstArg))) {
545
- injectSourcePropIntoFunctionParams(firstArg);
546
- }
547
- }
548
- function getSourceValue(state, loc, projectRoot) {
549
- const filename = state.file?.opts?.filename;
550
- if (!filename || !loc) {
551
- return null;
552
- }
553
- return toRelativeSource(filename, loc, projectRoot);
554
- }
555
- function buildAssignment(name, sourceValue) {
556
- return t.expressionStatement(
557
- t.assignmentExpression(
558
- "=",
559
- t.memberExpression(t.identifier(name), t.identifier(SOURCE_PROP)),
560
- t.stringLiteral(sourceValue)
561
- )
562
- );
563
- }
564
- function buildIntrinsicSourceHelper() {
565
- return t.functionDeclaration(
566
- t.identifier("_markIntrinsicElementSource"),
567
- [t.identifier("element"), t.identifier("source")],
568
- t.blockStatement([
569
- t.variableDeclaration("const", [
570
- t.variableDeclarator(
571
- t.identifier("registryKey"),
572
- t.callExpression(
573
- t.memberExpression(t.identifier("Symbol"), t.identifier("for")),
574
- [t.stringLiteral(JSX_SOURCE_REGISTRY_SYMBOL)]
575
- )
576
- )
577
- ]),
578
- t.variableDeclaration("let", [
579
- t.variableDeclarator(
580
- t.identifier("registry"),
581
- t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true)
582
- )
583
- ]),
584
- t.ifStatement(
585
- t.unaryExpression(
586
- "!",
587
- t.binaryExpression("instanceof", t.identifier("registry"), t.identifier("WeakMap"))
588
- ),
589
- t.blockStatement([
590
- t.expressionStatement(
591
- t.assignmentExpression(
592
- "=",
593
- t.identifier("registry"),
594
- t.assignmentExpression(
595
- "=",
596
- t.memberExpression(t.identifier("globalThis"), t.identifier("registryKey"), true),
597
- t.newExpression(t.identifier("WeakMap"), [])
598
- )
599
- )
600
- )
601
- ])
602
- ),
603
- t.ifStatement(
604
- t.logicalExpression(
605
- "&&",
606
- t.identifier("element"),
607
- t.logicalExpression(
608
- "&&",
609
- t.binaryExpression("===", t.unaryExpression("typeof", t.identifier("element")), t.stringLiteral("object")),
610
- t.binaryExpression(
611
- "===",
612
- t.unaryExpression("typeof", t.memberExpression(t.identifier("element"), t.identifier("props"))),
613
- t.stringLiteral("object")
614
- )
615
- )
616
- ),
617
- t.blockStatement([
618
- t.expressionStatement(
619
- t.callExpression(
620
- t.memberExpression(t.identifier("registry"), t.identifier("set")),
621
- [t.memberExpression(t.identifier("element"), t.identifier("props")), t.identifier("source")]
622
- )
623
- )
624
- ])
625
- ),
626
- t.returnStatement(t.identifier("element"))
627
- ])
628
- );
629
- }
630
- function ensureIntrinsicSourceHelper(programPath, state) {
631
- if (state.injectedIntrinsicHelper) {
632
- return;
633
- }
634
- const alreadyExists = programPath.node.body.some(
635
- (node) => t.isFunctionDeclaration(node) && t.isIdentifier(node.id, { name: "_markIntrinsicElementSource" })
636
- );
637
- if (!alreadyExists) {
638
- programPath.unshiftContainer("body", buildIntrinsicSourceHelper());
639
- }
640
- state.injectedIntrinsicHelper = true;
641
- }
642
- function visitDeclaration(declarationPath, insertAfterPath, state, seen, projectRoot) {
643
- if (declarationPath.isFunctionDeclaration() || declarationPath.isClassDeclaration()) {
644
- const name = declarationPath.node.id?.name;
645
- if (!name || !isComponentName(name) || seen.has(name)) {
646
- return;
647
- }
648
- if (declarationPath.isFunctionDeclaration()) {
649
- injectSourcePropIntoFunctionParams(declarationPath.node);
650
- }
651
- const sourceValue = getSourceValue(
652
- state,
653
- declarationPath.node.loc?.start,
654
- projectRoot
655
- );
656
- if (!sourceValue) {
657
- return;
658
- }
659
- seen.add(name);
660
- insertAfterPath.insertAfter(buildAssignment(name, sourceValue));
661
- return;
662
- }
663
- if (!declarationPath.isVariableDeclaration()) {
664
- return;
665
- }
666
- const assignments = declarationPath.node.declarations.flatMap(
667
- (declarator) => {
668
- if (!t.isIdentifier(declarator.id) || !isComponentName(declarator.id.name) || seen.has(declarator.id.name)) {
669
- return [];
670
- }
671
- if (!declarator.init) {
672
- return [];
673
- }
674
- if (!isSupportedComponentInit(declarator.init)) {
675
- return [];
676
- }
677
- injectSourcePropIntoExpression(declarator.init);
678
- const sourceValue = getSourceValue(
679
- state,
680
- declarator.loc?.start ?? declarator.init.loc?.start,
681
- projectRoot
682
- );
683
- if (!sourceValue) {
684
- return [];
685
- }
686
- seen.add(declarator.id.name);
687
- return [buildAssignment(declarator.id.name, sourceValue)];
688
- }
689
- );
690
- if (assignments.length > 0) {
691
- insertAfterPath.insertAfter(assignments);
692
- }
693
- }
694
- function babelInjectComponentSource(options = {}) {
695
- const {
696
- injectJsxSource = true,
697
- injectComponentSource = true,
698
- projectRoot
699
- } = options;
700
- return {
701
- name: "babel-inject-component-source",
702
- visitor: {
703
- CallExpression(pathNode, state) {
704
- if (!injectJsxSource) {
705
- return;
706
- }
707
- if (!isReactElementFactoryCall(pathNode)) {
708
- return;
709
- }
710
- if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, {
711
- name: "_markIntrinsicElementSource"
712
- })) {
713
- return;
714
- }
715
- const sourceValue = getSourceValue(
716
- state,
717
- pathNode.node.loc?.start,
718
- projectRoot
719
- );
720
- if (!sourceValue) {
721
- return;
722
- }
723
- const programPath = pathNode.findParent((parent) => parent.isProgram());
724
- if (!programPath || !programPath.isProgram()) {
725
- return;
726
- }
727
- ensureIntrinsicSourceHelper(programPath, state);
728
- pathNode.replaceWith(
729
- t.callExpression(t.identifier("_markIntrinsicElementSource"), [
730
- pathNode.node,
731
- t.stringLiteral(sourceValue)
732
- ])
733
- );
734
- pathNode.skip();
735
- },
736
- JSXElement: {
737
- exit(pathNode, state) {
738
- if (!injectJsxSource) {
739
- return;
740
- }
741
- if (!isIntrinsicElementTag(pathNode.node.openingElement.name)) {
742
- return;
743
- }
744
- if (pathNode.parentPath.isCallExpression() && t.isIdentifier(pathNode.parentPath.node.callee, { name: "_markIntrinsicElementSource" })) {
745
- return;
746
- }
747
- const sourceValue = getSourceValue(
748
- state,
749
- pathNode.node.openingElement.loc?.start,
750
- projectRoot
751
- );
752
- if (!sourceValue) {
753
- return;
754
- }
755
- const programPath = pathNode.findParent((parent) => parent.isProgram());
756
- if (!programPath || !programPath.isProgram()) {
757
- return;
758
- }
759
- ensureIntrinsicSourceHelper(programPath, state);
760
- const wrappedNode = t.callExpression(t.identifier("_markIntrinsicElementSource"), [
761
- pathNode.node,
762
- t.stringLiteral(sourceValue)
763
- ]);
764
- if (pathNode.parentPath.isJSXElement() || pathNode.parentPath.isJSXFragment()) {
765
- pathNode.replaceWith(t.jsxExpressionContainer(wrappedNode));
766
- return;
767
- }
768
- if (pathNode.parentPath.isJSXExpressionContainer()) {
769
- pathNode.parentPath.replaceWith(t.jsxExpressionContainer(wrappedNode));
770
- return;
771
- }
772
- pathNode.replaceWith(wrappedNode);
773
- }
774
- },
775
- JSXOpeningElement(pathNode, state) {
776
- if (!injectJsxSource) {
777
- return;
778
- }
779
- if (!isCustomComponentTag(pathNode.node.name)) {
780
- return;
781
- }
782
- const rootIdentifierName = getRootJsxIdentifierName(pathNode.node.name);
783
- if (rootIdentifierName && isExternalToProjectRoot(state.file?.opts?.filename, projectRoot) && isStyledModuleImport(pathNode.scope.getBinding(rootIdentifierName))) {
784
- return;
785
- }
786
- const hasSourceProp = pathNode.node.attributes.some(
787
- (attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name === JSX_SOURCE_PROP
788
- );
789
- if (hasSourceProp) {
790
- return;
791
- }
792
- const filename = state.file?.opts?.filename;
793
- const loc = pathNode.node.loc?.start;
794
- if (!filename || !loc) {
795
- return;
796
- }
797
- pathNode.node.attributes.push(
798
- t.jsxAttribute(
799
- t.jsxIdentifier(JSX_SOURCE_PROP),
800
- t.stringLiteral(
801
- getSourceValue(state, loc, projectRoot) ?? `${filename.replace(/\\/g, "/")}:${loc.line}:${loc.column + 1}`
802
- )
803
- )
804
- );
805
- },
806
- Program(programPath, state) {
807
- if (!injectComponentSource) {
808
- return;
809
- }
810
- const seen = /* @__PURE__ */ new Set();
811
- for (const childPath of programPath.get("body")) {
812
- if (childPath.isExportNamedDeclaration() || childPath.isExportDefaultDeclaration()) {
813
- const declarationPath = childPath.get("declaration");
814
- if (!Array.isArray(declarationPath) && declarationPath.node) {
815
- visitDeclaration(declarationPath, childPath, state, seen, projectRoot);
816
- }
817
- continue;
818
- }
819
- visitDeclaration(childPath, childPath, state, seen, projectRoot);
820
- }
821
- }
822
- }
823
- };
824
- }
825
-
826
- // src/babel.ts
827
- function createBabelSourceAdapter(options = {}) {
828
- return defineSourceAdapter({
829
- kind: "babel",
830
- name: "react-code-locator/babel",
831
- options,
832
- config: {
833
- plugins: [[babelInjectComponentSource, options]]
834
- }
835
- });
836
- }
837
- var babelSourceAdapter = createBabelSourceAdapter();
838
-
839
- // src/sourceTransform.ts
840
- import { transformAsync } from "@babel/core";
841
- async function transformSourceWithLocator(code, options) {
842
- const { filename, sourceMaps = true, ...pluginOptions } = options;
843
- const result = await transformAsync(code, {
844
- filename,
845
- babelrc: false,
846
- configFile: false,
847
- sourceMaps,
848
- parserOpts: {
849
- sourceType: "module",
850
- plugins: ["jsx", "typescript"]
851
- },
852
- generatorOpts: {
853
- retainLines: true
854
- },
855
- plugins: [[babelInjectComponentSource, pluginOptions]]
856
- });
857
- return {
858
- code: result?.code ?? code,
859
- map: result?.map ?? null
860
- };
861
- }
862
-
863
- // src/viteClientInjector.ts
864
- var VIRTUAL_CLIENT_MODULE_ID = "virtual:react-code-locator/client";
865
- var RESOLVED_VIRTUAL_CLIENT_MODULE_ID = `\0${VIRTUAL_CLIENT_MODULE_ID}`;
866
- function createClientInjector(locatorOptions = {}) {
867
- const serialized = JSON.stringify(locatorOptions);
868
- return {
869
- name: "react-code-locator-client-injector",
870
- apply: "serve",
871
- resolveId(id) {
872
- if (id === VIRTUAL_CLIENT_MODULE_ID) {
873
- return RESOLVED_VIRTUAL_CLIENT_MODULE_ID;
874
- }
875
- return null;
876
- },
877
- load(id) {
878
- if (id !== RESOLVED_VIRTUAL_CLIENT_MODULE_ID) {
879
- return null;
880
- }
881
- return `
882
- import { enableReactComponentJump } from "react-code-locator/client";
883
-
884
- enableReactComponentJump(${serialized});
885
- `;
886
- },
887
- transformIndexHtml() {
888
- return [
889
- {
890
- tag: "script",
891
- attrs: {
892
- type: "module",
893
- src: `/@id/__x00__${VIRTUAL_CLIENT_MODULE_ID}`
894
- },
895
- injectTo: "head"
896
- }
897
- ];
898
- }
899
- };
900
- }
901
- function createViteClientInjector(options = {}) {
902
- const { command = "serve", locator = {}, injectClient = true } = options;
903
- const isServe = command === "serve";
904
- return [isServe && injectClient ? createClientInjector(locator) : null].filter(Boolean);
905
- }
906
-
907
- // src/vite.ts
908
- function shouldTransformSource(id) {
909
- if (id.includes("/node_modules/") || id.startsWith("\0")) {
910
- return false;
911
- }
912
- return /\.[mc]?[jt]sx?$/.test(id);
913
- }
914
- function viteSourceTransformPlugin(options = {}) {
915
- return {
916
- name: "react-code-locator-source-transform",
917
- enforce: "pre",
918
- async transform(code, id) {
919
- if (!shouldTransformSource(id)) {
920
- return null;
921
- }
922
- return transformSourceWithLocator(code, {
923
- filename: id,
924
- ...options
925
- });
926
- }
927
- };
928
- }
929
- function createViteSourceAdapter(options = {}) {
930
- const { babel = {}, ...viteOptions } = options;
931
- const plugins = [
932
- viteSourceTransformPlugin(babel),
933
- ...createViteClientInjector(viteOptions)
934
- ].filter(Boolean);
935
- return defineSourceAdapter({
936
- kind: "vite",
937
- name: "react-code-locator/vite",
938
- options,
939
- config: {
940
- plugins
941
- }
942
- });
943
- }
944
- var viteSourceAdapter = createViteSourceAdapter();
945
-
946
- // src/esbuild.ts
947
- import { readFile } from "fs/promises";
948
- function getEsbuildLoader(filename) {
949
- if (filename.endsWith(".tsx")) {
950
- return "tsx";
951
- }
952
- if (filename.endsWith(".ts")) {
953
- return "ts";
954
- }
955
- if (filename.endsWith(".jsx")) {
956
- return "jsx";
957
- }
958
- return "js";
959
- }
960
- function esbuildSourceTransformPlugin(options = {}) {
961
- return {
962
- name: "react-code-locator-source-transform",
963
- setup(build) {
964
- build.onLoad({ filter: /\.[mc]?[jt]sx?$/ }, async ({ path }) => {
965
- if (path.includes("/node_modules/")) {
966
- return null;
967
- }
968
- const code = await readFile(path, "utf8");
969
- const result = await transformSourceWithLocator(code, {
970
- filename: path,
971
- ...options
972
- });
973
- return {
974
- contents: result.code,
975
- loader: getEsbuildLoader(path)
976
- };
977
- });
978
- }
979
- };
980
- }
981
- function createEsbuildSourceAdapter(options = {}) {
982
- return defineSourceAdapter({
983
- kind: "esbuild",
984
- name: "react-code-locator/esbuild",
985
- options,
986
- config: {
987
- plugins: [esbuildSourceTransformPlugin(options)]
988
- }
989
- });
990
- }
991
- var esbuildSourceAdapter = createEsbuildSourceAdapter();
992
-
993
- // src/swc.ts
994
- async function transformSourceWithSwcLocator(code, options) {
995
- return transformSourceWithLocator(code, options);
996
- }
997
- function createSwcSourceAdapter(options = {}) {
998
- const transform = (code, transformOptions) => transformSourceWithSwcLocator(code, {
999
- ...options,
1000
- ...transformOptions
1001
- });
1002
- return defineSourceAdapter({
1003
- kind: "swc",
1004
- name: "react-code-locator/swc",
1005
- options,
1006
- config: {
1007
- transform
1008
- }
1009
- });
1010
- }
1011
- var swcSourceAdapter = createSwcSourceAdapter();
1012
368
  export {
1013
- babelInjectComponentSource,
1014
- babelSourceAdapter,
1015
- createBabelSourceAdapter,
1016
- createEsbuildSourceAdapter,
1017
- createSwcSourceAdapter,
1018
- createViteClientInjector,
1019
- createViteSourceAdapter,
1020
- defineSourceAdapter,
1021
369
  enableReactComponentJump,
1022
- esbuildSourceAdapter,
1023
- locateComponentSource,
1024
- createViteClientInjector as reactComponentJump,
1025
- swcSourceAdapter,
1026
- viteSourceAdapter
370
+ locateComponentSource
1027
371
  };
1028
372
  //# sourceMappingURL=index.js.map