-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Make NPM post-processing agnostic to node_modules location #31519
Closed
kdmccormick
wants to merge
3
commits into
openedx:master
from
kdmccormick:kdmccormick/no-node-modules-links
Closed
Changes from all commits
Commits
Show all changes
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
xmodule | ||
edx-ui-toolkit |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/bin/sh | ||
# | ||
# Copy certain node_modules to other places in edx-platform. | ||
# | ||
# Run this from the root of edx-platform, after node_modules are installed, | ||
# but before trying to compile static assets. | ||
# | ||
# Background: | ||
# | ||
# Earlier in edx-platform's development, JS and CSS dependencies were | ||
# committed directly (a.k.a. "vendored in") to the platform. | ||
# Later on, as NPM became popular, new edx-platform frontends began | ||
# using package.json to specify dependencies, and of course those new | ||
# dependencies were installed into node_modules. | ||
# | ||
# Unfortunately, not all old pages were updated to use package.json. | ||
# However, rather then continuing to vendor-in the dependencies for | ||
# the old pages, it was decided to copy the required files from | ||
# node_modules to the old "vendor" directories. That way, the old | ||
# pages' dependencies would remain synced with the newer pages' | ||
# dependencies. That is what this script does. | ||
# | ||
# This was formerly implemented in pavelib/assets.py. As we are moving | ||
# away from paver, it was reimplemented in this shell script. | ||
# | ||
# NOTE: This uses plain POSIX `sh` instead of `bash` for the purpose of | ||
# maximum portability. | ||
|
||
USAGE="Usage: $0 [ (-n|--node-modules) NODE_MODULES_PATH ]" | ||
|
||
# By default, we look for node_modules in the current directory. | ||
# Some Open edX distributions may want node_modules to be located somewhere | ||
# else, so we let this be configured with -n|--node-modules. | ||
NODE_MODULES_PATH="./node_modules" | ||
|
||
# Vendor destination paths for assets. | ||
# These are not configurable yet, but that could be changed if necessary. | ||
JS_VENDOR_PATH="./common/static/common/js/vendor" | ||
CSS_VENDOR_PATH="./common/static/common/css/vendor" | ||
EDX_UI_TOOLKIT_VENDOR_PATH="./common/static/edx-ui-toolkit" | ||
|
||
# Enable stricter sh behavior. | ||
set -eu | ||
|
||
# Parse options. | ||
while [ $# -gt 0 ]; do | ||
case $1 in | ||
-n|--node-modules) | ||
shift | ||
if [ $# -eq 0 ]; then | ||
echo "Error: Missing value for -n/--node-modules" | ||
echo "$USAGE" | ||
exit 1 | ||
fi | ||
NODE_MODULES_PATH="$1" | ||
shift | ||
;; | ||
--help) | ||
echo "$USAGE" | ||
exit 0 | ||
;; | ||
*) | ||
echo "Error: Unrecognized option: $1" | ||
echo "$USAGE" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
echo "-------------------------------------------------------------------------" | ||
echo "Copying shared node_modules to 'vendor' directories..." | ||
echo " Working directory == '$(pwd)'" | ||
echo " NODE_MODULES_PATH == '$NODE_MODULES_PATH'" | ||
echo " CSS_VENDOR_PATH == '$CSS_VENDOR_PATH'" | ||
echo " JS_VENDOR_PATH == '$JS_VENDOR_PATH'" | ||
echo " EDX_UI_TOOLKIT_VENDOR_PATH == '$EDX_UI_TOOLKIT_VENDOR_PATH'" | ||
echo "-------------------------------------------------------------------------" | ||
|
||
# Input validation | ||
if ! [ -d "$NODE_MODULES_PATH" ]; then | ||
echo "Error: not a directory: $NODE_MODULES_PATH" | ||
exit 1 | ||
fi | ||
if ! [ -d ./common ]; then | ||
echo "Error: not a directory: ./common" | ||
echo "Hint: $0 must be run from the root of the edx-platform directory!" | ||
exit 1 | ||
fi | ||
|
||
# Echo lines back to user. | ||
set -x | ||
|
||
# Create vendor directories. | ||
mkdir -p "$JS_VENDOR_PATH" | ||
mkdir -p "$CSS_VENDOR_PATH" | ||
mkdir -p "$EDX_UI_TOOLKIT_VENDOR_PATH" | ||
|
||
# Copy studio-frontend assets into into vendor directory. | ||
find "$NODE_MODULES_PATH/@edx/studio-frontend/dist" \ | ||
-type f \! -name \*.css \! -name \*.css.map -print0 | \ | ||
xargs --null cp --target-directory="$JS_VENDOR_PATH" | ||
find "$NODE_MODULES_PATH/@edx/studio-frontend/dist" \ | ||
-type f \( -name \*.css -o -name \*.css.map \) -print0 | \ | ||
xargs --null cp --target-directory="$CSS_VENDOR_PATH" | ||
|
||
# Copy edx-ui-toolkit's JS to into its own special directory. | ||
# Note: $EDX_UI_TOOLKIT_VENDOR_PATH/js used to be a git-managed symlink. | ||
# To avoid confusing behavior for folks who still have the js/ symlink | ||
# hanging around in their repo, the safest thing to do is to remove | ||
# the target js/ before copying in js/ fresh from the source. | ||
rm -rf "$EDX_UI_TOOLKIT_VENDOR_PATH/js" | ||
cp --recursive \ | ||
"$NODE_MODULES_PATH/edx-ui-toolkit/src/js" \ | ||
"$EDX_UI_TOOLKIT_VENDOR_PATH" | ||
|
||
# Copy certain node_modules scripts into "vendor" directory. | ||
cp --force \ | ||
"$NODE_MODULES_PATH/backbone.paginator/lib/backbone.paginator.js" \ | ||
"$NODE_MODULES_PATH/backbone/backbone.js" \ | ||
"$NODE_MODULES_PATH/bootstrap/dist/js/bootstrap.bundle.js" \ | ||
"$NODE_MODULES_PATH/hls.js/dist/hls.js" \ | ||
"$NODE_MODULES_PATH/jquery-migrate/dist/jquery-migrate.js" \ | ||
"$NODE_MODULES_PATH/jquery.scrollto/jquery.scrollTo.js" \ | ||
"$NODE_MODULES_PATH/jquery/dist/jquery.js" \ | ||
"$NODE_MODULES_PATH/moment-timezone/builds/moment-timezone-with-data.js" \ | ||
"$NODE_MODULES_PATH/moment/min/moment-with-locales.js" \ | ||
"$NODE_MODULES_PATH/picturefill/dist/picturefill.js" \ | ||
"$NODE_MODULES_PATH/requirejs/require.js" \ | ||
"$NODE_MODULES_PATH/underscore.string/dist/underscore.string.js" \ | ||
"$NODE_MODULES_PATH/underscore/underscore.js" \ | ||
"$NODE_MODULES_PATH/which-country/index.js" \ | ||
"$JS_VENDOR_PATH" | ||
|
||
# Copy certain node_modules developer scripts into "vendor" directory. | ||
# Since they're just developer libraries, they might not exist in a production build pipeline. | ||
# So, let the error pass silently (`... || true`) if the copy fails. | ||
cp --force "$NODE_MODULES_PATH/sinon/pkg/sinon.js" "$JS_VENDOR_PATH" || true | ||
cp --force "$NODE_MODULES_PATH/squirejs/src/Squire.js" "$JS_VENDOR_PATH" || true | ||
|
||
# Stop echoing. | ||
set +x | ||
|
||
echo "-------------------------------------------------------------------------" | ||
echo "Done copying shared node_modules." | ||
echo "-------------------------------------------------------------------------" |
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.
Should this
process_npm_assets
function now call theprocess-npm-assets.sh
script? It seems to me that we would need this to be backward compatible.As a side note, the
openedx-assets.py
script in Tutor calls theprocess_npm_assets
function, so we would have to modify it if the function does not call the bash script: https://github.com/overhangio/tutor/blob/b903c69fac95e797532288d4e6f60530faf1db94/tutor/templates/build/openedx/bin/openedx-assets#L117There 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.
It does, see this line of the diff. And yes, goal is backwards-compatibility.
For what it's worth, I do plan to change Tutor's openedx-assets.py script to call this bash script directly--we will need to do so in order to pass in the
--node-modules=/openedx/node_modules
. That change is not necessary in order to merge this current PR, though.