Skip to content

Commit

Permalink
Add stricter eslint profile
Browse files Browse the repository at this point in the history
  • Loading branch information
WolffRuoff committed Oct 17, 2023
1 parent 51b7d8a commit e5173d1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"plugins": [
"@typescript-eslint"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
- name: Version Package
run: |
npm version $RELEASE_VERSION
git tag -a $RELEASE_VERSION -m "$RELEASE_VERSION"
- name: Package Extension
run: npm run package -- $RELEASE_VERSION -o "./rover-runner-$RELEASE_VERSION.vsix"
- name: Publish to Visual Studio Marketplace
Expand Down
27 changes: 15 additions & 12 deletions src/Subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const startup = (
subgraph: Subgraph,
debug: boolean,
context: vscode.ExtensionContext,
shouldRefresh: boolean = true
shouldRefresh = true
) => {
const subgraphStartupFulfilled = (name: string) => {
context.workspaceState.update(name, 'RunningSubgraph');
Expand Down Expand Up @@ -99,7 +99,7 @@ export class Subgraph extends vscode.TreeItem {
// Add auth header if Bearer Token set
const authHeader = vscode.workspace.getConfiguration().get('rover-runner.authorizationHeader', '');
process.env.ROV_TOK = authHeader;
let introspectionQuery = authHeader.length
const introspectionQuery = authHeader.length
? `rover subgraph introspect ${url} --header "Authorization: $ROV_TOK" --output ${this.label}.graphql`
: `rover subgraph introspect ${url} --output ${this.label}.graphql`;
const workspacePath = join(vscode.workspace?.workspaceFolders?.[0]?.uri?.fsPath || '', '.rover-runner/');
Expand All @@ -108,8 +108,10 @@ export class Subgraph extends vscode.TreeItem {
env: process.env,
});
return Promise.resolve('');
} catch (e: any) {
console.log(e?.message);
} catch (err) {
if (err instanceof Error) {
console.log(err?.message);
}
return Promise.reject(`Introspection failed at ${url}. Make sure Auth is up to date`);
}
}
Expand All @@ -124,14 +126,14 @@ export class Subgraph extends vscode.TreeItem {
return Promise.resolve('Path not provided');
} else if (debug) {
this.setLaunchJson();
let folder = vscode.workspace.workspaceFolders?.[0];
const folder = vscode.workspace.workspaceFolders?.[0];
await vscode.debug.startDebugging(folder, this.label, {
suppressDebugToolbar: false,
});
this.contextValue = 'RunningSubgraph';
return Promise.resolve('Launched in debug mode');
} else {
let subgraphTerminal =
const subgraphTerminal =
vscode.window.terminals.find((i) => i.name === this.label) || vscode.window.createTerminal(this.label);
subgraphTerminal.show(true);
subgraphTerminal.sendText(
Expand All @@ -145,7 +147,7 @@ export class Subgraph extends vscode.TreeItem {

public async startRunning(debug: boolean): Promise<string> {
this.contextValue = 'RunningSubgraph';
let roverTerminal =
const roverTerminal =
vscode.window.terminals.find((i) => i.name === `Rover ${this.label}`) ||
vscode.window.createTerminal(`Rover ${this.label}`);
roverTerminal.sendText(`
Expand All @@ -159,7 +161,7 @@ export class Subgraph extends vscode.TreeItem {
await setTimeout(3000);
roverTerminal.show(true);
// Make sure the subgraph is running before trying to run rover
let port: number = parseInt(this.local.split(':')?.[2]?.split('/')?.[0]);
const port: number = parseInt(this.local.split(':')?.[2]?.split('/')?.[0]);
return await detect(port).then((_port: number) => {
// _port is the next available port so if equal then server isn't running
if (port === _port && this.filePath) {
Expand Down Expand Up @@ -209,17 +211,18 @@ export class Subgraph extends vscode.TreeItem {
}

public async stopRunning(): Promise<string> {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
this.contextValue = 'StoppedSubgraph';
let roverTerminal = vscode.window.terminals.find((i) => i.name === `Rover ${this.label}`);
const roverTerminal = vscode.window.terminals.find((i) => i.name === `Rover ${this.label}`);
if (roverTerminal) {
roverTerminal.sendText('\u0003');
await setTimeout(3000);
roverTerminal.dispose();
}

if (this.current === 'localUrl') {
let subgraphTerminal = vscode.window.terminals.find((i) => i.name === this.label);
const subgraphTerminal = vscode.window.terminals.find((i) => i.name === this.label);
if (subgraphTerminal) {
subgraphTerminal.sendText('\u0003');
await setTimeout(3000);
Expand All @@ -231,8 +234,8 @@ export class Subgraph extends vscode.TreeItem {
}

setLaunchJson = () => {
let fileP: string = vscode.workspace.workspaceFolders?.[0].uri.path + '/.vscode/launch.json';
let launchFile = existsSync(fileP) ? readFileSync(fileP, 'utf-8') : undefined;
const fileP: string = vscode.workspace.workspaceFolders?.[0].uri.path + '/.vscode/launch.json';
const launchFile = existsSync(fileP) ? readFileSync(fileP, 'utf-8') : undefined;
let launchJson = launchFile ? JSON.parse(launchFile) : {};

if (!launchJson || !launchJson?.configurations) {
Expand Down
6 changes: 3 additions & 3 deletions src/SubgraphsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SubgraphsProvider implements vscode.TreeDataProvider<Subgraph | Sup
}

private getSupergraphs(configPath: string): Supergraph[] {
const toSupergraph = (supergraphName: string, supergraph: []): Supergraph => {
const toSupergraph = (supergraphName: string): Supergraph => {
// Can either be Stopped or Running
const contextValue = this.context.workspaceState.get(`${supergraphName}Supergraph`, 'StoppedSupergraph');
const newSupergraph = new Supergraph(
Expand All @@ -69,11 +69,11 @@ export class SubgraphsProvider implements vscode.TreeDataProvider<Subgraph | Sup
return newSupergraph;
};
const configJson = JSON.parse(readFileSync(configPath, 'utf-8'));
let supergraphs: Supergraph[] = [toSupergraph('All', [])];
let supergraphs: Supergraph[] = [toSupergraph('All')];
supergraphs = supergraphs.concat(
configJson.supergraphs
? Object.keys(configJson.supergraphs).map((supergraph) =>
toSupergraph(supergraph, configJson.supergraphs[supergraph])
toSupergraph(supergraph)
)
: []
);
Expand Down
6 changes: 3 additions & 3 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const isApolloConfigured = () => {
};

export const fetchSubgraphUrls = async () => {
let apolloKey = workspace
const apolloKey = workspace
.getConfiguration()
.get('apolloStudioConfiguration.apolloKey', '');
let graphRef = workspace
const graphRef = workspace
.getConfiguration()
.get('apolloStudioConfiguration.apolloGraphRef', '');
let body = {
const body = {
operationName: 'GetSubgraphUrls',
query:
'query GetSubgraphUrls($ref: ID!) { variant(ref: $ref) { ... on GraphVariant { subgraphs { name url }} ... on InvalidRefFormat { message }}}',
Expand Down
13 changes: 7 additions & 6 deletions src/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export class Supergraph extends TreeItem {

async getChildren(configPath: string, context: ExtensionContext): Promise<Subgraph[]> {
const toSubgraph = (subgraphName: string): Subgraph[] => {
let apolloDevUrl =
const apolloDevUrl =
apolloSubgraphs.data.variant?.subgraphs.find((e: any) => e['name'] === subgraphName)?.url ?? '';
let subgraphConfig = configJson.subgraphs[subgraphName];
const subgraphConfig = configJson.subgraphs[subgraphName];
if (!subgraphConfig) {
window.showErrorMessage(`Subgraph ${subgraphName} in supergraph has no match in the subgraphs list`);
return [];
}
let usedDevUrl = subgraphConfig?.devUrl ?? apolloDevUrl;
const usedDevUrl = subgraphConfig?.devUrl ?? apolloDevUrl;
// Can either be devUrl or localUrl
const current = context.workspaceState.get(subgraphName + 'currentUrl', 'devUrl');
// Can either be Stopped or Running
Expand Down Expand Up @@ -106,7 +106,7 @@ export class Supergraph extends TreeItem {
.then(() => writeSupergraphYaml(supergraphYaml))
.then(
() => {
let roverTerminal =
const roverTerminal =
window.terminals.find((i) => i.name === `Rover Runner`) || window.createTerminal(`Rover Runner`);
roverTerminal.show(true);
roverTerminal.sendText(`
Expand All @@ -124,14 +124,15 @@ export class Supergraph extends TreeItem {
}

public stopRunning(context: ExtensionContext): Promise<string> {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
let roverTerminal = window.terminals.find((i) => i.name === `Rover Runner`);
const roverTerminal = window.terminals.find((i) => i.name === `Rover Runner`);
if (roverTerminal) {
roverTerminal.sendText('\u0003');
await setTimeout(3000);
roverTerminal.dispose();
}
let stopList: any[] = [];
const stopList: Promise<void>[] = [];
// Add subgraphs to a promise all
this.children.forEach((subgraph) => {
if (context.workspaceState.get(subgraph.label) === 'RunningSubgraph') {
Expand Down

0 comments on commit e5173d1

Please sign in to comment.