Skip to content

Commit 8d97f14

Browse files
authored
Merge pull request #76 from WebDevStudios/hotfix/posinstall-script-conditional
Limit jq usage in cursorrules to non-CI environments
2 parents 158a93e + 675d05e commit 8d97f14

File tree

2 files changed

+106
-81
lines changed

2 files changed

+106
-81
lines changed

scripts/test-update-cursorrules.sh

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,65 @@ print_result() {
2424
# Test 1: Platform config format (current format)
2525
print_test "Testing platform config format..."
2626
echo '{"config": {"platform": {"php": "8.2"}}}' > test-composer.json
27-
PHP_VERSION=$(jq -r '.config.platform.php // empty' test-composer.json 2>/dev/null)
28-
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
29-
if [ "$PHP_VERSION" = "8.2" ]; then
30-
print_result 0 "Platform config format works"
27+
# Check if running in CI
28+
if [ "$CI" = "true" ]; then
29+
echo "CI environment detected. Skipping jq-dependent logic."
3130
else
32-
print_result 1 "Platform config format failed: got $PHP_VERSION"
31+
PHP_VERSION=$(jq -r '.config.platform.php // empty' test-composer.json 2>/dev/null)
32+
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
33+
if [ "$PHP_VERSION" = "8.2" ]; then
34+
print_result 0 "Platform config format works"
35+
else
36+
print_result 1 "Platform config format failed: got $PHP_VERSION"
37+
fi
3338
fi
3439

3540
# Test 2: Require-dev format
3641
print_test "Testing require-dev format..."
3742
echo '{"require-dev": {"php": ">=8.2"}}' > test-composer.json
38-
PHP_VERSION=$(jq -r '.require-dev.php // empty' test-composer.json 2>/dev/null)
39-
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
40-
if [ "$PHP_VERSION" = "8.2" ]; then
41-
print_result 0 "Require-dev format works"
43+
# Check if running in CI
44+
if [ "$CI" = "true" ]; then
45+
echo "CI environment detected. Skipping jq-dependent logic."
4246
else
43-
print_result 1 "Require-dev format failed: got $PHP_VERSION"
47+
PHP_VERSION=$(jq -r '.require-dev.php // empty' test-composer.json 2>/dev/null)
48+
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
49+
if [ "$PHP_VERSION" = "8.2" ]; then
50+
print_result 0 "Require-dev format works"
51+
else
52+
print_result 1 "Require-dev format failed: got $PHP_VERSION"
53+
fi
4454
fi
4555

4656
# Test 3: Require format
4757
print_test "Testing require format..."
4858
echo '{"require": {"php": "^8.2.0"}}' > test-composer.json
49-
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
50-
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
51-
if [ "$PHP_VERSION" = "8.2.0" ]; then
52-
print_result 0 "Require format works"
59+
# Check if running in CI
60+
if [ "$CI" = "true" ]; then
61+
echo "CI environment detected. Skipping jq-dependent logic."
5362
else
54-
print_result 1 "Require format failed: got $PHP_VERSION"
63+
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
64+
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
65+
if [ "$PHP_VERSION" = "8.2.0" ]; then
66+
print_result 0 "Require format works"
67+
else
68+
print_result 1 "Require format failed: got $PHP_VERSION"
69+
fi
5570
fi
5671

5772
# Test 4: Simple version constraint
5873
print_test "Testing simple version constraint..."
5974
echo '{"require": {"php": "~8.2.0"}}' > test-composer.json
60-
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
61-
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
62-
if [ "$PHP_VERSION" = "8.2.0" ]; then
63-
print_result 0 "Simple version constraint works"
75+
# Check if running in CI
76+
if [ "$CI" = "true" ]; then
77+
echo "CI environment detected. Skipping jq-dependent logic."
6478
else
65-
print_result 1 "Simple version constraint failed: got $PHP_VERSION"
79+
PHP_VERSION=$(jq -r '.require.php // empty' test-composer.json 2>/dev/null)
80+
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
81+
if [ "$PHP_VERSION" = "8.2.0" ]; then
82+
print_result 0 "Simple version constraint works"
83+
else
84+
print_result 1 "Simple version constraint failed: got $PHP_VERSION"
85+
fi
6686
fi
6787

6888
# Cleanup

scripts/update-cursorrules.sh

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -43,67 +43,72 @@ if [ ! -f "package.json" ]; then
4343
print_warning "package.json not found in current directory"
4444
fi
4545

46-
# Extract PHP version from composer.json
47-
print_status "Extracting PHP version from composer.json..."
48-
49-
# Try to get PHP version from platform config first
50-
PHP_VERSION=$(jq -r '.["config"]["platform"]["php"] // empty' composer.json 2>/dev/null)
51-
52-
# If not found in platform config, try require-dev
53-
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
54-
PHP_VERSION=$(jq -r '.["require-dev"]["php"] // empty' composer.json 2>/dev/null)
55-
fi
56-
57-
# If still not found, try require
58-
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
59-
PHP_VERSION=$(jq -r '.["require"]["php"] // empty' composer.json 2>/dev/null)
60-
fi
61-
62-
# Clean up version string (remove >=, ^, ~, etc.)
63-
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
64-
65-
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
66-
print_error "Could not extract PHP version from composer.json"
67-
print_status "Available PHP-related fields in composer.json:"
68-
jq -r 'paths | select(.[-1] == "php") | join(".")' composer.json 2>/dev/null || print_warning "No PHP version found in composer.json"
69-
exit 1
70-
fi
71-
72-
print_status "Extracted PHP version: $PHP_VERSION"
73-
74-
# Extract additional information from composer.json
75-
print_status "Extracting additional information from composer.json..."
76-
77-
COMPOSER_NAME=$(jq -r '.name // empty' composer.json 2>/dev/null)
78-
COMPOSER_DESCRIPTION=$(jq -r '.description // empty' composer.json 2>/dev/null)
79-
COMPOSER_VERSION=$(jq -r '.version // empty' composer.json 2>/dev/null)
80-
COMPOSER_LICENSE=$(jq -r '.license // empty' composer.json 2>/dev/null)
81-
COMPOSER_TYPE=$(jq -r '.type // empty' composer.json 2>/dev/null)
82-
83-
# Extract Node.js information from package.json if it exists
84-
NODE_VERSION=""
85-
NPM_VERSION=""
86-
PACKAGE_NAME=""
87-
PACKAGE_VERSION=""
88-
PACKAGE_DESCRIPTION=""
89-
90-
if [ -f "package.json" ]; then
91-
print_status "Extracting information from package.json..."
92-
93-
NODE_VERSION=$(jq -r '.engines.node // empty' package.json 2>/dev/null)
94-
NPM_VERSION=$(jq -r '.engines.npm // empty' package.json 2>/dev/null)
95-
PACKAGE_NAME=$(jq -r '.name // empty' package.json 2>/dev/null)
96-
PACKAGE_VERSION=$(jq -r '.version // empty' package.json 2>/dev/null)
97-
PACKAGE_DESCRIPTION=$(jq -r '.description // empty' package.json 2>/dev/null)
98-
fi
99-
100-
# Extract Composer scripts
101-
COMPOSER_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + (if (.value|type)=="array" then (.value|join(" && ")) else .value end)' composer.json 2>/dev/null)
102-
103-
# Extract npm scripts
104-
NPM_SCRIPTS=""
105-
if [ -f "package.json" ]; then
106-
NPM_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + .value' package.json 2>/dev/null)
46+
# Check if running in CI
47+
if [ "$CI" = "true" ]; then
48+
print_status "CI environment detected. Skipping jq-dependent logic."
49+
else
50+
# Extract PHP version from composer.json
51+
print_status "Extracting PHP version from composer.json..."
52+
53+
# Try to get PHP version from platform config first
54+
PHP_VERSION=$(jq -r '.["config"]["platform"]["php"] // empty' composer.json 2>/dev/null)
55+
56+
# If not found in platform config, try require-dev
57+
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
58+
PHP_VERSION=$(jq -r '.["require-dev"]["php"] // empty' composer.json 2>/dev/null)
59+
fi
60+
61+
# If still not found, try require
62+
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
63+
PHP_VERSION=$(jq -r '.["require"]["php"] // empty' composer.json 2>/dev/null)
64+
fi
65+
66+
# Clean up version string (remove >=, ^, ~, etc.)
67+
PHP_VERSION=$(echo "$PHP_VERSION" | sed 's/[^0-9.]//g')
68+
69+
if [ -z "$PHP_VERSION" ] || [ "$PHP_VERSION" = "null" ]; then
70+
print_error "Could not extract PHP version from composer.json"
71+
print_status "Available PHP-related fields in composer.json:"
72+
jq -r 'paths | select(.[-1] == "php") | join(".")' composer.json 2>/dev/null || print_warning "No PHP version found in composer.json"
73+
exit 1
74+
fi
75+
76+
print_status "Extracted PHP version: $PHP_VERSION"
77+
78+
# Extract additional information from composer.json
79+
print_status "Extracting additional information from composer.json..."
80+
81+
COMPOSER_NAME=$(jq -r '.name // empty' composer.json 2>/dev/null)
82+
COMPOSER_DESCRIPTION=$(jq -r '.description // empty' composer.json 2>/dev/null)
83+
COMPOSER_VERSION=$(jq -r '.version // empty' composer.json 2>/dev/null)
84+
COMPOSER_LICENSE=$(jq -r '.license // empty' composer.json 2>/dev/null)
85+
COMPOSER_TYPE=$(jq -r '.type // empty' composer.json 2>/dev/null)
86+
87+
# Extract Node.js information from package.json if it exists
88+
NODE_VERSION=""
89+
NPM_VERSION=""
90+
PACKAGE_NAME=""
91+
PACKAGE_VERSION=""
92+
PACKAGE_DESCRIPTION=""
93+
94+
if [ -f "package.json" ]; then
95+
print_status "Extracting information from package.json..."
96+
97+
NODE_VERSION=$(jq -r '.engines.node // empty' package.json 2>/dev/null)
98+
NPM_VERSION=$(jq -r '.engines.npm // empty' package.json 2>/dev/null)
99+
PACKAGE_NAME=$(jq -r '.name // empty' package.json 2>/dev/null)
100+
PACKAGE_VERSION=$(jq -r '.version // empty' package.json 2>/dev/null)
101+
PACKAGE_DESCRIPTION=$(jq -r '.description // empty' package.json 2>/dev/null)
102+
fi
103+
104+
# Extract Composer scripts
105+
COMPOSER_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + (if (.value|type)=="array" then (.value|join(" && ")) else .value end)' composer.json 2>/dev/null)
106+
107+
# Extract npm scripts
108+
NPM_SCRIPTS=""
109+
if [ -f "package.json" ]; then
110+
NPM_SCRIPTS=$(jq -r '.scripts | to_entries[] | " - " + .key + ": " + .value' package.json 2>/dev/null)
111+
fi
107112
fi
108113

109114
# Define Cursor rules directory

0 commit comments

Comments
 (0)