Skip to content

Commit 9197e8f

Browse files
committed
Add message if proptypes.js not included
1 parent ede084f commit 9197e8f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

@plotly/dash-generator-test-component-typescript/base/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
dict(
1717
relative_package_path='dash_generator_test_component_typescript.js',
1818
namespace='dash_generator_test_component_typescript'
19-
)
19+
),
20+
{
21+
"dev_package_path": "proptypes.js",
22+
"namespace": 'dash_generator_test_component_typescript'
23+
}
2024
]
2125

2226
for _component in __all__:

dash/development/_generate_prop_types.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,26 @@
33
# for them to be able to report invalid prop
44

55
import os
6+
import re
67

78

9+
init_check_re = re.compile("proptypes.js")
10+
11+
missing_init_msg = """
12+
{warning_box}
13+
{title}
14+
{warning_box}
15+
16+
Add the following to `{namespace}/__init__.py` to enable
17+
runtime prop types validation with tsx components:
18+
19+
_js_dist.append(dict(
20+
dev_package_path="proptypes.js",
21+
namespace="{namespace}"
22+
))
23+
24+
"""
25+
826
prop_type_file_template = """// AUTOGENERATED FILE - DO NOT EDIT
927
1028
var PropTypes = window.PropTypes;
@@ -86,6 +104,21 @@ def generate_prop_type(prop_info):
86104
return prop_types[prop_info["name"]](prop_info)
87105

88106

107+
def check_init(namespace):
108+
path = os.path.join(namespace, "__init__.py")
109+
if os.path.exists(path):
110+
with open(path, encoding="utf-8", mode="r") as f:
111+
if not init_check_re.search(f.read()):
112+
title = f"! Missing proptypes.js in `{namespace}/__init__.py` !"
113+
print(
114+
missing_init_msg.format(
115+
namespace=namespace,
116+
warning_box="!" * len(title),
117+
title=title,
118+
)
119+
)
120+
121+
89122
def generate_prop_types(
90123
metadata,
91124
package_name,
@@ -121,3 +154,5 @@ def generate_prop_types(
121154
components_prop_types="\n\n".join(patched)
122155
)
123156
)
157+
158+
check_init(package_name)

dash/development/_r_components_generation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ def generate_js_metadata(pkg_data, project_shortname):
278278
if len(alldist) > 1:
279279
for dep in range(len(alldist)):
280280
curr_dep = alldist[dep]
281-
rpp = curr_dep["relative_package_path"]
281+
rpp = curr_dep.get("relative_package_path", "")
282+
if not rpp:
283+
continue
282284

283285
async_or_dynamic = get_async_type(curr_dep)
284286

0 commit comments

Comments
 (0)