diff --git a/base.eslintrc b/base.eslintrc index 8eb7443f05..4e97814ce8 100644 --- a/base.eslintrc +++ b/base.eslintrc @@ -23,7 +23,11 @@ {"ignoreRestSiblings": true, "argsIgnorePattern": "^_"} ], "@typescript-eslint/explicit-member-accessibility": "error", - "@typescript-eslint/prefer-for-of": "error" + "@typescript-eslint/prefer-for-of": "error", + "@typescript-eslint/await-thenable": "error", + "require-await": [ + "error" + ] } }, { diff --git a/packages/angular/.eslintrc b/packages/angular/.eslintrc index 19ad67fb0b..ff5178bdc6 100644 --- a/packages/angular/.eslintrc +++ b/packages/angular/.eslintrc @@ -5,5 +5,8 @@ }, "rules": { "node/no-unpublished-import": ["off"] + }, + "parserOptions": { + "project": "tsconfig.json" } } diff --git a/packages/atomic/create-atomic/.eslintrc b/packages/atomic/create-atomic/.eslintrc index 9b3bb27953..a057889957 100644 --- a/packages/atomic/create-atomic/.eslintrc +++ b/packages/atomic/create-atomic/.eslintrc @@ -2,5 +2,8 @@ "extends": "../../../base.eslintrc", "env": { "browser": true + }, + "parserOptions": { + "project": "tsconfig.json" } } diff --git a/packages/atomic/create-atomic/scripts/!.eslintrc b/packages/atomic/create-atomic/scripts/!.eslintrc new file mode 100644 index 0000000000..838c8c412f --- /dev/null +++ b/packages/atomic/create-atomic/scripts/!.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": "./node_modules/gts", + "overrides": [ + { + "files": "stencil.config.ts", + "rules": { + "node/no-unpublished-import": "off" + } + } + ] +} diff --git a/packages/atomic/create-atomic/scripts/preparePackageJsonTemplate.mjs b/packages/atomic/create-atomic/scripts/preparePackageJsonTemplate.mjs index 4a3ceaab64..fd0d87d7c6 100644 --- a/packages/atomic/create-atomic/scripts/preparePackageJsonTemplate.mjs +++ b/packages/atomic/create-atomic/scripts/preparePackageJsonTemplate.mjs @@ -1,5 +1,5 @@ import fs from 'fs-extra'; -const {readFileSync, writeFileSync, copySync} = fs; +const {readFileSync, writeFileSync, copySync, copyFileSync} = fs; import {join, resolve, dirname} from 'path'; import detectIndent from 'detect-indent'; import {fileURLToPath} from 'url'; @@ -9,6 +9,10 @@ const atomicTemplatePath = resolve(__dirname, '..', '..', 'template'); const bundledTemplatePath = resolve(__dirname, '..', 'template'); copySync(atomicTemplatePath, bundledTemplatePath, {recursive: true}); +copyFileSync( + join(__dirname, '!.eslintrc'), + join(bundledTemplatePath, '.eslintrc') +); const packageJson = readFileSync( join(bundledTemplatePath, 'package.json'), diff --git a/packages/atomic/create-atomic/src/plopfile.ts b/packages/atomic/create-atomic/src/plopfile.ts index c1b9781255..ddc6eced33 100644 --- a/packages/atomic/create-atomic/src/plopfile.ts +++ b/packages/atomic/create-atomic/src/plopfile.ts @@ -20,7 +20,7 @@ interface PlopData { page: IManifest; } -export default async function (plop: NodePlopAPI) { +export default function (plop: NodePlopAPI) { const currentPath = process.cwd(); let platformClientInstance: PlatformClient; diff --git a/packages/atomic/template/.eslintrc b/packages/atomic/template/.eslintrc index d94dc7d8e9..b04b1a64b0 100644 --- a/packages/atomic/template/.eslintrc +++ b/packages/atomic/template/.eslintrc @@ -7,5 +7,8 @@ "node/no-unpublished-import": "off" } } - ] + ], + "parserOptions": { + "project": "tsconfig.donotcopy.json" + } } diff --git a/packages/atomic/template/tsconfig.donotcopy.json b/packages/atomic/template/tsconfig.donotcopy.json new file mode 100644 index 0000000000..06e52cda4a --- /dev/null +++ b/packages/atomic/template/tsconfig.donotcopy.json @@ -0,0 +1,21 @@ +{ + "extends": "../../../node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "declaration": false, + "experimentalDecorators": true, + "lib": ["dom", "es2018"], + "moduleResolution": "node", + "module": "esnext", + "target": "es2018", + "noUnusedLocals": true, + "noUnusedParameters": true, + "jsx": "react", + "jsxFactory": "h", + "paths": { + "@coveo/headless": ["../../../node_modules/@coveo/atomic/headless"] + } + }, + "include": ["stencil.config.ts", "src"], + "exclude": ["node_modules", "lambda"] +} diff --git a/packages/cli-e2e/.eslintrc b/packages/cli-e2e/.eslintrc index 418bfe8788..15e2e028b5 100644 --- a/packages/cli-e2e/.eslintrc +++ b/packages/cli-e2e/.eslintrc @@ -2,5 +2,8 @@ "extends": "../../base.eslintrc", "env": { "es6": true + }, + "parserOptions": { + "project": "tsconfig.json" } } diff --git a/packages/cli-e2e/__tests__/angular.specs.ts b/packages/cli-e2e/__tests__/angular.specs.ts index 5033179290..2ed654b9ce 100644 --- a/packages/cli-e2e/__tests__/angular.specs.ts +++ b/packages/cli-e2e/__tests__/angular.specs.ts @@ -142,7 +142,7 @@ describe('ui:create:angular', () => { .until(buildTerminalExitPromise); }; - const startApplication = async ( + const startApplication = ( processManager: ProcessManager, debugName = 'angular-server' ) => { @@ -206,7 +206,7 @@ describe('ui:create:angular', () => { beforeAll(async () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'angular-server-valid' ); @@ -285,7 +285,7 @@ describe('ui:create:angular', () => { await page.keyboard.type('my query'); await page.keyboard.press('Enter'); - await retry(async () => { + await retry(() => { expect( interceptedRequests.some(isSearchRequestOrResponse) ).toBeTruthy(); @@ -309,7 +309,7 @@ describe('ui:create:angular', () => { describe('when the .env file is missing', () => { let serverProcessManager: ProcessManager; - beforeAll(async () => { + beforeAll(() => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); deactivateEnvironmentFile(join(projectPath, 'server')); @@ -325,7 +325,7 @@ describe('ui:create:angular', () => { async () => { const missingEnvErrorSpy = jest.fn(); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'angular-server-missing-env' ); @@ -350,7 +350,7 @@ describe('ui:create:angular', () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); envFileContent = flushEnvFile(join(projectPath, 'server')); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'angular-server-invalid' ); @@ -379,7 +379,7 @@ describe('ui:create:angular', () => { processManagers.push(serverProcessManager); setCustomTokenEndpoint(customTokenEndpoint); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'angular-server-port-test' ); @@ -392,13 +392,13 @@ describe('ui:create:angular', () => { resetCustomTokenEndpoint(); }, 30e3); - beforeEach(async () => { + beforeEach(() => { page.on('request', (request: HTTPRequest) => { interceptedRequests.push(request); }); }); - afterEach(async () => { + afterEach(() => { page.removeAllListeners('request'); interceptedRequests = []; }); @@ -406,7 +406,7 @@ describe('ui:create:angular', () => { it('should use the custom token endpoint', async () => { page.goto(searchPageEndpoint()); - await retry(async () => { + await retry(() => { expect( interceptedRequests.some( (request: HTTPRequest) => request.url() === customTokenEndpoint @@ -436,7 +436,7 @@ describe('ui:create:angular', () => { ); await Promise.all(dummyServers.map((server) => server.start())); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'angular-server-port-test' ); @@ -449,19 +449,19 @@ describe('ui:create:angular', () => { await serverProcessManager.killAllProcesses(); }, 30e3); - it('should allocate a new port for the application', async () => { + it('should allocate a new port for the application', () => { expect(clientPort).not.toEqual(usedClientPort); }); - it('should not use an undefined port for application', async () => { + it('should not use an undefined port for application', () => { expect(clientPort).not.toBeUndefined(); }); - it('should allocate a new port for the token server', async () => { + it('should allocate a new port for the token server', () => { expect(serverPort).not.toEqual(usedServerPort); }); - it('should not use an undefined port for token server', async () => { + it('should not use an undefined port for token server', () => { expect(serverPort).not.toBeUndefined(); }); diff --git a/packages/cli-e2e/__tests__/atomic.specs.ts b/packages/cli-e2e/__tests__/atomic.specs.ts index b0a365a82d..25a6f4c540 100644 --- a/packages/cli-e2e/__tests__/atomic.specs.ts +++ b/packages/cli-e2e/__tests__/atomic.specs.ts @@ -54,7 +54,7 @@ describe('ui:create:atomic', () => { const getFlagsFromOptions = (options: BuildAppOptions) => options.pageId ? ['--pageId', options.pageId] : undefined; - const selectDefaultWithCli = async (buildTerminal: Terminal) => { + const selectDefaultWithCli = (buildTerminal: Terminal) => { buildTerminal .when(/Use an existing hosted search page/) .on('stdout') @@ -140,7 +140,7 @@ describe('ui:create:atomic', () => { return {output}; }; - const startApplication = async ( + const startApplication = ( processManager: ProcessManager, options: BuildAppOptions, debugName = 'atomic-server' @@ -290,7 +290,7 @@ describe('ui:create:atomic', () => { beforeAll(async () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, buildAppOptions, 'atomic-server-valid' @@ -370,7 +370,7 @@ describe('ui:create:atomic', () => { dummyServer = new DummyServer(3333); await dummyServer.start(); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, buildAppOptions, 'stencil-port-test' diff --git a/packages/cli-e2e/__tests__/react.specs.ts b/packages/cli-e2e/__tests__/react.specs.ts index 40a415ecad..f08cc22c46 100644 --- a/packages/cli-e2e/__tests__/react.specs.ts +++ b/packages/cli-e2e/__tests__/react.specs.ts @@ -90,7 +90,7 @@ describe('ui:create:react', () => { await buildTerminal.when('exit').on('process').do().once(); }; - const startApplication = async ( + const startApplication = ( processManager: ProcessManager, debugName = 'react-server' ) => { @@ -147,7 +147,7 @@ describe('ui:create:react', () => { beforeAll(async () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'react-server-valid' ); @@ -230,7 +230,7 @@ describe('ui:create:react', () => { await page.keyboard.type('my query'); await page.keyboard.press('Enter'); - await retry(async () => { + await retry(() => { expect( interceptedRequests.some(isSearchRequestOrResponse) ).toBeTruthy(); @@ -253,7 +253,7 @@ describe('ui:create:react', () => { describe('when the .env file is missing', () => { let serverProcessManager: ProcessManager; - beforeAll(async () => { + beforeAll(() => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); deactivateEnvironmentFile(projectPath); @@ -269,7 +269,7 @@ describe('ui:create:react', () => { async () => { const missingEnvErrorSpy = jest.fn(); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'react-server-missing-env' ); @@ -296,7 +296,7 @@ describe('ui:create:react', () => { processManagers.push(serverProcessManager); envFileContent = flushEnvFile(projectPath); overwriteEnvFile(projectPath, 'GENERATE_SOURCEMAP=false'); // TODO: CDX-737: fix exponential-backoff compilation warnings - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'react-server-invalid' ); @@ -333,7 +333,7 @@ describe('ui:create:react', () => { processManagers.push(serverProcessManager); forceApplicationPorts(hardCodedClientPort, hardCodedServerPort); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'react-server-port-test' ); @@ -345,11 +345,11 @@ describe('ui:create:react', () => { await serverProcessManager.killAllProcesses(); }, 30e3); - it('should run the application on the specified port', async () => { + it('should run the application on the specified port', () => { expect(clientPort).toEqual(hardCodedClientPort); }); - it('should run the token server on the specified port', async () => { + it('should run the token server on the specified port', () => { expect(serverPort).toEqual(hardCodedServerPort); }); }); @@ -373,7 +373,7 @@ describe('ui:create:react', () => { ); await Promise.all(dummyServers.map((server) => server.start())); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'react-server-port-test' ); @@ -386,19 +386,19 @@ describe('ui:create:react', () => { await serverProcessManager.killAllProcesses(); }, 30e3); - it('should allocate a new port for the application', async () => { + it('should allocate a new port for the application', () => { expect(clientPort).not.toEqual(usedClientPort); }); - it('should not use an undefined port for application', async () => { + it('should not use an undefined port for application', () => { expect(clientPort).not.toBeUndefined(); }); - it('should allocate a new port for the token server', async () => { + it('should allocate a new port for the token server', () => { expect(serverPort).not.toEqual(usedServerPort); }); - it('should not use an undefined port for token server', async () => { + it('should not use an undefined port for token server', () => { expect(serverPort).not.toBeUndefined(); }); diff --git a/packages/cli-e2e/__tests__/vue.specs.ts b/packages/cli-e2e/__tests__/vue.specs.ts index c1e6b713e4..94a55402f9 100644 --- a/packages/cli-e2e/__tests__/vue.specs.ts +++ b/packages/cli-e2e/__tests__/vue.specs.ts @@ -109,7 +109,7 @@ describe('ui:create:vue', () => { await buildTerminalExitPromise; }; - const startApplication = async ( + const startApplication = ( processManager: ProcessManager, debugName = 'vue-server' ) => { @@ -167,7 +167,7 @@ describe('ui:create:vue', () => { beforeAll(async () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'vue-server-valid' ); @@ -242,7 +242,7 @@ describe('ui:create:vue', () => { await page.keyboard.type('my query'); await page.keyboard.press('Enter'); - await retry(async () => { + await retry(() => { expect( interceptedRequests.some(isSearchRequestOrResponse) ).toBeTruthy(); @@ -277,7 +277,7 @@ describe('ui:create:vue', () => { it( 'should not have any ESLint warning or error', async () => { - const serverTerminal = await startApplication( + const serverTerminal = startApplication( serverProcessManager, 'vue-server-eslint' ); @@ -298,7 +298,7 @@ describe('ui:create:vue', () => { describe('when the .env file is missing', () => { let serverProcessManager: ProcessManager; - beforeAll(async () => { + beforeAll(() => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); deactivateEnvironmentFile(projectPath); @@ -314,7 +314,7 @@ describe('ui:create:vue', () => { async () => { const missingEnvErrorSpy = jest.fn(); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'vue-server-missing-env' ); @@ -339,7 +339,7 @@ describe('ui:create:vue', () => { serverProcessManager = new ProcessManager(); processManagers.push(serverProcessManager); envFileContent = flushEnvFile(projectPath); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'vue-server-invalid' ); @@ -370,7 +370,7 @@ describe('ui:create:vue', () => { processManagers.push(serverProcessManager); forceApplicationPorts(hardCodedClientPort, hardCodedServerPort); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'vue-server-port-test' ); @@ -382,11 +382,11 @@ describe('ui:create:vue', () => { await serverProcessManager.killAllProcesses(); }, 30e3); - it('should run the application on the specified port', async () => { + it('should run the application on the specified port', () => { expect(clientPort).toEqual(hardCodedClientPort); }, 60e3); - it('should run the token server on the specified port', async () => { + it('should run the token server on the specified port', () => { expect(serverPort).toEqual(hardCodedServerPort); }, 60e3); }); @@ -410,7 +410,7 @@ describe('ui:create:vue', () => { ); await Promise.all(dummyServers.map((server) => server.start())); - const appTerminal = await startApplication( + const appTerminal = startApplication( serverProcessManager, 'vue-server-port-test' ); @@ -423,19 +423,19 @@ describe('ui:create:vue', () => { await serverProcessManager.killAllProcesses(); }, 30e3); - it('should allocate a new port for the application', async () => { + it('should allocate a new port for the application', () => { expect(clientPort).not.toEqual(usedClientPort); }); - it('should not use an undefined port for application', async () => { + it('should not use an undefined port for application', () => { expect(clientPort).not.toBeUndefined(); }); - it('should allocate a new port for the token server', async () => { + it('should allocate a new port for the token server', () => { expect(serverPort).not.toEqual(usedServerPort); }); - it('should not use an undefined port for token server', async () => { + it('should not use an undefined port for token server', () => { expect(serverPort).not.toBeUndefined(); }); diff --git a/packages/cli-e2e/setup/ci-login.ts b/packages/cli-e2e/setup/ci-login.ts index b57cff77bc..f3d0ac1980 100644 --- a/packages/cli-e2e/setup/ci-login.ts +++ b/packages/cli-e2e/setup/ci-login.ts @@ -20,10 +20,10 @@ async function main() { process.stdout.write(`CLI PATH : ${process.env.CLI_EXEC_PATH}`); global.processManager = new ProcessManager(); await authenticateCli(); - await outputCliConfig(); + outputCliConfig(); await global.processManager.killAllProcesses(); } -async function outputCliConfig() { +function outputCliConfig() { const config = getConfig(); setSecret(config.accessToken); exportVariable('CLI_CONFIG_PATH', getConfigFilePath()); diff --git a/packages/cli-e2e/setup/utils.ts b/packages/cli-e2e/setup/utils.ts index 3fcc4f9fff..4b4b6d4c7a 100644 --- a/packages/cli-e2e/setup/utils.ts +++ b/packages/cli-e2e/setup/utils.ts @@ -206,7 +206,7 @@ export const resolveBinary = (programName: string) => { return spawner.stdout.trim(); }; -const registryEnv = process.env.E2E_USE_NPM_REGISTRY +const registryEnv: Record = process.env.E2E_USE_NPM_REGISTRY ? {} : { npm_config_registry: 'http://localhost:4873', @@ -214,11 +214,11 @@ const registryEnv = process.env.E2E_USE_NPM_REGISTRY YARN_REGISTRY: 'http://localhost:4873', }; -export function getCleanEnv(): Record { - const env: Record = { +export function getCleanEnv(): Record { + const env: Record = { ...process.env, ...registryEnv, - npm_config_cache: process.env[npmCachePathEnvVar], + npm_config_cache: process.env[npmCachePathEnvVar]!, }; const excludeEnvVars = [ 'npm_config_local_prefix', diff --git a/packages/cli-e2e/utils/cli.ts b/packages/cli-e2e/utils/cli.ts index 464b34a247..bb1f8c325e 100644 --- a/packages/cli-e2e/utils/cli.ts +++ b/packages/cli-e2e/utils/cli.ts @@ -75,7 +75,7 @@ export async function setupUIProject( await gitInitTerminal.when('exit').on('process').do().once(); } - const env: Record = getCleanEnv(); + const env: Record = getCleanEnv(); const buildProcess = new Terminal( args.shift()!, args, diff --git a/packages/cli-e2e/utils/server.ts b/packages/cli-e2e/utils/server.ts index 838dc3dc4b..bdd50eb123 100644 --- a/packages/cli-e2e/utils/server.ts +++ b/packages/cli-e2e/utils/server.ts @@ -15,7 +15,7 @@ export class DummyServer { this.server.listen(this.port); } - public async close() { + public close() { return new Promise((resolve, reject) => { this.server.close((err) => { if (err) { diff --git a/packages/cli/commons/.eslintrc.js b/packages/cli/commons/.eslintrc.js index 14097a40a5..fe3ffa0074 100644 --- a/packages/cli/commons/.eslintrc.js +++ b/packages/cli/commons/.eslintrc.js @@ -1,5 +1,9 @@ const base = require('@coveo/cli-commons-dev/.eslintrc'); -module.exports = { +const config = { ...base, }; + +config.parserOptions = {...config.parserOptions, project: 'tsconfig.json'}; + +module.exports = config; diff --git a/packages/cli/commons/src/platform/authenticatedClient.ts b/packages/cli/commons/src/platform/authenticatedClient.ts index 1959407ed6..a9bcc74083 100644 --- a/packages/cli/commons/src/platform/authenticatedClient.ts +++ b/packages/cli/commons/src/platform/authenticatedClient.ts @@ -13,7 +13,7 @@ export class AuthenticatedClient { } public async isLoggedIn() { - const {accessToken} = await this.cfg.get(); + const {accessToken} = this.cfg.get(); return accessToken !== undefined; } @@ -28,7 +28,7 @@ export class AuthenticatedClient { } public async getClient(overrideConfig?: Partial) { - const configFromDisk = await this.cfg.get(); + const configFromDisk = this.cfg.get(); const resolvedConfig = {...configFromDisk, ...overrideConfig}; const globalRequestSettings: Record = {}; const proxyServer = diff --git a/packages/cli/core/.eslintrc.js b/packages/cli/core/.eslintrc.js index 14097a40a5..33d18ec058 100644 --- a/packages/cli/core/.eslintrc.js +++ b/packages/cli/core/.eslintrc.js @@ -1,5 +1,5 @@ const base = require('@coveo/cli-commons-dev/.eslintrc'); +const config = {...base}; +config.parserOptions = {...config.parserOptions, project: 'tsconfig.json'}; -module.exports = { - ...base, -}; +module.exports = config; diff --git a/packages/cli/core/index.ts b/packages/cli/core/index.ts deleted file mode 100644 index 9ea8fd0691..0000000000 --- a/packages/cli/core/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {run} from '@oclif/core'; diff --git a/packages/cli/core/src/commands/auth/login.ts b/packages/cli/core/src/commands/auth/login.ts index 8a4ff64513..b61a4b6362 100644 --- a/packages/cli/core/src/commands/auth/login.ts +++ b/packages/cli/core/src/commands/auth/login.ts @@ -63,8 +63,8 @@ export default class Login extends CLICommand { private async persistRegionAndEnvironment() { const {flags} = await this.parse(Login); const cfg = this.configuration; - await cfg.set('environment', flags.environment as PlatformEnvironment); - await cfg.set('region', flags.region as Region); + cfg.set('environment', flags.environment as PlatformEnvironment); + cfg.set('region', flags.region as Region); } private async persistOrganization() { @@ -72,13 +72,13 @@ export default class Login extends CLICommand { const cfg = this.configuration; if (flags.organization) { - await cfg.set('organization', flags.organization); + cfg.set('organization', flags.organization); return; } const firstOrgAvailable = await this.pickFirstAvailableOrganization(); if (firstOrgAvailable) { - await cfg.set('organization', firstOrgAvailable as string); + cfg.set('organization', firstOrgAvailable as string); return; } diff --git a/packages/cli/core/src/commands/auth/token.ts b/packages/cli/core/src/commands/auth/token.ts index b71afb6609..68199d30fc 100644 --- a/packages/cli/core/src/commands/auth/token.ts +++ b/packages/cli/core/src/commands/auth/token.ts @@ -32,10 +32,10 @@ export default class Token extends CLICommand { await this.saveToken(); await this.saveRegionAndEnvironment(); await this.fetchAndSaveOrgId(); - await this.feedbackOnSuccessfulLogin(); + this.feedbackOnSuccessfulLogin(); } - private async feedbackOnSuccessfulLogin() { + private feedbackOnSuccessfulLogin() { const cfg = this.configuration.get(); this.log(` Successfully logged in! diff --git a/packages/cli/core/src/commands/org/resources/model/create.spec.ts b/packages/cli/core/src/commands/org/resources/model/create.spec.ts index c5d33763c2..8220999022 100644 --- a/packages/cli/core/src/commands/org/resources/model/create.spec.ts +++ b/packages/cli/core/src/commands/org/resources/model/create.spec.ts @@ -29,7 +29,7 @@ const mockAuthenticatedClient = () => { }; const mockConfigWithDefaultEnvironment = () => { - mockedConfig.mockResolvedValue({ + mockedConfig.mockReturnValue({ organization: 'my-org', environment: DEFAULT_ENVIRONMENT, region: DEFAULT_REGION, @@ -37,7 +37,7 @@ const mockConfigWithDefaultEnvironment = () => { }; const mockConfigWithNonDefaultEnvironment = () => { - mockedConfig.mockResolvedValue({ + mockedConfig.mockReturnValue({ organization: 'my-org', environment: PlatformEnvironment.Dev, region: Region.EU, diff --git a/packages/cli/core/src/commands/org/resources/model/create.ts b/packages/cli/core/src/commands/org/resources/model/create.ts index 27b17ff50e..8360716d2b 100644 --- a/packages/cli/core/src/commands/org/resources/model/create.ts +++ b/packages/cli/core/src/commands/org/resources/model/create.ts @@ -14,20 +14,21 @@ export default class Create extends CLICommand { @Trackable({eventName: 'org resources pull - new model'}) @Preconditions(IsAuthenticated()) - public async run() { - await this.openPlatform(); + public run() { + this.openPlatform(); this .log(dedent`Make sure to save the resulting snapshot pull model, so you can later run "org:resources:pull -m " to create a snapshot of the target resources in your organization.`); + return Promise.resolve(); } - private async openPlatform() { - const url = await this.getPlatformUrl(); + private openPlatform() { + const url = this.getPlatformUrl(); open(url); } - private async getPlatformUrl() { - const cfg = await new AuthenticatedClient().cfg.get(); + private getPlatformUrl() { + const cfg = new AuthenticatedClient().cfg.get(); return createSnapshotUrl(cfg.organization, { environment: cfg.environment, region: cfg.region, diff --git a/packages/cli/core/src/commands/org/resources/monitor.ts b/packages/cli/core/src/commands/org/resources/monitor.ts index ee4c14474d..917e470b20 100644 --- a/packages/cli/core/src/commands/org/resources/monitor.ts +++ b/packages/cli/core/src/commands/org/resources/monitor.ts @@ -56,7 +56,7 @@ export default class Monitor extends CLICommand { } private getErrorHandler() { - return async function (this: SnapshotReporter) { + return function (this: SnapshotReporter) { CliUx.ux.log(ReportViewerStyles.error(this.resultCode)); }; } diff --git a/packages/cli/core/src/commands/org/resources/preview.spec.ts b/packages/cli/core/src/commands/org/resources/preview.spec.ts index 7b5c9e8c43..135212c8e2 100644 --- a/packages/cli/core/src/commands/org/resources/preview.spec.ts +++ b/packages/cli/core/src/commands/org/resources/preview.spec.ts @@ -87,7 +87,7 @@ const mockUserNotHavingAllRequiredPlatformPrivileges = () => { mockEvaluate.mockResolvedValue({approved: false}); }; -const mockSnapshotFactory = async () => { +const mockSnapshotFactory = () => { const dummySnapshot = { validate: mockedValidateSnapshot, preview: mockedPreviewSnapshot, @@ -106,7 +106,7 @@ const mockSnapshotFactory = async () => { ); }; -const mockSnapshotFactoryReturningValidSnapshot = async () => { +const mockSnapshotFactoryReturningValidSnapshot = () => { const successReport = getSuccessReport( 'success-report', ResourceSnapshotsReportType.Apply @@ -114,10 +114,10 @@ const mockSnapshotFactoryReturningValidSnapshot = async () => { mockedValidateSnapshot.mockImplementation(() => Promise.resolve(new SnapshotReporter(successReport)) ); - await mockSnapshotFactory(); + mockSnapshotFactory(); }; -const mockSnapshotFactoryReturningInvalidSnapshot = async () => { +const mockSnapshotFactoryReturningInvalidSnapshot = () => { const errorReport = getErrorReport( 'error-report', ResourceSnapshotsReportType.Apply @@ -125,20 +125,19 @@ const mockSnapshotFactoryReturningInvalidSnapshot = async () => { mockedValidateSnapshot.mockImplementation(() => Promise.resolve(new SnapshotReporter(errorReport)) ); - await mockSnapshotFactory(); + mockSnapshotFactory(); }; -const mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries = - async () => { - const missingVaultEntry = getMissingVaultEntryReport( - 'missing-vault-entry', - ResourceSnapshotsReportType.Apply - ); - mockedValidateSnapshot.mockImplementation(() => - Promise.resolve(new SnapshotReporter(missingVaultEntry)) - ); - await mockSnapshotFactory(); - }; +const mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries = () => { + const missingVaultEntry = getMissingVaultEntryReport( + 'missing-vault-entry', + ResourceSnapshotsReportType.Apply + ); + mockedValidateSnapshot.mockImplementation(() => + Promise.resolve(new SnapshotReporter(missingVaultEntry)) + ); + mockSnapshotFactory(); +}; describe('org:resources:preview', () => { const doMockPreconditions = function () { @@ -163,8 +162,8 @@ describe('org:resources:preview', () => { }); describe('when the report contains no resources in error', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningValidSnapshot(); + beforeAll(() => { + mockSnapshotFactoryReturningValidSnapshot(); }); afterAll(() => { @@ -331,8 +330,8 @@ describe('org:resources:preview', () => { }); //#region TODO: CDX-948, setup phase needs to be rewrite and assertions 'split up' (e.g. the error ain't trigger directly by the function, therefore should not be handled) describe('when the report contains resources in error', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningInvalidSnapshot(); + beforeAll(() => { + mockSnapshotFactoryReturningInvalidSnapshot(); }); beforeEach(() => { @@ -366,8 +365,8 @@ describe('org:resources:preview', () => { }); describe('when the report contains resources with missing vault entries', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries(); + beforeAll(() => { + mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries(); }); afterAll(() => { @@ -378,7 +377,7 @@ describe('org:resources:preview', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => false) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(false)) .command(['org:resources:preview']) .catch(/Your destination organization is missing vault entries/) .it('should throw an error for invalid snapshots'); diff --git a/packages/cli/core/src/commands/org/resources/preview.ts b/packages/cli/core/src/commands/org/resources/preview.ts index a27dc7fd3e..6e1388306d 100644 --- a/packages/cli/core/src/commands/org/resources/preview.ts +++ b/packages/cli/core/src/commands/org/resources/preview.ts @@ -60,7 +60,7 @@ export default class Preview extends CLICommand { ) public async run() { const {flags} = await this.parse(Preview); - const target = await getTargetOrg(this.configuration, flags.organization); + const target = getTargetOrg(this.configuration, flags.organization); const cfg = this.configuration.get(); const options = await this.getOptions(); const {reporter, snapshot, project} = await dryRun( @@ -110,7 +110,7 @@ export default class Preview extends CLICommand { if (err instanceof SnapshotOperationTimeoutError) { const {flags} = await this.parse(Preview); const snapshot = err.snapshot; - const target = await getTargetOrg(this.configuration, flags.organization); + const target = getTargetOrg(this.configuration, flags.organization); this.log( dedent` diff --git a/packages/cli/core/src/commands/org/resources/pull.spec.ts b/packages/cli/core/src/commands/org/resources/pull.spec.ts index 9e200ef8e8..fd226eb0ed 100644 --- a/packages/cli/core/src/commands/org/resources/pull.spec.ts +++ b/packages/cli/core/src/commands/org/resources/pull.spec.ts @@ -83,7 +83,7 @@ const mockUserNotHavingAllRequiredPlatformPrivileges = () => { mockEvaluate.mockResolvedValue({approved: false}); }; -const doMockSnapshotFactory = async () => { +const doMockSnapshotFactory = () => { mockedSnapshotFactory.createFromOrg.mockReturnValue( Promise.resolve({ delete: mockedDeleteSnapshot, @@ -223,7 +223,7 @@ describe('org:resources:pull', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command([ 'org:resources:pull', '-m', @@ -249,7 +249,7 @@ describe('org:resources:pull', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command([ 'org:resources:pull', '-m', @@ -276,7 +276,7 @@ describe('org:resources:pull', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command([ 'org:resources:pull', '-m', diff --git a/packages/cli/core/src/commands/org/resources/pull.ts b/packages/cli/core/src/commands/org/resources/pull.ts index a81073a51d..f85f224485 100644 --- a/packages/cli/core/src/commands/org/resources/pull.ts +++ b/packages/cli/core/src/commands/org/resources/pull.ts @@ -85,7 +85,7 @@ export default class Pull extends CLICommand { default: allowedResourceType, }), model: Flags.custom({ - parse: async (input: string): Promise => { + parse: (input: string): Promise => { const model = readJsonSync(resolve(input)); validateSnapshotPullModel(model); return model; @@ -171,7 +171,7 @@ export default class Pull extends CLICommand { ); } - private async askUserShouldWeOverwrite() { + private askUserShouldWeOverwrite() { const question = PullCommandStrings.projectOverwriteQuestion( Project.resourceFolderName ); diff --git a/packages/cli/core/src/commands/org/resources/push.spec.ts b/packages/cli/core/src/commands/org/resources/push.spec.ts index c0c183b87b..5b06051aad 100644 --- a/packages/cli/core/src/commands/org/resources/push.spec.ts +++ b/packages/cli/core/src/commands/org/resources/push.spec.ts @@ -65,8 +65,8 @@ const doMockConfig = () => { ); }; -const mockSnapshotFactory = async () => { - mockedPreviewSnapshot.mockReturnValue(Promise.resolve(``)); +const mockSnapshotFactory = () => { + mockedPreviewSnapshot.mockReturnValue(Promise.resolve('')); mockedSnapshotFactory.createFromZip.mockImplementation(() => Promise.resolve({ apply: mockedApplySnapshot, @@ -100,7 +100,7 @@ const mockUserNotHavingAllRequiredPlatformPrivileges = () => { mockEvaluate.mockResolvedValue({approved: false}); }; -const mockSnapshotFactoryReturningValidSnapshot = async () => { +const mockSnapshotFactoryReturningValidSnapshot = () => { const successReportValidate = getSuccessReport( 'success-report', ResourceSnapshotsReportType.DryRun @@ -116,10 +116,10 @@ const mockSnapshotFactoryReturningValidSnapshot = async () => { mockedApplySnapshot.mockImplementation( () => new SnapshotReporter(successReportApply) ); - await mockSnapshotFactory(); + mockSnapshotFactory(); }; -const mockSnapshotFactoryReturningInvalidSnapshot = async () => { +const mockSnapshotFactoryReturningInvalidSnapshot = () => { const errorReportValidate = getErrorReport( 'error-report', ResourceSnapshotsReportType.DryRun @@ -134,27 +134,26 @@ const mockSnapshotFactoryReturningInvalidSnapshot = async () => { mockedApplySnapshot.mockImplementation(() => Promise.resolve(new SnapshotReporter(errorReportApply)) ); - await mockSnapshotFactory(); + mockSnapshotFactory(); }; -const mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries = - async () => { - const missingVaultEntriesValidate = getMissingVaultEntryReport( - 'error-report', - ResourceSnapshotsReportType.DryRun - ); - const missingVaultEntriesApply = getMissingVaultEntryReport( - 'error-report', - ResourceSnapshotsReportType.Apply - ); - mockedValidateSnapshot.mockImplementation(() => - Promise.resolve(new SnapshotReporter(missingVaultEntriesValidate)) - ); - mockedApplySnapshot.mockImplementation(() => - Promise.resolve(new SnapshotReporter(missingVaultEntriesApply)) - ); - await mockSnapshotFactory(); - }; +const mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries = () => { + const missingVaultEntriesValidate = getMissingVaultEntryReport( + 'error-report', + ResourceSnapshotsReportType.DryRun + ); + const missingVaultEntriesApply = getMissingVaultEntryReport( + 'error-report', + ResourceSnapshotsReportType.Apply + ); + mockedValidateSnapshot.mockImplementation(() => + Promise.resolve(new SnapshotReporter(missingVaultEntriesValidate)) + ); + mockedApplySnapshot.mockImplementation(() => + Promise.resolve(new SnapshotReporter(missingVaultEntriesApply)) + ); + mockSnapshotFactory(); +}; describe('org:resources:push', () => { beforeAll(() => { @@ -184,8 +183,8 @@ describe('org:resources:push', () => { }); //#region TODO: CDX-948, setup phase needs to be rewrite and assertions 'split up' (e.g. the error ain't trigger directly by the function, therefore should not be handled) describe('when the dryRun returns a report without errors', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningValidSnapshot(); + beforeAll(() => { + mockSnapshotFactoryReturningValidSnapshot(); }); afterAll(() => { @@ -195,7 +194,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should preview the snapshot', () => { expect(mockedPreviewSnapshot).toHaveBeenCalledTimes(1); @@ -204,7 +203,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should apply the snapshot after confirmation', () => { expect(mockedApplySnapshot).toHaveBeenCalledTimes(1); @@ -213,7 +212,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => false) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(false)) .command(['org:resources:push']) .it('should not apply the snapshot if not confirmed', () => { expect(mockedApplySnapshot).toHaveBeenCalledTimes(0); @@ -222,7 +221,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should work with default connected org', () => { expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith( @@ -235,7 +234,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push', '-o', 'myorg']) .it('should work with specified target org', () => { expect(mockedProject).toHaveBeenCalledWith(expect.anything(), 'myorg'); @@ -249,7 +248,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should set a 60 seconds wait', () => { expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith( @@ -262,7 +261,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push', '-w', '99']) .it('should set a 99 seconds wait', () => { expect(mockedSnapshotFactory.createFromZip).toHaveBeenCalledWith( @@ -275,7 +274,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('#should not apply missing resources', () => { expect(mockedApplySnapshot).toHaveBeenCalledWith(false, {wait: 60}); @@ -284,7 +283,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push', '--deleteMissingResources']) .it('should apply missing resoucres', () => { expect(mockedApplySnapshot).toHaveBeenCalledWith(true, {wait: 60}); @@ -293,7 +292,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should delete the compressed folder', () => { expect(mockedDeleteTemporaryZipFile).toHaveBeenCalledTimes(1); @@ -302,7 +301,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .do(() => { mockedValidateSnapshot.mockImplementationOnce(() => { throw new Error('You shall not pass'); @@ -317,7 +316,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push']) .it('should delete the snapshot', () => { expect(mockedDeleteSnapshot).toHaveBeenCalledTimes(1); @@ -334,7 +333,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push', '--previewLevel', 'light']) .it('should only display light preview', () => { expect(mockedPreviewSnapshot).toHaveBeenCalledWith( @@ -347,7 +346,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => true) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(true)) .command(['org:resources:push', '--previewLevel', 'detailed']) .it('should display light and expanded preview', () => { expect(mockedPreviewSnapshot).toHaveBeenCalledWith( @@ -359,8 +358,8 @@ describe('org:resources:push', () => { }); describe('when the dryRun returns a report with errors', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningInvalidSnapshot(); + beforeAll(() => { + mockSnapshotFactoryReturningInvalidSnapshot(); }); test @@ -389,15 +388,15 @@ describe('org:resources:push', () => { }); describe('when the dryRun returns a report with missing vault entries', () => { - beforeAll(async () => { - await mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries(); + beforeAll(() => { + mockSnapshotFactoryReturningSnapshotWithMissingVaultEntries(); }); describe('when the user refuses to migrate or type in the missing vault entries', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => false) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(false)) .command(['org:resources:push']) .catch(/Your destination organization is missing vault entries/) .it('should show the missingVaultEntries snapshot error'); @@ -405,7 +404,7 @@ describe('org:resources:push', () => { test .stdout() .stderr() - .stub(CliUx.ux, 'confirm', () => async () => false) + .stub(CliUx.ux, 'confirm', () => () => Promise.resolve(false)) .command(['org:resources:push']) .catch(() => { expect(mockedPreviewSnapshot).toHaveBeenCalledTimes(1); diff --git a/packages/cli/core/src/commands/org/resources/push.ts b/packages/cli/core/src/commands/org/resources/push.ts index 85673c0cea..de456f764d 100644 --- a/packages/cli/core/src/commands/org/resources/push.ts +++ b/packages/cli/core/src/commands/org/resources/push.ts @@ -91,7 +91,7 @@ export default class Push extends CLICommand { await this.cleanup(snapshot, project); } - public async catch(err?: Error & {exitCode?: number}) { + public catch(err?: Error & {exitCode?: number}) { cleanupProject(this.projectPath); return super.catch(err); } @@ -114,7 +114,7 @@ export default class Push extends CLICommand { private getSuccessReportHandler(snapshot: Snapshot) { const successReportWithChangesHandler = () => this.successReportWithChangesHandler(snapshot); - return async function (this: SnapshotReporter) { + return function (this: SnapshotReporter) { return successReportWithChangesHandler(); }; } diff --git a/packages/cli/core/src/commands/org/search/dump.spec.ts b/packages/cli/core/src/commands/org/search/dump.spec.ts index 56c7be3e52..4bcfd3ab5c 100644 --- a/packages/cli/core/src/commands/org/search/dump.spec.ts +++ b/packages/cli/core/src/commands/org/search/dump.spec.ts @@ -31,7 +31,7 @@ mockedParser.mockImplementation( mockedConfig.mockImplementation( () => ({ - get: () => Promise.resolve({organization: 'the_org'}), + get: () => ({organization: 'the_org'}), } as unknown as Config) ); diff --git a/packages/cli/core/src/commands/org/search/dump.ts b/packages/cli/core/src/commands/org/search/dump.ts index 9d77d23946..391cf9d945 100644 --- a/packages/cli/core/src/commands/org/search/dump.ts +++ b/packages/cli/core/src/commands/org/search/dump.ts @@ -1,6 +1,6 @@ import {CLICommand} from '@coveo/cli-commons/command/cliCommand'; import {Flags, CliUx} from '@oclif/core'; -import {readJSONSync, writeFile, writeJSONSync} from 'fs-extra'; +import {readJSONSync, writeFileSync, writeJSONSync} from 'fs-extra'; import {Parser} from 'json2csv'; import {SingleBar} from 'cli-progress'; import PlatformClient from '@coveord/platform-client'; @@ -16,7 +16,6 @@ import {Trackable} from '@coveo/cli-commons/preconditions/trackable'; import {without} from '../../../lib/utils/list'; import {join} from 'path'; import dedent from 'ts-dedent'; - type ResponseExceededMaximumSizeError = {message: string; type: string}; interface RawResult { @@ -137,7 +136,7 @@ export default class Dump extends CLICommand { } } - public async catch(err?: Error & {exitCode?: number}) { + public catch(err?: Error & {exitCode?: number}) { this.progressBar?.stop(); return super.catch(err); } @@ -154,7 +153,7 @@ export default class Dump extends CLICommand { this.getDumpFilePathFromIndex(currentDumpFileIndex) ); const parser = new Parser({fields}); - await writeFile( + writeFileSync( join( flags.destination, `${flags.name}${ diff --git a/packages/cli/core/src/commands/ui/create/angular.ts b/packages/cli/core/src/commands/ui/create/angular.ts index dcd090ce73..9622bc4260 100644 --- a/packages/cli/core/src/commands/ui/create/angular.ts +++ b/packages/cli/core/src/commands/ui/create/angular.ts @@ -74,7 +74,7 @@ export default class Angular extends CLICommand { this.displayFeedbackAfterSuccess(args.name); } - private async createProject(name: string, defaults: boolean) { + private createProject(name: string, defaults: boolean) { const cliArgs = ['new', name, '--style', 'scss', '--routing']; if (defaults) { diff --git a/packages/cli/core/src/commands/ui/create/react.ts b/packages/cli/core/src/commands/ui/create/react.ts index faee56a08f..f64ea79030 100644 --- a/packages/cli/core/src/commands/ui/create/react.ts +++ b/packages/cli/core/src/commands/ui/create/react.ts @@ -117,7 +117,7 @@ export default class React extends CLICommand { } } - private async runReactCliCommand(args: string[]) { + private runReactCliCommand(args: string[]) { return spawnProcess(appendCmdIfWindows`npx`, [React.cliPackage, ...args]); } diff --git a/packages/cli/core/src/commands/ui/create/vue.ts b/packages/cli/core/src/commands/ui/create/vue.ts index e6e5260a49..dccb0dd89b 100644 --- a/packages/cli/core/src/commands/ui/create/vue.ts +++ b/packages/cli/core/src/commands/ui/create/vue.ts @@ -77,7 +77,7 @@ export default class Vue extends CLICommand { public async run() { const {args, flags} = await this.parse(Vue); - let preset = await this.getDefaultPreset(); + let preset = this.getDefaultPreset(); if (flags.preset) { try { @@ -117,7 +117,7 @@ export default class Vue extends CLICommand { }); } - private async getDefaultPreset() { + private getDefaultPreset() { return { useConfigFiles: true, plugins: { diff --git a/packages/cli/core/src/hooks/analytics/analytics.spec.ts b/packages/cli/core/src/hooks/analytics/analytics.spec.ts index 61974c5c32..28304178d2 100644 --- a/packages/cli/core/src/hooks/analytics/analytics.spec.ts +++ b/packages/cli/core/src/hooks/analytics/analytics.spec.ts @@ -139,11 +139,11 @@ describe('analytics_hook', () => { beforeEach(async () => { await hook(getAnalyticsHook({})); }); - fancyIt()('should only log one event', async () => { + fancyIt()('should only log one event', () => { expect(mockedLogEvent).toHaveBeenCalledTimes(1); }); - fancyIt()('should not log any identify event', async () => { + fancyIt()('should not log any identify event', () => { expect(mockedLogEvent).toHaveReturnedWith( expect.not.objectContaining({event_type: '$identify'}) ); @@ -155,18 +155,18 @@ describe('analytics_hook', () => { await hook(getAnalyticsHook({identify: true})); }); - fancyIt()('should log 2 events', async () => { + fancyIt()('should log 2 events', () => { expect(mockedLogEvent).toHaveBeenCalledTimes(2); }); - fancyIt()('should log an identify event', async () => { + fancyIt()('should log an identify event', () => { expect(mockedLogEvent).toHaveBeenCalledWith( expect.objectContaining({event_type: '$identify'}) ); }); describe('when the user is a coveo employee', () => { - fancyIt()('should identify event with (un-hashed) email', async () => { + fancyIt()('should identify event with (un-hashed) email', () => { const userIdCheck = expect.stringMatching('bob@coveo.com'); expect(mockedLogEvent).toHaveBeenCalledWith( expect.objectContaining({user_id: userIdCheck}) @@ -185,18 +185,15 @@ describe('analytics_hook', () => { await hook(getAnalyticsHook({identify: true})); }); - fancyIt()( - 'should not identify event with (un-hashed) email', - async () => { - const userIdCheck = expect.not.stringMatching('bob@coveo.com'); - expect(mockedLogEvent).toHaveBeenCalledWith( - expect.objectContaining({user_id: userIdCheck}) - ); - } - ); + fancyIt()('should not identify event with (un-hashed) email', () => { + const userIdCheck = expect.not.stringMatching('bob@coveo.com'); + expect(mockedLogEvent).toHaveBeenCalledWith( + expect.objectContaining({user_id: userIdCheck}) + ); + }); }); - fancyIt()('should identify event with device ID', async () => { + fancyIt()('should identify event with device ID', () => { const deviceIdCheck = expect.stringMatching(/.*/); expect(mockedLogEvent).toHaveBeenCalledWith( expect.objectContaining({device_id: deviceIdCheck}) diff --git a/packages/cli/core/src/hooks/analytics/analytics.ts b/packages/cli/core/src/hooks/analytics/analytics.ts index c8ca037f97..84305299c3 100644 --- a/packages/cli/core/src/hooks/analytics/analytics.ts +++ b/packages/cli/core/src/hooks/analytics/analytics.ts @@ -19,7 +19,7 @@ const hook = async function (options: AnalyticsHook) { // TODO: track event with anonymous user return; } - const platformIdentifier = await platformInfoIdentifier(); + const platformIdentifier = platformInfoIdentifier(); const {userId, deviceId, identify} = await new Identifier().getIdentity(); if (options.identify) { @@ -52,7 +52,7 @@ const augmentEvent = async ( }; }; -const platformInfoIdentifier = async () => { +const platformInfoIdentifier = () => { const authenticatedClient = new AuthenticatedClient(); const config = authenticatedClient.cfg.get(); return { diff --git a/packages/cli/core/src/hooks/analytics/identifier.spec.ts b/packages/cli/core/src/hooks/analytics/identifier.spec.ts index b6f03b2962..e317d130e8 100644 --- a/packages/cli/core/src/hooks/analytics/identifier.spec.ts +++ b/packages/cli/core/src/hooks/analytics/identifier.spec.ts @@ -82,15 +82,15 @@ describe('identifier', () => { ); }; - const mockForInternalUser = async () => { + const mockForInternalUser = () => { doMockConfiguration(); doMockPlatformClient('bob@coveo.com'); }; - const mockForExternalUser = async () => { + const mockForExternalUser = () => { doMockConfiguration(); doMockPlatformClient('bob@acme.com'); }; - const mockForAnonymousUser = async () => { + const mockForAnonymousUser = () => { doMockConfiguration({anonymous: true}); doMockPlatformClient(); }; @@ -111,7 +111,7 @@ describe('identifier', () => { describe('when the user is internal', () => { beforeEach(async () => { - await mockForInternalUser(); + mockForInternalUser(); identity = await new Identifier().getIdentity(); }); @@ -120,7 +120,7 @@ describe('identifier', () => { mockedPlatformClient.mockClear(); }); - it('should not set platform information', async () => { + it('should not set platform information', () => { expect(mockSetIdentity).not.toHaveBeenCalledWith( 'organization_type', 'Production' @@ -129,46 +129,46 @@ describe('identifier', () => { expect(mockSetIdentity).not.toHaveBeenCalledWith('region', 'us'); }); - it('should set the user ID (unhashed)', async () => { + it('should set the user ID (unhashed)', () => { expect(identity.userId).toBe('bob@coveo.com'); }); - it('should set is_internal_user to true', async () => { + it('should set is_internal_user to true', () => { expect(mockSetIdentity).toHaveBeenCalledWith('is_internal_user', true); }); - it('should identify event with (un-hashed) email', async () => { + it('should identify event with (un-hashed) email', () => { expect(identity.userId).toBe('bob@coveo.com'); }); - it('should always identify events with a device ID', async () => { + it('should always identify events with a device ID', () => { expect(identity.deviceId).toBeDefined(); }); }); describe('when the user is external', () => { beforeEach(async () => { - await mockForExternalUser(); + mockForExternalUser(); identity = await new Identifier().getIdentity(); }); - it('should set the user ID (hashed)', async () => { + it('should set the user ID (hashed)', () => { expect(identity.userId).not.toBeNull(); expect(identity.userId).not.toBe('bob@acme.com'); }); - it('should set is_internal_user to false', async () => { + it('should set is_internal_user to false', () => { expect(mockSetIdentity).toHaveBeenCalledWith('is_internal_user', false); }); }); describe('when the user is anonymous', () => { beforeEach(async () => { - await mockForAnonymousUser(); + mockForAnonymousUser(); identity = await new Identifier().getIdentity(); }); - it('should set the user ID', async () => { + it('should set the user ID', () => { expect(identity.userId).not.toBeNull(); }); }); @@ -179,13 +179,13 @@ describe('identifier', () => { identity.identify(getDummyAmplitudeClient()); }); - it('should add the CLI version to the event', async () => { + it('should add the CLI version to the event', () => { expect(mockedLogEvent).toHaveBeenCalledWith( expect.objectContaining({app_version: '1.2.3'}) ); }); - it('should add the OS information to the event', async () => { + it('should add the OS information to the event', () => { expect(mockedLogEvent).toHaveBeenCalledWith( expect.objectContaining({ app_version: '1.2.3', diff --git a/packages/cli/core/src/hooks/analytics/identifier.ts b/packages/cli/core/src/hooks/analytics/identifier.ts index 436d579ff3..0e6612f68d 100644 --- a/packages/cli/core/src/hooks/analytics/identifier.ts +++ b/packages/cli/core/src/hooks/analytics/identifier.ts @@ -57,13 +57,13 @@ export class Identifier { return hash.digest('hex').toString(); } - private async getAnalyticsInfo(platformClient: PlatformClient) { + private getAnalyticsInfo(platformClient: PlatformClient) { return this.configuration.anonymous ? this.getApiKeyInfo() : this.getUserInfo(platformClient); } - private async getApiKeyInfo() { + private getApiKeyInfo() { const identifier = this.configuration.accessToken ?.split('-') .pop() as string; diff --git a/packages/cli/core/src/hooks/init/set-global-config.ts b/packages/cli/core/src/hooks/init/set-global-config.ts index 540f7819fc..cecbc9fab2 100644 --- a/packages/cli/core/src/hooks/init/set-global-config.ts +++ b/packages/cli/core/src/hooks/init/set-global-config.ts @@ -2,11 +2,12 @@ import {handleTerminationSignals} from './termination-signals'; import {Hook} from '@oclif/core'; import globalConfig from '@coveo/cli-commons/config/globalConfig'; -const hook: Hook<'init'> = async function (opts) { +const hook: Hook<'init'> = function (opts) { handleTerminationSignals(); globalConfig.set(opts.config); process.env[this.config.scopedEnvVarKey('UPDATE_INSTRUCTIONS')] = 'Use "npm update --global @coveo/cli" to update your npm-based CLI installation.'; + return Promise.resolve(); }; export default hook; diff --git a/packages/cli/core/src/hooks/init/termination-signals.spec.ts b/packages/cli/core/src/hooks/init/termination-signals.spec.ts index ce0f977457..da16217550 100644 --- a/packages/cli/core/src/hooks/init/termination-signals.spec.ts +++ b/packages/cli/core/src/hooks/init/termination-signals.spec.ts @@ -47,11 +47,11 @@ describe('termination-signal', () => { await flushPromises(); }); - fancyIt()('should terminate the process', async () => { + fancyIt()('should terminate the process', () => { expect(mockExit).toHaveBeenCalled(); }); - fancyIt()('should send an interruption event', async () => { + fancyIt()('should send an interruption event', () => { expect(mockedAnalyticHook).toHaveBeenCalledWith('analytics', { event: { event_type: 'interrupted operation', @@ -62,7 +62,7 @@ describe('termination-signal', () => { }); }); - fancyIt()('should flush analytic events', async () => { + fancyIt()('should flush analytic events', () => { expect(mockedFlush).toHaveBeenCalledTimes(1); }); } diff --git a/packages/cli/source/.eslintignore b/packages/cli/source/.eslintignore index 9b1c8b133c..f0e59cc00a 100644 --- a/packages/cli/source/.eslintignore +++ b/packages/cli/source/.eslintignore @@ -1 +1,3 @@ -/dist +lib +coverage +the_config_dir diff --git a/packages/cli/source/.eslintrc.js b/packages/cli/source/.eslintrc.js index 14097a40a5..bcc46a9970 100644 --- a/packages/cli/source/.eslintrc.js +++ b/packages/cli/source/.eslintrc.js @@ -1,5 +1,6 @@ const base = require('@coveo/cli-commons-dev/.eslintrc'); -module.exports = { - ...base, -}; +const config = {...base}; +config.parserOptions = {...config.parserOptions, project: 'tsconfig.json'}; + +module.exports = config; diff --git a/packages/cli/source/.prettierignore b/packages/cli/source/.prettierignore new file mode 100644 index 0000000000..f0e59cc00a --- /dev/null +++ b/packages/cli/source/.prettierignore @@ -0,0 +1,3 @@ +lib +coverage +the_config_dir diff --git a/packages/cli/source/src/commands/source/catalog/add.ts b/packages/cli/source/src/commands/source/catalog/add.ts index 4c96bd5af3..e0cdd6df1a 100644 --- a/packages/cli/source/src/commands/source/catalog/add.ts +++ b/packages/cli/source/src/commands/source/catalog/add.ts @@ -122,7 +122,7 @@ export default class SourceCatalogAdd extends CLICommand { .batch(); } - public async catch(err?: Error & {exitCode?: number}) { + public catch(err?: Error & {exitCode?: number}) { formatErrorMessage(err); return super.catch(err); } diff --git a/packages/cli/source/src/commands/source/list.spec.ts b/packages/cli/source/src/commands/source/list.spec.ts index 2eed78f452..4bb581a487 100644 --- a/packages/cli/source/src/commands/source/list.spec.ts +++ b/packages/cli/source/src/commands/source/list.spec.ts @@ -18,28 +18,30 @@ const mockListSources = jest .fn() .mockReturnValue(Promise.resolve({totalEntries: 0, sourceModels: []})); +const createMockSourceModel = (id: string): SourceModel => ({ + name: `${id}_displayName`, + id, + owner: 'bob', + sourceVisibility: SourceVisibility.SECURED, + information: { + sourceStatus: {type: SourceStatusType.PUSH_READY}, + numberOfDocuments: 1234, + }, +}); + describe('source:push:list', () => { - const createMockSourceModel = (id: string): SourceModel => ({ - name: `${id}_displayName`, - id, - owner: 'bob', - sourceVisibility: SourceVisibility.SECURED, - information: { - sourceStatus: {type: SourceStatusType.PUSH_READY}, - numberOfDocuments: 1234, - }, + beforeAll(() => { + mockedAuthenticatedClient.mockImplementation( + () => + ({ + cfg: { + get: () => ({organization: 'foo'}), + }, + getClient: () => Promise.resolve({source: {list: mockListSources}}), + } as unknown as AuthenticatedClient) + ); }); - mockedAuthenticatedClient.mockImplementation( - () => - ({ - cfg: { - get: () => Promise.resolve({organization: 'foo'}), - }, - getClient: () => Promise.resolve({source: {list: mockListSources}}), - } as unknown as AuthenticatedClient) - ); - test .stdout() .stderr() diff --git a/packages/cli/source/src/commands/source/push/add.ts b/packages/cli/source/src/commands/source/push/add.ts index 4c782eaeff..6f558c5304 100644 --- a/packages/cli/source/src/commands/source/push/add.ts +++ b/packages/cli/source/src/commands/source/push/add.ts @@ -75,7 +75,7 @@ export default class SourcePushAdd extends CLICommand { public async run() { await this.showDeprecatedFlagWarning(); const {args, flags} = await this.parse(SourcePushAdd); - const source = await this.getSource(); + const source = this.getSource(); startSpinner('Processing files'); @@ -96,19 +96,19 @@ export default class SourcePushAdd extends CLICommand { .batch(); } - public async catch(err?: Error & {exitCode?: number}) { + public catch(err?: Error & {exitCode?: number}) { formatErrorMessage(err); return super.catch(err); } protected async finally(_?: Error) { const {args} = await this.parse(SourcePushAdd); - const source = await this.getSource(); + const source = this.getSource(); await source.setSourceStatus(args.sourceId, 'IDLE'); await super.finally(_); } - public async getSource() { + public getSource() { const {accessToken, organization, environment, region} = new AuthenticatedClient().cfg.get(); return new PushSource(accessToken!, organization, { diff --git a/packages/cli/source/src/commands/source/push/delete.spec.ts b/packages/cli/source/src/commands/source/push/delete.spec.ts index 36fbe0a036..3b44770a91 100644 --- a/packages/cli/source/src/commands/source/push/delete.spec.ts +++ b/packages/cli/source/src/commands/source/push/delete.spec.ts @@ -14,39 +14,40 @@ import { const mockedClient = jest.mocked(AuthenticatedClient); const mockedSource = jest.mocked(PushSource); -describe('source:push:delete', () => { - const mockDeleteOlderThan = jest - .fn() - .mockReturnValue(Promise.resolve(doMockAxiosSuccess(202, 'tiguidou'))); +const mockDeleteOlderThan = jest + .fn() + .mockReturnValue(Promise.resolve(doMockAxiosSuccess(202, 'tiguidou'))); - const mockeleteDocument = jest - .fn() - .mockReturnValue(Promise.resolve(doMockAxiosSuccess(202, 'right trou'))); +const mockDeleteDocument = jest + .fn() + .mockReturnValue(Promise.resolve(doMockAxiosSuccess(202, 'right trou'))); - mockedClient.mockImplementation( - () => - ({ - cfg: { - get: () => - Promise.resolve({ +describe('source:push:delete', () => { + beforeAll(() => { + mockedClient.mockImplementation( + () => + ({ + cfg: { + get: () => ({ accessToken: 'the_token', organization: 'the_org', }), - }, - } as unknown as AuthenticatedClient) - ); + }, + } as unknown as AuthenticatedClient) + ); - mockedSource.mockImplementation( - () => - ({ - deleteDocumentsOlderThan: mockDeleteOlderThan, - deleteDocument: mockeleteDocument, - } as unknown as PushSource) - ); + mockedSource.mockImplementation( + () => + ({ + deleteDocumentsOlderThan: mockDeleteOlderThan, + deleteDocument: mockDeleteDocument, + } as unknown as PushSource) + ); + }); beforeEach(() => { mockDeleteOlderThan.mockClear(); - mockeleteDocument.mockClear(); + mockDeleteDocument.mockClear(); }); test @@ -153,7 +154,7 @@ describe('source:push:delete', () => { test .do(() => { - mockeleteDocument.mockReturnValueOnce( + mockDeleteDocument.mockReturnValueOnce( doMockAxiosSuccess(999, 'this document is gone') ); }) @@ -195,7 +196,7 @@ describe('source:push:delete', () => { test .do(() => { - mockeleteDocument.mockRejectedValueOnce( + mockDeleteDocument.mockRejectedValueOnce( doMockAxiosError( 412, 'this is a bad request and you should feel bad', @@ -227,7 +228,7 @@ describe('source:push:delete', () => { 'this is a bad request and you should feel bad', 'BAD_REQUEST' ); - mockeleteDocument.mockRejectedValueOnce(err).mockRejectedValueOnce(err); + mockDeleteDocument.mockRejectedValueOnce(err).mockRejectedValueOnce(err); }) .stdout() .stderr() @@ -253,7 +254,7 @@ describe('source:push:delete', () => { test .do(() => { - mockeleteDocument.mockRejectedValueOnce( + mockDeleteDocument.mockRejectedValueOnce( doMockAxiosError( 412, 'this is a bad request and you should feel bad', diff --git a/packages/cli/source/src/commands/source/push/delete.ts b/packages/cli/source/src/commands/source/push/delete.ts index 5b2f0203e2..2d6247e0e1 100644 --- a/packages/cli/source/src/commands/source/push/delete.ts +++ b/packages/cli/source/src/commands/source/push/delete.ts @@ -60,7 +60,7 @@ export default class SourcePushDelete extends CLICommand { 'You must minimally set the `delete` or the `deleteOlderThan` flag. Use `source:push:delete --help` to get more information.' ); } - const cfg = await new AuthenticatedClient().cfg.get(); + const cfg = new AuthenticatedClient().cfg.get(); const source = new PushSource(cfg.accessToken!, cfg.organization); if (flags.deleteOlderThan) { diff --git a/packages/cli/source/src/commands/source/push/list.spec.ts b/packages/cli/source/src/commands/source/push/list.spec.ts index a95f172083..e99e6b75a9 100644 --- a/packages/cli/source/src/commands/source/push/list.spec.ts +++ b/packages/cli/source/src/commands/source/push/list.spec.ts @@ -18,28 +18,30 @@ const mockListSources = jest .fn() .mockReturnValue(Promise.resolve({totalEntries: 0, sourceModels: []})); +const createMockSourceModel = (id: string): SourceModel => ({ + name: `${id}_displayName`, + id, + owner: 'bob', + sourceVisibility: SourceVisibility.SECURED, + information: { + sourceStatus: {type: SourceStatusType.PUSH_READY}, + numberOfDocuments: 1234, + }, +}); + describe('source:push:list', () => { - const createMockSourceModel = (id: string): SourceModel => ({ - name: `${id}_displayName`, - id, - owner: 'bob', - sourceVisibility: SourceVisibility.SECURED, - information: { - sourceStatus: {type: SourceStatusType.PUSH_READY}, - numberOfDocuments: 1234, - }, + beforeAll(() => { + mockedAuthenticatedClient.mockImplementation( + () => + ({ + cfg: { + get: () => ({organization: 'foo'}), + }, + getClient: () => Promise.resolve({source: {list: mockListSources}}), + } as unknown as AuthenticatedClient) + ); }); - mockedAuthenticatedClient.mockImplementation( - () => - ({ - cfg: { - get: () => Promise.resolve({organization: 'foo'}), - }, - getClient: () => Promise.resolve({source: {list: mockListSources}}), - } as unknown as AuthenticatedClient) - ); - test .stdout() .stderr() diff --git a/packages/cli/source/src/commands/source/push/list.ts b/packages/cli/source/src/commands/source/push/list.ts index 38c9af11b1..6bc626b9f9 100644 --- a/packages/cli/source/src/commands/source/push/list.ts +++ b/packages/cli/source/src/commands/source/push/list.ts @@ -30,7 +30,7 @@ export default class SourcePushList extends CLICommand { CliUx.ux.warn(`${magenta('deprecated')} Use ${SourceList.id} instead`); const {flags} = await this.parse(SourcePushList); const authenticatedClient = new AuthenticatedClient(); - const org = (await authenticatedClient.cfg.get()).organization; + const org = authenticatedClient.cfg.get().organization; const platformClient = await authenticatedClient.getClient(); const sources = await platformClient.source.list({ diff --git a/packages/cra-template/.eslintrc b/packages/cra-template/.eslintrc index 68b30056e6..d57741709a 100644 --- a/packages/cra-template/.eslintrc +++ b/packages/cra-template/.eslintrc @@ -2,5 +2,8 @@ "extends": "../../base.eslintrc", "rules": { "node/no-unpublished-import": ["off"] + }, + "parserOptions": { + "project": "../../tsconfig.base.json" } } diff --git a/packages/vue-cli-plugin-typescript/.eslintrc b/packages/vue-cli-plugin-typescript/.eslintrc index 68b30056e6..e107648084 100644 --- a/packages/vue-cli-plugin-typescript/.eslintrc +++ b/packages/vue-cli-plugin-typescript/.eslintrc @@ -2,5 +2,8 @@ "extends": "../../base.eslintrc", "rules": { "node/no-unpublished-import": ["off"] + }, + "parserOptions": { + "project": "tsconfig.json" } }