diff --git a/.eslintrc.json b/.eslintrc.json index f9b22b7..11ef8bf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,6 +8,7 @@ "plugins": [ "@typescript-eslint" ], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], "rules": { "@typescript-eslint/naming-convention": "warn", "@typescript-eslint/semi": "warn", diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 45e3899..9ef48c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/src/Subgraph.ts b/src/Subgraph.ts index 1bd2429..f75cbf1 100644 --- a/src/Subgraph.ts +++ b/src/Subgraph.ts @@ -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'); @@ -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/'); @@ -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`); } } @@ -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( @@ -145,7 +147,7 @@ export class Subgraph extends vscode.TreeItem { public async startRunning(debug: boolean): Promise { 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(` @@ -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) { @@ -209,9 +211,10 @@ export class Subgraph extends vscode.TreeItem { } public async stopRunning(): Promise { + // 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); @@ -219,7 +222,7 @@ export class Subgraph extends vscode.TreeItem { } 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); @@ -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) { diff --git a/src/SubgraphsProvider.ts b/src/SubgraphsProvider.ts index b84d305..3f4815e 100644 --- a/src/SubgraphsProvider.ts +++ b/src/SubgraphsProvider.ts @@ -54,7 +54,7 @@ export class SubgraphsProvider implements vscode.TreeDataProvider { + const toSupergraph = (supergraphName: string): Supergraph => { // Can either be Stopped or Running const contextValue = this.context.workspaceState.get(`${supergraphName}Supergraph`, 'StoppedSupergraph'); const newSupergraph = new Supergraph( @@ -69,11 +69,11 @@ export class SubgraphsProvider implements vscode.TreeDataProvider - toSupergraph(supergraph, configJson.supergraphs[supergraph]) + toSupergraph(supergraph) ) : [] ); diff --git a/src/setup.ts b/src/setup.ts index 3b122e2..8cd3600 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -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 }}}', diff --git a/src/supergraph.ts b/src/supergraph.ts index 045acfe..17e9179 100644 --- a/src/supergraph.ts +++ b/src/supergraph.ts @@ -23,14 +23,14 @@ export class Supergraph extends TreeItem { async getChildren(configPath: string, context: ExtensionContext): Promise { 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 @@ -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(` @@ -124,14 +124,15 @@ export class Supergraph extends TreeItem { } public stopRunning(context: ExtensionContext): Promise { + // 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[] = []; // Add subgraphs to a promise all this.children.forEach((subgraph) => { if (context.workspaceState.get(subgraph.label) === 'RunningSubgraph') {