Skip to content

Commit

Permalink
Change deps.edn launch on windows to use bb.exe
Browse files Browse the repository at this point in the history
* bb.exe is bundled
* Rename project type Clojure CLI to deps.edn

Fixes #1000
  • Loading branch information
PEZ committed Jan 31, 2021
1 parent d04eb73 commit fb43dcf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
Binary file added bb.exe
Binary file not shown.
5 changes: 3 additions & 2 deletions src/nrepl/jack-in-terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface JackInTerminalOptions extends vscode.TerminalOptions {
env: { [key: string]: string },
executable: string,
args: string[],
isWin: boolean
isWin: boolean,
useShell: boolean
};

export function createCommandLine(executable: string, args: string[]) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class JackInTerminal implements vscode.Pseudoterminal {
this.process = child.spawn(this.options.executable, this.options.args, {
env: this.options.env,
cwd: this.options.cwd,
shell: !this.options.isWin
shell: this.options.useShell
});
this.process.on('exit', (status) => {
this.writeEmitter.fire(`Jack-in process exited. Status: ${status}\r\n`);
Expand Down
23 changes: 21 additions & 2 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import * as path from 'path';
import * as utilities from "../utilities";
import * as _ from "lodash";
import * as state from "../state"
Expand Down Expand Up @@ -136,9 +137,26 @@ async function getJackInTerminalOptions(projectConnectSequence: ReplConnectSeque
}

const projectType = projectTypes.getProjectTypeForName(projectTypeName);
const executable = projectTypes.isWin ? projectType.winCmd : projectType.cmd;
let executable: string;
let args: string[] = await projectType.commandLine(projectConnectSequence, selectedCljsType);
if (projectTypes.isWin) {
if (projectType.name === 'deps.edn') {
executable = path.join(state.extensionContext.extensionPath, 'bb.exe');
args = ['--clojure', ...args];
} else {
executable = projectType.winCmd[0];
args = [...projectType.winCmd.slice(1), ...args];
}
} else {
executable = projectType.cmd[0];
args = [...projectType.cmd.slice(1), ...args];
}

// Ask the project type to build up the command line. This may prompt for further information.
const args = await projectType.commandLine(projectConnectSequence, selectedCljsType);

if (projectTypes.isWin && projectType.name === 'deps.edn') {
executable = path.join(state.extensionContext.extensionPath, 'bb.exe'); //'cmd.exe';
}

const terminalOptions: JackInTerminalOptions = {
name: `Calva Jack-in: ${projectConnectSequence.name}`,
Expand All @@ -147,6 +165,7 @@ async function getJackInTerminalOptions(projectConnectSequence: ReplConnectSeque
env: getJackInEnv(),
isWin: projectTypes.isWin,
cwd: state.getProjectRootLocal(),
useShell: projectTypes.isWin ? projectType.processShellWin : projectType.processShellUnix
};
return terminalOptions;
}
Expand Down
43 changes: 25 additions & 18 deletions src/nrepl/project-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const isWin = /^win/.test(process.platform);
export type ProjectType = {
name: string;
cljsTypes: string[];
cmd: string;
winCmd: string;
cmd: string[];
winCmd: string[];
processShellWin: boolean;
processShellUnix: boolean;
commandLine: (connectSequence: ReplConnectSequence, cljsType: CljsTypes) => any;
useWhenExists: string;
nReplPortFile: string[];
Expand Down Expand Up @@ -245,8 +247,10 @@ const projectTypes: { [id: string]: ProjectType } = {
"lein": {
name: "Leiningen",
cljsTypes: ["Figwheel", "Figwheel Main"],
cmd: "lein",
winCmd: "cmd.exe",
cmd: ["lein"],
winCmd: ["cmd.exe", "/d", "/c", "lein"],
processShellUnix: true,
processShellWin: false,
useWhenExists: "project.clj",
nReplPortFile: [".nrepl-port"],
/** Build the command line args for a lein-project.
Expand Down Expand Up @@ -278,8 +282,10 @@ const projectTypes: { [id: string]: ProjectType } = {
"clj": {
name: "deps.edn",
cljsTypes: ["Figwheel", "Figwheel Main"],
cmd: "clojure",
winCmd: "powershell.exe",
cmd: ["clojure"],
winCmd: [], // this will be determined at jack-in
processShellUnix: true,
processShellWin: true,
useWhenExists: "deps.edn",
nReplPortFile: [".nrepl-port"],
/** Build the command line args for a clj-project.
Expand Down Expand Up @@ -338,29 +344,29 @@ const projectTypes: { [id: string]: ProjectType } = {
if (aliasHasMain)
break;
}
const q = isWin ? '"' : "'";
const dQ = isWin ? '""' : '"';
for (let dep in dependencies)
out.push(dep + ` {:mvn/version ${dQ}${dependencies[dep]}${dQ}}`)
out.push(dep + ` {:mvn/version,${dQ}${dependencies[dep]}${dQ}}`)

let args = ["-Sdeps", `'${"{:deps {" + out.join(' ') + "}}"}'`];
let args = ["-Sdeps", `${q}${"{:deps {" + out.join(',') + "}}"}${q}`];

if (aliasHasMain) {
args.push(aliasesOption);
} else {
args.push(aliasesOption, "-m", "nrepl.cmdline", "--middleware", `"[${useMiddleware.join(' ')}]"`);
}

if (isWin) {
args.unshift("clojure");
}
return args;
}
},
"shadow-cljs": {
name: "shadow-cljs",
cljsTypes: [],
cmd: "npx",
winCmd: "npx.cmd",
cmd: ["npx"],
winCmd: ["npx.cmd"],
processShellUnix: true,
processShellWin: false,
useWhenExists: "shadow-cljs.edn",
nReplPortFile: [".shadow-cljs", "nrepl.port"],
/**
Expand Down Expand Up @@ -391,8 +397,10 @@ const projectTypes: { [id: string]: ProjectType } = {
"lein-shadow": {
name: "lein-shadow",
cljsTypes: [],
cmd: "lein",
winCmd: "cmd.exe",
cmd: ["lein"],
winCmd: ["cmd.exe", "/d", "/c", "lein"],
processShellUnix: true,
processShellWin: false,
useWhenExists: "project.clj",
nReplPortFile: [".shadow-cljs", "nrepl.port"],
/**
Expand Down Expand Up @@ -420,6 +428,8 @@ const projectTypes: { [id: string]: ProjectType } = {
cljsTypes: [],
cmd: undefined,
winCmd: undefined,
processShellUnix: true,
processShellWin: false,
useWhenExists: undefined,
nReplPortFile: [".nrepl-port"],
commandLine: async (connectSequence: ReplConnectSequence, cljsType: CljsTypes) => {
Expand All @@ -438,9 +448,6 @@ async function leinCommandLine(command: string[], cljsType: CljsTypes, connectSe
let keys = Object.keys(dependencies);
const defproject = await leinDefProject();
const { profiles, alias } = await leinProfilesAndAlias(defproject, connectSequence);
if (isWin) {
out.push("/d", "/c", "lein");
}
const q = isWin ? '' : "'", dQ = '"';
for (let i = 0; i < keys.length; i++) {
let dep = keys[i];
Expand Down

0 comments on commit fb43dcf

Please sign in to comment.