mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-25 05:02:17 -04:00
feat(client): add tsconfig support to editor and use it in ts compiler (#66259)
This commit is contained in:
committed by
GitHub
parent
c9071dd6a9
commit
9356588e80
@@ -16,13 +16,25 @@ export class Compiler {
|
||||
this.tsvfs = tsvfs;
|
||||
}
|
||||
|
||||
async setup(opts?: { useNodeModules?: boolean; compilerOptions?: unknown }) {
|
||||
async setup(opts?: { useNodeModules?: boolean; tsconfig?: string }) {
|
||||
const ts = this.ts;
|
||||
const tsvfs = this.tsvfs;
|
||||
|
||||
const parsedOptions = ts.convertCompilerOptionsFromJson(
|
||||
opts?.compilerOptions ?? {},
|
||||
'/'
|
||||
// This just parses the JSON, it doesn't do any validation.
|
||||
const parsedOptions = opts?.tsconfig
|
||||
? (ts.parseConfigFileTextToJson('', opts.tsconfig).config as {
|
||||
compilerOptions?: unknown;
|
||||
})
|
||||
: undefined;
|
||||
|
||||
// For now we're only interested in the compilerOptions, so that's all we're
|
||||
// extracting and validating. For everything else, we could
|
||||
// parseJsonConfigFileContent and create a host using createSystem and
|
||||
// fsMap, but that needs compilerOptions... This is a bit of a chicken and
|
||||
// egg problem, which we don't need to solve yet.
|
||||
const validatedOptions = ts.convertCompilerOptionsFromJson(
|
||||
parsedOptions?.compilerOptions ?? {},
|
||||
'./'
|
||||
);
|
||||
|
||||
const compilerOptions: CompilerOptions = {
|
||||
@@ -34,7 +46,7 @@ export class Compiler {
|
||||
// 3.8.0-rc."
|
||||
jsx: ts.JsxEmit.Preserve, // Babel will handle JSX,
|
||||
allowUmdGlobalAccess: true, // Necessary because React is loaded via a UMD script.
|
||||
...parsedOptions.options
|
||||
...validatedOptions.options
|
||||
};
|
||||
|
||||
const fsMap = opts?.useNodeModules
|
||||
|
||||
Reference in New Issue
Block a user