mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-10 18:25: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 { BUILD_TARGETS, CONFIGS_DIR, ENGINE_DIR } from '../constants'
|
||||||
import { log } from '../log'
|
import { log } from '../log'
|
||||||
import { patchCheck } from '../middleware/patch-check'
|
import { patchCheck } from '../middleware/patch-check'
|
||||||
import { configDispatch, dispatch, stringTemplate } from '../utils'
|
import { configDispatch, stringTemplate } from '../utils'
|
||||||
|
|
||||||
const platform: Record<string, string> = {
|
const platform: Record<string, string> = {
|
||||||
win32: 'windows',
|
win32: 'windows',
|
||||||
|
@ -157,6 +157,6 @@ export const build = async (options: Options): Promise<void> => {
|
||||||
|
|
||||||
log.info('Starting build...')
|
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 { log } from '../log'
|
||||||
import { ENGINE_DIR } from '../constants'
|
import { ENGINE_DIR } from '../constants'
|
||||||
|
|
||||||
interface Options {
|
export const discard = async (file: string): Promise<void> => {
|
||||||
keep?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export const discard = async (
|
|
||||||
file: string,
|
|
||||||
options: Options
|
|
||||||
): Promise<void> => {
|
|
||||||
const realFile = resolve(ENGINE_DIR, file)
|
const realFile = resolve(ENGINE_DIR, file)
|
||||||
|
|
||||||
log.info(`Discarding ${file}...`)
|
log.info(`Discarding ${file}...`)
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {
|
||||||
windowsPathToUnix,
|
windowsPathToUnix,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { downloadFileToLocation } from '../utils/download'
|
import { downloadFileToLocation } from '../utils/download'
|
||||||
import { readItem, writeItem } from '../utils/store'
|
import { readItem } from '../utils/store'
|
||||||
import { discard } from './discard'
|
import { discard } from './discard'
|
||||||
import { init } from './init'
|
import { init } from './init'
|
||||||
import { log } from '../log'
|
import { log } from '../log'
|
||||||
|
@ -49,7 +49,11 @@ export const download = async (): Promise<void> => {
|
||||||
...config.addons[addon],
|
...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',
|
title: 'Downloading firefox source',
|
||||||
|
@ -82,9 +86,9 @@ export const download = async (): Promise<void> => {
|
||||||
.reduce((acc, cur) => [...acc, ...cur], []),
|
.reduce((acc, cur) => [...acc, ...cur], []),
|
||||||
{
|
{
|
||||||
title: 'Add addons to mozbuild',
|
title: 'Add addons to mozbuild',
|
||||||
task: async (ctx, task) => {
|
task: async () => {
|
||||||
// Discard the file to make sure it has no changes
|
// 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')
|
const path = join(ENGINE_DIR, 'browser', 'extensions', 'moz.build')
|
||||||
|
|
||||||
|
@ -109,6 +113,14 @@ export const download = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.firefoxSourceTar) {
|
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(
|
unlinkSync(
|
||||||
resolve(cwd, '.dotbuild', 'engines', ctx.firefoxSourceTar)
|
resolve(cwd, '.dotbuild', 'engines', ctx.firefoxSourceTar)
|
||||||
)
|
)
|
||||||
|
@ -131,7 +143,7 @@ const includeAddon = (
|
||||||
name: string,
|
name: string,
|
||||||
downloadURL: string,
|
downloadURL: string,
|
||||||
id: string
|
id: string
|
||||||
): Listr.ListrTask<any>[] => {
|
): Listr.ListrTask<Record<string, string>>[] => {
|
||||||
const tempFile = join(MELON_TMP_DIR, name + '.xpi')
|
const tempFile = join(MELON_TMP_DIR, name + '.xpi')
|
||||||
const outPath = join(ENGINE_DIR, 'browser', 'extensions', name)
|
const outPath = join(ENGINE_DIR, 'browser', 'extensions', name)
|
||||||
|
|
||||||
|
@ -206,9 +218,13 @@ const includeAddon = (
|
||||||
{
|
{
|
||||||
title: 'Generate mozbuild',
|
title: 'Generate mozbuild',
|
||||||
enabled: (ctx) => typeof ctx[name] !== 'undefined',
|
enabled: (ctx) => typeof ctx[name] !== 'undefined',
|
||||||
task: async (ctx, task) => {
|
task: async () => {
|
||||||
const files = await walkDirectoryTree(outPath)
|
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 {
|
function runTree(tree: any, parent: string): string {
|
||||||
if (Array.isArray(tree)) {
|
if (Array.isArray(tree)) {
|
||||||
return tree
|
return tree
|
||||||
|
@ -276,7 +292,7 @@ ${runTree(files, '')}`
|
||||||
|
|
||||||
async function unpackFirefoxSource(
|
async function unpackFirefoxSource(
|
||||||
name: string,
|
name: string,
|
||||||
task: Listr.ListrTaskWrapper<any>
|
task: Listr.ListrTaskWrapper<never>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let cwd = process.cwd().split(sep).join(posix.sep)
|
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
|
// check for it and ask for the user to install it if necessary
|
||||||
if (!commandExistsSync('gtar')) {
|
if (!commandExistsSync('gtar')) {
|
||||||
throw new Error(
|
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
|
// TODO: Make this function cache its output
|
||||||
async function downloadFirefoxSource(
|
async function downloadFirefoxSource(
|
||||||
version: string,
|
version: string,
|
||||||
task: Listr.ListrTaskWrapper<any>
|
task: Listr.ListrTaskWrapper<never>
|
||||||
) {
|
) {
|
||||||
const base = `https://archive.mozilla.org/pub/firefox/releases/${version}/source/`
|
const base = `https://archive.mozilla.org/pub/firefox/releases/${version}/source/`
|
||||||
const filename = `firefox-${version}.source.tar.xz`
|
const filename = `firefox-${version}.source.tar.xz`
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { log } from '../log'
|
||||||
import { ENGINE_DIR } from '../constants'
|
import { ENGINE_DIR } from '../constants'
|
||||||
import { dispatch } from '../utils'
|
import { dispatch } from '../utils'
|
||||||
|
|
||||||
export const execute = async (_: any, cmd: any[]) => {
|
export const execute = async (cmd: string[]) => {
|
||||||
if (existsSync(ENGINE_DIR)) {
|
if (existsSync(ENGINE_DIR)) {
|
||||||
if (!cmd || cmd.length == 0)
|
if (!cmd || cmd.length == 0)
|
||||||
log.error('You need to specify a command to run.')
|
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 { resolve } from 'path'
|
||||||
import { bin_name } from '..'
|
import { bin_name } from '..'
|
||||||
import { log } from '../log'
|
import { log } from '../log'
|
||||||
import { config, configDispatch, dispatch } from '../utils'
|
import { config, configDispatch } from '../utils'
|
||||||
|
|
||||||
export const init = async (
|
export const init = async (
|
||||||
directory: Command | string,
|
directory: Command | string,
|
||||||
task?: Listr.ListrTaskWrapper<any>
|
task?: Listr.ListrTaskWrapper<unknown>
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
function logInfo(data: string) {
|
function logInfo(data: string) {
|
||||||
if (task) {
|
if (task) {
|
||||||
|
|
|
@ -53,7 +53,10 @@ export async function isValidLicense(path: string): Promise<boolean> {
|
||||||
return hasLicense
|
return hasLicense
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listrCheckFile(path: string, noFix: boolean): ListrTask<any> {
|
export function listrCheckFile(
|
||||||
|
path: string,
|
||||||
|
noFix: boolean
|
||||||
|
): ListrTask<unknown> {
|
||||||
return {
|
return {
|
||||||
skip: () => ignoredFiles.test(path),
|
skip: () => ignoredFiles.test(path),
|
||||||
title: path.replace(SRC_DIR, ''),
|
title: path.replace(SRC_DIR, ''),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
import { existsSync } from 'fs'
|
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 { join, resolve } from 'path'
|
||||||
import { bin_name, config } from '..'
|
import { bin_name, config } from '..'
|
||||||
import { DIST_DIR, ENGINE_DIR, OBJ_DIR } from '../constants'
|
import { DIST_DIR, ENGINE_DIR, OBJ_DIR } from '../constants'
|
||||||
|
|
|
@ -14,12 +14,12 @@ import { patchCountFile } from '../../middleware/patch-check'
|
||||||
import { checkHash } from '../../utils'
|
import { checkHash } from '../../utils'
|
||||||
import { log } from '../../log'
|
import { log } from '../../log'
|
||||||
|
|
||||||
type ListrTaskGroup = Listr.ListrTask<any>
|
type ListrTaskGroup = Listr.ListrTask<unknown>
|
||||||
|
|
||||||
export interface IMelonPatch {
|
export interface IMelonPatch {
|
||||||
name: string
|
name: string
|
||||||
skip?: (
|
skip?: (
|
||||||
ctx: any
|
ctx: unknown
|
||||||
) => string | boolean | void | Promise<string | boolean | undefined>
|
) => string | boolean | void | Promise<string | boolean | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { config, dispatch } from '../utils'
|
||||||
|
|
||||||
export const run = async (chrome?: string) => {
|
export const run = async (chrome?: string) => {
|
||||||
const dirs = readdirSync(ENGINE_DIR)
|
const dirs = readdirSync(ENGINE_DIR)
|
||||||
const objDirname: any = dirs.find((dir) => dir.startsWith('obj-'))
|
const objDirname = dirs.find((dir) => dir.startsWith('obj-'))
|
||||||
|
|
||||||
if (!objDirname) {
|
if (!objDirname) {
|
||||||
throw new Error(`${config.name} needs to be built before you can do this.`)
|
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
|
// If the program is verbose, store that fact within the logger
|
||||||
log.isDebug = program.opts().verbose
|
log.isDebug = program.opts().verbose
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ commands.forEach((command) => {
|
||||||
// executing
|
// executing
|
||||||
const controller = command.requestController()
|
const controller = command.requestController()
|
||||||
|
|
||||||
await middleware(buildCommand, args)
|
await middleware(buildCommand)
|
||||||
|
|
||||||
// Finish loading the controller and execute it
|
// Finish loading the controller and execute it
|
||||||
;(await controller)(...args)
|
;(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
|
* @param args The error you want to throw or a type that you want to convert to an error
|
||||||
*/
|
*/
|
||||||
error(...args: (Error | unknown)[]): never {
|
error(...args: (Error | unknown)[]): never {
|
||||||
if (args[0] instanceof Error) {
|
throw args[0] instanceof Error
|
||||||
throw args[0]
|
? args[0]
|
||||||
}
|
: new Error(
|
||||||
|
|
||||||
throw new Error(
|
|
||||||
...args.map((a) =>
|
...args.map((a) =>
|
||||||
typeof a !== 'undefined' ? (a as object).toString() : 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
|
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
|
* load them to reduce the startup time of gluon, which, at the time of
|
||||||
* writing, is getting a touch long
|
* writing, is getting a touch long
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
requestController: () => Promise<(...args: any) => void>
|
requestController: () => Promise<(...args: any) => void>
|
||||||
|
|
||||||
options?: CmdOption[]
|
options?: CmdOption[]
|
||||||
|
|
|
@ -31,7 +31,7 @@ export async function downloadFileToLocation(
|
||||||
consoleWriter(chunk.toString())
|
consoleWriter(chunk.toString())
|
||||||
next()
|
next()
|
||||||
},
|
},
|
||||||
read: (size) => {
|
read: () => {
|
||||||
/* Empty output */
|
/* Empty output */
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -55,12 +55,10 @@ export async function walkDirectory(dirName: string): Promise<string[]> {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TreeType<T> = Record<string, T | string[]>
|
export type TreeType = { [property: string]: string[] | TreeType }
|
||||||
|
|
||||||
export async function walkDirectoryTree(
|
export async function walkDirectoryTree(dirName: string): Promise<TreeType> {
|
||||||
dirName: string
|
const output: TreeType = {}
|
||||||
): Promise<TreeType<TreeType<TreeType<TreeType<TreeType<TreeType<any>>>>>>> {
|
|
||||||
const output: TreeType<any> = {}
|
|
||||||
|
|
||||||
if (!isAbsolute(dirName)) {
|
if (!isAbsolute(dirName)) {
|
||||||
log.askForReport()
|
log.askForReport()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue