Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Print one JSON document from the base size measurement

Nguyen Xuan An587cdbcff4d7
diff --git a/scripts/measure-archive.mjs b/scripts/measure-archive.mjs
index e0f98201..90a9ca8d 100644
--- a/scripts/measure-archive.mjs
+++ b/scripts/measure-archive.mjs
@@ -4,6 +4,7 @@
import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
+import { pathToFileURL } from 'node:url';
const MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
@@ -34,6 +35,7 @@ export function measureArchiveBytes() {
return packed.size;
}
-if (process.argv.includes('--json')) {
+// Only when this file is the script that runs: measure-size.mjs imports it and has its own --json output.
+if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href && process.argv.includes('--json')) {
process.stdout.write(JSON.stringify({ archiveBytes: measureArchiveBytes() }));
}
diff --git a/tests/size-growth.test.js b/tests/size-growth.test.js
index 7087fef1..19afca8a 100644
--- a/tests/size-growth.test.js
+++ b/tests/size-growth.test.js
@@ -110,6 +110,14 @@ test('two pull requests that grow different entries merge in sequence without to
}
});
+test('the base measurement of the bundles prints one JSON document and no archive size', () => {
+ const result = spawnSync(process.execPath, ['scripts/measure-size.mjs', '--json'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
+ assert.equal(result.status, 0, result.stderr);
+ const measured = JSON.parse(result.stdout);
+ assert.ok(measured['entry:core'].gzip > 0);
+ assert.equal(measured.archiveBytes, undefined);
+});
+
test('a pull request behind the base branch is compared with the base it was merged into, not the newest tip', () => {
const folder = mkdtempSync(join(tmpdir(), 'size-behind-'));
try {