From 0a691339b69ff611c242ef387be2a7ad50ae2976 Mon Sep 17 00:00:00 2001 From: jycouet Date: Mon, 12 Sep 2022 21:24:23 +0200 Subject: [PATCH 1/6] :sparkles: NEW: mon repo support --- .changeset/olive-carrots-fry.md | 5 +++++ src/common/config.ts | 36 +++++++++++++++++++++++++++++---- src/common/fs.ts | 4 ++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .changeset/olive-carrots-fry.md diff --git a/.changeset/olive-carrots-fry.md b/.changeset/olive-carrots-fry.md new file mode 100644 index 0000000000..3d96fa0891 --- /dev/null +++ b/.changeset/olive-carrots-fry.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +fix - mono repo support diff --git a/src/common/config.ts b/src/common/config.ts index 0f07bd4616..0a165d476b 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -293,15 +293,43 @@ ${ return '$houdini.d.ts' } + 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.isDirectorySync(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 diff --git a/src/common/fs.ts b/src/common/fs.ts index 818bea95e8..c65000ec5b 100644 --- a/src/common/fs.ts +++ b/src/common/fs.ts @@ -113,6 +113,10 @@ export async function stat(filepath: string) { return memfs.statSync(filepath) } +export function isDirectorySync(dirPath: string) { + return fsExtra.existsSync(dirPath) && fsExtra.lstatSync(dirPath).isDirectory() +} + export async function readdir(filepath: string): Promise { // no mock in production if (process.env.NODE_ENV !== 'test') { From 469eacef1ba3e203d7ab036b1f70a99e00d63be3 Mon Sep 17 00:00:00 2001 From: jycouet Date: Mon, 12 Sep 2022 21:41:05 +0200 Subject: [PATCH 2/6] Trigger From 96e1ecd187ab7b2b13650725efe4225a7a72eaed Mon Sep 17 00:00:00 2001 From: jycouet Date: Mon, 12 Sep 2022 22:01:00 +0200 Subject: [PATCH 3/6] :bug: FIX: isDirectory --- src/common/fs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/fs.ts b/src/common/fs.ts index c65000ec5b..8864c0ed9f 100644 --- a/src/common/fs.ts +++ b/src/common/fs.ts @@ -114,7 +114,7 @@ export async function stat(filepath: string) { } export function isDirectorySync(dirPath: string) { - return fsExtra.existsSync(dirPath) && fsExtra.lstatSync(dirPath).isDirectory() + return fsExtra.existsSync(dirPath) } export async function readdir(filepath: string): Promise { From 0ce3c440f136a8b7b56edcb24248a1a266ce2970 Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 13 Sep 2022 00:08:01 +0200 Subject: [PATCH 4/6] :zap: IMPROVE: making it private --- src/common/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/config.ts b/src/common/config.ts index 0a165d476b..ebb5d25e02 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -293,7 +293,7 @@ ${ return '$houdini.d.ts' } - findNodeModulesHoudini(currentLocation: string) { + private findNodeModulesHoudini(currentLocation: string) { const pathEndingBy = ['node_modules', 'houdini'] // Build the first possible location From 7e03c9c675e1ba3a5469fd35feaf815629af4f37 Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 13 Sep 2022 00:10:15 +0200 Subject: [PATCH 5/6] :zap: IMPROVE: ready for mocks as well --- src/common/fs.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/fs.ts b/src/common/fs.ts index 8864c0ed9f..6ce7bca62e 100644 --- a/src/common/fs.ts +++ b/src/common/fs.ts @@ -114,7 +114,12 @@ export async function stat(filepath: string) { } export function isDirectorySync(dirPath: string) { - return fsExtra.existsSync(dirPath) + // 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 { From 67268a23587f11bb1d54d6e9976bd2f23f7cdcb2 Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 13 Sep 2022 09:51:25 +0200 Subject: [PATCH 6/6] :recycle: IMPROVE: naming to existsSync --- src/common/config.ts | 2 +- src/common/fs.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/config.ts b/src/common/config.ts index ebb5d25e02..b9f3655326 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -305,7 +305,7 @@ ${ // if previousLocation !== locationFound that mean that we can go upper // if the directory doesn't exist, let's go upper. - while (previousLocation !== locationFound && !fs.isDirectorySync(locationFound)) { + while (previousLocation !== locationFound && !fs.existsSync(locationFound)) { // save the previous path previousLocation = locationFound diff --git a/src/common/fs.ts b/src/common/fs.ts index 6ce7bca62e..d3fb02f848 100644 --- a/src/common/fs.ts +++ b/src/common/fs.ts @@ -113,7 +113,7 @@ export async function stat(filepath: string) { return memfs.statSync(filepath) } -export function isDirectorySync(dirPath: string) { +export function existsSync(dirPath: string) { // no mock in production if (process.env.NODE_ENV !== 'test') { return fsExtra.existsSync(dirPath)