improve bun auto-type fetching

This commit is contained in:
Ruben Fiszel
2024-02-28 13:22:12 +01:00
parent 15bbccf0eb
commit 4ee18c4f91
3 changed files with 14 additions and 4 deletions
+5 -1
View File
@@ -63,8 +63,12 @@ export interface ResLimit {
usage: number
}
export function isOverlimit(resLimit: ResLimit) {
return resLimit.usage > 500000
}
function api<T>(url: string, resLimit: ResLimit, init?: RequestInit): Promise<T | Error> {
if (resLimit.usage > 500000) {
if (isOverlimit(resLimit)) {
console.warn(
`Exceeded limit of types downloaded for the needs of the assistant fetching: ${url}`
)
+8 -2
View File
@@ -3,6 +3,7 @@ import {
getFiletreeForModuleWithVersion,
getNPMVersionForModuleReference,
getNPMVersionsForModule,
isOverlimit,
type NPMTreeMeta,
type ResLimit
} from './apis'
@@ -51,11 +52,13 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
let estimatedToDownload = 0
let estimatedDownloaded = 0
let resLimit = { usage: 0 }
return (initialSourceFile: string) => {
estimatedToDownload = 0
estimatedDownloaded = 0
return resolveDeps(initialSourceFile, 0, { usage: 0 }).then((t) => {
return resolveDeps(initialSourceFile, 0, resLimit).then((t) => {
if (estimatedDownloaded > 0) {
config.delegate.finished?.(fsMap)
}
@@ -116,7 +119,6 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
const trees = await Promise.all(
depsToGet.map((f) => getFileTreeForModuleWithTag(f.module, f.version, f.raw, resLimit))
)
console.log(trees, 'trees')
const treesOnly = trees.filter((t) => !('error' in t)) as NPMTreeMeta[]
// These are the modules which we can grab directly
@@ -175,6 +177,10 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
// Grab all dts files
await Promise.all(
allDTSFiles.map(async (dts) => {
if (isOverlimit(resLimit)) {
console.warn('Exceeded limit of types downloaded for the needs of the assistant')
return
}
const dtsCode = await getDTSFileForModuleWithVersion(
dts.moduleName,
dts.moduleVersion,
+1 -1
View File
@@ -789,7 +789,7 @@
}
await initWasm()
const root = await genRoot(hostname)
console.log('SETUP TYPE ACQUISITION', { root, path })
ata = setupTypeAcquisition({
projectName: 'Windmill',
depsParser: (c) => {