mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-10 02:05:31 +02:00
♻️ Fix eslint warnings
This commit is contained in:
parent
6d5b48c37f
commit
f90dd9c30c
15 changed files with 67 additions and 45 deletions
|
@ -8,7 +8,7 @@ import { bin_name, config } from '..'
|
|||
import { BUILD_TARGETS, CONFIGS_DIR, ENGINE_DIR } from '../constants'
|
||||
import { log } from '../log'
|
||||
import { patchCheck } from '../middleware/patch-check'
|
||||
import { configDispatch, dispatch, stringTemplate } from '../utils'
|
||||
import { configDispatch, stringTemplate } from '../utils'
|
||||
|
||||
const platform: Record<string, string> = {
|
||||
win32: 'windows',
|
||||
|
@ -157,6 +157,6 @@ export const build = async (options: Options): Promise<void> => {
|
|||
|
||||
log.info('Starting build...')
|
||||
|
||||
await genericBuild(prettyHost, options.ui).then((_) => success(d))
|
||||
await genericBuild(prettyHost, options.ui).then(() => success(d))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,7 @@ import { resolve } from 'path'
|
|||
import { log } from '../log'
|
||||
import { ENGINE_DIR } from '../constants'
|
||||
|
||||
interface Options {
|
||||
keep?: boolean
|
||||
}
|
||||
|
||||
export const discard = async (
|
||||
file: string,
|
||||
options: Options
|
||||
): Promise<void> => {
|
||||
export const discard = async (file: string): Promise<void> => {
|
||||
const realFile = resolve(ENGINE_DIR, file)
|
||||
|
||||
log.info(`Discarding ${file}...`)
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
windowsPathToUnix,
|
||||
} from '../utils'
|
||||
import { downloadFileToLocation } from '../utils/download'
|
||||
import { readItem, writeItem } from '../utils/store'
|
||||
import { readItem } from '../utils/store'
|
||||
import { discard } from './discard'
|
||||
import { init } from './init'
|
||||
import { log } from '../log'
|
||||
|
@ -49,7 +49,11 @@ export const download = async (): Promise<void> => {
|
|||
...config.addons[addon],
|
||||
}))
|
||||
|
||||
await new Listr(
|
||||
// Listr and typescript do not mix. Just specify any and move on with the
|
||||
// rest of our life
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await new Listr<Record<string, string | any>>(
|
||||
[
|
||||
{
|
||||
title: 'Downloading firefox source',
|
||||
|
@ -82,9 +86,9 @@ export const download = async (): Promise<void> => {
|
|||
.reduce((acc, cur) => [...acc, ...cur], []),
|
||||
{
|
||||
title: 'Add addons to mozbuild',
|
||||
task: async (ctx, task) => {
|
||||
task: async () => {
|
||||
// Discard the file to make sure it has no changes
|
||||
await discard('browser/extensions/moz.build', {})
|
||||
await discard('browser/extensions/moz.build')
|
||||
|
||||
const path = join(ENGINE_DIR, 'browser', 'extensions', 'moz.build')
|
||||
|
||||
|
@ -109,6 +113,14 @@ export const download = async (): Promise<void> => {
|
|||
}
|
||||
|
||||
if (ctx.firefoxSourceTar) {
|
||||
if (typeof ctx.firefoxSourceTar !== 'string') {
|
||||
log.askForReport()
|
||||
log.error(
|
||||
`The type ctx.firefoxSourceTar was ${typeof ctx.firefoxSourceTar} when it should have been a string`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
unlinkSync(
|
||||
resolve(cwd, '.dotbuild', 'engines', ctx.firefoxSourceTar)
|
||||
)
|
||||
|
@ -131,7 +143,7 @@ const includeAddon = (
|
|||
name: string,
|
||||
downloadURL: string,
|
||||
id: string
|
||||
): Listr.ListrTask<any>[] => {
|
||||
): Listr.ListrTask<Record<string, string>>[] => {
|
||||
const tempFile = join(MELON_TMP_DIR, name + '.xpi')
|
||||
const outPath = join(ENGINE_DIR, 'browser', 'extensions', name)
|
||||
|
||||
|
@ -206,9 +218,13 @@ const includeAddon = (
|
|||
{
|
||||
title: 'Generate mozbuild',
|
||||
enabled: (ctx) => typeof ctx[name] !== 'undefined',
|
||||
task: async (ctx, task) => {
|
||||
task: async () => {
|
||||
const files = await walkDirectoryTree(outPath)
|
||||
|
||||
// Because the tree has the potential of being infinitely recursive, we
|
||||
// cannot possibly know the the type of the tree
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function runTree(tree: any, parent: string): string {
|
||||
if (Array.isArray(tree)) {
|
||||
return tree
|
||||
|
@ -276,7 +292,7 @@ ${runTree(files, '')}`
|
|||
|
||||
async function unpackFirefoxSource(
|
||||
name: string,
|
||||
task: Listr.ListrTaskWrapper<any>
|
||||
task: Listr.ListrTaskWrapper<never>
|
||||
): Promise<void> {
|
||||
let cwd = process.cwd().split(sep).join(posix.sep)
|
||||
|
||||
|
@ -302,7 +318,7 @@ async function unpackFirefoxSource(
|
|||
// check for it and ask for the user to install it if necessary
|
||||
if (!commandExistsSync('gtar')) {
|
||||
throw new Error(
|
||||
`GNU Tar is required to extract Firefox\'s source on MacOS. Please install it using the command |brew install gnu-tar| and try again`
|
||||
`GNU Tar is required to extract Firefox's source on MacOS. Please install it using the command |brew install gnu-tar| and try again`
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -329,7 +345,7 @@ async function unpackFirefoxSource(
|
|||
// TODO: Make this function cache its output
|
||||
async function downloadFirefoxSource(
|
||||
version: string,
|
||||
task: Listr.ListrTaskWrapper<any>
|
||||
task: Listr.ListrTaskWrapper<never>
|
||||
) {
|
||||
const base = `https://archive.mozilla.org/pub/firefox/releases/${version}/source/`
|
||||
const filename = `firefox-${version}.source.tar.xz`
|
||||
|
|
|
@ -6,7 +6,7 @@ import { log } from '../log'
|
|||
import { ENGINE_DIR } from '../constants'
|
||||
import { dispatch } from '../utils'
|
||||
|
||||
export const execute = async (_: any, cmd: any[]) => {
|
||||
export const execute = async (cmd: string[]) => {
|
||||
if (existsSync(ENGINE_DIR)) {
|
||||
if (!cmd || cmd.length == 0)
|
||||
log.error('You need to specify a command to run.')
|
||||
|
|
13
src/commands/export-file.test.ts
Normal file
13
src/commands/export-file.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { getPatchName } from './export-file'
|
||||
|
||||
describe('getPatchName', () => {
|
||||
it('works on root files', () => {
|
||||
const name = getPatchName('foo.js')
|
||||
expect(name).toBe('foo-js.patch')
|
||||
})
|
||||
|
||||
it('works on embedded files', () => {
|
||||
const name = getPatchName('foo/bar.js')
|
||||
expect(name).toBe('bar-js.patch')
|
||||
})
|
||||
})
|
|
@ -7,11 +7,11 @@ import Listr from 'listr'
|
|||
import { resolve } from 'path'
|
||||
import { bin_name } from '..'
|
||||
import { log } from '../log'
|
||||
import { config, configDispatch, dispatch } from '../utils'
|
||||
import { config, configDispatch } from '../utils'
|
||||
|
||||
export const init = async (
|
||||
directory: Command | string,
|
||||
task?: Listr.ListrTaskWrapper<any>
|
||||
task?: Listr.ListrTaskWrapper<unknown>
|
||||
): Promise<void> => {
|
||||
function logInfo(data: string) {
|
||||
if (task) {
|
||||
|
|
|
@ -53,7 +53,10 @@ export async function isValidLicense(path: string): Promise<boolean> {
|
|||
return hasLicense
|
||||
}
|
||||
|
||||
export function listrCheckFile(path: string, noFix: boolean): ListrTask<any> {
|
||||
export function listrCheckFile(
|
||||
path: string,
|
||||
noFix: boolean
|
||||
): ListrTask<unknown> {
|
||||
return {
|
||||
skip: () => ignoredFiles.test(path),
|
||||
title: path.replace(SRC_DIR, ''),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
import { existsSync } from 'fs'
|
||||
import { copyFile, mkdir, readdir, rmdir, stat, unlink } from 'fs/promises'
|
||||
import { copyFile, mkdir, readdir, unlink } from 'fs/promises'
|
||||
import { join, resolve } from 'path'
|
||||
import { bin_name, config } from '..'
|
||||
import { DIST_DIR, ENGINE_DIR, OBJ_DIR } from '../constants'
|
||||
|
|
|
@ -14,12 +14,12 @@ import { patchCountFile } from '../../middleware/patch-check'
|
|||
import { checkHash } from '../../utils'
|
||||
import { log } from '../../log'
|
||||
|
||||
type ListrTaskGroup = Listr.ListrTask<any>
|
||||
type ListrTaskGroup = Listr.ListrTask<unknown>
|
||||
|
||||
export interface IMelonPatch {
|
||||
name: string
|
||||
skip?: (
|
||||
ctx: any
|
||||
ctx: unknown
|
||||
) => string | boolean | void | Promise<string | boolean | undefined>
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { config, dispatch } from '../utils'
|
|||
|
||||
export const run = async (chrome?: string) => {
|
||||
const dirs = readdirSync(ENGINE_DIR)
|
||||
const objDirname: any = dirs.find((dir) => dir.startsWith('obj-'))
|
||||
const objDirname = dirs.find((dir) => dir.startsWith('obj-'))
|
||||
|
||||
if (!objDirname) {
|
||||
throw new Error(`${config.name} needs to be built before you can do this.`)
|
||||
|
|
|
@ -57,7 +57,7 @@ program
|
|||
])
|
||||
)
|
||||
|
||||
async function middleware(command: commander.Command, args: unknown[]) {
|
||||
async function middleware(command: commander.Command) {
|
||||
// If the program is verbose, store that fact within the logger
|
||||
log.isDebug = program.opts().verbose
|
||||
|
||||
|
@ -84,7 +84,7 @@ commands.forEach((command) => {
|
|||
// executing
|
||||
const controller = command.requestController()
|
||||
|
||||
await middleware(buildCommand, args)
|
||||
await middleware(buildCommand)
|
||||
|
||||
// Finish loading the controller and execute it
|
||||
;(await controller)(...args)
|
||||
|
|
|
@ -96,11 +96,9 @@ class Log {
|
|||
* @param args The error you want to throw or a type that you want to convert to an error
|
||||
*/
|
||||
error(...args: (Error | unknown)[]): never {
|
||||
if (args[0] instanceof Error) {
|
||||
throw args[0]
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
throw args[0] instanceof Error
|
||||
? args[0]
|
||||
: new Error(
|
||||
...args.map((a) =>
|
||||
typeof a !== 'undefined' ? (a as object).toString() : a
|
||||
)
|
||||
|
|
3
src/types.d.ts
vendored
3
src/types.d.ts
vendored
|
@ -6,10 +6,11 @@ export interface Cmd {
|
|||
description: string
|
||||
|
||||
/**
|
||||
* A function that returns the controller as a promise. We want to dynamicly
|
||||
* A function that returns the controller as a promise. We want to dynamically
|
||||
* load them to reduce the startup time of gluon, which, at the time of
|
||||
* writing, is getting a touch long
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
requestController: () => Promise<(...args: any) => void>
|
||||
|
||||
options?: CmdOption[]
|
||||
|
|
|
@ -31,7 +31,7 @@ export async function downloadFileToLocation(
|
|||
consoleWriter(chunk.toString())
|
||||
next()
|
||||
},
|
||||
read: (size) => {
|
||||
read: () => {
|
||||
/* Empty output */
|
||||
},
|
||||
})
|
||||
|
|
|
@ -55,12 +55,10 @@ export async function walkDirectory(dirName: string): Promise<string[]> {
|
|||
return output
|
||||
}
|
||||
|
||||
export type TreeType<T> = Record<string, T | string[]>
|
||||
export type TreeType = { [property: string]: string[] | TreeType }
|
||||
|
||||
export async function walkDirectoryTree(
|
||||
dirName: string
|
||||
): Promise<TreeType<TreeType<TreeType<TreeType<TreeType<TreeType<any>>>>>>> {
|
||||
const output: TreeType<any> = {}
|
||||
export async function walkDirectoryTree(dirName: string): Promise<TreeType> {
|
||||
const output: TreeType = {}
|
||||
|
||||
if (!isAbsolute(dirName)) {
|
||||
log.askForReport()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue