fix: support Windows launcher import paths
This commit is contained in:
7
bin/import-specifier.mjs
Normal file
7
bin/import-specifier.mjs
Normal file
@@ -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
|
||||
}
|
||||
13
bin/import-specifier.test.mjs
Normal file
13
bin/import-specifier.test.mjs
Normal file
@@ -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',
|
||||
)
|
||||
})
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user