@@ -26,9 +26,8 @@ echo "Platform: $PLATFORM $ARCH"
2626echo " Bazel platform: ${BAZEL_PLATFORM} _${BAZEL_ARCH} "
2727
2828# Build first to ensure bazel-out directory exists
29- echo " "
30- echo " Building node_modules to generate bazel-out structure..."
31- bazel build //:node_modules > /dev/null
29+ echo " Building node_modules..."
30+ bazel build //:node_modules > /dev/null 2>&1
3231
3332# Find the bazel-out directory structure
3433BAZEL_OUT_DIR=" "
@@ -40,139 +39,173 @@ for potential_dir in "bazel-out/${BAZEL_PLATFORM}_${BAZEL_ARCH}-fastbuild" "baze
4039done
4140
4241if [[ -z " $BAZEL_OUT_DIR " ]]; then
43- echo " ❌ Could not find bazel-out directory for platform ${BAZEL_PLATFORM} _${BAZEL_ARCH} "
42+ echo " ERROR: Could not find bazel-out directory for platform ${BAZEL_PLATFORM} _${BAZEL_ARCH} "
4443 echo " Available bazel-out directories:"
4544 ls -la bazel-out/ 2> /dev/null || echo " No bazel-out directory found"
4645 exit 1
4746fi
4847
4948echo " Found bazel-out directory: $BAZEL_OUT_DIR "
5049
51- # Function to check if a package has a fake package.json
52- check_package_is_fake () {
50+ # Function to check if a package repository directory exists
51+ check_package_repository_exists () {
5352 local package_name=" $1 "
54- local expected_fake =" $2 " # "true" or "false"
53+ local should_exist =" $2 " # "true" or "false"
5554
56- echo " Checking $package_name (should be $( [ " $expected_fake " = " true" ] && echo " fake" || echo " real" ) )..."
55+ # Check if repository directory exists in bazel-out
56+ local repo_path=" $BAZEL_OUT_DIR /bin/external/npm__esbuild_${package_name} __0.16.17"
57+ local package_store_path=" $BAZEL_OUT_DIR /bin/node_modules/.aspect_rules_js/@esbuild+${package_name} @0.16.17"
5758
58- # Build the expected path
59- local package_path= " $BAZEL_OUT_DIR /bin/node_modules/.aspect_rules_js/@esbuild+ ${package_name} @0.16.17/node_modules/@esbuild/ ${package_name} /package.json "
59+ local repo_exists= " false "
60+ local package_exists= " false "
6061
61- if [[ ! -f " $package_path " ]]; then
62- echo " ❌ Package file not found: $package_path "
63- return 1
62+ if [[ -d " $repo_path " ]]; then
63+ repo_exists=" true"
64+ fi
65+
66+ if [[ -d " $package_store_path " ]]; then
67+ package_exists=" true"
6468 fi
6569
66- echo " 📁 Found: $package_path "
67-
68- # Check if package.json contains _incompatible marker (indicates fake package)
69- local is_fake=" false"
70- if grep -q " _incompatible" " $package_path " 2> /dev/null; then
71- is_fake=" true"
72- echo " 🚫 Contains _incompatible marker (fake package)"
73-
74- # Show the fake package content for verification
75- echo " 📄 Fake package.json content:"
76- cat " $package_path " | sed ' s/^/ /'
70+ # Verify expectations
71+ if [[ " $should_exist " = " true" ]]; then
72+ if [[ " $repo_exists " = " true" || " $package_exists " = " true" ]]; then
73+ echo " PASS: $package_name (compatible platform)"
74+ return 0
75+ else
76+ echo " FAIL: $package_name missing but should exist (compatible platform)"
77+ return 1
78+ fi
7779 else
78- echo " ✅ No _incompatible marker (real package)"
79-
80- # Show basic info about real package
81- if command -v jq > /dev/null 2>&1 ; then
82- local name=$( jq -r ' .name // "unknown"' " $package_path " 2> /dev/null)
83- local version=$( jq -r ' .version // "unknown"' " $package_path " 2> /dev/null)
84- echo " 📦 Real package: $name @$version "
80+ if [[ " $repo_exists " = " false" && " $package_exists " = " false" ]]; then
81+ echo " PASS: $package_name correctly filtered (incompatible platform)"
82+ return 0
83+ else
84+ echo " FAIL: $package_name exists but should be filtered (incompatible platform)"
85+ return 1
8586 fi
8687 fi
88+ }
89+
90+ # Function to check generated repositories.bzl file
91+ check_repositories_bzl () {
92+ # Look for the generated repositories file
93+ local repos_file=" "
94+ for potential_file in " bazel-bin/external/npm/repositories.bzl" " bazel-out/*/bin/external/npm/repositories.bzl" ; do
95+ if [[ -f " $potential_file " ]]; then
96+ repos_file=" $potential_file "
97+ break
98+ fi
99+ done
87100
88- # Verify expectations
89- if [[ " $expected_fake " = " $is_fake " ]]; then
90- echo " ✅ Package type matches expectation"
101+ if [[ -z " $repos_file " ]]; then
102+ echo " WARNING: Could not find repositories.bzl file"
91103 return 0
104+ fi
105+
106+ # Count npm_import rules for platform-specific packages
107+ local incompatible_count=0
108+
109+ # Define incompatible packages for current platform
110+ local incompatible_packages=()
111+ if [[ " $BAZEL_PLATFORM " = " darwin" && " $BAZEL_ARCH " = " arm64" ]]; then
112+ incompatible_packages=(" linux-x64" " win32-x64" " linux-arm64" )
113+ elif [[ " $BAZEL_PLATFORM " = " linux" && " $BAZEL_ARCH " = " amd64" ]]; then
114+ incompatible_packages=(" darwin-arm64" " win32-x64" " darwin-x64" )
92115 else
93- echo " ❌ Package type mismatch: expected $( [ " $expected_fake " = " true" ] && echo " fake" || echo " real" ) , got $( [ " $is_fake " = " true" ] && echo " fake" || echo " real" ) "
116+ # Generic check - just look for common incompatible ones
117+ incompatible_packages=(" win32-x64" )
118+ fi
119+
120+ for package in " ${incompatible_packages[@]} " ; do
121+ if grep -q " npm__esbuild_${package} __" " $repos_file " ; then
122+ echo " FAIL: Found npm_import rule for incompatible package: $package "
123+ incompatible_count=$(( incompatible_count + 1 ))
124+ fi
125+ done
126+
127+ if [[ " $incompatible_count " -gt 0 ]]; then
128+ echo " FAIL: Found $incompatible_count npm_import rules for incompatible packages"
94129 return 1
130+ else
131+ echo " PASS: No npm_import rules found for incompatible packages"
132+ return 0
95133 fi
96134}
97135
98136# Main test logic based on current platform
99- echo " "
100137echo " Running platform-specific validation..."
101138
102139success=true
103140
104141if [[ " $BAZEL_PLATFORM " = " darwin" && " $BAZEL_ARCH " = " arm64" ]]; then
105- echo " 🖥️ Testing on Darwin ARM64..."
142+ # linux-x64 should NOT exist (incompatible)
143+ if ! check_package_repository_exists " linux-x64" " false" ; then
144+ success=false
145+ fi
106146
107- # linux -x64 should be fake (incompatible)
108- if ! check_package_is_fake " linux -x64" " true " ; then
147+ # win32 -x64 should NOT exist (incompatible)
148+ if ! check_package_repository_exists " win32 -x64" " false " ; then
109149 success=false
110150 fi
111151
112- # darwin-arm64 should be real (compatible) - but might be fake if optional
113- echo " "
114- if ! check_package_is_fake " darwin-arm64" " false" ; then
115- echo " ℹ️ darwin-arm64 is fake - this might be OK if it's optional and not needed"
116- # Don't fail the test for this case
152+ # darwin-arm64 should exist (compatible) if not optional
153+ if ! check_package_repository_exists " darwin-arm64" " true" ; then
154+ echo " INFO: darwin-arm64 doesn't exist - this is OK if it's optional and not needed"
155+ # Don't fail the test for this case since it's optional
117156 fi
118157
119158elif [[ " $BAZEL_PLATFORM " = " linux" && " $BAZEL_ARCH " = " amd64" ]]; then
120- echo " 🖥️ Testing on Linux x64..."
159+ # darwin-arm64 should NOT exist (incompatible)
160+ if ! check_package_repository_exists " darwin-arm64" " false" ; then
161+ success=false
162+ fi
121163
122- # darwin-arm64 should be fake (incompatible)
123- if ! check_package_is_fake " darwin-arm64 " " true " ; then
164+ # win32-x64 should NOT exist (incompatible)
165+ if ! check_package_repository_exists " win32-x64 " " false " ; then
124166 success=false
125167 fi
126168
127- # linux-x64 should be real (compatible)
128- echo " "
129- if ! check_package_is_fake " linux-x64" " false" ; then
130- echo " ℹ️ linux-x64 is fake - this might be OK if it's optional and not needed"
131- # Don't fail the test for this case
169+ # linux-x64 should exist (compatible) if not optional
170+ if ! check_package_repository_exists " linux-x64" " true" ; then
171+ echo " INFO: linux-x64 doesn't exist - this is OK if it's optional and not needed"
172+ # Don't fail the test for this case since it's optional
132173 fi
133174
134175else
135- echo " 🖥️ Testing on $BAZEL_PLATFORM $BAZEL_ARCH ..."
136- echo " ℹ️ Platform-specific validation not implemented for this platform"
137- echo " ℹ️ Will check that at least one platform-specific package exists and some are fake"
138-
139- # Generic test - just check that we have some fake packages
140- fake_count=0
141- total_count=0
142-
143- for package in " linux-x64" " darwin-arm64" ; do
144- package_path=" $BAZEL_OUT_DIR /bin/node_modules/.aspect_rules_js/@esbuild+${package} @0.16.17/node_modules/@esbuild/${package} /package.json"
145- if [[ -f " $package_path " ]]; then
146- total_count=$(( total_count + 1 ))
147- if grep -q " _incompatible" " $package_path " 2> /dev/null; then
148- fake_count=$(( fake_count + 1 ))
149- echo " 🚫 Found fake package: $package "
150- else
151- echo " ✅ Found real package: $package "
152- fi
176+ echo " Testing generic platform filtering..."
177+
178+ # Generic test - just check that some packages don't exist
179+ skipped_count=0
180+ total_checked=0
181+
182+ for package in " win32-x64" " win32-ia32" " sunos-x64" ; do
183+ total_checked=$(( total_checked + 1 ))
184+ if ! check_package_repository_exists " $package " " false" ; then
185+ # Package exists when it shouldn't
186+ echo " WARNING: Package $package exists but should be filtered"
187+ else
188+ skipped_count=$(( skipped_count + 1 ))
153189 fi
154190 done
155191
156- echo " 📊 Summary: $fake_count fake packages out of $total_count total"
157-
158- if [[ " $fake_count " -gt 0 ]]; then
159- echo " 🎉 Platform filtering is working (found fake packages)"
160- else
161- echo " ⚠️ No fake packages found - platform filtering might not be working"
192+ if [[ " $skipped_count " -eq 0 ]]; then
193+ echo " FAIL: No packages filtered - platform filtering might not be working"
162194 success=false
163195 fi
164196fi
165197
198+ # Check the generated repositories.bzl file
199+ if ! check_repositories_bzl; then
200+ success=false
201+ fi
202+
166203# Final result
167204echo " "
168- echo " === Test Summary ==="
169205if [[ " $success " = " true" ]]; then
170- echo " 🎉 Platform filtering test passed!"
171- echo " ✅ Incompatible packages have fake package.json files"
172- echo " ✅ Platform-specific handling is working correctly"
206+ echo " PASS: Platform filtering test passed"
173207 exit 0
174208else
175- echo " ❌ Platform filtering test failed!"
176- echo " 💡 Check that incompatible packages are being replaced with fake packages"
209+ echo " FAIL: Platform filtering test failed"
177210 exit 1
178211fi
0 commit comments