Skip to content

Commit 64399cd

Browse files
committed
Address Copilot review comments
- type lexer results explicitly in validateBundle - surface smoke-build failures as validation violations - clamp bundle budget at zero for tiny upload limits - fix package description typo and add license field
1 parent 5f2811a commit 64399cd

4 files changed

Lines changed: 33 additions & 26 deletions

File tree

packages/composition-cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@fishjam-cloud/composition-cli",
33
"version": "0.29.0-rc.2",
4-
"description": "Utilites to build, validate composition React code",
4+
"description": "CLI for scaffolding and building Fishjam composition templates",
5+
"license": "Apache-2.0",
56
"homepage": "https://github.com/fishjam-cloud/js-server-sdk",
67
"author": "Fishjam Team",
78
"repository": {

packages/composition-cli/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function buildTemplate(entry: string, outfile: string, manifest: Ma
4747
const violations = await validateBundle(bundle.text, manifest);
4848

4949
const bytes = bundle.contents.byteLength;
50-
const maxBundleBytes = manifest.maxUploadBytes - UPLOAD_OVERHEAD_RESERVE_BYTES;
50+
const maxBundleBytes = Math.max(0, manifest.maxUploadBytes - UPLOAD_OVERHEAD_RESERVE_BYTES);
5151
if (bytes > maxBundleBytes) {
5252
violations.push(
5353
`bundle is ${bytes} bytes; the upload limit is ${manifest.maxUploadBytes} bytes and ${UPLOAD_OVERHEAD_RESERVE_BYTES} bytes are reserved for registration config and multipart overhead, so bundles must stay under ${maxBundleBytes} bytes`

packages/composition-cli/src/smoke.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ export async function smokeLoadBundle(source: string, manifest: Manifest): Promi
88
const escaped = manifest.allowedImports.map((spec) => spec.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
99
const allowedFilter = new RegExp(`^(${escaped.join('|')})$`);
1010

11-
const result = await build({
12-
stdin: { contents: source, loader: 'js' },
13-
bundle: true,
14-
write: false,
15-
format: 'esm',
16-
logLevel: 'silent',
17-
plugins: [
18-
{
19-
name: 'stub-allowed-imports',
20-
setup(builder) {
21-
builder.onResolve({ filter: allowedFilter }, (args) => ({
22-
path: args.path,
23-
namespace: 'stub',
24-
}));
25-
builder.onLoad({ filter: /.*/, namespace: 'stub' }, () => ({
26-
contents: stubModule,
27-
loader: 'js',
28-
}));
11+
let result;
12+
try {
13+
result = await build({
14+
stdin: { contents: source, loader: 'js' },
15+
bundle: true,
16+
write: false,
17+
format: 'esm',
18+
logLevel: 'silent',
19+
plugins: [
20+
{
21+
name: 'stub-allowed-imports',
22+
setup(builder) {
23+
builder.onResolve({ filter: allowedFilter }, (args) => ({
24+
path: args.path,
25+
namespace: 'stub',
26+
}));
27+
builder.onLoad({ filter: /.*/, namespace: 'stub' }, () => ({
28+
contents: stubModule,
29+
loader: 'js',
30+
}));
31+
},
2932
},
30-
},
31-
],
32-
});
33+
],
34+
});
35+
} catch (err) {
36+
const message = err instanceof Error ? err.message : String(err);
37+
return [`bundle could not be prepared for loading: ${message}`];
38+
}
3339

3440
const encoded = Buffer.from(result.outputFiles[0].contents).toString('base64');
3541
let mod: { default?: unknown };

packages/composition-cli/src/validate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { init, parse } from 'es-module-lexer';
1+
import { type ExportSpecifier, type ImportSpecifier, init, parse } from 'es-module-lexer';
22
import type { Manifest } from './manifests';
33

44
export async function validateBundle(source: string, manifest: Manifest): Promise<string[]> {
55
await init;
66

7-
let imports;
8-
let exports;
7+
let imports: readonly ImportSpecifier[];
8+
let exports: readonly ExportSpecifier[];
99
try {
1010
[imports, exports] = parse(source);
1111
} catch {

0 commit comments

Comments
 (0)