mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-12 00:06:14 +00:00
fix: resolve absolute-path imports in monaco ts editor (#9213)
* fix: resolve absolute-path imports in monaco ts editor * fix: dispose absolute-path extra libs on editor teardown and reset * fix: skip late ata local-file callbacks after editor teardown
This commit is contained in:
@@ -136,7 +136,7 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
|
||||
: '/' + config.scriptPath + (f.raw.startsWith('../') ? '/../' : '/.') + f.raw
|
||||
let url = config.root + path
|
||||
let localPath = f.raw
|
||||
if (f.raw.startsWith('.') && !f.raw.endsWith('.ts')) {
|
||||
if ((f.raw.startsWith('.') || f.raw.startsWith('/')) && !f.raw.endsWith('.ts')) {
|
||||
url += '.ts'
|
||||
localPath += '.ts'
|
||||
}
|
||||
|
||||
@@ -204,6 +204,7 @@
|
||||
let lastWsAttempt: Date = new Date()
|
||||
let nbWsAttempt = 0
|
||||
let disposeMethod: (() => void) | undefined
|
||||
const absolutePathExtraLibs = new Map<string, { dispose: () => void }>()
|
||||
const dispatch = createEventDispatcher()
|
||||
// let graphqlService: MonacoGraphQLAPI | undefined = undefined
|
||||
|
||||
@@ -1644,6 +1645,8 @@
|
||||
(scriptLang == 'bun' || scriptLang == 'tsx' || scriptLang == 'bunnative') &&
|
||||
ata == undefined
|
||||
) {
|
||||
absolutePathExtraLibs.forEach((d) => d.dispose())
|
||||
absolutePathExtraLibs.clear()
|
||||
const hostname = getHostname()
|
||||
|
||||
const addLibraryToRuntime = async (code: string, _path: string) => {
|
||||
@@ -1659,12 +1662,17 @@
|
||||
}
|
||||
|
||||
const addLocalFile = async (code: string, _path: string) => {
|
||||
if (destroyed) return
|
||||
let p = new URL(_path, uri).href
|
||||
// if (_path?.startsWith('/')) {
|
||||
// p = 'file://' + p
|
||||
// }
|
||||
let nuri = mUri.parse(p)
|
||||
console.log('adding local file', _path, nuri.toString())
|
||||
// Monaco's TS service resolves relative imports against the importer's URI (finding the
|
||||
// model), but absolute paths like "/u/admin/foo" are looked up as raw paths and miss the
|
||||
// `file://` model. Register them as extra libs so TS can resolve them.
|
||||
if (_path.startsWith('/')) {
|
||||
absolutePathExtraLibs.get(_path)?.dispose()
|
||||
absolutePathExtraLibs.set(_path, typescriptDefaults.addExtraLib(code, _path))
|
||||
}
|
||||
if (editor) {
|
||||
let localModel = meditor.getModel(nuri)
|
||||
if (localModel) {
|
||||
@@ -1783,6 +1791,8 @@
|
||||
timeoutModel && clearTimeout(timeoutModel)
|
||||
loadTimeout && clearTimeout(loadTimeout)
|
||||
aiChatEditorHandler?.clear()
|
||||
absolutePathExtraLibs.forEach((d) => d.dispose())
|
||||
absolutePathExtraLibs.clear()
|
||||
})
|
||||
|
||||
async function genRoot(hostname: string) {
|
||||
|
||||
Reference in New Issue
Block a user