Skip to content

Commit

Permalink
Fix build action workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Milkshiift committed Oct 29, 2023
1 parent 0c6bf55 commit 2a54ad0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ jobs:
strategy:
matrix:
include:
- name: Windows
- name: Windows64
runner: windows-latest
arch: x64,ia32
- name: Linux
arch: x64
- name: Windows32
runner: windows-latest
arch: ia32
- name: Linux64
runner: ubuntu-latest
arch: x64
- name: LinuxArm64
runner: ubuntu-latest
arch: x64,arm64,armv7l
- name: macOS
arch: arm64
- name: LinuxArmV7
runner: ubuntu-latest
arch: armv7l
- name: macOSIntel
runner: macos-latest
arch: x64
- name: macOSArm
runner: macos-latest
arch: x64,arm64
arch: arm64

name: ${{ matrix.name }} (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
Expand Down
43 changes: 33 additions & 10 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');

const {join} = require("path");
const {readdirSync, unlinkSync} = require("graceful-fs");
const {join, extname} = require("path");
const fs = require("graceful-fs");
const {platform} = require("os");

Expand Down Expand Up @@ -96,8 +95,29 @@ const config = {
}
],
hooks: {
// remove folders & files not to be included in the app
packageAfterCopy: async (config, buildPath, electronVersion, platform, arch) => {
async function cleanUpNodeModules(directory) {
const files = await fs.promises.readdir(directory);
for (const file of files) {
const filePath = join(directory, file);
const stats = await fs.promises.stat(filePath);

if (file.includes("esm") === true || file.includes("bundle") === true || extname(file) === '.ts' || extname(file) === '.map') {
if (stats.isDirectory()) {
await fs.promises.rm(filePath, {recursive: true, force: true});
}
else {
await fs.promises.unlink(filePath);
}

}
else if (stats.isDirectory()) {
await cleanUpNodeModules(filePath);
}
}
}
await cleanUpNodeModules(buildPath)

// folders & files to be included in the app
const appItems = [
'assets',
Expand All @@ -106,25 +126,28 @@ const config = {
'node_modules'
];

readdirSync(buildPath).filter((item) => {
return appItems.indexOf(item) === -1
}).forEach((item) => {
fs.promises.rm(join(buildPath, item), {recursive: true, force: true});
});
// remove root folders & files not to be included in the app
const files = await fs.promises.readdir(buildPath);
for (const file of files) {
const filePath = join(buildPath, file);
if (appItems.includes(file) === false) {
await fs.promises.rm(filePath, {recursive: true, force: true});
}
}
},

// remove unused locales
postPackage: async (config, packageResult) => {
if (platform() === "darwin") return;

const dirPath = join(packageResult.outputPaths[0], "locales");
const files = readdirSync(dirPath);
const files = await fs.promises.readdir(dirPath);

for (const file of files) {
const filePath = join(dirPath, file);

if (file !== "en-US.pak") {
unlinkSync(filePath);
await fs.promises.unlink(filePath);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export function unstrictCSP() {
if (!responseHeaders) return done({});

if (resourceType === "mainFrame") {
// This behaves very strangely. For some, everything works without deleting CSP,
// For some "CSP" works, for some "csp"
delete responseHeaders["Content-Security-Policy"];
delete responseHeaders["content-security-policy"];
} else if (resourceType === "stylesheet") {
// Fix hosts that don't properly set the css content type, such as
Expand Down

0 comments on commit 2a54ad0

Please sign in to comment.