Add typing info to requires wherever possible

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-06-30 20:54:35 +01:00
parent 3d0a93692f
commit 5e94f3f9c9
10 changed files with 41 additions and 18 deletions

View File

@ -63,7 +63,8 @@ export async function release() {
/** Return a cached Octokit instance, creating a new one as needed. */
const getOctokit = _.once(function () {
const Octokit = (require('@octokit/rest') as typeof import('@octokit/rest')).Octokit.plugin(
require('@octokit/plugin-throttling'),
(require('@octokit/plugin-throttling') as typeof import('@octokit/plugin-throttling'))
.throttling,
);
return new Octokit({
auth: GITHUB_TOKEN,
@ -109,8 +110,11 @@ function getPageNumbers(
if (!response.headers.link) {
return res;
}
const parse = require('parse-link-header');
const parse = require('parse-link-header') as typeof import('parse-link-header');
const parsed = parse(response.headers.link);
if (parsed == null) {
throw new Error(`Failed to parse link header: '${response.headers.link}'`);
}
let perPage = perPageDefault;
if (parsed.next) {
if (parsed.next.per_page) {

View File

@ -83,7 +83,7 @@ export async function run(args?: string[]) {
// limitation of some library used by NSIS), as the "current working dir"
// provided by balena CI is a rather long path to start with.
if (process.platform === 'win32' && !process.env.BUILD_TMP) {
const randID = require('crypto')
const randID = (await import('crypto'))
.randomBytes(6)
.toString('base64')
.replace(/\+/g, '-')

View File

@ -211,11 +211,10 @@ export function makeUrlFromTunnelNgConfig(cfg: GlobalTunnelNgConfig): string {
function setupBalenaSdkSharedOptions(settings: CliSettings) {
// We don't yet use balena-sdk directly everywhere, but we set up shared
// options correctly so we can do safely in submodules
const BalenaSdk = require('balena-sdk');
const BalenaSdk = require('balena-sdk') as typeof import('balena-sdk');
BalenaSdk.setSharedOptions({
apiUrl: settings.get<string>('apiUrl'),
dataDirectory: settings.get<string>('dataDirectory'),
retries: 2,
});
}
@ -232,7 +231,7 @@ export function configureBluebird() {
return;
}
BluebirdConfigured = true;
const Bluebird = require('bluebird');
const Bluebird = require('bluebird') as typeof import('bluebird');
Bluebird.config({
longStackTraces: process.env.DEBUG ? true : false,
});
@ -263,5 +262,5 @@ export async function globalInit() {
setupBalenaSdkSharedOptions(settings);
// check for CLI updates once a day
require('./utils/update').notify();
(await import('./utils/update')).notify();
}

View File

@ -544,7 +544,7 @@ async function performResolution(
releaseHash: string,
preprocessHook?: (dockerfile: string) => string,
): Promise<MultiBuild.BuildTask[]> {
const { cloneTarStream } = require('tar-utils');
const { cloneTarStream } = await import('tar-utils');
return await new Promise<MultiBuild.BuildTask[]>((resolve, reject) => {
const buildTasks = MultiBuild.performResolution(
@ -796,7 +796,7 @@ export async function deployProject(
apiEndpoint: string,
skipLogUpload: boolean,
): Promise<Partial<import('balena-release/build/models').ReleaseModel>> {
const releaseMod = require('balena-release');
const releaseMod = await import('balena-release');
const { createRelease, tagServiceImages } = await import('./compose');
const tty = (await import('./tty'))(process.stdout);

View File

@ -20,7 +20,7 @@ import * as Bluebird from 'bluebird';
import { spawn, SpawnOptions } from 'child_process';
import * as _ from 'lodash';
import * as os from 'os';
import * as ShellEscape from 'shell-escape';
import type * as ShellEscape from 'shell-escape';
import type { Device, PineOptionsFor } from 'balena-sdk';
import { ExpectedError } from '../errors';

View File

@ -331,7 +331,7 @@ function createRemoteBuildRequest(
builderUrl: string,
onError: (error: Error) => void,
): request.Request {
const zlib = require('zlib');
const zlib = require('zlib') as typeof import('zlib');
if (DEBUG_MODE) {
console.error(`[debug] Connecting to builder at ${builderUrl}`);
}

24
npm-shrinkwrap.json generated
View File

@ -755,12 +755,24 @@
}
},
"@octokit/plugin-throttling": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-2.7.1.tgz",
"integrity": "sha512-08CKNFCpSpmOEAQBn6/MR8zbJgjP4+bplNUJbKlqJSNBHTO1NdsDHzBD4VeFYopOo7rBEySng4WifxNVaQ5bVw==",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.3.0.tgz",
"integrity": "sha512-0hMtpqTAwAvo3XkNoaPQFqX2+csfbuR0bYpruHq3anrBrhQFPt9Gn01RVqqoDla/qBYmIIY2MRirxlaLO21Apg==",
"dev": true,
"requires": {
"@octokit/types": "^5.0.0",
"bottleneck": "^2.15.3"
},
"dependencies": {
"@octokit/types": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.0.1.tgz",
"integrity": "sha512-GorvORVwp244fGKEt3cgt/P+M0MGy4xEDbckw+K5ojEezxyMDgCaYPKVct+/eWQfZXOT7uq0xRpmrl/+hliabA==",
"dev": true,
"requires": {
"@types/node": ">= 8"
}
}
}
},
"@octokit/request": {
@ -1389,6 +1401,12 @@
"integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==",
"dev": true
},
"@types/parse-link-header": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-link-header/-/parse-link-header-1.0.0.tgz",
"integrity": "sha512-fCA3btjE7QFeRLfcD0Sjg+6/CnmC66HpMBoRfRzd2raTaWMJV21CCZ0LO8MOqf8onl5n0EPfjq4zDhbyX8SVwA==",
"dev": true
},
"@types/prettier": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.1.tgz",

View File

@ -106,7 +106,7 @@
"@oclif/config": "^1.14.0",
"@oclif/dev-cli": "1.22.0",
"@oclif/parser": "^3.8.4",
"@octokit/plugin-throttling": "^2.7.1",
"@octokit/plugin-throttling": "^3.3.0",
"@octokit/rest": "^16.43.1",
"@types/archiver": "^2.1.3",
"@types/bluebird": "^3.5.31",
@ -137,6 +137,7 @@
"@types/nock": "^11.0.7",
"@types/node": "^10.17.20",
"@types/node-cleanup": "^2.1.1",
"@types/parse-link-header": "^1.0.0",
"@types/prettyjson": "0.0.29",
"@types/progress-stream": "^2.0.0",
"@types/request": "^2.48.4",

View File

@ -94,7 +94,9 @@ export async function inspectTarStream(
try {
expect($expected).to.deep.equal(found);
} catch (e) {
const { diff } = require('deep-object-diff');
const {
diff,
} = require('deep-object-diff') as typeof import('deep-object-diff');
const diffStr = JSON.stringify(
diff($expected, found),
(_k, v) => (v === undefined ? 'undefined' : v),

View File

@ -15,8 +15,7 @@
* limitations under the License.
*/
// tslint:disable-next-line:no-var-requires
require('./config-tests'); // required for side effects
import './config-tests'; // required for side effects
import { execFile } from 'child_process';
import intercept = require('intercept-stdout');