Skip to content

Commit 6ab3f08

Browse files
committed
Adds --no-package-lock parameter to manage.py tailwind install
1 parent 0de1c95 commit 6ab3f08

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

example/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ENV DEBUG="${DEBUG}" \
2929

3030
COPY --chown=python:python . .
3131

32-
RUN SECRET_KEY=nothing python manage.py tailwind install --no-input;
32+
RUN SECRET_KEY=nothing python manage.py tailwind install --no-package-lock --no-input;
3333
RUN SECRET_KEY=nothing python manage.py tailwind build --no-input;
3434
RUN SECRET_KEY=nothing python manage.py collectstatic --no-input;
3535

src/tailwind/management/commands/tailwind.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def add_arguments(self, parser):
4040
"--app-name",
4141
help="Sets default app name on Tailwind project initialization",
4242
)
43+
parser.add_argument(
44+
"--no-package-lock",
45+
action="store_true",
46+
help="Disables package-lock.json creation during install",
47+
)
4348

4449
def validate_app(self):
4550
try:
@@ -94,7 +99,11 @@ def handle_init_command(self, **options):
9499
raise CommandError(err)
95100

96101
def handle_install_command(self, **options):
97-
self.npm_command("install")
102+
args = ["install"]
103+
if options["no_package_lock"]:
104+
args.append("--no-package-lock")
105+
106+
self.npm_command(*args)
98107

99108
def handle_build_command(self, **options):
100109
self.npm_command("run", "build")

src/tailwind/npm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def cd(self, cwd):
2121

2222
def command(self, *args):
2323
try:
24+
print([self.npm_bin_path] + list(args))
2425
subprocess.run([self.npm_bin_path] + list(args), cwd=self.cwd, check=True)
2526
return True
2627
except subprocess.CalledProcessError:

tests/test_cli.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import os
22
import uuid
33

4+
import pytest
45
from django.core.management import call_command
56

67
from tailwind.utils import get_app_path
78

89
from .conftest import cleanup_theme_app_dir
910

1011

11-
def test_tailwind_install_and_build(settings):
12+
@pytest.mark.parametrize("no_package_lock", [True, False])
13+
def test_tailwind_install_and_build(no_package_lock, settings):
1214
app_name = f'test_theme_{str(uuid.uuid1()).replace("-", "_")}'
1315

1416
call_command("tailwind", "init", "--app-name", app_name, "--no-input")
@@ -21,7 +23,20 @@ def test_tailwind_install_and_build(settings):
2123
tailwind_config_path = os.path.join(get_app_path(app_name), "static_src", "tailwind.config.js")
2224
assert os.path.isfile(tailwind_config_path), "tailwind.config.js is present"
2325

24-
call_command("tailwind", "install")
26+
if no_package_lock:
27+
call_command("tailwind", "install", "--no-package-lock")
28+
else:
29+
call_command("tailwind", "install")
30+
31+
package_json_path = os.path.join(get_app_path(app_name), "static_src", "package.json")
32+
assert os.path.isfile(package_json_path), "Tailwind has created package.json file"
33+
34+
package_lock_json_path = os.path.join(get_app_path(app_name), "static_src", "package-lock.json")
35+
if no_package_lock:
36+
assert not os.path.isfile(package_lock_json_path), "Tailwind has not created package-lock.json file"
37+
else:
38+
assert os.path.isfile(package_lock_json_path), "Tailwind has created package-lock.json file"
39+
2540
assert os.path.isdir(
2641
os.path.join(get_app_path(app_name), "static_src", "node_modules")
2742
), "Tailwind has been installed from npm"

0 commit comments

Comments
 (0)