Skip to content

Commit

Permalink
Merge branch 'main' into fix-dont-sanitize-github-asset-names
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Feb 10, 2024
2 parents b79a015 + b0cae41 commit 29ef4ae
Show file tree
Hide file tree
Showing 44 changed files with 938 additions and 521 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'monthly'
2 changes: 1 addition & 1 deletion .github/workflows/add-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
creds: ${{ secrets.ECOSYSTEM_ISSUE_TRIAGE_GH_APP_CREDS }}
org: electron
- name: Add to Project
uses: dsanders11/project-actions/add-item@a24415515fa60a22f71f9d9d00e36ca82660cde9 # v1.0.1
uses: dsanders11/project-actions/add-item@82e99438bd44a14ad18d92d036dbc25cbfb9a8c4 # v1.2.0
with:
field: Opened
field-value: ${{ github.event.pull_request.created_at || github.event.issue.created_at }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
creds: ${{ secrets.GH_APP_CREDS }}
export-git-user: true

- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: true
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}

- name: Use Node.js LTS
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: 20.x
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: semantic-pull-request
uses: amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb # tag: v5
uses: amannn/action-semantic-pull-request@e9fabac35e210fea40ca5b14c0da95a099eff26f # tag: v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.nyc_output
*.lcov
/coverage
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
"lint:fix": "prettier --write .",
"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": "xvfb-maybe cross-env NODE_ENV=test TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha",
"test": "npm run test:clear && xvfb-maybe cross-env NODE_ENV=test TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha",
"test:fast": "npm run test -- --suite=fast",
"test:slow": "npm run test -- --suite=slow",
"test:clear": "ts-node tools/test-clear",
"postinstall": "rimraf node_modules/.bin/*.ps1 && ts-node ./tools/gen-tsconfigs.ts && ts-node ./tools/gen-ts-glue.ts",
"prepare": "husky install",
"preversion": "yarn build"
Expand Down Expand Up @@ -74,7 +75,7 @@
"source-map-support": "^0.5.13",
"sudo-prompt": "^9.1.1",
"username": "^5.1.0",
"vite": "^4.5.1",
"vite": "^5.0.12",
"webpack": "^5.69.1",
"webpack-dev-server": "^4.0.0",
"webpack-merge": "^5.7.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type ElectronegativityConfig = {
*
* Defaults to `false`.
*/
isRelative?: false;
isRelative?: boolean;
/**
* Specify a range to run Electron upgrade checks. For example, `'7..8'` checks an upgrade
* from Electron 7 to Electron 8.
Expand All @@ -49,7 +49,7 @@ export type ElectronegativityConfig = {
*
* Defaults to empty array (`[]`)
*/
parserPlugins: Array<string>;
parserPlugins?: Array<string>;
};

export default class ElectronegativityPlugin extends PluginBase<ElectronegativityConfig> {
Expand All @@ -65,6 +65,7 @@ export default class ElectronegativityPlugin extends PluginBase<Electronegativit
await runElectronegativity(
{
...this.config,
isRelative: this.config.isRelative ?? false,
parserPlugins: this.config.parserPlugins ?? [],
input: options.outputPaths[0],
},
Expand Down
20 changes: 10 additions & 10 deletions packages/plugin/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
"scripts": {
"test": "xvfb-maybe mocha --config ../../../.mocharc.js test/**/*_spec.ts test/*_spec.ts"
},
"dependencies": {
"@electron-forge/core-utils": "7.2.0",
"@electron-forge/plugin-base": "7.2.0",
"@electron-forge/shared-types": "7.2.0",
"@electron-forge/web-multi-logger": "7.2.0",
"chalk": "^4.0.0",
"debug": "^4.3.1",
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@electron/packager": "^18.1.2",
"@malept/cross-spawn-promise": "^2.0.0",
"@types/node": "^18.0.3",
"chai": "^4.3.3",
"mocha": "^9.0.1",
"vite": "^5.0.12",
"which": "^2.0.2",
"xvfb-maybe": "^0.2.1"
},
"engines": {
"node": ">= 16.4.0"
},
"dependencies": {
"@electron-forge/core-utils": "7.2.0",
"@electron-forge/plugin-base": "7.2.0",
"@electron-forge/shared-types": "7.2.0",
"@electron-forge/web-multi-logger": "7.2.0",
"chalk": "^4.0.0",
"debug": "^4.3.1",
"fs-extra": "^10.0.0",
"vite": "^4.5.1"
},
"publishConfig": {
"access": "public"
},
Expand Down
13 changes: 9 additions & 4 deletions packages/plugin/vite/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line node/no-unpublished-import
import type { LibraryOptions } from 'vite';

export interface VitePluginBuildConfig {
Expand All @@ -8,27 +9,31 @@ export interface VitePluginBuildConfig {
/**
* Vite config file path.
*/
config?: string;
config: string;
}

export interface VitePluginRendererConfig {
/**
* Human friendly name of your entry point
* Human friendly name of your entry point.
*/
name: string;
name?: string;
/**
* Vite config file path.
*/
config: string;
}

export interface VitePluginConfig {
// Reserved option, may support modification in the future.
// @defaultValue '.vite'
// baseDir?: string;

/**
* Build anything such as Main process, Preload scripts and Worker process, etc.
*/
build: VitePluginBuildConfig[];
/**
* Renderer process.
* Renderer process Vite configs.
*/
renderer: VitePluginRendererConfig[];
}
110 changes: 25 additions & 85 deletions packages/plugin/vite/src/ViteConfig.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import path from 'node:path';

import debug from 'debug';
import { ConfigEnv, loadConfigFromFile, mergeConfig, UserConfig } from 'vite';

import { VitePluginConfig } from './Config';
import { externalBuiltins } from './util/plugins';
// eslint-disable-next-line node/no-unpublished-import
import { loadConfigFromFile } from 'vite';

const d = debug('electron-forge:plugin:vite:viteconfig');
import type { VitePluginBuildConfig, VitePluginConfig, VitePluginRendererConfig } from './Config';
// eslint-disable-next-line node/no-unpublished-import
import type { ConfigEnv, UserConfig } from 'vite';

/**
* Vite allows zero-config runs, if the user does not provide `vite.config.js`,
* then the value of `LoadResult` will become `null`.
*/
export type LoadResult = Awaited<ReturnType<typeof loadConfigFromFile>>;
const d = debug('@electron-forge/plugin-vite:ViteConfig');

export default class ViteConfigGenerator {
private readonly baseDir: string;

private rendererConfigCache!: Promise<UserConfig>[];

constructor(private readonly pluginConfig: VitePluginConfig, private readonly projectDir: string, private readonly isProd: boolean) {
this.baseDir = path.join(projectDir, '.vite');
d('Config mode:', this.mode);
}

resolveConfig(config: string, configEnv: Partial<ConfigEnv> = {}) {
// `command` is to be passed as an arguments when the user export a function in `vite.config.js`.
resolveConfig(buildConfig: VitePluginBuildConfig | VitePluginRendererConfig, configEnv: Partial<ConfigEnv> = {}) {
// @see - https://vitejs.dev/config/#conditional-config
configEnv.command ??= this.isProd ? 'build' : 'serve';
// `mode` affects `.env.[mode]` file loading.
// `mode` affects `.env.[mode]` file load.
configEnv.mode ??= this.mode;
return loadConfigFromFile(configEnv as ConfigEnv, config);

// Hack! Pass the forge runtime config to the vite config file in the template.
Object.assign(configEnv, {
root: this.projectDir,
forgeConfig: this.pluginConfig,
forgeConfigSelf: buildConfig,
});

// `configEnv` is to be passed as an arguments when the user export a function in `vite.config.js`.
return loadConfigFromFile(configEnv as ConfigEnv, buildConfig.config);
}

get mode(): string {
Expand All @@ -40,61 +37,15 @@ export default class ViteConfigGenerator {
return this.isProd ? 'production' : 'development';
}

async getDefines(): Promise<Record<string, string>> {
const defines: Record<string, any> = {};
const rendererConfigs = await this.getRendererConfig();
for (const [index, userConfig] of rendererConfigs.entries()) {
const name = this.pluginConfig.renderer[index].name;
if (!name) {
continue;
}
const NAME = name.toUpperCase().replace(/ /g, '_');
// `server.port` is set in `launchRendererDevServers` in `VitePlugin.ts`.
defines[`${NAME}_VITE_DEV_SERVER_URL`] = this.isProd ? undefined : JSON.stringify(`http://localhost:${userConfig?.server?.port}`);
defines[`${NAME}_VITE_NAME`] = JSON.stringify(name);
}
return defines;
}

async getBuildConfig(watch = false): Promise<UserConfig[]> {
async getBuildConfig(): Promise<UserConfig[]> {
if (!Array.isArray(this.pluginConfig.build)) {
throw new Error('"config.build" must be an Array');
}

const define = await this.getDefines();
const plugins = [externalBuiltins()];
const configs = this.pluginConfig.build
.filter(({ entry, config }) => entry || config)
.map<Promise<UserConfig>>(async ({ entry, config }) => {
const defaultConfig: UserConfig = {
// Ensure that each build config loads the .env file correctly.
mode: this.mode,
build: {
lib: entry
? {
entry,
// Electron can only support cjs.
formats: ['cjs'],
fileName: () => '[name].js',
}
: undefined,
// Prevent multiple builds from interfering with each other.
emptyOutDir: false,
// 🚧 Multiple builds may conflict.
outDir: path.join(this.baseDir, 'build'),
watch: watch ? {} : undefined,
minify: this.isProd,
},
clearScreen: false,
define,
plugins,
};
if (config) {
const loadResult = await this.resolveConfig(config);
return mergeConfig(defaultConfig, loadResult?.config ?? {});
}
return defaultConfig;
});
// Prevent load the default `vite.config.js` file.
.filter(({ config }) => config)
.map<Promise<UserConfig>>(async (buildConfig) => (await this.resolveConfig(buildConfig))?.config ?? {});

return await Promise.all(configs);
}
Expand All @@ -104,20 +55,9 @@ export default class ViteConfigGenerator {
throw new Error('"config.renderer" must be an Array');
}

const configs = (this.rendererConfigCache ??= this.pluginConfig.renderer.map(async ({ name, config }) => {
const defaultConfig: UserConfig = {
// Ensure that each build config loads the .env file correctly.
mode: this.mode,
// Make sure that Electron can be loaded into the local file using `loadFile` after packaging.
base: './',
build: {
outDir: path.join(this.baseDir, 'renderer', name),
},
clearScreen: false,
};
const loadResult = (await this.resolveConfig(config)) ?? { path: '', config: {}, dependencies: [] };
return mergeConfig(defaultConfig, loadResult.config);
}));
const configs = this.pluginConfig.renderer
.filter(({ config }) => config)
.map<Promise<UserConfig>>(async (buildConfig) => (await this.resolveConfig(buildConfig))?.config ?? {});

return await Promise.all(configs);
}
Expand Down
Loading

0 comments on commit 29ef4ae

Please sign in to comment.