Skip to content

Commit

Permalink
fix: support for newer npm and macOS
Browse files Browse the repository at this point in the history
macOS does not support the `--force` flag in `cp`, so use the equivalent `-f`
flag instead. Newer versions of npm also require `legacy-peer-deps` to be set
to true to install successfully. They also no longer have the `npm bin`
command, so use `npm root` instead.
  • Loading branch information
mohd-akram authored and gabor-boros committed Oct 1, 2023
1 parent 4266934 commit d7b463f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ fetch-retry-factor = 2
fetch-retry-mintimeout = 10000
fetch-retry-maxtimeout = 60000
progress = false
legacy-peer-deps = true
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"postinstall": "scripts/copy-node-modules.sh",
"build": "echo 'WARNING: `npm run build` in edx-platform is experimental. Use at your own risk.' && npm run webpack && npm run compile-sass",
"build-dev": "echo 'WARNING: `npm run build-dev` in edx-platform is experimental. Use at your own risk.' && npm run webpack-dev && npm run compile-sass-dev",
"webpack": "NODE_ENV=${NODE_ENV:-production} \"$(npm bin)/webpack\" --config=${WEBPACK_CONFIG_PATH:-webpack.prod.config.js}",
"webpack-dev": "NODE_ENV=development \"$(npm bin)/webpack\" --config=webpack.dev.config.js",
"webpack": "NODE_ENV=${NODE_ENV:-production} webpack --config=${WEBPACK_CONFIG_PATH:-webpack.prod.config.js}",
"webpack-dev": "NODE_ENV=development webpack --config=webpack.dev.config.js",
"compile-sass": "scripts/compile_sass.py --env=${NODE_ENV:-production}",
"compile-sass-dev": "scripts/compile_sass.py --env=development",
"watch": "echo 'WARNING: `npm run watch` in edx-platform is experimental. Use at your own risk.' && { npm run watch-webpack& npm run watch-sass& } && sleep infinity",
Expand Down
6 changes: 3 additions & 3 deletions pavelib/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
COLLECTSTATIC_LOG_DIR_ARG = 'collect_log_dir'

# Webpack command
WEBPACK_COMMAND = 'STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm bin)/webpack {options}'
WEBPACK_COMMAND = 'STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm root)/.bin/webpack {options}'


def get_sass_directories(system, theme_dir=None):
Expand Down Expand Up @@ -680,7 +680,7 @@ def webpack(options):
)
sh(
cmd(
'{environment} $(npm bin)/webpack --config={config_path}'.format(
'{environment} $(npm root)/.bin/webpack --config={config_path}'.format(
environment=environment,
config_path=config_path
)
Expand All @@ -700,7 +700,7 @@ def execute_webpack_watch(settings=None):
static_root_lms, config_path = result
static_root_cms, = Env.get_django_settings(["STATIC_ROOT"], "cms", settings=settings)
run_background_process(
'STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm bin)/webpack {options}'.format(
'STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm root)/.bin/webpack {options}'.format(
options='--watch --config={config_path}'.format(
config_path=config_path
),
Expand Down
2 changes: 1 addition & 1 deletion pavelib/paver_tests/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
EXPECTED_WEBPACK_COMMAND = (
"NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} "
"JS_ENV_EXTRA_CONFIG={js_env_extra_config} "
"$(npm bin)/webpack --config={webpack_config_path}"
"$(npm root)/.bin/webpack --config={webpack_config_path}"
)


Expand Down
15 changes: 7 additions & 8 deletions scripts/copy-node-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ mkdir -p "$vendor_css"
log "Copying studio-frontend JS & CSS from node_modules into vendor directores..."
while read -r -d $'\0' src_file ; do
if [[ "$src_file" = *.css ]] || [[ "$src_file" = *.css.map ]] ; then
cp --force "$src_file" "$vendor_css"
cp -f "$src_file" "$vendor_css"
else
cp --force "$src_file" "$vendor_js"
cp -f "$src_file" "$vendor_js"
fi
done < <(find "$node_modules/@edx/studio-frontend/dist" -type f -print0)

log "Copying certain JS modules from node_modules into vendor directory..."
cp --force \
cp -f \
"$node_modules/backbone.paginator/lib/backbone.paginator.js" \
"$node_modules/backbone/backbone.js" \
"$node_modules/bootstrap/dist/js/bootstrap.bundle.js" \
Expand All @@ -66,8 +66,8 @@ cp --force \

log "Copying certain JS developer modules into vendor directory..."
if [[ "${NODE_ENV:-production}" = development ]] ; then
cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js"
cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js"
cp -f "$node_modules/sinon/pkg/sinon.js" "$vendor_js"
cp -f "$node_modules/squirejs/src/Squire.js" "$vendor_js"
else
# TODO: https://github.com/openedx/edx-platform/issues/31768
# In the old implementation of this scipt (pavelib/assets.py), these two
Expand All @@ -77,8 +77,8 @@ else
# However, in the future, it would be good to only copy them for dev
# builds. Furthermore, these libraries should not be `npm install`ed
# into prod builds in the first place.
cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js" || true # "|| true" means "tolerate errors"; in this case,
cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js" || true # that's "tolerate if these files don't exist."
cp -f "$node_modules/sinon/pkg/sinon.js" "$vendor_js" || true # "|| true" means "tolerate errors"; in this case,
cp -f "$node_modules/squirejs/src/Squire.js" "$vendor_js" || true # that's "tolerate if these files don't exist."
fi

# Done echoing.
Expand All @@ -87,4 +87,3 @@ set +x
log "-------------------------------------------------------------------------------"
log " Done copying required assets from node_modules."
log "====================================================================================="

0 comments on commit d7b463f

Please sign in to comment.