fix(scripts): use pathToFileURL for ESM entrypoint check on Windows#7
Open
yugao-gaos wants to merge 1 commit into
Open
fix(scripts): use pathToFileURL for ESM entrypoint check on Windows#7yugao-gaos wants to merge 1 commit into
yugao-gaos wants to merge 1 commit into
Conversation
The check `import.meta.url === \`file://${process.argv[1]}\`` fails silently
on Windows because import.meta.url uses forward-slash file URLs
(file:///D:/...) while process.argv[1] uses backslash paths (D:\...).
Scripts exit 0 without ever running main().
Swap to `pathToFileURL(process.argv[1]).href` which constructs the matching
file URL regardless of platform. Affects 15 generation/project scripts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, all 15
.mjsscripts under.claude/scripts/exit silently with code 0 without ever running theirmain().Root cause: the standard ESM "is this script the entrypoint" check uses
On Windows:
import.meta.urlresolves tofile:///D:/.../foo.mjs(forward slashes)process.argv[1]resolves toD:\...\foo.mjs(backslashes)main()never runsVerified by running
node .claude/scripts/project/project-state.mjs --world test --stage-input— exit code 0, no output, no directories created. macOS / Linux are unaffected because their paths and file URLs share the same separator.Fix
Use
url.pathToFileURL()to construct the comparison URL with platform-correct encoding:pathToFileURLproducesfile:///D:/.../foo.mjson Windows andfile:///foo/bar.mjson POSIX, which matchesimport.meta.urlexactly in both cases.Scope
Applied to every script that uses this pattern (15 total):
.claude/scripts/asset-pipeline/*.mjs(7 files).claude/scripts/fal/run-fal.mjs.claude/scripts/image-edit/generate-edit.mjs.claude/scripts/project/*.mjs(5 files).claude/scripts/sfx/fal-elevenlabs-sfx.mjs.claude/scripts/world/generate-world.mjsEach file got two changes:
import { pathToFileURL } from "node:url";Total diff: +30 / -15 lines, no behavior change on macOS / Linux.
Test
Re-ran
project-state.mjsafter the fix on Windows 11 + Node 24.11 — emits the expected JSON state and creates theworlds/<slug>/tree. Other scripts verified by running the IMAGE-BLAST pipeline end-to-end on Windows: clean plate (Agent(image-blast-plate)), world generation (Agent(image-blast-world)), and 3D mesh generation (Agent(image-blast-3d)) all succeed where they previously no-op'd.🤖 Generated with Claude Code