Skip to content

Commit

Permalink
fix(build): fix workers build for mac
Browse files Browse the repository at this point in the history
  • Loading branch information
lsagetlethias committed Oct 26, 2022
1 parent 96cf0d9 commit 2fc180c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/branch-test-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
$(yarn global bin)/replace "\"version": \"$TMP_CURRENT_VERSION\"" "\"version": \"$TMP_NEXT_VERSION\"" package.json
echo ::set-output name=next-version::$TMP_NEXT_VERSION
yarn compile --no-progress
yarn compile-workers --no-progress
env:
SKIP_SENTRY_UPLOAD: 1
TRACKER_MATOMO_ID_SITE: ${{ secrets.TRACKER_MATOMO_ID_SITE }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
run: yarn --frozen-lockfile --perfer-offline

- name: Compiling
run: yarn compile
run: |
yarn compile --no-progress
yarn compile-workers --no-progress
env:
SKIP_SENTRY_UPLOAD: 1
TRACKER_MATOMO_ID_SITE: ${{ secrets.TRACKER_MATOMO_ID_SITE }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
yarn --frozen-lockfile --perfer-offline
- name: Test if code compile
run: yarn compile --no-progress --display-error-details
run: |
yarn compile --no-progress --display-error-details
yarn compile-workers --no-progress --display-error-details
env:
SKIP_SENTRY_UPLOAD: 1
TRACKER_MATOMO_ID_SITE: ${{ secrets.TRACKER_MATOMO_ID_SITE }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
yarn semantic-release
echo "next-version=$(node -e "console.log(require('./package.json').version)")" >> $GITHUB_OUTPUT
yarn compile --no-progress
yarn compile-workers --no-progress
env:
ARCHIFILTRE_RELEASE_MODE: version
TRACKER_MATOMO_ID_SITE: ${{ steps.nosecrets.outputs.tracker_matomo_id_site }}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"scripts": {
"dev": "electron-webpack dev",
"debug": "cross-env 'ELECTRON_ARGS=[\"--inspect-brk=9229\"]' yarn dev",
"compile": "electron-webpack && webpack --config webpack.workers.config.js",
"compile": "electron-webpack",
"compile-workers": "webpack --config webpack.workers.config.js",
"dist:win": "electron-builder --x64 --win portable msi nsis",
"dist:mac": "electron-builder --mac dmg zip",
"dist:mac-local": "CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac dmg",
Expand Down
7 changes: 7 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface WorkerConfig {
IS_PACKAGED: boolean;
IS_TEST: boolean;
IS_WIN: boolean;
NATIVES_PATH: string;
PRODUCT_CHANNEL: "beta" | "next" | "stable";
STATIC_PATH: string;
}
Expand Down Expand Up @@ -110,6 +111,11 @@ export const STATIC_PATH =
? path.resolve(__dirname, "../../static") // dist / e2e
: __static; // dev

export const NATIVES_PATH =
localWorkerConfig.NATIVES_PATH ?? IS_PACKAGED()
? path.resolve(STATIC_PATH, "../natives") // prod
: path.resolve(__dirname, "../../node_modules"); // dist / e2e | should not be used in dev

export const workerConfig: WorkerConfig = {
APP_CACHE: APP_CACHE(),
APP_DATA: APP_DATA(),
Expand All @@ -121,6 +127,7 @@ export const workerConfig: WorkerConfig = {
IS_PACKAGED: IS_PACKAGED(),
IS_TEST,
IS_WIN,
NATIVES_PATH,
PRODUCT_CHANNEL,
STATIC_PATH,
};
13 changes: 13 additions & 0 deletions src/main/electron-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
APP_CACHE,
APP_DATA,
IS_PACKAGED,
NATIVES_PATH,
STATIC_PATH,
} from "@common/config";

process.env.ELECTRON_APP_DATA = APP_DATA();
process.env.ELECTRON_APP_CACHE = APP_CACHE();
process.env.ELECTRON_IS_PACKAGED = `${IS_PACKAGED()}`;
process.env.ELECTRON_NATIVES_PATH = NATIVES_PATH;
process.env.ELECTRON_STATIC_PATH = STATIC_PATH;
1 change: 1 addition & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@common/utils/overload";
import "./electron-env";

import { IS_DIST_MODE, IS_E2E, IS_PACKAGED } from "@common/config";
import { getIsomorphicModules } from "@common/lib/core/isomorphic";
Expand Down
9 changes: 2 additions & 7 deletions webpack.workers.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const workers = glob
return [name, path.dirname(filePath).split("src/main/")[1], filePath];
})
.reduce((acc, [name, directoryPath, filePath]) => {
console.log({ directoryPath, filePath, name });
acc[path.join(directoryPath, name)] = filePath;
return acc;
}, {});

module.exports = async (
/** @type {import("electron-webpack/out/core").ConfigurationEnv} */ env = {}
) => {
console.info("Compile workers", workers);
env.production = true;
env.autoClean = false;
const config = await webpackMain(env);
Expand All @@ -41,12 +41,7 @@ module.exports = async (
config.module.rules.push({
loader: "string-replace-loader",
options: {
replace: `(() => {
const path = require("path");
const IS_PACKAGED = __dirname.indexOf(path.join("resources/workers/")) > -1;
return path.resolve(process.cwd(), IS_PACKAGED ? "resources/natives/" : "node_modules/", "classic-level/");
})()`,
replace: `require("path").resolve(process.env.ELECTRON_NATIVES_PATH, "classic-level/")`,
search: "__dirname",
},
test: /node_modules\/classic-level\/binding\.js$/,
Expand Down

0 comments on commit 2fc180c

Please sign in to comment.