From 42b68ca1a784a249bcf84701e845ff60ecec0388 Mon Sep 17 00:00:00 2001 From: steelbrain Date: Tue, 29 Dec 2015 23:49:49 -0700 Subject: [PATCH 1/3] :new: Use consistent-path Fixes AtomLinter/atom-linter#62 --- lib/helpers.js | 48 +++++++++++++++++++++++++----------------------- package.json | 3 ++- src/helpers.js | 13 +++++++------ 3 files changed, 34 insertions(+), 30 deletions(-) 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..305c3d4 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.0" }, "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: []} From bb8e568d7f3b2997dd963453bb35a8a4ed6e16f0 Mon Sep 17 00:00:00 2001 From: steelbrain Date: Tue, 29 Dec 2015 23:51:02 -0700 Subject: [PATCH 2/3] :memo: Document change in CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From 970370fed14b85a8ce2be5048cb1ef0274314065 Mon Sep 17 00:00:00 2001 From: steelbrain Date: Tue, 29 Dec 2015 23:56:13 -0700 Subject: [PATCH 3/3] :arrow_up: Bump version to 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 305c3d4..d651c64 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "xregexp": "^3.0.0", "tmp": "latest", - "consistent-path": "^1.0.0" + "consistent-path": "^1.0.1" }, "devDependencies": { "babel-preset-steelbrain": "^1.0.0"