fix: improve bun assistant for relative paths

This commit is contained in:
Ruben Fiszel
2024-03-15 11:09:01 +01:00
parent 74a8816eea
commit 059420b05b
3 changed files with 15 additions and 3 deletions
+7 -1
View File
@@ -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('/')
)
}
+4 -2
View File
@@ -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(
@@ -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) {