forked from openedx-unsupported/tubular
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: install npm private requirements during frontend build #1
Merged
iamsobanjaved
merged 2 commits into
edx:master
from
iamsobanjaved:iamsobanjaved/npm-private
May 7, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import io | ||
import json | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
|
@@ -62,6 +63,7 @@ def install_requirements(self): | |
self.FAIL(1, 'Could not run `npm install` for app {}.'.format(self.app_name)) | ||
|
||
self.install_requirements_npm_aliases() | ||
self.install_requirements_npm_private() | ||
|
||
def install_requirements_npm_aliases(self): | ||
""" Install npm alias requirements for app to build """ | ||
|
@@ -86,6 +88,22 @@ def install_requirements_npm_aliases(self): | |
aliased_installs, self.app_name | ||
)) | ||
|
||
def install_requirements_npm_private(self): | ||
""" Install npm private requirements for app to build """ | ||
npm_private = self.get_npm_private_config() | ||
if npm_private: | ||
install_list = ' '.join(npm_private) | ||
install_private_proc = subprocess.Popen( | ||
[f'npm install {install_list}'], | ||
cwd=self.app_name, | ||
shell=True | ||
) | ||
install_private_proc_return_code = install_private_proc.wait() | ||
if install_private_proc_return_code != 0: | ||
self.FAIL(1, 'Could not run `npm install {}` for app {}.'.format( | ||
install_list, self.app_name | ||
)) | ||
|
||
def get_app_config(self): | ||
""" Combines the common and environment configs APP_CONFIG data """ | ||
app_config = self.common_cfg.get('APP_CONFIG', {}) | ||
|
@@ -102,6 +120,14 @@ def get_npm_aliases_config(self): | |
self.LOG('No npm package aliases defined in config.') | ||
return npm_aliases_config | ||
|
||
def get_npm_private_config(self): | ||
""" Combines the common and environment configs NPM_PRIVATE packages """ | ||
npm_private_config = self.common_cfg.get('NPM_PRIVATE', []) | ||
npm_private_config.extend(self.env_cfg.get('NPM_PRIVATE', [])) | ||
if not npm_private_config: | ||
self.LOG('No npm private packages defined in config.') | ||
return list(set(npm_private_config)) | ||
|
||
def build_app(self, env_vars, fail_msg): | ||
""" Builds the app with environment variable.""" | ||
proc = subprocess.Popen( | ||
|
@@ -127,6 +153,23 @@ def create_version_file(self): | |
except IOError: | ||
self.FAIL(1, 'Could not write to version file for app {}.'.format(self.app_name)) | ||
|
||
def copy_js_config_file_to_app_root(self, app_config, app_name): | ||
""" Creates a copy of env.config.js(x) file to the app root """ | ||
source = app_config.get('JS_CONFIG_FILEPATH') | ||
|
||
# Skip if JS_CONFIG_FILEPATH not defined | ||
if not source: | ||
return | ||
|
||
filename = app_config.get('LOCAL_JS_CONFIG_FILENAME', "env.config.js") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is it worth having one extra check on line 161 if |
||
destination = f"{app_name}/{filename}" | ||
try: | ||
shutil.copyfile(source, destination) | ||
except FileNotFoundError: | ||
self.FAIL(1, f"Could not find '{source}' for copying for app {app_name}.") | ||
except OSError: | ||
self.FAIL(1, f"Could not copy '{source}' to '{destination}', due to destination not writable.") | ||
|
||
|
||
class FrontendDeployer: | ||
""" Utility class for deploying frontends. """ | ||
|
This file contains 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be achieved with
NPM_ALIASES
. I don't think we need to add another implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, the difference between
NPM_ALIASES
andNPM_PRIVATE
is that dependencies inNPM_PRIVATE
are not aliases. If we relied onNPM_ALIASES
, the syntax might be somewhat unnecessarily verbose/confusing to define an NPM alias for the same package name it already has.versus:
NPM_PRIVATE: - "@datadog/browser-rum@2"