- 
                Notifications
    You must be signed in to change notification settings 
- Fork 55
CM-40907 - Implement NPM restore support for SCA #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      46365cb
              
                CM-40907 supports restoring npm and refactoring process of generating…
              
              
                naftalicy 0b720e4
              
                CM-40907 fromatting
              
              
                naftalicy a347a62
              
                CM-40907 set secured shell command
              
              
                naftalicy 277d783
              
                CM-40907 fix
              
              
                naftalicy 98bf549
              
                CM-40907 fix
              
              
                naftalicy 4dc7456
              
                CM-40907 add npm timeout
              
              
                naftalicy 5078064
              
                CM-40907 fixed
              
              
                naftalicy a286428
              
                CM-40907 format
              
              
                naftalicy 70176cc
              
                CM-40907 format
              
              
                naftalicy ee7a5c6
              
                CM-40907 format
              
              
                naftalicy 555706e
              
                CM-40907 format
              
              
                naftalicy cbdc7f5
              
                CM-40907 format
              
              
                naftalicy f525cc9
              
                CM-40907 format
              
              
                naftalicy 45942c7
              
                CM-40907 format
              
              
                naftalicy 0a589a9
              
                CM-40907 format
              
              
                naftalicy File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
              Empty file.
          
    
        
          
  
    
      
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  cycode/cli/files_collector/sca/npm/restore_npm_dependencies.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import os | ||
| from typing import List | ||
|  | ||
| import click | ||
|  | ||
| from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies | ||
| from cycode.cli.models import Document | ||
|  | ||
| NPM_PROJECT_FILE_EXTENSIONS = ['.json'] | ||
| NPM_LOCK_FILE_NAME = 'package-lock.json' | ||
| NPM_MANIFEST_FILE_NAME = 'package.json' | ||
|  | ||
|  | ||
| class RestoreNpmDependencies(BaseRestoreDependencies): | ||
| def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None: | ||
| super().__init__(context, is_git_diff, command_timeout) | ||
|  | ||
| def is_project(self, document: Document) -> bool: | ||
| return any(document.path.endswith(ext) for ext in NPM_PROJECT_FILE_EXTENSIONS) | ||
|  | ||
| def get_command(self, manifest_file_path: str) -> List[str]: | ||
| return [ | ||
| 'npm', | ||
| 'install', | ||
| '--prefix', | ||
| self.prepare_manifest_file_path_for_command(manifest_file_path), | ||
| '--package-lock-only', | ||
| '--ignore-scripts', | ||
| '--no-audit', | ||
| ] | ||
|  | ||
| def get_lock_file_name(self) -> str: | ||
| return NPM_LOCK_FILE_NAME | ||
|  | ||
| def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: | ||
| return os.path.isfile(restore_file_path) | ||
|  | ||
| def prepare_manifest_file_path_for_command(self, manifest_file_path: str) -> str: | ||
| return manifest_file_path.replace(os.sep + NPM_MANIFEST_FILE_NAME, '') | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.