Skip to content

Commit 13f5313

Browse files
committed
Switch to ESM and Baseline2024
1 parent b852632 commit 13f5313

File tree

7 files changed

+321
-145
lines changed

7 files changed

+321
-145
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ jobs:
1919
- run: python -m build --sdist --wheel
2020
- run: python -m twine check dist/*
2121

22-
standardjs:
22+
js-lint:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/setup-node@v4
26-
with:
27-
node-version: '14.x'
2826
- uses: actions/checkout@v4
29-
- id: cache-npm
30-
uses: actions/cache@v4
31-
with:
32-
path: ~/.npm
33-
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
34-
restore-keys: |
35-
${{ runner.os }}-node-
3627
- name: Install Node dependencies
3728
run: npm ci
3829
- run: npm run lint:js
3930

40-
lint:
31+
32+
js-test:
33+
runs-on: ubuntu-latest
34+
needs:
35+
- js-lint
36+
steps:
37+
- uses: actions/setup-node@v4
38+
- uses: actions/checkout@v4
39+
- name: Install Node dependencies
40+
run: npm ci
41+
- run: npm test
42+
43+
py-lint:
4144
runs-on: ubuntu-latest
4245
strategy:
4346
matrix:
@@ -59,20 +62,19 @@ jobs:
5962

6063
pytest:
6164
needs:
62-
- lint
63-
- standardjs
65+
- py-lint
6466
- dist
6567
runs-on: ubuntu-latest
6668
strategy:
6769
matrix:
6870
python-version:
69-
- "3.10"
7071
- "3.11"
7172
- "3.12"
73+
- "3.13"
7274
django-version:
73-
- "3.2"
7475
- "4.2"
7576
- "5.0"
77+
- "5.1"
7678
steps:
7779
- uses: actions/checkout@v4
7880
- name: Set up Python ${{ matrix.python-version }}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "tests"
77
},
88
"scripts": {
9-
"test": "standard",
9+
"test": "node --test",
1010
"postinstall": "uglifyjs --compress -o s3file/static/s3file/js/s3file.min.js s3file/static/s3file/js/s3file.js",
1111
"minify": "uglifyjs --compress -o s3file/static/s3file/js/s3file.min.js s3file/static/s3file/js/s3file.js",
1212
"lint:js": "standard"
@@ -23,11 +23,14 @@
2323
],
2424
"author": "Johannes Hoppe <[email protected]>",
2525
"license": "MIT",
26+
"type": "module",
2627
"bugs": {
2728
"url": "https://github.com/codingjoe/django-s3file/issues"
2829
},
2930
"homepage": "https://github.com/codingjoe/django-s3file#readme",
3031
"devDependencies": {
32+
"global-jsdom": "^25.0.0",
33+
"jsdom": "^25.0.1",
3134
"standard": "*",
3235
"uglify-js": "*"
3336
}

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ classifiers = [
2121
"Topic :: Software Development",
2222
"Programming Language :: Python :: 3",
2323
"Programming Language :: Python :: 3 :: Only",
24-
"Programming Language :: Python :: 3.10",
2524
"Programming Language :: Python :: 3.11",
2625
"Programming Language :: Python :: 3.12",
26+
"Programming Language :: Python :: 3.13",
2727
"Framework :: Django",
28-
"Framework :: Django :: 3.2",
2928
"Framework :: Django :: 4.2",
3029
"Framework :: Django :: 5.0",
30+
"Framework :: Django :: 5.1",
3131
]
32-
requires-python = ">=3.9"
32+
requires-python = ">=3.11"
3333
dependencies = [
34-
"django>=2.0",
34+
"django>=4.2",
3535
"django-storages>=1.6",
3636
"boto3",
3737
]

s3file/forms.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import uuid
55

66
from django.conf import settings
7+
from django.templatetags.static import static
78
from django.utils.functional import cached_property
9+
from django.utils.html import format_html, html_safe
810
from storages.utils import safe_join
911

1012
from s3file.middleware import S3FileMiddleware
@@ -13,6 +15,44 @@
1315
logger = logging.getLogger("s3file")
1416

1517

18+
19+
20+
@html_safe
21+
class Asset:
22+
"""A generic asset that can be included in a template."""
23+
24+
def __init__(self, path):
25+
self.path = path
26+
27+
def __eq__(self, other):
28+
return (self.__class__ is other.__class__ and self.path == other.path) or (
29+
other.__class__ is str and self.path == other
30+
)
31+
32+
def __hash__(self):
33+
return hash(self.path)
34+
35+
def __str__(self):
36+
return self.absolute_path(self.path)
37+
38+
def absolute_path(self, path):
39+
if path.startswith(("http://", "https://", "/")):
40+
return path
41+
return static(path)
42+
43+
def __repr__(self):
44+
return f"{type(self).__qualname__}: {self.path!r}"
45+
46+
47+
class ESM(Asset):
48+
"""A JavaScript asset for ECMA Script Modules (ESM)."""
49+
50+
def __str__(self):
51+
path = super().__str__()
52+
template = '<script src="{}" type="module"></script>'
53+
return format_html(template, self.absolute_path(path))
54+
55+
1656
class S3FileInputMixin:
1757
"""FileInput that uses JavaScript to directly upload to Amazon S3."""
1858

@@ -91,4 +131,4 @@ def upload_folder(self):
91131
) # S3 uses POSIX paths
92132

93133
class Media:
94-
js = ("s3file/js/s3file.js" if settings.DEBUG else "s3file/js/s3file.min.js",)
134+
js = [ESM("s3file/js/s3file.js")]

0 commit comments

Comments
 (0)