Skip to content

Commit 0e482f4

Browse files
committed
fix: resolve .ts extension import error in CLI by implementing config helpers in JS
1 parent fb0c14c commit 0e482f4

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

bin/lib/desktopConfig.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
1-
export {
2-
DESKTOP_CONFIG_FILENAME,
3-
LEGACY_DESKTOP_CONFIG_FILENAME,
4-
LEGACY_CONFIG_DEPRECATION,
5-
resolveDesktopConfigPath,
6-
warnLegacyDesktopConfig,
7-
desktopConfigWritePath,
8-
} from '@owdproject/core/kit/authoring.ts'
1+
import { existsSync } from 'node:fs'
2+
import { join } from 'node:path'
3+
4+
export const DESKTOP_CONFIG_FILENAME = 'desktop.config.ts'
5+
export const LEGACY_DESKTOP_CONFIG_FILENAME = 'owd.config.ts'
6+
7+
export const LEGACY_CONFIG_DEPRECATION =
8+
'[@owdproject/core] owd.config.ts is deprecated and kept only for backward compatibility; rename to desktop.config.ts (required from @owdproject/core 3.2).'
9+
10+
export function resolveDesktopConfigPath(rootDir) {
11+
const desktopPath = join(rootDir, DESKTOP_CONFIG_FILENAME)
12+
const legacyPath = join(rootDir, LEGACY_DESKTOP_CONFIG_FILENAME)
13+
const hasDesktop = existsSync(desktopPath)
14+
const hasLegacy = existsSync(legacyPath)
15+
16+
if (hasDesktop && hasLegacy) {
17+
console.warn(
18+
'[@owdproject/core] Both desktop.config.ts and owd.config.ts exist; using desktop.config.ts. Remove owd.config.ts.',
19+
)
20+
return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false }
21+
}
22+
23+
if (hasDesktop) {
24+
return { path: desktopPath, file: DESKTOP_CONFIG_FILENAME, legacy: false }
25+
}
26+
27+
if (hasLegacy) {
28+
return {
29+
path: legacyPath,
30+
file: LEGACY_DESKTOP_CONFIG_FILENAME,
31+
legacy: true,
32+
}
33+
}
34+
35+
return null
36+
}
37+
38+
export function warnLegacyDesktopConfig(resolved) {
39+
if (resolved?.legacy) {
40+
console.warn(LEGACY_CONFIG_DEPRECATION)
41+
}
42+
}
43+
44+
/** Path used when creating or updating config from the CLI (always the new filename). */
45+
export function desktopConfigWritePath(desktopDir) {
46+
return join(desktopDir, DESKTOP_CONFIG_FILENAME)
47+
}
48+

0 commit comments

Comments
 (0)