Skip to content

Commit 13db292

Browse files
committed
Add support for string based export objects
1 parent 49fe1a4 commit 13db292

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

django_esm/utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ def parse_package_json(path: Path = None, node_modules: Path = None):
1616
package_json = json.load(f)
1717
name = package_json["name"]
1818
dependencies = package_json.get("dependencies", {})
19+
if path.is_relative_to(node_modules):
20+
base_path = node_modules
21+
else:
22+
base_path = path
1923
for key in ESM_KEYS:
2024
export = package_json.get(key, None)
2125
if export:
2226
try:
2327
for module_name, module in export.items():
24-
yield str(Path(name) / module_name), staticfiles_storage.url(
25-
str((path / module["default"]).relative_to(node_modules))
26-
)
28+
try:
29+
yield str(Path(name) / module_name), staticfiles_storage.url(
30+
str((path / module["default"]).relative_to(base_path))
31+
)
32+
except TypeError:
33+
yield str(Path(name) / module_name), staticfiles_storage.url(
34+
str((path / module).relative_to(base_path))
35+
)
2736
except AttributeError:
2837
yield name, staticfiles_storage.url(
29-
str((path / export).relative_to(node_modules))
38+
str((path / export).relative_to(base_path))
3039
)
3140
for dep_name, dep_version in dependencies.items():
3241
yield from parse_package_json(node_modules / dep_name, node_modules)

tests/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"name": "django-esm",
3+
"exports": {
4+
".": "./js/index.js",
5+
"./components":{
6+
"import": "./js/components/index.js",
7+
"default": "./js/components/index.js"
8+
}
9+
},
310
"dependencies": {
411
"htmx.org": "^1.9.9",
512
"lit": "^3.1.0"

tests/testapp/static/js/components/index.js

Whitespace-only changes.

tests/testapp/static/js/index.js

Whitespace-only changes.

0 commit comments

Comments
 (0)