Fork me on GitHub
#cljsrn
<
2022-10-13
>
joshmiller20:10:06

Does anyone have experience passing Clojurescript source maps through the Metro bundler and getting the full results back out? Is this even possible?

Oliver George00:10:17

Something related hit my inbox the other day. While I doubt it's an easy fix it might help you on your way: https://github.com/facebook/metro/issues/104#issuecomment-1278243145

joshmiller00:10:33

@U055DUUFS Awesome, thanks for that pointer. Subscribing to that thread, and when the feature is straightened out with metro I’ll document whatever extra CLJS needs.

👍 2
joshmiller20:10:38

For reference, I can create an advanced compilation single JS file of my Krell app, and feed that into the Metro bundler, and deploy it successfully. And I can create source maps from my CLJS, and I can create source maps from Metro. But the final source maps I get from Metro reference the advanced-compiled index.js that the CLJS compiler created, not the original CLJS source it came from.

shaunlebron13:10:38

Can I ask you about your setup?

shaunlebron13:10:57

I was able to write a node.js script that merges cljs source maps into metro’s source map file. Maybe you can try it? https://github.com/shaunlebron/cljs-expo/blob/659505a1f832816f142f111178911294156755f2/expo/remap.js

shaunlebron13:10:16

I haven’t figured out how to insert this into Metro as a PR

joshmiller17:10:45

@shaunlebron Oh, interesting, let me try this out.

joshmiller16:11:24

This script, modified a little bit for my different source file locations, turns out to have worked to get me ClojureScript-aware source maps. Thanks @shaunlebron!

🤯 1
shaunlebron18:02:51

did you use my script or austin’s?

joshmiller19:02:21

(With modifications for my paths etc)

shaunlebron19:02:19

Great! Do you have any success for dev source maps? Just use chrome dev tools?

joshmiller19:02:26

I haven’t tried for dev yet, I just use the errors I get in the Krell repl.

shaunlebron19:02:30

the Krell repl catches runtime errors?

shaunlebron19:02:42

(we’re using Expo)

joshmiller19:02:21

Yes, it does.

shaunlebron19:02:40

Good to know, thank you!

👍 2
shaunlebron18:02:26

Just a heads-up. I’m having some trouble using this method in a Hermes-bytecode build from Expo, internally produced with Metro somehow. This is the source map file e.g.:

{
  "version": 3,
  "sources": [],
  "names": [],
  "mappings": "A,4B,M,...",
  "x_facebook_sources": [],
  "x_hermes_function_offsets": {
    "0": [
      0,
      74130,
      74394,
      74423,
      74512,
      ...
    ]
  }
}

joshmiller18:02:44

Hm, I haven’t tried with Hermes yet, interesting that it seems like it’s got some Hermes-specific info in there.

shaunlebron20:02:57

Even turning Hermes off, our "mappings" key is empty, and they seemed to be moved to the x_facebook_sources extension:

{
  "version": 3,

  // STANDARD
  "sources": [ ... lots of filenames ... ],
  "sourcesContent": [ .. lots of file sources ... ],
  "names": [],   // <-- EMPTY
  "mappings": "" // <-- EMPTY

  // EXTENSIONS
  "x_facebook_sources": [
    null,
    [
      {
        "names": [ ... lots of names ],
        "mappings": "AAA;wBCyB,QD;..."
      }
    ],
    [
      {
        "names": [ ... lots of names ...],
        "mappings": "AAA;iBCiB;ECwB;..."
      }
    ],
    ... lots more ...
  ],
}