Skip to content

Commit bb8fe0f

Browse files
committed
move reactjs re-export stubs to their own files
1 parent 9ce3a96 commit bb8fe0f

File tree

12 files changed

+85
-22
lines changed

12 files changed

+85
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# --- Build Artifacts ---
2-
src/reactpy/static/index.js*
2+
src/reactpy/static/*.js*
33
src/reactpy/static/morphdom/
44
src/reactpy/static/pyscript/
55

src/build_scripts/clean_js_dir.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@
1313

1414
# Get the path to the JS source directory
1515
js_src_dir = pathlib.Path(__file__).parent.parent / "js"
16-
17-
# Get the paths to all `dist` folders in the JS source directory
18-
dist_dirs = glob.glob(str(js_src_dir / "**/dist"), recursive=True)
19-
20-
# Get the paths to all `node_modules` folders in the JS source directory
21-
node_modules_dirs = glob.glob(str(js_src_dir / "**/node_modules"), recursive=True)
22-
23-
# Get the paths to all `tsconfig.tsbuildinfo` files in the JS source directory
24-
tsconfig_tsbuildinfo_files = glob.glob(
25-
str(js_src_dir / "**/tsconfig.tsbuildinfo"), recursive=True
26-
)
16+
static_output_dir = pathlib.Path(__file__).parent.parent / "reactpy" / "static"
2717

2818
# Delete all `dist` folders
19+
dist_dirs = glob.glob(str(js_src_dir / "**/dist"), recursive=True)
2920
for dist_dir in dist_dirs:
3021
with contextlib.suppress(FileNotFoundError):
3122
shutil.rmtree(dist_dir)
3223

3324
# Delete all `node_modules` folders
25+
node_modules_dirs = glob.glob(str(js_src_dir / "**/node_modules"), recursive=True)
3426
for node_modules_dir in node_modules_dirs:
3527
with contextlib.suppress(FileNotFoundError):
3628
shutil.rmtree(node_modules_dir)
3729

3830
# Delete all `tsconfig.tsbuildinfo` files
31+
tsconfig_tsbuildinfo_files = glob.glob(
32+
str(js_src_dir / "**/tsconfig.tsbuildinfo"), recursive=True
33+
)
3934
for tsconfig_tsbuildinfo_file in tsconfig_tsbuildinfo_files:
4035
with contextlib.suppress(FileNotFoundError):
4136
os.remove(tsconfig_tsbuildinfo_file)
37+
38+
# Delete all `index-*.js` files
39+
index_js_files = glob.glob(str(static_output_dir / "index-*.js*"))
40+
for index_js_file in index_js_files:
41+
with contextlib.suppress(FileNotFoundError):
42+
os.remove(index_js_file)

src/js/packages/@reactpy/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"license": "MIT",
1414
"name": "@reactpy/app",
1515
"scripts": {
16-
"build": "bun build \"src/index.ts\" --outdir=\"../../../../reactpy/static/\" --minify --sourcemap=\"linked\"",
16+
"build": "bun build \"src/index.ts\" \"src/react.ts\" \"src/react-dom.ts\" \"src/react-jsx-runtime.ts\" --outdir=\"../../../../reactpy/static/\" --minify --sourcemap=\"linked\" --splitting",
1717
"checkTypes": "tsc --noEmit"
1818
}
1919
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
export {
2-
mountReactPy,
3-
React,
4-
ReactDOM,
5-
jsx,
6-
jsxs,
7-
Fragment,
8-
} from "@reactpy/client";
1+
export { mountReactPy } from "@reactpy/client";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import ReactDOM from "preact/compat";
2+
3+
// @ts-ignore
4+
export * from "preact/compat";
5+
6+
export default ReactDOM;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "preact/jsx-runtime";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "preact/compat";
2+
3+
// @ts-ignore
4+
export * from "preact/compat";
5+
6+
export default React;

src/js/packages/@reactpy/app/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"composite": true,
44
"outDir": "dist",
5-
"rootDir": "src"
5+
"rootDir": "src",
6+
"esModuleInterop": true
67
},
78
"extends": "../../../tsconfig.json",
89
"include": ["src"],

src/reactpy/web/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
reactjs_component_from_string,
99
reactjs_component_from_url,
1010
)
11+
from reactpy.web.utils import (
12+
reactjs_import_map,
13+
)
1114

1215
__all__ = [
1316
"export",
@@ -18,4 +21,5 @@
1821
"reactjs_component_from_npm",
1922
"reactjs_component_from_string",
2023
"reactjs_component_from_url",
24+
"reactjs_import_map",
2125
]

src/reactpy/web/module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def reactjs_component_from_npm(
146146
) -> VdomConstructor | list[VdomConstructor]:
147147
"""Import a component from an NPM package.
148148
149+
Is is mandatory to load `reactpy.web.reactjs_import_map()` on your page before using this
150+
function. It is recommended to put this within your HTML <head> content.
151+
149152
Parameters:
150153
package:
151154
The name of the NPM package.

0 commit comments

Comments
 (0)