Skip to content

Commit

Permalink
fix(legacy/cli): Register tsconfig paths on startup (#7493)
Browse files Browse the repository at this point in the history
* register

* no paths matcher no register

* changeset

* chore(dependencies): updated changesets for modified dependencies

* use basedir for cwd

* chore(dependencies): updated changesets for modified dependencies

* return empty unregister func

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
enisdenjo and github-actions[bot] authored Aug 14, 2024
1 parent 6ba3f99 commit 78b7569
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-poems-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/include': patch
---

Return noop unregister function if no tsconfig paths have been registered
5 changes: 5 additions & 0 deletions .changeset/thirty-news-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/include': patch
---

Nothing to register if tsconfig does not contain paths
5 changes: 5 additions & 0 deletions .changeset/yellow-coats-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/cli': patch
---

Register tsconfig paths on startup
3 changes: 2 additions & 1 deletion packages/include/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export function registerTsconfigPaths({
configName = process.env.MESH_INCLUDE_TSCONFIG_NAME || 'tsconfig.json',
}: RegisterTsconfigPathsOptions = {}): () => void {
const tsconfig = getTsconfig(cwd, configName);
if (!tsconfig) return; // no tsconfig, no register
if (!tsconfig) return () => {}; // no tsconfig, no register

const pathsMatcher = createPathsMatcher(tsconfig);
if (!pathsMatcher) return () => {}; // no paths matcher, no register

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand Down
5 changes: 4 additions & 1 deletion packages/legacy/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { config as dotEnvRegister } from 'dotenv';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { fs, path as pathModule, process } from '@graphql-mesh/cross-helpers';
import { include } from '@graphql-mesh/include';
import { include, registerTsconfigPaths } from '@graphql-mesh/include';
import type { GetMeshOptions, MeshInstance, ServeMeshOptions } from '@graphql-mesh/runtime';
import { getMesh } from '@graphql-mesh/runtime';
import { FsStoreStorageAdapter, MeshStore } from '@graphql-mesh/store';
Expand Down Expand Up @@ -63,6 +63,7 @@ export async function graphqlMesh(
) {
let baseDir = cwdPath;
let logger: Logger = new DefaultLogger(cliParams.initialLoggerPrefix);
const unregisterTsconfigPaths = registerTsconfigPaths({ cwd: baseDir });
return yargs(args)
.help()
.option('r', {
Expand Down Expand Up @@ -93,6 +94,8 @@ export async function graphqlMesh(
} else {
baseDir = pathModule.resolve(cwdPath, dir);
}
unregisterTsconfigPaths();
registerTsconfigPaths({ cwd: baseDir });
if (fs.existsSync(pathModule.join(baseDir, '.env'))) {
dotEnvRegister({
path: pathModule.join(baseDir, '.env'),
Expand Down

0 comments on commit 78b7569

Please sign in to comment.