Skip to content

Commit

Permalink
Move various node dependencies into flowr-cli (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce authored May 8, 2024
2 parents 8c0c7db + e4ab320 commit eeb85db
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 267 deletions.
63 changes: 0 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
"@types/n-readlines": "^1.0.6",
"@types/n3": "^1.16.4",
"@types/object-hash": "^3.0.6",
"@types/semver": "^7.5.6",
Expand All @@ -254,8 +253,6 @@
"@j-ulrich/release-it-regex-bumper": "^5.1.0"
},
"dependencies": {
"joi": "^17.11.0",
"n-readlines": "^1.0.1",
"n3": "^1.17.2",
"object-hash": "^3.0.0",
"rotating-file-stream": "^3.1.1",
Expand Down
63 changes: 1 addition & 62 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type { MergeableRecord } from './util/objects'
import { deepMergeObject } from './util/objects'
import path from 'path'
import fs from 'fs'
import { log, LogLevel } from './util/log'
import { getParentDirectory } from './util/files'
import Joi from 'joi'

export interface FlowrConfigOptions extends MergeableRecord {
/**
Expand All @@ -21,68 +15,13 @@ export const defaultConfigOptions: FlowrConfigOptions = {
ignoreSourceCalls: false,
rPath: undefined
}
export const defaultConfigFile = 'flowr.json'

const schema = Joi.object({
ignoreSourceCalls: Joi.boolean().optional()
})

let configWorkingDirectory = process.cwd()
let configFile = defaultConfigFile
let currentConfig: FlowrConfigOptions | undefined

export function setConfigFile(workingDirectory = process.cwd(), file = defaultConfigFile, forceLoad = false) {
configWorkingDirectory = workingDirectory
configFile = file

// reset the config so it gets reloaded
currentConfig = undefined
if(forceLoad) {
getConfig()
}
}

export function setConfig(config: FlowrConfigOptions) {
currentConfig = config
}

export function getConfig(): FlowrConfigOptions {
// lazy-load the config based on the current settings
if(currentConfig === undefined) {
setConfig(parseConfigOptions(configWorkingDirectory, configFile))
}
return currentConfig as FlowrConfigOptions
}

function parseConfigOptions(workingDirectory: string, configFile: string): FlowrConfigOptions {
let searchPath = path.resolve(workingDirectory)
do{
const configPath = path.join(searchPath, configFile)
if(fs.existsSync(configPath)) {
try {
const text = fs.readFileSync(configPath,{ encoding: 'utf-8' })
const parsed = JSON.parse(text) as FlowrConfigOptions
const validate = schema.validate(parsed)
if(!validate.error) {
// assign default values to all config options except for the specified ones
const ret = deepMergeObject(defaultConfigOptions, parsed)
if(log.settings.minLevel <= LogLevel.Info) {
log.info(`Using config ${JSON.stringify(ret)} from ${configPath}`)
}
return ret
} else {
log.error(`Failed to validate config file at ${configPath}: ${validate.error.message}`)
}
} catch(e) {
log.error(`Failed to parse config file at ${configPath}: ${(e as Error).message}`)
}
}
// move up to parent directory
searchPath = getParentDirectory(searchPath)
} while(fs.existsSync(searchPath))

if(log.settings.minLevel <= LogLevel.Info) {
log.info(`Using default config ${JSON.stringify(defaultConfigOptions)}`)
}
return defaultConfigOptions
return currentConfig ?? defaultConfigOptions
}
139 changes: 0 additions & 139 deletions src/util/files.ts

This file was deleted.

2 comments on commit eeb85db

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"artificial" Benchmark Suite

Benchmark suite Current: eeb85db Previous: 1e5ddeb Ratio
Retrieve AST from R code 301.87415777272724 ms 305.50355490909095 ms 0.99
Normalize R AST 32.169129681818184 ms 33.04192136363636 ms 0.97
Produce dataflow information 66.81157213636364 ms 66.58585145454545 ms 1.00
Total per-file 1514.0401912272728 ms 1512.547620909091 ms 1.00
Static slicing 1.3873507369764244 ms (1.312289537727514) 1.3817132831241319 ms (1.27303105869458) 1.00
Reconstruct code 0.45159394717291496 ms (0.21451536995151912) 0.45135141022522257 ms (0.25927254974160097) 1.00
Total per-slice 1.8532635343929047 ms (1.3655381361484946) 1.8475447304133532 ms (1.3326721674469058) 1.00
failed to reconstruct/re-parse 0 # 0 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.7329390759026897 # 0.7329390759026897 # 1
reduction (normalized tokens) 0.7209834969577295 # 0.7209834969577295 # 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"social-science" Benchmark Suite

Benchmark suite Current: eeb85db Previous: 1e5ddeb Ratio
Retrieve AST from R code 320.2464132 ms 330.55613118 ms 0.97
Normalize R AST 36.60502658 ms 36.10837608 ms 1.01
Produce dataflow information 185.58098492 ms 188.6117503 ms 0.98
Total per-file 3809.90101672 ms 3858.78617088 ms 0.99
Static slicing 8.709549860657114 ms (15.292225335607261) 8.763488287471356 ms (15.142795018273485) 0.99
Reconstruct code 0.5598218852733112 ms (0.2719058816589645) 0.6295735167403027 ms (0.28826473087031307) 0.89
Total per-slice 9.279278301019591 ms (15.404686419393109) 9.403718790030862 ms (15.25727767695505) 0.99
failed to reconstruct/re-parse 7 # 7 # 1
times hit threshold 298 # 298 # 1
reduction (characters) 0.8935817303062389 # 0.8935817303062389 # 1
reduction (normalized tokens) 0.8531248144961375 # 0.8531248144961375 # 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.