-
As me and @ryardley came to the idea of not-drilling down the server config in there: #878 (comment) I am opening this threat to discuss if it make sense to create some global place from where the My idea is something like this (not tested just came to my mind now):
let cachedConfig: NormalizedConfig | null = null
export async function getNormalizedConfig(
config: ServerConfig,
useCache: boolean = true,
): Promise<NormalizedConfig> {
if (!useCache || cachedConfig === null) {
// maybe use `config.rootFolder || pkgDir.sync() || process.cwd()`, is it there any benefit using pkgDir?
const rootFolder = config.rootFolder || process.cwd();
// do not await for both bin-pkg because always just one is used
const nextBinPkg = config.interceptNextErrors ? "@blitzjs/server" : "next"
const nextBinExec = config.interceptNextErrors ? "next-patched" : undefined
const nextBin = await resolveBinAsync(nextBinPkg, nextBinExec)
const git = parseChokidarRulesFromGitignore(resolve(process.cwd(), rootFolder))
const isTypescript = fs.existsSync(path.join(rootFolder, "tsconfig.json"))
cachedConfig = {
...config,
buildFolder: resolve(rootFolder, config.buildFolder ?? defaults.buildFolder),
devFolder: resolve(rootFolder, config.devFolder ?? defaults.devFolder),
ignore: defaults.ignoredPaths.concat(git.ignoredPaths),
include: defaults.includePaths.concat(git.includePaths),
nextBin: resolve(rootFolder, nextBin),
transformFiles: config.transformFiles ?? transformFiles,
watch: config.watch ?? false,
writeManifestFile: config.writeManifestFile ?? defaults.writeManifestFile,
isTypescript: isTypescript ?? true,
}
}
return cachedConfig;
} I think it would be easily to get current server config with How does it sound to others? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Sounds like a good idea to me! |
Beta Was this translation helpful? Give feedback.
-
Cool. Is that something I should start the working on or should I wait for more opinions? :-) |
Beta Was this translation helpful? Give feedback.
-
After a small time of investigating in this I came up to resolution that initial idea of caching the server config leads to no benefits. It breaks the "pure" concept of Instead of caching I created PR with small server code refactor and made possible to skip TS checking by explicitly provide new flag |
Beta Was this translation helpful? Give feedback.
After a small time of investigating in this I came up to resolution that initial idea of caching the server config leads to no benefits. It breaks the "pure" concept of
normalize
function in server package and makes future testing hard to maintain. So therefore I do not think that server config caching is benefical here any more.Instead of caching I created PR with small server code refactor and made possible to skip TS checking by explicitly provide new flag
--ts
--> #1014