Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57201b124c | ||
|
|
20b1b02c11 | ||
|
|
b6f0c88db4 | ||
|
|
bb304ce10b | ||
|
|
8e2842b4a3 | ||
|
|
02119d5a83 | ||
|
|
1948f1caa9 | ||
|
|
52fa9a2a78 | ||
|
|
4e631b7ca2 | ||
|
|
fe1a0e06b0 | ||
|
|
9a808beecc | ||
|
|
381ca1a748 | ||
|
|
0d2b974dcc | ||
|
|
0cfaddcc77 | ||
|
|
fddff57c15 | ||
|
|
b02ce7697f | ||
|
|
85b1f90f2c | ||
|
|
3ecbbd5710 | ||
|
|
8bff0b7579 | ||
|
|
283773eb45 | ||
|
|
a99ae94fc2 | ||
|
|
0d70c1c39f | ||
|
|
ba587f0a08 | ||
|
|
580002844b | ||
|
|
365775311f | ||
|
|
1fc0005ae8 | ||
|
|
64cbc83faf | ||
|
|
691e4ef31d | ||
|
|
d902197267 | ||
|
|
72a3f83d27 | ||
|
|
3cc1365561 | ||
|
|
3a30fe989b | ||
|
|
01dfb8a963 | ||
|
|
3bd173d61a | ||
|
|
479e80d6a9 | ||
|
|
2c3c1a60a0 | ||
|
|
cdcbe58dee | ||
|
|
38ab1c3559 | ||
|
|
9f86e1dd2b | ||
|
|
a626463c95 | ||
|
|
36b58a84f3 | ||
|
|
fe8d99e31d | ||
|
|
d336231787 | ||
|
|
6cd85d89aa | ||
|
|
7b1c610963 | ||
|
|
060a299188 | ||
|
|
64420e4c32 | ||
|
|
2b411ce98b | ||
|
|
e80eed7f69 | ||
|
|
6053796432 | ||
|
|
0a1d0f916c | ||
|
|
1d4e198ba5 | ||
|
|
2f06fcab5f | ||
|
|
e7d57dd1e5 | ||
|
|
d9b1b4104f | ||
|
|
b445fa1974 | ||
|
|
f265d1f5e2 | ||
|
|
a05a5e6db8 | ||
|
|
8c55e5b4f3 | ||
|
|
477a52e779 |
@@ -1,46 +1,35 @@
|
||||
step-restore-cache: &step-restore-cache
|
||||
restore_cache:
|
||||
keys:
|
||||
- v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
|
||||
- v1-dependencies-{{ arch }}
|
||||
|
||||
steps-test: &steps-test
|
||||
steps:
|
||||
- checkout
|
||||
- *step-restore-cache
|
||||
- run: yarn --frozen-lockfile
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
|
||||
- run: yarn build
|
||||
- run: yarn test
|
||||
|
||||
version: 2.1
|
||||
jobs:
|
||||
test:
|
||||
macos:
|
||||
xcode: "12.2.0"
|
||||
<<: *steps-test
|
||||
|
||||
release:
|
||||
docker:
|
||||
- image: circleci/node:14.15
|
||||
steps:
|
||||
- checkout
|
||||
- *step-restore-cache
|
||||
- run: yarn --frozen-lockfile
|
||||
- run: npx semantic-release
|
||||
orbs:
|
||||
cfa: continuousauth/npm@2.0.0
|
||||
node: electronjs/node@2.1.0
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
test_and_release:
|
||||
# Run the test jobs first, then the release only when all the test jobs are successful
|
||||
jobs:
|
||||
- test
|
||||
- release:
|
||||
- node/test:
|
||||
executor: node/macos
|
||||
name: test-mac-<< matrix.node-version >>
|
||||
override-ci-command: yarn install --frozen-lockfile --ignore-engines
|
||||
test-steps:
|
||||
- node/install-rosetta
|
||||
- run: yarn build
|
||||
- run: yarn lint
|
||||
- run: yarn test
|
||||
use-test-steps: true
|
||||
matrix:
|
||||
alias: test
|
||||
parameters:
|
||||
node-version:
|
||||
- 20.5.0
|
||||
- 18.17.0
|
||||
- 16.20.1
|
||||
- cfa/release:
|
||||
requires:
|
||||
- test
|
||||
filters:
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
- main
|
||||
context: cfa-release
|
||||
|
||||
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* @electron/wg-ecosystem
|
||||
29
.github/workflows/add-to-project.yml
vendored
Normal file
29
.github/workflows/add-to-project.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Add to Ecosystem WG Project
|
||||
|
||||
on:
|
||||
issues:
|
||||
types:
|
||||
- opened
|
||||
pull_request_target:
|
||||
types:
|
||||
- opened
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
add-to-project:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Generate GitHub App token
|
||||
uses: electron/github-app-auth-action@384fd19694fe7b6dcc9a684746c6976ad78228ae # v1.1.1
|
||||
id: generate-token
|
||||
with:
|
||||
creds: ${{ secrets.ECOSYSTEM_ISSUE_TRIAGE_GH_APP_CREDS }}
|
||||
org: electron
|
||||
- name: Add to Project
|
||||
uses: dsanders11/project-actions/add-item@3a81985616963f32fae17d1d1b406c631f3201a1 # v1.1.0
|
||||
with:
|
||||
field: Opened
|
||||
field-value: ${{ github.event.pull_request.created_at || github.event.issue.created_at }}
|
||||
project-number: 89
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
26
.github/workflows/semantic.yml
vendored
Normal file
26
.github/workflows/semantic.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: "Check Semantic Commit"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- edited
|
||||
- synchronize
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
main:
|
||||
permissions:
|
||||
pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs
|
||||
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
|
||||
name: Validate PR Title
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: semantic-pull-request
|
||||
uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54 # v5.2.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
validateSingleCommit: false
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,7 @@
|
||||
node_modules
|
||||
dist
|
||||
entry-asar/*.js*
|
||||
entry-asar/*.ts
|
||||
*.app
|
||||
test/fixtures/apps
|
||||
coverage
|
||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
yarn lint-staged
|
||||
@@ -4,6 +4,7 @@
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@continuous-auth/semantic-release-npm",
|
||||
"@semantic-release/github"
|
||||
]
|
||||
],
|
||||
"branches": [ "main" ]
|
||||
}
|
||||
|
||||
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Contributors to the Electron project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
> Create universal macOS Electron applications
|
||||
|
||||
[](https://circleci.com/gh/electron/universal)
|
||||
[](https://circleci.com/gh/electron/universal)
|
||||
[](https://npm.im/@electron/universal)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
19
entry-asar/ambient.d.ts
vendored
Normal file
19
entry-asar/ambient.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
declare namespace NodeJS {
|
||||
interface Process extends EventEmitter {
|
||||
// This is an undocumented private API. It exists.
|
||||
_archPath: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'electron' {
|
||||
const app: Electron.App;
|
||||
|
||||
namespace Electron {
|
||||
interface App {
|
||||
getAppPath: () => string;
|
||||
setAppPath: (p: string) => void;
|
||||
}
|
||||
}
|
||||
|
||||
export { app };
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
if (process.arch === 'arm64') {
|
||||
process._archPath = require.resolve('../app-arm64.asar');
|
||||
} else {
|
||||
process._archPath = require.resolve('../app-x64.asar');
|
||||
}
|
||||
|
||||
require(process._archPath);
|
||||
27
entry-asar/has-asar.ts
Normal file
27
entry-asar/has-asar.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { app } from 'electron';
|
||||
import path from 'path';
|
||||
|
||||
if (process.arch === 'arm64') {
|
||||
setPaths('arm64');
|
||||
} else {
|
||||
setPaths('x64');
|
||||
}
|
||||
|
||||
function setPaths(platform: string) {
|
||||
// This should return the full path, ending in something like
|
||||
// Notion.app/Contents/Resources/app.asar
|
||||
const appPath = app.getAppPath();
|
||||
const asarFile = `app-${platform}.asar`;
|
||||
|
||||
// Maybe we'll handle this in Electron one day
|
||||
if (path.basename(appPath) === 'app.asar') {
|
||||
const platformAppPath = path.join(path.dirname(appPath), asarFile);
|
||||
|
||||
// This is an undocumented API. It exists.
|
||||
app.setAppPath(platformAppPath);
|
||||
}
|
||||
|
||||
process._archPath = require.resolve(`../${asarFile}`);
|
||||
}
|
||||
|
||||
require(process._archPath);
|
||||
@@ -1,7 +0,0 @@
|
||||
if (process.arch === 'arm64') {
|
||||
process._archPath = require.resolve('../app-arm64');
|
||||
} else {
|
||||
process._archPath = require.resolve('../app-x64');
|
||||
}
|
||||
|
||||
require(process._archPath);
|
||||
27
entry-asar/no-asar.ts
Normal file
27
entry-asar/no-asar.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { app } from 'electron';
|
||||
import path from 'path';
|
||||
|
||||
if (process.arch === 'arm64') {
|
||||
setPaths('arm64');
|
||||
} else {
|
||||
setPaths('x64');
|
||||
}
|
||||
|
||||
function setPaths(platform: string) {
|
||||
// This should return the full path, ending in something like
|
||||
// Notion.app/Contents/Resources/app
|
||||
const appPath = app.getAppPath();
|
||||
const appFolder = `app-${platform}`;
|
||||
|
||||
// Maybe we'll handle this in Electron one day
|
||||
if (path.basename(appPath) === 'app') {
|
||||
const platformAppPath = path.join(path.dirname(appPath), appFolder);
|
||||
|
||||
// This is an undocumented private API. It exists.
|
||||
app.setAppPath(platformAppPath);
|
||||
}
|
||||
|
||||
process._archPath = require.resolve(`../${appFolder}`);
|
||||
}
|
||||
|
||||
require(process._archPath);
|
||||
14
jest.config.js
Normal file
14
jest.config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
transform: {
|
||||
'.': [
|
||||
'ts-jest',
|
||||
{
|
||||
tsconfig: 'tsconfig.jest.json'
|
||||
}
|
||||
]
|
||||
},
|
||||
globalSetup: './jest.setup.ts'
|
||||
};
|
||||
57
jest.setup.ts
Normal file
57
jest.setup.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { downloadArtifact } from '@electron/get';
|
||||
import * as zip from 'cross-zip';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
const asarsDir = path.resolve(__dirname, 'test', 'fixtures', 'asars');
|
||||
const appsDir = path.resolve(__dirname, 'test', 'fixtures', 'apps');
|
||||
|
||||
const templateApp = async (
|
||||
name: string,
|
||||
arch: string,
|
||||
modify: (appPath: string) => Promise<void>,
|
||||
) => {
|
||||
const electronZip = await downloadArtifact({
|
||||
artifactName: 'electron',
|
||||
version: '27.0.0',
|
||||
platform: 'darwin',
|
||||
arch,
|
||||
});
|
||||
const appPath = path.resolve(appsDir, name);
|
||||
zip.unzipSync(electronZip, appsDir);
|
||||
await fs.rename(path.resolve(appsDir, 'Electron.app'), appPath);
|
||||
await fs.remove(path.resolve(appPath, 'Contents', 'Resources', 'default_app.asar'));
|
||||
await modify(appPath);
|
||||
};
|
||||
|
||||
export default async () => {
|
||||
await fs.remove(appsDir);
|
||||
await fs.mkdirp(appsDir);
|
||||
await templateApp('Asar.app', 'arm64', async (appPath) => {
|
||||
await fs.copy(
|
||||
path.resolve(asarsDir, 'app.asar'),
|
||||
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
|
||||
);
|
||||
});
|
||||
|
||||
await templateApp('X64Asar.app', 'x64', async (appPath) => {
|
||||
await fs.copy(
|
||||
path.resolve(asarsDir, 'app.asar'),
|
||||
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
|
||||
);
|
||||
});
|
||||
|
||||
await templateApp('NoAsar.app', 'arm64', async (appPath) => {
|
||||
await fs.copy(
|
||||
path.resolve(asarsDir, 'app'),
|
||||
path.resolve(appPath, 'Contents', 'Resources', 'app'),
|
||||
);
|
||||
});
|
||||
|
||||
await templateApp('X64NoAsar.app', 'x64', async (appPath) => {
|
||||
await fs.copy(
|
||||
path.resolve(asarsDir, 'app'),
|
||||
path.resolve(appPath, 'Contents', 'Resources', 'app'),
|
||||
);
|
||||
});
|
||||
};
|
||||
58
package.json
58
package.json
@@ -10,47 +10,61 @@
|
||||
"apple silicon",
|
||||
"universal"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/electron/universal.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
"node": ">=16.4"
|
||||
},
|
||||
"files": [
|
||||
"dist/*",
|
||||
"entry-asar/*",
|
||||
"!entry-asar/**/*.ts",
|
||||
"README.md"
|
||||
],
|
||||
"author": "Samuel Attard",
|
||||
"scripts": {
|
||||
"build": "tsc && tsc -p tsconfig.esm.json",
|
||||
"lint": "prettier --check \"src/**/*.ts\"",
|
||||
"build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.entry-asar.json",
|
||||
"lint": "prettier --check \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
||||
"prettier:write": "prettier --write \"{src,entry-asar,test}/**/*.ts\" \"*.ts\"",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "exit 0"
|
||||
"test": "jest",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@continuous-auth/semantic-release-npm": "^2.0.0",
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/fs-extra": "^9.0.4",
|
||||
"@types/node": "^14.14.7",
|
||||
"husky": "^4.3.0",
|
||||
"lint-staged": "^10.5.1",
|
||||
"prettier": "^2.1.2",
|
||||
"semantic-release": "^17.2.2",
|
||||
"typescript": "^4.0.5"
|
||||
"@continuous-auth/semantic-release-npm": "^4.0.0",
|
||||
"@electron/get": "^3.0.0",
|
||||
"@types/cross-zip": "^4.0.1",
|
||||
"@types/debug": "^4.1.10",
|
||||
"@types/fs-extra": "^11.0.3",
|
||||
"@types/jest": "^29.5.7",
|
||||
"@types/minimatch": "^5.1.2",
|
||||
"@types/node": "^20.8.10",
|
||||
"@types/plist": "^3.0.4",
|
||||
"cross-zip": "^4.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"lint-staged": "^15.0.2",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@malept/cross-spawn-promise": "^1.1.0",
|
||||
"asar": "^3.0.3",
|
||||
"@electron/asar": "^3.2.7",
|
||||
"@malept/cross-spawn-promise": "^2.0.0",
|
||||
"debug": "^4.3.1",
|
||||
"dir-compare": "^2.4.0",
|
||||
"fs-extra": "^9.0.1"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged"
|
||||
}
|
||||
"dir-compare": "^4.2.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"minimatch": "^9.0.3",
|
||||
"plist": "^3.1.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": [
|
||||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"resolutions": {
|
||||
"jackspeak": "2.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,41 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import asar from '@electron/asar';
|
||||
import { execFileSync } from 'child_process';
|
||||
import crypto from 'crypto';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { minimatch } from 'minimatch';
|
||||
import os from 'os';
|
||||
import { d } from './debug';
|
||||
|
||||
const LIPO = 'lipo';
|
||||
|
||||
export enum AsarMode {
|
||||
NO_ASAR,
|
||||
HAS_ASAR,
|
||||
}
|
||||
|
||||
export type MergeASARsOptions = {
|
||||
x64AsarPath: string;
|
||||
arm64AsarPath: string;
|
||||
outputAsarPath: string;
|
||||
|
||||
singleArchFiles?: string;
|
||||
};
|
||||
|
||||
// See: https://github.com/apple-opensource-mirror/llvmCore/blob/0c60489d96c87140db9a6a14c6e82b15f5e5d252/include/llvm/Object/MachOFormat.h#L108-L112
|
||||
const MACHO_MAGIC = new Set([
|
||||
// 32-bit Mach-O
|
||||
0xfeedface, 0xcefaedfe,
|
||||
|
||||
// 64-bit Mach-O
|
||||
0xfeedfacf, 0xcffaedfe,
|
||||
]);
|
||||
|
||||
const MACHO_UNIVERSAL_MAGIC = new Set([
|
||||
// universal
|
||||
0xcafebabe, 0xbebafeca,
|
||||
]);
|
||||
|
||||
export const detectAsarMode = async (appPath: string) => {
|
||||
d('checking asar mode of', appPath);
|
||||
const asarPath = path.resolve(appPath, 'Contents', 'Resources', 'app.asar');
|
||||
@@ -19,3 +48,176 @@ export const detectAsarMode = async (appPath: string) => {
|
||||
d('determined has asar');
|
||||
return AsarMode.HAS_ASAR;
|
||||
};
|
||||
|
||||
export const generateAsarIntegrity = (asarPath: string) => {
|
||||
return {
|
||||
algorithm: 'SHA256' as const,
|
||||
hash: crypto
|
||||
.createHash('SHA256')
|
||||
.update(asar.getRawHeader(asarPath).headerString)
|
||||
.digest('hex'),
|
||||
};
|
||||
};
|
||||
|
||||
function toRelativePath(file: string): string {
|
||||
return file.replace(/^\//, '');
|
||||
}
|
||||
|
||||
function isDirectory(a: string, file: string): boolean {
|
||||
return Boolean('files' in asar.statFile(a, file));
|
||||
}
|
||||
|
||||
function checkSingleArch(archive: string, file: string, allowList?: string): void {
|
||||
if (allowList === undefined || !minimatch(file, allowList, { matchBase: true })) {
|
||||
throw new Error(
|
||||
`Detected unique file "${file}" in "${archive}" not covered by ` +
|
||||
`allowList rule: "${allowList}"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const mergeASARs = async ({
|
||||
x64AsarPath,
|
||||
arm64AsarPath,
|
||||
outputAsarPath,
|
||||
singleArchFiles,
|
||||
}: MergeASARsOptions): Promise<void> => {
|
||||
d(`merging ${x64AsarPath} and ${arm64AsarPath}`);
|
||||
|
||||
const x64Files = new Set(asar.listPackage(x64AsarPath).map(toRelativePath));
|
||||
const arm64Files = new Set(asar.listPackage(arm64AsarPath).map(toRelativePath));
|
||||
|
||||
//
|
||||
// Build set of unpacked directories and files
|
||||
//
|
||||
|
||||
const unpackedFiles = new Set<string>();
|
||||
|
||||
function buildUnpacked(a: string, fileList: Set<string>): void {
|
||||
for (const file of fileList) {
|
||||
const stat = asar.statFile(a, file);
|
||||
|
||||
if (!('unpacked' in stat) || !stat.unpacked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('files' in stat) {
|
||||
continue;
|
||||
}
|
||||
unpackedFiles.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
buildUnpacked(x64AsarPath, x64Files);
|
||||
buildUnpacked(arm64AsarPath, arm64Files);
|
||||
|
||||
//
|
||||
// Build list of files/directories unique to each asar
|
||||
//
|
||||
|
||||
for (const file of x64Files) {
|
||||
if (!arm64Files.has(file)) {
|
||||
checkSingleArch(x64AsarPath, file, singleArchFiles);
|
||||
}
|
||||
}
|
||||
const arm64Unique = [];
|
||||
for (const file of arm64Files) {
|
||||
if (!x64Files.has(file)) {
|
||||
checkSingleArch(arm64AsarPath, file, singleArchFiles);
|
||||
arm64Unique.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Find common bindings with different content
|
||||
//
|
||||
|
||||
const commonBindings = [];
|
||||
for (const file of x64Files) {
|
||||
if (!arm64Files.has(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip directories
|
||||
if (isDirectory(x64AsarPath, file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const x64Content = asar.extractFile(x64AsarPath, file);
|
||||
const arm64Content = asar.extractFile(arm64AsarPath, file);
|
||||
|
||||
if (x64Content.compare(arm64Content) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
MACHO_UNIVERSAL_MAGIC.has(x64Content.readUInt32LE(0)) &&
|
||||
MACHO_UNIVERSAL_MAGIC.has(arm64Content.readUInt32LE(0))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!MACHO_MAGIC.has(x64Content.readUInt32LE(0))) {
|
||||
throw new Error(`Can't reconcile two non-macho files ${file}`);
|
||||
}
|
||||
|
||||
commonBindings.push(file);
|
||||
}
|
||||
|
||||
//
|
||||
// Extract both
|
||||
//
|
||||
|
||||
const x64Dir = await fs.mkdtemp(path.join(os.tmpdir(), 'x64-'));
|
||||
const arm64Dir = await fs.mkdtemp(path.join(os.tmpdir(), 'arm64-'));
|
||||
|
||||
try {
|
||||
d(`extracting ${x64AsarPath} to ${x64Dir}`);
|
||||
asar.extractAll(x64AsarPath, x64Dir);
|
||||
|
||||
d(`extracting ${arm64AsarPath} to ${arm64Dir}`);
|
||||
asar.extractAll(arm64AsarPath, arm64Dir);
|
||||
|
||||
for (const file of arm64Unique) {
|
||||
const source = path.resolve(arm64Dir, file);
|
||||
const destination = path.resolve(x64Dir, file);
|
||||
|
||||
if (isDirectory(arm64AsarPath, file)) {
|
||||
d(`creating unique directory: ${file}`);
|
||||
await fs.mkdirp(destination);
|
||||
continue;
|
||||
}
|
||||
|
||||
d(`xopying unique file: ${file}`);
|
||||
await fs.mkdirp(path.dirname(destination));
|
||||
await fs.copy(source, destination);
|
||||
}
|
||||
|
||||
for (const binding of commonBindings) {
|
||||
const source = await fs.realpath(path.resolve(arm64Dir, binding));
|
||||
const destination = await fs.realpath(path.resolve(x64Dir, binding));
|
||||
|
||||
d(`merging binding: ${binding}`);
|
||||
execFileSync(LIPO, [source, destination, '-create', '-output', destination]);
|
||||
}
|
||||
|
||||
d(`creating archive at ${outputAsarPath}`);
|
||||
|
||||
const resolvedUnpack = Array.from(unpackedFiles).map((file) => path.join(x64Dir, file));
|
||||
|
||||
let unpack: string | undefined;
|
||||
if (resolvedUnpack.length > 1) {
|
||||
unpack = `{${resolvedUnpack.join(',')}}`;
|
||||
} else if (resolvedUnpack.length === 1) {
|
||||
unpack = resolvedUnpack[0];
|
||||
}
|
||||
|
||||
await asar.createPackageWithOptions(x64Dir, outputAsarPath, {
|
||||
unpack,
|
||||
});
|
||||
|
||||
d('done merging');
|
||||
} finally {
|
||||
await Promise.all([fs.remove(x64Dir), fs.remove(arm64Dir)]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import * as debug from 'debug';
|
||||
import debug from 'debug';
|
||||
|
||||
export const d = debug('electron-universal');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { spawn } from '@malept/cross-spawn-promise';
|
||||
import { spawn, ExitCodeError } from '@malept/cross-spawn-promise';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -7,6 +7,7 @@ const MACHO_PREFIX = 'Mach-O ';
|
||||
export enum AppFileType {
|
||||
MACHO,
|
||||
PLAIN,
|
||||
INFO_PLIST,
|
||||
SNAPSHOT,
|
||||
APP_CODE,
|
||||
}
|
||||
@@ -34,13 +35,24 @@ export const getAllAppFiles = async (appPath: string): Promise<AppFile[]> => {
|
||||
if (info.isFile()) {
|
||||
let fileType = AppFileType.PLAIN;
|
||||
|
||||
const fileOutput = await spawn('file', ['--brief', '--no-pad', p]);
|
||||
var fileOutput = '';
|
||||
try {
|
||||
fileOutput = await spawn('file', ['--brief', '--no-pad', p]);
|
||||
} catch (e) {
|
||||
if (e instanceof ExitCodeError) {
|
||||
/* silently accept error codes from "file" */
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (p.includes('app.asar')) {
|
||||
fileType = AppFileType.APP_CODE;
|
||||
} else if (fileOutput.startsWith(MACHO_PREFIX)) {
|
||||
fileType = AppFileType.MACHO;
|
||||
} else if (p.endsWith('.bin')) {
|
||||
fileType = AppFileType.SNAPSHOT;
|
||||
} else if (path.basename(p) === 'Info.plist') {
|
||||
fileType = AppFileType.INFO_PLIST;
|
||||
}
|
||||
|
||||
files.push({
|
||||
|
||||
134
src/index.ts
134
src/index.ts
@@ -1,15 +1,18 @@
|
||||
import { spawn } from '@malept/cross-spawn-promise';
|
||||
import * as asar from 'asar';
|
||||
import * as asar from '@electron/asar';
|
||||
import * as fs from 'fs-extra';
|
||||
import { minimatch } from 'minimatch';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as plist from 'plist';
|
||||
import * as dircompare from 'dir-compare';
|
||||
|
||||
import { AppFile, AppFileType, getAllAppFiles } from './file-utils';
|
||||
import { AsarMode, detectAsarMode } from './asar-utils';
|
||||
import { AsarMode, detectAsarMode, generateAsarIntegrity, mergeASARs } from './asar-utils';
|
||||
import { sha } from './sha';
|
||||
import { d } from './debug';
|
||||
|
||||
type MakeUniversalOpts = {
|
||||
export type MakeUniversalOpts = {
|
||||
/**
|
||||
* Absolute file system path to the x64 version of your application. E.g. /Foo/bar/MyApp_x64.app
|
||||
*/
|
||||
@@ -27,7 +30,23 @@ type MakeUniversalOpts = {
|
||||
/**
|
||||
* Forcefully overwrite any existing files that are in the way of generating the universal application
|
||||
*/
|
||||
force: boolean;
|
||||
force?: boolean;
|
||||
/**
|
||||
* Merge x64 and arm64 ASARs into one.
|
||||
*/
|
||||
mergeASARs?: boolean;
|
||||
/**
|
||||
* Minimatch pattern of paths that are allowed to be present in one of the ASAR files, but not in the other.
|
||||
*/
|
||||
singleArchFiles?: string;
|
||||
/**
|
||||
* Minimatch pattern of binaries that are expected to be the same x64 binary in both of the ASAR files.
|
||||
*/
|
||||
x64ArchFiles?: string;
|
||||
/**
|
||||
* Minimatch pattern of paths that should not receive an injected ElectronAsarIntegrity value
|
||||
*/
|
||||
infoPlistsToIgnore?: string;
|
||||
};
|
||||
|
||||
const dupedFiles = (files: AppFile[]) =>
|
||||
@@ -104,16 +123,42 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
const arm64Sha = await sha(path.resolve(opts.arm64AppPath, file.relativePath));
|
||||
if (x64Sha !== arm64Sha) {
|
||||
d('SHA for file', file.relativePath, `does not match across builds ${x64Sha}!=${arm64Sha}`);
|
||||
// The MainMenu.nib files generated by Xcode13 are deterministic in effect but not deterministic in generated sequence
|
||||
if (path.basename(path.dirname(file.relativePath)) === 'MainMenu.nib') {
|
||||
// The mismatch here is OK so we just move on to the next one
|
||||
continue;
|
||||
}
|
||||
throw new Error(
|
||||
`Expected all non-binary files to have identical SHAs when creating a universal build but "${file.relativePath}" did not`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const knownMergedMachOFiles = new Set();
|
||||
for (const machOFile of x64Files.filter((f) => f.type === AppFileType.MACHO)) {
|
||||
const first = await fs.realpath(path.resolve(tmpApp, machOFile.relativePath));
|
||||
const second = await fs.realpath(path.resolve(opts.arm64AppPath, machOFile.relativePath));
|
||||
|
||||
const x64Sha = await sha(path.resolve(opts.x64AppPath, machOFile.relativePath));
|
||||
const arm64Sha = await sha(path.resolve(opts.arm64AppPath, machOFile.relativePath));
|
||||
if (x64Sha === arm64Sha) {
|
||||
if (
|
||||
opts.x64ArchFiles === undefined ||
|
||||
!minimatch(machOFile.relativePath, opts.x64ArchFiles, { matchBase: true })
|
||||
) {
|
||||
throw new Error(
|
||||
`Detected file "${machOFile.relativePath}" that's the same in both x64 and arm64 builds and not covered by the ` +
|
||||
`x64ArchFiles rule: "${opts.x64ArchFiles}"`,
|
||||
);
|
||||
}
|
||||
|
||||
d(
|
||||
'SHA for Mach-O file',
|
||||
machOFile.relativePath,
|
||||
`matches across builds ${x64Sha}===${arm64Sha}, skipping lipo`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
d('joining two MachO files with lipo', {
|
||||
first,
|
||||
second,
|
||||
@@ -125,6 +170,7 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
'-output',
|
||||
await fs.realpath(path.resolve(tmpApp, machOFile.relativePath)),
|
||||
]);
|
||||
knownMergedMachOFiles.add(machOFile.relativePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,8 +186,18 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
path.resolve(opts.arm64AppPath, 'Contents', 'Resources', 'app'),
|
||||
{ compareSize: true, compareContent: true },
|
||||
);
|
||||
const differences = comparison.diffSet!.filter((difference) => difference.state !== 'equal');
|
||||
d(`Found ${differences.length} difference(s) between the x64 and arm64 folders`);
|
||||
const nonMergedDifferences = differences.filter(
|
||||
(difference) =>
|
||||
!difference.name1 ||
|
||||
!knownMergedMachOFiles.has(
|
||||
path.join('Contents', 'Resources', 'app', difference.relativePath, difference.name1),
|
||||
),
|
||||
);
|
||||
d(`After discluding MachO files merged with lipo ${nonMergedDifferences.length} remain.`);
|
||||
|
||||
if (!comparison.same) {
|
||||
if (nonMergedDifferences.length > 0) {
|
||||
d('x64 and arm64 app folders are different, creating dynamic entry ASAR');
|
||||
await fs.move(
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app'),
|
||||
@@ -172,6 +228,9 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
}
|
||||
}
|
||||
|
||||
const generatedIntegrity: Record<string, { algorithm: 'SHA256'; hash: string }> = {};
|
||||
let didSplitAsar = false;
|
||||
|
||||
/**
|
||||
* If we have an ASAR we just need to check if the two "app.asar" files have the same hash,
|
||||
* if they are, same as above, we can leave one there and call it a day. If they're different
|
||||
@@ -180,7 +239,18 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
* look at codifying that assumption as actual logic.
|
||||
*/
|
||||
// FIXME: Codify the assumption that app.asar.unpacked only contains native modules
|
||||
if (x64AsarMode === AsarMode.HAS_ASAR) {
|
||||
if (x64AsarMode === AsarMode.HAS_ASAR && opts.mergeASARs) {
|
||||
d('merging x64 and arm64 asars');
|
||||
const output = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar');
|
||||
await mergeASARs({
|
||||
x64AsarPath: path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'),
|
||||
arm64AsarPath: path.resolve(opts.arm64AppPath, 'Contents', 'Resources', 'app.asar'),
|
||||
outputAsarPath: output,
|
||||
singleArchFiles: opts.singleArchFiles,
|
||||
});
|
||||
|
||||
generatedIntegrity['Resources/app.asar'] = generateAsarIntegrity(output);
|
||||
} else if (x64AsarMode === AsarMode.HAS_ASAR) {
|
||||
d('checking if the x64 and arm64 asars are identical');
|
||||
const x64AsarSha = await sha(path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'));
|
||||
const arm64AsarSha = await sha(
|
||||
@@ -188,11 +258,10 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
);
|
||||
|
||||
if (x64AsarSha !== arm64AsarSha) {
|
||||
didSplitAsar = true;
|
||||
d('x64 and arm64 asars are different');
|
||||
await fs.move(
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'),
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app-x64.asar'),
|
||||
);
|
||||
const x64AsarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app-x64.asar');
|
||||
await fs.move(path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'), x64AsarPath);
|
||||
const x64Unpacked = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar.unpacked');
|
||||
if (await fs.pathExists(x64Unpacked)) {
|
||||
await fs.move(
|
||||
@@ -201,9 +270,10 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
);
|
||||
}
|
||||
|
||||
const arm64AsarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app-arm64.asar');
|
||||
await fs.copy(
|
||||
path.resolve(opts.arm64AppPath, 'Contents', 'Resources', 'app.asar'),
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app-arm64.asar'),
|
||||
arm64AsarPath,
|
||||
);
|
||||
const arm64Unpacked = path.resolve(
|
||||
opts.arm64AppPath,
|
||||
@@ -234,15 +304,47 @@ export const makeUniversalApp = async (opts: MakeUniversalOpts): Promise<void> =
|
||||
);
|
||||
pj.main = 'index.js';
|
||||
await fs.writeJson(path.resolve(entryAsar, 'package.json'), pj);
|
||||
await asar.createPackage(
|
||||
entryAsar,
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'),
|
||||
);
|
||||
const asarPath = path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar');
|
||||
await asar.createPackage(entryAsar, asarPath);
|
||||
|
||||
generatedIntegrity['Resources/app.asar'] = generateAsarIntegrity(asarPath);
|
||||
generatedIntegrity['Resources/app-x64.asar'] = generateAsarIntegrity(x64AsarPath);
|
||||
generatedIntegrity['Resources/app-arm64.asar'] = generateAsarIntegrity(arm64AsarPath);
|
||||
} else {
|
||||
d('x64 and arm64 asars are the same');
|
||||
generatedIntegrity['Resources/app.asar'] = generateAsarIntegrity(
|
||||
path.resolve(tmpApp, 'Contents', 'Resources', 'app.asar'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const plistFiles = x64Files.filter((f) => f.type === AppFileType.INFO_PLIST);
|
||||
for (const plistFile of plistFiles) {
|
||||
const x64PlistPath = path.resolve(opts.x64AppPath, plistFile.relativePath);
|
||||
const arm64PlistPath = path.resolve(opts.arm64AppPath, plistFile.relativePath);
|
||||
|
||||
const { ElectronAsarIntegrity: x64Integrity, ...x64Plist } = plist.parse(
|
||||
await fs.readFile(x64PlistPath, 'utf8'),
|
||||
) as any;
|
||||
const { ElectronAsarIntegrity: arm64Integrity, ...arm64Plist } = plist.parse(
|
||||
await fs.readFile(arm64PlistPath, 'utf8'),
|
||||
) as any;
|
||||
if (JSON.stringify(x64Plist) !== JSON.stringify(arm64Plist)) {
|
||||
throw new Error(
|
||||
`Expected all Info.plist files to be identical when ignoring integrity when creating a universal build but "${plistFile.relativePath}" was not`,
|
||||
);
|
||||
}
|
||||
|
||||
const injectAsarIntegrity =
|
||||
!opts.infoPlistsToIgnore ||
|
||||
minimatch(plistFile.relativePath, opts.infoPlistsToIgnore, { matchBase: true });
|
||||
const mergedPlist = injectAsarIntegrity
|
||||
? { ...x64Plist, ElectronAsarIntegrity: generatedIntegrity }
|
||||
: { ...x64Plist };
|
||||
|
||||
await fs.writeFile(path.resolve(tmpApp, plistFile.relativePath), plist.build(mergedPlist));
|
||||
}
|
||||
|
||||
for (const snapshotsFile of arm64Files.filter((f) => f.type === AppFileType.SNAPSHOT)) {
|
||||
d('copying snapshot file', snapshotsFile.relativePath, 'to target application');
|
||||
await fs.copy(
|
||||
|
||||
12
src/sha.ts
12
src/sha.ts
@@ -1,15 +1,13 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import * as crypto from 'crypto';
|
||||
import { pipeline } from 'stream/promises';
|
||||
|
||||
import { d } from './debug';
|
||||
|
||||
export const sha = async (filePath: string) => {
|
||||
d('hashing', filePath);
|
||||
const hash = crypto.createHash('sha256');
|
||||
const fileStream = fs.createReadStream(filePath);
|
||||
fileStream.pipe(hash);
|
||||
await new Promise((resolve, reject) => {
|
||||
fileStream.on('end', () => resolve());
|
||||
fileStream.on('error', (err) => reject(err));
|
||||
});
|
||||
return hash.digest('hex');
|
||||
hash.setEncoding('hex');
|
||||
await pipeline(fs.createReadStream(filePath), hash);
|
||||
return hash.read();
|
||||
};
|
||||
|
||||
26
test/asar-utils.spec.ts
Normal file
26
test/asar-utils.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as path from 'path';
|
||||
|
||||
import { AsarMode, detectAsarMode, generateAsarIntegrity } from '../src/asar-utils';
|
||||
|
||||
const asarsPath = path.resolve(__dirname, 'fixtures', 'asars');
|
||||
const appsPath = path.resolve(__dirname, 'fixtures', 'apps');
|
||||
|
||||
describe('asar-utils', () => {
|
||||
describe('detectAsarMode', () => {
|
||||
it('should correctly detect an asar enabled app', async () => {
|
||||
expect(await detectAsarMode(path.resolve(appsPath, 'Asar.app'))).toBe(AsarMode.HAS_ASAR);
|
||||
});
|
||||
|
||||
it('should correctly detect an app without an asar', async () => {
|
||||
expect(await detectAsarMode(path.resolve(appsPath, 'NoAsar.app'))).toBe(AsarMode.NO_ASAR);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateAsarIntegrity', () => {
|
||||
it('should deterministically hash an asar header', async () => {
|
||||
expect(generateAsarIntegrity(path.resolve(asarsPath, 'app.asar')).hash).toEqual(
|
||||
'85fff474383bd8df11cd9c5784e8fcd1525af71ff140a8a882e1dc9d5b39fcbf',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
61
test/file-utils.spec.ts
Normal file
61
test/file-utils.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import * as path from 'path';
|
||||
|
||||
import { AppFile, AppFileType, getAllAppFiles } from '../src/file-utils';
|
||||
|
||||
const appsPath = path.resolve(__dirname, 'fixtures', 'apps');
|
||||
|
||||
describe('file-utils', () => {
|
||||
describe('getAllAppFiles', () => {
|
||||
let asarFiles: AppFile[];
|
||||
let noAsarFiles: AppFile[];
|
||||
|
||||
beforeAll(async () => {
|
||||
asarFiles = await getAllAppFiles(path.resolve(appsPath, 'Asar.app'));
|
||||
noAsarFiles = await getAllAppFiles(path.resolve(appsPath, 'NoAsar.app'));
|
||||
});
|
||||
|
||||
it('should correctly identify plist files', async () => {
|
||||
expect(asarFiles.find((f) => f.relativePath === 'Contents/Info.plist')?.type).toBe(
|
||||
AppFileType.INFO_PLIST,
|
||||
);
|
||||
});
|
||||
|
||||
it('should correctly identify asar files as app code', async () => {
|
||||
expect(asarFiles.find((f) => f.relativePath === 'Contents/Resources/app.asar')?.type).toBe(
|
||||
AppFileType.APP_CODE,
|
||||
);
|
||||
});
|
||||
|
||||
it('should correctly identify non-asar code files as plain text', async () => {
|
||||
expect(
|
||||
noAsarFiles.find((f) => f.relativePath === 'Contents/Resources/app/index.js')?.type,
|
||||
).toBe(AppFileType.PLAIN);
|
||||
});
|
||||
|
||||
it('should correctly identify the Electron binary as Mach-O', async () => {
|
||||
expect(noAsarFiles.find((f) => f.relativePath === 'Contents/MacOS/Electron')?.type).toBe(
|
||||
AppFileType.MACHO,
|
||||
);
|
||||
});
|
||||
|
||||
it('should correctly identify the Electron Framework as Mach-O', async () => {
|
||||
expect(
|
||||
noAsarFiles.find(
|
||||
(f) =>
|
||||
f.relativePath ===
|
||||
'Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework',
|
||||
)?.type,
|
||||
).toBe(AppFileType.MACHO);
|
||||
});
|
||||
|
||||
it('should correctly identify the v8 context snapshot', async () => {
|
||||
expect(
|
||||
noAsarFiles.find(
|
||||
(f) =>
|
||||
f.relativePath ===
|
||||
'Contents/Frameworks/Electron Framework.framework/Versions/A/Resources/v8_context_snapshot.arm64.bin',
|
||||
)?.type,
|
||||
).toBe(AppFileType.SNAPSHOT);
|
||||
});
|
||||
});
|
||||
});
|
||||
BIN
test/fixtures/asars/app.asar
vendored
Normal file
BIN
test/fixtures/asars/app.asar
vendored
Normal file
Binary file not shown.
2
test/fixtures/asars/app/index.js
vendored
Normal file
2
test/fixtures/asars/app/index.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
console.log('I am an app folder', process.arch);
|
||||
process.exit(0);
|
||||
4
test/fixtures/asars/app/package.json
vendored
Normal file
4
test/fixtures/asars/app/package.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "app",
|
||||
"main": "index.js"
|
||||
}
|
||||
1
test/fixtures/tohash
vendored
Normal file
1
test/fixtures/tohash
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello there
|
||||
40
test/index.spec.ts
Normal file
40
test/index.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { spawn } from '@malept/cross-spawn-promise';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
import { makeUniversalApp } from '../src/index';
|
||||
|
||||
const appsPath = path.resolve(__dirname, 'fixtures', 'apps');
|
||||
|
||||
async function ensureUniversal(app: string) {
|
||||
const exe = path.resolve(app, 'Contents', 'MacOS', 'Electron');
|
||||
const result = await spawn(exe);
|
||||
expect(result).toContain('arm64');
|
||||
const result2 = await spawn('arch', ['-x86_64', exe]);
|
||||
expect(result2).toContain('x64');
|
||||
}
|
||||
|
||||
describe('makeUniversalApp', () => {
|
||||
it('should correctly merge two identical asars', async () => {
|
||||
const out = path.resolve(appsPath, 'MergedAsar.app');
|
||||
await makeUniversalApp({
|
||||
x64AppPath: path.resolve(appsPath, 'X64Asar.app'),
|
||||
arm64AppPath: path.resolve(appsPath, 'Asar.app'),
|
||||
outAppPath: out,
|
||||
});
|
||||
await ensureUniversal(out);
|
||||
// Only a single asar as they were identical
|
||||
expect(
|
||||
(await fs.readdir(path.resolve(out, 'Contents', 'Resources'))).filter((p) =>
|
||||
p.endsWith('asar'),
|
||||
),
|
||||
).toEqual(['app.asar']);
|
||||
}, 60000);
|
||||
|
||||
// TODO: Add tests for
|
||||
// * different asar files
|
||||
// * identical app dirs
|
||||
// * different app dirs
|
||||
// * different app dirs with different macho files
|
||||
// * identical app dirs with universal macho files
|
||||
});
|
||||
11
test/sha.spec.ts
Normal file
11
test/sha.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as path from 'path';
|
||||
|
||||
import { sha } from '../src/sha';
|
||||
|
||||
describe('sha', () => {
|
||||
it('should correctly hash a file', async () => {
|
||||
expect(await sha(path.resolve(__dirname, 'fixtures', 'tohash'))).toEqual(
|
||||
'12998c017066eb0d2a70b94e6ed3192985855ce390f321bbdb832022888bd251',
|
||||
);
|
||||
});
|
||||
});
|
||||
4
tsconfig.cjs.json
Normal file
4
tsconfig.cjs.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
10
tsconfig.entry-asar.json
Normal file
10
tsconfig.entry-asar.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "entry-asar",
|
||||
},
|
||||
"include": [
|
||||
"entry-asar"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
@@ -3,5 +3,6 @@
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm"
|
||||
}
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
11
tsconfig.jest.json
Normal file
11
tsconfig.jest.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm",
|
||||
"types": [
|
||||
"jest"
|
||||
]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -13,9 +13,11 @@
|
||||
],
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
"src",
|
||||
"entry-asar"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user