From a3eae4dfa0671a8ce470b11e81d93d036ba291e4 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Wed, 11 Dec 2019 21:20:00 -0800 Subject: [PATCH] refactor: replace indexOf with includes/startsWith where applicable (#1337) --- packages/api/core/src/api/install.ts | 2 +- packages/api/core/src/api/make.ts | 4 ++-- packages/api/core/src/api/publish.ts | 2 +- packages/api/core/test/fast/publish_spec.ts | 2 +- packages/plugin/webpack/src/WebpackPlugin.ts | 7 ++----- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/api/core/src/api/install.ts b/packages/api/core/src/api/install.ts index 47e2ac2ede..d2a3e57890 100644 --- a/packages/api/core/src/api/install.ts +++ b/packages/api/core/src/api/install.ts @@ -76,7 +76,7 @@ export default async ({ let possibleAssets: Asset[] = []; await asyncOra('Searching for Application', async (searchSpinner) => { - if (!repo || repo.indexOf('/') === -1) { + if (!repo || !repo.includes('/')) { throw new Error('Invalid repository name, must be in the format owner/name'); } diff --git a/packages/api/core/src/api/make.ts b/packages/api/core/src/api/make.ts index 6900561bfd..a4d8112c00 100644 --- a/packages/api/core/src/api/make.ts +++ b/packages/api/core/src/api/make.ts @@ -104,7 +104,7 @@ export default async ({ if ((target as MakerBase).__isElectronForgeMaker) { maker = target as MakerBase; // eslint-disable-next-line no-continue - if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue; + if (!maker.platforms.includes(actualTargetPlatform)) continue; } else { const resolvableTarget: IForgeResolvableMaker = target as IForgeResolvableMaker; const MakerClass = requireSearch(dir, [resolvableTarget.name]); @@ -114,7 +114,7 @@ export default async ({ maker = new MakerClass(resolvableTarget.config, resolvableTarget.platforms || undefined); // eslint-disable-next-line no-continue - if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue; + if (!maker.platforms.includes(actualTargetPlatform)) continue; } if (!maker.isSupportedOnCurrentPlatform) { diff --git a/packages/api/core/src/api/publish.ts b/packages/api/core/src/api/publish.ts index 8bc4a0ee69..daa9887084 100644 --- a/packages/api/core/src/api/publish.ts +++ b/packages/api/core/src/api/publish.ts @@ -142,7 +142,7 @@ const publish = async ({ if (!publishTargets) { publishTargets = (forgeConfig.publishers || []); // .filter(publisher => (typeof publisher !== 'string' && publisher.platforms) - // ? publisher.platforms.indexOf(testPlatform) !== -1 : true); + // ? publisher.platforms.includes(testPlatform) : true); } publishTargets = (publishTargets as ForgeConfigPublisher[]).map((target) => { if (typeof target === 'string') { diff --git a/packages/api/core/test/fast/publish_spec.ts b/packages/api/core/test/fast/publish_spec.ts index 44428db5bd..bd45089667 100644 --- a/packages/api/core/test/fast/publish_spec.ts +++ b/packages/api/core/test/fast/publish_spec.ts @@ -280,7 +280,7 @@ describe('publish', () => { it('should successfully restore values and pass them to publisher', () => { expect(makeStub.callCount).to.equal(0); expect(publisherSpy.callCount).to.equal(2, 'should call once for each platform (make run)'); - const darwinIndex = publisherSpy.firstCall.args[0].makeResults[0].artifacts.some((a: string) => a.indexOf('darwin') !== -1) ? 0 : 1; + const darwinIndex = publisherSpy.firstCall.args[0].makeResults[0].artifacts.some((a: string) => a.includes('darwin')) ? 0 : 1; const win32Index = darwinIndex === 0 ? 1 : 0; const darwinArgs = publisherSpy.getCall(darwinIndex).args[0]; const darwinArtifacts = []; diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index f2d8fbc6df..b595780876 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -222,7 +222,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe getDefines = (inRendererDir = true) => { const defines: { [key: string]: string; } = { ASSET_RELOCATOR_BASE_DIR: this.isProd - ? `process.resourcesPath + "/" + (__filename.indexOf(".asar") === -1 ? "app" : "app.asar") + "/.webpack/${inRendererDir ? 'main' : 'renderer/any_folder'}"` + ? `process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/${inRendererDir ? 'main' : 'renderer/any_folder'}"` : JSON.stringify( path.resolve( this.baseDir, @@ -259,10 +259,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe const fix = (item: EntryType): EntryType => { if (typeof item === 'string') return (fix([item]) as string[])[0]; if (Array.isArray(item)) { - return item.map((val) => { - if (val.indexOf('./') === 0) return path.resolve(this.projectDir, val); - return val; - }); + return item.map((val) => (val.startsWith('./') ? path.resolve(this.projectDir, val) : val)); } const ret: Record = {}; for (const key of Object.keys(item)) {