Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(website): [playground] correct issues with libs#5162

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 12 commits intomainfromfix/default-lib-import-5142
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
ac39c5f
chore(website): [playground] correct issues with changing default lib…
armano2Jun 8, 2022
25d8f18
chore(website): [playground] default lib to es6 + dom
armano2Jun 8, 2022
5e77452
chore(website): [playground] further refine lib handling, and remove …
armano2Jun 8, 2022
86e97b9
chore(website): [playground] remove unnecessary ?.
armano2Jun 8, 2022
97266b0
chore(website): [playground] improve resolving default libs
armano2Jun 9, 2022
3cf6e47
chore(website): [playground] revert incorrect change
armano2Jun 9, 2022
6ac8fbb
chore(website): [playground] move module augmentation to typings
armano2Jun 9, 2022
4997135
fix: improve default lib selection
armano2Jun 10, 2022
5ebc151
Merge remote-tracking branch 'origin/main' into fix/default-lib-impor…
armano2Jun 10, 2022
34aa7bb
Merge remote-tracking branch 'origin/main' into fix/default-lib-impor…
armano2Jun 10, 2022
ba22b89
fix: use ts build-in config parsing
armano2Jun 10, 2022
036f13c
Merge branch 'main' into fix/default-lib-import-5142
armano2Jun 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletionspackages/website/src/components/config/utils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,12 +34,16 @@ export function parseESLintRC(code?: string): EslintRC {
export function parseTSConfig(code?: string): TSConfig {
if (code) {
try {
const parsed: unknown = parse(code);
if (isRecord(parsed)) {
if ('compilerOptions' in parsed && isRecord(parsed.compilerOptions)) {
return parsed as TSConfig;
}
return { ...parsed, compilerOptions: {} };
const parsed = window.ts.parseConfigFileTextToJson(
'/tsconfig.json',
code,
);
if (parsed.error) {
// eslint-disable-next-line no-console
console.error(parsed.error);
}
if (isRecord(parsed.config)) {
return parsed.config as TSConfig;
}
} catch (e) {
// eslint-disable-next-line no-console
Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,12 +63,12 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
tsconfig: sandboxInstance.monaco.editor.createModel(
tsconfig,
'json',
sandboxInstance.monaco.Uri.file('./tsconfig.json'),
sandboxInstance.monaco.Uri.file('/tsconfig.json'),
),
eslintrc: sandboxInstance.monaco.editor.createModel(
eslintrc,
'json',
sandboxInstance.monaco.Uri.file('./.eslintrc'),
sandboxInstance.monaco.Uri.file('/.eslintrc'),
),
};
tabsDefault.code.updateOptions({ tabSize: 2, insertSpaces: true });
Expand Down
39 changes: 25 additions & 14 deletionspackages/website/src/components/editor/config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,20 +6,31 @@ export function createCompilerOptions(
jsx = false,
tsConfig: Record<string, unknown> = {},
): Monaco.languages.typescript.CompilerOptions {
return {
noResolve: true,
// 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,
moduleResolution: undefined,
plugins: undefined,
typeRoots: undefined,
paths: undefined,
moduleDetection: undefined,
baseUrl: undefined,
};
const config = window.ts.convertCompilerOptionsFromJson(
{
// ts and monaco has different type as monaco types are not changing base on ts version
target: 'esnext',
module: 'esnext',
...tsConfig,
jsx: jsx ? 'preserve' : undefined,
lib: Array.isArray(tsConfig.lib) ? tsConfig.lib : undefined,
moduleResolution: undefined,
plugins: undefined,
typeRoots: undefined,
paths: undefined,
moduleDetection: undefined,
baseUrl: undefined,
},
'/tsconfig.json',
);

const options = config.options as Monaco.languages.typescript.CompilerOptions;

if (!options.lib) {
options.lib = [window.ts.getDefaultLibFileName(options)];
}

return options;
}

export function getEslintSchema(
Expand Down
42 changes: 29 additions & 13 deletionspackages/website/src/components/editor/useSandboxServices.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,7 @@ export const useSandboxServices = (
formatOnType: true,
wrappingIndent: 'same',
},
acquireTypes: false,
compilerOptions: compilerOptions,
domID: editorEmbedId,
};
Expand All@@ -77,19 +78,34 @@ export const useSandboxServices = (
colorMode === 'dark' ? 'vs-dark' : 'vs-light',
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
const libs = ((window.ts as any).libs as string[]) ?? ['esnext'];

const libMap = await sandboxInstance.tsvfs.createDefaultMapFromCDN(
{
...sandboxInstance.getCompilerOptions(),
lib: libs.filter(item => !item.includes('.')),
},
props.ts,
true,
window.ts,
);
const system = sandboxInstance.tsvfs.createSystem(libMap);
let libEntries: Map<string, string> | undefined;
const worker = await sandboxInstance.getWorkerProcess();
if (worker.getLibFiles) {
libEntries = new Map(
Object.entries((await worker.getLibFiles()) ?? {}).map(item => [
'/' + item[0],
item[1],
]),
);
} else {
// for some older version of playground we do not have definitions available
libEntries = await sandboxInstance.tsvfs.createDefaultMapFromCDN(
{
lib: Array.from(window.ts.libMap.keys()),
},
props.ts,
true,
window.ts,
);
for (const pair of libEntries) {
sandboxInstance.languageServiceDefaults.addExtraLib(
pair[1],
'ts:' + pair[0],
);
}
}

const system = sandboxInstance.tsvfs.createSystem(libEntries);

const webLinter = new WebLinter(system, compilerOptions, lintUtils);

Expand Down
3 changes: 2 additions & 1 deletionpackages/website/src/vendor/sandbox.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -105,7 +105,8 @@ export declare const createTypeScriptSandbox: (
};
/** A list of TypeScript versions you can use with the TypeScript sandbox */
supportedVersions: readonly [
'4.6.2',
'4.7.3',
'4.6.4',
'4.5.5',
'4.4.4',
'4.3.5',
Expand Down
4 changes: 4 additions & 0 deletionspackages/website/src/vendor/tsWorker.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,10 @@ export declare class TypeScriptWorker implements ts.LanguageServiceHost {
formatOptions: ts.FormatCodeOptions,
): Promise<ReadonlyArray<ts.CodeFixAction>>;
updateExtraLibs(extraLibs: IExtraLibs): void;
/**
* https://github.com/microsoft/TypeScript-Website/blob/246798df5013036bd9b4389932b642c20ab35deb/packages/playground-worker/types.d.ts#L48
*/
getLibFiles(): Promise<Record<string, string>>;
}
export interface IExtraLib {
content: string;
Expand Down
1 change: 1 addition & 0 deletionspackages/website/typings/remark-docusaurus-tabs.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
declare module 'remark-docusaurus-tabs' {
import type { Plugin } from 'unified';

const plugin: Plugin;
export = plugin;
}
13 changes: 13 additions & 0 deletionspackages/website/typings/typescript.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
import 'typescript';

type StringMap = Map<string, string>;

declare module 'typescript' {
/**
* Map of available libraries
*
* The key is the key used in compilerOptions.lib
* The value is the file name
*/
const libMap: StringMap;
}

[8]ページ先頭

©2009-2025 Movatter.jp