From fb6d7b566820f193b2318f49c154b225be681e71 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 22 Apr 2019 18:27:40 -0400 Subject: [PATCH] Fix issue installing scoped NPM packages Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 ++- docs/releases/3.2.rst | 1 + mayan/apps/dependencies/javascript.py | 29 +++++++++++++++------------ mayan/apps/dependencies/literals.py | 6 ++++++ 4 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 mayan/apps/dependencies/literals.py diff --git a/HISTORY.rst b/HISTORY.rst index 92db0a068f..68c5effbad 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -110,6 +110,7 @@ * Add mailer use event. * Remove the include fontawesome and download it from the NPMregistry. +* Fix issue installing scoped NPM packages. 3.1.11 (2019-04-XX) =================== @@ -120,7 +121,7 @@ * Add DOCUMENTS_HASH_BLOCK_SIZE to control the size of the file block when calculating a document's checksum. -3.1.10 (2019-04-04) +a3.1.10 (2019-04-04) =================== * Backport test case improvements from the development branch. Add random primary key mixin. Split test case code into mixins. Make the view test diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 02b50a8347..58c897980a 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -142,6 +142,7 @@ Other changes * Add mailer use event. * Remove the include fontawesome and download it from the NPMregistry. +* Fix issue installing scoped NPM packages. Removals -------- diff --git a/mayan/apps/dependencies/javascript.py b/mayan/apps/dependencies/javascript.py index 99bd7986b0..4146ec50e4 100644 --- a/mayan/apps/dependencies/javascript.py +++ b/mayan/apps/dependencies/javascript.py @@ -18,11 +18,10 @@ from django.utils.functional import cached_property from mayan.apps.storage.utils import mkdtemp from .exceptions import DependenciesException - -DEFAULT_REGISTRY_URL = 'http://registry.npmjs.com' -DEFAULT_MODULE_DIRECTORY = 'node_modules' -DEFAULT_PACKAGE_FILENAME = 'package.json' -DEFAULT_LOCK_FILENAME = 'package-lock.json' +from .literals import ( + DEFAULT_LOCK_FILENAME, DEFAULT_MODULE_DIRECTORY, DEFAULT_PACKAGE_FILENAME, + DEFAULT_REGISTRY_URL, +) class NPMPackage(object): @@ -49,21 +48,25 @@ class NPMPackage(object): ) def extract(self): - shutil.rmtree( - path=force_text( - Path( - self.registry.module_directory, self.name - ) - ), ignore_errors=True + download_path = force_text( + Path( + self.registry.module_directory, self.name + ) ) + shutil.rmtree(path=download_path, ignore_errors=True) - with tarfile.open(name=force_text(self.get_tar_file_path()), mode='r') as file_object: + compressed_filepath = force_text(self.get_tar_file_path()) + with tarfile.open(name=compressed_filepath, mode='r') as file_object: file_object.extractall( path=force_text(self.registry.module_directory) ) + target_path = Path(self.registry.module_directory, self.name) + # Scoped packages are nested under a parent directory + # create it to avoid rename errors. + target_path.mkdir(parents=True) Path(self.registry.module_directory, 'package').rename( - target=Path(self.registry.module_directory, self.name) + target=target_path ) def get_algorithm_function(self): diff --git a/mayan/apps/dependencies/literals.py b/mayan/apps/dependencies/literals.py new file mode 100644 index 0000000000..99b360d579 --- /dev/null +++ b/mayan/apps/dependencies/literals.py @@ -0,0 +1,6 @@ +from __future__ import print_function, unicode_literals + +DEFAULT_LOCK_FILENAME = 'package-lock.json' +DEFAULT_PACKAGE_FILENAME = 'package.json' +DEFAULT_MODULE_DIRECTORY = 'node_modules' +DEFAULT_REGISTRY_URL = 'http://registry.npmjs.com'