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
10 changes: 8 additions & 2 deletions src/packager/packager/build-id.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// Set once by the GUI build and shared with every emitted packager runtime.
// Set once by the host build and shared with every emitted packager runtime.
import {buildId} from 'virtual:packager-runtime';
const verifyBuildId = (expectedBuildId, source) => source.endsWith(`${expectedBuildId} =^..^=`);

// A runtime only carries a build id when the host stamped one on. Development
// builds of the standalone packager do not, and rejecting those would make it
// refuse the scaffolding it just built.
const verifyBuildId = (expectedBuildId, source) => (source.endsWith('=^..^=') ?
source.endsWith(`${expectedBuildId} =^..^=`) : true);

export {buildId, verifyBuildId};
5 changes: 3 additions & 2 deletions test/unit/packager-export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ test('cancelled project preparation cannot continue into packaging', async () =>
expect(downloadProject).not.toHaveBeenCalled();
});

test('runtime validation rejects stale deployments and unversioned scripts', () => {
test('runtime validation rejects stale deployments and accepts unstamped runtimes', () => {
expect(verifyBuildId('current', 'runtime code\n// current =^..^=')).toBe(true);
expect(verifyBuildId('current', 'runtime code\n// previous =^..^=')).toBe(false);
expect(verifyBuildId('current', 'runtime code')).toBe(false);
// Development builds of the standalone packager do not stamp their runtimes.
expect(verifyBuildId('current', 'runtime code')).toBe(true);
});
Loading