Skip to content

Commit 9c9e1ba

Browse files
author
Dane Pilcher
authored
fix: ensure posix path sep is used (#728)
* fix: ensure posix path sep is used * fix: replace windows path separator with posix * fix: only replace win sep
1 parent 0c9db5b commit 9c9e1ba

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

packages/amplify-codegen/src/utils/getRelativeTypesPath.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const path = require('path');
22

33
function getRelativeTypesPath(opsGenDirectory, generatedFileName) {
44
if (generatedFileName) {
5-
const relativePath = path.relative(opsGenDirectory, generatedFileName);
5+
const relativePath = path
6+
.relative(opsGenDirectory, generatedFileName)
7+
// ensure posix path separators are used
8+
.split(path.win32.sep)
9+
.join(path.posix.sep);
610

711
// generatedFileName is in same directory as opsGenDirectory
812
// i.e. generatedFileName: src/graphql/API.ts, opsGenDirectory: src/graphql

packages/graphql-generator/src/__tests__/utils/GraphQLStatementsFormatter.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ describe('GraphQL statements Formatter', () => {
2626
expect(formattedOutput).toMatchSnapshot();
2727
});
2828

29-
it('Generates formatted output for TS frontend', () => {
29+
it('Generates formatted output for TS frontend with posix path', () => {
3030
const formattedOutput = new GraphQLStatementsFormatter('typescript', 'queries', '../API.ts').format(statements);
3131
expect(formattedOutput).toMatchSnapshot();
3232
});
3333

34+
it('Generates formatted output for TS frontend with windows path', () => {
35+
const formattedOutput = new GraphQLStatementsFormatter('typescript', 'queries', '..\\API.ts').format(statements);
36+
expect(formattedOutput).toMatchSnapshot();
37+
});
38+
3439
it('Generates formatted output for Flow frontend', () => {
3540
const formattedOutput = new GraphQLStatementsFormatter('flow').format(statements);
3641
expect(formattedOutput).toMatchSnapshot();

packages/graphql-generator/src/__tests__/utils/__snapshots__/GraphQLStatementsFormatter.test.ts.snap

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,33 @@ export const getProject = /* GraphQL */ \`
6262
"
6363
`;
6464

65-
exports[`GraphQL statements Formatter Generates formatted output for TS frontend 1`] = `
65+
exports[`GraphQL statements Formatter Generates formatted output for TS frontend with posix path 1`] = `
66+
"/* tslint:disable */
67+
/* eslint-disable */
68+
// this is an auto generated file. This will be overwritten
69+
70+
import * as APITypes from \\"../API\\";
71+
type GeneratedQuery<InputType, OutputType> = string & {
72+
__generatedQueryInput: InputType;
73+
__generatedQueryOutput: OutputType;
74+
};
75+
76+
export const getProject = /* GraphQL */ \`query GetProject($id: ID!) {
77+
getProject(id: $id) {
78+
id
79+
name
80+
createdAt
81+
updatedAt
82+
}
83+
}
84+
\` as GeneratedQuery<
85+
APITypes.GetProjectQueryVariables,
86+
APITypes.GetProjectQuery
87+
>;
88+
"
89+
`;
90+
91+
exports[`GraphQL statements Formatter Generates formatted output for TS frontend with windows path 1`] = `
6692
"/* tslint:disable */
6793
/* eslint-disable */
6894
// this is an auto generated file. This will be overwritten

packages/graphql-generator/src/utils/GraphQLStatementsFormatter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import prettier, { BuiltInParserName } from 'prettier';
23
import {
34
interfaceNameFromOperation,
@@ -34,7 +35,12 @@ export class GraphQLStatementsFormatter {
3435
}[operation];
3536
this.lintOverrides = [];
3637
this.headerComments = [];
37-
this.typesPath = typesPath ? typesPath.replace(/.ts/i, '') : null;
38+
this.typesPath = typesPath
39+
? typesPath.replace(/.ts/i, '')
40+
// ensure posix path separators are used
41+
.split(path.win32.sep)
42+
.join(path.posix.sep)
43+
: null;
3844
this.includeTypeScriptTypes = !!(this.language === 'typescript' && this.opTypeName && this.typesPath);
3945
}
4046

0 commit comments

Comments
 (0)