Skip to content

Commit 6219d0c

Browse files
vitorbalnzakas
authored andcommitted
Fix: use __dirname to find transform files (refs #2) (#3)
* Fix: use __dirname to find transform files (refs #2) * Fix: add node_modules to env.path before running jscodeshift (fixes #2)
1 parent a091907 commit 6219d0c

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

bin/eslint-transforms.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,44 @@
22

33
"use strict";
44

5-
var nodeCLI = require("shelljs-nodecli");
5+
var execSync = require("child_process").execSync;
6+
var objectAssign = require("object-assign");
7+
var path = require("path");
68

79
var argv = process.argv.slice(2);
810
var args = argv.slice(1);
911
var transform = argv[0];
1012

11-
nodeCLI.exec(
13+
/**
14+
* Add possible node_modules/.bin paths to env and run the command passed in.
15+
*
16+
* @param {string} cmd The command to run
17+
* @returns {void}
18+
*/
19+
function execWithNodeModules(cmd) {
20+
var SEPARATOR = process.platform === "win32" ? ";" : ":",
21+
env = objectAssign({}, process.env);
22+
23+
env.PATH = [
24+
// Covers case when npm flattens dependencies and the jscodeshift bin will be directly under the root
25+
// node_modules folder
26+
path.resolve("./node_modules/.bin"),
27+
// Covers case when dependencies are not flattened and the jscodeshift bin can be found under the
28+
// node_modules folder of our package
29+
path.resolve(__dirname, "../node_modules/.bin"),
30+
env.PATH
31+
].join(SEPARATOR);
32+
33+
execSync(cmd, {
34+
env: env,
35+
cwd: process.cwd(),
36+
stdio: "inherit"
37+
});
38+
}
39+
40+
execWithNodeModules([
1241
"jscodeshift",
13-
"-t", "./lib/" + transform + "/" + transform + ".js",
42+
"-t",
43+
path.resolve(__dirname, "../lib/" + transform + "/" + transform + ".js"),
1444
args.join(" ")
15-
);
45+
].join(" "));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"dependencies": {
3434
"jscodeshift": "^0.3.20",
35-
"shelljs-nodecli": "^0.1.1"
35+
"object-assign": "^4.1.0"
3636
},
3737
"keywords": [
3838
"javascript",

0 commit comments

Comments
 (0)