Skip to content

Commit 2358dda

Browse files
committed
do not assume source suffix in client
1 parent 7036d67 commit 2358dda

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/idom/client/packages/idom-app-react/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getWebSocketEndpoint() {
2626
}
2727

2828
function loadImportSource(source, sourceType) {
29-
return import(sourceType == "NAME" ? `/modules/${source}.js` : source);
29+
return import(sourceType == "NAME" ? `/modules/${source}` : source);
3030
}
3131

3232
function shouldReconnect() {

src/idom/web/module.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
from pathlib import Path
1111
from typing import Any, List, NewType, Optional, Set, Tuple, Union, overload
1212

13-
from idom.config import IDOM_DEBUG_MODE
13+
from idom.config import IDOM_DEBUG_MODE, IDOM_WED_MODULES_DIR
1414
from idom.core.vdom import ImportSourceDict, VdomDictConstructor, make_vdom_constructor
1515

1616
from .utils import (
17+
module_name_suffix,
1718
resolve_module_exports_from_file,
1819
resolve_module_exports_from_url,
19-
url_suffix,
20-
web_module_path,
2120
)
2221

2322

@@ -59,21 +58,21 @@ def module_from_template(
5958
) -> WebModule:
6059
cdn = cdn.rstrip("/")
6160
template_file = (
62-
Path(__file__).parent / "templates" / f"{template}{url_suffix(name)}"
61+
Path(__file__).parent / "templates" / f"{template}{module_name_suffix(name)}"
6362
)
6463

6564
if not template_file.exists():
6665
raise ValueError(f"No template for {template!r} exists")
6766

68-
target_file = web_module_path(name)
67+
target_file = _web_module_path(name)
6968
if not target_file.exists():
7069
target_file.parent.mkdir(parents=True, exist_ok=True)
7170
target_file.write_text(
7271
template_file.read_text().replace("$PACKAGE", name).replace("$CDN", cdn)
7372
)
7473

7574
return WebModule(
76-
source=name,
75+
source=name + module_name_suffix(name),
7776
source_type=NAME_SOURCE,
7877
default_fallback=fallback,
7978
file=target_file,
@@ -93,15 +92,15 @@ def module_from_file(
9392
resolve_exports_depth: int = 5,
9493
) -> WebModule:
9594
source_file = Path(file)
96-
target_file = web_module_path(name)
95+
target_file = _web_module_path(name)
9796
if target_file.exists():
9897
if target_file.resolve() != source_file.resolve():
9998
raise ValueError(f"{name!r} already exists as {target_file.resolve()}")
10099
else:
101100
target_file.parent.mkdir(parents=True, exist_ok=True)
102101
target_file.symlink_to(source_file)
103102
return WebModule(
104-
source=name,
103+
source=name + module_name_suffix(name),
105104
source_type=NAME_SOURCE,
106105
default_fallback=fallback,
107106
file=target_file,
@@ -180,3 +179,9 @@ def _make_export(
180179
fallback=(fallback or web_module.default_fallback),
181180
),
182181
)
182+
183+
184+
def _web_module_path(name: str) -> Path:
185+
name += module_name_suffix(name)
186+
path = IDOM_WED_MODULES_DIR.current.joinpath(*name.split("/"))
187+
return path.with_suffix(path.suffix)

src/idom/web/utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,16 @@
66

77
import requests
88

9-
from idom.config import IDOM_WED_MODULES_DIR
10-
119

1210
logger = logging.getLogger(__name__)
1311

1412

15-
def url_suffix(name: str) -> str:
13+
def module_name_suffix(name: str) -> str:
1614
head, _, tail = name.partition("@") # handle version identifier
1715
version, _, tail = tail.partition("/") # get section after version
1816
return PurePosixPath(tail or head).suffix or ".js"
1917

2018

21-
def web_module_path(name: str) -> Path:
22-
name += url_suffix(name)
23-
path = IDOM_WED_MODULES_DIR.current.joinpath(*name.split("/"))
24-
return path.with_suffix(path.suffix)
25-
26-
2719
def resolve_module_exports_from_file(file: Path, max_depth: int) -> Set[str]:
2820
if max_depth == 0:
2921
logger.warning(f"Did not resolve all exports for {file} - max depth reached")

0 commit comments

Comments
 (0)