@diagonal-hq/cli 0.41.5 → 0.41.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/check-data.json +1 -1
- package/dist/{cli-assets-cli-FMLE5XEF.mjs → cli-assets-cli-WEGERBBR.mjs} +8 -134
- package/dist/{cli-check-data-PIXADUF2.mjs → cli-check-data-7TKAM34J.mjs} +152 -2259
- package/dist/cli-chunk-25JQRNTW.mjs +24138 -0
- package/dist/{cli-chunk-U2ET6LQJ.mjs → cli-chunk-3SEADNVJ.mjs} +153 -1
- package/dist/{cli-chunk-TEV2VFGB.mjs → cli-chunk-77DCVFIZ.mjs} +7 -23955
- package/dist/{cli-chunk-4FQYK2WG.mjs → cli-chunk-ES45EAOO.mjs} +4 -1
- package/dist/{cli-skill-file-26B4RRZZ.mjs → cli-chunk-KZOQCV4Y.mjs} +7 -8
- package/dist/{cli-chunk-2YX3ABIW.mjs → cli-chunk-NEXRHJ3X.mjs} +1500 -44
- package/dist/{cli-chunk-XMVYLKEB.mjs → cli-chunk-TDGR3ENO.mjs} +278 -1
- package/dist/cli-chunk-XO3FRXQ4.mjs +3200 -0
- package/dist/{cli-chunk-GCF6XYTF.mjs → cli-chunk-XQQBHS6I.mjs} +18 -2
- package/dist/cli-skill-file-XEFKCU5Y.mjs +27 -0
- package/dist/{cli-workflows-YLHANSO2.mjs → cli-workflows-VFKTQW7H.mjs} +14 -18
- package/dist/cli.mjs +10361 -99
- package/dist/index.d.ts +18 -0
- package/dist/sdk-contract.d.ts +4 -1
- package/package.json +4 -4
- package/dist/cli-chunk-C3LVTOK3.mjs +0 -1054
- package/dist/cli-chunk-WPC3DBHX.mjs +0 -52
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { createRequire as __diagonalCreateRequire } from 'node:module';
|
|
2
2
|
const require = __diagonalCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
ASSETS_EXPORT,
|
|
5
|
+
GENERATED_ASSETS_MODULE,
|
|
6
|
+
assetKeyMessage,
|
|
7
|
+
assetsBinding,
|
|
8
|
+
buildAssets,
|
|
9
|
+
isAssetKey
|
|
10
|
+
} from "./cli-chunk-XQQBHS6I.mjs";
|
|
11
|
+
import {
|
|
12
|
+
SourceError,
|
|
13
|
+
bindsName,
|
|
14
|
+
byteOrder,
|
|
15
|
+
defaultExportOf,
|
|
16
|
+
expectDefineCall,
|
|
17
|
+
parseSource,
|
|
18
|
+
staticObject,
|
|
19
|
+
studlyName,
|
|
20
|
+
traverse
|
|
21
|
+
} from "./cli-chunk-NEXRHJ3X.mjs";
|
|
3
22
|
|
|
4
23
|
// scripts/lib/runtime-build/api-cli.mjs
|
|
5
24
|
var WORKFLOWS_USAGE = "Usage: diagonal workflows [--json]";
|
|
@@ -342,6 +361,255 @@ function formatDiagnostic(diagnostic) {
|
|
|
342
361
|
return lines.join("\n");
|
|
343
362
|
}
|
|
344
363
|
|
|
364
|
+
// scripts/lib/runtime-build/assets-file.mjs
|
|
365
|
+
var traverse2 = traverse.default ?? traverse;
|
|
366
|
+
var ASSETS_PATH = "assets.ts";
|
|
367
|
+
function readAssetEntries(source) {
|
|
368
|
+
return source === null ? [] : buildAssets(parseSource(source, { jsx: false }), null);
|
|
369
|
+
}
|
|
370
|
+
function applyEdits(source, edits) {
|
|
371
|
+
for (const { start, end = start, text } of edits.sort((a, b) => b.start - a.start)) {
|
|
372
|
+
source = source.slice(0, start) + text + source.slice(end);
|
|
373
|
+
}
|
|
374
|
+
return source;
|
|
375
|
+
}
|
|
376
|
+
function addAssetImport(ast, source, edits) {
|
|
377
|
+
const imports = ast.program.body.filter(
|
|
378
|
+
(node) => node.type === "ImportDeclaration" && node.source.value === "@diagonal-hq/cli"
|
|
379
|
+
);
|
|
380
|
+
const hasAsset = imports.some(
|
|
381
|
+
(node) => node.importKind !== "type" && node.specifiers.some(
|
|
382
|
+
(specifier) => specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && specifier.imported.name === "asset" && specifier.local.name === "asset"
|
|
383
|
+
)
|
|
384
|
+
);
|
|
385
|
+
if (hasAsset) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const namedImport = imports.find(
|
|
389
|
+
(node) => node.importKind !== "type" && node.specifiers.some((specifier) => specifier.type === "ImportSpecifier")
|
|
390
|
+
);
|
|
391
|
+
if (namedImport) {
|
|
392
|
+
const brace = source.indexOf("{", namedImport.start);
|
|
393
|
+
edits.push({ start: brace + 1, text: " asset," });
|
|
394
|
+
} else {
|
|
395
|
+
edits.push({
|
|
396
|
+
start: ast.program.interpreter?.end ?? 0,
|
|
397
|
+
text: "\nimport { asset } from '@diagonal-hq/cli';\n"
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function writeAssetCatalog(entries) {
|
|
402
|
+
const properties = Object.entries(entries).sort(([left], [right]) => byteOrder(left, right)).map(([key, reference]) => {
|
|
403
|
+
if (!isAssetKey(key)) throw new SourceError(assetKeyMessage(key));
|
|
404
|
+
if (typeof reference !== "string") throw new SourceError("An asset reference must be a string.");
|
|
405
|
+
return ` ${key}: asset.version(${JSON.stringify(reference)})`;
|
|
406
|
+
});
|
|
407
|
+
const source = `import { defineAssets, asset } from '@diagonal-hq/cli';
|
|
408
|
+
|
|
409
|
+
export default defineAssets({
|
|
410
|
+
${properties.join(",\n")}
|
|
411
|
+
});
|
|
412
|
+
`;
|
|
413
|
+
readAssetEntries(source);
|
|
414
|
+
return source;
|
|
415
|
+
}
|
|
416
|
+
function writeAssetEntry(source, key, reference) {
|
|
417
|
+
if (!isAssetKey(key)) {
|
|
418
|
+
throw new SourceError(assetKeyMessage(key));
|
|
419
|
+
}
|
|
420
|
+
const entries = readAssetEntries(source);
|
|
421
|
+
let output;
|
|
422
|
+
if (source === null) {
|
|
423
|
+
output = `import { defineAssets, asset } from '@diagonal-hq/cli';
|
|
424
|
+
|
|
425
|
+
export default defineAssets({
|
|
426
|
+
${key}: asset.version('${reference}')
|
|
427
|
+
});
|
|
428
|
+
`;
|
|
429
|
+
} else {
|
|
430
|
+
const ast = parseSource(source, { jsx: false });
|
|
431
|
+
const { declaration } = defaultExportOf(ast);
|
|
432
|
+
const [argument] = expectDefineCall(declaration, "defineAssets", 1);
|
|
433
|
+
const definition = ["TSAsExpression", "TSSatisfiesExpression"].includes(argument.type) ? argument.expression : argument;
|
|
434
|
+
const { value } = staticObject(definition, { assetVersions: true });
|
|
435
|
+
const edits = [];
|
|
436
|
+
const existing = entries.find((entry) => entry.key === key);
|
|
437
|
+
if (existing) {
|
|
438
|
+
const node = value[key].node;
|
|
439
|
+
const quote = source[node.start];
|
|
440
|
+
edits.push({ start: node.start, end: node.end, text: `${quote}${reference}${quote}` });
|
|
441
|
+
} else {
|
|
442
|
+
const last = definition.properties.at(-1);
|
|
443
|
+
const property = `${key}: asset.version('${reference}')`;
|
|
444
|
+
const newline = source.includes("\r\n") ? "\r\n" : "\n";
|
|
445
|
+
if (!last) {
|
|
446
|
+
edits.push({ start: definition.start + 1, text: `${newline} ${property}${newline}` });
|
|
447
|
+
} else {
|
|
448
|
+
let between = source.slice(last.end, definition.end - 1);
|
|
449
|
+
for (const comment of ast.comments) {
|
|
450
|
+
if (comment.start >= last.end && comment.end < definition.end) {
|
|
451
|
+
const start = comment.start - last.end;
|
|
452
|
+
between = between.slice(0, start) + " ".repeat(comment.end - comment.start) + between.slice(comment.end - last.end);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const comma = between.indexOf(",");
|
|
456
|
+
const trailingComma = comma !== -1;
|
|
457
|
+
let lineEnd = source.indexOf("\n", last.end);
|
|
458
|
+
for (const comment of ast.comments) {
|
|
459
|
+
if (comment.start >= last.end && comment.start < lineEnd && comment.end > lineEnd) {
|
|
460
|
+
lineEnd = source.indexOf("\n", comment.end);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const multiline = last.loc.end.line < definition.loc.end.line;
|
|
464
|
+
if (multiline) {
|
|
465
|
+
const lineStart = source.lastIndexOf("\n", last.start - 1) + 1;
|
|
466
|
+
const indent = source.slice(lineStart, last.start).match(/^[\t ]*/)[0];
|
|
467
|
+
if (!trailingComma) {
|
|
468
|
+
edits.push({ start: last.end, text: "," });
|
|
469
|
+
}
|
|
470
|
+
const insertBeforeBrace = lineEnd === -1 || lineEnd >= definition.end;
|
|
471
|
+
edits.push({
|
|
472
|
+
start: insertBeforeBrace ? definition.end - 1 : lineEnd + 1,
|
|
473
|
+
text: `${insertBeforeBrace ? newline : ""}${indent}${property}${trailingComma ? "," : ""}${newline}`
|
|
474
|
+
});
|
|
475
|
+
} else {
|
|
476
|
+
edits.push({
|
|
477
|
+
start: trailingComma ? last.end + comma + 1 : last.end,
|
|
478
|
+
text: `${trailingComma ? "" : ","} ${property}${trailingComma ? "," : ""}`
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
addAssetImport(ast, source, edits);
|
|
484
|
+
output = applyEdits(source, edits);
|
|
485
|
+
}
|
|
486
|
+
const result = readAssetEntries(output);
|
|
487
|
+
const expected = new Map(entries.map((entry) => [entry.key, entry.reference]));
|
|
488
|
+
expected.set(key, reference);
|
|
489
|
+
if (result.length !== expected.size || result.some((entry) => expected.get(entry.key) !== entry.reference)) {
|
|
490
|
+
throw new SourceError("The assets.ts edit did not preserve the asset entries.");
|
|
491
|
+
}
|
|
492
|
+
return output;
|
|
493
|
+
}
|
|
494
|
+
var REFERENCE_MEMBERS = Object.freeze({ url: ".url", asset: "", key: ".key" });
|
|
495
|
+
var CSS_FORM = "css";
|
|
496
|
+
var ASSET_REFERENCE_FORMS = Object.freeze([...Object.keys(REFERENCE_MEMBERS), CSS_FORM]);
|
|
497
|
+
var isCss = (path) => path.endsWith(".css");
|
|
498
|
+
var parseCode = (path, source) => parseSource(source, { jsx: path.endsWith(".tsx") });
|
|
499
|
+
function assetName(key) {
|
|
500
|
+
return studlyName(key);
|
|
501
|
+
}
|
|
502
|
+
function takesAssetReference(path) {
|
|
503
|
+
return /\.(css|tsx?)$/.test(path) && !path.endsWith(".d.ts") && path !== ASSETS_PATH && !path.startsWith("generated/") && !path.startsWith("node_modules/");
|
|
504
|
+
}
|
|
505
|
+
function readAssetsBinding(path, source) {
|
|
506
|
+
return isCss(path) ? null : assetsBinding(parseCode(path, source), null)?.local ?? null;
|
|
507
|
+
}
|
|
508
|
+
function assetsImportEdit(ast, source) {
|
|
509
|
+
const newline = source.includes("\r\n") ? "\r\n" : "\n";
|
|
510
|
+
const last = ast.program.body.findLast((node) => node.type === "ImportDeclaration");
|
|
511
|
+
if (last) {
|
|
512
|
+
const quote = source[last.source.start];
|
|
513
|
+
const semicolon = source[last.end - 1] === ";" ? ";" : "";
|
|
514
|
+
return {
|
|
515
|
+
start: last.end,
|
|
516
|
+
text: `${newline}import { ${ASSETS_EXPORT} } from ${quote}${GENERATED_ASSETS_MODULE}${quote}${semicolon}`
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
const statement = `import { ${ASSETS_EXPORT} } from '${GENERATED_ASSETS_MODULE}';`;
|
|
520
|
+
const start = ast.program.directives.at(-1)?.end ?? ast.program.interpreter?.end ?? 0;
|
|
521
|
+
if (start > 0) {
|
|
522
|
+
return { start, text: `${newline}${statement}` };
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
start,
|
|
526
|
+
text: `${statement}${newline}${source === "" || /^\r?\n/.test(source) ? "" : newline}`
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function referenceExpressionAt(ast, offset, end) {
|
|
530
|
+
let found = null;
|
|
531
|
+
traverse2(ast, {
|
|
532
|
+
Identifier(path) {
|
|
533
|
+
if (path.node.start === offset) {
|
|
534
|
+
found = path;
|
|
535
|
+
path.stop();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
if (found === null || !found.isReferencedIdentifier()) {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
let expression = found;
|
|
543
|
+
while (expression.parentPath.isMemberExpression() && expression.key === "object" && !expression.parent.computed && expression.parent.end <= end) {
|
|
544
|
+
expression = expression.parentPath;
|
|
545
|
+
}
|
|
546
|
+
return expression.node.end === end ? found : null;
|
|
547
|
+
}
|
|
548
|
+
function insertAssetReference(path, source, { key, form, start, end }) {
|
|
549
|
+
if (!isAssetKey(key)) {
|
|
550
|
+
throw new SourceError(assetKeyMessage(key));
|
|
551
|
+
}
|
|
552
|
+
if (isCss(path) !== (form === CSS_FORM)) {
|
|
553
|
+
throw new SourceError(
|
|
554
|
+
isCss(path) ? "A CSS file takes an asset as url(asset:<key>)." : "A TypeScript file takes an asset as Assets.<Name>, Assets.<Name>.url, or Assets.<Name>.key."
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
if (isCss(path)) {
|
|
558
|
+
return applyEdits(source, [{ start, end, text: `url(asset:${key})` }]);
|
|
559
|
+
}
|
|
560
|
+
const reference = (local2) => ({
|
|
561
|
+
start,
|
|
562
|
+
end,
|
|
563
|
+
text: `${local2}.${assetName(key)}${REFERENCE_MEMBERS[form]}`
|
|
564
|
+
});
|
|
565
|
+
let ast;
|
|
566
|
+
try {
|
|
567
|
+
ast = parseCode(path, applyEdits(source, [reference(ASSETS_EXPORT)]));
|
|
568
|
+
} catch (error) {
|
|
569
|
+
if (!(error instanceof SyntaxError)) {
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
parseCode(path, source);
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
const edits = [];
|
|
576
|
+
let local = assetsBinding(ast, null)?.local ?? null;
|
|
577
|
+
let referenceStart = start;
|
|
578
|
+
if (local === null) {
|
|
579
|
+
if (bindsName(ast, ASSETS_EXPORT)) {
|
|
580
|
+
throw new SourceError(
|
|
581
|
+
`This file already declares ${ASSETS_EXPORT}. Rename it, or import the generated assets under another name, such as import { ${ASSETS_EXPORT} as AppAssets } from '${GENERATED_ASSETS_MODULE}'. Then insert the asset again.`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
const importEdit = assetsImportEdit(ast, source);
|
|
585
|
+
if (importEdit.start > start) {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
local = ASSETS_EXPORT;
|
|
589
|
+
edits.push(importEdit);
|
|
590
|
+
referenceStart += importEdit.text.length;
|
|
591
|
+
}
|
|
592
|
+
const referenceEdit = reference(local);
|
|
593
|
+
edits.unshift(referenceEdit);
|
|
594
|
+
const output = applyEdits(source, edits);
|
|
595
|
+
const outputAst = parseCode(path, output);
|
|
596
|
+
if (assetsBinding(outputAst, null)?.local !== local) {
|
|
597
|
+
throw new SourceError(`The edit did not keep the ${ASSETS_EXPORT} import.`);
|
|
598
|
+
}
|
|
599
|
+
const referenceEnd = referenceStart + referenceEdit.text.length;
|
|
600
|
+
const identifier = referenceExpressionAt(outputAst, referenceStart, referenceEnd);
|
|
601
|
+
if (identifier === null) {
|
|
602
|
+
return output;
|
|
603
|
+
}
|
|
604
|
+
const binding = identifier.scope.getBinding(local);
|
|
605
|
+
if (binding?.path.isImportSpecifier() !== true || binding.path.parent.source.value !== GENERATED_ASSETS_MODULE) {
|
|
606
|
+
throw new SourceError(
|
|
607
|
+
`A local declaration of ${local} hides the generated ${ASSETS_EXPORT} at the cursor. Rename the local declaration. Then insert the asset again.`
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
return output;
|
|
611
|
+
}
|
|
612
|
+
|
|
345
613
|
export {
|
|
346
614
|
WORKFLOWS_USAGE,
|
|
347
615
|
RUN_USAGE,
|
|
@@ -355,5 +623,14 @@ export {
|
|
|
355
623
|
showLogs,
|
|
356
624
|
ASSETS_UPLOAD_USAGE,
|
|
357
625
|
ASSETS_LIST_USAGE,
|
|
358
|
-
formatDiagnostic
|
|
626
|
+
formatDiagnostic,
|
|
627
|
+
ASSETS_PATH,
|
|
628
|
+
readAssetEntries,
|
|
629
|
+
writeAssetCatalog,
|
|
630
|
+
writeAssetEntry,
|
|
631
|
+
ASSET_REFERENCE_FORMS,
|
|
632
|
+
assetName,
|
|
633
|
+
takesAssetReference,
|
|
634
|
+
readAssetsBinding,
|
|
635
|
+
insertAssetReference
|
|
359
636
|
};
|