fix(core): use file:// URLs for command autoload imports#180
Conversation
Resolves #179. On Windows, kidd's runtime autoloader silently failed to register every subcommand because absolute filesystem paths (with backslashes and drive letters) are not valid ESM specifiers. `import()` threw `ERR_UNSUPPORTED_ESM_URL_SCHEME` for each command file; the error was swallowed unless `KIDD_DEBUG=1`, leaving yargs with no subcommands and reporting "Unknown arguments: build" for `kidd build --compile`. Convert the absolute path to a `file://` URL via `pathToFileURL` before passing it to `import()` so command files load on both platforms. Co-Authored-By: Claude <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: e3edcf9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes Windows subcommand registration by converting dynamic import paths to Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Merging this PR will degrade performance by 27.4%
Performance Changes
Comparing Footnotes
|
Summary
Fixes #179. On Windows,
kidd <subcommand>printed "Unknown arguments" for every positional because the runtime autoloader silently failed to register any commands. The cause:packages/core/src/autoload.tspassed absolute filesystem paths straight to ESMimport(). Node ESM rejects backslash-only paths and treatsC:as an unknown URL scheme (ERR_UNSUPPORTED_ESM_URL_SCHEME). The error was swallowed unlessKIDD_DEBUG=1.path.joinwas doing the right thing — building OS-native paths. The bug was the next step: those native paths aren't valid ESM specifiers. Fix: convert withpathToFileURL(...).hreffromnode:urlbeforeimport(), which producesfile:///...URLs that resolve identically on macOS, Linux, and Windows.Changes
packages/core/src/autoload.ts— wrap the path inpathToFileURL(filePath).hrefbefore the dynamic import; update the debug warning to log the URL formpackages/core/src/autoload.test.ts— mocknode:url'spathToFileURLto passthrough so existing path-formvi.doMockkeys still match (vitest can't interceptfile://specifiers through helper indirection); add a regression test assertingpathToFileURLis invoked for command files.changeset/fix-windows-autoload-paths.md—@kidd-cli/corepatch changesetTest plan
pnpm check(typecheck + lint + format) passespnpm testpasses (1075 core tests, 17 tasks)pathToFileURLis called on the absolute pathkidd build --compile,kidd dev,kidd storiesall execute their handlers instead of yargs printing "Unknown arguments"Out of scope
There is a related concern in
packages/bundler/src/autoloader/generate-autoloader.ts— it embeds native filesystem paths into generatedimportstring literals, which would also break when building a CLI on Windows. That isn't the symptom reported in #179 (which is purely runtime command discovery in@kidd-cli/cli), so it's deliberately not included here. Happy to follow up in a separate PR if Windows testing surfaces it.