Skip to content

Commit 6edf87f

Browse files
committed
fix: make file operations Windows-compatible
- Use path.join() instead of string concatenation for default outDir - Fix glob patterns to use path.join() instead of template literals - Ensure cross-platform compatibility for all file system operations Changes: - proto-parser: Fixed default outDir path construction - proto-parser test-utils: Fixed glob pattern for reading output files - deparser scripts: Fixed glob patterns for SQL file discovery No breaking changes - all functionality remains the same
1 parent 7d00b2a commit 6edf87f

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

WINDOWS_COMPATIBILITY.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Windows Compatibility Improvements
2+
3+
## Overview
4+
5+
Made the codebase Windows-compatible by fixing path handling issues that would cause problems on Windows systems due to hardcoded forward slashes and string concatenation for paths.
6+
7+
## Changes Made
8+
9+
### 1. Fixed Default Output Directory Path
10+
**File:** `/workspace/packages/proto-parser/src/options/defaults.ts`
11+
12+
**Before:**
13+
```typescript
14+
outDir: `${process.cwd()}/out`,
15+
```
16+
17+
**After:**
18+
```typescript
19+
import { join } from 'path';
20+
// ...
21+
outDir: join(process.cwd(), 'out'),
22+
```
23+
24+
### 2. Fixed Glob Pattern in Test Utils
25+
**File:** `/workspace/packages/proto-parser/test-utils/index.ts`
26+
27+
**Before:**
28+
```typescript
29+
glob(outDir + '**/*')
30+
```
31+
32+
**After:**
33+
```typescript
34+
glob(join(outDir, '**/*'))
35+
```
36+
37+
### 3. Fixed Glob Patterns in Deparser Scripts
38+
**Files:**
39+
- `/workspace/packages/deparser/scripts/make-fixtures-sql.ts`
40+
- `/workspace/packages/deparser/scripts/make-fixtures-ast.ts`
41+
- `/workspace/packages/deparser/scripts/make-fixtures.ts`
42+
- `/workspace/packages/deparser/scripts/make-kitchen-sink.ts`
43+
44+
**Before:**
45+
```typescript
46+
const fixtures = globSync(`${FIXTURE_DIR}/**/*.sql`);
47+
```
48+
49+
**After:**
50+
```typescript
51+
const fixtures = globSync(path.join(FIXTURE_DIR, '**/*.sql'));
52+
```
53+
54+
## Why These Changes Matter
55+
56+
1. **Cross-Platform Compatibility**: Using `path.join()` ensures that the correct path separator is used for each operating system (forward slash on Unix-like systems, backslash on Windows).
57+
58+
2. **Glob Pattern Compatibility**: While glob patterns typically use forward slashes even on Windows, using `path.join()` ensures consistency and prevents potential issues with path resolution.
59+
60+
3. **Future-Proof**: These changes make the codebase more maintainable and prevent future Windows-related issues.
61+
62+
## Verification
63+
64+
All existing path operations in the codebase were already using proper Node.js path module functions:
65+
- `mkdirSync` with `{ recursive: true }` for directory creation
66+
- `path.join()`, `path.resolve()`, `path.dirname()`, `path.basename()` for path manipulation
67+
- `readFileSync` and `writeFileSync` for file operations
68+
69+
## No Breaking Changes
70+
71+
These changes are purely internal and do not affect the public API or behavior of the packages. All functionality remains the same across all platforms.

packages/deparser/scripts/make-fixtures-ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function ensureDir(dir: string) {
1717

1818
ensureDir(OUT_DIR);
1919

20-
const fixtures = globSync(`${FIXTURE_DIR}/**/*.sql`);
20+
const fixtures = globSync(path.join(FIXTURE_DIR, '**/*.sql'));
2121

2222
async function main() {
2323
for (const fixturePath of fixtures) {

packages/deparser/scripts/make-fixtures-sql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function ensureDir(dir: string) {
1616

1717
ensureDir(OUT_DIR);
1818

19-
const fixtures = globSync(`${FIXTURE_DIR}/**/*.sql`);
19+
const fixtures = globSync(path.join(FIXTURE_DIR, '**/*.sql'));
2020

2121
async function main() {
2222
for (const fixturePath of fixtures) {

packages/deparser/scripts/make-fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function ensureDir(dir: string) {
1616

1717
ensureDir(OUT_DIR);
1818

19-
const fixtures = globSync(`${FIXTURE_DIR}/**/*.sql`);
19+
const fixtures = globSync(path.join(FIXTURE_DIR, '**/*.sql'));
2020

2121
async function main() {
2222
// Collect deparsed SQL in a single JSON

packages/deparser/scripts/make-kitchen-sink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ it('${name}', async () => {
2727
`
2828
};
2929

30-
const fixtures = globSync(`${FIXTURE_DIR}/**/*.sql`);
30+
const fixtures = globSync(path.join(FIXTURE_DIR, '**/*.sql'));
3131

3232
async function main() {
3333
for (const fixturePath of fixtures) {

packages/proto-parser/src/options/defaults.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import deepmerge from 'deepmerge';
2+
import { join } from 'path';
23

34
import { PgProtoParserOptions } from "./types";
45

56
// Define default options outside of the class
67
export const defaultPgProtoParserOptions: PgProtoParserOptions = {
7-
outDir: `${process.cwd()}/out`,
8+
outDir: join(process.cwd(), 'out'),
89
includeHeader: true,
910
exclude: [],
1011
utils: {

packages/proto-parser/test-utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const expectAstsCodeToEqual = (testAst: any, expectAst: any) => {
2929
}
3030

3131
export const readFilesFromDir = (outDir: string) =>
32-
glob(outDir + '**/*').map(file => ({ file: basename(file), code: readFileSync(file, 'utf-8') }));
32+
glob(join(outDir, '**/*')).map(file => ({ file: basename(file), code: readFileSync(file, 'utf-8') }));
3333

3434
export const FIXTURES_DIR = resolve(join(__dirname, '../../../__fixtures__/'));
3535

0 commit comments

Comments
 (0)