Skip to content

Commit 0045798

Browse files
authored
This PR resolves two critical issues that prevented the typesync application from building and running correctly on Windows environments. These changes ensure a consistent developer experience across all operating systems. (#317)
1 parent 9f482bb commit 0045798

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

apps/typesync/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dev": "vite build && pnpx tsx ./src/bin.ts typesync",
2828
"dev:cli": "pnpx tsx ./src/bin.ts typesync",
2929
"dev:client": "vite --force",
30-
"clean": "rm -rf dist client/dist",
30+
"clean": "rimraf dist client/dist",
3131
"start": "node ./dist/bin.js",
3232
"check": "tsc --noEmit",
3333
"test": "vitest run",
@@ -59,7 +59,8 @@
5959
"glob": "^11.0.3",
6060
"tsup": "^8.5.0",
6161
"tsx": "^4.20.3",
62-
"vite": "^6.3.5"
62+
"vite": "^6.3.5",
63+
"rimraf": "^6.0.1"
6364
},
6465
"dependencies": {
6566
"@graphql-typed-document-node/core": "^3.2.0",

apps/typesync/src/Database.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { Chunk, Console, Effect, Array as EffectArray, Layer, Option, Order, Sch
66

77
import * as TypesyncDomain from '../domain/Domain.js';
88
import * as Domain from './Domain.js';
9+
import { fromFileSystem } from './Utils.js';
910

1011
const SqlLive = SqliteClient.layer({
1112
filename: '.typesync.db',
1213
});
14+
1315
const MigratorLive = Migrator.layer({
14-
loader: Migrator.fromFileSystem(fileURLToPath(new URL('migrations', import.meta.url))),
15-
}).pipe(Layer.provide(SqlLive));
16+
loader: fromFileSystem(fileURLToPath(new URL('migrations', import.meta.url))),
17+
}).pipe(Layer.provide(SqlLive))
1618

1719
const DatabaseLive = Layer.mergeAll(SqlLive, MigratorLive).pipe(Layer.provide(NodeContext.layer));
1820

apps/typesync/src/Utils.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,54 @@ export class InvalidInputError extends Data.TaggedError('/typesync/errors/Invali
125125
readonly input: string;
126126
readonly cause: unknown;
127127
}> {}
128+
129+
/* ------------------------------------------------------------------ */
130+
/* Windows-safe migration loader */
131+
/* ------------------------------------------------------------------ */
132+
133+
import { pathToFileURL } from "node:url"
134+
import { FileSystem } from "@effect/platform/FileSystem"
135+
import * as Effect from "effect/Effect"
136+
import type { Loader, ResolvedMigration } from "@effect/sql/Migrator"
137+
import { MigrationError } from "@effect/sql/Migrator"
138+
139+
/**
140+
* Patched version of
141+
* `@effect/sql/Migrator/FileSystem.fromFileSystem`.
142+
*
143+
* The only difference is that the dynamic `import()` receives a proper
144+
* `file://` URL, so it works on Windows as well as on Linux / macOS.
145+
*/
146+
export const fromFileSystem = (
147+
dir: string,
148+
): Loader<FileSystem> =>
149+
FileSystem.pipe(
150+
/* read directory ----------------------------------------------------- */
151+
Effect.flatMap((FS) => FS.readDirectory(dir)),
152+
Effect.mapError(
153+
(e) => new MigrationError({ reason: "failed", message: e.message }),
154+
),
155+
/* build migration list ---------------------------------------------- */
156+
Effect.map((files): ReadonlyArray<ResolvedMigration> =>
157+
files
158+
.flatMap((file) => {
159+
const m =
160+
file.match(/^(?:.*[\\/])?(\d+)_([^.]+)\.(js|ts)$/) // win/posix
161+
if (!m) return []
162+
const [basename, id, name] = m
163+
return [
164+
[
165+
Number(id),
166+
name,
167+
Effect.promise(() =>
168+
import(
169+
/* @vite-ignore */ /* webpackIgnore: true */
170+
pathToFileURL(`${dir}/${basename}`).href,
171+
),
172+
),
173+
],
174+
] as const
175+
})
176+
.sort(([a], [b]) => a - b),
177+
),
178+
)

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)