Skip to content

Commit c369190

Browse files
committed
feat: add integrity digest plugin
1 parent 3d524f7 commit c369190

File tree

4 files changed

+203
-0
lines changed

4 files changed

+203
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## @electron-forge/plugin-integrity-digest
2+
3+
This plugin provides a `packageAfterCopy` hook for calculating and storing integrity digests when packaging with Electron Forge.
4+
5+
### Usage
6+
7+
Install `@electron-forge/plugin-integrity-digest` and add this plugin to the `plugins` array in your Forge configuration:
8+
9+
```shell
10+
# Yarn
11+
yarn add --dev @electron-forge/plugin-integrity-digest
12+
13+
# npm
14+
npm i -D @electron-forge/plugin-integrity-digest
15+
```
16+
17+
```js
18+
// forge.config.js
19+
20+
const { IntegrityDigestPlugin } = require('@electron-forge/plugin-integrity-digest');
21+
22+
const forgeConfig = {
23+
plugins: [new IntegrityDigestPlugin()],
24+
};
25+
26+
module.exports = forgeConfig;
27+
```
28+
29+
If desired, you can pass a specific version of integrity digest to calculate and store. Currently, the only version is `1`.
30+
31+
```js
32+
const forgeConfig = {
33+
plugins: [new IntegrityDigestPlugin({version: 1})],
34+
};
35+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@electron-forge/plugin-integrity-digest",
3+
"version": "7.11.1",
4+
"description": "A plugin for generating integrity digests in Electron Forge",
5+
"repository": "https://github.com/electron/forge",
6+
"author": "Noah Gregory <noahmgregory@gmail.com>",
7+
"license": "MIT",
8+
"main": "dist/IntegrityDigestPlugin.js",
9+
"files": [
10+
"dist",
11+
"src",
12+
"package.json",
13+
"README.md"
14+
],
15+
"typings": "dist/IntegrityDigestPlugin.d.ts",
16+
"engines": {
17+
"node": ">= 16.4.0"
18+
},
19+
"dependencies": {
20+
"@electron-forge/plugin-base": "workspace:*",
21+
"@electron-forge/shared-types": "workspace:*",
22+
"@electron/asar": "4.1.0"
23+
},
24+
"publishConfig": {
25+
"access": "public"
26+
}
27+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import path from 'node:path';
2+
3+
import {
4+
calculateIntegrityDigestForApp,
5+
setStoredIntegrityDigestForApp,
6+
// eslint-disable-next-line import/no-unresolved -- @electron/asar is ESM; ESLint can't resolve it.
7+
} from '@electron/asar';
8+
import { namedHookWithTaskFn, PluginBase } from '@electron-forge/plugin-base';
9+
import {
10+
ForgeMultiHookMap,
11+
type ForgePlatform,
12+
} from '@electron-forge/shared-types';
13+
14+
type IntegrityDigestVersion = 1; // TODO: Export this from @electron/asar
15+
16+
export type IntegrityDigestConfig = {
17+
version: IntegrityDigestVersion;
18+
};
19+
20+
export default class IntegrityDigestPlugin extends PluginBase<IntegrityDigestConfig> {
21+
name = 'integrity-digest';
22+
23+
constructor(config: IntegrityDigestConfig = { version: 1 }) {
24+
super(config);
25+
}
26+
27+
getHooks(): ForgeMultiHookMap {
28+
return {
29+
packageAfterCopy: namedHookWithTaskFn<'packageAfterCopy'>(
30+
async (
31+
listrTask,
32+
resolvedForgeConfig,
33+
resourcesPath,
34+
electronVersion,
35+
platform,
36+
) => {
37+
const { version } = this.config;
38+
const applePlatforms: ForgePlatform[] = ['darwin', 'mas'];
39+
if (!applePlatforms.includes(platform)) return;
40+
// `resourcesPath` points to `<App>.app/Contents/Resources/app`, so go up 3 levels to reach `<App>.app`.
41+
const appPath = path.resolve(resourcesPath, '../../..');
42+
const integrityDigest = calculateIntegrityDigestForApp(
43+
appPath,
44+
version,
45+
);
46+
setStoredIntegrityDigestForApp(appPath, integrityDigest);
47+
},
48+
'Calculating and Storing Integrity Digest',
49+
),
50+
};
51+
}
52+
}
53+
54+
export { IntegrityDigestPlugin };

yarn.lock

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,16 @@ __metadata:
11151115
languageName: unknown
11161116
linkType: soft
11171117

1118+
"@electron-forge/plugin-integrity-digest@workspace:packages/plugin/integrity-digest":
1119+
version: 0.0.0-use.local
1120+
resolution: "@electron-forge/plugin-integrity-digest@workspace:packages/plugin/integrity-digest"
1121+
dependencies:
1122+
"@electron-forge/plugin-base": "workspace:*"
1123+
"@electron-forge/shared-types": "workspace:*"
1124+
"@electron/asar": "npm:4.1.0"
1125+
languageName: unknown
1126+
linkType: soft
1127+
11181128
"@electron-forge/plugin-local-electron@workspace:packages/plugin/local-electron":
11191129
version: 0.0.0-use.local
11201130
resolution: "@electron-forge/plugin-local-electron@workspace:packages/plugin/local-electron"
@@ -1412,6 +1422,23 @@ __metadata:
14121422
languageName: unknown
14131423
linkType: soft
14141424

1425+
"@electron/asar@npm:4.1.0":
1426+
version: 4.1.0
1427+
resolution: "@electron/asar@npm:4.1.0"
1428+
dependencies:
1429+
commander: "npm:^13.1.0"
1430+
glob: "npm:^13.0.2"
1431+
minimatch: "npm:^10.0.1"
1432+
plist: "npm:^3.1.0"
1433+
dependenciesMeta:
1434+
electron:
1435+
built: true
1436+
bin:
1437+
asar: bin/asar.mjs
1438+
checksum: 10c0/f75565faeae0e54170ec625ceb5339d0f5c3fec79ff6d6794b0172aa2c5d96a2a9d189943c78004875b53d0010f39925dc6d6fcc76b324571986e68f82d87b0a
1439+
languageName: node
1440+
linkType: hard
1441+
14151442
"@electron/asar@npm:^3.2.1, @electron/asar@npm:^3.2.13, @electron/asar@npm:^3.3.1":
14161443
version: 3.4.1
14171444
resolution: "@electron/asar@npm:3.4.1"
@@ -6782,6 +6809,13 @@ __metadata:
67826809
languageName: node
67836810
linkType: hard
67846811

6812+
"balanced-match@npm:^4.0.2":
6813+
version: 4.0.4
6814+
resolution: "balanced-match@npm:4.0.4"
6815+
checksum: 10c0/07e86102a3eb2ee2a6a1a89164f29d0dbaebd28f2ca3f5ca786f36b8b23d9e417eb3be45a4acf754f837be5ac0a2317de90d3fcb7f4f4dc95720a1f36b26a17b
6816+
languageName: node
6817+
linkType: hard
6818+
67856819
"bare-events@npm:^2.7.0":
67866820
version: 2.8.2
67876821
resolution: "bare-events@npm:2.8.2"
@@ -6973,6 +7007,15 @@ __metadata:
69737007
languageName: node
69747008
linkType: hard
69757009

7010+
"brace-expansion@npm:^5.0.2":
7011+
version: 5.0.3
7012+
resolution: "brace-expansion@npm:5.0.3"
7013+
dependencies:
7014+
balanced-match: "npm:^4.0.2"
7015+
checksum: 10c0/e474d300e581ec56851b3863ff1cf18573170c6d06deb199ccbd03b2119c36975f6ce2abc7b770f5bebddc1ab022661a9fea9b4d56f33315d7bef54d8793869e
7016+
languageName: node
7017+
linkType: hard
7018+
69767019
"braces@npm:^3.0.3, braces@npm:~3.0.2":
69777020
version: 3.0.3
69787021
resolution: "braces@npm:3.0.3"
@@ -7688,6 +7731,13 @@ __metadata:
76887731
languageName: node
76897732
linkType: hard
76907733

7734+
"commander@npm:^13.1.0":
7735+
version: 13.1.0
7736+
resolution: "commander@npm:13.1.0"
7737+
checksum: 10c0/7b8c5544bba704fbe84b7cab2e043df8586d5c114a4c5b607f83ae5060708940ed0b5bd5838cf8ce27539cde265c1cbd59ce3c8c6b017ed3eec8943e3a415164
7738+
languageName: node
7739+
linkType: hard
7740+
76917741
"commander@npm:^2.19.0, commander@npm:^2.20.0":
76927742
version: 2.20.3
76937743
resolution: "commander@npm:2.20.3"
@@ -11454,6 +11504,17 @@ __metadata:
1145411504
languageName: node
1145511505
linkType: hard
1145611506

11507+
"glob@npm:^13.0.2":
11508+
version: 13.0.6
11509+
resolution: "glob@npm:13.0.6"
11510+
dependencies:
11511+
minimatch: "npm:^10.2.2"
11512+
minipass: "npm:^7.1.3"
11513+
path-scurry: "npm:^2.0.2"
11514+
checksum: 10c0/269c236f11a9b50357fe7a8c6aadac667e01deb5242b19c84975628f05f4438d8ee1354bb62c5d6c10f37fd59911b54d7799730633a2786660d8c69f1d18120a
11515+
languageName: node
11516+
linkType: hard
11517+
1145711518
"glob@npm:^7.1.3, glob@npm:^7.1.6":
1145811519
version: 7.2.3
1145911520
resolution: "glob@npm:7.2.3"
@@ -14871,6 +14932,15 @@ __metadata:
1487114932
languageName: node
1487214933
linkType: hard
1487314934

14935+
"minimatch@npm:^10.0.1, minimatch@npm:^10.2.2":
14936+
version: 10.2.4
14937+
resolution: "minimatch@npm:10.2.4"
14938+
dependencies:
14939+
brace-expansion: "npm:^5.0.2"
14940+
checksum: 10c0/35f3dfb7b99b51efd46afd378486889f590e7efb10e0f6a10ba6800428cf65c9a8dedb74427d0570b318d749b543dc4e85f06d46d2858bc8cac7e1eb49a95945
14941+
languageName: node
14942+
linkType: hard
14943+
1487414944
"minimatch@npm:^10.0.3":
1487514945
version: 10.0.3
1487614946
resolution: "minimatch@npm:10.0.3"
@@ -15069,6 +15139,13 @@ __metadata:
1506915139
languageName: node
1507015140
linkType: hard
1507115141

15142+
"minipass@npm:^7.1.3":
15143+
version: 7.1.3
15144+
resolution: "minipass@npm:7.1.3"
15145+
checksum: 10c0/539da88daca16533211ea5a9ee98dc62ff5742f531f54640dd34429e621955e91cc280a91a776026264b7f9f6735947629f920944e9c1558369e8bf22eb33fbb
15146+
languageName: node
15147+
linkType: hard
15148+
1507215149
"minizlib@npm:^2.1.1, minizlib@npm:^2.1.2":
1507315150
version: 2.1.2
1507415151
resolution: "minizlib@npm:2.1.2"
@@ -16479,6 +16556,16 @@ __metadata:
1647916556
languageName: node
1648016557
linkType: hard
1648116558

16559+
"path-scurry@npm:^2.0.2":
16560+
version: 2.0.2
16561+
resolution: "path-scurry@npm:2.0.2"
16562+
dependencies:
16563+
lru-cache: "npm:^11.0.0"
16564+
minipass: "npm:^7.1.2"
16565+
checksum: 10c0/b35ad37cf6557a87fd057121ce2be7695380c9138d93e87ae928609da259ea0a170fac6f3ef1eb3ece8a068e8b7f2f3adf5bb2374cf4d4a57fe484954fcc9482
16566+
languageName: node
16567+
linkType: hard
16568+
1648216569
"path-to-regexp@npm:0.1.12":
1648316570
version: 0.1.12
1648416571
resolution: "path-to-regexp@npm:0.1.12"

0 commit comments

Comments
 (0)