Skip to content

Integrated aegir as lint #2960

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
2,914 changes: 1,922 additions & 992 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkgs/macos/build-universal-kubo-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const execLog = (cmd) => {
await downloadKubo({
version: kuboVersion,
platform: 'darwin',
arch: arch,
arch,
distUrl: 'https://dist.ipfs.tech',
installPath: archDir
})
Expand Down
10 changes: 5 additions & 5 deletions src/add-to-ipfs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { extname, basename } = require('path')
const { clipboard } = require('electron')
const { globSource } = require('ipfs-http-client')
const fs = require('fs-extra')
const i18n = require('i18next')
const { globSource } = require('ipfs-http-client')
const last = require('it-last')
const fs = require('fs-extra')
const { analyticsKeys } = require('./analytics/keys')
const logger = require('./common/logger')
const { notify, notifyError } = require('./common/notify')
const { analyticsKeys } = require('./analytics/keys')
const getCtx = require('./context')

async function copyFileToMfs (ipfs, cid, filename) {
Expand Down Expand Up @@ -90,7 +90,7 @@ async function addFileOrDirectory (ipfs, filepath) {
let cid = null

if (stat.isDirectory()) {
const files = globSource(filepath, '**/*', { recursive: true, cidVersion: 1 })
const files = globSource(filepath, '**/*')
const res = await last(ipfs.addAll(files, {
pin: false,
wrapWithDirectory: true,
Expand Down Expand Up @@ -129,7 +129,7 @@ module.exports = async function (files) {
const res = await addFileOrDirectory(ipfsd.api, file)
successes.push(res)
} catch (e) {
failures.push(e.toString())
failures.push(String(e))
}
}))

Expand Down
7 changes: 3 additions & 4 deletions src/analytics/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @ts-check
const { existsSync, mkdirSync } = require('fs')
const { join } = require('path')
const Countly = require('countly-sdk-nodejs')
const { ipcMain } = require('electron')
const { COUNTLY_KEY } = require('../common/consts')
const { join } = require('path')
const { app } = require('electron')
const { existsSync, mkdirSync } = require('fs')
const { COUNTLY_KEY } = require('../common/consts')
const ipcMainEvents = require('../common/ipc-main-events')
const logger = require('../common/logger')
const getCtx = require('../context')
Expand Down
3 changes: 1 addition & 2 deletions src/analytics/keys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check

/**
* This should be an enum once we migrate to typescript
*
* @readonly
* @type {import('countly-sdk-nodejs').AnalyticsKeys}
*/
Expand Down
2 changes: 2 additions & 0 deletions src/app-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if (process.platform === 'darwin') {

// Edit menu
template[1].submenu.push(
// @ts-ignore
{ type: 'separator' },
{
label: 'Speech',
Expand All @@ -90,6 +91,7 @@ if (process.platform === 'darwin') {

module.exports = function () {
logger.info('[appMenu] init...')
// @ts-ignore
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
logger.info('[appMenu] init done...')
Expand Down
16 changes: 8 additions & 8 deletions src/auto-launch.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @ts-check
const { app } = require('electron')
const i18n = require('i18next')
const os = require('os')
const path = require('path')
const { app } = require('electron')
const fs = require('fs-extra')
const i18n = require('i18next')
const untildify = require('untildify')
const createToggler = require('./utils/create-toggler')
const { AUTO_LAUNCH: CONFIG_KEY } = require('./common/config-keys')
const { IS_MAC, IS_WIN } = require('./common/consts')
const logger = require('./common/logger')
const store = require('./common/store')
const { IS_MAC, IS_WIN } = require('./common/consts')
const { AUTO_LAUNCH: CONFIG_KEY } = require('./common/config-keys')
const { showDialog, recoverableErrorDialog } = require('./dialogs')
const createToggler = require('./utils/create-toggler')

function isSupported () {
const plat = os.platform()
Expand Down Expand Up @@ -79,7 +78,7 @@ module.exports = async function () {
return false
}

if (newValue === oldValue) return
if (newValue === oldValue) { return }

try {
if (newValue === true) {
Expand All @@ -92,7 +91,7 @@ module.exports = async function () {

return true
} catch (err) {
logger.error(`[launch on startup] ${err.toString()}`)
logger.error(`[launch on startup] ${String(err)}`)

if (feedback) {
recoverableErrorDialog(err, {
Expand All @@ -105,6 +104,7 @@ module.exports = async function () {
}
}

// @ts-ignore
activate({ newValue: store.get(CONFIG_KEY, false) })
createToggler(CONFIG_KEY, activate)
}
Expand Down
12 changes: 6 additions & 6 deletions src/auto-updater/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { shell, app, BrowserWindow, Notification } = require('electron')
const { ipcMain } = require('electron')
const { autoUpdater } = require('electron-updater')
const i18n = require('i18next')
const { ipcMain } = require('electron')
const logger = require('../common/logger')
const { showDialog } = require('../dialogs')
const CONFIG_KEYS = require('../common/config-keys')
const { IS_MAC, IS_WIN, IS_APPIMAGE } = require('../common/consts')
const ipcMainEvents = require('../common/ipc-main-events')
const getCtx = require('../context')
const logger = require('../common/logger')
const store = require('../common/store')
const CONFIG_KEYS = require('../common/config-keys')
const getCtx = require('../context')
const { showDialog } = require('../dialogs')

function isAutoUpdateSupported () {
if (store.get(CONFIG_KEYS.DISABLE_AUTO_UPDATE, false)) {
Expand Down Expand Up @@ -54,7 +54,7 @@ function setup () {
try {
await autoUpdater.downloadUpdate()
} catch (err) {
logger.error(`[updater] ${err.toString()}`)
logger.error(`[updater] ${String(err)}`)
}

if (!feedback) {
Expand Down
13 changes: 7 additions & 6 deletions src/automatic-gc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const createToggler = require('./utils/create-toggler')
const logger = require('./common/logger')
const store = require('./common/store')
const { AUTO_GARBAGE_COLLECTOR: CONFIG_KEY } = require('./common/config-keys')
const { ipcMain } = require('electron')
const { AUTO_GARBAGE_COLLECTOR: CONFIG_KEY } = require('./common/config-keys')
const ipcMainEvents = require('./common/ipc-main-events')
const logger = require('./common/logger')
const store = require('./common/store')
const createToggler = require('./utils/create-toggler')

const gcFlag = '--enable-gc'
const isEnabled = flags => flags.some(f => f === gcFlag)
Expand Down Expand Up @@ -36,7 +36,7 @@ function applyConfig (newFlags) {

module.exports = async function () {
const activate = ({ newValue, oldValue }) => {
if (newValue === oldValue) return
if (newValue === oldValue) { return }

try {
if (newValue === true) {
Expand All @@ -47,11 +47,12 @@ module.exports = async function () {

return true
} catch (err) {
logger.error(`[automatic gc] ${err.toString()}`)
logger.error(`[automatic gc] ${String(err)}`)

return false
}
}
// @ts-ignore
activate({ newValue: store.get(CONFIG_KEY, true) })
createToggler(CONFIG_KEY, activate)
logger.info(`[automatic gc] ${store.get(CONFIG_KEY, true) ? 'enabled' : 'disabled'}`)
Expand Down
4 changes: 3 additions & 1 deletion src/common/config-keys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Configuration key constants for the features in IPFS Desktop.
*
* @constant
* @type {Record<import('../types').CONFIG_KEYS, string>}
*/
Expand All @@ -11,7 +12,8 @@ const CONFIG_KEYS = {
OPEN_WEBUI_LAUNCH: 'openWebUIAtLaunch',
MONOCHROME_TRAY_ICON: 'monochromeTrayIcon',
EXPERIMENT_PUBSUB: 'experiments.pubsub',
EXPERIMENT_PUBSUB_NAMESYS: 'experiments.pubsubNamesys'
EXPERIMENT_PUBSUB_NAMESYS: 'experiments.pubsubNamesys',
AUTO_UPDATE: ''
}

module.exports = CONFIG_KEYS
9 changes: 4 additions & 5 deletions src/common/logger.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// @ts-check
const { createLogger, format, transports } = require('winston')
const { join } = require('path')
const { app } = require('electron')
const { performance } = require('perf_hooks')
const Countly = require('countly-sdk-nodejs')
const { app } = require('electron')
const { createLogger, format, transports } = require('winston')
const { analyticsKeys } = require('../analytics/keys')

/**
Expand Down Expand Up @@ -138,11 +137,11 @@ module.exports = Object.freeze({
}
},

warn: (msg, meta) => {
warn: (/** @type {string} */ msg, /** @type {import("winston").LogCallback} */ meta) => {
logger.warn(msg, meta)
},

debug: (msg) => {
debug: (/** @type {any} */ msg) => {
logger.debug(msg)
},

Expand Down
1 change: 0 additions & 1 deletion src/common/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { app } = require('electron')
const Store = require('electron-store')

const logger = require('./logger')

const { fileLogger } = logger
Expand Down
8 changes: 4 additions & 4 deletions src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface DesktopPersistentStore_IpfsdConfig {
path: string,
path: string
flags: string[]
}

export interface DesktopPersistentStore {

ipfsConfig: DesktopPersistentStore_IpfsdConfig,
language: string,
experiments: Record<string, boolean>,
ipfsConfig: DesktopPersistentStore_IpfsdConfig
language: string
experiments: Record<string, boolean>
binaryPath?: string
}
17 changes: 10 additions & 7 deletions src/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
const pDefer = require('p-defer')
const logger = require('./common/logger')

Expand All @@ -11,9 +10,9 @@ const logger = require('./common/logger')
* can set a property on the context and other modules can get that property from the context when they need it.
*
* Benefits:
* * Avoid passing the same object to many different modules.
* * Avoid circular dependencies and makes it easier to test modules in isolation.
* * Speed up startup time by only loading what we need when we need it.
* Avoid passing the same object to many different modules.
* Avoid circular dependencies and makes it easier to test modules in isolation.
* Speed up startup time by only loading what we need when we need it.
*
*
* | Context property exists? | Is the backing promise fulfilled? | Method called | Is a deferred promise created? | Returned Value |
Expand All @@ -26,18 +25,20 @@ const logger = require('./common/logger')
* | Yes | Yes | SetProp | No | We throw an error here. Any getProps called for the property prior to this would have a hanging promise. |
*
* @extends {Record<string, unknown>}
* @property {function} launchWebUI
* @property {Function} launchWebUI
*/
class Context {
constructor () {
/**
* Stores prop->value mappings.
*
* @type {Map<string|symbol, unknown>}
*/
this._properties = new Map()

/**
* Stores prop->Promise mappings.
*
* @type {Map<string|symbol, pDefer.DeferredPromise<unknown>>}
*/
this._promiseMap = new Map()
Expand All @@ -63,12 +64,13 @@ class Context {
this._properties.set(propertyName, value)
this._resolvePropToValue(propertyName, value)
} catch (e) {
logger.error(e)
logger.error(String(e))
}
}

/**
* Get the value of a property wrapped in a promise.
*
* @template T
* @param {ContextProperties} propertyName
* @returns {Promise<T>}
Expand All @@ -93,6 +95,7 @@ class Context {
* A simple helper to improve DX and UX when calling functions.
*
* This function allows you to request a function from AppContext without blocking until you actually need to call it.
*
* @param {ContextProperties} propertyName
* @returns {(...args: unknown[]) => Promise<unknown>}
*/
Expand All @@ -105,7 +108,7 @@ class Context {
return await originalFn(...args)
} catch (err) {
logger.error(`[ctx] Error calling ${String(propertyName)}`)
logger.error(err)
logger.error(String(err))
throw err
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/custom-ipfs-binary.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const i18n = require('i18next')
const { app, dialog } = require('electron')
const { showDialog } = require('./dialogs')
const i18n = require('i18next')
const logger = require('./common/logger')
const store = require('./common/store')
const dock = require('./utils/dock')
const getCtx = require('./context')
const { showDialog } = require('./dialogs')
const dock = require('./utils/dock')

const SETTINGS_KEY = 'binaryPath'

Expand Down
Loading