Skip to content

Commit

Permalink
Merge pull request #172 from snyk/chore/create-bundle-func-split
Browse files Browse the repository at this point in the history
fix: separated of getting supported files from creating remote bundle
  • Loading branch information
Arvi3d committed Feb 21, 2023
2 parents bf87e11 + c37bb94 commit 9a4fb65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
37 changes: 26 additions & 11 deletions src/bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -218,21 +214,40 @@ export interface FileBundle extends RemoteBundle {
skippedOversizedFiles?: string[];
}

interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFoldersOptions {
// pass
}

/**
* Creates a remote bundle and returns response from the bundle API
*
* @param {CreateBundleFromFoldersOptions} options
* @returns {Promise<FileBundle | null>}
*/
export async function createBundleFromFolders(options: CreateBundleFromFoldersOptions): Promise<FileBundle | null> {
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<FileBundle | null>}
*/
export async function createBundleWithCustomFiles(
options: CreateBundleFromFoldersOptions,
supportedFiles: SupportedFiles,
): Promise<FileBundle | null> {
// 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 = [];
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,6 +23,7 @@ export {
getGlobPatterns,
analyzeFolders,
createBundleFromFolders,
createBundleWithCustomFiles,
extendAnalysis,
emitter,
MAX_FILE_SIZE,
Expand Down

0 comments on commit 9a4fb65

Please sign in to comment.