-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix playground usage from external package (#2540)
Playground usage was completely broken when used as a package. Local reference seems to make it work but hwne the package is in node_modules vite doesn't allow certain things
- Loading branch information
1 parent
e02b74a
commit 99d80f8
Showing
16 changed files
with
109 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@typespec/bundler/fix-playground-external-use_2023-10-04-18-20.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@typespec/bundler", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@typespec/bundler" | ||
} |
10 changes: 10 additions & 0 deletions
10
common/changes/@typespec/playground/fix-playground-external-use_2023-10-04-18-20.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@typespec/playground", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@typespec/playground" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@typespec/openapi", | ||
"entries": [ | ||
{ | ||
"version": "0.1.0-alpha.1", | ||
"tag": "@typespec/playground_v0.1.0-alpha.1", | ||
"date": "Wed, 03 Oct 2023 18:00:18 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Fix: Usage of the package in vite dev mode was broken. Some errors due to the loading of the manifest as well as monaco editor workers.\n**BREAKING CHANGE:** Changed `import { PlaygroundManifest } from \"@typespec/playground/manifest\";` to`import PlaygroundManifest from \"@typespec/playground/manifest\";`" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Change Log - @typespec/playground | ||
|
||
This log was last generated on Wed, 04 Oct 2023 18:19:25 GMT and should not be manually modified. | ||
|
||
## 0.1.0-alpha.1 | ||
Wed, 03 Oct 2023 18:00:18 GMT | ||
|
||
### Updates | ||
|
||
- Fix: Usage of the package in vite dev mode was broken. Some errors due to the loading of the manifest as well as monaco editor workers. | ||
**BREAKING CHANGE:** Changed `import { PlaygroundManifest } from "@typespec/playground/manifest";` to`import PlaygroundManifest from "@typespec/playground/manifest";` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import manifest from "playground-manifest.js"; | ||
import { PlaygroundConfig } from "./vite/types.js"; | ||
/** | ||
* THIS FILE IS MEANT TO BE STUBBED using the manifest plugin. | ||
*/ | ||
import { PlaygroundConfig } from "../src/vite/types.js"; | ||
|
||
export const PlaygroundManifest: PlaygroundConfig = manifest; | ||
const config: PlaygroundConfig = {} as any; | ||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters