@diagonal-hq/cli 0.10.2 → 0.11.0

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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/dist/cli.mjs +101 -64
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -425,6 +425,12 @@ Use `background: url(asset:hero)` in a CSS file. The hosted build replaces it wi
425
425
 
426
426
  The check follows CSS imports from pages, layouts, and components. An unknown `asset:` key fails with its file, line, and column. `asset:` in `@import` fails. A `url(asset:` value in a TypeScript or TSX module also fails. Move that value to a CSS file.
427
427
 
428
+ The check refuses binary imports from workspace modules, including images, fonts, SVG, video, audio, and PDF files. Binary files in `pages/`, `layouts/`, and `components/` also fail when no module imports them. Upload an image as an Application Asset and use `url(asset:<key>)` in CSS. For icons, use `Sdk.Icon` or an SVG written as a TSX component. SVG and font uploads are not supported yet; use an https: URL for those files.
429
+
430
+ A CSS `url()` can name an Application Asset as `url(asset:<key>)`, a data URL, an HTTP or HTTPS URL, or a fragment. Relative, root-relative, and protocol-relative file URLs fail. CSS `@import` and `composes` cannot name binary files or Application Assets. Import a CSS file instead.
431
+
432
+ npm packages cannot bring media files either. A package stylesheet or module that imports an image, font, video, audio, or PDF file fails the hosted build. `diagonal check` does not read package files. Use an https: URL or an Application Asset in your own CSS.
433
+
428
434
  ## Editor types
429
435
 
430
436
  A page, layout, component, or workflow can import any other file of the workspace by its path from the root with `@app/`, for example `import { formatPrice } from '@app/lib/money'`. The extension is optional, and a folder's `index` file is found. The build links each imported file into the importing page or workflow, so the files need no folder of their own; a file outside the build's folders, such as `lib/`, is built only when something imports it. An imported module can import other `@app/` files, `@diagonal-hq/cli`, and, in a workflow, `@diagonal/workflow`. Add `"@app/*": ["./*"]` to the `paths` of `tsconfig.json` so the editor resolves them too.
package/dist/cli.mjs CHANGED
@@ -263867,7 +263867,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
263867
263867
  ]);
263868
263868
  var BINARY_FILE_MESSAGE = "Binary files cannot be in the repository. Add it as an Application Asset and use Assets.<key>. For an icon, use Sdk.Icon or an SVG written as a TSX component";
263869
263869
  function binaryCssUrlMessage(value) {
263870
- return `url("${value}") names a file in the repository. Binary files cannot be in the repository. Add it as an Application Asset and use url(asset:<key>)`;
263870
+ return `url("${value}") is not supported. A CSS url() can name an Application Asset as url(asset:<key>), a data: URL, an http: or https: URL, or a #fragment`;
263871
263871
  }
263872
263872
  function binaryCssImportMessage(value) {
263873
263873
  const request2 = value.split(/[?#]/)[0];
@@ -264517,7 +264517,7 @@ function buildAssets(ast, catalog) {
264517
264517
  const [definition] = expectDefineCall(declaration, "defineAssets", 1);
264518
264518
  const { value, nodes } = staticObject(definition, { assetVersions: true });
264519
264519
  if (Object.keys(value).length > MAX_ASSET_VERSIONS) {
264520
- throw new SourceError("assets.ts can name at most 500 asset versions.", declaration);
264520
+ throw new SourceError("assets.ts can have at most 500 entries.", declaration);
264521
264521
  }
264522
264522
  return Object.entries(value).map(([key, version]) => {
264523
264523
  if (!isAssetKey(key)) {
@@ -292916,6 +292916,70 @@ function requestedNames(statement2) {
292916
292916
  return [];
292917
292917
  });
292918
292918
  }
292919
+ function checkModuleImports(root, path, ast, packages) {
292920
+ const diagnostics = [];
292921
+ const imports = [];
292922
+ let blocksUnitBuild = false;
292923
+ for (const found2 of moduleSpecifiers2(ast)) {
292924
+ if (found2.specifier === null) {
292925
+ diagnostics.push(diagnosticAt(path, found2.node, "A dynamic import must name its module with a string literal"));
292926
+ continue;
292927
+ }
292928
+ if (found2.typeOnly) {
292929
+ continue;
292930
+ }
292931
+ const importType = importKind(found2.specifier);
292932
+ const refused = unsupportedImportMessage(found2.specifier, importType);
292933
+ if (refused !== null) {
292934
+ diagnostics.push(diagnosticAt(path, found2.node, refused));
292935
+ blocksUnitBuild = true;
292936
+ continue;
292937
+ }
292938
+ if (importType === "host") {
292939
+ imports.push({ specifier: found2.specifier, kind: "host", target: found2.specifier, dynamic: found2.dynamic });
292940
+ continue;
292941
+ }
292942
+ if (importType === "package") {
292943
+ if (!packages.has(packageName(found2.specifier))) {
292944
+ diagnostics.push(
292945
+ diagnosticAt(
292946
+ path,
292947
+ found2.node,
292948
+ `"${packageName(found2.specifier)}" is not a dependency. Add it to "dependencies" in package.json`
292949
+ )
292950
+ );
292951
+ continue;
292952
+ }
292953
+ imports.push({
292954
+ specifier: found2.specifier,
292955
+ kind: "package",
292956
+ target: found2.specifier,
292957
+ dynamic: found2.dynamic,
292958
+ package_names: found2.dynamic ? ["*"] : requestedNames(found2.statement)
292959
+ });
292960
+ continue;
292961
+ }
292962
+ const target = importType === "app" ? resolveLocalSpecifier(root, path, found2.specifier) : resolveFileSpecifier(root, path, found2.specifier);
292963
+ if (target === null) {
292964
+ diagnostics.push(diagnosticAt(path, found2.node, `Cannot find "${found2.specifier}" from ${path}`));
292965
+ blocksUnitBuild ||= importType === "app" && !found2.dynamic;
292966
+ continue;
292967
+ }
292968
+ if (target === GENERATED_RESOURCES_PATH) {
292969
+ imports.push({ specifier: found2.specifier, kind: "resources", target, dynamic: found2.dynamic });
292970
+ continue;
292971
+ }
292972
+ imports.push({
292973
+ specifier: found2.specifier,
292974
+ kind: importType,
292975
+ target,
292976
+ dynamic: found2.dynamic,
292977
+ names: requestedNames(found2.statement),
292978
+ node: found2.node
292979
+ });
292980
+ }
292981
+ return { diagnostics, imports, blocksUnitBuild };
292982
+ }
292919
292983
  function buildModuleGraph(root, entries, manifest, diagnostics, assetKeys = /* @__PURE__ */ new Set(), resourceEntries2 = {}) {
292920
292984
  const packages = declaredPackages(manifest);
292921
292985
  const scannedStyles = /* @__PURE__ */ new Set();
@@ -292965,64 +293029,15 @@ function buildModuleGraph(root, entries, manifest, diagnostics, assetKeys = /* @
292965
293029
  )
292966
293030
  );
292967
293031
  }
292968
- const imports = [];
292969
- for (const found2 of moduleSpecifiers2(entry.ast)) {
292970
- if (found2.specifier === null) {
292971
- diagnostics.push(diagnosticAt(path, found2.node, "A dynamic import must name its module with a string literal"));
292972
- continue;
292973
- }
292974
- if (found2.typeOnly) {
292975
- continue;
293032
+ const checked = checkModuleImports(root, path, entry.ast, packages);
293033
+ diagnostics.push(...checked.diagnostics);
293034
+ const { imports } = checked;
293035
+ for (const item of imports) {
293036
+ if (item.kind === "package") {
293037
+ usedPackages.add(item.specifier);
293038
+ } else if (item.kind !== "host" && item.kind !== "resources") {
293039
+ pending.push(item.target);
292976
293040
  }
292977
- const importType = importKind(found2.specifier);
292978
- const refused = unsupportedImportMessage(found2.specifier, importType);
292979
- if (refused !== null) {
292980
- diagnostics.push(diagnosticAt(path, found2.node, refused));
292981
- continue;
292982
- }
292983
- if (importType === "host") {
292984
- imports.push({ specifier: found2.specifier, kind: "host", target: found2.specifier, dynamic: found2.dynamic });
292985
- continue;
292986
- }
292987
- if (importType === "package") {
292988
- if (!packages.has(packageName(found2.specifier))) {
292989
- diagnostics.push(
292990
- diagnosticAt(
292991
- path,
292992
- found2.node,
292993
- `"${packageName(found2.specifier)}" is not a dependency. Add it to "dependencies" in package.json`
292994
- )
292995
- );
292996
- continue;
292997
- }
292998
- usedPackages.add(found2.specifier);
292999
- imports.push({
293000
- specifier: found2.specifier,
293001
- kind: "package",
293002
- target: found2.specifier,
293003
- dynamic: found2.dynamic,
293004
- package_names: found2.dynamic ? ["*"] : requestedNames(found2.statement)
293005
- });
293006
- continue;
293007
- }
293008
- const target = importType === "app" ? resolveLocalSpecifier(root, path, found2.specifier) : resolveFileSpecifier(root, path, found2.specifier);
293009
- if (target === null) {
293010
- diagnostics.push(diagnosticAt(path, found2.node, `Cannot find "${found2.specifier}" from ${path}`));
293011
- continue;
293012
- }
293013
- if (target === GENERATED_RESOURCES_PATH) {
293014
- imports.push({ specifier: found2.specifier, kind: "resources", target, dynamic: found2.dynamic });
293015
- continue;
293016
- }
293017
- imports.push({
293018
- specifier: found2.specifier,
293019
- kind: importType,
293020
- target,
293021
- dynamic: found2.dynamic,
293022
- names: requestedNames(found2.statement),
293023
- node: found2.node
293024
- });
293025
- pending.push(target);
293026
293041
  }
293027
293042
  if (imports.some((item) => item.kind === "resources")) {
293028
293043
  checkResourceReferences(root, entry, resourceEntries2, diagnostics);
@@ -299784,7 +299799,7 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
299784
299799
  continue;
299785
299800
  }
299786
299801
  if (ui && unsupportedImportMessage(specifier, kind) !== null) {
299787
- throw new SourceError(`${path}: ${unsupportedImportMessage(specifier, kind)}`, statement2.source);
299802
+ continue;
299788
299803
  }
299789
299804
  if (!namesWorkspaceFile(specifier, ui)) {
299790
299805
  throw new SourceError(
@@ -299794,6 +299809,9 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
299794
299809
  }
299795
299810
  const target = resolveLocalSpecifier(root, path, specifier);
299796
299811
  if (target === null) {
299812
+ if (ui) {
299813
+ continue;
299814
+ }
299797
299815
  throw new SourceError(
299798
299816
  `${path} imports "${specifier}", which does not exist`,
299799
299817
  statement2.source
@@ -300039,7 +300057,10 @@ function lazyDeclaration(lazy) {
300039
300057
  if (lazy.length === 0) {
300040
300058
  return "";
300041
300059
  }
300042
- const signatures = [...new Map(lazy.map((item) => [item.specifier, item.path]))].map(([specifier, path]) => `(path: ${JSON.stringify(specifier)}): Promise<typeof import(${JSON.stringify(`/app/${path}`)})>;`).join(" ");
300060
+ const signatures = [...new Map(lazy.map((item) => [item.specifier, item.path]))].map(([specifier, path]) => {
300061
+ const module = path === null ? "any" : `typeof import(${JSON.stringify(`/app/${path}`)})`;
300062
+ return `(path: ${JSON.stringify(specifier)}): Promise<${module}>;`;
300063
+ }).join(" ");
300043
300064
  return `
300044
300065
  const __lazy = undefined as unknown as { ${signatures} };`;
300045
300066
  }
@@ -300122,7 +300143,11 @@ function foreignBindings(source, ast, imports) {
300122
300143
  })).filter((binding) => binding.text !== "" || binding.lintText !== "");
300123
300144
  }
300124
300145
  function lazyImports(root, path, ast) {
300125
- return moduleSpecifiers2(ast).filter((item) => item.dynamic && item.specifier !== null && importKind(item.specifier) === "app").map((item) => ({ ...item, target: resolveLocalSpecifier(root, path, item.specifier) })).filter((item) => item.target !== null).map((item) => ({ specifier: item.specifier, path: item.target, start: item.call.start }));
300146
+ return moduleSpecifiers2(ast).filter((item) => item.dynamic && item.specifier !== null && importKind(item.specifier) === "app").map((item) => ({
300147
+ specifier: item.specifier,
300148
+ path: resolveLocalSpecifier(root, path, item.specifier),
300149
+ start: item.call.start
300150
+ }));
300126
300151
  }
300127
300152
  function appImports(root, path, source, ast) {
300128
300153
  if (root === null) {
@@ -300134,7 +300159,7 @@ function appImports(root, path, source, ast) {
300134
300159
  if (imports.length === 0 && lazy.length === 0) {
300135
300160
  return { ...NO_APP_IMPORTS, bindings: foreign };
300136
300161
  }
300137
- const modules = appModuleClosure(root, [...imports, ...lazy], /* @__PURE__ */ new Set(), { ui: true });
300162
+ const modules = appModuleClosure(root, [...imports, ...lazy.filter((item) => item.path !== null)], /* @__PURE__ */ new Set(), { ui: true });
300138
300163
  const bindings = [...appBindings(source, imports), ...foreign].toSorted((left, right) => left.start - right.start);
300139
300164
  return { imports, lazy, modules, bindings, prelude: appPrelude(modules) };
300140
300165
  }
@@ -302605,6 +302630,8 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
302605
302630
  files.filter((path) => classify(path) === "resource"),
302606
302631
  diagnostics
302607
302632
  );
302633
+ const packageFiles = readPackageFiles(root, diagnostics);
302634
+ const packages = declaredPackages(packageFiles.manifest);
302608
302635
  const uiEntries = [];
302609
302636
  const failedLayouts = /* @__PURE__ */ new Set();
302610
302637
  const failedComponents = /* @__PURE__ */ new Set();
@@ -302627,6 +302654,17 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
302627
302654
  }
302628
302655
  try {
302629
302656
  const ast = parseSource(source, { jsx: extname2(path) === ".tsx" });
302657
+ if (["page", "layout", "component"].includes(kind) && checkModuleImports(root, path, ast, packages).blocksUnitBuild) {
302658
+ if (kind === "page") {
302659
+ failedPageKeys.push(...pageKeyOfSource(path, source));
302660
+ } else if (kind === "layout") {
302661
+ failedLayouts.add(stem(path));
302662
+ } else {
302663
+ failedComponents.add(stem(path));
302664
+ }
302665
+ uiEntries.push({ path, source, ast });
302666
+ return;
302667
+ }
302630
302668
  switch (kind) {
302631
302669
  case "assets":
302632
302670
  output.assets = buildAssets(ast, assetCatalog);
@@ -302731,7 +302769,6 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
302731
302769
  if (resourcesComplete) {
302732
302770
  checkPageResources(output.pages, output.resources, platformSlugs, names2, diagnostics);
302733
302771
  }
302734
- const packageFiles = readPackageFiles(root, diagnostics);
302735
302772
  const assetsComplete = !diagnostics.some((diagnostic2) => diagnostic2.path === "assets.ts");
302736
302773
  const assetKeys = assetsComplete ? new Set(output.assets.map((asset2) => asset2.key)) : null;
302737
302774
  const moduleGraph = buildModuleGraph(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {