From 29e570df37ecdaac8e80db75b357ec3c7a5fa186 Mon Sep 17 00:00:00 2001 From: Ramon Fincken Date: Sat, 7 Jun 2025 10:46:19 +0200 Subject: [PATCH] [TASK] first attempt to reduce NPM need bu using the Core nightly build as source of truth for CSS and JS files --- .env.default | 3 +++ patch_gruntfile.sh | 18 ++++++++++++++++++ prepare.php | 11 ++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 patch_gruntfile.sh diff --git a/.env.default b/.env.default index 84de84c..e9c0af7 100644 --- a/.env.default +++ b/.env.default @@ -24,6 +24,9 @@ export WPT_REPORT_API_KEY= # (Optionally) define an alternate reporting URL export WPT_REPORT_URL= +# Path to the WP Core nightly files +export WPT_CORE_NIGHTLY_DIR=/tmp/nightly + # Credentials for a database that can be written to and reset. # WARNING!!! This database will be destroyed between tests. Only use safe database credentials. # Please note that you must escape _or_ refrain from using # as special character in your credentials. diff --git a/patch_gruntfile.sh b/patch_gruntfile.sh new file mode 100644 index 0000000..0736af4 --- /dev/null +++ b/patch_gruntfile.sh @@ -0,0 +1,18 @@ +sourcefile=$1 +awk ' +BEGIN { inside = 0 } +/grunt\.registerTask\(.*'\''build:(js|css)'\''/ { + inside = 1 + match($0, /'\''build:(js|css)'\''/, m) + task = m[1] + print "grunt.registerTask('\''build:" task "'\'', function() {" + print " grunt.log.writeln('\''Main task build:" task " is not used'\'');" + print "});" + next +} +inside && /\);/ { + inside = 0 + next +} +!inside +' $sourcefile > Gruntfile.tmp && mv Gruntfile.tmp $sourcefile diff --git a/prepare.php b/prepare.php index 2948b70..0253fdd 100644 --- a/prepare.php +++ b/prepare.php @@ -126,7 +126,16 @@ 'cd ' . escapeshellarg( $WPT_PREPARE_DIR . '/tests/phpunit/data/plugins/' ) . '; unzip wordpress-importer.zip; rm wordpress-importer.zip', // Change directory to the preparation directory, install npm dependencies, and build the project. - 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build' + /// 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build', + + // Install NPM but skip the css and js build step + 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && npm install && bash patch_gruntfile.sh Gruntfile.js && npm run build --force', + + // Refresh nightly + 'mkdir -p ' . escapeshellarg( $WPT_CORE_NIGHTLY_DIR ) . ' && cd ' . escapeshellarg( $WPT_CORE_NIGHTLY_DIR ) . ' && wp-cli core download --force --version=nightly', + + // Now rsync the CSS and JS files from nightly + 'cd ' . escapeshellarg( $WPT_CORE_NIGHTLY_DIR ) . ' && rsync -zarv --include="*/" --include="*.js" --include="*.css" --exclude="*" --include="*.js" --include="*.css" . '.. escapeshellarg( $WPT_PREPARE_DIR ) . '/build', ) );