Skip to content
Permalink
Browse files

chore(deps-dev): upgrade to ESLint 6 and friends (#1104)

* 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 ef0b6630933379b3b3dc1fe895f9cbbc19cf6a39
Showing with 330 additions and 413 deletions.
  1. +1 −1 .eslintrc.json
  2. +4 −6 package.json
  3. +1 −1 packages/api/cli/src/electron-forge-install.ts
  4. +3 −3 packages/api/cli/src/electron-forge-start.ts
  5. +2 −2 packages/api/cli/src/electron-forge.ts
  6. +2 −2 packages/api/cli/src/util/check-system.ts
  7. +1 −18 packages/api/core/src/api/index.ts
  8. +0 −2 packages/api/core/src/api/init-scripts/init-custom.ts
  9. +1 −1 packages/api/core/src/api/init-scripts/init-git.ts
  10. +2 −2 packages/api/core/src/api/install.ts
  11. +7 −5 packages/api/core/src/api/package.ts
  12. +8 −6 packages/api/core/src/api/publish.ts
  13. +7 −4 packages/api/core/src/api/start.ts
  14. +3 −3 packages/api/core/src/util/electron-version.ts
  15. +5 −4 packages/api/core/src/util/forge-config.ts
  16. +19 −0 packages/api/core/src/util/index.ts
  17. +4 −4 packages/api/core/src/util/publish-state.ts
  18. +3 −2 packages/api/core/src/util/rebuild.ts
  19. +2 −2 packages/api/core/src/util/require-search.ts
  20. +1 −1 packages/api/core/src/util/upgrade-forge-config.ts
  21. +7 −5 packages/api/core/test/fast/forge-config_spec.ts
  22. +6 −6 packages/api/core/test/fast/hook_spec.ts
  23. +1 −1 packages/api/core/test/fast/start_spec.ts
  24. +7 −6 packages/api/core/test/fast/upgrade-forge-config_spec.ts
  25. +4 −4 packages/api/core/test/slow/api_spec_slow.ts
  26. +2 −2 packages/installer/dmg/src/InstallerDMG.ts
  27. +2 −2 packages/installer/zip/src/InstallerZip.ts
  28. +3 −3 packages/maker/appx/src/MakerAppX.ts
  29. +1 −1 packages/maker/base/src/Maker.ts
  30. +3 −3 packages/maker/dmg/src/MakerDMG.ts
  31. +5 −4 packages/maker/flatpak/src/MakerFlatpak.ts
  32. +3 −2 packages/maker/pkg/src/MakerPKG.ts
  33. +1 −1 packages/maker/snap/src/MakerSnap.ts
  34. +3 −3 packages/maker/squirrel/src/MakerSquirrel.ts
  35. +2 −2 packages/maker/wix/src/MakerWix.ts
  36. +35 −31 packages/plugin/webpack/src/WebpackPlugin.ts
  37. +1 −1 packages/publisher/bitbucket/src/PublisherBitbucket.ts
  38. +19 −26 packages/publisher/electron-release-server/src/PublisherERS.ts
  39. +3 −4 packages/publisher/github/src/PublisherGithub.ts
  40. +1 −1 packages/publisher/nucleus/src/PublisherNucleus.ts
  41. +2 −2 packages/publisher/s3/src/PublisherS3.ts
  42. +1 −1 packages/publisher/snapcraft/src/PublisherSnapcraft.ts
  43. +4 −3 packages/utils/types/src/index.ts
  44. +1 −1 tools/position-docs.ts
  45. +1 −1 tools/test-globber.ts
  46. +136 −228 yarn.lock
@@ -13,7 +13,7 @@
"node": true
},
"extends": [
"airbnb"
"airbnb-base"
],
"rules": {
"class-methods-use-this": "off",
@@ -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",
@@ -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",
@@ -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({
@@ -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;
@@ -81,6 +81,6 @@ import workingDir from './util/working-dir';
child.on('exit', onExit);
child.on('restarted', onRestart);
};
listenForExit(spawned);
listenForExit(spawned as ChildProcess);
});
})();
@@ -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;
@@ -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));
});
}

@@ -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;
@@ -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 {
/**
@@ -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();
@@ -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');
@@ -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();
@@ -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;
@@ -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}"`);
}
@@ -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
@@ -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) {
@@ -3,6 +3,7 @@ import { asyncOra } from '@electron-forge/async-ora';
import {
IForgeResolvablePublisher,
IForgePublisher,
ForgeConfigPublisher,
ForgeMakeResult,
// ForgePlatform,
} from '@electron-forge/shared-types';
@@ -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()
*/
@@ -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');
@@ -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>;
@@ -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) {
@@ -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');
}
@@ -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];
@@ -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) {
@@ -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;
}
@@ -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);
}
}
@@ -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();
@@ -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;
@@ -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 {
@@ -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

0 comments on commit ef0b663

Please sign in to comment.
You can’t perform that action at this time.