Skip to content

Commit

Permalink
Fix erroring with EISDIR when a directory that ends with .ts/`.ts…
Browse files Browse the repository at this point in the history
…x` exists
  • Loading branch information
emmatown committed Oct 26, 2021
1 parent fd92cc6 commit 0e9f8b4
Show file tree
Hide file tree
Showing 7 changed files with 4,800 additions and 5,455 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-elephants-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ts-gql/compiler": patch
---

Fixed erroring with `EISDIR` when a directory that ends with `.ts`/`.tsx` exists
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
restore-keys: pnpm-v5-ubuntu-latest-

- name: Install pnpm
run: npm i -g pnpm
run: npm i -g pnpm@6.19.0

- name: Install Dependencies
run: pnpm i
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
restore-keys: pnpm-${{ matrix.platform }}-

- name: Install pnpm
run: npm i -g pnpm
run: npm i -g pnpm@6.19.0

- name: Install Dependencies
run: pnpm i
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
restore-keys: pnpm-v5-ubuntu-latest

- name: Install pnpm
run: npm i -g pnpm@4
run: npm i -g pnpm@6.19.0

- name: Install Dependencies
run: pnpm i
Expand Down
9 changes: 5 additions & 4 deletions packages/compiler/src/get-generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ const walk = promisify(_walk);
function getPrintCompilerError() {
let readFile = memoize((filename: string) => fs.readFile(filename, "utf8"));
return async (error: CompilerError) => {
const { codeFrameColumns } = lazyRequire<
typeof import("@babel/code-frame")
>();
const { codeFrameColumns } =
lazyRequire<typeof import("@babel/code-frame")>();
let content = await readFile(error.filename);
return (
error.filename +
Expand Down Expand Up @@ -72,7 +71,9 @@ const walkSettings = new Settings({
!entry.path.includes("node_modules") &&
entry.path !== `__generated__${nodePath.sep}ts-gql`,
entryFilter: (entry) =>
tsExtensionRegex.test(entry.name) && !dtsExtensionRegex.test(entry.name),
entry.dirent.isFile() &&
tsExtensionRegex.test(entry.name) &&
!dtsExtensionRegex.test(entry.name),
});

export const getGeneratedTypes = async (
Expand Down
48 changes: 48 additions & 0 deletions packages/compiler/src/test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,54 @@ type ThingQuery = (
);
export type type = TypedDocumentNode<{
type: \\"query\\";
result: ThingQuery;
variables: ThingQueryVariables;
documents: SchemaTypes.TSGQLDocuments;
}>
declare module \\"./@schema\\" {
interface TSGQLDocuments {
Thing: type;
}
}
export const document = JSON.parse(\\"{\\\\\\"kind\\\\\\":\\\\\\"Document\\\\\\",\\\\\\"definitions\\\\\\":[{\\\\\\"kind\\\\\\":\\\\\\"OperationDefinition\\\\\\",\\\\\\"operation\\\\\\":\\\\\\"query\\\\\\",\\\\\\"name\\\\\\":{\\\\\\"kind\\\\\\":\\\\\\"Name\\\\\\",\\\\\\"value\\\\\\":\\\\\\"Thing\\\\\\"},\\\\\\"variableDefinitions\\\\\\":[],\\\\\\"directives\\\\\\":[],\\\\\\"selectionSet\\\\\\":{\\\\\\"kind\\\\\\":\\\\\\"SelectionSet\\\\\\",\\\\\\"selections\\\\\\":[{\\\\\\"kind\\\\\\":\\\\\\"Field\\\\\\",\\\\\\"name\\\\\\":{\\\\\\"kind\\\\\\":\\\\\\"Name\\\\\\",\\\\\\"value\\\\\\":\\\\\\"hello\\\\\\"},\\\\\\"arguments\\\\\\":[],\\\\\\"directives\\\\\\":[]}]}}]}\\")
",
"filename": "__generated__/ts-gql/Thing.ts",
"type": "output",
},
],
}
`;

exports[`basic with 1`] = `
Object {
"errors": Array [],
"fsOperations": Array [
Object {
"content": "// ts-gql-integrity:4eb35d4812c8886680efbce5422b30a8
/*
ts-gql-meta-begin
{
\\"hash\\": \\"ed812131898601ba06f7be4f59a44fe5\\"
}
ts-gql-meta-end
*/
import * as SchemaTypes from \\"./@schema\\";
import { TypedDocumentNode } from \\"@ts-gql/tag\\";
type ThingQueryVariables = {};
type ThingQuery = (
{ readonly __typename: 'Query' }
& Pick<SchemaTypes.Query, 'hello'>
);
export type type = TypedDocumentNode<{
type: \\"query\\";
result: ThingQuery;
Expand Down
21 changes: 21 additions & 0 deletions packages/compiler/src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,24 @@ test("errors in fragments are not shown for usages", async () => {
]
`);
});

test("with directory that ends with .ts", async () => {
let dir = await setupEnv();

await fs.writeFile(
path.join(dir, "index.tsx"),
makeSourceFile([
graphql`
query Thing {
hello
}
`,
])
);
const dirEndsWithTs = path.join(dir, "thing.ts");
await fs.mkdir(dirEndsWithTs);

await fs.writeFile(path.join(dirEndsWithTs, "thing.mp4"), ``);

expect(await build(dir)).toMatchSnapshot();
});
Loading

0 comments on commit 0e9f8b4

Please sign in to comment.