Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* © 2013 Liferay, Inc. and Node GH contributors
* (see file: README.md)
* SPDX-License-Identifier: BSD-3-Clause
*/
import * as S from 'sanctuary'
import * as Future from 'fluture'
import * as fs from 'fs'
import * as which from 'which'
import * as $ from 'sanctuary-def'
/* SAFE UTILS */
export const safeWhich = Future.encase(which.sync)
export const safeRealpath = Future.encase(fs.realpathSync)
export function safeImport(
fileName: string
): Future.FutureInstance {
let moduleObj = null
try {
moduleObj = require(fileName)
} catch (e) {
return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
}
return Future.of(moduleObj)
}
/**
* © 2013 Liferay, Inc. and Node GH contributors
* (see file: README.md)
* SPDX-License-Identifier: BSD-3-Clause
*/
import * as S from 'sanctuary'
import * as Future from 'fluture'
import * as fs from 'fs'
import * as which from 'which'
import * as $ from 'sanctuary-def'
/* SAFE UTILS */
export const safeWhich = Future.encase(which.sync)
export const safeRealpath = Future.encase(fs.realpathSync)
export function safeImport(
fileName: string
): Future.FutureInstance {
let moduleObj = null
try {
moduleObj = require(fileName)
} catch (e) {
return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
}
return Future.of(moduleObj)
}
export const safeReaddir = Future.encaseN(fs.readdir)
const takeMaxValues = R.reduce(
(result, [key, val]) =>
R.merge(result, { [key]: R.max(result[key] || 0, val) }),
{}
)
const configPath = ['coverageThreshold', 'global']
// thresholdLens :: Lens
const thresholdLens = R.lensPath(['jest', ...configPath])
// ratchetThresholds :: (Object, Object) -> Object
const ratchetThresholds = R.compose(takeMaxValues, R.unnest, R.map(R.toPairs))
// String -> Future a Error
const requireF = F.encase(require)
// getConfig :: String -> Future Object Error
const getCurrentThresholdsFromConfig = R.ifElse(
R.has('jest'),
R.path(['jest', ...configPath]),
R.path(configPath)
)
// getPackageJsonPath :: () -> Future String Error
const getPackageJsonPath = () =>
F.of(process.cwd()).map(rootDir => resolve(rootDir, 'package.json'))
// getPackageJson :: () -> Future Object Error
const getPackageJson = () => getPackageJsonPath().chain(requireF)
// writePackage :: String -> Object -> Future Object Error
function cli(args) {
const { _: [input] } = args
const ast = readFile(input)
.chain(Future.encase(parse(_, { sourceType: 'module' })))
.chain(Future.encase(compileToAdvPL))
return ast
.fork(emitError, ({ code }) => console.log(code))
}
function cli(args) {
const { _: [input] } = args
const ast = readFile(input)
.chain(Future.encase(parse(_, { sourceType: 'module' })))
.chain(Future.encase(compileToAdvPL))
return ast
.fork(emitError, ({ code }) => console.log(code))
}
const taskOfSnippets = ({ dependencies, globals, timeout }, glob) =>
S.pipe(
[
S.chain(Future.encase(skip)),
S.chain(Future.encase(normalizeFiles(dependencies, globals))),
S.chain(traverseFiles(timeout)),
],
taskify(extract)(glob, ['js', 'javascript'])
)
const taskOfSnippets = ({ dependencies, globals, timeout }, glob) =>
S.pipe(
[
S.chain(Future.encase(skip)),
S.chain(Future.encase(normalizeFiles(dependencies, globals))),
S.chain(traverseFiles(timeout)),
],
taskify(extract)(glob, ['js', 'javascript'])
)