From c37bb94ea332255729ff44bdfc09866d8abe9360 Mon Sep 17 00:00:00 2001 From: Arvyd Paeglit Date: Tue, 21 Feb 2023 13:29:59 +0000 Subject: [PATCH] fix: separated of getting supported files from creating remote bundle This refactoring is needed for improved internal testing. --- src/bundles.ts | 37 ++++++++++++++++++++++++++----------- src/index.ts | 3 ++- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/bundles.ts b/src/bundles.ts index ea8979d5..09b92391 100644 --- a/src/bundles.ts +++ b/src/bundles.ts @@ -172,10 +172,6 @@ export async function remoteBundleFactory(options: RemoteBundleFactoryOptions): return remoteBundle; } -interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFoldersOptions { - // pass -} - /** * Get supported filters and test baseURL for correctness and availability * @@ -218,6 +214,10 @@ export interface FileBundle extends RemoteBundle { skippedOversizedFiles?: string[]; } +interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFoldersOptions { + // pass +} + /** * Creates a remote bundle and returns response from the bundle API * @@ -225,14 +225,29 @@ export interface FileBundle extends RemoteBundle { * @returns {Promise} */ export async function createBundleFromFolders(options: CreateBundleFromFoldersOptions): Promise { - const baseDir = determineBaseDir(options.paths); - const [supportedFiles, fileIgnores] = await Promise.all([ - // Fetch supporte files to save network traffic - getSupportedFiles(options.baseURL, options.source, options.requestId, options.languages), - // Scan for custom ignore rules - collectIgnoreRules(options.paths, options.symlinksEnabled, options.defaultFileIgnores), - ]); + // Fetch supported files to save network traffic + const supportedFiles = await getSupportedFiles(options.baseURL, options.source, options.requestId, options.languages); + // Collect files and create a remote bundle + return await createBundleWithCustomFiles(options, supportedFiles); +} + +/** + * Creates a remote bundle and returns response from the bundle API + * This function is used to create a bundle with a custom list of supported file extensions + * + * @param {CreateBundleFromFoldersOptions} options + * @param {SupportedFiles} supportedFiles + * @returns {Promise} + */ +export async function createBundleWithCustomFiles( + options: CreateBundleFromFoldersOptions, + supportedFiles: SupportedFiles, +): Promise { + // Scan for custom ignore rules + const fileIgnores = await collectIgnoreRules(options.paths, options.symlinksEnabled, options.defaultFileIgnores); + + const baseDir = determineBaseDir(options.paths); emitter.scanFilesProgress(0); const bundleFiles = []; const skippedOversizedFiles = []; diff --git a/src/index.ts b/src/index.ts index b5f2639c..df012279 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { analyzeFolders, extendAnalysis } from './analysis'; -import { createBundleFromFolders } from './bundles'; +import { createBundleFromFolders, createBundleWithCustomFiles } from './bundles'; import { emitter } from './emitter'; import { startSession, checkSession, getAnalysis, getIpFamily, IpFamily } from './http'; import { MAX_FILE_SIZE } from './constants'; @@ -23,6 +23,7 @@ export { getGlobPatterns, analyzeFolders, createBundleFromFolders, + createBundleWithCustomFiles, extendAnalysis, emitter, MAX_FILE_SIZE,