Skip to content

Commit b3d73d9

Browse files
authored
Try to install with yarn if npm failed (#267)
1 parent 6b2aa89 commit b3d73d9

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In this user guide, you can see how to install the FOSSLight Dependency Scanner
3131
</thead>
3232
<tbody>
3333
<tr>
34-
<td rowspan="2">Javascript</td>
34+
<td rowspan="3">Javascript</td>
3535
<td>Npm</td>
3636
<td>package.json</td>
3737
<td>O</td>
@@ -44,6 +44,13 @@ In this user guide, you can see how to install the FOSSLight Dependency Scanner
4444
<td>O</td>
4545
<td>O</td>
4646
<td>O</td>
47+
</tr>
48+
<tr>
49+
<td>Yarn</td>
50+
<td>package.json</td>
51+
<td>O</td>
52+
<td>O</td>
53+
<td>O</td>
4754
</tr>
4855
<tr>
4956
<td rowspan="2">Java</td>

src/fosslight_dependency/_analyze_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def analyze_dependency(package_manager_name, input_dir, output_dir, pip_activate
3535

3636
if package_manager_name == const.PYPI:
3737
package_manager = Pypi(input_dir, output_dir, pip_activate_cmd, pip_deactivate_cmd)
38-
elif package_manager_name == const.NPM:
38+
elif package_manager_name == const.NPM or package_manager_name == const.YARN:
3939
package_manager = Npm(input_dir, output_dir)
4040
elif package_manager_name == const.MAVEN:
4141
package_manager = Maven(input_dir, output_dir, output_custom_dir)

src/fosslight_dependency/_help.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Maven (Java)
1717
NPM (Node.js)
1818
PNPM (Node.js)
19+
Yarn (Node.js)
1920
PIP (Python)
2021
Pub (Dart with flutter)
2122
Cocoapods (Swift/Obj-C)
@@ -33,7 +34,7 @@
3334
-v\t\t\t\t Print the version of the script.
3435
-m <package_manager>\t Enter the package manager.
3536
\t(npm, maven, gradle, pypi, pub, cocoapods, android, swift, carthage,
36-
\t go, nuget, helm, unity, cargo, pnpm)
37+
\t go, nuget, helm, unity, cargo, pnpm, yarn)
3738
-p <input_path>\t\t Enter the path where the script will be run.
3839
-e <exclude_path>\t\t Enter the path where the analysis will not be performed.
3940
-o <output_path>\t\t Output path

src/fosslight_dependency/constant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
UNITY = 'unity'
2626
CARGO = 'cargo'
2727
PNPM = 'pnpm'
28+
YARN = 'yarn'
2829

2930
# Supported package name and manifest file
3031
SUPPORT_PACKAE = {

src/fosslight_dependency/package_manager/Npm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ def start_license_checker(self):
5353
self.flag_tmp_node_modules = True
5454
cmd_ret = subprocess.call(npm_install_cmd, shell=True)
5555
if cmd_ret != 0:
56-
logger.error(f"{npm_install_cmd} returns an error")
57-
return False
56+
logger.warning(f"{npm_install_cmd} returns an error. Trying yarn as fallback...")
57+
yarn_install_cmd = 'yarn install --production --ignore-scripts'
58+
cmd_ret = subprocess.call(yarn_install_cmd, shell=True)
59+
if cmd_ret != 0:
60+
logger.error(f"Both {npm_install_cmd} and {yarn_install_cmd} failed")
61+
return False
62+
else:
63+
logger.info(f"Successfully executed {yarn_install_cmd}")
5864

5965
# customized json file for obtaining specific items with license-checker
6066
self.make_custom_json(self.tmp_custom_json)

src/fosslight_dependency/run_dependency_scanner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
207207
autodetect = True
208208
found_package_manager = {}
209209
if package_manager:
210+
scan_item.set_cover_comment(f"Manual detect mode (-m {package_manager})")
211+
if package_manager == const.YARN:
212+
package_manager = const.NPM
210213
autodetect = False
211214
support_packagemanager = list(const.SUPPORT_PACKAE.keys())
212215

@@ -221,7 +224,6 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
221224
manifest_file_name.extend(value)
222225
else:
223226
manifest_file_name.append(value)
224-
scan_item.set_cover_comment(f"Manual detect mode (-m {package_manager})")
225227
else:
226228
manifest_file_name = []
227229

0 commit comments

Comments
 (0)