File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
+ import threading
2
3
3
4
from lektor .pluginsystem import Plugin
4
5
from lektor .reporter import reporter
@@ -11,6 +12,7 @@ class WebpackSupportPlugin(Plugin):
11
12
12
13
def __init__ (self , * args , ** kwargs ):
13
14
Plugin .__init__ (self , * args , ** kwargs )
15
+ self .npm_lock = threading .Lock ()
14
16
self .webpack_process = None
15
17
16
18
def is_enabled (self , extra_flags ):
@@ -26,7 +28,11 @@ def run_webpack(self, watch=False):
26
28
def npm_install (self ):
27
29
reporter .report_generic ('Running npm install' )
28
30
webpack_root = os .path .join (self .env .root_path , 'webpack' )
29
- portable_popen (['npm' , 'install' ], cwd = webpack_root ).wait ()
31
+ if self .npm_lock .acquire (False ):
32
+ portable_popen (['npm' , 'install' ], cwd = webpack_root ).wait ()
33
+ else :
34
+ self .npm_lock .acquire ()
35
+ self .npm_lock .release ()
30
36
31
37
def on_server_spawn (self , ** extra ):
32
38
extra_flags = extra .get ("extra_flags" ) or extra .get ("build_flags" ) or {}
Original file line number Diff line number Diff line change 1
1
import py
2
+ import threading
3
+ import time
2
4
3
5
4
6
def test_disabled_by_default (plugin ):
@@ -66,3 +68,19 @@ def test_server_stop(plugin, mocker):
66
68
plugin .webpack_process = mocker .Mock ()
67
69
plugin .on_server_stop ()
68
70
plugin .webpack_process .kill .assert_called_with ()
71
+
72
+
73
+ def test_single_npm_process (plugin , builder , mocker ):
74
+ def pause (* args , ** kwargs ):
75
+ time .sleep (.1 )
76
+ return mocker .DEFAULT
77
+
78
+ mock_popen = mocker .patch ("lektor_webpack_support.portable_popen" )
79
+ mock_popen .side_effect = pause
80
+ thread1 = threading .Thread (target = plugin .npm_install )
81
+ thread2 = threading .Thread (target = plugin .npm_install )
82
+ thread1 .start ()
83
+ thread2 .start ()
84
+ thread1 .join ()
85
+ thread2 .join ()
86
+ assert mock_popen .call_count == 1
You can’t perform that action at this time.
0 commit comments