diff --git a/.changeset/smooth-doors-argue.md b/.changeset/smooth-doors-argue.md new file mode 100644 index 00000000..ea9dc3ae --- /dev/null +++ b/.changeset/smooth-doors-argue.md @@ -0,0 +1,5 @@ +--- +'fuse': patch +--- + +Fix src dir with appended file diff --git a/examples/standalone/src/App.tsx b/examples/standalone/src/App.tsx index 55ad7707..d856dca8 100644 --- a/examples/standalone/src/App.tsx +++ b/examples/standalone/src/App.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import { graphql, useQuery } from '../fuse' +import { graphql, useQuery } from './fuse' import { LaunchItem } from './components/LaunchItem' import { PageNumbers } from './components/PageNumbers' import { LaunchDetails } from './components/LaunchDetails' diff --git a/examples/standalone/src/components/LaunchDetails.tsx b/examples/standalone/src/components/LaunchDetails.tsx index add9c898..b72fd23d 100644 --- a/examples/standalone/src/components/LaunchDetails.tsx +++ b/examples/standalone/src/components/LaunchDetails.tsx @@ -1,4 +1,4 @@ -import { graphql, useQuery } from '../../fuse' +import { graphql, useQuery } from '../fuse' import { LaunchSite } from './LaunchSite' const LaunchDetailsQuery = graphql(` @@ -9,16 +9,9 @@ const LaunchDetailsQuery = graphql(` name details launchDate - image site { ...LaunchSiteFields } - rocket { - cost - country - company - description - } } } } diff --git a/examples/standalone/src/components/LaunchItem.tsx b/examples/standalone/src/components/LaunchItem.tsx index c644d147..7537ff90 100644 --- a/examples/standalone/src/components/LaunchItem.tsx +++ b/examples/standalone/src/components/LaunchItem.tsx @@ -1,4 +1,4 @@ -import { FragmentType, graphql, useFragment } from '../../fuse' +import { FragmentType, graphql, useFragment } from '../fuse' import styles from './LaunchItem.module.css' const LaunchFields = graphql(` diff --git a/examples/standalone/src/components/LaunchSite.tsx b/examples/standalone/src/components/LaunchSite.tsx index 33a8ab9e..b0b78954 100644 --- a/examples/standalone/src/components/LaunchSite.tsx +++ b/examples/standalone/src/components/LaunchSite.tsx @@ -1,4 +1,4 @@ -import { FragmentType, graphql, useFragment } from '../../fuse' +import { FragmentType, graphql, useFragment } from '../fuse' import { Location } from './Location' const LaunchSiteFields = graphql(` diff --git a/examples/standalone/src/components/Location.tsx b/examples/standalone/src/components/Location.tsx index 1dd67877..51593f1f 100644 --- a/examples/standalone/src/components/Location.tsx +++ b/examples/standalone/src/components/Location.tsx @@ -1,4 +1,4 @@ -import { FragmentType, graphql, useFragment } from '../../fuse' +import { FragmentType, graphql, useFragment } from '../fuse' const SiteLocationFields = graphql(` fragment SiteLocationFields on Location { diff --git a/examples/standalone/src/components/PageNumbers.tsx b/examples/standalone/src/components/PageNumbers.tsx index af741172..1537fb90 100644 --- a/examples/standalone/src/components/PageNumbers.tsx +++ b/examples/standalone/src/components/PageNumbers.tsx @@ -1,4 +1,4 @@ -import { FragmentType, graphql, useFragment } from '../../fuse' +import { FragmentType, graphql, useFragment } from '../fuse' import styles from './PageNumbers.module.css' diff --git a/examples/standalone/src/components/Rocket.tsx b/examples/standalone/src/components/Rocket.tsx deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/standalone/fuse/fragment-masking.ts b/examples/standalone/src/fuse/fragment-masking.ts similarity index 100% rename from examples/standalone/fuse/fragment-masking.ts rename to examples/standalone/src/fuse/fragment-masking.ts diff --git a/examples/standalone/fuse/gql.ts b/examples/standalone/src/fuse/gql.ts similarity index 87% rename from examples/standalone/fuse/gql.ts rename to examples/standalone/src/fuse/gql.ts index a90f0104..b7a59dc4 100644 --- a/examples/standalone/fuse/gql.ts +++ b/examples/standalone/src/fuse/gql.ts @@ -15,7 +15,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ const documents = { '\n query Launches_SSR($limit: Int, $offset: Int) {\n launches(limit: $limit, offset: $offset) {\n nodes {\n id\n ...LaunchFields\n }\n ...TotalCountFields\n }\n }\n': types.Launches_SsrDocument, - '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n': + '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n': types.LaunchDetailsDocument, '\n fragment LaunchFields on Launch {\n name\n launchDate\n image\n }\n': types.LaunchFieldsFragmentDoc, @@ -51,8 +51,8 @@ export function graphql( * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n', -): (typeof documents)['\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n'] + source: '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n', +): (typeof documents)['\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n'] /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/examples/standalone/fuse/graphql.ts b/examples/standalone/src/fuse/graphql.ts similarity index 92% rename from examples/standalone/fuse/graphql.ts rename to examples/standalone/src/fuse/graphql.ts index 18454097..bb2ea2c9 100644 --- a/examples/standalone/fuse/graphql.ts +++ b/examples/standalone/src/fuse/graphql.ts @@ -162,19 +162,11 @@ export type LaunchDetailsQuery = { name: string details?: string | null launchDate: string - image: string site: { __typename: 'Site' } & { ' $fragmentRefs'?: { LaunchSiteFieldsFragment: LaunchSiteFieldsFragment } } - rocket: { - __typename: 'Rocket' - cost?: number | null - country?: string | null - company?: string | null - description?: string | null - } } | { __typename: 'Rocket' } | { __typename: 'Site' } @@ -493,7 +485,6 @@ export const LaunchDetailsDocument = { kind: 'Field', name: { kind: 'Name', value: 'launchDate' }, }, - { kind: 'Field', name: { kind: 'Name', value: 'image' } }, { kind: 'Field', name: { kind: 'Name', value: 'site' }, @@ -507,31 +498,6 @@ export const LaunchDetailsDocument = { ], }, }, - { - kind: 'Field', - name: { kind: 'Name', value: 'rocket' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'cost' }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'country' }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'company' }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'description' }, - }, - ], - }, - }, ], }, }, diff --git a/examples/standalone/fuse/index.ts b/examples/standalone/src/fuse/index.ts similarity index 100% rename from examples/standalone/fuse/index.ts rename to examples/standalone/src/fuse/index.ts diff --git a/examples/standalone/src/main.tsx b/examples/standalone/src/main.tsx index 27d1f069..17ac5502 100644 --- a/examples/standalone/src/main.tsx +++ b/examples/standalone/src/main.tsx @@ -1,6 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom/client' -import { createClient, Provider } from '../fuse' +import { createClient, Provider } from './fuse' import App from './App.tsx' import './index.css' diff --git a/packages/core/src/cli.ts b/packages/core/src/cli.ts index 3cb40c2c..8f3e841a 100644 --- a/packages/core/src/cli.ts +++ b/packages/core/src/cli.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import sade from 'sade' import path from 'path' -import fs, { appendFile } from 'fs/promises' +import fs, { writeFile } from 'fs/promises' import { createServer, build } from 'vite' import { VitePluginNode } from 'vite-plugin-node' import { generate, CodegenContext } from '@graphql-codegen/cli' @@ -173,17 +173,32 @@ async function boostrapCodegen(location: string, watch: boolean) { const baseDirectory = process.cwd() const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src')) + const contents = `export * from "./fragment-masking"; +export * from "./gql"; +export * from "fuse/client";\n` const ctx = new CodegenContext({ filepath: 'codgen.yml', config: { ignoreNoDocuments: true, errorsOnly: true, noSilentErrors: true, + hooks: { + afterOneFileWrite: async () => { + await writeFile( + hasSrcDir + ? baseDirectory + '/src/fuse/index.ts' + : baseDirectory + '/fuse/index.ts', + contents, + ) + }, + }, watch: watch ? [ hasSrcDir ? baseDirectory + '/src/**/*.{ts,tsx}' : baseDirectory + '/**/*.{ts,tsx}', + '!./{node_modules,.next,.git}/**/*', + hasSrcDir ? '!./src/fuse/*.{ts,tsx}' : '!./fuse/*.{ts,tsx}', ] : false, schema: location, @@ -192,6 +207,7 @@ async function boostrapCodegen(location: string, watch: boolean) { documents: [ hasSrcDir ? './src/**/*.{ts,tsx}' : './**/*.{ts,tsx}', '!./{node_modules,.next,.git}/**/*', + hasSrcDir ? '!./src/fuse/*.{ts,tsx}' : '!./fuse/*.{ts,tsx}', ], preset: 'client', // presetConfig: { @@ -217,9 +233,4 @@ async function boostrapCodegen(location: string, watch: boolean) { }) await generate(ctx, true) - - await appendFile( - baseDirectory + '/fuse' + '/index.ts', - '\nexport * from "fuse/client"', - ) }