Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.1] - 2026-10-12

### Fixed
- `generate --json`: a sign failure caused by the device being keyed for another app now reports `KEY_MISMATCH` with a fix (run again with the rekey), instead of the device's "Failed: Invalid Password." and an unrelated `--package-only` hint.
- `generate --json`: `packagePath` in the result is always absolute, even when the project's output path is relative.

## [1.2.0] - 2026-10-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Steps are `home`, `build`, `validate`, `rekey`, `deploy`, `sign` and `save`. A f
`{"type":"result","ok":false,"step":"rekey","code":"REKEY_FAILED","message":"...","hint":"..."}`.
Error codes: `PROJECT_NOT_FOUND`, `DEVICE_UNREACHABLE`, `AUTH_FAILED`, `NEEDS_BUILD_CHOICE`, `TASK_NOT_FOUND`,
`BUILD_FAILED`, `BUILD_TIMEOUT`, `INVALID_BUILD`, `SIGNED_PKG_MISSING`, `REKEY_FAILED`, `DEPLOY_FAILED`,
`DEPLOY_TIMEOUT`, `SIGN_FAILED`, `CANCELLED`, `UNKNOWN`. Exit code is 0 on success, 1 on failure, 130 when cancelled.
`DEPLOY_TIMEOUT`, `SIGN_FAILED`, `KEY_MISMATCH`, `CANCELLED`, `UNKNOWN`. Exit code is 0 on success, 1 on failure, 130 when cancelled.

With no build flag, `--json` uses the project's `defaultBuildTask`; if it has none and VSCode tasks exist, it fails with `NEEDS_BUILD_CHOICE`.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roku-pkg-cli",
"version": "1.2.0",
"version": "1.2.1",
"description": "A comprehensive CLI tool for managing multiple Roku projects with automated device discovery, build integration, and package generation. Perfect for CI/CD pipelines with full automation support.",
"main": "dist/index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Step = 'home' | 'build' | 'validate' | 'rekey' | 'deploy' | 'sign' |
export type ErrorCode =
| 'PROJECT_NOT_FOUND' | 'DEVICE_UNREACHABLE' | 'AUTH_FAILED' | 'NEEDS_BUILD_CHOICE'
| 'TASK_NOT_FOUND' | 'BUILD_FAILED' | 'BUILD_TIMEOUT' | 'INVALID_BUILD' | 'SIGNED_PKG_MISSING'
| 'REKEY_FAILED' | 'DEPLOY_FAILED' | 'DEPLOY_TIMEOUT' | 'SIGN_FAILED' | 'CANCELLED' | 'UNKNOWN';
| 'REKEY_FAILED' | 'DEPLOY_FAILED' | 'DEPLOY_TIMEOUT' | 'SIGN_FAILED' | 'KEY_MISMATCH' | 'CANCELLED' | 'UNKNOWN';
export type StepStatus = 'start' | 'done' | 'skip' | 'fail';
export type PkgEvent =
| { type: 'step'; step: Step; status: StepStatus; ms?: number; detail?: string }
Expand Down
23 changes: 18 additions & 5 deletions src/lib/generate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export async function runGenerateJson(opts: GenerateJsonOptions, emitter: Emitte
const project = opts.project ? deps.config.getProject(opts.project) : undefined;
if (!project) return fail('PROJECT_NOT_FOUND', `Project '${opts.project ?? ''}' not found.`, 'Run roku-pkg list to see the configured projects.');
const configured = deps.config.getRokuDevice();
// Relative output paths resolve against the working directory; report and use the absolute path.
const outputLocation = path.resolve(project.outputLocation);
const host = opts.host || configured.ip;
const password = opts.password ?? configured.password;

Expand Down Expand Up @@ -211,24 +213,35 @@ export async function runGenerateJson(opts: GenerateJsonOptions, emitter: Emitte
const downloadDir = path.join(os.tmpdir(), `roku-pkg-out-${process.pid}`);
try {
const remote = await deps.sign({ host, password, rootDir: tempDir, signingPassword: project.signKey });
local = await deps.retrieve(remote, { host, password, outDir: downloadDir, outFile: path.basename(project.outputLocation, '.pkg') });
local = await deps.retrieve(remote, { host, password, outDir: downloadDir, outFile: path.basename(outputLocation, '.pkg') });
} catch (e) {
checkCancel();
fail('SIGN_FAILED', (e as Error).message, 'Packaging needs the app deployed on the device; run without --package-only.');
const msg = (e as Error).message;
// The device signs with the key it was last rekeyed with; another app's key rejects this sign key.
if (/invalid password/i.test(msg)) {
fail(
'KEY_MISMATCH',
`The device is keyed for a different app, so it rejected ${project.name}'s sign key.`,
opts.skipRekey
? `Run again without skipping the rekey, so the device gets ${project.name}'s key.`
: `Check that the sign key matches ${path.basename(project.signPackageLocation)}, then run again.`
);
}
fail('SIGN_FAILED', msg, opts.packageOnly ? 'Package only needs the app already deployed on the device; run again without Package only.' : undefined);
} finally {
if (!local) deps.removeDir(downloadDir);
}
done('sign');
checkCancel();

start('save');
deps.mkdirp(path.dirname(project.outputLocation));
deps.copyFile(local, project.outputLocation);
deps.mkdirp(path.dirname(outputLocation));
deps.copyFile(local, outputLocation);
deps.removeDir(downloadDir);
done('save');

await deps.home(host).catch(() => undefined);
emitter.emit({ type: 'result', ok: true, packagePath: project.outputLocation, sizeBytes: deps.size(project.outputLocation), version: deps.readVersion(project.rootDir) });
emitter.emit({ type: 'result', ok: true, packagePath: outputLocation, sizeBytes: deps.size(outputLocation), version: deps.readVersion(project.rootDir) });
return 0;
} catch (e) {
const err = opts.signal?.aborted
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/generate-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,33 @@ describe('runGenerateJson', () => {
expect(outDirs[0]).not.toBe('/out');
expect(events.at(-1)).toMatchObject({ ok: false, code: 'SIGN_FAILED' });
});
it('reports an absolute package path even when outputLocation is relative', async () => {
const deps = fakeDeps({ config: { getProject: () => ({ ...project, outputLocation: './output/CNBC.pkg' }), getRokuDevice: () => ({ ip: '', password: '' }) } });
const { events } = await run({}, deps);
expect(events.at(-1)).toMatchObject({ ok: true, packagePath: require('path').resolve('./output/CNBC.pkg') });
});

it('explains a key mismatch when rekey was skipped', async () => {
const deps = fakeDeps({ sign: async () => { throw new Error('Failed: Invalid Password.'); } });
const { events } = await run({ skipRekey: true }, deps);
const r = events.at(-1) as { code: string; step: string; message: string; hint: string };
expect(r.code).toBe('KEY_MISMATCH');
expect(r.step).toBe('sign');
expect(r.message).toMatch(/keyed for a different app/);
expect(r.hint).toMatch(/rekey/i);
expect(r.hint).not.toMatch(/package-only/);
});

it('explains a key mismatch even after a rekey', async () => {
const deps = fakeDeps({ sign: async () => { throw new Error('Failed: Invalid Password.'); } });
const { events } = await run({}, deps);
expect(events.at(-1)).toMatchObject({ code: 'KEY_MISMATCH', step: 'sign' });
});

it('only suggests a deploy for other sign failures when package-only was used', async () => {
const deps = fakeDeps({ sign: async () => { throw new Error('No app to package'); } });
expect((await run({}, deps)).events.at(-1)).toMatchObject({ code: 'SIGN_FAILED' });
expect(((await run({}, deps)).events.at(-1) as { hint?: string }).hint ?? '').not.toMatch(/package-only/);
expect(((await run({ packageOnly: true }, deps)).events.at(-1) as { hint?: string }).hint).toMatch(/package only/i);
});
});
Loading