-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load Monaco Files From Node Modules Folder (#3032)
Load Monaco Files From Node Modules Folder
- Loading branch information
Showing
9 changed files
with
78 additions
and
21 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
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 @@ | ||
import {app, net} from "electron" | ||
import path from "node:path" | ||
import {pathToFileURL} from "node:url" | ||
|
||
export class AssetServer { | ||
fromNodeModules(relativePath: string) { | ||
const file = require.resolve(relativePath) | ||
const url = pathToFileURL(file).toString() | ||
return net.fetch(url, {bypassCustomProtocolHandlers: true}) | ||
} | ||
|
||
fromPublic(relativeUrl: string) { | ||
const file = path.join(app.getAppPath(), "out", relativeUrl) | ||
const url = pathToFileURL(file).toString() | ||
return net.fetch(url, {bypassCustomProtocolHandlers: true}) | ||
} | ||
} |
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,14 @@ | ||
import {AssetUrl} from "./asset-url" | ||
|
||
test("node module asset", () => { | ||
const asset = new AssetUrl( | ||
"app-asset://zui/node_modules/monaco/worker.js#worker" | ||
) | ||
expect(asset.relativeUrl).toBe("monaco/worker.js") | ||
expect(asset.isNodeModule).toBe(true) | ||
}) | ||
|
||
test("public asset", () => { | ||
const asset = new AssetUrl("app-asset://zui/search.html?id=123&name=abc") | ||
expect(asset.relativeUrl).toBe("search.html") | ||
}) |
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,19 @@ | ||
export class AssetUrl { | ||
url: URL | ||
|
||
constructor(url: string) { | ||
this.url = new URL(url) | ||
} | ||
|
||
get isNodeModule() { | ||
return this.url.pathname.startsWith("/node_modules") | ||
} | ||
|
||
get relativeUrl() { | ||
if (this.isNodeModule) { | ||
return this.url.pathname.replace("/node_modules/", "") | ||
} else { | ||
return this.url.pathname.replace(/^\//, "") | ||
} | ||
} | ||
} |
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