Skip to content

Commit

Permalink
fix(conf): lazy load cosmiconfig's TypeScriptLoader (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekip committed Feb 6, 2023
1 parent bf7f655 commit 617a333
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@
],
"devDependencies": {
"ts-node": "^10.9.1"
},
"peerDependencies": {
"ts-node": ">=10",
"typescript": ">=4"
},
"peerDependenciesMeta": {
"ts-node": {
"optional": true
},
"typescript": {
"optional": true
}
}
}
16 changes: 14 additions & 2 deletions packages/conf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type { GeneratorOptions } from "@babel/core"
import path from "path"
import fs from "fs"
import chalk from "chalk"
import { cosmiconfigSync } from "cosmiconfig"
import { cosmiconfigSync, type LoaderSync } from "cosmiconfig"
import { multipleValidOptions, validate } from "jest-validate"
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";

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

Expand Down Expand Up @@ -104,6 +103,19 @@ function configExists(path) {
return path && fs.existsSync(path)
}

function TypeScriptLoader(): LoaderSync {
let loaderInstance: LoaderSync
return (filepath, content) => {
if (!loaderInstance) {
const { TypeScriptLoader } =
require("cosmiconfig-typescript-loader") as typeof import("cosmiconfig-typescript-loader")
loaderInstance = TypeScriptLoader()
}

return loaderInstance(filepath, content)
}
}

export function getConfig({
cwd,
configPath,
Expand Down

1 comment on commit 617a333

@vercel
Copy link

@vercel vercel bot commented on 617a333 Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.