Title: Proposal: Load foreign code with ES Module Shims and import maps · Issue #263 · purescript/trypurescript · GitHub
Open Graph Title: Proposal: Load foreign code with ES Module Shims and import maps · Issue #263 · purescript/trypurescript
X Title: Proposal: Load foreign code with ES Module Shims and import maps · Issue #263 · purescript/trypurescript
Description: Try PureScript is going to have to be reworked when the PureScript compiler switches from CommonJS to ES modules for foreign code. This issue details a proposal for how to handle this rewrite. Current Implementation We currently parse th...
Open Graph Description: Try PureScript is going to have to be reworked when the PureScript compiler switches from CommonJS to ES modules for foreign code. This issue details a proposal for how to handle this rewrite. Curr...
X Description: Try PureScript is going to have to be reworked when the PureScript compiler switches from CommonJS to ES modules for foreign code. This issue details a proposal for how to handle this rewrite. Curr...
Opengraph URL: https://github.com/purescript/trypurescript/issues/263
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Load foreign code with ES Module Shims and import maps","articleBody":"Try PureScript is going to have to be reworked when the PureScript compiler [switches from CommonJS to ES modules](https://github.com/purescript/purescript/pull/3791) for foreign code. This issue details a proposal for how to handle this rewrite.\r\n\r\n### Current Implementation\r\n\r\nWe currently parse through the generated JavaScript on Try PureScript to discover all dependencies present via `require()` statements. For every dependency we find we do one of:\r\n\r\n1. Load the JS from `compile.purescript.org` (for example, [`Data.EuclidianRing/foreign.js`](https://compile.purescript.org/output/Data.EuclideanRing/foreign.js))\r\n2. Look up its URL from the [Shim.purs](https://github.com/purescript/trypurescript/blob/master/client/src/Try/Shim.purs) file which lists CDN locations for some common FFI libraries like `react`, and then load the contents\r\n\r\nOnce we know what dependencies to load, we take their contents and insert them into the code iframe. Finally, we load their contents via the [`evalSources` function in `frame.js`](https://github.com/purescript/trypurescript/blob/af70d48e3d500ab6909e782b7ac50f982b6948e2/client/public/js/frame.js#L2-L28).\r\n\r\n### Issues\r\n\r\nThis code is no longer going to work. PureScript 0.15 will only work with ES modules, so the code in `Shim.purs`, `Loader.purs`, and `frame.js` will all need to be updated to work with ES modules instead of CommonJS modules -- in other words, there is no more `require` or `module.exports`; instead, there's `import` and `export`.\r\n\r\nI also don't think we can instantiate the code the same way we do now, which I _believe_ happens here:\r\n\r\nhttps://github.com/purescript/trypurescript/blob/53a82a636802aad4007a0a6cbee9bc7dfdd1be4b/client/public/js/frame.js#L25\r\n\r\nFinally, if we swap all the way over to ES modules, we lose all Internet Explorer support, which we have historically not wanted to lose.\r\n\r\n### Proposal: SystemJS\r\n\r\nWe're clearly going to have to rewrite how we handle foreign code in Try PureScript. After a brief discussion with @natefaubion on the PureScript chat I would like to propose that we use two technologies:\r\n\r\n1. [SystemJS](https://github.com/systemjs/systemjs), which [covers IE11](https://github.com/systemjs/systemjs#ie11-support)\r\n2. [Import maps](https://wicg.github.io/import-maps), which are [supported in SystemJS](https://github.com/systemjs/systemjs#import-maps), including [for IE11](https://github.com/systemjs/systemjs#note-on-import-maps-support-in-ie11)\r\n\r\nThe [SystemJS documentation on import maps](https://github.com/systemjs/systemjs/blob/main/docs/import-maps.md) does a good job of explaining how we can use this tool to replace our existing shim + loader + frame.js setup. If I'm reading correctly, we'd strip out almost everything and move the contents of `Shim.purs` into an import map. We'd rely on SystemJS for everything else.","author":{"url":"https://github.com/thomashoneyman","@type":"Person","name":"thomashoneyman"},"datePublished":"2022-01-18T03:58:31Z","url":"https://github.com/purescript/trypurescript/issues/263"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b8b72566-2eee-6f2f-a28c-ca33a14127f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAA8:23880A:F17784:14D1BCD:6AFBF560 |
| html-safe-nonce | fc625b2c478b3449578c5b1e5841f3ad145e6f8fd01fcccdaa3a6096b3f2dd58 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUE4OjIzODgwQTpGMTc3ODQ6MTREMUJDRDo2QUZCRjU2MCIsInZpc2l0b3JfaWQiOiIzMDM2NjUzNjA5MzQ2MTM1MzkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 40e7f96e71e4531e222fc7d7c6fc101a1efadbdff30e4d01b1f9f94f4fa0cdc5 |
| hovercard-subject-tag | issue:1106449877 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript/trypurescript/263/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfe70a322492d9c573d20c9ee6dc563bc5383e98995e0ce1f8a203192e3af28d/purescript/trypurescript/issues/263 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfe70a322492d9c573d20c9ee6dc563bc5383e98995e0ce1f8a203192e3af28d/purescript/trypurescript/issues/263 |
| og:image:alt | Try PureScript is going to have to be reworked when the PureScript compiler switches from CommonJS to ES modules for foreign code. This issue details a proposal for how to handle this rewrite. Curr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thomashoneyman |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript/trypurescript git https://github.com/purescript/trypurescript.git |
| octolytics-dimension-user_id | 6556677 |
| octolytics-dimension-user_login | purescript |
| octolytics-dimension-repository_id | 14093432 |
| octolytics-dimension-repository_nwo | purescript/trypurescript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14093432 |
| octolytics-dimension-repository_network_root_nwo | purescript/trypurescript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width