From d7b463fd0e10f5bb1702af6d76dd39cbd5c60e49 Mon Sep 17 00:00:00 2001 From: Mohamed Akram Date: Tue, 12 Sep 2023 23:21:42 +0400 Subject: [PATCH] fix: support for newer npm and macOS 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. --- .npmrc | 1 + package.json | 4 ++-- pavelib/assets.py | 6 +++--- pavelib/paver_tests/test_servers.py | 2 +- scripts/copy-node-modules.sh | 15 +++++++-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.npmrc b/.npmrc index dcbbc6340e8..b990b45daed 100644 --- a/.npmrc +++ b/.npmrc @@ -3,3 +3,4 @@ fetch-retry-factor = 2 fetch-retry-mintimeout = 10000 fetch-retry-maxtimeout = 60000 progress = false +legacy-peer-deps = true diff --git a/package.json b/package.json index 34167313628..48c08b2c031 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pavelib/assets.py b/pavelib/assets.py index 8f950fe3f64..73b2a5e9631 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -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): @@ -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 ) @@ -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 ), diff --git a/pavelib/paver_tests/test_servers.py b/pavelib/paver_tests/test_servers.py index e9a07b94f0c..e03ff893efd 100644 --- a/pavelib/paver_tests/test_servers.py +++ b/pavelib/paver_tests/test_servers.py @@ -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}" ) diff --git a/scripts/copy-node-modules.sh b/scripts/copy-node-modules.sh index db997da9578..a8dce47d7f8 100755 --- a/scripts/copy-node-modules.sh +++ b/scripts/copy-node-modules.sh @@ -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" \ @@ -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 @@ -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. @@ -87,4 +87,3 @@ set +x log "-------------------------------------------------------------------------------" log " Done copying required assets from node_modules." log "=====================================================================================" -