Skip to content

Conversation

@JoMind
Copy link
Contributor

@JoMind JoMind commented Jul 4, 2025

Key Changes

  1. Use rimraf for the "clean" script

    rm -rf is not available on Windows. apps/typesync/package.json now uses rimraf so the command works on all platforms.

  2. Ship a cross-platform File-system migration loader

    Problem – The loader that ships with @effect/sql builds the specifier for import() with an OS-specific path (e.g. C:\project\…\1_init.js). On Windows, the Node.js ESM resolver treats the leading C: as a URL scheme and throws the following error:

    Only URLs with a scheme in: file, data, and node are supported …
    Received protocol 'c:'

    (See nodejs/node#31710, effect-ts/effect#4297).

    Fix – We added src/Utils.ts::fromFileSystem() which:

    • Keeps directory as a plain OS path when calling FileSystem.readDirectory.
    • Converts the specifier given to import() with pathToFileURL(...).href (e.g. file:///C:/project/…/1_init.js).
    • Accepts both / and \ in the filename RegExp.

    The loader is plugged into DatabaseService:

    import { fromFileSystem } from "./Utils.js";
    
    const MigratorLive = Migrator.layer({
      loader: fromFileSystem(
        fileURLToPath(new URL("migrations", import.meta.url)),
      ),
    }).pipe(Layer.provide(SqlLive));

    Behaviour on Linux/macOS is unchanged; migrations now load on Windows as well.

These two changes eliminate the build error on clean and the runtime error, so the project builds and runs successfully on Windows, Linux, and macOS.

@JoMind JoMind marked this pull request as draft July 4, 2025 15:36
@JoMind JoMind force-pushed the fix/cross-platform-typesync branch from 07a823d to efecdab Compare July 4, 2025 17:02
@JoMind JoMind marked this pull request as ready for review July 4, 2025 17:29
@nikgraf nikgraf requested a review from Copilot July 5, 2025 09:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures typesync builds and runs on Windows by replacing platform-specific scripts and fixing dynamic import paths.

  • Swaps rm -rf for cross-platform rimraf in the clean script
  • Introduces fromFileSystem to convert OS paths to file:// URLs for the migration loader
  • Updates Database.ts to use the new loader

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
apps/typesync/package.json Replaced "rm -rf" with "rimraf" in the clean script and added rimraf to devDependencies
apps/typesync/src/Utils.ts Added fromFileSystem loader that uses pathToFileURL to support Windows migration imports
apps/typesync/src/Database.ts Switched Migrator loader to use the new fromFileSystem function
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

apps/typesync/src/Utils.ts:146

  • Add unit tests for the fromFileSystem loader to cover both POSIX and Windows-style file names and ensure that the import() URL conversion behaves correctly under each environment.
export const fromFileSystem = (

apps/typesync/src/Utils.ts:139

  • Expand the JSDoc for fromFileSystem to include a description of the dir parameter and the returned loader type, clarifying expected input and behavior.
/**

Effect.promise(() =>
import(
/* @vite-ignore */ /* webpackIgnore: true */
pathToFileURL(`${dir}/${basename}`).href,
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use path.join or path.resolve to combine dir and basename when constructing the file path, e.g., pathToFileURL(path.join(dir, basename)).href for clarity and cross-platform safety.

Copilot uses AI. Check for mistakes.
loader: Migrator.fromFileSystem(fileURLToPath(new URL('migrations', import.meta.url))),
}).pipe(Layer.provide(SqlLive));
loader: fromFileSystem(fileURLToPath(new URL('migrations', import.meta.url))),
}).pipe(Layer.provide(SqlLive))
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add a semicolon at the end of this statement to maintain consistency with the surrounding code style.

Suggested change
}).pipe(Layer.provide(SqlLive))
}).pipe(Layer.provide(SqlLive));

Copilot uses AI. Check for mistakes.
@nikgraf
Copy link
Collaborator

nikgraf commented Jul 5, 2025

@JoMind great changes, thanks! Can you reapply your commits as signed commits. Due merge rules I can't merge in the organization I can't merge without.

If too complicated let me know and I can try to get your commits and re-apply them manually.

@JoMind JoMind force-pushed the fix/cross-platform-typesync branch from dc1f88b to efecdab Compare July 5, 2025 15:27
JoMind added 2 commits July 5, 2025 16:43
Replaces the \
m -rf\ command with \
imraf\ so the clean script works on Windows, macOS, and Linux.

Affected files:

 • apps/typesync/package.json – updated "clean" script
Problem
-------
`@effect/sql`’s File-system loader passes a raw Win32 path such as

  C:\project\apps\typesync\src\migrations\1_create_table__app.js

directly to `import()`.
On Windows the Node ESM loader interprets the leading
“C:” as a URL scheme and throws:

  Only URLs with a scheme in: file, data, and node are supported …
  Received protocol 'c:'

(Linux and macOS do not throw because the path starts with '/'.)

See Node issue: nodejs/node#31710
See Effect issue: Effect-TS/effect#4297

Fix
---
1. Keep `dir` as a *plain OS path* when calling
   `FileSystem.readDirectory(dir)` (still required by platform-fs).

2. Convert the specifier used by the dynamic `import()` to a **file URL**
   with `pathToFileURL(...).href`.

3. Extend the filename RegExp to accept both “/” and “\” separators.

Result
------
• Behaviour on POSIX remains unchanged.
• Migrations now load correctly on Windows.
• No other library code is touched; the change can be removed once the
  upstream patch is released.

Affected files:

 • apps/typesync/src/Database.ts – use fromFileSystem() helper
 • apps/typesync/src/Utils.ts – add fromFileSystem() helper
@JoMind JoMind force-pushed the fix/cross-platform-typesync branch from efecdab to 9496567 Compare July 5, 2025 15:44
@JoMind
Copy link
Contributor Author

JoMind commented Jul 5, 2025

@JoMind great changes, thanks! Can you reapply your commits as signed commits. Due merge rules I can't merge in the organization I can't merge without.

If too complicated let me know and I can try to get your commits and re-apply them manually.

Sure, signed.

@nikgraf nikgraf mentioned this pull request Jul 7, 2025
@nikgraf nikgraf merged commit 0045798 into graphprotocol:main Jul 8, 2025
0 of 2 checks passed
@yanivtal yanivtal mentioned this pull request Jul 9, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants