-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for locating a bundled version of
air
- Loading branch information
1 parent
d91c8bf
commit 8828ccb
Showing
8 changed files
with
255 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as vscode from "vscode"; | ||
import which from "which"; | ||
import { AIR_BINARY_NAME, BUNDLED_AIR_EXECUTABLE } from "./constants"; | ||
import { outputLog } from "./logging"; | ||
|
||
export type ExecutableLocation = "environment" | "bundled"; | ||
|
||
export async function resolveAirBinaryPath( | ||
executableLocation: ExecutableLocation | ||
): Promise<string> { | ||
if (!vscode.workspace.isTrusted) { | ||
outputLog( | ||
`Workspace is not trusted, using bundled executable: ${BUNDLED_AIR_EXECUTABLE}` | ||
); | ||
return BUNDLED_AIR_EXECUTABLE; | ||
} | ||
|
||
// User requested the bundled air binary | ||
if (executableLocation === "bundled") { | ||
outputLog( | ||
`Using bundled executable as requested by \`air.executableLocation\`: ${BUNDLED_AIR_EXECUTABLE}` | ||
); | ||
return BUNDLED_AIR_EXECUTABLE; | ||
} | ||
|
||
// First choice: the executable in the global environment. | ||
const environmentPath = await which(AIR_BINARY_NAME, { nothrow: true }); | ||
if (environmentPath) { | ||
outputLog(`Using environment executable: ${environmentPath}`); | ||
return environmentPath; | ||
} | ||
|
||
// Second choice: bundled executable. | ||
outputLog(`Using bundled executable: ${BUNDLED_AIR_EXECUTABLE}`); | ||
return BUNDLED_AIR_EXECUTABLE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as path from "path"; | ||
|
||
const folderName = path.basename(__dirname); | ||
|
||
/** | ||
* Path to the root directory of this extension. | ||
*/ | ||
export const EXTENSION_ROOT_DIR = | ||
folderName === "common" | ||
? path.dirname(path.dirname(__dirname)) | ||
: path.dirname(__dirname); | ||
|
||
/** | ||
* Name of the `air` binary based on the current platform. | ||
*/ | ||
export const AIR_BINARY_NAME = process.platform === "win32" ? "air.exe" : "air"; | ||
|
||
/** | ||
* Path to the `air` executable that is bundled with the extension. | ||
* The GitHub Action is in charge of placing the executable here. | ||
*/ | ||
export const BUNDLED_AIR_EXECUTABLE = path.join( | ||
EXTENSION_ROOT_DIR, | ||
"bundled", | ||
"bin", | ||
AIR_BINARY_NAME | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as util from "util"; | ||
import { Disposable, OutputChannel } from "vscode"; | ||
|
||
type Arguments = unknown[]; | ||
class OutputChannelLogger { | ||
constructor(private readonly channel: OutputChannel) {} | ||
|
||
public outputLog(...data: Arguments): void { | ||
this.channel.appendLine(util.format(...data)); | ||
} | ||
} | ||
|
||
let channel: OutputChannelLogger | undefined; | ||
export function registerLogger(logChannel: OutputChannel): Disposable { | ||
channel = new OutputChannelLogger(logChannel); | ||
return { | ||
dispose: () => { | ||
channel = undefined; | ||
}, | ||
}; | ||
} | ||
|
||
export function outputLog(...args: Arguments): void { | ||
if (process.env.CI === "true") { | ||
console.log(...args); | ||
} | ||
channel?.outputLog(...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.