Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ NEW: mono repo support #539

Merged
merged 6 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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