cljsrn

joshmiller 2022-10-13T20:49:06.190859Z

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

Oliver George 2022-10-14T00:26:17.290039Z

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

joshmiller 2022-10-14T00:42:33.285579Z

@olivergeorge 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
joshmiller 2022-10-13T20:50:38.694259Z

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.

shaunlebron 2022-10-20T13:50:38.080009Z

Can I ask you about your setup?

shaunlebron 2022-10-20T13:54:57.965259Z

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

shaunlebron 2022-10-20T13:56:16.055829Z

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

shaunlebron 2022-10-20T14:13:08.966469Z

and actually I just found this method: http://austinbirch.co.uk/clojurescript-react-native-bundling-release.html

joshmiller 2022-10-20T17:01:45.551209Z

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

shaunlebron 2023-02-02T18:22:51.966599Z

did you use my script or austin’s?

shaunlebron 2023-02-02T18:22:59.384949Z

@joshmiller ^

joshmiller 2023-02-02T19:23:00.034919Z

@shaunlebron Yours

joshmiller 2023-02-02T19:23:21.833959Z

(With modifications for my paths etc)

shaunlebron 2023-02-02T19:24:19.782039Z

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

joshmiller 2023-02-02T19:25:26.923439Z

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

shaunlebron 2023-02-02T19:26:30.672679Z

the Krell repl catches runtime errors?

shaunlebron 2023-02-02T19:26:42.437879Z

(we’re using Expo)

joshmiller 2023-02-02T19:28:21.794809Z

Yes, it does.

shaunlebron 2023-02-02T19:29:40.044599Z

Good to know, thank you!

👍 1
shaunlebron 2023-02-10T20:59:57.655569Z

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 ...
  ],
}

joshmiller 2022-11-18T16:32:24.298639Z

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
shaunlebron 2023-02-09T18:12:26.907779Z

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,
      ...
    ]
  }
}

joshmiller 2023-02-09T18:20:44.057999Z

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