Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a startup configuration file for flowr #651

Merged
merged 16 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { MergeableRecord} from './util/objects'
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
import {deepMergeObject} from './util/objects'
import path from 'path'
import fs from 'fs'
import {log} from './util/log'

export interface FlowrConfigOptions extends MergeableRecord {
ignoreSourceCalls: boolean
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
}

export const defaultConfigFile = 'flowr.json'
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
export const defaultConfigOptions: FlowrConfigOptions = {
ignoreSourceCalls: false
}
export const config = parseConfigOptions(process.cwd())
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved

function parseConfigOptions(workingDirectory: string, configFile = defaultConfigFile): FlowrConfigOptions {
let searchPath = path.resolve(workingDirectory)
do{
const configPath = path.join(searchPath, configFile)
if(fs.existsSync(configPath)) {
try {
const read = fs.readFileSync(configPath,{encoding: 'utf-8'})

Check warning on line 23 in src/config.ts

View check run for this annotation

Codecov / codecov/patch

src/config.ts#L22-L23

Added lines #L22 - L23 were not covered by tests
// assign default values to all config options except for the specified ones
const ret = deepMergeObject(defaultConfigOptions, JSON.parse(read) as FlowrConfigOptions)
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
log.info(`Using config ${JSON.stringify(ret)} from ${configPath}`)
return ret

Check warning on line 27 in src/config.ts

View check run for this annotation

Codecov / codecov/patch

src/config.ts#L25-L27

Added lines #L25 - L27 were not covered by tests
} catch(e) {
log.error(`Failed to parse config file at ${configPath}: ${(e as Error).message}`)

Check warning on line 29 in src/config.ts

View check run for this annotation

Codecov / codecov/patch

src/config.ts#L29

Added line #L29 was not covered by tests
}
}
// move up to parent directory (apparently this is somehow the best way to do it in node, what)
searchPath = searchPath.split(path.sep).slice(0, -1).join(path.sep)
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
} while(fs.existsSync(searchPath))

log.info('Using default config')
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
return defaultConfigOptions
}
6 changes: 6 additions & 0 deletions src/dataflow/internal/process/functions/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {type DataflowScopeName, type Identifier, overwriteEnvironments, type REnvironmentInformation, resolveByName} from '../../../environments'
import type {DataflowInformation} from '../../info'
import {dataflowLogger} from '../../../index'
import {config} from '../../../../config'

let sourceProvider = requestProviderFromFile()

Expand All @@ -32,6 +33,11 @@
export function processSourceCall<OtherInfo>(functionCall: RFunctionCall<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, information: DataflowInformation): DataflowInformation {
const sourceFile = functionCall.arguments[0] as RArgument<ParentInformation> | undefined
if(sourceFile?.value?.type == RType.String) {
if(config.ignoreSourceCalls) {
dataflowLogger.info(`Skipping source call ${JSON.stringify(sourceFile)} (disabled in config file)`)
return information

Check warning on line 38 in src/dataflow/internal/process/functions/source.ts

View check run for this annotation

Codecov / codecov/patch

src/dataflow/internal/process/functions/source.ts#L37-L38

Added lines #L37 - L38 were not covered by tests
}

const path = removeTokenMapQuotationMarks(sourceFile.lexeme)
const request = sourceProvider.createRequest(path)

Expand Down
Loading