|
4 | 4 | "encoding/json" |
5 | 5 | "os" |
6 | 6 | "path/filepath" |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/cloudfoundry/switchblade" |
@@ -72,9 +73,24 @@ func testNPM(platform switchblade.Platform, fixtures string) func(*testing.T, sp |
72 | 73 | Expect(file.Close()).To(Succeed()) |
73 | 74 |
|
74 | 75 | pkg["engines"] = map[string]string{"npm": "^8"} |
| 76 | + |
| 77 | + // Remove cpu-features (native module) because npm 8's bundled |
| 78 | + // node-gyp v9.1.0 requires distutils, which was removed in Python 3.12+. |
| 79 | + // This test validates npm version selection, not native compilation. |
| 80 | + deps := pkg["dependencies"].(map[string]interface{}) |
| 81 | + delete(deps, "cpu-features") |
| 82 | + pkg["dependencies"] = deps |
| 83 | + |
75 | 84 | content, err := json.Marshal(pkg) |
76 | 85 | Expect(err).NotTo(HaveOccurred()) |
77 | 86 | Expect(os.WriteFile(filepath.Join(source, "package.json"), content, 0600)).To(Succeed()) |
| 87 | + |
| 88 | + // Also remove the require('cpu-features') from server.js so the |
| 89 | + // app doesn't crash at startup trying to load the missing module. |
| 90 | + serverJS, err := os.ReadFile(filepath.Join(source, "server.js")) |
| 91 | + Expect(err).NotTo(HaveOccurred()) |
| 92 | + serverJS = []byte(strings.Replace(string(serverJS), "const features = require('cpu-features')();\n", "", 1)) |
| 93 | + Expect(os.WriteFile(filepath.Join(source, "server.js"), serverJS, 0600)).To(Succeed()) |
78 | 94 | }) |
79 | 95 |
|
80 | 96 | it.After(func() { |
|
0 commit comments