From 6426ce1fb1eb7882dfd24f9d009d274b43afa2ed Mon Sep 17 00:00:00 2001 From: Justin Dalrymple Date: Tue, 16 Jun 2020 13:37:56 +0200 Subject: [PATCH] Removal of esinterlop to prefer namespace imports over default exports (#893) --- packages/gitbeaker-browser/src/KyRequester.ts | 4 ++-- .../test/unit/KyRequester.ts | 4 ++-- packages/gitbeaker-browser/tsconfig.json | 1 + packages/gitbeaker-cli/src/cli.ts | 21 +++++++++---------- packages/gitbeaker-cli/test/unit/index.ts | 2 +- packages/gitbeaker-core/scripts/tsconfig.json | 3 ++- .../src/infrastructure/RequestHelper.ts | 4 ++-- .../src/infrastructure/Utils.ts | 2 +- .../test/unit/infrastructure/RequestHelper.ts | 2 +- packages/gitbeaker-node/src/GotRequester.ts | 2 +- .../gitbeaker-node/test/unit/GotRequester.ts | 4 ++-- .../src/RequesterUtils.ts | 4 ++-- .../test/unit/RequesterUtils.ts | 2 +- tsconfig.json | 2 +- 14 files changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/gitbeaker-browser/src/KyRequester.ts b/packages/gitbeaker-browser/src/KyRequester.ts index 41adcec7..2434a2df 100644 --- a/packages/gitbeaker-browser/src/KyRequester.ts +++ b/packages/gitbeaker-browser/src/KyRequester.ts @@ -1,4 +1,4 @@ -import Ky from 'ky'; +import ky from 'ky'; import { Agent } from 'https'; import { Service, @@ -52,7 +52,7 @@ export async function handler(endpoint, options) { let response; try { - response = await Ky(endpoint, options); + response = await ky(endpoint, options); } catch (e) { if (e.response) { const output = await e.response.json(); diff --git a/packages/gitbeaker-browser/test/unit/KyRequester.ts b/packages/gitbeaker-browser/test/unit/KyRequester.ts index 3e79a2a1..c9a13c5f 100644 --- a/packages/gitbeaker-browser/test/unit/KyRequester.ts +++ b/packages/gitbeaker-browser/test/unit/KyRequester.ts @@ -1,5 +1,5 @@ -import ky from 'ky'; -import fetch from 'node-fetch'; +import * as ky from 'ky'; +import * as fetch from 'node-fetch'; import { Agent } from 'https'; import { processBody, handler, defaultRequest } from '../../src/KyRequester'; diff --git a/packages/gitbeaker-browser/tsconfig.json b/packages/gitbeaker-browser/tsconfig.json index 8da2efa0..894b27e5 100644 --- a/packages/gitbeaker-browser/tsconfig.json +++ b/packages/gitbeaker-browser/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "esModuleInterop": true, "outDir": "./dist", "declaration": true, "declarationDir": "dist/types" diff --git a/packages/gitbeaker-cli/src/cli.ts b/packages/gitbeaker-cli/src/cli.ts index 166ee7b3..9ba048e9 100644 --- a/packages/gitbeaker-cli/src/cli.ts +++ b/packages/gitbeaker-cli/src/cli.ts @@ -1,19 +1,19 @@ -import program, { Options } from 'sywac'; -import chalk from 'chalk'; +import * as Sywac from 'sywac'; +import * as Chalk from 'chalk'; import { camelize, decamelize, depascalize } from 'xcase'; import * as Gitbeaker from '@gitbeaker/node'; import * as map from '@gitbeaker/core/dist/map.json'; // Styling settings -const commandStyle = chalk.hex('#e34329').bold; -const groupStyle = chalk.hex('#fca325').bold; -const usageStyle = chalk.hex('#fc6e26').bold; -const optionStyle = chalk.white.bold; -const descriptionStyle = chalk.hex('#848484'); -const hintStyle = chalk.hex('#6a5f88'); +const commandStyle = Chalk.hex('#e34329').bold; +const groupStyle = Chalk.hex('#fca325').bold; +const usageStyle = Chalk.hex('#fc6e26').bold; +const optionStyle = Chalk.white.bold; +const descriptionStyle = Chalk.hex('#848484'); +const hintStyle = Chalk.hex('#6a5f88'); // Globally configurable arguments -function globalConfig(env = process.env): { [name: string]: Options } { +function globalConfig(env = process.env): { [name: string]: Sywac.Options } { return { 'gb-token': { alias: 'gl-token', @@ -159,8 +159,7 @@ function setupAPIs(setupArgs, apiName, methods) { } // Add default settings -const cli = program - .version('-v, --version') +const cli = Sywac.version('-v, --version') .help('-h, --help') .showHelpByDefault() .epilogue('Copyright 2019') diff --git a/packages/gitbeaker-cli/test/unit/index.ts b/packages/gitbeaker-cli/test/unit/index.ts index be902e87..b9e04001 100644 --- a/packages/gitbeaker-cli/test/unit/index.ts +++ b/packages/gitbeaker-cli/test/unit/index.ts @@ -1,4 +1,4 @@ -import pkg from '../../package.json'; +import * as pkg from '../../package.json'; jest.mock('@gitbeaker/node'); jest.mock('ora', () => ({ diff --git a/packages/gitbeaker-core/scripts/tsconfig.json b/packages/gitbeaker-core/scripts/tsconfig.json index a996a1e8..c45510f7 100644 --- a/packages/gitbeaker-core/scripts/tsconfig.json +++ b/packages/gitbeaker-core/scripts/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "esModuleInterop": true, + // "esModuleInterop": true, + "allowSyntheticDefaultImports": true, "allowJs": true, "target": "es6", "module": "esnext", diff --git a/packages/gitbeaker-core/src/infrastructure/RequestHelper.ts b/packages/gitbeaker-core/src/infrastructure/RequestHelper.ts index d569ee77..23d71881 100644 --- a/packages/gitbeaker-core/src/infrastructure/RequestHelper.ts +++ b/packages/gitbeaker-core/src/infrastructure/RequestHelper.ts @@ -1,4 +1,4 @@ -import Li from 'li'; +import { parse as parseLink } from 'li'; import { camelizeKeys } from 'xcase'; import { BaseService } from './BaseService'; import { appendFormFromObject } from './Utils'; @@ -75,7 +75,7 @@ async function get( // Rescurse through pagination results if (!query.page && underLimit && pagination.next) { - const { next } = Li.parse(headers.link); + const { next } = parseLink(headers.link); const leaf = service.url.split('/').pop() || ''; const regex = new RegExp(`.+/api/v\\d(/${leaf})?/`); const more = (await get(service, next.replace(regex, ''), { diff --git a/packages/gitbeaker-core/src/infrastructure/Utils.ts b/packages/gitbeaker-core/src/infrastructure/Utils.ts index 8029e880..fa6ceed3 100644 --- a/packages/gitbeaker-core/src/infrastructure/Utils.ts +++ b/packages/gitbeaker-core/src/infrastructure/Utils.ts @@ -1,4 +1,4 @@ -import FormData from 'form-data'; +import * as FormData from 'form-data'; /* eslint @typescript-eslint/no-explicit-any: 0 */ interface Constructor { diff --git a/packages/gitbeaker-core/test/unit/infrastructure/RequestHelper.ts b/packages/gitbeaker-core/test/unit/infrastructure/RequestHelper.ts index 9b4796ae..22f087c1 100644 --- a/packages/gitbeaker-core/test/unit/infrastructure/RequestHelper.ts +++ b/packages/gitbeaker-core/test/unit/infrastructure/RequestHelper.ts @@ -1,4 +1,4 @@ -import FormData from 'form-data'; +import * as FormData from 'form-data'; import { RequestHelper, BaseService } from '../../../src/infrastructure'; /* eslint no-empty-pattern: 0 */ diff --git a/packages/gitbeaker-node/src/GotRequester.ts b/packages/gitbeaker-node/src/GotRequester.ts index 5f7457c7..595ab773 100644 --- a/packages/gitbeaker-node/src/GotRequester.ts +++ b/packages/gitbeaker-node/src/GotRequester.ts @@ -1,5 +1,5 @@ import Got from 'got'; -import FormData from 'form-data'; +import * as FormData from 'form-data'; import { decamelizeKeys } from 'xcase'; import { Agent } from 'https'; import { diff --git a/packages/gitbeaker-node/test/unit/GotRequester.ts b/packages/gitbeaker-node/test/unit/GotRequester.ts index 9ec7b1d7..a02ecf01 100644 --- a/packages/gitbeaker-node/test/unit/GotRequester.ts +++ b/packages/gitbeaker-node/test/unit/GotRequester.ts @@ -1,5 +1,5 @@ -import got from 'got'; -import FormData from 'form-data'; +import * as got from 'got'; +import * as FormData from 'form-data'; import { Agent } from 'https'; import { processBody, handler, defaultRequest } from '../../src/GotRequester'; diff --git a/packages/gitbeaker-requester-utils/src/RequesterUtils.ts b/packages/gitbeaker-requester-utils/src/RequesterUtils.ts index 25c2e6cb..2b66c7f2 100644 --- a/packages/gitbeaker-requester-utils/src/RequesterUtils.ts +++ b/packages/gitbeaker-requester-utils/src/RequesterUtils.ts @@ -1,7 +1,7 @@ import { Agent } from 'https'; import { decamelizeKeys } from 'xcase'; import { stringify } from 'query-string'; -import FormDataC from 'form-data'; +import * as FormData from 'form-data'; // Types export interface RequesterType { @@ -41,7 +41,7 @@ export function defaultRequest( if (sudo) headers.sudo = sudo; - if (typeof body === 'object' && !(body instanceof FormDataC)) { + if (typeof body === 'object' && !(body instanceof FormData)) { bod = JSON.stringify(decamelizeKeys(body)); headers['content-type'] = 'application/json'; } else { diff --git a/packages/gitbeaker-requester-utils/test/unit/RequesterUtils.ts b/packages/gitbeaker-requester-utils/test/unit/RequesterUtils.ts index 9718abf9..c847a2a5 100644 --- a/packages/gitbeaker-requester-utils/test/unit/RequesterUtils.ts +++ b/packages/gitbeaker-requester-utils/test/unit/RequesterUtils.ts @@ -1,4 +1,4 @@ -import FormData from 'form-data'; +import * as FormData from 'form-data'; import { createInstance, defaultRequest, modifyServices } from '../../src/RequesterUtils'; const methods = ['get', 'put', 'delete', 'stream', 'post']; diff --git a/tsconfig.json b/tsconfig.json index 3f2f6f64..1f1dbff1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ /* Module Resolution Options */ "moduleResolution": "node", - "esModuleInterop": true, + // "esModuleInterop": true, "resolveJsonModule": true, "baseUrl": ".", "paths": {