Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(website): pass user defined compilerOptions to linter #5080

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions packages/website/src/components/editor/LoadedEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { WebLinter } from '../linter/WebLinter';
import { debounce } from '../lib/debounce';
import { lintCode, LintCodeAction } from '../linter/lintCode';
import { createProvideCodeActions } from './createProvideCodeActions';
import { createCompilerOptions } from '@site/src/components/editor/config';
import { parseMarkers } from '../linter/utils';

export interface LoadedEditorProps extends CommonEditorProps {
Expand Down Expand Up @@ -39,13 +40,7 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
const fixes = useRef(new Map<string, LintCodeAction[]>()).current;

useEffect(() => {
const config = {
noResolve: true,
target: main.languages.typescript.ScriptTarget.ESNext,
module: main.languages.typescript.ModuleKind.ESNext,
...tsConfig,
jsx: jsx ? main.languages.typescript.JsxEmit.React : undefined,
};
const config = createCompilerOptions(jsx, tsConfig);

webLinter.updateOptions(config);
sandboxInstance.setCompilerSettings(config);
Expand Down
16 changes: 16 additions & 0 deletions packages/website/src/components/editor/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type Monaco from 'monaco-editor';

export function createCompilerOptions(
jsx = false,
tsConfig: Record<string, unknown> = {},
): Monaco.languages.typescript.CompilerOptions {
return {
noResolve: true,
lib: ['es2021', 'esnext'],
// ts and monaco has different type as monaco types are not changing base on ts version
target: window.ts.ScriptTarget.ESNext as number,
module: window.ts.ModuleKind.ESNext as number,
...tsConfig,
jsx: jsx ? window.ts.JsxEmit.Preserve : window.ts.JsxEmit.None,
};
}
9 changes: 2 additions & 7 deletions packages/website/src/components/editor/useSandboxServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { WebLinter } from '../linter/WebLinter';
import { sandboxSingleton } from './loadSandbox';
import { editorEmbedId } from './EditorEmbed';
import { useColorMode } from '@docusaurus/theme-common';
import { createCompilerOptions } from '@site/src/components/editor/config';

export interface SandboxServicesProps {
readonly jsx?: boolean;
Expand Down Expand Up @@ -51,13 +52,7 @@ export const useSandboxServices = (

sandboxSingleton(props.ts)
.then(async ({ main, sandboxFactory, ts, lintUtils }) => {
const compilerOptions: Monaco.languages.typescript.CompilerOptions = {
noResolve: true,
target: main.languages.typescript.ScriptTarget.ESNext,
jsx: props.jsx ? main.languages.typescript.JsxEmit.React : undefined,
lib: ['es2021', 'esnext'],
module: main.languages.typescript.ModuleKind.ESNext,
};
const compilerOptions = createCompilerOptions(props.jsx);

const sandboxConfig: Partial<SandboxConfig> = {
text: '',
Expand Down