Skip to content

Commit

Permalink
chore(deps-dev): upgrade to ESLint 6 and friends (#1104)
Browse files Browse the repository at this point in the history
* chore(deps-dev): upgrade to ESLint 6 compatible packages
* chore: autofix a bunch of eslint warnings
* chore: fix lint/build warnings
* chore: switch from eslint-config-airbnb to eslint-config-airbnb-base
* chore: fix some async lint warnings
* chore(deps-dev): upgrade eslint and eslint-plugin-mocha
* refactor(plugin-webpack): fix the rest of the lint warnings
* chore(core): fix test
* test(core): fix forge-config tests
* chore(core): remove eslint ignore line
  • Loading branch information
malept committed Aug 26, 2019
1 parent a2d04f4 commit ef0b663
Show file tree
Hide file tree
Showing 46 changed files with 330 additions and 413 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -13,7 +13,7 @@
"node": true
},
"extends": [
"airbnb"
"airbnb-base"
],
"rules": {
"class-methods-use-this": "off",
Expand Down
10 changes: 4 additions & 6 deletions package.json
Expand Up @@ -120,8 +120,8 @@
"@types/webpack-dev-middleware": "^2.0.3",
"@types/webpack-hot-middleware": "^2.16.3",
"@types/webpack-merge": "^4.1.5",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"asar": "^2.0.1",
"babel-plugin-source-map-support": "^2.1.1",
"chai": "4.2.0",
Expand All @@ -130,12 +130,10 @@
"coveralls": "^3.0.4",
"cross-env": "^5.0.0",
"cz-customizable": "^6.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.1",
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-mocha": "^6.1.0",
"eslint-plugin-react": "^7.14.2",
"fetch-mock": "^7.3.9",
"generate-changelog": "^1.8.0",
"listr": "^0.14.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-install.ts
Expand Up @@ -29,7 +29,7 @@ import './util/terminate';
message: 'Multiple potential assets found, please choose one from the list below:'.cyan,
});

return assets.find(asset => asset.id === assetID)!;
return assets.find((asset) => asset.id === assetID)!;
};

await api.install({
Expand Down
6 changes: 3 additions & 3 deletions packages/api/cli/src/electron-forge-start.ts
Expand Up @@ -49,8 +49,8 @@ import workingDir from './util/working-dir';
if (program.vscode && appArgs) {
// Args are in the format ~arg~ so we need to strip the "~"
appArgs = appArgs
.map(arg => arg.substr(1, arg.length - 2))
.filter(arg => arg.length > 0);
.map((arg) => arg.substr(1, arg.length - 2))
.filter((arg) => arg.length > 0);
}

if (program.appPath) opts.appPath = program.appPath;
Expand Down Expand Up @@ -81,6 +81,6 @@ import workingDir from './util/working-dir';
child.on('exit', onExit);
child.on('restarted', onRestart);
};
listenForExit(spawned);
listenForExit(spawned as ChildProcess);
});
})();
4 changes: 2 additions & 2 deletions packages/api/cli/src/electron-forge.ts
Expand Up @@ -12,8 +12,8 @@ program.executeSubCommand = (argv: string[], args: string[], unknown: string[])
let indexOfDoubleDash = process.argv.indexOf('--');
indexOfDoubleDash = indexOfDoubleDash < 0 ? process.argv.length + 1 : indexOfDoubleDash;

const passThroughArgs = args.filter(arg => process.argv.indexOf(arg) > indexOfDoubleDash);
const normalArgs = args.filter(arg => process.argv.indexOf(arg) <= indexOfDoubleDash);
const passThroughArgs = args.filter((arg) => process.argv.indexOf(arg) > indexOfDoubleDash);
const normalArgs = args.filter((arg) => process.argv.indexOf(arg) <= indexOfDoubleDash);

let newArgs = args;
let newUnknown = unknown;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/cli/src/util/check-system.ts
Expand Up @@ -12,7 +12,7 @@ const d = debug('electron-forge:check-system');

async function checkGitExists() {
return new Promise<boolean>((resolve) => {
exec('git --version', err => resolve(!err));
exec('git --version', (err) => resolve(!err));
});
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export default async function (ora: OraImpl): Promise<boolean> {
checkGitExists(),
checkNodeVersion(),
checkPackageManagerVersion(ora),
])).every(check => check);
])).every((check) => check);
}
d('skipping system check');
return true;
Expand Down
19 changes: 1 addition & 18 deletions packages/api/core/src/api/index.ts
Expand Up @@ -10,8 +10,7 @@ import _package, { PackageOptions } from './package';
import publish, { PublishOptions } from './publish';
import start, { StartOptions } from './start';

import { fromBuildIdentifier } from '../util/forge-config';
import { hasYarn, yarnOrNpmSpawn } from '../util/yarn-or-npm';
import ForgeUtils from '../util';

export class ForgeAPI {
/**
Expand Down Expand Up @@ -81,22 +80,6 @@ export class ForgeAPI {
}
}

export class ForgeUtils {
/**
* Helper for creating a dynamic config value that will get it's real value
* based on the "buildIdentifier" in your forge config.
*
* Usage:
* `fromBuildIdentifier({ stable: 'App', beta: 'App Beta' })`
*/
fromBuildIdentifier<T>(map: { [key: string]: T | undefined }) {
return fromBuildIdentifier(map);
}

hasYarn = hasYarn;

yarnOrNpmSpawn = yarnOrNpmSpawn;
}

const api = new ForgeAPI();
const utils = new ForgeUtils();
Expand Down
2 changes: 0 additions & 2 deletions packages/api/core/src/api/init-scripts/init-custom.ts
Expand Up @@ -4,8 +4,6 @@ import resolvePackage from 'resolve-package';

import { ForgeTemplate } from '@electron-forge/shared-types';
import installDepList, { DepType } from '../../util/install-dependencies';
// https://github.com/benmosher/eslint-plugin-import/issues/1120
// eslint-disable-next-line import/named
import { PossibleModule } from '../../util/require-search';

const d = debug('electron-forge:init:custom');
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/init-scripts/init-git.ts
Expand Up @@ -13,7 +13,7 @@ export default async (dir: string) => {
if (err) {
// not run within a Git repository
d('executing "git init" in directory:', dir);
exec('git init', { cwd: dir }, initErr => (initErr ? reject(initErr) : resolve()));
exec('git init', { cwd: dir }, (initErr) => (initErr ? reject(initErr) : resolve()));
} else {
d('.git directory already exists, skipping git initialization');
resolve();
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/install.ts
Expand Up @@ -96,7 +96,7 @@ export default async ({
throw new Error(`Repository "${repo}" has no releases`);
}

releases = releases.filter(release => !release.prerelease || prerelease);
releases = releases.filter((release) => !release.prerelease || prerelease);

const sortedReleases = releases.sort((releaseA, releaseB) => {
let tagA = releaseA.tag_name;
Expand Down Expand Up @@ -181,7 +181,7 @@ export default async ({
};

const suffixFnIdent = Object.keys(installActions[process.platform])
.find(suffix => targetAsset.name.endsWith(suffix));
.find((suffix) => targetAsset.name.endsWith(suffix));
if (!suffixFnIdent) {
throw new Error(`No installer to handle "${targetAsset.name}"`);
}
Expand Down
12 changes: 7 additions & 5 deletions packages/api/core/src/api/package.ts
Expand Up @@ -34,7 +34,7 @@ type ElectronPackagerAfterCopyHook = (
*/
function resolveHooks(hooks: (string | ElectronPackagerAfterCopyHook)[] | undefined, dir: string) {
if (hooks) {
return hooks.map(hook => (
return hooks.map((hook) => (
typeof hook === 'string'
? requireSearch<ElectronPackagerAfterCopyHook>(dir, [hook]) as ElectronPackagerAfterCopyHook
: hook
Expand Down Expand Up @@ -170,19 +170,21 @@ export default async ({
}) as ElectronPackagerAfterCopyHook];
afterExtractHooks.push(...resolveHooks(forgeConfig.packagerConfig.afterExtract, dir));

const packageOpts: packager.Options = Object.assign({
type PackagerArch = Exclude<ForgeArch, 'arm'>;

const packageOpts: packager.Options = {
asar: false,
overwrite: true,
}, forgeConfig.packagerConfig, {
...forgeConfig.packagerConfig,
dir,
arch,
arch: arch as PackagerArch,
platform,
afterCopy: sequentialHooks(afterCopyHooks),
afterExtract: sequentialHooks(afterExtractHooks),
afterPrune: sequentialHooks(afterPruneHooks),
out: calculatedOutDir,
electronVersion: await getElectronVersion(dir, packageJSON),
});
};
packageOpts.quiet = true;

if (packageOpts.all) {
Expand Down
14 changes: 8 additions & 6 deletions packages/api/core/src/api/publish.ts
Expand Up @@ -3,6 +3,7 @@ import { asyncOra } from '@electron-forge/async-ora';
import {
IForgeResolvablePublisher,
IForgePublisher,
ForgeConfigPublisher,
ForgeMakeResult,
// ForgePlatform,
} from '@electron-forge/shared-types';
Expand Down Expand Up @@ -34,7 +35,7 @@ export interface PublishOptions {
* The publish targets, by default pulled from forge config, set this prop to
* override that list
*/
publishTargets?: (IForgeResolvablePublisher | IForgePublisher | string)[];
publishTargets?: ForgeConfigPublisher[];
/**
* Options object to passed through to make()
*/
Expand Down Expand Up @@ -103,10 +104,11 @@ const publish = async ({

if (!makeResults) {
d('triggering make');
makeResults = await make(Object.assign({
makeResults = await make({
dir,
interactive,
}, makeOptions));
...makeOptions,
});
} else {
// Restore values from dry run
d('restoring publish settings from dry run');
Expand Down Expand Up @@ -142,17 +144,17 @@ const publish = async ({
// .filter(publisher => (typeof publisher !== 'string' && publisher.platforms)
// ? publisher.platforms.indexOf(testPlatform) !== -1 : true);
}
publishTargets = publishTargets.map((target) => {
publishTargets = (publishTargets as ForgeConfigPublisher[]).map((target) => {
if (typeof target === 'string') {
return (forgeConfig.publishers || []).find((p) => {
return (forgeConfig.publishers || []).find((p: ForgeConfigPublisher) => {
if (typeof p === 'string') return false;
// eslint-disable-next-line no-underscore-dangle
if ((p as IForgePublisher).__isElectronForgePublisher) return false;
return (p as IForgeResolvablePublisher).name === target;
}) || { name: target };
}
return target;
}) as (IForgeResolvablePublisher | IForgePublisher)[];
});

for (const publishTarget of publishTargets) {
let publisher: PublisherBase<any>;
Expand Down
11 changes: 7 additions & 4 deletions packages/api/core/src/api/start.ts
Expand Up @@ -82,10 +82,13 @@ export default async ({
const spawnOpts = {
cwd: dir,
stdio: 'inherit',
env: Object.assign({}, process.env, enableLogging ? {
ELECTRON_ENABLE_LOGGING: 'true',
ELECTRON_ENABLE_STACK_DUMPING: 'true',
} : {}) as NodeJS.ProcessEnv,
env: ({
...process.env,
...(enableLogging ? {
ELECTRON_ENABLE_LOGGING: 'true',
ELECTRON_ENABLE_STACK_DUMPING: 'true',
} : {}),
}) as NodeJS.ProcessEnv,
};

if (runAsNode) {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/core/src/util/electron-version.ts
Expand Up @@ -50,7 +50,7 @@ export async function getElectronVersion(dir: string, packageJSON: any): Promise
if (!packageJSON.devDependencies) {
throw new Error('package.json for app does not have any devDependencies'.red);
}
const packageName = electronPackageNames.find(pkg => packageJSON.devDependencies[pkg]);
const packageName = electronPackageNames.find((pkg) => packageJSON.devDependencies[pkg]);
if (packageName === undefined) {
throw new Error('Could not find any Electron packages in devDependencies');
}
Expand Down Expand Up @@ -82,11 +82,11 @@ export function updateElectronDependency(
const alteredDev = ([] as string[]).concat(dev);
let alteredExact = ([] as string[]).concat(exact);
if (Object.keys(packageJSON.devDependencies).find(findElectronDep)) {
alteredExact = alteredExact.filter(dep => dep !== 'electron');
alteredExact = alteredExact.filter((dep) => dep !== 'electron');
} else {
const electronKey = Object.keys(packageJSON.dependencies).find(findElectronDep);
if (electronKey) {
alteredExact = alteredExact.filter(dep => dep !== 'electron');
alteredExact = alteredExact.filter((dep) => dep !== 'electron');
d(`Moving ${electronKey} from dependencies to devDependencies`);
alteredDev.push(`${electronKey}@${packageJSON.dependencies[electronKey]}`);
delete packageJSON.dependencies[electronKey];
Expand Down
9 changes: 5 additions & 4 deletions packages/api/core/src/util/forge-config.ts
Expand Up @@ -116,15 +116,16 @@ export default async (dir: string) => {
} else if (typeof forgeConfig !== 'object') {
throw new Error('Expected packageJSON.config.forge to be an object or point to a requirable JS file');
}
forgeConfig = Object.assign({
forgeConfig = {
electronRebuildConfig: {},
packagerConfig: {},
rebuildConfig: {},
makers: [],
publishers: [],
plugins: [],
}, forgeConfig);
...forgeConfig,
};

const templateObj = Object.assign({}, packageJSON, { year: (new Date()).getFullYear() });
const templateObj = { ...packageJSON, year: (new Date()).getFullYear() };
const template = (obj: any) => {
Object.keys(obj).forEach((objKey) => {
if (typeof obj[objKey] === 'object' && obj !== null) {
Expand Down
19 changes: 19 additions & 0 deletions packages/api/core/src/util/index.ts
@@ -0,0 +1,19 @@
import { fromBuildIdentifier } from './forge-config';
import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';

export default class ForgeUtils {
/**
* Helper for creating a dynamic config value that will get it's real value
* based on the "buildIdentifier" in your forge config.
*
* Usage:
* `fromBuildIdentifier({ stable: 'App', beta: 'App Beta' })`
*/
fromBuildIdentifier<T>(map: { [key: string]: T | undefined }) {
return fromBuildIdentifier(map);
}

hasYarn = hasYarn;

yarnOrNpmSpawn = yarnOrNpmSpawn;
}
8 changes: 4 additions & 4 deletions packages/api/core/src/util/publish-state.ts
Expand Up @@ -18,14 +18,14 @@ export default class PublishState {

if ((await fs.stat(subDir)).isDirectory()) {
const filePaths = (await fs.readdir(subDir))
.filter(fileName => fileName.endsWith(EXTENSION))
.map(fileName => path.resolve(subDir, fileName));
.filter((fileName) => fileName.endsWith(EXTENSION))
.map((fileName) => path.resolve(subDir, fileName));

for (const filePath of filePaths) {
const state = new PublishState(filePath);
await state.load();
// eslint-disable-next-line max-len
state.state.artifacts = state.state.artifacts.map(artifactPath => path.resolve(rootDir, artifactPath));
state.state.artifacts = state.state.artifacts.map((artifactPath) => path.resolve(rootDir, artifactPath));
states.push(state);
}
}
Expand All @@ -38,7 +38,7 @@ export default class PublishState {
const id = crypto.createHash('SHA256').update(JSON.stringify(artifacts)).digest('hex');
for (const artifact of artifacts) {
// eslint-disable-next-line max-len
artifact.artifacts = artifact.artifacts.map(artifactPath => path.relative(rootDir, artifactPath));
artifact.artifacts = artifact.artifacts.map((artifactPath) => path.relative(rootDir, artifactPath));
const publishState = new PublishState(path.resolve(directory, id, 'null'), false);
publishState.state = artifact;
await publishState.saveToDisk();
Expand Down
5 changes: 3 additions & 2 deletions packages/api/core/src/util/rebuild.ts
Expand Up @@ -12,11 +12,12 @@ export default async (
config: Partial<RebuildOptions> = {},
) => {
await asyncOra('Preparing native dependencies', async (rebuildSpinner) => {
const rebuilder = rebuild(Object.assign({}, config, {
const rebuilder = rebuild({
...config,
buildPath,
electronVersion,
arch,
}));
});
const { lifecycle } = rebuilder;

let found = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/util/require-search.ts
Expand Up @@ -5,8 +5,8 @@ const d = debug('electron-forge:require-search');

export function requireSearchRaw<T>(relativeTo: string, paths: string[]): T | null {
const testPaths = paths
.concat(paths.map(mapPath => path.resolve(relativeTo, mapPath)))
.concat(paths.map(mapPath => path.resolve(relativeTo, 'node_modules', mapPath)));
.concat(paths.map((mapPath) => path.resolve(relativeTo, mapPath)))
.concat(paths.map((mapPath) => path.resolve(relativeTo, 'node_modules', mapPath)));
d('searching', testPaths, 'relative to', relativeTo);
for (const testPath of testPaths) {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/upgrade-forge-config.ts
Expand Up @@ -133,7 +133,7 @@ export default function upgradeForgeConfig(forge5Config: any): ForgeConfig {

export function updateUpgradedForgeDevDeps(packageJSON: any, devDeps: string[]): string[] {
const forgeConfig = packageJSON.config.forge;
devDeps = devDeps.filter(dep => !dep.startsWith('@electron-forge/maker-'));
devDeps = devDeps.filter((dep) => !dep.startsWith('@electron-forge/maker-'));
// eslint-disable-next-line max-len
devDeps = devDeps.concat(forgeConfig.makers.map((maker: IForgeResolvableMaker) => siblingDep(path.basename(maker.name))));
// eslint-disable-next-line max-len
Expand Down

0 comments on commit ef0b663

Please sign in to comment.