From 059420b05b5ee976ecd1f1ddde2c1b43ad9cdbbf Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 15 Mar 2024 11:09:01 +0100 Subject: [PATCH] fix: improve bun assistant for relative paths --- frontend/src/lib/ata/edgeCases.ts | 8 +++++++- frontend/src/lib/ata/index.ts | 6 ++++-- frontend/src/lib/components/Editor.svelte | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/ata/edgeCases.ts b/frontend/src/lib/ata/edgeCases.ts index 1e5a57537e..f7b2beeb37 100644 --- a/frontend/src/lib/ata/edgeCases.ts +++ b/frontend/src/lib/ata/edgeCases.ts @@ -72,5 +72,11 @@ export const mapModuleNameToModule = (moduleSpecifier: string) => { } export function isRelativePath(d: string) { - return d.startsWith('./') || d.startsWith('../') || d.startsWith('/') || d.startsWith('.../') + return ( + d.startsWith('./') || + d.startsWith('../') || + d.startsWith('/') || + d.startsWith('.../') || + d.startsWith('/') + ) } diff --git a/frontend/src/lib/ata/index.ts b/frontend/src/lib/ata/index.ts index 64969ac73e..308b37033d 100644 --- a/frontend/src/lib/ata/index.ts +++ b/frontend/src/lib/ata/index.ts @@ -114,15 +114,18 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => { const relativeDeps = depsToGet.filter((f) => isRelativePath(f.raw)) relativeDeps.forEach(async (f) => { let path = f.raw.startsWith('/') - ? '' + ? f.raw : '/' + config.scriptPath + (f.raw.startsWith('../') ? '/../' : '/.') + f.raw let url = config.root + path + console.log('fetching local file', url, f.raw) const res = await fetch(url) if (res.ok) { config.delegate.localFile?.(await res.text(), f.raw) } }) } + depsToGet.forEach((dep) => moduleMap.set(dep.raw, { state: 'loading' })) + depsToGet = depsToGet.filter((f) => !isRelativePath(f.raw)) if (depsToGet.length === 0) { return [] @@ -132,7 +135,6 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => { depsToGet.map((x) => x.raw) ) // Make it so it won't get re-downloaded - depsToGet.forEach((dep) => moduleMap.set(dep.raw, { state: 'loading' })) // Grab the module trees which gives us a list of files to download const trees = await Promise.all( diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index 87e4083905..8492e07e22 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -777,7 +777,11 @@ const addLocalFile = async (code: string, _path: string) => { 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()) if (editor) { let localModel = meditor.getModel(nuri) if (localModel) {