diff --git a/CHANGELOG.md b/CHANGELOG.md index 14bec8b..df7110d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Upcoming + +* Use `consistent-path` package to determine `$PATH` correctly on OSX + ### 4.1.1 * Export `FindCache`, now you can do `Helper.FindCache.clear()` to clear find cache diff --git a/lib/helpers.js b/lib/helpers.js index 748b0ee..e7f10a4 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -20,17 +20,19 @@ var _atom = require('atom'); var _path = require('path'); -var _path2 = _interopRequireDefault(_path); +var Path = _interopRequireWildcard(_path); var _fs = require('fs'); -var _fs2 = _interopRequireDefault(_fs); +var FS = _interopRequireWildcard(_fs); var _tmp = require('tmp'); -var _tmp2 = _interopRequireDefault(_tmp); +var TMP = _interopRequireWildcard(_tmp); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _consistentPath = require('consistent-path'); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } let XRegExp = null; const EventsCache = new WeakMap(); @@ -46,15 +48,15 @@ const assign = Object.assign || function (target, source) { function _exec(command, args, opts, isNode) { const options = assign({ + env: process.env, stream: 'stdout', throwOnStdErr: true }, opts); if (isNode) { - const env = assign({}, process.env); - delete env.OS; - assign(options, { env: env }); + delete options.env.OS; } + assign(options.env, { PATH: (0, _consistentPath.getPath)() }); return new Promise(function (resolve, reject) { const data = { stdout: [], stderr: [] }; @@ -204,26 +206,26 @@ function createElement(name) { function findAsync(directory, name) { validate_find(directory, name); const names = name instanceof Array ? name : [name]; - const chunks = directory.split(_path2.default.sep); + const chunks = directory.split(Path.sep); let promise = Promise.resolve(null); while (chunks.length) { - let currentDir = chunks.join(_path2.default.sep); + let currentDir = chunks.join(Path.sep); if (currentDir === '') { - currentDir = _path2.default.resolve(directory, '/'); + currentDir = Path.resolve(directory, '/'); } promise = promise.then(function (filePath) { if (filePath !== null) { return filePath; } return names.reduce(function (promise, name) { - const currentFile = _path2.default.join(currentDir, name); + const currentFile = Path.join(currentDir, name); return promise.then(function (filePath) { if (filePath !== null) { return filePath; } return new Promise(function (resolve) { - _fs2.default.access(currentFile, _fs2.default.R_OK, function (error) { + FS.access(currentFile, FS.R_OK, function (error) { if (error) { resolve(null); } else resolve(currentFile); @@ -245,7 +247,7 @@ function findCachedAsync(directory, name) { if (FindCache.has(cacheKey)) { const cachedFilePath = FindCache.get(cacheKey); return new Promise(function (resolve, reject) { - _fs2.default.access(cachedFilePath, _fs2.default.R_OK, function (error) { + FS.access(cachedFilePath, FS.R_OK, function (error) { if (error) { FindCache.delete(cacheKey); resolve(findCachedAsync(directory, names)); @@ -263,18 +265,18 @@ function findCachedAsync(directory, name) { function find(directory, name) { validate_find(directory, name); const names = name instanceof Array ? name : [name]; - const chunks = directory.split(_path2.default.sep); + const chunks = directory.split(Path.sep); while (chunks.length) { - let currentDir = chunks.join(_path2.default.sep); + let currentDir = chunks.join(Path.sep); if (currentDir === '') { - currentDir = _path2.default.resolve(directory, '/'); + currentDir = Path.resolve(directory, '/'); } for (const fileName of names) { - const filePath = _path2.default.join(currentDir, fileName); + const filePath = Path.join(currentDir, fileName); try { - _fs2.default.accessSync(filePath, _fs2.default.R_OK); + FS.accessSync(filePath, FS.R_OK); return filePath; } catch (_) {} } @@ -291,7 +293,7 @@ function findCached(directory, name) { if (FindCache.has(cacheKey)) { const cachedFilePath = FindCache.get(cacheKey); try { - _fs2.default.accessSync(cachedFilePath, _fs2.default.R_OK); + FS.accessSync(cachedFilePath, FS.R_OK); return cachedFilePath; } catch (_) { FindCache.delete(cacheKey); @@ -314,20 +316,20 @@ function tempFile(fileName, fileContents, callback) { } return new Promise(function (resolve, reject) { - _tmp2.default.dir({ + TMP.dir({ prefix: 'atom-linter_' }, function (error, directory, directoryCleanup) { if (error) { return reject(error); } - const filePath = _path2.default.join(directory, fileName); - _fs2.default.writeFile(filePath, fileContents, function (error) { + const filePath = Path.join(directory, fileName); + FS.writeFile(filePath, fileContents, function (error) { if (error) { directoryCleanup(); return reject(error); } function fileCleanup() { - _fs2.default.unlink(filePath, function () { + FS.unlink(filePath, function () { directoryCleanup(); }); } diff --git a/package.json b/package.json index 4aa5673..d651c64 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "homepage": "https://github.com/AtomLinter/atom-linter#readme", "dependencies": { "xregexp": "^3.0.0", - "tmp": "latest" + "tmp": "latest", + "consistent-path": "^1.0.1" }, "devDependencies": { "babel-preset-steelbrain": "^1.0.0" diff --git a/src/helpers.js b/src/helpers.js index 1429713..a2fe928 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,9 +1,10 @@ 'use babel' import {BufferedProcess, BufferedNodeProcess} from 'atom' -import Path from 'path' -import FS from 'fs' -import TMP from 'tmp' +import * as Path from 'path' +import * as FS from 'fs' +import * as TMP from 'tmp' +import {getPath} from 'consistent-path' let XRegExp = null const EventsCache = new WeakMap() @@ -19,15 +20,15 @@ const assign = Object.assign || function(target, source) { function _exec(command, args, opts, isNode) { const options = assign({ + env: process.env, stream: 'stdout', throwOnStdErr: true }, opts) if (isNode) { - const env = assign({}, process.env) - delete env.OS - assign(options, {env}) + delete options.env.OS } + assign(options.env, {PATH: getPath()}) return new Promise(function(resolve, reject) { const data = {stdout: [], stderr: []}