From 096f493c217fa70de17ecd86a1ea783e8d3d9fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20Ka=CC=88mper-Leymann?= Date: Mon, 24 Nov 2025 12:20:00 +0100 Subject: [PATCH 1/2] #4 Rely on user .npmrc instead of project .npmrc --- commands/host/1x-playwright-host-install | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/commands/host/1x-playwright-host-install b/commands/host/1x-playwright-host-install index f27e653..bb54104 100755 --- a/commands/host/1x-playwright-host-install +++ b/commands/host/1x-playwright-host-install @@ -26,9 +26,20 @@ echo -e "Please note this will install playwright on your HOST machine - *not* i echo -e "Creating test-directory $DDEV_APPROOT/test/playwright" mkdir -p $DDEV_APPROOT/test/playwright -# Adjust for 1X-internet private repository -echo -e "${GREEN}Adjust .npmrc${NC}" -pushd $DDEV_APPROOT/test/playwright && echo '@dxp:registry=https://git.1xinternet.de/api/v4/packages/npm/' >> .npmrc ; popd +# Verify global .npmrc file. +if ! grep -F -- "@dxp:registry=" ~/.npmrc >/dev/null 2>&1; then + printf '❌ Error! You need to add the DXP registry to you global .npmrc\n' >&2 + echo "Run this command to add the DXP registry to your global .npmrc:" >&2 + echo "echo '@dxp:registry=https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/' >> ~/.npmrc" >&2 + exit 1 +fi +# Check if GitLab PAT for npm registry exists in ~/.npmrc +if ! grep -E -- "^//git\.1xinternet\.de/.*:_authToken=glpat-" ~/.npmrc >/dev/null 2>&1; then + printf '❌ Error! You need to add your GitLab personal access token to your global .npmrc\n' >&2 + echo "Run this command to add your GitLab token to ~/.npmrc (replace YOUR_TOKEN):" >&2 + echo "echo '//git.1xinternet.de/api/v4/groups/392/-/packages/npm/:_authToken=YOUR_TOKEN' >> ~/.npmrc" >&2 + exit 1 +fi # To install with npx. pushd $DDEV_APPROOT/test/playwright && npx --yes @1xinternet/create-dxp-playwright --lang=Javascript --quiet From 752049a117a0a2ab350df3194a19143d63f6c688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20Ka=CC=88mper-Leymann?= Date: Mon, 24 Nov 2025 12:26:47 +0100 Subject: [PATCH 2/2] #3 On project setup create .nvmrc and build.sh file if not exists --- commands/host/1x-playwright-host-install | 51 +++++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/commands/host/1x-playwright-host-install b/commands/host/1x-playwright-host-install index bb54104..c24704b 100755 --- a/commands/host/1x-playwright-host-install +++ b/commands/host/1x-playwright-host-install @@ -41,8 +41,55 @@ if ! grep -E -- "^//git\.1xinternet\.de/.*:_authToken=glpat-" ~/.npmrc >/dev/nul exit 1 fi -# To install with npx. -pushd $DDEV_APPROOT/test/playwright && npx --yes @1xinternet/create-dxp-playwright --lang=Javascript --quiet +# If no package-lock.json found run initial setup, else execute build.sh. +if [ ! -f $DDEV_APPROOT/test/playwright/package-lock.json ]; then + echo "👀 Existing package-lock.json not found. Creating new test project..." + pushd $DDEV_APPROOT/test/playwright && npx --yes @1xinternet/create-dxp-playwright --lang=Javascript --quiet + node -p 'process.release.lts ? "lts/"+process.release.lts.toLowerCase() : "lts/*"' > .nvmrc + # Create build.sh + if [ ! -f "$DDEV_APPROOT/test/playwright/build.sh" ]; then + cat << 'EOF' > "$DDEV_APPROOT/test/playwright/build.sh" +#!/bin/bash + +# The purpose of this script is to install the test dependencies. + +# Function for error catching. +# @see http://linuxcommand.org/lc3_wss0140.php +error_exit () { + echo "$1" 1>&2 + exit 1 +} + +# Path of this script. +scriptPath=$(dirname $0) +pushd $scriptPath || exit 1 + +# Run nvm version check +if [ -f $HOME/.nvm/nvm.sh ]; then + source $HOME/.nvm/nvm.sh +fi + +# Get the required node version from .nvmrc +required_node_version=$(<.nvmrc) + +# Enforce the version +nvm use $required_node_version || { nvm install -b $required_node_version && nvm use $required_node_version || error_exit "nvm failed."; } + +NODE_ENV=production + +echo "Installing test dependencies..." + +# npm install. +CI='' npm ci --prefer-offline --no-audit || error_exit "npm install failed." +EOF + fi + chmod +x "$DDEV_APPROOT/test/playwright/build.sh" +else + if [ -f "$DDEV_APPROOT/test/playwright/build.sh" ]; then + chmod +x "$DDEV_APPROOT/test/playwright/build.sh" + $DDEV_APPROOT/test/playwright/build.sh || { echo "❌ Error! Build failed"; exit 1; } + fi +fi if [! ddev exec "command -v jq" &> /dev/null ]; then playwright_error = "jq command not found in ddev web container - you'll need to adjust the test/playwright/playwright.config.ts manually!"