Skip to content

fix(scripts): decode file:// URLs so a checkout path with spaces works - #23

Open
john-the-dev wants to merge 1 commit into
mainfrom
fix/decode-file-urls
Open

fix(scripts): decode file:// URLs so a checkout path with spaces works#23
john-the-dev wants to merge 1 commit into
mainfrom
fix/decode-file-urls

Conversation

@john-the-dev

Copy link
Copy Markdown
Owner

Follow-up to the incidental finding in #22, as offered there.

The bug

new URL(...).pathname returns a percent-encoded path. Any checkout whose directory contains a space then resolves to a name that does not exist. Both entry points have it:

scripts/lib.mjs:12     ENTRIES_DIR = new URL("../entries/", import.meta.url).pathname
scripts/build.mjs:10   DIST        = new URL("../dist/",    import.meta.url).pathname

fileURLToPath() is the documented conversion and decodes correctly.

Evidence

From a checkout under .../Application Support/..., same path both runs:

before   validate.mjs  rc=1   ENOENT ... /Application%20Support/.../entries
         build.mjs     rc=1   ENOENT ... /Application%20Support/.../dist
after    validate.mjs  rc=0   ✅ 59 entries valid. 48 warning(s).
         build.mjs     rc=0   Built dist/kb.json — 59 entries. Grades: {"unrated":48,"A":11}

build.mjs was failing for the same reason and would have kept failing after a lib.mjs-only fix — worth fixing both rather than the one that surfaced.

Scope

Two lines plus two imports. dist/ is deliberately not included: running build.mjs to verify regenerates it, and a rebuilt artifact does not belong in a fix commit — I restored it before committing.

CI is unaffected either way, since its checkout path has no spaces. That is also why this survived: the failure is invisible to the only environment that runs the scripts automatically.

`new URL(...).pathname` returns a percent-encoded path, so any checkout whose
directory contains a space resolves to a name that does not exist. Both entry
points hit it:

  scripts/lib.mjs:12    ENTRIES_DIR = new URL("../entries/", import.meta.url).pathname
  scripts/build.mjs:10  DIST        = new URL("../dist/",    import.meta.url).pathname

`fileURLToPath()` is the API that decodes, and is what Node documents for this
conversion.

Measured from a checkout under ".../Application Support/...":

  before   validate.mjs rc=1   ENOENT ... /Application%20Support/...
           build.mjs    rc=1   ENOENT ... /Application%20Support/...
  after    validate.mjs rc=0   59 entries valid, 48 warnings
           build.mjs    rc=0   Built dist/kb.json — 59 entries

CI is unaffected either way — its checkout path has no spaces — so this only
ever showed up locally, which is also why it survived.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant