You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want users to be able to use ReactJS components from NPM in a similar level of complexity to a pip install. This will require developing ReactPy Package Manager. This tool will pull packages down using NPM, statically build/analyze them, then auto-generate a Python file containing the usable interface.
For users that really want to dive into the nitty-gritty of writing their components in JavaScript, we will re-engineer the JavaScript API to leverage any standard JavaScript tooling. Ideally, it should feel exactly like writing a normal ReactJS component.
Current Situation
Right now there's a few factors that make using ReactJS components a bit awkward/infeasible
It's not reasonable manually translate every ReactJS component to a Python.
module_from_template can cause ReactJS version mismatches resulting in the imported library not working
JavaScript Module API feels awkward to use.
Proposed Actions
We need to investigate how to best automatically interface with, let's say, the top 100 React libraries on NPM.
The main question is, how do we make sure things written for ReactJS are compatible with ReactPy? This will involve is having to rethink our compatibility layer for the following:
Hooks
Events
Components
Design Concept
Create a ReactPy build step can automatically generate Python wrappers of JavaScript functionality. Ideally, this machine generated Python would also include type hints that are automatically inferred from the JavaScript code. We can potentially deduce type hints using a JavaScript AST parser.
A generated Python file for a react-bootstrap Card could potentially look something like this:
Run JavaScript client side, and figure out how to communicate info back to the server
Run JavaScript client side, but have the user only be able to interact with that code with other client-side code
Run JavaScript server side. This will likely be transpiled into WASM and run within python.
The NPM Dependency Issue
For ease of use, we should bundle precompiled NPM binaries within ReactPy Package Manager. This would be far less janky than requiring the user to externally install NPM. We may also want to consider using bun instead of NPM.
We should probably follow the same precedence as Playwright/Selenium. If the user tries to use reactpy build, we should first check if our NPM binary has been installed. If it hasn't, we will tell the user to run a reactpy download-npm command.
The "children as props" issue
As mentioned in #989, we need to spend some additional thought on how to convert JavaScript components to Python components.
This is due to libraries like MaterialUI existing that have components as props. This might involve inventing some way to serialize React components in a reproducible way.
The CLI should be accessible within the reactpy <command> namespace. All package manager commands will print out an error if reactpy-package-manager is not installed.
build command
User generated packages will need a package.json, formatted in NPM parseable format
Users must declare their own dependencies within a package.json
reactpy build --all will auto discover all package.json files that have a reactpy attribute within them.
reactpy build <DIR> will build a single package.
Docs will show custom components using ReactJS, not Preact
If we see workspaces in package.json, throw an error.
We will output a __init__.py into the given directory, unless a different output file is specified (in package.json)
Use npm and automatically create node_modules/.gitignore containing *
Always recreate node_modules/.gitignore if it does not exist
We should hide our output in node_modules/@reactpy/_build/output.js
Add settings within package.json:reactpy such as output_path, node_modules_gitignore
The two mandatory package.json fields are main and reactpy
install command
Should have a --target-dir option (we should make sure to name it the same as the pip's equivalent)
Should have a --exports=... option to limit what gets built
Should create a python module via cookiecutter.
Installed modules are accessible within Python via reactjs.pkg_name
Should automatically create a top level package.json and start populate it for every installed package
uninstall command
uninstall command should have an --all option
npm command
npm command is a direct passthrough of our local node npm instance
download-npm command
Downloads node to the current environment, similar to how selenium downloads Chromium.
If called a second time, will prompt the user if they want to delete then redownload
The text was updated successfully, but these errors were encountered:
Archmonger
changed the title
Better compatibility with React modules
Implement an IDOM build step (better compatibility with React modules)
Aug 17, 2022
rmorshea
changed the title
Implement an IDOM build step (better compatibility with React modules)
Implement a ReactPy build tool (better compatibility with React modules)
May 24, 2023
Archmonger
changed the title
Implement a ReactPy build tool (better compatibility with React modules)
Better compatibility with ReactJS Packages
Jun 5, 2023
TLDR
We want users to be able to use ReactJS components from NPM in a similar level of complexity to a
pip install
. This will require developing ReactPy Package Manager. This tool will pull packages down using NPM, statically build/analyze them, then auto-generate a Python file containing the usable interface.For users that really want to dive into the nitty-gritty of writing their components in JavaScript, we will re-engineer the JavaScript API to leverage any standard JavaScript tooling. Ideally, it should feel exactly like writing a normal ReactJS component.
Current Situation
Right now there's a few factors that make using ReactJS components a bit awkward/infeasible
module_from_template
can cause ReactJS version mismatches resulting in the imported library not workingProposed Actions
We need to investigate how to best automatically interface with, let's say, the top 100 React libraries on NPM.
The main question is, how do we make sure things written for ReactJS are compatible with ReactPy? This will involve is having to rethink our compatibility layer for the following:
Design Concept
Create a ReactPy build step can automatically generate Python wrappers of JavaScript functionality. Ideally, this machine generated Python would also include type hints that are automatically inferred from the JavaScript code. We can potentially deduce type hints using a JavaScript AST parser.
A generated Python file for a react-bootstrap Card could potentially look something like this:
How to handle JavaScript
We have a few ways we can handle JS modules:
The NPM Dependency Issue
For ease of use, we should bundle precompiled NPM binaries within ReactPy Package Manager. This would be far less janky than requiring the user to externally install NPM. We may also want to consider using bun instead of NPM.
We should probably follow the same precedence as Playwright/Selenium. If the user tries to use
reactpy build
, we should first check if our NPM binary has been installed. If it hasn't, we will tell the user to run areactpy download-npm
command.The "children as props" issue
As mentioned in #989, we need to spend some additional thought on how to convert JavaScript components to Python components.
This is due to libraries like MaterialUI existing that have components as props. This might involve inventing some way to serialize React components in a reproducible way.
react-serialize
could potentially work for this.Command Line Interface
The CLI should be accessible within the
reactpy <command>
namespace. All package manager commands will print out an error ifreactpy-package-manager
is not installed.build
commandpackage.json
, formatted in NPM parseable formatdependencies
within apackage.json
reactpy build --all
will auto discover allpackage.json
files that have areactpy
attribute within them.reactpy build <DIR>
will build a single package.workspaces
inpackage.json
, throw an error.__init__.py
into the given directory, unless a different output file is specified (in package.json)npm
and automatically createnode_modules/.gitignore
containing*
node_modules/.gitignore
if it does not existnode_modules/@reactpy/_build/output.js
package.json:reactpy
such asoutput_path
,node_modules_gitignore
package.json
fields aremain
andreactpy
install
command--target-dir
option (we should make sure to name it the same as the pip's equivalent)--exports=...
option to limit what gets builtreactjs.pkg_name
package.json
and start populate it for every installed packageuninstall
commanduninstall
command should have an--all
optionnpm
commandnpm
command is a direct passthrough of our local nodenpm
instancedownload-npm
commandnode
to the current environment, similar to howselenium
downloads Chromium.The text was updated successfully, but these errors were encountered: