Skip to content

Commit 617a333

Browse files
author
Timofey
authored
fix(conf): lazy load cosmiconfig's TypeScriptLoader (#1403)
1 parent bf7f655 commit 617a333

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

packages/conf/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@
3434
],
3535
"devDependencies": {
3636
"ts-node": "^10.9.1"
37+
},
38+
"peerDependencies": {
39+
"ts-node": ">=10",
40+
"typescript": ">=4"
41+
},
42+
"peerDependenciesMeta": {
43+
"ts-node": {
44+
"optional": true
45+
},
46+
"typescript": {
47+
"optional": true
48+
}
3749
}
3850
}

packages/conf/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import type { GeneratorOptions } from "@babel/core"
22
import path from "path"
33
import fs from "fs"
44
import chalk from "chalk"
5-
import { cosmiconfigSync } from "cosmiconfig"
5+
import { cosmiconfigSync, type LoaderSync } from "cosmiconfig"
66
import { multipleValidOptions, validate } from "jest-validate"
7-
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
87

98
export type CatalogFormat = "lingui" | "minimal" | "po" | "csv"
109

@@ -104,6 +103,19 @@ function configExists(path) {
104103
return path && fs.existsSync(path)
105104
}
106105

106+
function TypeScriptLoader(): LoaderSync {
107+
let loaderInstance: LoaderSync
108+
return (filepath, content) => {
109+
if (!loaderInstance) {
110+
const { TypeScriptLoader } =
111+
require("cosmiconfig-typescript-loader") as typeof import("cosmiconfig-typescript-loader")
112+
loaderInstance = TypeScriptLoader()
113+
}
114+
115+
return loaderInstance(filepath, content)
116+
}
117+
}
118+
107119
export function getConfig({
108120
cwd,
109121
configPath,

0 commit comments

Comments
 (0)