From c4e317a2908eb9b23ca0355d783540a6f160b06d Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Tue, 4 Jan 2022 14:50:54 +0000 Subject: [PATCH] Automation: enforce noImplicitAny for the type-checked javascript Change-type: patch --- automation/check-npm-version.js | 6 ++++++ lib/utils/lazy.ts | 3 +-- patches/apply-patches.js | 5 ++++- tsconfig.dev.json | 1 - typings/common-tags/index.d.ts | 22 ++++++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 typings/common-tags/index.d.ts diff --git a/automation/check-npm-version.js b/automation/check-npm-version.js index 13bd5018..59866cdc 100644 --- a/automation/check-npm-version.js +++ b/automation/check-npm-version.js @@ -6,6 +6,8 @@ * * We don't `require('semver')` to allow this script to be run as a npm * 'preinstall' hook, at which point no dependencies have been installed. + * + * @param {string} version */ function parseSemver(version) { const match = /v?(\d+)\.(\d+).(\d+)/.exec(version); @@ -16,6 +18,10 @@ function parseSemver(version) { return [parseInt(major, 10), parseInt(minor, 10), parseInt(patch, 10)]; } +/** + * @param {string} v1 + * @param {string} v2 + */ function semverGte(v1, v2) { let v1Array = parseSemver(v1); let v2Array = parseSemver(v2); diff --git a/lib/utils/lazy.ts b/lib/utils/lazy.ts index d8402a67..be7b510c 100644 --- a/lib/utils/lazy.ts +++ b/lib/utils/lazy.ts @@ -21,7 +21,6 @@ import type { Chalk } from 'chalk'; import type * as visuals from 'resin-cli-visuals'; import type * as CliForm from 'resin-cli-form'; import type { ux } from 'cli-ux'; -import type { stripIndent as StripIndent } from 'common-tags'; // Equivalent of _.once but avoiding the need to import lodash for lazy deps const once = (fn: () => T) => { @@ -63,4 +62,4 @@ export const getCliUx = once(() => require('cli-ux').ux as typeof ux); // Directly export stripIndent as we always use it immediately, but importing just `stripIndent` reduces startup time export const stripIndent = // tslint:disable-next-line:no-var-requires - require('common-tags/lib/stripIndent') as typeof StripIndent; + require('common-tags/lib/stripIndent') as typeof import('common-tags/lib/stripIndent'); diff --git a/patches/apply-patches.js b/patches/apply-patches.js index 74dd04ea..26c1118a 100644 --- a/patches/apply-patches.js +++ b/patches/apply-patches.js @@ -24,7 +24,10 @@ const { promisify } = require('util'); const execFileAsync = promisify(execFile); const patchesDir = 'patches'; -/** Run the patch-package tool in a child process and wait for it to finish */ +/** + * Run the patch-package tool in a child process and wait for it to finish + * @param {string} patchDir + */ async function patchPackage(patchDir) { // Equivalent to: `npx patch-package --patch-dir $patchDir` const result = await execFileAsync('node', [ diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 1862dc6b..3b00a90e 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -2,7 +2,6 @@ "extends": "./tsconfig.json", "compilerOptions": { "allowJs": true, - "noImplicitAny": false, "checkJs": true }, "include": [ diff --git a/typings/common-tags/index.d.ts b/typings/common-tags/index.d.ts new file mode 100644 index 00000000..4299383c --- /dev/null +++ b/typings/common-tags/index.d.ts @@ -0,0 +1,22 @@ +/** + * @license + * Copyright 2022 Balena Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare module 'common-tags/lib/stripIndent' { + import { stripIndent } from 'common-tags'; + + export = stripIndent; +}