Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
findToolInDelimitedEnvironmentVariable (toolName, key, options = {}) {
if (isFalsy(toolName) || toolName.constructor !== String || toolName.trim() === '') {
return false
}
let p = this.environment(options)[key]
if (isFalsy(p)) {
return false
}
let elements = p.split(path.delimiter)
if (key === 'GOPATH' && isTruthy(this.environment(options)['GO15VENDOREXPERIMENT'])) {
// TODO: Understand Vendor Experiment Paths Better
// elements.unshift('vendor')
}
for (let element of elements) {
let item = ''
if (key === 'GOPATH') {
item = path.join(element, 'bin', toolName + this.executableSuffix)
} else {
item = path.join(element, toolName + this.executableSuffix)
}
if (fs.existsSync(item)) {
let stat = fs.statSync(item)
if (stat && stat.isFile() && stat.size > 0) {
return item
const alias = Object.entries(mhyConfig.defaultAliases).reduce(function(acc, [key, entry]) {
// Leave alone every path which is outside cwd
const e = path.resolve(entry)
if (!e.includes(process.cwd())) {
acc[key] = entry
return acc
}
// Search for last occurrence of src folder and replace it to dist
if (isBabel) {
const entrySegments = entry.split(path.delimiter).reverse()
const srcIndex = entrySegments.findIndex(_ => _ === mhyConfig.srcFolder)
entrySegments[srcIndex] = mhyConfig.distFolder
entry = entrySegments.reverse().join(path.delimiter)
}
acc[key] = `./${path.relative(process.cwd(), path.resolve(entry))}`
return acc
}, {})
r.push([
return function importer(url, prev) {
// Create an array of include paths to search for files.
const includePaths = [];
if (path.isAbsolute(prev)) {
includePaths.push(path.dirname(prev));
}
selectorImporter.options.includePaths = includePaths
.concat(this.options.includePaths.split(path.delimiter));
// Merge default with custom options.
Object.assign(selectorImporter.options, options);
return selectorImporter.resolveSync(url);
};
};
const binPath = path.resolve('./node_modules/.bin')
// Pick relevant option keys and set default values
const nextOptions = {
async: !!options.async,
cwd: options.cwd,
env: options.env || process.env,
stdio: options.stdio || 'inherit',
timeout: options.timeout
}
const env = nextOptions.env
// Include in PATH node_modules bin path
if (env) {
env.PATH = [binPath, env.PATH || process.env.PATH].join(path.delimiter)
}
logger.log(chalk.bold(command))
return shell(command, nextOptions)
}
export default function runCmd (cwd, argv) {
const scripts = argv._.slice(1)
const pkgJson = readFile(path.join(cwd, 'package.json'), 'utf8')
::map(JSON.parse)
// if no script(s) have been specified, log out the available scripts.
if (!scripts.length) {
return pkgJson::_do(logAvailable)
}
const PATH = [path.join(cwd, 'node_modules/.bin'), process.env.PATH]
.join(path.delimiter)
const env = {...process.env, PATH}
const runOptions = {env, stdio: 'inherit'}
return pkgJson::map(({scripts = {}}) => scripts)::entries() // eslint-disable-line no-shadow
::filter(([name]) => ~scripts.indexOf(name))
::concatMap(([name, script]) => run(script, runOptions)
::map((code) => ([name, script, code])))
::_do(logCode)
::reduce((codes, [name, script, code]) => codes + code, 0)
::_do((code) => assert.equal(code, 0, 'exit status != 0'))
}
function defaultTemplate(topDocument) {
try {
topDocument.files.forEach((file) => {
file.filename = _replaceExt(file.filename, '.html');
});
const content = pug.renderFile(
path.resolve(__dirname, 'template.pug'),
{ document: topDocument }
);
fs.mkdirsSync(path.resolve(topDocument.destination, 'css', path.delimiter));
const cssDestination = path.resolve(topDocument.destination, 'css', topDocument.filename);
fs.copySync(topDocument.source, cssDestination);
const newFileName = topDocument.first ?
'index.html' : _replaceExt(topDocument.filename, '.html');
fs.writeFileSync(path.resolve(topDocument.destination, newFileName), content);
console.log(path.relative(process.cwd(), path.resolve(topDocument.destination, newFileName)));
} catch (err) {
console.log(err);
}
}
it('uses platform default when `latex.texPath` is not configured', () => {
const defaultTexPath = '/foo/bar'
const expectedPath = [defaultTexPath, process.env.PATH].join(path.delimiter)
atom.config.set('latex.texPath', '')
spyOn(builder, 'defaultTexPath').andReturn(defaultTexPath)
const constructedPath = builder.constructPath()
expect(constructedPath).toBe(expectedPath)
})
it('expands the path', () => {
let env = Object.assign({}, process.env)
env.GOPATH = '~' + path.sep + 'go' + path.delimiter + '~' + path.sep + 'othergo'
let result = pathhelper.expand(env, path.join('~', 'go', 'go', '..', 'bin', 'goimports'))
expect(result).toBeDefined()
expect(result).toBeTruthy()
expect(result).toBe(path.join(pathhelper.home(), 'go', 'bin', 'goimports'))
result = pathhelper.expand(env, path.join(gopathToken, 'go', '..', 'bin', 'goimports'))
expect(result).toBeDefined()
expect(result).toBeTruthy()
expect(result).toBe(path.join(pathhelper.home(), 'go', 'bin', 'goimports'))
})
})
export const getPathDelimiter = shell => {
if (isFishShell(shell)) {
return ' '
}
return path.delimiter
}
constructPath () {
let texPath = (atom.config.get('latex.texPath') || '').trim()
if (texPath.length === 0) {
texPath = this.defaultTexPath(process.platform)
}
const processPath = process.env[this.envPathKey]
const match = texPath.match(/^(.*)(\$PATH)(.*)$/)
if (match) {
return `${match[1]}${processPath}${match[3]}`
}
return [texPath, processPath]
.filter(str => str && str.length > 0)
.join(path.delimiter)
}