Skip to content

Commit

Permalink
Improve monorepo support (#539)
Browse files Browse the repository at this point in the history
* ✨ NEW: mon repo support

* Trigger

* 🐛 FIX: isDirectory

* ⚡ IMPROVE: making it private

* ⚡ IMPROVE: ready for mocks as well

* ♻️ IMPROVE: naming to existsSync
  • Loading branch information
jycouet authored Sep 13, 2022
1 parent 599fc3c commit a7d4c2e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-carrots-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

fix - mono repo support
36 changes: 32 additions & 4 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,43 @@ ${
return '$houdini.d.ts'
}

private findNodeModulesHoudini(currentLocation: string) {
const pathEndingBy = ['node_modules', 'houdini']

// Build the first possible location
let locationFound = path.join(currentLocation, ...pathEndingBy)

// previousLocation is nothing
let previousLocation = ''
const backFolder = []

// if previousLocation !== locationFound that mean that we can go upper
// if the directory doesn't exist, let's go upper.
while (previousLocation !== locationFound && !fs.existsSync(locationFound)) {
// save the previous path
previousLocation = locationFound

// add a back folder
backFolder.push('../')

// set the new location
locationFound = path.join(currentLocation, ...backFolder, ...pathEndingBy)
}

if (previousLocation === locationFound) {
throw new Error('Could not find any node_modules/houdini folder')
}

return locationFound
}

get runtimeSource() {
// when running in the real world, scripts are nested in a sub directory of build, in tests they aren't nested
// under /src so we need to figure out how far up to go to find the appropriately compiled runtime
const relative = process.env.TEST
? path.join(currentDir, '../../')
: // TODO: it's very possible this breaks someones setup. the old version walked up from currentDir
// there isn't a consistent number of steps up anymore since the vite plugin and cmd live at different depths
// a better approach could be to start at current dir and walk up until we find a `houdini` dir
path.join(path.dirname(this.filepath), 'node_modules', 'houdini')
: // start here and go to parent until we find the node_modules/houdini folder
this.findNodeModulesHoudini(path.join(path.dirname(this.filepath)))

// we want to copy the typescript source code for the templates and then compile the files according
// to the requirements of the platform
Expand Down
9 changes: 9 additions & 0 deletions src/common/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ export async function stat(filepath: string) {
return memfs.statSync(filepath)
}

export function existsSync(dirPath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
return fsExtra.existsSync(dirPath)
}

return memfs.existsSync(dirPath)
}

export async function readdir(filepath: string): Promise<string[]> {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
Expand Down

2 comments on commit a7d4c2e

@vercel
Copy link

@vercel vercel bot commented on a7d4c2e Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a7d4c2e Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs-next – ./site

docs-next-git-main-houdinigraphql.vercel.app
docs-next-houdinigraphql.vercel.app
docs-next-kohl.vercel.app

Please sign in to comment.