* fix: when native modules are already universal, don't lipo. adds `node-mac-permissions` fixture from https://github.com/codebytere/node-mac-permissions and resolves 3 `it.todo` test cases * add test `different app dirs with different macho files (shim and lipo)` * add additional test * PR feedback * gotta close `fd` * use `stream` to read first 4 bytes. copy native fixture before packing into asar to leverage `unpack: "**/*.node"` properly. * convert params to object * rename `createTestApp` to `createStagingAppDir` and add jsdoc to the function * compiler error from merge conflict * update snapshots * update snapshots * only check x64Content since it's the tmp app * compile macho binaries at runtime using hellow-world.c for fixtures in lipo tests * Update jest.setup.ts Co-authored-by: Erik Moura <erikian@erikian.dev> * Update jest.setup.ts Co-authored-by: Erik Moura <erikian@erikian.dev> * remove unstable properties for specific keys * force redo * update snapshots * stripping only hello-world from snapshot and only hash from macho-specific asar integrity * optimize logic :) --------- Co-authored-by: Erik Moura <erikian@erikian.dev>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import { execFileSync } from 'child_process';
|
|
import * as fs from 'fs-extra';
|
|
import * as path from 'path';
|
|
import { appsDir, asarsDir, fixtureDir, templateApp } from './test/util';
|
|
|
|
// generates binaries from hello-world.c
|
|
// hello-world-universal, hello-world-x86_64, hello-world-arm64
|
|
const generateMachO = () => {
|
|
const src = path.resolve(fixtureDir, 'hello-world.c');
|
|
|
|
const outputFiles = ['x86_64', 'arm64'].map((arch) => {
|
|
const machO = path.resolve(appsDir, `hello-world-${arch === 'x86_64' ? 'x64' : arch}`);
|
|
execFileSync('clang', ['-arch', arch, '-o', machO, src]);
|
|
return machO;
|
|
});
|
|
|
|
execFileSync('lipo', [
|
|
...outputFiles,
|
|
'-create',
|
|
'-output',
|
|
path.resolve(appsDir, 'hello-world-universal'),
|
|
]);
|
|
};
|
|
|
|
export default async () => {
|
|
await fs.remove(appsDir);
|
|
await fs.mkdirp(appsDir);
|
|
|
|
// generate mach-o binaries to be leveraged in lipo tests
|
|
generateMachO();
|
|
|
|
await templateApp('Arm64Asar.app', 'arm64', async (appPath) => {
|
|
await fs.copy(
|
|
path.resolve(asarsDir, 'app.asar'),
|
|
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
|
|
);
|
|
});
|
|
|
|
// contains `extra-file.txt`
|
|
await templateApp('Arm64AsarExtraFile.app', 'arm64', async (appPath) => {
|
|
await fs.copy(
|
|
path.resolve(asarsDir, 'app2.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('Arm64NoAsar.app', 'arm64', async (appPath) => {
|
|
await fs.copy(
|
|
path.resolve(asarsDir, 'app'),
|
|
path.resolve(appPath, 'Contents', 'Resources', 'app'),
|
|
);
|
|
});
|
|
|
|
// contains `extra-file.txt`
|
|
await templateApp('Arm64NoAsarExtraFile.app', 'arm64', async (appPath) => {
|
|
await fs.copy(
|
|
path.resolve(asarsDir, 'app2'),
|
|
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'),
|
|
);
|
|
});
|
|
};
|