From 296e0edd7f46bf704168433506e8c19ad6958e26 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Mon, 2 Oct 2023 10:56:38 -0600 Subject: [PATCH 1/3] fix: ensure posix path sep is used --- .../utils/GraphQLStatementsFormatter.test.ts | 7 ++++- .../GraphQLStatementsFormatter.test.ts.snap | 28 ++++++++++++++++++- .../src/utils/GraphQLStatementsFormatter.ts | 8 +++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/graphql-generator/src/__tests__/utils/GraphQLStatementsFormatter.test.ts b/packages/graphql-generator/src/__tests__/utils/GraphQLStatementsFormatter.test.ts index 2ff2eda76..a9a049b7d 100644 --- a/packages/graphql-generator/src/__tests__/utils/GraphQLStatementsFormatter.test.ts +++ b/packages/graphql-generator/src/__tests__/utils/GraphQLStatementsFormatter.test.ts @@ -26,11 +26,16 @@ describe('GraphQL statements Formatter', () => { expect(formattedOutput).toMatchSnapshot(); }); - it('Generates formatted output for TS frontend', () => { + it('Generates formatted output for TS frontend with posix path', () => { const formattedOutput = new GraphQLStatementsFormatter('typescript', 'queries', '../API.ts').format(statements); expect(formattedOutput).toMatchSnapshot(); }); + it('Generates formatted output for TS frontend with windows path', () => { + const formattedOutput = new GraphQLStatementsFormatter('typescript', 'queries', '..\\API.ts').format(statements); + expect(formattedOutput).toMatchSnapshot(); + }); + it('Generates formatted output for Flow frontend', () => { const formattedOutput = new GraphQLStatementsFormatter('flow').format(statements); expect(formattedOutput).toMatchSnapshot(); diff --git a/packages/graphql-generator/src/__tests__/utils/__snapshots__/GraphQLStatementsFormatter.test.ts.snap b/packages/graphql-generator/src/__tests__/utils/__snapshots__/GraphQLStatementsFormatter.test.ts.snap index 4873bdc95..72114f01c 100644 --- a/packages/graphql-generator/src/__tests__/utils/__snapshots__/GraphQLStatementsFormatter.test.ts.snap +++ b/packages/graphql-generator/src/__tests__/utils/__snapshots__/GraphQLStatementsFormatter.test.ts.snap @@ -62,7 +62,33 @@ export const getProject = /* GraphQL */ \` " `; -exports[`GraphQL statements Formatter Generates formatted output for TS frontend 1`] = ` +exports[`GraphQL statements Formatter Generates formatted output for TS frontend with posix path 1`] = ` +"/* tslint:disable */ +/* eslint-disable */ +// this is an auto generated file. This will be overwritten + +import * as APITypes from \\"../API\\"; +type GeneratedQuery = string & { + __generatedQueryInput: InputType; + __generatedQueryOutput: OutputType; +}; + +export const getProject = /* GraphQL */ \`query GetProject($id: ID!) { + getProject(id: $id) { + id + name + createdAt + updatedAt + } +} +\` as GeneratedQuery< + APITypes.GetProjectQueryVariables, + APITypes.GetProjectQuery +>; +" +`; + +exports[`GraphQL statements Formatter Generates formatted output for TS frontend with windows path 1`] = ` "/* tslint:disable */ /* eslint-disable */ // this is an auto generated file. This will be overwritten diff --git a/packages/graphql-generator/src/utils/GraphQLStatementsFormatter.ts b/packages/graphql-generator/src/utils/GraphQLStatementsFormatter.ts index 4b76a4e73..0958df584 100644 --- a/packages/graphql-generator/src/utils/GraphQLStatementsFormatter.ts +++ b/packages/graphql-generator/src/utils/GraphQLStatementsFormatter.ts @@ -1,3 +1,4 @@ +import * as path from 'path'; import prettier, { BuiltInParserName } from 'prettier'; import { interfaceNameFromOperation, @@ -34,7 +35,12 @@ export class GraphQLStatementsFormatter { }[operation]; this.lintOverrides = []; this.headerComments = []; - this.typesPath = typesPath ? typesPath.replace(/.ts/i, '') : null; + this.typesPath = typesPath + ? typesPath.replace(/.ts/i, '') + // ensure posix path separators are used + .split(path.win32.sep) + .join(path.posix.sep) + : null; this.includeTypeScriptTypes = !!(this.language === 'typescript' && this.opTypeName && this.typesPath); } From f13fb5905098514b0fb2152766cdfc43c8b1a640 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Mon, 2 Oct 2023 10:25:53 -0600 Subject: [PATCH 2/3] fix: replace windows path separator with posix --- packages/amplify-codegen/src/utils/getRelativeTypesPath.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/amplify-codegen/src/utils/getRelativeTypesPath.js b/packages/amplify-codegen/src/utils/getRelativeTypesPath.js index 7d3f8cb5b..39aeec1f7 100644 --- a/packages/amplify-codegen/src/utils/getRelativeTypesPath.js +++ b/packages/amplify-codegen/src/utils/getRelativeTypesPath.js @@ -2,7 +2,10 @@ const path = require('path'); function getRelativeTypesPath(opsGenDirectory, generatedFileName) { if (generatedFileName) { - const relativePath = path.relative(opsGenDirectory, generatedFileName); + const relativePath = path + .relative(opsGenDirectory, generatedFileName) + .split(path.sep) + .join(path.posix.sep); // generatedFileName is in same directory as opsGenDirectory // i.e. generatedFileName: src/graphql/API.ts, opsGenDirectory: src/graphql From 25cacc6a03cd9be1871958c8954c06cd558f6b82 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Mon, 2 Oct 2023 11:56:24 -0600 Subject: [PATCH 3/3] fix: only replace win sep --- packages/amplify-codegen/src/utils/getRelativeTypesPath.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/amplify-codegen/src/utils/getRelativeTypesPath.js b/packages/amplify-codegen/src/utils/getRelativeTypesPath.js index 39aeec1f7..7d8a406bc 100644 --- a/packages/amplify-codegen/src/utils/getRelativeTypesPath.js +++ b/packages/amplify-codegen/src/utils/getRelativeTypesPath.js @@ -4,7 +4,8 @@ function getRelativeTypesPath(opsGenDirectory, generatedFileName) { if (generatedFileName) { const relativePath = path .relative(opsGenDirectory, generatedFileName) - .split(path.sep) + // ensure posix path separators are used + .split(path.win32.sep) .join(path.posix.sep); // generatedFileName is in same directory as opsGenDirectory