Skip to content

Commit

Permalink
fix playground usage from external package
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Oct 4, 2023
1 parent eeff796 commit ed81024
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/playground-website/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaygroundManifest } from "@typespec/playground/manifest";
import PlaygroundManifest from "@typespec/playground/manifest";
import { renderReactPlayground } from "@typespec/playground/react";
import { SwaggerUIViewer } from "@typespec/playground/react/viewers";
import "./style.css";
Expand Down
5 changes: 5 additions & 0 deletions packages/playground/definitions/manifest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
import { PlaygroundConfig } from "../src/vite/types.js";

const config: PlaygroundConfig = {} as any;
export default config;
5 changes: 4 additions & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"exports": {
".": "./dist/src/index.js",
"./vite": "./dist/src/vite/index.js",
"./manifest": "./dist/src/manifest.js",
"./manifest": {
"default": "./do-not-use-virtual-import",
"types": "./definitions/manifest.d.ts"
},
"./react": "./dist/src/react/index.js",
"./react/viewers": "./dist/src/react/viewers.js"
},
Expand Down
6 changes: 0 additions & 6 deletions packages/playground/src/manifest.ts

This file was deleted.

39 changes: 27 additions & 12 deletions packages/playground/src/monaco-worker.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";

export function registerMonacoDefaultWorkers() {
self.MonacoEnvironment = {
createTrustedTypesPolicy: () => undefined,
getWorker(_: any, label: string) {
if (label === "json") {
return new jsonWorker();
getWorker: function (workerId, label) {
const getWorkerModule = (moduleUrl: string, label: string) => {
return new Worker((self.MonacoEnvironment as any).getWorkerUrl(moduleUrl), {
name: label,
type: "module",
});
};

switch (label) {
case "json":
return getWorkerModule("/monaco-editor/esm/vs/language/json/json.worker?worker", label);
case "css":
case "scss":
case "less":
return getWorkerModule("/monaco-editor/esm/vs/language/css/css.worker?worker", label);
case "html":
case "handlebars":
case "razor":
return getWorkerModule("/monaco-editor/esm/vs/language/html/html.worker?worker", label);
case "typescript":
case "javascript":
return getWorkerModule(
"/monaco-editor/esm/vs/language/typescript/ts.worker?worker",
label
);
default:
return getWorkerModule("/monaco-editor/esm/vs/editor/editor.worker?worker", label);
}
return new editorWorker();
},
};
}
4 changes: 2 additions & 2 deletions packages/playground/src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function playgroundManifestPlugin(config: PlaygroundUserConfig): Plugin {
viteConfig = c;
},
resolveId(id: string) {
if (id === "playground-manifest.js") {
if (id === "@typespec/playground/manifest") {
return id;
}
return null;
},
load(id: string) {
if (id === `playground-manifest.js`) {
if (id === `@typespec/playground/manifest`) {
const sampleImport = Object.values(samples)
.map(
(sampleValue, index) =>
Expand Down
9 changes: 8 additions & 1 deletion packages/playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"lib": ["DOM"],
"types": ["@emotion/react"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "e2e/**/*.ts", "vite.config.ts"]
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"test/**/*.ts",
"e2e/**/*.ts",
"vite.config.ts",
"definitions/*.d.ts"
]
}

0 comments on commit ed81024

Please sign in to comment.