@diagonal-hq/cli 0.9.1 → 0.9.3
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 +22 -2
- package/dist/cli.mjs +478 -104
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ This package is the authoring SDK for file-based workspaces. A workspace reposit
|
|
|
6
6
|
- Types for the helpers, `WorkflowConfig`, and the `Sdk` and `React` globals.
|
|
7
7
|
- Editor types for the workflow script SDK: `@diagonal/workflow`, `@diagonal/workflow/testing`, and `@diagonal/workflow/workspace`.
|
|
8
8
|
- The `diagonal check` command. It runs the same build and checks that a platform deploy runs, including the workflow tests. It also writes `generated/resources.ts` and the missing definition uids.
|
|
9
|
+
- The `diagonal assets upload` and `diagonal assets list` commands. They upload Application Assets, update `assets.ts`, and list immutable references.
|
|
9
10
|
- The `diagonal workflows` and `diagonal run` commands. They list the deployed workflows and run a manual workflow by its file path.
|
|
10
11
|
|
|
11
12
|
## Check a workspace
|
|
@@ -26,6 +27,10 @@ diagonal check [dir] [--json]
|
|
|
26
27
|
|
|
27
28
|
Each diagnostic prints as `path:line:column severity message`. The command exits with 1 when an error exists, with 2 for a usage error, and with 0 otherwise.
|
|
28
29
|
|
|
30
|
+
## Workspace API credentials
|
|
31
|
+
|
|
32
|
+
The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY`. Workflow commands require `manage_workflows`. Asset commands require `manage_workspace_settings`. A System Administrator has both permissions. Keep API keys out of the repository.
|
|
33
|
+
|
|
29
34
|
## Run a deployed workflow
|
|
30
35
|
|
|
31
36
|
`diagonal workflows` and `diagonal run` call the runtime API of a deployed workspace. Set two environment variables first:
|
|
@@ -383,7 +388,22 @@ A workflow script reads the capabilities of each resource from `@diagonal/workfl
|
|
|
383
388
|
|
|
384
389
|
## Application asset references
|
|
385
390
|
|
|
386
|
-
|
|
391
|
+
Run the upload command in the workspace root, the folder with `diagonal.config.ts`:
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
diagonal assets upload <file> [--key <key>] [--no-write] [--json]
|
|
395
|
+
diagonal assets list [--search <text>] [--versions] [--json]
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
`diagonal assets upload hero.png --key hero` creates or updates the `hero` entry in `assets.ts`. An existing key adds a version to the asset that owns its current reference. A new key creates an asset whose display name defaults to the file name. Identical bytes for an existing key reuse its latest version. The command preserves source comments and formatting.
|
|
399
|
+
|
|
400
|
+
`--key` is required unless `--no-write` is given. `--no-write` writes nothing and prints only the version reference. It can run outside a workspace root. With an existing key in a valid `assets.ts`, it still adds a version to that key's asset. `--json` prints `{ key, written, asset, version }`.
|
|
401
|
+
|
|
402
|
+
`diagonal assets list` reads every index page and prints each asset with its latest version. `--search` filters by display name or latest filename. `--versions` also fetches each asset's newest 100 versions and reports when older versions are omitted. `--json` prints `{ data: [...] }`, with `versions` added when requested.
|
|
403
|
+
|
|
404
|
+
Both commands exit with 0 on success, 1 for a request failure or a refused `assets.ts`, and 2 for a usage error or missing environment variables. Manifest errors use the same `assets.ts:line:column error message` format as `diagonal check`. Uploads require a file-based workspace and `manage_workspace_settings`. The command checks access before it sends file bytes.
|
|
405
|
+
|
|
406
|
+
Other API clients can upload in two steps. `POST /api/files/uploads` with a multipart `file` returns `{key}`. `POST /api/application-assets` with `{"upload_key": "<key>"}` returns the asset and its immutable version `reference`. To replace an existing key, resolve its reference with `GET /api/application-asset-versions/{reference}`, then use `POST /api/application-assets/{asset}/versions`. The CLI writes the optional root `assets.ts` in this form:
|
|
387
407
|
|
|
388
408
|
```ts
|
|
389
409
|
import { defineAssets, asset } from '@diagonal-hq/cli';
|
|
@@ -393,7 +413,7 @@ export default defineAssets({
|
|
|
393
413
|
});
|
|
394
414
|
```
|
|
395
415
|
|
|
396
|
-
Use `background: url(asset:hero)` in a CSS file. The hosted build replaces it with the version's delivery URL and records its verified digest in the deployment manifest. SVG and
|
|
416
|
+
Use `background: url(asset:hero)` in a CSS file. The hosted build replaces it with the version's delivery URL and records its verified digest in the deployment manifest. SVG, ICO, WOFF and WOFF2 files are Application Assets too. Use `@font-face { font-family: Brand; src: url(asset:brandFont) format('woff2'); }` in a CSS file. Asset keys match `^[a-z][A-Za-z0-9]*$`.
|
|
397
417
|
|
|
398
418
|
`diagonal check` validates this file offline. Each key must be a camelCase name of at most 64 letters and digits that starts with a lowercase letter, such as `hero`; otherwise the check reports `Asset key "<key>" must be a camelCase name ...` at the key. The manifest can have at most 500 entries. Each value must be `asset.version()` with one lower-case UUID string literal written without escapes. The default export must be `defineAssets({...})`. Other calls and non-literal expressions fail at their source location. The hosted build also checks that each version belongs to this application's asset library.
|
|
399
419
|
|
package/dist/cli.mjs
CHANGED
|
@@ -13287,7 +13287,7 @@ ${lanes.join("\n")}
|
|
|
13287
13287
|
return process.memoryUsage().heapUsed;
|
|
13288
13288
|
},
|
|
13289
13289
|
getFileSize(path) {
|
|
13290
|
-
const stat =
|
|
13290
|
+
const stat = statSync5(path);
|
|
13291
13291
|
if (stat == null ? void 0 : stat.isFile()) {
|
|
13292
13292
|
return stat.size;
|
|
13293
13293
|
}
|
|
@@ -13331,7 +13331,7 @@ ${lanes.join("\n")}
|
|
|
13331
13331
|
}
|
|
13332
13332
|
};
|
|
13333
13333
|
return nodeSystem;
|
|
13334
|
-
function
|
|
13334
|
+
function statSync5(path) {
|
|
13335
13335
|
try {
|
|
13336
13336
|
return _fs.statSync(path, statSyncOptions);
|
|
13337
13337
|
} catch {
|
|
@@ -13390,7 +13390,7 @@ ${lanes.join("\n")}
|
|
|
13390
13390
|
activeSession.post("Profiler.stop", (err, { profile }) => {
|
|
13391
13391
|
var _a;
|
|
13392
13392
|
if (!err) {
|
|
13393
|
-
if ((_a =
|
|
13393
|
+
if ((_a = statSync5(profilePath)) == null ? void 0 : _a.isDirectory()) {
|
|
13394
13394
|
profilePath = _path.join(profilePath, `${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}+P${process.pid}.cpuprofile`);
|
|
13395
13395
|
}
|
|
13396
13396
|
try {
|
|
@@ -13510,7 +13510,7 @@ ${lanes.join("\n")}
|
|
|
13510
13510
|
let stat;
|
|
13511
13511
|
if (typeof dirent === "string" || dirent.isSymbolicLink()) {
|
|
13512
13512
|
const name = combinePaths(path, entry);
|
|
13513
|
-
stat =
|
|
13513
|
+
stat = statSync5(name);
|
|
13514
13514
|
if (!stat) {
|
|
13515
13515
|
continue;
|
|
13516
13516
|
}
|
|
@@ -13534,7 +13534,7 @@ ${lanes.join("\n")}
|
|
|
13534
13534
|
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames2, process.cwd(), depth, getAccessibleFileSystemEntries, realpath);
|
|
13535
13535
|
}
|
|
13536
13536
|
function fileSystemEntryExists(path, entryKind) {
|
|
13537
|
-
const stat =
|
|
13537
|
+
const stat = statSync5(path);
|
|
13538
13538
|
if (!stat) {
|
|
13539
13539
|
return false;
|
|
13540
13540
|
}
|
|
@@ -13576,7 +13576,7 @@ ${lanes.join("\n")}
|
|
|
13576
13576
|
}
|
|
13577
13577
|
function getModifiedTime3(path) {
|
|
13578
13578
|
var _a;
|
|
13579
|
-
return (_a =
|
|
13579
|
+
return (_a = statSync5(path)) == null ? void 0 : _a.mtime;
|
|
13580
13580
|
}
|
|
13581
13581
|
function setModifiedTime(path, time) {
|
|
13582
13582
|
try {
|
|
@@ -128929,7 +128929,7 @@ ${lanes.join("\n")}
|
|
|
128929
128929
|
}
|
|
128930
128930
|
}
|
|
128931
128931
|
function createImportCallExpressionAMD(arg, containsLexicalThis) {
|
|
128932
|
-
const
|
|
128932
|
+
const resolve6 = factory2.createUniqueName("resolve");
|
|
128933
128933
|
const reject = factory2.createUniqueName("reject");
|
|
128934
128934
|
const parameters = [
|
|
128935
128935
|
factory2.createParameterDeclaration(
|
|
@@ -128938,7 +128938,7 @@ ${lanes.join("\n")}
|
|
|
128938
128938
|
/*dotDotDotToken*/
|
|
128939
128939
|
void 0,
|
|
128940
128940
|
/*name*/
|
|
128941
|
-
|
|
128941
|
+
resolve6
|
|
128942
128942
|
),
|
|
128943
128943
|
factory2.createParameterDeclaration(
|
|
128944
128944
|
/*modifiers*/
|
|
@@ -128955,7 +128955,7 @@ ${lanes.join("\n")}
|
|
|
128955
128955
|
factory2.createIdentifier("require"),
|
|
128956
128956
|
/*typeArguments*/
|
|
128957
128957
|
void 0,
|
|
128958
|
-
[factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]),
|
|
128958
|
+
[factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve6, reject]
|
|
128959
128959
|
)
|
|
128960
128960
|
)
|
|
128961
128961
|
]);
|
|
@@ -141766,9 +141766,9 @@ ${lanes.join("\n")}
|
|
|
141766
141766
|
/*ignoreCase*/
|
|
141767
141767
|
false
|
|
141768
141768
|
)) {
|
|
141769
|
-
const
|
|
141770
|
-
if (
|
|
141771
|
-
const name = removeSuffix(removePrefix(
|
|
141769
|
+
const basename5 = getBaseFileName(a.fileName);
|
|
141770
|
+
if (basename5 === "lib.d.ts" || basename5 === "lib.es6.d.ts") return 0;
|
|
141771
|
+
const name = removeSuffix(removePrefix(basename5, "lib."), ".d.ts");
|
|
141772
141772
|
const index3 = libs.indexOf(name);
|
|
141773
141773
|
if (index3 !== -1) return index3 + 1;
|
|
141774
141774
|
}
|
|
@@ -205714,8 +205714,8 @@ ${options2.prefix}` : "\n" : options2.prefix
|
|
|
205714
205714
|
}
|
|
205715
205715
|
};
|
|
205716
205716
|
for (const file2 of files) {
|
|
205717
|
-
const
|
|
205718
|
-
if (
|
|
205717
|
+
const basename5 = getBaseFileName(file2);
|
|
205718
|
+
if (basename5 === "package.json" || basename5 === "bower.json") {
|
|
205719
205719
|
createProjectWatcher(
|
|
205720
205720
|
file2,
|
|
205721
205721
|
"FileWatcher"
|
|
@@ -209399,8 +209399,8 @@ All files are: ${JSON.stringify(names2)}`,
|
|
|
209399
209399
|
var _a;
|
|
209400
209400
|
const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
|
|
209401
209401
|
if (!fileOrDirectoryPath) return;
|
|
209402
|
-
const
|
|
209403
|
-
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (
|
|
209402
|
+
const basename5 = getBaseFileName(fileOrDirectoryPath);
|
|
209403
|
+
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename5 === "package.json" || basename5 === "node_modules")) {
|
|
209404
209404
|
result.affectedModuleSpecifierCacheProjects.forEach((project) => {
|
|
209405
209405
|
var _a2;
|
|
209406
209406
|
(_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
|
|
@@ -215089,11 +215089,11 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
|
|
|
215089
215089
|
return { fileName: textChanges2.fileName, textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: change.newText }] };
|
|
215090
215090
|
}
|
|
215091
215091
|
function getLocationInNewDocument(oldText, renameFilename, renameLocation, edits) {
|
|
215092
|
-
const newText =
|
|
215092
|
+
const newText = applyEdits2(oldText, renameFilename, edits);
|
|
215093
215093
|
const { line, character } = computeLineAndCharacterOfPosition(computeLineStarts(newText), renameLocation);
|
|
215094
215094
|
return { line: line + 1, offset: character + 1 };
|
|
215095
215095
|
}
|
|
215096
|
-
function
|
|
215096
|
+
function applyEdits2(text, textFilename, edits) {
|
|
215097
215097
|
for (const { fileName, textChanges: textChanges2 } of edits) {
|
|
215098
215098
|
if (fileName !== textFilename) {
|
|
215099
215099
|
continue;
|
|
@@ -215886,8 +215886,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
|
|
|
215886
215886
|
installPackage(options2) {
|
|
215887
215887
|
this.packageInstallId++;
|
|
215888
215888
|
const request2 = { kind: "installPackage", ...options2, id: this.packageInstallId };
|
|
215889
|
-
const promise = new Promise((
|
|
215890
|
-
(this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve:
|
|
215889
|
+
const promise = new Promise((resolve6, reject) => {
|
|
215890
|
+
(this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve6, reject });
|
|
215891
215891
|
});
|
|
215892
215892
|
this.installer.send(request2);
|
|
215893
215893
|
return promise;
|
|
@@ -229491,7 +229491,7 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
229491
229491
|
}
|
|
229492
229492
|
url.path = path;
|
|
229493
229493
|
}
|
|
229494
|
-
function
|
|
229494
|
+
function resolve6(input, base2) {
|
|
229495
229495
|
if (!input && !base2)
|
|
229496
229496
|
return "";
|
|
229497
229497
|
const url = parseUrl2(input);
|
|
@@ -229544,7 +229544,7 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
229544
229544
|
return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
|
|
229545
229545
|
}
|
|
229546
229546
|
}
|
|
229547
|
-
return
|
|
229547
|
+
return resolve6;
|
|
229548
229548
|
}));
|
|
229549
229549
|
}
|
|
229550
229550
|
});
|
|
@@ -229890,8 +229890,8 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
229890
229890
|
this.sources = sources;
|
|
229891
229891
|
this.sourcesContent = sourcesContent;
|
|
229892
229892
|
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
229893
|
-
const
|
|
229894
|
-
this.resolvedSources = sources.map(
|
|
229893
|
+
const resolve6 = resolver2(mapUrl, sourceRoot);
|
|
229894
|
+
this.resolvedSources = sources.map(resolve6);
|
|
229895
229895
|
const { mappings } = parsed;
|
|
229896
229896
|
if (typeof mappings === "string") {
|
|
229897
229897
|
this._encoded = mappings;
|
|
@@ -249229,8 +249229,8 @@ interface GeneratorFunctionConstructor {
|
|
|
249229
249229
|
|
|
249230
249230
|
// scripts/lib/runtime-build/check-cli.mjs
|
|
249231
249231
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
249232
|
-
import { statSync as
|
|
249233
|
-
import { resolve as
|
|
249232
|
+
import { statSync as statSync4 } from "node:fs";
|
|
249233
|
+
import { resolve as resolve5 } from "node:path";
|
|
249234
249234
|
|
|
249235
249235
|
// scripts/lib/runtime-build/api-cli.mjs
|
|
249236
249236
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
@@ -249260,16 +249260,18 @@ function errorText(status, body) {
|
|
|
249260
249260
|
return `${lines.join("\n")}
|
|
249261
249261
|
`;
|
|
249262
249262
|
}
|
|
249263
|
-
async function request({ url, apiKey }, method, path, body, stderr) {
|
|
249263
|
+
async function request({ url, apiKey }, method, path, body, stderr, { responseDetails = false } = {}) {
|
|
249264
249264
|
const headers = { Accept: "application/json", Authorization: `Bearer ${apiKey}` };
|
|
249265
|
-
const init = body === void 0 ? { method, headers } : {
|
|
249265
|
+
const init = body === void 0 || body instanceof FormData ? { method, headers, body } : {
|
|
249266
249266
|
method,
|
|
249267
249267
|
headers: { ...headers, "Content-Type": "application/json" },
|
|
249268
249268
|
body: JSON.stringify(body)
|
|
249269
249269
|
};
|
|
249270
249270
|
let response;
|
|
249271
|
+
let text;
|
|
249271
249272
|
try {
|
|
249272
249273
|
response = await fetch(`${url}${path}`, init);
|
|
249274
|
+
text = await response.text();
|
|
249273
249275
|
} catch (error) {
|
|
249274
249276
|
if (!(error instanceof TypeError)) {
|
|
249275
249277
|
throw error;
|
|
@@ -249278,7 +249280,6 @@ async function request({ url, apiKey }, method, path, body, stderr) {
|
|
|
249278
249280
|
`);
|
|
249279
249281
|
return null;
|
|
249280
249282
|
}
|
|
249281
|
-
const text = await response.text();
|
|
249282
249283
|
let json;
|
|
249283
249284
|
try {
|
|
249284
249285
|
json = JSON.parse(text);
|
|
@@ -249290,6 +249291,9 @@ async function request({ url, apiKey }, method, path, body, stderr) {
|
|
|
249290
249291
|
`);
|
|
249291
249292
|
return null;
|
|
249292
249293
|
}
|
|
249294
|
+
if (responseDetails) {
|
|
249295
|
+
return { ok: response.ok, status: response.status, body: json };
|
|
249296
|
+
}
|
|
249293
249297
|
if (!response.ok) {
|
|
249294
249298
|
stderr.write(errorText(response.status, json));
|
|
249295
249299
|
return null;
|
|
@@ -249313,7 +249317,7 @@ function parseFlags(args, valueFlags, booleanFlags) {
|
|
|
249313
249317
|
if (!valueFlags.includes(arg)) {
|
|
249314
249318
|
return { error: `Unknown option ${arg}` };
|
|
249315
249319
|
}
|
|
249316
|
-
if (index3 + 1 >= args.length) {
|
|
249320
|
+
if (index3 + 1 >= args.length || args[index3 + 1].startsWith("--")) {
|
|
249317
249321
|
return { error: `${arg} needs a value` };
|
|
249318
249322
|
}
|
|
249319
249323
|
values[arg] = args[++index3];
|
|
@@ -249424,10 +249428,13 @@ ${RUN_USAGE}
|
|
|
249424
249428
|
return succeeded ? 0 : 1;
|
|
249425
249429
|
}
|
|
249426
249430
|
|
|
249427
|
-
// scripts/lib/runtime-build/
|
|
249431
|
+
// scripts/lib/runtime-build/assets-cli.mjs
|
|
249432
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
249433
|
+
import { readFileSync, statSync as statSync2, writeFileSync } from "node:fs";
|
|
249434
|
+
import { basename as basename2, join as join2, resolve } from "node:path";
|
|
249435
|
+
|
|
249436
|
+
// scripts/lib/runtime-build/assets-file.mjs
|
|
249428
249437
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
249429
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync7, readdirSync as readdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
249430
|
-
import { basename as basename3, dirname as dirname6, extname as extname2, join as join10, relative as relative4, sep } from "node:path";
|
|
249431
249438
|
|
|
249432
249439
|
// scripts/lib/runtime-build/assets.mjs
|
|
249433
249440
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
@@ -264369,6 +264376,12 @@ var VERSION_REFERENCE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-
|
|
|
264369
264376
|
function isAssetKey(key) {
|
|
264370
264377
|
return key.length <= 64 && ASSET_KEY.test(key);
|
|
264371
264378
|
}
|
|
264379
|
+
function assetKeyMessage(key) {
|
|
264380
|
+
return `Asset key "${key}" must be a camelCase name of at most 64 letters and digits that starts with a lowercase letter, such as 'hero'`;
|
|
264381
|
+
}
|
|
264382
|
+
function assetLibraryMessage(reference) {
|
|
264383
|
+
return `Asset version "${reference}" is not in this application's asset library`;
|
|
264384
|
+
}
|
|
264372
264385
|
function buildAssets(ast, catalog) {
|
|
264373
264386
|
const { declaration } = defaultExportOf(ast);
|
|
264374
264387
|
const [definition] = expectDefineCall(declaration, "defineAssets", 1);
|
|
@@ -264378,10 +264391,7 @@ function buildAssets(ast, catalog) {
|
|
|
264378
264391
|
}
|
|
264379
264392
|
return Object.entries(value).map(([key, version]) => {
|
|
264380
264393
|
if (!isAssetKey(key)) {
|
|
264381
|
-
throw new SourceError(
|
|
264382
|
-
`Asset key "${key}" must be a camelCase name of at most 64 letters and digits that starts with a lowercase letter, such as 'hero'`,
|
|
264383
|
-
nodes[key].key
|
|
264384
|
-
);
|
|
264394
|
+
throw new SourceError(assetKeyMessage(key), nodes[key].key);
|
|
264385
264395
|
}
|
|
264386
264396
|
if (!(version instanceof AssetVersionValue)) {
|
|
264387
264397
|
throw new SourceError(
|
|
@@ -264393,10 +264403,7 @@ function buildAssets(ast, catalog) {
|
|
|
264393
264403
|
throw new SourceError("An asset version reference must be a lower-case UUID", version.node);
|
|
264394
264404
|
}
|
|
264395
264405
|
if (catalog !== null && !Object.hasOwn(catalog, version.reference)) {
|
|
264396
|
-
throw new SourceError(
|
|
264397
|
-
`Asset version "${version.reference}" is not in this application's asset library`,
|
|
264398
|
-
version.node
|
|
264399
|
-
);
|
|
264406
|
+
throw new SourceError(assetLibraryMessage(version.reference), version.node);
|
|
264400
264407
|
}
|
|
264401
264408
|
return {
|
|
264402
264409
|
key,
|
|
@@ -264407,6 +264414,368 @@ function buildAssets(ast, catalog) {
|
|
|
264407
264414
|
});
|
|
264408
264415
|
}
|
|
264409
264416
|
|
|
264417
|
+
// scripts/lib/runtime-build/assets-file.mjs
|
|
264418
|
+
function readAssetEntries(source) {
|
|
264419
|
+
return source === null ? [] : buildAssets(parseSource(source, { jsx: false }), null);
|
|
264420
|
+
}
|
|
264421
|
+
function applyEdits(source, edits) {
|
|
264422
|
+
for (const { start, end = start, text } of edits.sort((a, b2) => b2.start - a.start)) {
|
|
264423
|
+
source = source.slice(0, start) + text + source.slice(end);
|
|
264424
|
+
}
|
|
264425
|
+
return source;
|
|
264426
|
+
}
|
|
264427
|
+
function addAssetImport(ast, source, edits) {
|
|
264428
|
+
const imports = ast.program.body.filter(
|
|
264429
|
+
(node) => node.type === "ImportDeclaration" && node.source.value === "@diagonal-hq/cli"
|
|
264430
|
+
);
|
|
264431
|
+
const hasAsset = imports.some(
|
|
264432
|
+
(node) => node.importKind !== "type" && node.specifiers.some(
|
|
264433
|
+
(specifier) => specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && specifier.imported.name === "asset" && specifier.local.name === "asset"
|
|
264434
|
+
)
|
|
264435
|
+
);
|
|
264436
|
+
if (hasAsset) {
|
|
264437
|
+
return;
|
|
264438
|
+
}
|
|
264439
|
+
const namedImport = imports.find(
|
|
264440
|
+
(node) => node.importKind !== "type" && node.specifiers.some((specifier) => specifier.type === "ImportSpecifier")
|
|
264441
|
+
);
|
|
264442
|
+
if (namedImport) {
|
|
264443
|
+
const brace = source.indexOf("{", namedImport.start);
|
|
264444
|
+
edits.push({ start: brace + 1, text: " asset," });
|
|
264445
|
+
} else {
|
|
264446
|
+
edits.push({
|
|
264447
|
+
start: ast.program.interpreter?.end ?? 0,
|
|
264448
|
+
text: "\nimport { asset } from '@diagonal-hq/cli';\n"
|
|
264449
|
+
});
|
|
264450
|
+
}
|
|
264451
|
+
}
|
|
264452
|
+
function writeAssetEntry(source, key, reference) {
|
|
264453
|
+
if (!isAssetKey(key)) {
|
|
264454
|
+
throw new SourceError(assetKeyMessage(key));
|
|
264455
|
+
}
|
|
264456
|
+
const entries = readAssetEntries(source);
|
|
264457
|
+
let output;
|
|
264458
|
+
if (source === null) {
|
|
264459
|
+
output = `import { defineAssets, asset } from '@diagonal-hq/cli';
|
|
264460
|
+
|
|
264461
|
+
export default defineAssets({
|
|
264462
|
+
${key}: asset.version('${reference}')
|
|
264463
|
+
});
|
|
264464
|
+
`;
|
|
264465
|
+
} else {
|
|
264466
|
+
const ast = parseSource(source, { jsx: false });
|
|
264467
|
+
const { declaration } = defaultExportOf(ast);
|
|
264468
|
+
const [argument] = expectDefineCall(declaration, "defineAssets", 1);
|
|
264469
|
+
const definition = ["TSAsExpression", "TSSatisfiesExpression"].includes(argument.type) ? argument.expression : argument;
|
|
264470
|
+
const { value } = staticObject(definition, { assetVersions: true });
|
|
264471
|
+
const edits = [];
|
|
264472
|
+
const existing = entries.find((entry) => entry.key === key);
|
|
264473
|
+
if (existing) {
|
|
264474
|
+
const node = value[key].node;
|
|
264475
|
+
const quote = source[node.start];
|
|
264476
|
+
edits.push({ start: node.start, end: node.end, text: `${quote}${reference}${quote}` });
|
|
264477
|
+
} else {
|
|
264478
|
+
const last2 = definition.properties.at(-1);
|
|
264479
|
+
const property = `${key}: asset.version('${reference}')`;
|
|
264480
|
+
const newline = source.includes("\r\n") ? "\r\n" : "\n";
|
|
264481
|
+
if (!last2) {
|
|
264482
|
+
edits.push({ start: definition.start + 1, text: `${newline} ${property}${newline}` });
|
|
264483
|
+
} else {
|
|
264484
|
+
let between = source.slice(last2.end, definition.end - 1);
|
|
264485
|
+
for (const comment of ast.comments) {
|
|
264486
|
+
if (comment.start >= last2.end && comment.end < definition.end) {
|
|
264487
|
+
const start = comment.start - last2.end;
|
|
264488
|
+
between = between.slice(0, start) + " ".repeat(comment.end - comment.start) + between.slice(comment.end - last2.end);
|
|
264489
|
+
}
|
|
264490
|
+
}
|
|
264491
|
+
const comma2 = between.indexOf(",");
|
|
264492
|
+
const trailingComma = comma2 !== -1;
|
|
264493
|
+
let lineEnd = source.indexOf("\n", last2.end);
|
|
264494
|
+
for (const comment of ast.comments) {
|
|
264495
|
+
if (comment.start >= last2.end && comment.start < lineEnd && comment.end > lineEnd) {
|
|
264496
|
+
lineEnd = source.indexOf("\n", comment.end);
|
|
264497
|
+
}
|
|
264498
|
+
}
|
|
264499
|
+
const multiline = last2.loc.end.line < definition.loc.end.line;
|
|
264500
|
+
if (multiline) {
|
|
264501
|
+
const lineStart = source.lastIndexOf("\n", last2.start - 1) + 1;
|
|
264502
|
+
const indent = source.slice(lineStart, last2.start).match(/^[\t ]*/)[0];
|
|
264503
|
+
if (!trailingComma) {
|
|
264504
|
+
edits.push({ start: last2.end, text: "," });
|
|
264505
|
+
}
|
|
264506
|
+
const insertBeforeBrace = lineEnd === -1 || lineEnd >= definition.end;
|
|
264507
|
+
edits.push({
|
|
264508
|
+
start: insertBeforeBrace ? definition.end - 1 : lineEnd + 1,
|
|
264509
|
+
text: `${insertBeforeBrace ? newline : ""}${indent}${property}${trailingComma ? "," : ""}${newline}`
|
|
264510
|
+
});
|
|
264511
|
+
} else {
|
|
264512
|
+
edits.push({
|
|
264513
|
+
start: trailingComma ? last2.end + comma2 + 1 : last2.end,
|
|
264514
|
+
text: `${trailingComma ? "" : ","} ${property}${trailingComma ? "," : ""}`
|
|
264515
|
+
});
|
|
264516
|
+
}
|
|
264517
|
+
}
|
|
264518
|
+
}
|
|
264519
|
+
addAssetImport(ast, source, edits);
|
|
264520
|
+
output = applyEdits(source, edits);
|
|
264521
|
+
}
|
|
264522
|
+
const result = readAssetEntries(output);
|
|
264523
|
+
const expected = new Map(entries.map((entry) => [entry.key, entry.reference]));
|
|
264524
|
+
expected.set(key, reference);
|
|
264525
|
+
if (result.length !== expected.size || result.some((entry) => expected.get(entry.key) !== entry.reference)) {
|
|
264526
|
+
throw new SourceError("The assets.ts edit did not preserve the asset entries.");
|
|
264527
|
+
}
|
|
264528
|
+
return output;
|
|
264529
|
+
}
|
|
264530
|
+
|
|
264531
|
+
// scripts/lib/runtime-build/format-diagnostic.mjs
|
|
264532
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
264533
|
+
function formatDiagnostic(diagnostic2) {
|
|
264534
|
+
const [headline, ...details] = diagnostic2.message.split("\n");
|
|
264535
|
+
const lines = [
|
|
264536
|
+
`${diagnostic2.path}:${diagnostic2.line}:${diagnostic2.column} ${diagnostic2.severity} ${headline}`
|
|
264537
|
+
];
|
|
264538
|
+
for (const detail of details) {
|
|
264539
|
+
lines.push(` ${detail}`);
|
|
264540
|
+
}
|
|
264541
|
+
return lines.join("\n");
|
|
264542
|
+
}
|
|
264543
|
+
|
|
264544
|
+
// scripts/lib/runtime-build/assets-cli.mjs
|
|
264545
|
+
var ASSETS_UPLOAD_USAGE = "Usage: diagonal assets upload <file> [--key <key>] [--no-write] [--json]";
|
|
264546
|
+
var ASSETS_LIST_USAGE = "Usage: diagonal assets list [--search <text>] [--versions] [--json]";
|
|
264547
|
+
var NIL_REFERENCE = "00000000-0000-0000-0000-000000000000";
|
|
264548
|
+
var MISSING_VERSION = "This version is not in the Application Asset library.";
|
|
264549
|
+
function readManifest(path) {
|
|
264550
|
+
try {
|
|
264551
|
+
return readFileSync(path, "utf8");
|
|
264552
|
+
} catch (error) {
|
|
264553
|
+
if (error.code === "ENOENT") {
|
|
264554
|
+
return null;
|
|
264555
|
+
}
|
|
264556
|
+
throw error;
|
|
264557
|
+
}
|
|
264558
|
+
}
|
|
264559
|
+
function printFileError(error, stderr) {
|
|
264560
|
+
if (error instanceof SourceError || error instanceof SyntaxError) {
|
|
264561
|
+
stderr.write(`${formatDiagnostic(diagnosticFromError("assets.ts", error))}
|
|
264562
|
+
`);
|
|
264563
|
+
} else if (error.code) {
|
|
264564
|
+
stderr.write(`Could not access assets.ts: ${error.message}
|
|
264565
|
+
`);
|
|
264566
|
+
} else {
|
|
264567
|
+
throw error;
|
|
264568
|
+
}
|
|
264569
|
+
}
|
|
264570
|
+
async function uploadAsset(args, { cwd, env: env2, stdout, stderr }) {
|
|
264571
|
+
const parsed = parseFlags(args, ["--key"], ["--no-write", "--json"]);
|
|
264572
|
+
const key = parsed.values?.["--key"];
|
|
264573
|
+
const noWrite = parsed.booleans?.has("--no-write");
|
|
264574
|
+
const usageError = parsed.error ?? (parsed.positional.length !== 1 ? "Give one file to upload" : key !== void 0 && !isAssetKey(key) ? assetKeyMessage(key) : !noWrite && key === void 0 ? "--key is required unless --no-write is given" : null);
|
|
264575
|
+
if (usageError !== null) {
|
|
264576
|
+
stderr.write(`${usageError}
|
|
264577
|
+
${ASSETS_UPLOAD_USAGE}
|
|
264578
|
+
`);
|
|
264579
|
+
return 2;
|
|
264580
|
+
}
|
|
264581
|
+
const file2 = resolve(cwd, parsed.positional[0]);
|
|
264582
|
+
let bytes;
|
|
264583
|
+
try {
|
|
264584
|
+
if (!statSync2(file2, { throwIfNoEntry: false })?.isFile()) {
|
|
264585
|
+
stderr.write(`Not a regular file: ${file2}
|
|
264586
|
+
`);
|
|
264587
|
+
return 2;
|
|
264588
|
+
}
|
|
264589
|
+
bytes = readFileSync(file2);
|
|
264590
|
+
} catch (error) {
|
|
264591
|
+
if (!error.code) throw error;
|
|
264592
|
+
stderr.write(`Could not read ${file2}: ${error.message}
|
|
264593
|
+
`);
|
|
264594
|
+
return 2;
|
|
264595
|
+
}
|
|
264596
|
+
const manifest = join2(cwd, "assets.ts");
|
|
264597
|
+
let source = null;
|
|
264598
|
+
let current;
|
|
264599
|
+
if (!noWrite && !statSync2(join2(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
|
|
264600
|
+
stderr.write(
|
|
264601
|
+
"Run diagonal assets upload in the workspace root, the folder with diagonal.config.ts, or pass --no-write.\n"
|
|
264602
|
+
);
|
|
264603
|
+
return 2;
|
|
264604
|
+
}
|
|
264605
|
+
try {
|
|
264606
|
+
source = readManifest(manifest);
|
|
264607
|
+
const entries = readAssetEntries(source);
|
|
264608
|
+
current = entries.find((entry) => entry.key === key);
|
|
264609
|
+
if (!noWrite) writeAssetEntry(source, key, NIL_REFERENCE);
|
|
264610
|
+
} catch (error) {
|
|
264611
|
+
printFileError(error, stderr);
|
|
264612
|
+
return 1;
|
|
264613
|
+
}
|
|
264614
|
+
const target = credentials(env2, stderr);
|
|
264615
|
+
if (target === null) return 2;
|
|
264616
|
+
if (await request(target, "GET", "/api/application-assets?per_page=1", void 0, stderr) === null)
|
|
264617
|
+
return 1;
|
|
264618
|
+
let assetId;
|
|
264619
|
+
if (current) {
|
|
264620
|
+
const lookup = await request(
|
|
264621
|
+
target,
|
|
264622
|
+
"GET",
|
|
264623
|
+
`/api/application-asset-versions/${current.reference}`,
|
|
264624
|
+
void 0,
|
|
264625
|
+
stderr,
|
|
264626
|
+
{ responseDetails: true }
|
|
264627
|
+
);
|
|
264628
|
+
if (lookup === null) return 1;
|
|
264629
|
+
if (!lookup.ok) {
|
|
264630
|
+
if (lookup.status === 404 && lookup.body.message === MISSING_VERSION) {
|
|
264631
|
+
stderr.write(
|
|
264632
|
+
`${formatDiagnostic(diagnostic("assets.ts", current.line, current.column, assetLibraryMessage(current.reference)))}
|
|
264633
|
+
`
|
|
264634
|
+
);
|
|
264635
|
+
} else {
|
|
264636
|
+
stderr.write(errorText(lookup.status, lookup.body));
|
|
264637
|
+
}
|
|
264638
|
+
return 1;
|
|
264639
|
+
}
|
|
264640
|
+
assetId = lookup.body.asset.id;
|
|
264641
|
+
}
|
|
264642
|
+
const form = new FormData();
|
|
264643
|
+
form.append("file", new Blob([bytes]), basename2(file2));
|
|
264644
|
+
const uploaded = await request(target, "POST", "/api/files/uploads", form, stderr);
|
|
264645
|
+
if (uploaded === null) return 1;
|
|
264646
|
+
const result = await request(
|
|
264647
|
+
target,
|
|
264648
|
+
"POST",
|
|
264649
|
+
assetId ? `/api/application-assets/${assetId}/versions` : "/api/application-assets",
|
|
264650
|
+
{ upload_key: uploaded.key },
|
|
264651
|
+
stderr,
|
|
264652
|
+
{ responseDetails: true }
|
|
264653
|
+
);
|
|
264654
|
+
if (result === null) return 1;
|
|
264655
|
+
if (!result.ok) {
|
|
264656
|
+
stderr.write(errorText(result.status, result.body));
|
|
264657
|
+
return 1;
|
|
264658
|
+
}
|
|
264659
|
+
const { asset: asset2, version } = result.body;
|
|
264660
|
+
let written = false;
|
|
264661
|
+
let action;
|
|
264662
|
+
if (!noWrite) {
|
|
264663
|
+
try {
|
|
264664
|
+
const latest = readManifest(manifest);
|
|
264665
|
+
const existing = readAssetEntries(latest).find((entry) => entry.key === key);
|
|
264666
|
+
const output = writeAssetEntry(latest, key, version.reference);
|
|
264667
|
+
if (output !== latest) writeFileSync(manifest, output);
|
|
264668
|
+
written = true;
|
|
264669
|
+
action = existing?.reference === version.reference ? `${key} already uses this version` : existing ? `Updated ${key} in assets.ts` : `Added ${key} to assets.ts`;
|
|
264670
|
+
} catch (error) {
|
|
264671
|
+
printFileError(error, stderr);
|
|
264672
|
+
stderr.write(
|
|
264673
|
+
`${key}: asset.version('${version.reference}')
|
|
264674
|
+
Do not run the upload again: a new key creates another asset.
|
|
264675
|
+
`
|
|
264676
|
+
);
|
|
264677
|
+
return 1;
|
|
264678
|
+
}
|
|
264679
|
+
}
|
|
264680
|
+
if (parsed.booleans.has("--json")) {
|
|
264681
|
+
stdout.write(`${JSON.stringify({ key: key ?? null, written, asset: asset2, version }, null, 2)}
|
|
264682
|
+
`);
|
|
264683
|
+
} else if (noWrite) {
|
|
264684
|
+
stdout.write(`${version.reference}
|
|
264685
|
+
`);
|
|
264686
|
+
} else {
|
|
264687
|
+
if (result.status === 200)
|
|
264688
|
+
stdout.write(`The bytes match version ${version.number}; no new version was created.
|
|
264689
|
+
`);
|
|
264690
|
+
stdout.write(
|
|
264691
|
+
`${key} ${version.reference} ${asset2.display_name} v${version.number}
|
|
264692
|
+
${action}
|
|
264693
|
+
`
|
|
264694
|
+
);
|
|
264695
|
+
}
|
|
264696
|
+
return 0;
|
|
264697
|
+
}
|
|
264698
|
+
async function listAssets(args, { env: env2, stdout, stderr }) {
|
|
264699
|
+
const parsed = parseFlags(args, ["--search"], ["--versions", "--json"]);
|
|
264700
|
+
if (parsed.error !== void 0 || parsed.positional.length > 0) {
|
|
264701
|
+
stderr.write(
|
|
264702
|
+
`${parsed.error ?? "diagonal assets list takes no arguments"}
|
|
264703
|
+
${ASSETS_LIST_USAGE}
|
|
264704
|
+
`
|
|
264705
|
+
);
|
|
264706
|
+
return 2;
|
|
264707
|
+
}
|
|
264708
|
+
const target = credentials(env2, stderr);
|
|
264709
|
+
if (target === null) return 2;
|
|
264710
|
+
const assets = [];
|
|
264711
|
+
let page = 1;
|
|
264712
|
+
while (true) {
|
|
264713
|
+
const query = new URLSearchParams({ per_page: "100", page: String(page) });
|
|
264714
|
+
if (parsed.values["--search"] !== void 0) query.set("search", parsed.values["--search"]);
|
|
264715
|
+
const body = await request(
|
|
264716
|
+
target,
|
|
264717
|
+
"GET",
|
|
264718
|
+
`/api/application-assets?${query}`,
|
|
264719
|
+
void 0,
|
|
264720
|
+
stderr
|
|
264721
|
+
);
|
|
264722
|
+
if (body === null) return 1;
|
|
264723
|
+
assets.push(...body.data);
|
|
264724
|
+
if (body.pagination.current_page >= body.pagination.last_page) break;
|
|
264725
|
+
page++;
|
|
264726
|
+
}
|
|
264727
|
+
if (parsed.booleans.has("--versions")) {
|
|
264728
|
+
for (const asset2 of assets) {
|
|
264729
|
+
const body = await request(
|
|
264730
|
+
target,
|
|
264731
|
+
"GET",
|
|
264732
|
+
`/api/application-assets/${asset2.id}`,
|
|
264733
|
+
void 0,
|
|
264734
|
+
stderr
|
|
264735
|
+
);
|
|
264736
|
+
if (body === null) return 1;
|
|
264737
|
+
asset2.versions = body.versions;
|
|
264738
|
+
}
|
|
264739
|
+
}
|
|
264740
|
+
if (parsed.booleans.has("--json")) {
|
|
264741
|
+
stdout.write(`${JSON.stringify({ data: assets }, null, 2)}
|
|
264742
|
+
`);
|
|
264743
|
+
return 0;
|
|
264744
|
+
}
|
|
264745
|
+
const rows = assets.map((asset2) => [
|
|
264746
|
+
asset2.latest_version?.reference ?? "-",
|
|
264747
|
+
asset2.latest_version ? `v${asset2.latest_version.number} of ${asset2.versions_count}` : `- of ${asset2.versions_count}`,
|
|
264748
|
+
asset2.latest_version?.mime_type ?? "-",
|
|
264749
|
+
asset2.display_name
|
|
264750
|
+
]);
|
|
264751
|
+
const widths = [0, 1, 2].map((column) => Math.max(0, ...rows.map((row) => row[column].length)));
|
|
264752
|
+
for (const [index3, row] of rows.entries()) {
|
|
264753
|
+
stdout.write(
|
|
264754
|
+
`${row.map((value, column) => column < 3 ? value.padEnd(widths[column]) : value).join(" ")}
|
|
264755
|
+
`
|
|
264756
|
+
);
|
|
264757
|
+
const asset2 = assets[index3];
|
|
264758
|
+
for (const version of asset2.versions ?? []) {
|
|
264759
|
+
stdout.write(
|
|
264760
|
+
` v${version.number} ${version.reference} ${version.original_filename} ${version.bytes} bytes
|
|
264761
|
+
`
|
|
264762
|
+
);
|
|
264763
|
+
}
|
|
264764
|
+
if (asset2.versions && asset2.versions.length < asset2.versions_count) {
|
|
264765
|
+
stdout.write(` showing the newest ${asset2.versions.length} of ${asset2.versions_count}
|
|
264766
|
+
`);
|
|
264767
|
+
}
|
|
264768
|
+
}
|
|
264769
|
+
stdout.write(`${assets.length} asset${assets.length === 1 ? "" : "s"}
|
|
264770
|
+
`);
|
|
264771
|
+
return 0;
|
|
264772
|
+
}
|
|
264773
|
+
|
|
264774
|
+
// scripts/lib/runtime-build/build-workspace.mjs
|
|
264775
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
264776
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync8, readdirSync as readdirSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
264777
|
+
import { basename as basename4, dirname as dirname6, extname as extname2, join as join11, relative as relative4, sep } from "node:path";
|
|
264778
|
+
|
|
264410
264779
|
// scripts/lib/runtime-build/capabilities.mjs
|
|
264411
264780
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
264412
264781
|
|
|
@@ -267585,8 +267954,8 @@ function checkCapabilities(resources, platformSlugs, diagnostics) {
|
|
|
267585
267954
|
// scripts/lib/runtime-build/definition-uid.mjs
|
|
267586
267955
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
267587
267956
|
import { randomUUID } from "node:crypto";
|
|
267588
|
-
import { writeFileSync } from "node:fs";
|
|
267589
|
-
import { join as
|
|
267957
|
+
import { writeFileSync as writeFileSync2 } from "node:fs";
|
|
267958
|
+
import { join as join3 } from "node:path";
|
|
267590
267959
|
var UID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
267591
267960
|
var UID_EXAMPLE = "3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c";
|
|
267592
267961
|
function isUid(value) {
|
|
@@ -267696,15 +268065,15 @@ function checkDefinitionUids(root, definitions, { write }) {
|
|
|
267696
268065
|
uids.push(generated);
|
|
267697
268066
|
}
|
|
267698
268067
|
for (const [path, insertions] of insertionsByPath) {
|
|
267699
|
-
|
|
268068
|
+
writeFileSync2(join3(root, path), withInsertions(sourceByPath.get(path), insertions));
|
|
267700
268069
|
}
|
|
267701
268070
|
return { uids, diagnostics };
|
|
267702
268071
|
}
|
|
267703
268072
|
|
|
267704
268073
|
// scripts/lib/runtime-build/module-graph.mjs
|
|
267705
268074
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
267706
|
-
import { readFileSync } from "node:fs";
|
|
267707
|
-
import { posix as posix2, join as
|
|
268075
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
268076
|
+
import { posix as posix2, join as join4 } from "node:path";
|
|
267708
268077
|
|
|
267709
268078
|
// scripts/lib/runtime-build/page-build-protocol.mjs
|
|
267710
268079
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
@@ -267717,7 +268086,7 @@ function sha256(value) {
|
|
|
267717
268086
|
|
|
267718
268087
|
// scripts/lib/runtime-build/resource-references.mjs
|
|
267719
268088
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
267720
|
-
import { basename as
|
|
268089
|
+
import { basename as basename3, extname } from "node:path";
|
|
267721
268090
|
|
|
267722
268091
|
// node_modules/@babel/traverse/lib/index.js
|
|
267723
268092
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
@@ -280592,7 +280961,7 @@ function normalizePath(url, type) {
|
|
|
280592
280961
|
}
|
|
280593
280962
|
url.path = path;
|
|
280594
280963
|
}
|
|
280595
|
-
function
|
|
280964
|
+
function resolve2(input, base2) {
|
|
280596
280965
|
if (!input && !base2)
|
|
280597
280966
|
return "";
|
|
280598
280967
|
const url = parseUrl(input);
|
|
@@ -280655,7 +281024,7 @@ function stripFilename(path) {
|
|
|
280655
281024
|
function resolver(mapUrl, sourceRoot) {
|
|
280656
281025
|
const from = stripFilename(mapUrl);
|
|
280657
281026
|
const prefix2 = sourceRoot ? sourceRoot + "/" : "";
|
|
280658
|
-
return (source) =>
|
|
281027
|
+
return (source) => resolve2(prefix2 + (source || ""), from);
|
|
280659
281028
|
}
|
|
280660
281029
|
var COLUMN = 0;
|
|
280661
281030
|
var SOURCES_INDEX = 1;
|
|
@@ -280768,8 +281137,8 @@ var TraceMap = class {
|
|
|
280768
281137
|
this.sources = sources;
|
|
280769
281138
|
this.sourcesContent = sourcesContent;
|
|
280770
281139
|
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
280771
|
-
const
|
|
280772
|
-
this.resolvedSources = sources.map(
|
|
281140
|
+
const resolve6 = resolver(mapUrl, sourceRoot);
|
|
281141
|
+
this.resolvedSources = sources.map(resolve6);
|
|
280773
281142
|
const { mappings } = parsed;
|
|
280774
281143
|
if (typeof mappings === "string") {
|
|
280775
281144
|
this._encoded = mappings;
|
|
@@ -291043,7 +291412,7 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base2, target,
|
|
|
291043
291412
|
nodeMap.set(target.node, result);
|
|
291044
291413
|
return result;
|
|
291045
291414
|
}
|
|
291046
|
-
function
|
|
291415
|
+
function resolve3(dangerous, resolved) {
|
|
291047
291416
|
if (resolved?.includes(this)) return this;
|
|
291048
291417
|
resolved = resolved || [];
|
|
291049
291418
|
resolved.push(this);
|
|
@@ -291691,7 +292060,7 @@ var methods = {
|
|
|
291691
292060
|
getSource,
|
|
291692
292061
|
willIMaybeExecuteBefore,
|
|
291693
292062
|
_guessExecutionStatusRelativeTo,
|
|
291694
|
-
resolve:
|
|
292063
|
+
resolve: resolve3,
|
|
291695
292064
|
isConstantExpression,
|
|
291696
292065
|
isInStrictMode,
|
|
291697
292066
|
isDenylisted,
|
|
@@ -291977,7 +292346,7 @@ function resourceNames(paths, diagnostics) {
|
|
|
291977
292346
|
const slugsByName = /* @__PURE__ */ new Map();
|
|
291978
292347
|
const namesBySlug = /* @__PURE__ */ new Map();
|
|
291979
292348
|
for (const path of paths) {
|
|
291980
|
-
const slug =
|
|
292349
|
+
const slug = basename3(path, extname(path));
|
|
291981
292350
|
if (!SLUG_PATTERN.test(slug)) {
|
|
291982
292351
|
diagnostics.push(
|
|
291983
292352
|
diagnosticAt(
|
|
@@ -292432,12 +292801,12 @@ function buildModuleGraph(root, entries, manifest, diagnostics, assetKeys = /* @
|
|
|
292432
292801
|
const kind = importKind(`./${posix2.basename(path)}`);
|
|
292433
292802
|
if (STYLE_KINDS.has(kind)) {
|
|
292434
292803
|
checkStylesheet(root, path, assetKeys, diagnostics, scannedStyles);
|
|
292435
|
-
modules[path] = { kind, source_sha256: sha256(
|
|
292804
|
+
modules[path] = { kind, source_sha256: sha256(readFileSync2(join4(root, path))), imports: [] };
|
|
292436
292805
|
continue;
|
|
292437
292806
|
}
|
|
292438
292807
|
let entry = parsed.get(path);
|
|
292439
292808
|
if (entry === void 0) {
|
|
292440
|
-
const source =
|
|
292809
|
+
const source = readFileSync2(join4(root, path), "utf8");
|
|
292441
292810
|
try {
|
|
292442
292811
|
entry = { path, source, ast: parseSource(source, { jsx: path.endsWith("x") }) };
|
|
292443
292812
|
} catch (error) {
|
|
@@ -292621,7 +292990,7 @@ function checkStylesheet(root, path, assetKeys, diagnostics, scanned) {
|
|
|
292621
292990
|
return;
|
|
292622
292991
|
}
|
|
292623
292992
|
scanned.add(path);
|
|
292624
|
-
const { urls, imports } = cssReferences(
|
|
292993
|
+
const { urls, imports } = cssReferences(readFileSync2(join4(root, path), "utf8"));
|
|
292625
292994
|
for (const url of urls) {
|
|
292626
292995
|
const key = assetUrlKey(url.value);
|
|
292627
292996
|
if (key !== null && assetKeys !== null && !assetKeys.has(key)) {
|
|
@@ -293848,8 +294217,8 @@ and limitations under the License.
|
|
|
293848
294217
|
|
|
293849
294218
|
// scripts/pageTypeCheck.mjs
|
|
293850
294219
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
293851
|
-
import { existsSync as existsSync2, readFileSync as
|
|
293852
|
-
import { dirname as dirname2, join as
|
|
294220
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
294221
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
293853
294222
|
|
|
293854
294223
|
// app/pages/resources/js/pageRuntime/sdk/buildCustomComponentTypes.ts
|
|
293855
294224
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
@@ -294901,8 +295270,8 @@ function typeCheckPage(userSource, {
|
|
|
294901
295270
|
if (libFiles3) {
|
|
294902
295271
|
return libFiles3.get(name);
|
|
294903
295272
|
}
|
|
294904
|
-
const path =
|
|
294905
|
-
return existsSync2(path) ?
|
|
295273
|
+
const path = join5(libDir, name);
|
|
295274
|
+
return existsSync2(path) ? readFileSync3(path, "utf8") : void 0;
|
|
294906
295275
|
};
|
|
294907
295276
|
const getText = (name) => virtual.get(name) ?? readLib(name);
|
|
294908
295277
|
const host = {
|
|
@@ -298912,18 +299281,18 @@ function withoutBuildNodes(resource) {
|
|
|
298912
299281
|
|
|
298913
299282
|
// scripts/lib/runtime-build/sdk-packages.mjs
|
|
298914
299283
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
298915
|
-
import { existsSync as existsSync3, readFileSync as
|
|
298916
|
-
import { join as
|
|
299284
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
299285
|
+
import { join as join6 } from "node:path";
|
|
298917
299286
|
var DIAGONAL_PACKAGE = /^@diagonal(-hq)?\//;
|
|
298918
299287
|
var TARBALL_VERSION = /-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\.tgz$/;
|
|
298919
299288
|
var EXACT_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
298920
299289
|
function readPackageFiles(root, diagnostics) {
|
|
298921
299290
|
const read = (path) => {
|
|
298922
|
-
if (!existsSync3(
|
|
299291
|
+
if (!existsSync3(join6(root, path))) {
|
|
298923
299292
|
return null;
|
|
298924
299293
|
}
|
|
298925
299294
|
try {
|
|
298926
|
-
return JSON.parse(
|
|
299295
|
+
return JSON.parse(readFileSync4(join6(root, path), "utf8"));
|
|
298927
299296
|
} catch (error) {
|
|
298928
299297
|
if (!(error instanceof SyntaxError)) {
|
|
298929
299298
|
throw error;
|
|
@@ -299115,8 +299484,8 @@ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
|
299115
299484
|
// scripts/lib/runtime-build/app-modules.mjs
|
|
299116
299485
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
299117
299486
|
var import_sucrase2 = __toESM(require_dist2(), 1);
|
|
299118
|
-
import { readFileSync as
|
|
299119
|
-
import { join as
|
|
299487
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
299488
|
+
import { join as join7 } from "node:path";
|
|
299120
299489
|
|
|
299121
299490
|
// packages/cli/index.js
|
|
299122
299491
|
var cli_exports = {};
|
|
@@ -299268,7 +299637,7 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
|
|
|
299268
299637
|
if (modules.has(path)) {
|
|
299269
299638
|
continue;
|
|
299270
299639
|
}
|
|
299271
|
-
const read =
|
|
299640
|
+
const read = readFileSync5(join7(root, path), "utf8");
|
|
299272
299641
|
const source = transform3 === null ? read : transform3(path, read);
|
|
299273
299642
|
const ast = parseModule(path, source);
|
|
299274
299643
|
const requires = {};
|
|
@@ -299919,34 +300288,34 @@ function pageKeyOf(path, ast) {
|
|
|
299919
300288
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
299920
300289
|
var import_typescript2 = __toESM(require_typescript(), 1);
|
|
299921
300290
|
import { spawnSync } from "node:child_process";
|
|
299922
|
-
import { mkdirSync, mkdtempSync, realpathSync as realpathSync2, rmSync, writeFileSync as
|
|
300291
|
+
import { mkdirSync, mkdtempSync, realpathSync as realpathSync2, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
299923
300292
|
import { tmpdir } from "node:os";
|
|
299924
|
-
import { dirname as dirname4, join as
|
|
300293
|
+
import { dirname as dirname4, join as join9, relative as relative3 } from "node:path";
|
|
299925
300294
|
|
|
299926
300295
|
// scripts/lib/runtime-build/script-sdk.mjs
|
|
299927
300296
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
299928
|
-
import { readFileSync as
|
|
300297
|
+
import { readFileSync as readFileSync6, readdirSync as readdirSync2, statSync as statSync3 } from "node:fs";
|
|
299929
300298
|
import { createRequire } from "node:module";
|
|
299930
|
-
import { dirname as dirname3, join as
|
|
300299
|
+
import { dirname as dirname3, join as join8, relative as relative2, resolve as resolve4 } from "node:path";
|
|
299931
300300
|
import { fileURLToPath } from "node:url";
|
|
299932
|
-
var SCRIPT_SDK_ROOT =
|
|
300301
|
+
var SCRIPT_SDK_ROOT = resolve4(
|
|
299933
300302
|
dirname3(fileURLToPath(import.meta.url)),
|
|
299934
300303
|
"../../../packages/workflows/src"
|
|
299935
300304
|
);
|
|
299936
300305
|
var SDK_RUNTIME_ENTRY_POINTS = {
|
|
299937
|
-
workflow:
|
|
299938
|
-
testing:
|
|
300306
|
+
workflow: join8(SCRIPT_SDK_ROOT, "index.ts"),
|
|
300307
|
+
testing: join8(SCRIPT_SDK_ROOT, "testing/index.ts")
|
|
299939
300308
|
};
|
|
299940
300309
|
function walk(directory) {
|
|
299941
300310
|
return readdirSync2(directory).flatMap(
|
|
299942
|
-
(name) =>
|
|
300311
|
+
(name) => statSync3(join8(directory, name)).isDirectory() ? walk(join8(directory, name)) : [join8(directory, name)]
|
|
299943
300312
|
);
|
|
299944
300313
|
}
|
|
299945
300314
|
function readSandboxSdkFiles() {
|
|
299946
300315
|
return Object.fromEntries(
|
|
299947
300316
|
walk(SCRIPT_SDK_ROOT).filter(
|
|
299948
300317
|
(file2) => file2.endsWith(".ts") && !file2.includes("/testing/") && !file2.endsWith("/http-transport.ts") && !file2.endsWith("/workspace.generated.ts")
|
|
299949
|
-
).map((file2) => [`/sdk/${relative2(SCRIPT_SDK_ROOT, file2)}`,
|
|
300318
|
+
).map((file2) => [`/sdk/${relative2(SCRIPT_SDK_ROOT, file2)}`, readFileSync6(file2, "utf8")])
|
|
299950
300319
|
);
|
|
299951
300320
|
}
|
|
299952
300321
|
function bundleSdkRuntime(buildSync) {
|
|
@@ -300094,8 +300463,8 @@ function relativeSandboxPath(from, target) {
|
|
|
300094
300463
|
return path.startsWith(".") ? path : `./${path}`;
|
|
300095
300464
|
}
|
|
300096
300465
|
function writeFile(root, path, content) {
|
|
300097
|
-
mkdirSync(dirname4(
|
|
300098
|
-
|
|
300466
|
+
mkdirSync(dirname4(join9(root, path)), { recursive: true });
|
|
300467
|
+
writeFileSync3(join9(root, path), content);
|
|
300099
300468
|
}
|
|
300100
300469
|
function parseResults(stdout) {
|
|
300101
300470
|
return stdout.split("\n").filter((line) => line.startsWith(RESULT_PREFIX)).map((line) => JSON.parse(line.slice(RESULT_PREFIX.length)));
|
|
@@ -300143,7 +300512,7 @@ function runWorkflowTests({
|
|
|
300143
300512
|
modules.set(path, module);
|
|
300144
300513
|
}
|
|
300145
300514
|
}
|
|
300146
|
-
const root = realpathSync2(mkdtempSync(
|
|
300515
|
+
const root = realpathSync2(mkdtempSync(join9(tmpdir(), "diagonal-workflow-tests-")));
|
|
300147
300516
|
try {
|
|
300148
300517
|
writeFile(root, "package.json", '{"type":"module"}\n');
|
|
300149
300518
|
writeFile(root, "reporter.mjs", REPORTER_SOURCE);
|
|
@@ -300215,7 +300584,7 @@ function runWorkflowTests({
|
|
|
300215
300584
|
const results = parseResults(run.stdout ?? "");
|
|
300216
300585
|
const timedOut = run.error?.code === "ETIMEDOUT" || run.signal !== null;
|
|
300217
300586
|
const workflowTests = runnable.map((test) => {
|
|
300218
|
-
const file2 =
|
|
300587
|
+
const file2 = join9(root, test.path.replace(/\.ts$/, ".js"));
|
|
300219
300588
|
const own = results.filter((result) => result.file === file2);
|
|
300220
300589
|
for (const result of own) {
|
|
300221
300590
|
if (!result.ok) {
|
|
@@ -300563,9 +300932,9 @@ function literal(node) {
|
|
|
300563
300932
|
|
|
300564
300933
|
// scripts/lib/workflow-script/lib-files.mjs
|
|
300565
300934
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
300566
|
-
import { readFileSync as
|
|
300935
|
+
import { readFileSync as readFileSync7 } from "node:fs";
|
|
300567
300936
|
import { createRequire as createRequire2 } from "node:module";
|
|
300568
|
-
import { dirname as dirname5, join as
|
|
300937
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
300569
300938
|
var ROOT_LIB = "lib.es2023.d.ts";
|
|
300570
300939
|
function libClosure(read, root = ROOT_LIB) {
|
|
300571
300940
|
const files = {};
|
|
@@ -300584,7 +300953,7 @@ function libClosure(read, root = ROOT_LIB) {
|
|
|
300584
300953
|
}
|
|
300585
300954
|
function readLibClosure(root = ROOT_LIB) {
|
|
300586
300955
|
const libDir = dirname5(createRequire2(import.meta.url).resolve("typescript/lib/lib.d.ts"));
|
|
300587
|
-
return libClosure((name) =>
|
|
300956
|
+
return libClosure((name) => readFileSync7(join10(libDir, name), "utf8"), root);
|
|
300588
300957
|
}
|
|
300589
300958
|
|
|
300590
300959
|
// scripts/lib/workflow-script/lint-rules.mjs
|
|
@@ -301847,10 +302216,10 @@ function listFiles(root) {
|
|
|
301847
302216
|
}
|
|
301848
302217
|
if (entry.isDirectory()) {
|
|
301849
302218
|
if (!IGNORED_DIRECTORIES.has(entry.name)) {
|
|
301850
|
-
pending.push(
|
|
302219
|
+
pending.push(join11(directory, entry.name));
|
|
301851
302220
|
}
|
|
301852
302221
|
} else if (entry.isFile()) {
|
|
301853
|
-
files.push(relative4(root,
|
|
302222
|
+
files.push(relative4(root, join11(directory, entry.name)).split(sep).join("/"));
|
|
301854
302223
|
}
|
|
301855
302224
|
}
|
|
301856
302225
|
}
|
|
@@ -301864,7 +302233,7 @@ function isDirectChild(path, directory) {
|
|
|
301864
302233
|
return path.startsWith(`${directory}/`) && !path.slice(directory.length + 1).includes("/");
|
|
301865
302234
|
}
|
|
301866
302235
|
function stem(path) {
|
|
301867
|
-
return
|
|
302236
|
+
return basename4(path, extname2(path));
|
|
301868
302237
|
}
|
|
301869
302238
|
function buildConfig(source, ast) {
|
|
301870
302239
|
const { declaration } = defaultExportOf(ast);
|
|
@@ -302047,16 +302416,16 @@ function checkPageResources(pages, resources, platformSlugs, names2, diagnostics
|
|
|
302047
302416
|
}
|
|
302048
302417
|
}
|
|
302049
302418
|
function writeGeneratedResources(root, names2, resources) {
|
|
302050
|
-
const path =
|
|
302419
|
+
const path = join11(root, GENERATED_RESOURCES_PATH);
|
|
302051
302420
|
if (names2.slugsByName.size === 0 && !existsSync4(path)) {
|
|
302052
302421
|
return;
|
|
302053
302422
|
}
|
|
302054
302423
|
const source = generatedResourcesSource(names2, resources);
|
|
302055
|
-
if (existsSync4(path) &&
|
|
302424
|
+
if (existsSync4(path) && readFileSync8(path, "utf8") === source) {
|
|
302056
302425
|
return;
|
|
302057
302426
|
}
|
|
302058
302427
|
mkdirSync2(dirname6(path), { recursive: true });
|
|
302059
|
-
|
|
302428
|
+
writeFileSync4(path, source);
|
|
302060
302429
|
}
|
|
302061
302430
|
function lintUnits(units, resources, components, pages, diagnostics) {
|
|
302062
302431
|
const catalogs = {
|
|
@@ -302121,7 +302490,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
302121
302490
|
);
|
|
302122
302491
|
return;
|
|
302123
302492
|
}
|
|
302124
|
-
const source =
|
|
302493
|
+
const source = readFileSync8(join11(root, path), "utf8");
|
|
302125
302494
|
if (kind === "skill") {
|
|
302126
302495
|
skillFiles.push({ path, content: source });
|
|
302127
302496
|
return;
|
|
@@ -302325,17 +302694,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
|
|
|
302325
302694
|
|
|
302326
302695
|
// scripts/lib/runtime-build/check-cli.mjs
|
|
302327
302696
|
var CHECK_USAGE = "Usage: diagonal check [dir] [--json]";
|
|
302328
|
-
var USAGE = [
|
|
302329
|
-
|
|
302330
|
-
|
|
302331
|
-
|
|
302332
|
-
|
|
302333
|
-
|
|
302334
|
-
|
|
302335
|
-
lines.push(` ${detail}`);
|
|
302336
|
-
}
|
|
302337
|
-
return lines.join("\n");
|
|
302338
|
-
}
|
|
302697
|
+
var USAGE = [
|
|
302698
|
+
CHECK_USAGE,
|
|
302699
|
+
WORKFLOWS_USAGE,
|
|
302700
|
+
RUN_USAGE,
|
|
302701
|
+
ASSETS_UPLOAD_USAGE,
|
|
302702
|
+
ASSETS_LIST_USAGE
|
|
302703
|
+
].join("\n");
|
|
302339
302704
|
function plural(count, word) {
|
|
302340
302705
|
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
302341
302706
|
}
|
|
@@ -302364,8 +302729,8 @@ ${CHECK_USAGE}
|
|
|
302364
302729
|
`);
|
|
302365
302730
|
return 2;
|
|
302366
302731
|
}
|
|
302367
|
-
const root =
|
|
302368
|
-
if (!
|
|
302732
|
+
const root = resolve5(cwd, parsed.dir);
|
|
302733
|
+
if (!statSync4(root, { throwIfNoEntry: false })?.isDirectory()) {
|
|
302369
302734
|
stderr.write(`Not a directory: ${root}
|
|
302370
302735
|
`);
|
|
302371
302736
|
return 2;
|
|
@@ -302394,6 +302759,15 @@ async function main(argv, io) {
|
|
|
302394
302759
|
switch (command) {
|
|
302395
302760
|
case "check":
|
|
302396
302761
|
return check(args, io);
|
|
302762
|
+
case "assets": {
|
|
302763
|
+
const [subcommand, ...assetArgs] = args;
|
|
302764
|
+
if (subcommand === "upload") return uploadAsset(assetArgs, io);
|
|
302765
|
+
if (subcommand === "list") return listAssets(assetArgs, io);
|
|
302766
|
+
io.stderr.write(`${ASSETS_UPLOAD_USAGE}
|
|
302767
|
+
${ASSETS_LIST_USAGE}
|
|
302768
|
+
`);
|
|
302769
|
+
return 2;
|
|
302770
|
+
}
|
|
302397
302771
|
case "workflows":
|
|
302398
302772
|
return listWorkflows(args, io);
|
|
302399
302773
|
case "run":
|