Skip to content

fix(deps): remove or type last remaining untyped deps #7211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions eslint_temporary_suppressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,19 +1056,6 @@ export default [
'@typescript-eslint/prefer-nullish-coalescing': 'off',
},
},
{
files: ['src/utils/shell.ts'],
rules: {
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'n/no-process-exit': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
{
files: ['src/utils/sign-redirect.ts'],
rules: {
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
"readdirp": "4.1.2",
"semver": "7.7.1",
"source-map-support": "0.5.21",
"strip-ansi-control-characters": "2.0.0",
"tempy": "3.1.0",
"terminal-link": "4.0.0",
"toml": "3.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/lib/functions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { IncomingHttpHeaders } from 'http'
import path from 'path'

import express, { type Request, type RequestHandler } from 'express'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'expr... Remove this comment to see the full error message
import expressLogging from 'express-logging'
import { jwtDecode } from 'jwt-decode'

Expand Down
8 changes: 1 addition & 7 deletions src/utils/copy-template-dir/copy-template-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ import path from 'path'
import { pipeline } from 'stream'
import { promisify } from 'util'

// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'maxstache... Remove this comment to see the full error message
import maxstache from 'maxstache'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'maxstache-stream... Remove this comment to see the full error message
import maxstacheStream from 'maxstache-stream'
import { readdirp, EntryInfo, ReaddirpStream } from 'readdirp'

const noop = (): void => undefined

// Remove a leading underscore
function removeUnderscore(filepath: string): string {
const parts = filepath.split(path.sep)
Expand All @@ -56,9 +52,7 @@ async function writeFile(outDir: string, vars: Record<string, string>, file: Ent
}

// High throughput template dir writes
export async function copyTemplateDir(srcDir: string, outDir: string, vars: any): Promise<string[]> {
if (!vars) vars = noop
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's only one caller and it always passes this in


export async function copyTemplateDir(srcDir: string, outDir: string, vars: Record<string, string>): Promise<string[]> {
assert.strictEqual(typeof srcDir, 'string')
assert.strictEqual(typeof outDir, 'string')
assert.strictEqual(typeof vars, 'object')
Expand Down
65 changes: 33 additions & 32 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import process from 'process'
import { Transform } from 'stream'
import { stripVTControlCharacters } from 'util'

import execa from 'execa'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'stri... Remove this comment to see the full error message
import stripAnsiCc from 'strip-ansi-control-characters'

import { stopSpinner, type Spinner } from '../lib/spinner.js'

import { chalk, log, NETLIFYDEVERR, NETLIFYDEVWARN } from './command-helpers.js'
import { processOnExit } from './dev.js'

/**
* @type {(() => Promise<void>)[]} - array of functions to run before the process exits
*/
// @ts-expect-error TS(7034) FIXME: Variable 'cleanupWork' implicitly has type 'any[]'... Remove this comment to see the full error message
const cleanupWork = []
const isErrnoException = (value: unknown): value is NodeJS.ErrnoException =>
value instanceof Error && Object.hasOwn(value, 'code')

const createStripAnsiControlCharsStream = (): Transform =>
new Transform({
transform(chunk, _encoding, callback) {
callback(null, stripVTControlCharacters(typeof chunk === 'string' ? chunk : (chunk as unknown)?.toString() ?? ''))
},
})

const cleanupWork: (() => Promise<void>)[] = []

let cleanupStarted = false

/**
* @param {object} input
* @param {number=} input.exitCode The exit code to return when exiting the process after cleanup
*/
const cleanupBeforeExit = async ({ exitCode }: { exitCode?: number | undefined } = {}) => {
// If cleanup has started, then wherever started it will be responsible for exiting
if (!cleanupStarted) {
cleanupStarted = true
try {
// @ts-expect-error TS(7005) FIXME: Variable 'cleanupWork' implicitly has an 'any[]' t... Remove this comment to see the full error message
await Promise.all(cleanupWork.map((cleanup) => cleanup()))
} finally {
// eslint-disable-next-line n/no-process-exit
process.exit(exitCode)
}
}
Expand Down Expand Up @@ -63,7 +66,7 @@ export const runCommand = (
// In this case, we want to manually control when to clear and when to render a frame, so we turn this off.
stopSpinner({ error: false, spinner })
}
const pipeDataWithSpinner = (writeStream: NodeJS.WriteStream, chunk: any) => {
const pipeDataWithSpinner = (writeStream: NodeJS.WriteStream, chunk: string | Uint8Array) => {
if (spinner?.isSpinning) {
spinner.clear()
}
Expand All @@ -72,15 +75,19 @@ export const runCommand = (
})
}

// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
commandProcess.stdout.pipe(stripAnsiCc.stream()).on('data', pipeDataWithSpinner.bind(null, process.stdout))
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
commandProcess.stderr.pipe(stripAnsiCc.stream()).on('data', pipeDataWithSpinner.bind(null, process.stderr))
// @ts-expect-error TS(2345) FIXME: Argument of type 'Writable | null' is not assignab... Remove this comment to see the full error message
process.stdin.pipe(commandProcess.stdin)
commandProcess.stdout
?.pipe(createStripAnsiControlCharsStream())
.on('data', pipeDataWithSpinner.bind(null, process.stdout))
commandProcess.stderr
?.pipe(createStripAnsiControlCharsStream())
.on('data', pipeDataWithSpinner.bind(null, process.stderr))
if (commandProcess.stdin != null) {
process.stdin.pipe(commandProcess.stdin)
}

// we can't try->await->catch since we don't want to block on the framework server which
// is a long running process
// eslint-disable-next-line @typescript-eslint/no-floating-promises
commandProcess.then(async () => {
const result = await commandProcess
const [commandWithoutArgs] = command.split(' ')
Expand All @@ -92,9 +99,10 @@ export const runCommand = (
)
} else {
const errorMessage = result.failed
? // @ts-expect-error TS(2339) FIXME: Property 'shortMessage' does not exist on type 'Ex... Remove this comment to see the full error message
`${NETLIFYDEVERR} ${result.shortMessage}`
: `${NETLIFYDEVWARN} "${command}" exited with code ${result.exitCode}`
? // @ts-expect-error FIXME(serhalp): We use `reject: false` which means the resolved value is either the resolved value
// or the rejected value, but the types aren't smart enough to know this.
`${NETLIFYDEVERR} ${result.shortMessage as string}`
: `${NETLIFYDEVWARN} "${command}" exited with code ${result.exitCode.toString()}`

log(`${errorMessage}. Shutting down Netlify Dev server`)
}
Expand All @@ -108,18 +116,10 @@ export const runCommand = (
return commandProcess
}

/**
*
* @param {object} config
* @param {string} config.command
* @param {*} config.error
* @returns
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message
const isNonExistingCommandError = ({ command, error: commandError }) => {
const isNonExistingCommandError = ({ command, error: commandError }: { command: string; error: unknown }) => {
// `ENOENT` is only returned for non Windows systems
// See https://github.com/sindresorhus/execa/pull/447
if (commandError.code === 'ENOENT') {
if (isErrnoException(commandError) && commandError.code === 'ENOENT') {
return true
}

Expand All @@ -130,6 +130,7 @@ const isNonExistingCommandError = ({ command, error: commandError }) => {

// this only works on English versions of Windows
return (
commandError instanceof Error &&
typeof commandError.message === 'string' &&
commandError.message.includes('is not recognized as an internal or external command')
)
Expand Down
17 changes: 17 additions & 0 deletions types/express-logging/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
declare module 'express-logging' {
import { RequestHandler } from 'express';

interface LoggerOptions {blacklist?: string[]}

interface Logger {
info(...args: unknown[]): void;
error(...args: unknown[]): void;
warn(...args: unknown[]): void;
debug?(...args: unknown[]): void;
log(...args: unknown[]): void;
}

function expressLogging(logger?: Logger, options?: LoggerOptions): RequestHandler;

export default expressLogging;
}
7 changes: 7 additions & 0 deletions types/maxstache-stream/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'maxstache-stream' {
import { Transform } from 'stream';

function maxstacheStream(vars: Record<string, string>): Transform;

export default maxstacheStream;
}
5 changes: 5 additions & 0 deletions types/maxstache/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'maxstache' {
function maxstache(str: string, ctx: Record<string, string>): string;

export default maxstache;
}
Loading