Fix: Remove NodeJS dependency for get-virtual-routes.ts
WHY are these changes introduced?
Currently the file packages/hydrogen/src/vite/get-virtual-routes.ts uses NodeJS specific functions to get the virtual routes (graphiql, subrequest profiler, etc).
When the hydrogenRoutes function is called during the Hydrogen build process if the current execution environment is in Mini-Oxygen or Cloudflare an error is thrown which prevents the build from succeeding
node_modules/@shopify/hydrogen/dist/development/get-virtual-routes-6PVSMJPH.js:1:9 │
│ │
│ 1: import { fileURLToPath } from 'url'; │
│ ^ │
│ 2: import path from 'path'; │
│ 3: import { readdir } from 'fs/promises'; │
│ │
│ │
│ To investigate the issue, examine this stack trace: │
│ at js (1:9): "fileURLToPath" is not exported by "__vite-browser-external:url", imported by "node_modules/
WHAT is this pull request doing?
Removes getVirtualRoutes from get-virtual-routes.ts (this function isn't used anywhere)
Removes all NodeJS imports from get-virtual-routes.ts
Removes unit test for getVirtualRoutes
HOW to test your changes?
Verify unit test packages/hydrogen/src/vite/get-virtual-routes.test.ts is passing
I have a test npm package with these changes you can add this package as a depedency like below:
...
"@shopify/hydrogen": "https://gitpkg.vercel.app/darintanakaFN/hydrogen/packages/hydrogen?main",
...
in a test hydrogen react router 7 project.
Verify shopify hydrogen NODE_ENV=development shopify hydrogen dev --codegen builds successfully
Verify NODE_ENV=test npm run build && shopify hydrogen preview builds successfully
Checklist
- [x] I've read the Contributing Guidelines
- [x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- (N/A) I've added a changeset if this PR contains user-facing or noteworthy changes
- [x] I've added tests to cover my changes
- (N/A) I've added or updated the documentation