Skip to content

Commit

Permalink
refactor: standardise apps config
Browse files Browse the repository at this point in the history
  • Loading branch information
goosewobbler committed Sep 11, 2024
1 parent eff62c7 commit 0a4f0f2
Show file tree
Hide file tree
Showing 37 changed files with 305 additions and 773 deletions.
12 changes: 1 addition & 11 deletions apps/builder-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,17 @@
"wdio-electron-service": "workspace:*"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"electron-builder": "^25.0.5",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
},
"build": {
"asar": true,
"appId": "com.example-builder-cjs.demo",
Expand Down
16 changes: 0 additions & 16 deletions apps/builder-cjs/rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion apps/builder-esm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

An ESM project for a minimal Electron app, designed to provide E2E testing for `wdio-electron-service`.

The app is built using `electron-builder` and the preload script is bundled as CJS, this is to work around a limitation of Electron's ESM support.
The app is built using `electron-builder` and is not bundled.
15 changes: 2 additions & 13 deletions apps/builder-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"scripts": {
"build": "pnpm build:bundle && pnpm build:package",
"build:bundle": "tsc --outDir dist",
"build:bundle": "tsc",
"build:package": "cp ./src/index.html ./dist && electron-builder -p never",
"build:package:mac-universal": "cp ./src/index.html ./dist && electron-builder -p never -m --universal",
"build:mac-universal": "pnpm build:bundle && pnpm build:package:mac-universal",
Expand All @@ -18,28 +18,17 @@
"wdio-electron-service": "workspace:*"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"electron-builder": "^25.0.5",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
},
"build": {
"asar": true,
"appId": "com.example-builder-esm.demo",
Expand Down
15 changes: 0 additions & 15 deletions apps/builder-esm/rollup.config.js

This file was deleted.

9 changes: 4 additions & 5 deletions apps/builder-esm/src/preload.cts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron';

async function init() {
(async () => {
// util.js is an ESM module so we need to use dynamic import
const { isTest } = await import('./util.js');

if (isTest) {
import('wdio-electron-service/preload');
require('wdio-electron-service/preload');
}

const validChannels = ['increase-window-size', 'decrease-window-size'];
Expand All @@ -15,6 +16,4 @@ async function init() {
contextBridge.exposeInMainWorld('api', {
invoke,
});
}

init();
})();
3 changes: 2 additions & 1 deletion apps/builder-esm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"target": "ESNext",
"types": ["node"],
"typeRoots": ["./node_modules", "./node_modules/@types", "../../@types"]
"typeRoots": ["./node_modules", "./node_modules/@types", "../../@types"],
"outDir": "dist"
},
"include": ["src/*.ts", "src/preload.cts"],
"exclude": ["node_modules"]
Expand Down
11 changes: 4 additions & 7 deletions apps/forge-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@
"@electron-forge/cli": "^7.4.0",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
"resolutions": {
"@electron/asar": "3.2.10"
}
}
2 changes: 1 addition & 1 deletion apps/forge-cjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import { isTest } from './util';
import { isTest } from './util.js';

if (isTest) {
require('wdio-electron-service/main');
Expand Down
2 changes: 1 addition & 1 deletion apps/forge-cjs/src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { contextBridge, ipcRenderer } from 'electron';
import { isTest } from './util';
import { isTest } from './util.js';

if (isTest) {
require('wdio-electron-service/preload');
Expand Down
11 changes: 4 additions & 7 deletions apps/forge-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@
"@electron-forge/cli": "^7.4.0",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
"resolutions": {
"@electron/asar": "3.2.10"
}
}
9 changes: 6 additions & 3 deletions apps/forge-esm/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { defineConfig } from 'rollup';

const nodeResolvePlugin = nodeResolve();
const commonjsPlugin = commonjs();

export default defineConfig([
{
input: 'dist/preload.js',
input: 'dist/preload.cjs',
output: {
file: 'dist/preload.bundle.cjs',
inlineDynamicImports: true,
format: 'cjs',
},
plugins: [nodeResolve(), commonjs()],
plugins: [nodeResolvePlugin, commonjsPlugin],
external: ['electron'],
},
{
Expand All @@ -20,7 +23,7 @@ export default defineConfig([
inlineDynamicImports: true,
format: 'esm',
},
plugins: [nodeResolve()],
plugins: [nodeResolvePlugin],
external: ['electron'],
},
]);
2 changes: 1 addition & 1 deletion apps/forge-esm/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app, BrowserWindow, ipcMain } from 'electron';
import { isTest } from './util.js';

if (isTest) {
import('wdio-electron-service/main');
await import('wdio-electron-service/main');
}

const appPath = app.getAppPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { contextBridge, ipcRenderer } from 'electron';
import { isTest } from './util.js';

const { isTest } = require('./util.js');

if (isTest) {
import('wdio-electron-service/preload');
require('wdio-electron-service/preload');
}

const validChannels = ['increase-window-size', 'decrease-window-size'];
Expand Down
2 changes: 1 addition & 1 deletion apps/forge-esm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"outDir": "dist"
},
"exclude": ["node_modules"],
"include": ["src/*.ts"]
"include": ["src/*.ts", "src/preload.cts"]
}
10 changes: 2 additions & 8 deletions apps/no-binary-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
}
}
7 changes: 5 additions & 2 deletions apps/no-binary-cjs/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { defineConfig } from 'rollup';

const nodeResolvePlugin = nodeResolve();
const commonjsPlugin = commonjs();

export default defineConfig([
{
input: 'dist/preload.js',
Expand All @@ -10,7 +13,7 @@ export default defineConfig([
inlineDynamicImports: true,
format: 'cjs',
},
plugins: [nodeResolve(), commonjs()],
plugins: [nodeResolvePlugin, commonjsPlugin],
external: ['electron'],
},
{
Expand All @@ -20,7 +23,7 @@ export default defineConfig([
inlineDynamicImports: true,
format: 'cjs',
},
plugins: [nodeResolve(), commonjs()],
plugins: [nodeResolvePlugin, commonjsPlugin],
external: ['electron'],
},
]);
2 changes: 1 addition & 1 deletion apps/no-binary-cjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import { isTest } from './util';
import { isTest } from './util.js';

if (isTest) {
require('wdio-electron-service/main');
Expand Down
2 changes: 1 addition & 1 deletion apps/no-binary-cjs/src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { contextBridge, ipcRenderer } from 'electron';
import { isTest } from './util';
import { isTest } from './util.js';

if (isTest) {
require('wdio-electron-service/preload');
Expand Down
10 changes: 2 additions & 8 deletions apps/no-binary-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.16.1",
"@wdio/cli": "^9.0.9",
"@wdio/globals": "^9.0.9",
"@wdio/local-runner": "^9.0.9",
"@wdio/mocha-framework": "^9.0.8",
"cross-env": "^7.0.3",
"electron": "^32.0.2",
"global-jsdom": "^24.0.0",
"jsdom": "^24.1.1",
"rollup": "^4.21.2",
"ts-loader": "^9.4.4",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"webdriverio": "^9.0.9"
},
"peerDependencies": {
"typescript": "5.2.2"
}
}
9 changes: 6 additions & 3 deletions apps/no-binary-esm/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { defineConfig } from 'rollup';

const nodeResolvePlugin = nodeResolve();
const commonjsPlugin = commonjs();

export default defineConfig([
{
input: 'dist/preload.js',
input: 'dist/preload.cjs',
output: {
file: 'dist/preload.bundle.cjs',
inlineDynamicImports: true,
format: 'cjs',
},
plugins: [nodeResolve(), commonjs()],
plugins: [nodeResolvePlugin, commonjsPlugin],
external: ['electron'],
},
{
Expand All @@ -20,7 +23,7 @@ export default defineConfig([
inlineDynamicImports: true,
format: 'esm',
},
plugins: [nodeResolve()],
plugins: [nodeResolvePlugin],
external: ['electron'],
},
]);
2 changes: 1 addition & 1 deletion apps/no-binary-esm/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app, BrowserWindow, ipcMain } from 'electron';
import { isTest } from './util.js';

if (isTest) {
import('wdio-electron-service/main');
await import('wdio-electron-service/main');
}

const appPath = app.getAppPath();
Expand Down
Loading

0 comments on commit 0a4f0f2

Please sign in to comment.