Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

feat: add option to skip signature on macos #1878

Merged
merged 5 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false # prevent test to stop if one fails
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
os: [ubuntu-latest, windows-latest] # Skip macos-latest
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pkg [options] <input>
--public-packages force specified packages to be considered public
--no-bytecode skip bytecode generation and include source files as plain js
--no-native-build skip native addons build
--no-signature skip signature of the final executable on macos
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
-C, --compress [default=None] compression algorithm = Brotli or GZip

Expand Down
5 changes: 3 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export async function exec(argv2: string[]) {
'public',
'v',
'version',
'signature',
],
string: [
'_',
Expand All @@ -251,7 +252,7 @@ export async function exec(argv2: string[]) {
'C',
'compress',
],
default: { bytecode: true, 'native-build': true },
default: { bytecode: true, 'native-build': true, signature: true },
});

if (argv.h || argv.help) {
Expand Down Expand Up @@ -682,7 +683,7 @@ export async function exec(argv2: string[]) {
});

if (target.platform !== 'win' && target.output) {
if (target.platform === 'macos') {
if (argv.signature && target.platform === 'macos') {
// patch executable to allow code signing
const buf = patchMachOExecutable(readFileSync(target.output));
writeFileSync(target.output, buf);
Expand Down
8 changes: 8 additions & 0 deletions test/test-50-bakery-fetch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ fetch
arch: fetch.system.hostArch,
})
.then(function (needed) {
if (process.platform === 'darwin') {
utils.spawn.sync(
'codesign',
['-fds', '-', './' + path.basename(needed)],
{ cwd: path.dirname(needed) }
);
}

right = utils.spawn.sync(
'./' + path.basename(needed),
['--expose-gc', '-e', 'if (global.gc) console.log("ok");'],
Expand Down
5 changes: 5 additions & 0 deletions test/test-50-corrupt-executable/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const utils = require('../utils.js');
assert(!module.parent);
assert(__dirname === process.cwd());

// TODO : understand why the damage is not impacting macos build
if (process.platform === 'darwin') {
return;
}

const host = 'node' + process.version.match(/^v(\d+)/)[1];
const target = process.argv[2] || host;
const input = './test-x-index.js';
Expand Down
42 changes: 42 additions & 0 deletions test/test-50-no-signature/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const darwin = process.platform === 'darwin';
if (!darwin) {
return;
}

const target = process.argv[2] || 'host';
const input = './test-x-index.js';
const output = './test-output';

let right;

utils.pkg.sync([
'--no-signature',
'--target',
target,
'--output',
output,
input,
]);

right = utils.spawn.sync('codesign', ['-dv', './' + path.basename(output)], {
stdio: 'pipe',
expect: 1,
});

assert.strictEqual(
right.stderr,
'./test-output: code object is not signed at all\n'
);

utils.vacuum.sync(output);
3 changes: 3 additions & 0 deletions test/test-50-no-signature/test-x-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('ok');
2 changes: 2 additions & 0 deletions test/test-50-reproducible/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const output2 = './test-output-2.exe';

utils.pkg.sync([
'--public',
'--no-signature', // the signature will make the build not reproducible
'--no-bytecode',
'--target',
target,
Expand All @@ -30,6 +31,7 @@ utils.pkg.sync([

utils.pkg.sync([
'--public',
'--no-signature',
'--no-bytecode',
'--target',
target,
Expand Down