diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/npm.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/npm.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/bitbake/lib/bb/fetch2/npm.py b/bitbake/lib/bb/fetch2/npm.py index 15f3f19bc8..e469d66768 100644 --- a/bitbake/lib/bb/fetch2/npm.py +++ b/bitbake/lib/bb/fetch2/npm.py | |||
@@ -42,11 +42,12 @@ from bb.utils import is_semver | |||
42 | 42 | ||
43 | def npm_package(package): | 43 | def npm_package(package): |
44 | """Convert the npm package name to remove unsupported character""" | 44 | """Convert the npm package name to remove unsupported character""" |
45 | # Scoped package names (with the @) use the same naming convention | 45 | # For scoped package names ('@user/package') the '/' is replaced by a '-'. |
46 | # as the 'npm pack' command. | 46 | # This is similar to what 'npm pack' does, but 'npm pack' also strips the |
47 | # leading '@', which can lead to ambiguous package names. | ||
47 | name = re.sub("/", "-", package) | 48 | name = re.sub("/", "-", package) |
48 | name = name.lower() | 49 | name = name.lower() |
49 | name = re.sub(r"[^\-a-z0-9]", "", name) | 50 | name = re.sub(r"[^\-a-z0-9@]", "", name) |
50 | name = name.strip("-") | 51 | name = name.strip("-") |
51 | return name | 52 | return name |
52 | 53 | ||
@@ -90,6 +91,12 @@ class NpmEnvironment(object): | |||
90 | self.d = d | 91 | self.d = d |
91 | 92 | ||
92 | self.user_config = tempfile.NamedTemporaryFile(mode="w", buffering=1) | 93 | self.user_config = tempfile.NamedTemporaryFile(mode="w", buffering=1) |
94 | |||
95 | hn = self._home_npmrc(d) | ||
96 | if hn is not None: | ||
97 | with open(hn, 'r') as hnf: | ||
98 | self.user_config.write(hnf.read()) | ||
99 | |||
93 | for key, value in configs: | 100 | for key, value in configs: |
94 | self.user_config.write("%s=%s\n" % (key, value)) | 101 | self.user_config.write("%s=%s\n" % (key, value)) |
95 | 102 | ||
@@ -102,6 +109,15 @@ class NpmEnvironment(object): | |||
102 | if self.user_config: | 109 | if self.user_config: |
103 | self.user_config.close() | 110 | self.user_config.close() |
104 | 111 | ||
112 | def _home_npmrc(self, d): | ||
113 | """Function to return user's HOME .npmrc file (or None if it doesn't exist)""" | ||
114 | home_npmrc_file = os.path.join(os.environ.get("HOME"), ".npmrc") | ||
115 | if d.getVar("BB_USE_HOME_NPMRC") == "1" and os.path.exists(home_npmrc_file): | ||
116 | bb.warn(f"BB_USE_HOME_NPMRC flag set and valid .npmrc detected - "\ | ||
117 | f"npm fetcher will use {home_npmrc_file}") | ||
118 | return home_npmrc_file | ||
119 | return None | ||
120 | |||
105 | def run(self, cmd, args=None, configs=None, workdir=None): | 121 | def run(self, cmd, args=None, configs=None, workdir=None): |
106 | """Run npm command in a controlled environment""" | 122 | """Run npm command in a controlled environment""" |
107 | with tempfile.TemporaryDirectory() as tmpdir: | 123 | with tempfile.TemporaryDirectory() as tmpdir: |
@@ -165,7 +181,7 @@ class Npm(FetchMethod): | |||
165 | # Using the 'downloadfilename' parameter as local filename | 181 | # Using the 'downloadfilename' parameter as local filename |
166 | # or the npm package name. | 182 | # or the npm package name. |
167 | if "downloadfilename" in ud.parm: | 183 | if "downloadfilename" in ud.parm: |
168 | ud.localfile = npm_localfile(d.expand(ud.parm["downloadfilename"])) | 184 | ud.localfile = npm_localfile(ud.parm["downloadfilename"]) |
169 | else: | 185 | else: |
170 | ud.localfile = npm_localfile(ud.package, ud.version) | 186 | ud.localfile = npm_localfile(ud.package, ud.version) |
171 | 187 | ||