Skip to content

Conversation

@guludo
Copy link

@guludo guludo commented Mar 6, 2021

Hi there!

I was trying to use this library in another project and ran into some problems:

  1. The module @babel/runtime was missing from brython-runner dependency list. So, when I used import BrythonRunner from 'brython-runner/lib/brython-runner.js', webpack complained that could not find the modules required by the code generated by the @babel/plugin-transform-runtime plugin.
  2. The module lib/core/brython-runner.js loads lib/core/brython-runner.worker.js as a raw string, so calls like require("@babel/runtime/...") generated by @babel/plugin-transform-runtime are not resolved by webpack. That results in the code failing to execute in the Web worker.

In this pull request I address problem (1) by adding @babel/runtime as a dependency, as recommended by the documentation. This is done in the first commit.

As for problem (2), instead of generating lib/core/brython-runner.worker.js in the compile-js-babel Gulp task, I change the build configuration so that lib/core/brython-runner.worker.js is generated as a bundle by webpack. This is done in the second commit.

Finally, the third commit regenerates files in lib/, which was done via yarn run build.

I hope the changes proposed here do not break other workflows already in use! :-) If they do, what would be the way of using this library in another project using webpack?

Best regards,
Gustavo Sousa

guludo added 3 commits March 6, 2021 10:34
As recommended by `@babel/plugin-transform-runtime`'s documentation:

> (...) and @babel/runtime as a production dependency (since it's for
> the "runtime").

Otherwise other packages trying to use `lib/brython-runner.js` will fail
to find the files necessary for the code generated by the pacakge
`@babel/plugin-transform-runtime`.
Since this file is loaded as a raw string by
`lib/core/brython-runner.js`, calls like
`require("@babel/runtime/...")` will not be resolved by webpack and will
be kept in the resulting string. Because of that, the loaded string will
fail to run in a Web worker. In order to solve this, let us turn
`lib/core/brython-runner.worker.js` into a bundle, so that those
`require()` calls are already resolved during build time.
guludo added a commit to guludo/revealjs-ace-brython that referenced this pull request Mar 8, 2021
Fixes to allow importing the library. Those where already sent to
upstream as pull request:
pythonpad/brython-runner#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant