Skip to content

Commit

Permalink
fix: normalize paths to POSIX format (#332)
Browse files Browse the repository at this point in the history
Normalize script paths to use POSIX format to avoid broken paths on Windows.
  • Loading branch information
dariuszkuc authored Jan 19, 2023
1 parent fe53a3e commit 10a5384
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/compatibility/src/composeSupergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import execa from 'execa';
import debug from 'debug';
import { healthcheckRouter, healthcheck } from './utils/client';
import { logWithTimestamp, writeableDebugStream } from './utils/logging';
import { normalizePath } from './utils/path';
import { resolve } from 'path';
import { readFile, writeFile } from 'fs/promises';
import { createWriteStream } from 'fs';
Expand Down Expand Up @@ -109,7 +110,7 @@ export async function composeSupergraph(
'utf-8',
);
const supergraphConfig = template
.replaceAll('${DIST_DIR}', resolve(__dirname))
.replaceAll('${DIST_DIR}', normalizePath(resolve(__dirname)))
.replace('${PORT}', port)
.replace('${GRAPHQL_PATH}', graphQLEndpoint)
.replace('${SCHEMA_FILE}', schemaFile);
Expand Down
7 changes: 4 additions & 3 deletions packages/compatibility/src/startSupergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import debug from 'debug';
import { logWithTimestamp, writeableDebugStream } from './utils/logging';
import { composeDevSupergraph, composeSupergraph } from './composeSupergraph';
import { healtcheckSupergraph } from './utils/client';
import { normalizePath } from './utils/path';
import { resolve } from 'path';
import { readFile, writeFile } from 'fs/promises';

Expand Down Expand Up @@ -80,7 +81,7 @@ async function startSupergraphUsingPm2(config: Pm2Config) {
);
const supergraphConfig = template.replaceAll(
'${DIST_DIR}',
resolve(__dirname),
normalizePath(resolve(__dirname)),
);
await writeFile('supergraph.config.js', supergraphConfig);

Expand Down Expand Up @@ -155,8 +156,8 @@ async function startSupergraphUsingDocker(config: DockerConfig) {
'utf-8',
);
const supergraphConfig = template
.replaceAll('${SCRIPT_DIR}', resolve(__dirname, '..'))
.replaceAll('${DIST_DIR}', resolve(__dirname));
.replaceAll('${SCRIPT_DIR}', normalizePath(resolve(__dirname, '..')))
.replaceAll('${DIST_DIR}', normalizePath(resolve(__dirname)));

await writeFile('supergraph-compose.yaml', supergraphConfig);

Expand Down
8 changes: 8 additions & 0 deletions packages/compatibility/src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'path';

/**
* Normalizes passed in path to ensure it is always in POSIX format.
*/
export function normalizePath(pathToNormalize: string): string {
return pathToNormalize.split(path.sep).join(path.posix.sep);
}

0 comments on commit 10a5384

Please sign in to comment.