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

refactor: use forge.config.ts in the webpack typescript template #3012

Merged
merged 14 commits into from
Oct 31, 2022
Merged
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@knodes/typedoc-plugin-monorepo-readmes": "0.22.5",
"@malept/eslint-config": "^2.0.0",
"@swc/cli": "^0.1.49",
"@swc/core": "^1.2.87",
Expand Down Expand Up @@ -133,6 +134,7 @@
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"fetch-mock": "^9.10.7",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"generate-changelog": "^1.8.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
Expand All @@ -149,7 +151,6 @@
"typedoc": "^0.22.15",
"typedoc-plugin-missing-exports": "^1.0.0",
"typedoc-plugin-rename-defaults": "^0.6.4",
"@knodes/typedoc-plugin-monorepo-readmes": "0.22.5",
"typescript": "^4.6.3",
"xvfb-maybe": "^0.2.1"
},
Expand Down
1 change: 1 addition & 0 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"@electron-forge/async-ora": "6.0.0-beta.69",
"@electron-forge/core-utils": "^6.0.0-beta.69",
"@electron-forge/maker-base": "6.0.0-beta.69",
"@electron-forge/plugin-base": "6.0.0-beta.69",
"@electron-forge/publisher-base": "6.0.0-beta.69",
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
@@ -1,13 +1,13 @@
import path from 'path';

import { asyncOra } from '@electron-forge/async-ora';
import { updateElectronDependency } from '@electron-forge/core-utils';
import baseTemplate from '@electron-forge/template-base';
import chalk from 'chalk';
import debug from 'debug';
import fs from 'fs-extra';
import { merge } from 'lodash';

import { updateElectronDependency } from '../util/electron-version';
import installDepList, { DepType, DepVersionRestriction } from '../util/install-dependencies';
import { info, warn } from '../util/messages';
import { readRawPackageJson } from '../util/read-package-json';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import path from 'path';

import { asyncOra } from '@electron-forge/async-ora';
import { getElectronVersion } from '@electron-forge/core-utils';
import { MakerBase } from '@electron-forge/maker-base';
import { ForgeArch, ForgeConfigMaker, ForgeMakeResult, ForgePlatform, IForgeResolvableMaker, ResolvedForgeConfig } from '@electron-forge/shared-types';
import { getHostArch } from '@electron/get';
import chalk from 'chalk';
import filenamify from 'filenamify';
import fs from 'fs-extra';

import { getElectronVersion } from '../util/electron-version';
import getForgeConfig from '../util/forge-config';
import { runHook, runMutatingHook } from '../util/hook';
import { info, warn } from '../util/messages';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import { promisify } from 'util';

import { fakeOra, OraImpl, ora as realOra } from '@electron-forge/async-ora';
import { getElectronVersion } from '@electron-forge/core-utils';
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';
import { getHostArch } from '@electron/get';
import chalk from 'chalk';
Expand All @@ -10,7 +11,6 @@ import packager, { HookFunction } from 'electron-packager';
import glob from 'fast-glob';
import fs from 'fs-extra';

import { getElectronVersion } from '../util/electron-version';
import getForgeConfig from '../util/forge-config';
import { runHook } from '../util/hook';
import { warn } from '../util/messages';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { spawn, SpawnOptions } from 'child_process';

import { asyncOra } from '@electron-forge/async-ora';
import { getElectronVersion } from '@electron-forge/core-utils';
import { ElectronProcess, ForgeArch, ForgePlatform, StartOptions } from '@electron-forge/shared-types';
import chalk from 'chalk';
import debug from 'debug';

import locateElectronExecutable from '../util/electron-executable';
import { getElectronVersion } from '../util/electron-version';
import getForgeConfig from '../util/forge-config';
import { runHook } from '../util/hook';
import { readMutatedPackageJson } from '../util/read-package-json';
Expand Down
3 changes: 1 addition & 2 deletions packages/api/core/src/util/electron-executable.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'path';

import { getElectronModulePath } from '@electron-forge/core-utils';
import chalk from 'chalk';
import logSymbols from 'log-symbols';

import { getElectronModulePath } from './electron-version';

type PackageJSON = Record<string, unknown>;
type Dependencies = Record<string, string>;

Expand Down
7 changes: 3 additions & 4 deletions packages/api/core/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getElectronVersion } from './electron-version';
import { getElectronVersion, hasYarn, packagerRebuildHook, yarnOrNpmSpawn } from '@electron-forge/core-utils';

import { BuildIdentifierConfig, BuildIdentifierMap, fromBuildIdentifier } from './forge-config';
import rebuildHook from './rebuild';
import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';

export default class ForgeUtils {
/**
Expand All @@ -19,7 +18,7 @@ export default class ForgeUtils {

hasYarn = hasYarn;

rebuildHook = rebuildHook;
rebuildHook = packagerRebuildHook;

yarnOrNpmSpawn = yarnOrNpmSpawn;
}
3 changes: 1 addition & 2 deletions packages/api/core/src/util/install-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { hasYarn, yarnOrNpmSpawn } from '@electron-forge/core-utils';
import { ExitError } from '@malept/cross-spawn-promise';
import debug from 'debug';

import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';

const d = debug('electron-forge:dependency-installer');

export enum DepType {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/resolve-dir.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';

import { getElectronVersion } from '@electron-forge/core-utils';
import debug from 'debug';
import fs from 'fs-extra';

import { getElectronVersion } from './electron-version';
import { readRawPackageJson } from './read-package-json';

const d = debug('electron-forge:project-resolver');
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@electron-forge/async-ora": "6.0.0-beta.69",
"@electron-forge/core": "6.0.0-beta.69",
"@electron-forge/core-utils": "^6.0.0-beta.69",
"@electron-forge/plugin-base": "6.0.0-beta.69",
"@electron-forge/shared-types": "6.0.0-beta.69",
"@electron-forge/web-multi-logger": "6.0.0-beta.69",
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import http from 'http';
import path from 'path';

import { asyncOra } from '@electron-forge/async-ora';
import { utils } from '@electron-forge/core';
import { getElectronVersion, packagerRebuildHook } from '@electron-forge/core-utils';
import { PluginBase } from '@electron-forge/plugin-base';
import { ForgeHookMap, ResolvedForgeConfig } from '@electron-forge/shared-types';
import Logger, { Tab } from '@electron-forge/web-multi-logger';
Expand Down Expand Up @@ -155,9 +155,9 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
return {
prePackage: async (config, platform, arch) => {
await fs.remove(this.baseDir);
await utils.rebuildHook(
await packagerRebuildHook(
this.projectDir,
await utils.getElectronVersion(this.projectDir, await fs.readJson(path.join(this.projectDir, 'package.json'))),
await getElectronVersion(this.projectDir, await fs.readJson(path.join(this.projectDir, 'package.json'))),
platform,
arch,
config.rebuildConfig
Expand Down
8 changes: 7 additions & 1 deletion packages/template/typescript-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@electron-forge/maker-deb": "^6.0.0-beta.69",
"@electron-forge/maker-rpm": "^6.0.0-beta.69",
"@electron-forge/maker-squirrel": "^6.0.0-beta.69",
"@electron-forge/maker-zip": "^6.0.0-beta.69",
"@electron-forge/plugin-webpack": "^6.0.0-beta.69",
"@electron-forge/test-utils": "6.0.0-beta.69",
"chai": "^4.3.3",
"fast-glob": "^3.2.7"
"fast-glob": "^3.2.7",
"fork-ts-checker-webpack-plugin": "^7.2.13"
}
}
64 changes: 28 additions & 36 deletions packages/template/typescript-webpack/tmpl/forge.config.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
module.exports = {
import type { ForgeConfig } from '@electron-forge/shared-types';
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { MakerZIP } from '@electron-forge/maker-zip';
import { MakerDeb } from '@electron-forge/maker-deb';
import { MakerRpm } from '@electron-forge/maker-rpm';
import { WebpackPlugin } from '@electron-forge/plugin-webpack';

import { mainConfig } from './webpack.main.config';
import { rendererConfig } from './webpack.renderer.config';

const config: ForgeConfig = {
packagerConfig: {},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
plugins: [
{
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack.main.config.js',
renderer: {
config: './webpack.renderer.config.js',
entryPoints: [
{
html: './src/index.html',
js: './src/renderer.js',
name: 'main_window',
preload: {
js: './src/preload.js',
},
new WebpackPlugin({
mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [
{
html: './src/index.html',
js: './src/renderer.js',
name: 'main_window',
preload: {
js: './src/preload.js',
},
],
},
},
],
},
},
}),
],
};

export default config;
2 changes: 1 addition & 1 deletion packages/template/typescript-webpack/tmpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ts-loader": "^9.2.2",
"style-loader": "^3.0.0",
"typescript": "~4.5.4",
"fork-ts-checker-webpack-plugin": "^7.2.1",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Configuration } from 'webpack';

export const mainConfig: Configuration = {
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';

const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

export const plugins = [new ForkTsCheckerWebpackPlugin()];
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const rules = require('./webpack.rules');
const plugins = require('./webpack.plugins');
import type { Configuration } from 'webpack';

import { rules } from './webpack.rules';
import { plugins } from './webpack.plugins';

rules.push({
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
});

module.exports = {
export const rendererConfig: Configuration = {
module: {
rules,
},
plugins: plugins,
plugins,
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css'],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = [
import type { ModuleOptions } from 'webpack';

export const rules: Required<ModuleOptions>['rules'] = [
// Add support for native node modules
{
// We're specifying native_modules in the test because the asset relocator loader generates a
Expand Down
26 changes: 26 additions & 0 deletions packages/utils/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@electron-forge/core-utils",
"version": "6.0.0-beta.69",
"description": "Core utilities for the Electron Forge packages",
"repository": "https://github.com/electron-userland/electron-forge",
"author": "Samuel Attard",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"dependencies": {
"@electron-forge/async-ora": "^6.0.0-beta.69",
"@electron-forge/shared-types": "^6.0.0-beta.69",
"@malept/cross-spawn-promise": "^2.0.0",
"chalk": "^4.0.0",
"debug": "^4.3.1",
"electron-rebuild": "^3.2.6",
"find-up": "^5.0.0",
"fs-extra": "^10.0.0",
"log-symbols": "^4.0.0",
"semver": "^7.2.1",
"yarn-or-npm": "^3.0.1"
},
"engines": {
"node": ">= 14.17.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import findUp from 'find-up';
import fs from 'fs-extra';
import semver from 'semver';

import yarnOrNpm from './yarn-or-npm';
import { safeYarnOrNpm } from './yarn-or-npm';

const d = debug('electron-forge:electron-version');

Expand Down Expand Up @@ -44,7 +44,7 @@ async function determineNodeModulesPath(dir: string, packageName: string): Promi

export class PackageNotFoundError extends Error {
constructor(packageName: string, dir: string) {
super(`Cannot find the package "${packageName}". Perhaps you need to run "${yarnOrNpm()} install" in "${dir}"?`);
super(`Cannot find the package "${packageName}". Perhaps you need to run "${safeYarnOrNpm()} install" in "${dir}"?`);
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/utils/core-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './rebuild';
export * from './electron-version';
export * from './yarn-or-npm';
Loading