From a40de96831fa912ec2d3bad4f453db20e8e66db5 Mon Sep 17 00:00:00 2001 From: Harrison Ifeanyichukwu Date: Mon, 13 Nov 2023 23:36:03 +0100 Subject: [PATCH] fix: generate typescript definitions in one pass --- .DS_Store | Bin 6148 -> 6148 bytes src/assets/index.json | 1 + src/modules/Bundler.ts | 64 ++++++++++++----------------------------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/.DS_Store b/.DS_Store index cec08e01e5ee8a1e509510c95ddc590f342b9184..b46a29cde87a77c1acc09103c6009b9d30110f5d 100644 GIT binary patch delta 31 ncmZoMXfc@J&&abeU^g=(&tx7J&CT&FE0`xXXl-Wa_{$FfnZgOT delta 56 zcmZoMXfc@J&&azmU^g=(?_?epO=(t!B!*IkOokkW6wjRe { - let rejected = false; - - // run with try catch block - const run = (callback) => { - try { - callback(); - } catch (ex) { - rejected = true; - reject(ex); - } - }; - - // write to filesytem and index - const onEmit = (filename, content) => - run(() => { - const out = path.join(outFolder, filename.split(this.src)[1]); - processedTDFiles.add(out); - fs.mkdirSync(path.dirname(out), { recursive: true }); - fs.writeFileSync(out, content); - }); - - for (let i = 0; i < fileModules.length; i++) { - const fileModule = fileModules[i]; - if (rejected) { - break; - } - - const tsdOut = path.join( - outFolder, - fileModule.locationRelativeToSrc, - fileModule.baseName + '.d.ts' - ); - - if (processedTDFiles.has(tsdOut)) { - continue; - } - - run(() => { - const program = ts.createProgram([fileModule.location], { - declaration: true, - emitDeclarationOnly: true, - }); + const host = ts.createCompilerHost(options); - program.emit(undefined, onEmit, undefined, true); - }); - } + host.writeFile = (filename: string, contents: string) => { + const out = path.join(outFolder, filename.split(this.src)[1]); + processedTDFiles.add(out); + fs.mkdirSync(path.dirname(out), { recursive: true }); + fs.writeFileSync(out, contents); + }; + const program = ts.createProgram( + fileModules.map((current) => current.location), + options, + host + ); + program.emit(); resolve(true); }); }