Skip to content
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

build(deps): TypeScript 5.4 #3790

Open
wants to merge 4 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
8 changes: 5 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"rules": {
"no-throw-literal": "off",
"@typescript-eslint/no-throw-literal": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-expressions": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand All @@ -57,7 +58,8 @@
"ignoreRestSiblings": true,
"vars": "all"
}
]
],
"@typescript-eslint/only-throw-error": "error"
}
},
{
Expand Down Expand Up @@ -93,7 +95,7 @@
{
"files": ["packages/api/core/test/**/*.ts", "packages/maker/*/src/Maker*.ts"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
"@typescript-eslint/no-require-imports": "off"
}
},
{
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint:markdown-js": "electron-lint-markdown-standard --root . --ignore-path .markdownlintignore --semi \"**/*.md\"",
"lint:markdown-links": "electron-lint-markdown-links --root . --ignore-path .markdownlintignore \"**/*.md\"",
"lint": "npm run lint:js && npm run lint:markdown && npm run lint:markdown-js && npm run lint:markdown-links",
"lint:fix": "prettier --write .",
"lint:fix": "prettier --write . && eslint --fix .",
"link:prepare": "lerna exec -- node ../../../tools/silent.js yarn link --silent --no-bin-links --link-folder ../../../.links",
"link:remove": "lerna exec -- node ../../../tools/silent.js yarn unlink --silent --no-bin-links --link-folder ../../../.links",
"test": "npm run test:clear && xvfb-maybe cross-env NODE_ENV=test TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha",
Expand Down Expand Up @@ -108,14 +108,14 @@
"@types/sinon": "^10.0.0",
"@types/sinon-chai": "^3.2.5",
"@types/which": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"cross-env": "^7.0.2",
"electron-installer-common": "^0.10.2",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.26.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-mocha": "^9.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
Expand All @@ -139,7 +139,7 @@
"syncpack": "^11.2.1",
"ts-node": "^10.0.0",
"typedoc": "0.25.13",
"typescript": "^4.6.3",
"typescript": "~5.4.5",
"xvfb-maybe": "^0.2.1",
"yaml-hook": "^1.0.0"
},
Expand Down Expand Up @@ -179,5 +179,8 @@
"packages/template/*",
"packages/utils/*"
]
},
"resolutions": {
"@typescript-eslint/parser": "^8.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-make.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';

import { api, MakeOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, MakeOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-package.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';

import { api, PackageOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, PackageOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge-publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';

import { api, PublishOptions } from '@electron-forge/core';
import { initializeProxy } from '@electron/get';
import { api, PublishOptions } from '@electron-forge/core';
import program from 'commander';
import fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/src/electron-forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './util/terminate';

import { checkSystem } from './util/check-system';

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const metadata = require('../package.json');

const originalSC = program.executeSubCommand.bind(program);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default autoTrace(
// if there's an existing config.forge object in package.json
if (packageJSON?.config?.forge && typeof packageJSON.config.forge === 'object') {
d('detected existing Forge config in package.json, merging with base template Forge config');
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const templateConfig = require(path.resolve(baseTemplate.templateDir, 'forge.config.js'));
packageJSON = await readRawPackageJson(dir);
merge(templateConfig, packageJSON.config.forge); // mutates the templateConfig object
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/init-scripts/find-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const findTemplate = async (dir: string, template: string): Promise<Forge

d(`found template module at: ${templateModulePath}`);

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const templateModule: PossibleModule<ForgeTemplate> = require(templateModulePath);

return templateModule.default || templateModule;
Expand Down
18 changes: 9 additions & 9 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path';

import { getHostArch } from '@electron/get';
import { getElectronVersion } from '@electron-forge/core-utils';
import { MakerBase } from '@electron-forge/maker-base';
import {
Expand All @@ -13,7 +14,6 @@ import {
ResolvedForgeConfig,
} from '@electron-forge/shared-types';
import { autoTrace, delayTraceTillSignal } from '@electron-forge/tracer';
import { getHostArch } from '@electron/get';
import chalk from 'chalk';
import filenamify from 'filenamify';
import fs from 'fs-extra';
Expand All @@ -30,12 +30,10 @@ import resolveDir from '../util/resolve-dir';

import { listrPackage } from './package';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
class MakerImpl extends MakerBase<any> {
name = 'impl';

defaultPlatforms = [];
}
type MakerImpl = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new (...args: any[]): MakerBase<any>;
};

type MakeTargets = ForgeConfigMaker[] | string[];

Expand Down Expand Up @@ -168,7 +166,7 @@ export const listrMake = (
throw new Error(`The following maker config has a maker name that is not a string: ${JSON.stringify(resolvableTarget)}`);
}

const MakerClass = await importSearch<typeof MakerImpl>(dir, [resolvableTarget.name]);
const MakerClass = await importSearch<MakerImpl>(dir, [resolvableTarget.name]);
if (!MakerClass) {
throw new Error(
`Could not find module with name '${resolvableTarget.name}'. If this is a package from NPM, make sure it's listed in the devDependencies of your package.json. If this is a local module, make sure you have the correct path to its entry point. Try using the DEBUG="electron-forge:require-search" environment variable for more information.`
Expand Down Expand Up @@ -294,8 +292,10 @@ export const listrMake = (
arch: targetArch,
});
} catch (err) {
if (err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is semantically different, in some places we throw strings, we should still somehow log those?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there specific places where we throw strings? This was caught in lint by "@typescript-eslint/only-throw-error".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've definitely done it before, probably in forge, or it's dependencies 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we still do it today or not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another else if clause for when the error is a string as well: 12efc76

if (err instanceof Error) {
throw err;
} else if (typeof err === 'string') {
throw new Error(err);
} else {
throw new Error(`An unknown error occurred while making for target: ${uniqMaker.name}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'node:path';
import { promisify } from 'node:util';

import { getHostArch } from '@electron/get';
import { FinalizePackageTargetsHookFunction, HookFunction, Options, packager, TargetDefinition } from '@electron/packager';
import { getElectronVersion, listrCompatibleRebuildHook } from '@electron-forge/core-utils';
import { ForgeArch, ForgeListrTask, ForgeListrTaskDefinition, ForgeListrTaskFn, ForgePlatform, ResolvedForgeConfig } from '@electron-forge/shared-types';
import { autoTrace, delayTraceTillSignal } from '@electron-forge/tracer';
import { getHostArch } from '@electron/get';
import { FinalizePackageTargetsHookFunction, HookFunction, Options, packager, TargetDefinition } from '@electron/packager';
import chalk from 'chalk';
import debug from 'debug';
import glob from 'fast-glob';
Expand Down
3 changes: 2 additions & 1 deletion packages/api/core/src/util/electron-executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ type PackageJSON = Record<string, unknown>;
export default async function locateElectronExecutable(dir: string, packageJSON: PackageJSON): Promise<string> {
const electronModulePath: string | undefined = await getElectronModulePath(dir, packageJSON);

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
let electronExecPath = require(electronModulePath || path.resolve(dir, 'node_modules/electron'));

if (typeof electronExecPath !== 'string') {
console.warn(logSymbols.warning, 'Returned Electron executable path is not a string, defaulting to a hardcoded location. Value:', electronExecPath);
// eslint-disable-next-line @typescript-eslint/no-require-imports
electronExecPath = require(path.resolve(dir, 'node_modules/electron'));
}

Expand Down
8 changes: 6 additions & 2 deletions packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ const underscoreCase = (str: string) =>
.toUpperCase();

// Why: needs access to Object methods and also needs to be able to match any interface.
// eslint-disable-next-line @typescript-eslint/ban-types
type ProxiedObject = object;

/* eslint-disable @typescript-eslint/no-explicit-any */
function isBuildIdentifierConfig(value: any): value is BuildIdentifierConfig<any> {
return value && typeof value === 'object' && value.__isMagicBuildIdentifierMap;
}

const proxify = <T extends ProxiedObject>(buildIdentifier: string | (() => string), proxifiedObject: T, envPrefix: string): T => {
let newObject: T = {} as any;
if (Array.isArray(proxifiedObject)) {
Expand All @@ -46,7 +49,7 @@ const proxify = <T extends ProxiedObject>(buildIdentifier: string | (() => strin
}
const value = Reflect.get(target, name, receiver);

if (value && typeof value === 'object' && value.__isMagicBuildIdentifierMap) {
if (isBuildIdentifierConfig(value)) {
const identifier = typeof buildIdentifier === 'function' ? buildIdentifier() : buildIdentifier;
return value.map[identifier];
}
Expand Down Expand Up @@ -107,6 +110,7 @@ export function renderConfigTemplate(dir: string, templateObj: any, obj: any): v
} else if (typeof value === 'string') {
obj[key] = template(value)(templateObj);
if (obj[key].startsWith('require:')) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
obj[key] = require(path.resolve(dir, obj[key].substr(8)));
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/core/src/util/is-installed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default function isInstalled(pkg: string): boolean {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require(pkg);
return true;
} catch {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/parse-archs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';
import { allOfficialArchsForPlatformAndVersion, SupportedPlatform } from '@electron/packager';
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';

export default function parseArchs(platform: ForgePlatform | string, declaredArch: ForgeArch | 'all' | string, electronVersion: string): ForgeArch[] {
if (declaredArch === 'all') {
Expand Down
1 change: 1 addition & 0 deletions packages/api/core/test/fast/publish_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('publish', () => {
public name = name;

constructor(public providedConfig: Record<string, unknown>) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
fooPublisher = this;
this.publish = stub;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default abstract class Maker<C> implements IForgeMaker {
try {
require(module);
return true;
} catch (e) {
} catch {
// Package doesn't exist -- must not be installable on this platform
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/maker/flatpak/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface MakerFlatpakOptionsConfig {
* into the flatpak, and dest should be the path inside the app install
* prefix (e.g. /share/applications/)
*
* Application assets and code will be fully handled by @electron/packager,
* Application assets and code will be fully handled by \@electron/packager,
* but this is a useful way to install things such as appstream metadata
* for an app, or dbus configuration files.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/maker/pkg/src/MakerPKG.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';

import { flatAsync } from '@electron/osx-sign';
import { MakerBase, MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';
import { flatAsync } from '@electron/osx-sign';

import { MakerPKGConfig } from './Config';

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/auto-unpack-natives/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface AutoUnpackNativesConfig {
// No configuration options
}
2 changes: 1 addition & 1 deletion packages/plugin/fuses/src/FusesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';

import { flipFuses, FuseConfig } from '@electron/fuses';
import { namedHookWithTaskFn, PluginBase } from '@electron-forge/plugin-base';
import { ForgeMultiHookMap, ForgePlatform } from '@electron-forge/shared-types';
import { flipFuses, FuseConfig } from '@electron/fuses';

import { getElectronExecutablePath } from './util/getElectronExecutablePath';

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/fuses/test/fixture/app/forge.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';

import { FuseV1Options, FuseVersion } from '@electron/fuses';
import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { ForgeConfig } from '@electron-forge/shared-types';
import { FuseV1Options, FuseVersion } from '@electron/fuses';
import fsExtra from 'fs-extra';

const forgeConfig: ForgeConfig = {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/vite/test/VitePlugin_spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as os from 'node:os';
import * as path from 'node:path';

import { ResolvedForgeConfig } from '@electron-forge/shared-types';
import { IgnoreFunction } from '@electron/packager';
import { ResolvedForgeConfig } from '@electron-forge/shared-types';
import { expect } from 'chai';
import * as fs from 'fs-extra';

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/webpack/src/WebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class WebpackConfigGenerator {

let rawConfig =
typeof config === 'string'
? // eslint-disable-next-line @typescript-eslint/no-var-requires
? // eslint-disable-next-line @typescript-eslint/no-require-imports
(require(path.resolve(this.projectDir, config)) as MaybeESM<Configuration | ConfigurationFactory>)
: config;

Expand Down
2 changes: 2 additions & 0 deletions packages/plugin/webpack/src/util/rendererTypeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { WebpackPluginEntryPoint, WebpackPluginEntryPointLocalWindow, WebpackPluginEntryPointNoWindow, WebpackPluginEntryPointPreloadOnly } from '../Config';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/webpack/test/WebpackPlugin_spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as os from 'node:os';
import * as path from 'node:path';

import { ResolvedForgeConfig } from '@electron-forge/shared-types';
import { IgnoreFunction } from '@electron/packager';
import { ResolvedForgeConfig } from '@electron-forge/shared-types';
import { expect } from 'chai';
import * as fs from 'fs-extra';

Expand Down
8 changes: 5 additions & 3 deletions packages/publisher/github/src/PublisherGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { PublisherGitHubConfig } from './Config';
import GitHub from './util/github';
import NoReleaseError from './util/no-release-error';

import type { Octokit } from '@octokit/rest';

interface GitHubRelease {
tag_name: string;
assets: {
Expand Down Expand Up @@ -46,10 +48,10 @@ export default class PublisherGithub extends PublisherBase<PublisherGitHubConfig
}

const github = new GitHub(config.authToken, true, config.octokitOptions);
github.getGitHub();

const octokit = github.getGitHub();
type OctokitRelease = GetResponseDataTypeFromEndpointMethod<typeof octokit.repos.getRelease>;
type OctokitReleaseAsset = GetResponseDataTypeFromEndpointMethod<typeof octokit.repos.updateReleaseAsset>;
type OctokitRelease = GetResponseDataTypeFromEndpointMethod<Octokit['repos']['getRelease']>;
type OctokitReleaseAsset = GetResponseDataTypeFromEndpointMethod<Octokit['repos']['updateReleaseAsset']>;

for (const releaseVersion of Object.keys(perReleaseArtifacts)) {
let release: OctokitRelease | undefined;
Expand Down
1 change: 0 additions & 1 deletion packages/publisher/github/test/github_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('GitHub', () => {
this.options = options;
}

// eslint-disable-next-line @typescript-eslint/ban-types
static plugin(): object {
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/snapcraft/src/PublisherSnapcraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs-extra';
import { PublisherSnapcraftConfig } from './Config';

// TODO: convert to import statement once electron-installer-snap imports Snapcraft properly.
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const Snapcraft = require('electron-installer-snap/src/snapcraft');

export default class PublisherSnapcraft extends PublisherBase<PublisherSnapcraftConfig> {
Expand Down
Loading
Loading