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

fix(website): update hash value if problem occurs due to ts version error#11292

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

Open
developer-bandi wants to merge5 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromdeveloper-bandi:website/tsversion-error
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
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
1 change: 1 addition & 0 deletionspackages/website/src/components/Playground.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -152,6 +152,7 @@ function Playground(): React.JSX.Element {
onMarkersChange={setMarkers}
onSelect={setPosition}
selectedRange={selectedRange}
setState={setState}
/>
</Panel>
<PanelResizeHandle className={styles.PanelResizeHandle} />
Expand Down
229 changes: 131 additions & 98 deletionspackages/website/src/components/editor/useSandboxServices.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ import semverSatisfies from 'semver/functions/satisfies';
import type { createTypeScriptSandbox } from '../../vendor/sandbox';
import type { CreateLinter } from '../linter/createLinter';
import type { PlaygroundSystem } from '../linter/types';
import type { RuleDetails } from '../types';
import type {ConfigModel,RuleDetails } from '../types';
import type { CommonEditorProps } from './types';

import rootPackageJson from '../../../../../package.json';
Expand All@@ -23,6 +23,7 @@ export interface SandboxServicesProps {
ruleDetails: RuleDetails[],
tsVersions: readonly string[],
) => void;
readonly setState: (value: Partial<ConfigModel>) => void;
readonly ts: string;
}

Expand All@@ -34,6 +35,23 @@ export interface SandboxServices {
webLinter: CreateLinter;
}

const checkUseSupportedTypescriptVersion = async (tsVersion: string) => {
const supportedVersionsResponse = await fetch(
'https://typescript.azureedge.net/indexes/releases.json',
);

if (supportedVersionsResponse.ok) {
const supportedVersions = (await supportedVersionsResponse.json()) as {
versions: string[];
};
const filteredVersions = supportedVersions.versions.filter(item =>
semverSatisfies(item, rootPackageJson.devDependencies.typescript),
);
return filteredVersions.includes(tsVersion);
}
return false;
};

export const useSandboxServices = (
props: CommonEditorProps & SandboxServicesProps,
): Error | SandboxServices | undefined => {
Expand All@@ -44,107 +62,122 @@ export const useSandboxServices = (
useEffect(() => {
let sandboxInstance: SandboxInstance | undefined;

sandboxSingleton(props.ts)
.then(async ({ lintUtils, main, sandboxFactory }) => {
const compilerOptions = createCompilerOptions();

sandboxInstance = sandboxFactory.createTypeScriptSandbox(
{
acquireTypes: true,
compilerOptions:
compilerOptions as Monaco.languages.typescript.CompilerOptions,
domID: editorEmbedId,
monacoSettings: {
autoIndent: 'full',
fontSize: 13,
formatOnPaste: true,
formatOnType: true,
hover: { above: false },
minimap: { enabled: false },
scrollBeyondLastLine: false,
smoothScrolling: true,
wordWrap: 'off',
wrappingIndent: 'same',
},
text: props.code,
},
main,
window.ts,
);
sandboxInstance.monaco.editor.setTheme(
colorMode === 'dark' ? 'vs-dark' : 'vs-light',
);

sandboxInstance.monaco.languages.registerInlayHintsProvider(
sandboxInstance.language,
createTwoslashInlayProvider(sandboxInstance),
);

const system = createFileSystem(props, sandboxInstance.tsvfs);

// Write files in vfs when a model is created in the editor (this is used only for ATA types)
sandboxInstance.monaco.editor.onDidCreateModel(model => {
if (!model.uri.path.includes('node_modules')) {
return;
}
const path = model.uri.path.replace('/file:///', '/');
system.writeFile(path, model.getValue());
});
// Delete files in vfs when a model is disposed in the editor (this is used only for ATA types)
sandboxInstance.monaco.editor.onWillDisposeModel(model => {
if (!model.uri.path.includes('node_modules')) {
return;
}
const path = model.uri.path.replace('/file:///', '/');
system.deleteFile(path);
});

// Load the lib files from typescript to vfs (eg. es2020.d.ts)
const worker = await sandboxInstance.getWorkerProcess();
if (worker.getLibFiles) {
const libs = await worker.getLibFiles();
for (const [key, value] of Object.entries(libs)) {
system.writeFile(`/${key}`, value);
}
checkUseSupportedTypescriptVersion(props.ts)
.then(res => {
if (!res) {
props.setState({ ts: process.env.TS_VERSION });
}

window.system = system;
window.esquery = lintUtils.esquery;
window.visitorKeys = lintUtils.visitorKeys;

const webLinter = createLinter(
system,
lintUtils,
sandboxInstance.tsvfs,
);

onLoaded(
[...webLinter.rules.values()],
[
...new Set([
window.ts.version,
...sandboxInstance.supportedVersions,
]),
]
.filter(item =>
semverSatisfies(item, rootPackageJson.devDependencies.typescript),
)
.sort((a, b) => b.localeCompare(a)),
);

setServices({
sandboxInstance,
system,
webLinter,
});
})
.then(() => {
sandboxSingleton(props.ts)
.then(async ({ lintUtils, main, sandboxFactory }) => {
Comment on lines +71 to +73

Choose a reason for hiding this comment

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

[Refactor] The code already has anasync inside a.then(() => {. Could you please refactor the new code so that it keeps to theasync/await pattern where possible? That'll reduce the noise from this diff. Which is non-trivial and making it hard to review.

const compilerOptions = createCompilerOptions();

sandboxInstance = sandboxFactory.createTypeScriptSandbox(
{
acquireTypes: true,
compilerOptions:
compilerOptions as Monaco.languages.typescript.CompilerOptions,
domID: editorEmbedId,
monacoSettings: {
autoIndent: 'full',
fontSize: 13,
formatOnPaste: true,
formatOnType: true,
hover: { above: false },
minimap: { enabled: false },
scrollBeyondLastLine: false,
smoothScrolling: true,
wordWrap: 'off',
wrappingIndent: 'same',
},
text: props.code,
},
main,
window.ts,
);
sandboxInstance.monaco.editor.setTheme(
colorMode === 'dark' ? 'vs-dark' : 'vs-light',
);

sandboxInstance.monaco.languages.registerInlayHintsProvider(
sandboxInstance.language,
createTwoslashInlayProvider(sandboxInstance),
);

const system = createFileSystem(props, sandboxInstance.tsvfs);

// Write files in vfs when a model is created in the editor (this is used only for ATA types)
sandboxInstance.monaco.editor.onDidCreateModel(model => {
if (!model.uri.path.includes('node_modules')) {
return;
}
const path = model.uri.path.replace('/file:///', '/');
system.writeFile(path, model.getValue());
});
// Delete files in vfs when a model is disposed in the editor (this is used only for ATA types)
sandboxInstance.monaco.editor.onWillDisposeModel(model => {
if (!model.uri.path.includes('node_modules')) {
return;
}
const path = model.uri.path.replace('/file:///', '/');
system.deleteFile(path);
});

// Load the lib files from typescript to vfs (eg. es2020.d.ts)
const worker = await sandboxInstance.getWorkerProcess();
if (worker.getLibFiles) {
const libs = await worker.getLibFiles();
for (const [key, value] of Object.entries(libs)) {
system.writeFile(`/${key}`, value);
}
}

window.system = system;
window.esquery = lintUtils.esquery;
window.visitorKeys = lintUtils.visitorKeys;

const webLinter = createLinter(
system,
lintUtils,
sandboxInstance.tsvfs,
);

onLoaded(
[...webLinter.rules.values()],
[
...new Set([
window.ts.version,
...sandboxInstance.supportedVersions,
]),
]
.filter(item =>
semverSatisfies(
item,
rootPackageJson.devDependencies.typescript,
),
)
.sort((a, b) => b.localeCompare(a)),
);

setServices({
sandboxInstance,
system,
webLinter,
});
})
.catch((err: unknown) => {
if (err instanceof Error) {
setServices(err);
} else {
setServices(new Error(String(err)));
}
});
})
.catch((err: unknown) => {
if (err instanceof Error) {
setServices(err);
} else {
setServices(new Error(String(err)));
}
console.error(err);
});

return (): void => {
if (!sandboxInstance) {
return;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp