diff --git a/bin/import-specifier.mjs b/bin/import-specifier.mjs new file mode 100644 index 00000000..4fcc5d3c --- /dev/null +++ b/bin/import-specifier.mjs @@ -0,0 +1,7 @@ +import { join } from 'path' +import { pathToFileURL } from 'url' + +export function getDistImportSpecifier(baseDir) { + const distPath = join(baseDir, '..', 'dist', 'cli.mjs') + return pathToFileURL(distPath).href +} diff --git a/bin/import-specifier.test.mjs b/bin/import-specifier.test.mjs new file mode 100644 index 00000000..5b6ef270 --- /dev/null +++ b/bin/import-specifier.test.mjs @@ -0,0 +1,13 @@ +import assert from 'node:assert/strict' +import test from 'node:test' + +import { getDistImportSpecifier } from './import-specifier.mjs' + +test('builds a file URL import specifier for dist/cli.mjs', () => { + const specifier = getDistImportSpecifier('C:\\repo\\bin') + + assert.equal( + specifier, + 'file:///C:/repo/dist/cli.mjs', + ) +}) diff --git a/bin/openclaude b/bin/openclaude index fee65ddf..a5688523 100755 --- a/bin/openclaude +++ b/bin/openclaude @@ -10,12 +10,13 @@ import { existsSync } from 'fs' import { join, dirname } from 'path' import { fileURLToPath } from 'url' +import { getDistImportSpecifier } from './import-specifier.mjs' const __dirname = dirname(fileURLToPath(import.meta.url)) const distPath = join(__dirname, '..', 'dist', 'cli.mjs') if (existsSync(distPath)) { - await import(distPath) + await import(getDistImportSpecifier(__dirname)) } else { console.error(` openclaude: dist/cli.mjs not found.