Skip to content

Commit

Permalink
fix: windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 15, 2018
1 parent 0c256b0 commit 35d0f5e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/get-npm-modules-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = memoize(
const [npmPathPrefix] = String(stdout).split("\n", 1);
if (!npmPathPrefix) throw new Error("Could not resolve npm path prefix");
log.notice("npm path prefix: %s", npmPathPrefix);
if (process.platform === "win32") return resolve(npmPathPrefix, "node_modules");
return resolve(npmPathPrefix, "lib", "node_modules");
},
{ promise: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ module.exports = async dependencyContext => {
Object.entries(getPackageJson(path).bin || {}).map(async ([targetName, linkedPath]) => {
const targetPath = resolve(dependentContext.path, "node_modules/.bin", targetName);
await rm(targetPath, { loose: true, force: true, recursive: true });
await symlink(join("../", name, linkedPath), targetPath, { intermediate: true });
await symlink(join("../", name, linkedPath), targetPath, {
type: "junction",
intermediate: true
});
})
);
};
16 changes: 14 additions & 2 deletions lib/run-program.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const isObject = require("es5-ext/object/is-object")
, { spawn } = require("child-process-es6-promise")
, split = require("split");

const winCmdCommands = new Set();

module.exports = (command, args, options = {}) => {
if (!isObject(options)) options = {};
const { logger } = options, promise = spawn(command, args, { cwd: options.cwd });
const { logger } = options;
const promise = spawn(command + (winCmdCommands.has(command) ? ".cmd" : ""), args, {
cwd: options.cwd
});
const { child } = promise;

if (logger) {
Expand All @@ -17,5 +22,12 @@ module.exports = (command, args, options = {}) => {
.pipe(split(/\r?\n/u, null, { trailing: false }))
.on("data", data => logger.notice(String(data)));
}
return promise;

if (process.platform !== "win32") return promise;
if (winCmdCommands.has(command)) return promise;
return promise.catch(error => {
if (error.code !== "ENOENT") throw error;
winCmdCommands.add(command);
return module.exports(command, args, options);
});
};

0 comments on commit 35d0f5e

Please sign in to comment.