Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fx
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroHryshyn committed Jan 10, 2024
1 parent c6b7956 commit c2acda4
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions src/components/engineService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,32 @@ export class EngineService {
await this.fetchPrivateCodemods();
}

private __getCodemodEngineNodeExecutableCommand() {
if (this.__codemodEngineNodeExecutableUri === null) {
throw new Error('The engines are not bootstrapped.');
}

return process.platform !== 'win32' ? singleQuotify(this.__codemodEngineNodeExecutableUri.fsPath) : this.__codemodEngineNodeExecutableUri.fsPath;
}

private __getCodemodEngineRustExecutableCommand() {
if (this.__codemodEngineRustExecutableUri === null) {
throw new Error('The engines are not bootstrapped.');
}

return process.platform !== 'win32' ? singleQuotify(this.__codemodEngineRustExecutableUri.fsPath) : this.__codemodEngineRustExecutableUri.fsPath;
}


public isEngineBootstrapped() {
return this.__codemodEngineNodeExecutableUri !== null;
}

public async syncRegistry(): Promise<void> {
if (this.__codemodEngineNodeExecutableUri === null) {
throw new Error('The engines are not bootstrapped.');
}


const childProcess = spawn(
singleQuotify(this.__codemodEngineNodeExecutableUri.fsPath),
this.__getCodemodEngineNodeExecutableCommand(),
['syncRegistry'],
{
stdio: 'pipe',
Expand All @@ -275,16 +290,8 @@ export class EngineService {
}

public async __getCodemodNames(): Promise<ReadonlyArray<string>> {
const executableUri = this.__codemodEngineNodeExecutableUri;

if (executableUri === null) {
throw new EngineNotFoundError(
'The codemod engine node has not been downloaded yet',
);
}

const childProcess = spawn(
singleQuotify(executableUri.fsPath),
this.__getCodemodEngineNodeExecutableCommand(),
['list', '--useJson', '--useCache'],
{
stdio: 'pipe',
Expand All @@ -294,7 +301,6 @@ export class EngineService {
);

const codemodListJSON = await streamToString(childProcess.stdout);

try {
const codemodListOrError = codemodNamesCodec.decode(
JSON.parse(codemodListJSON),
Expand Down Expand Up @@ -511,6 +517,7 @@ export class EngineService {
async #onExecuteCodemodSetMessage(
message: Message & { kind: MessageKind.executeCodemodSet },
) {

if (this.#execution) {
if (message.command.kind === 'executeCodemod') {
this.__executionMessageQueue.push(
Expand All @@ -531,17 +538,6 @@ export class EngineService {
return;
}

if (
!this.__codemodEngineNodeExecutableUri ||
!this.__codemodEngineRustExecutableUri
) {
await window.showErrorMessage(
'Wait until the engines has been bootstrapped to execute the operation',
);

return;
}

const codemodHash =
message.command.kind === 'executeCodemod' ||
message.command.kind === 'executeLocalCodemod'
Expand Down Expand Up @@ -569,13 +565,13 @@ export class EngineService {
message,
storageUri,
);


const executableCommand = message.command.kind === 'executePiranhaRule'
? this.__getCodemodEngineNodeExecutableCommand()
: this.__getCodemodEngineRustExecutableCommand()

const childProcess = spawn(
singleQuotify(
message.command.kind === 'executePiranhaRule'
? this.__codemodEngineRustExecutableUri.fsPath
: this.__codemodEngineNodeExecutableUri.fsPath,
),
executableCommand,
args,
{
stdio: 'pipe',
Expand Down

0 comments on commit c2acda4

Please sign in to comment.