@diagonal-hq/cli 0.27.0 → 0.27.1

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 (2) hide show
  1. package/dist/cli.mjs +60 -11
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -315089,6 +315089,15 @@ var defineNotificationSchedule = (schedule) => schedule;
315089
315089
  var defineTestSuite = (suite) => suite;
315090
315090
  var defineTest = (config, handlers) => ({ config, ...handlers });
315091
315091
 
315092
+ // scripts/lib/runtime-build/factory-foreign-imports.mjs
315093
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
315094
+ function packageExpression(specifier) {
315095
+ return `globalThis.__DIAGONAL_HOST__.requirePackage(${JSON.stringify(specifier)})`;
315096
+ }
315097
+ function styleModuleExpression(path) {
315098
+ return path === null ? "{}" : `__appStyleModule(${JSON.stringify(path)})`;
315099
+ }
315100
+
315092
315101
  // scripts/lib/runtime-build/module-graph.mjs
315093
315102
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
315094
315103
  import { readFileSync as readFileSync6 } from "node:fs";
@@ -316791,6 +316800,7 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
316791
316800
  const source = transform3 === null ? read2 : transform3(path, read2);
316792
316801
  const ast = parseModule(path, source);
316793
316802
  const requires = {};
316803
+ const foreign = {};
316794
316804
  const references = ui ? moduleSpecifiers2(ast).filter((item) => item.specifier !== null && !item.typeOnly).map((item) => ({ specifier: item.specifier, source: item.node })) : ast.program.body.filter(
316795
316805
  (statement2) => statement2.type === "ImportDeclaration" || statement2.type === "ExportAllDeclaration" || statement2.type === "ExportNamedDeclaration"
316796
316806
  ).map((statement2) => ({ specifier: statement2.source?.value, source: statement2.source }));
@@ -316801,6 +316811,10 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
316801
316811
  }
316802
316812
  const kind = importKind(specifier);
316803
316813
  if (ui && PRELUDE_SKIPPED_KINDS.has(kind)) {
316814
+ const value = foreignValue(root, path, specifier, kind);
316815
+ if (value !== null) {
316816
+ foreign[specifier] = value;
316817
+ }
316804
316818
  continue;
316805
316819
  }
316806
316820
  if (ui && unsupportedImportMessage(specifier, kind) !== null) {
@@ -316828,11 +316842,24 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
316828
316842
  modules.set(path, {
316829
316843
  source,
316830
316844
  requires,
316845
+ foreign,
316831
316846
  pagesNames: ui ? pagesSdkNames(ast) : []
316832
316847
  });
316833
316848
  }
316834
316849
  return modules;
316835
316850
  }
316851
+ function foreignValue(root, path, specifier, kind) {
316852
+ switch (kind) {
316853
+ case "package":
316854
+ return `{ __esModule: true, ...${packageExpression(specifier)} }`;
316855
+ case "style_module":
316856
+ return styleModuleExpression(resolveLocalSpecifier(root, path, specifier));
316857
+ case "style":
316858
+ return "{}";
316859
+ default:
316860
+ return null;
316861
+ }
316862
+ }
316836
316863
  function pagesSdkNames(ast) {
316837
316864
  return moduleSpecifiers2(ast).filter((item) => item.specifier === PAGES_SDK_MODULE && !item.typeOnly).flatMap((item) => item.dynamic ? ["*"] : requestedNames(item.statement));
316838
316865
  }
@@ -316847,12 +316874,20 @@ function appPrelude(modules) {
316847
316874
  if (modules.size === 0) {
316848
316875
  return "";
316849
316876
  }
316877
+ const hasForeign = [...modules.values()].some((module) => Object.keys(module.foreign ?? {}).length > 0);
316850
316878
  const entries = [...modules].map(([path, module]) => {
316851
316879
  const code2 = compileModule(path, module.source);
316880
+ const foreign = Object.entries(module.foreign ?? {}).map(([specifier, value]) => `${JSON.stringify(specifier)}: () => (${value})`);
316881
+ const foreignEntry = hasForeign ? `, { ${foreign.join(", ")} }` : "";
316852
316882
  return `${JSON.stringify(path)}: [function (exports, require, module) {
316853
316883
  ${code2}
316854
- }, ${JSON.stringify(module.requires)}]`;
316884
+ }, ${JSON.stringify(module.requires)}${foreignEntry}]`;
316855
316885
  });
316886
+ const foreignRequire = hasForeign ? `
316887
+ if (foreign[specifier] !== undefined) {
316888
+ return foreign[specifier]();
316889
+ }
316890
+ ` : "";
316856
316891
  const pagesNames = new Set([...modules.values()].flatMap((module) => module.pagesNames));
316857
316892
  const pagesSdk = pagesNames.has("*") ? pagesSdkObjectText() : pagesSdkObjectText([...pagesNames].toSorted());
316858
316893
  return `const ${APP_IMPORT} = ((modules, outer) => {
@@ -316864,10 +316899,10 @@ ${code2}
316864
316899
  return cache[path].exports;
316865
316900
  }
316866
316901
 
316867
- const [factory, requires] = modules[path];
316902
+ const [factory, requires${hasForeign ? ", foreign" : ""}] = modules[path];
316868
316903
  const module = { exports: {} };
316869
316904
  cache[path] = module;
316870
- const require = (specifier) => {
316905
+ const require = (specifier) => {${foreignRequire}
316871
316906
  if (specifier === ${JSON.stringify(AUTHORING_MODULE)}) {
316872
316907
  return runtime;
316873
316908
  }
@@ -326051,7 +326086,7 @@ function isTypeOnlySpecifier(statement2, specifier) {
326051
326086
  function importedName(specifier) {
326052
326087
  return specifier.imported.type === "StringLiteral" ? specifier.imported.value : specifier.imported.name;
326053
326088
  }
326054
- function foreignBindingText(statement2, { lint: lint3 }) {
326089
+ function foreignBindingText(statement2, { lint: lint3, resolve: resolve8 }) {
326055
326090
  const specifier = statement2.source.value;
326056
326091
  const kind = importKind(specifier);
326057
326092
  const statements2 = [];
@@ -326091,8 +326126,22 @@ function foreignBindingText(statement2, { lint: lint3 }) {
326091
326126
  }
326092
326127
  continue;
326093
326128
  }
326094
- const placeholder2 = kind === "style_module" ? `const ${local}: Record<string, string> = {};` : `const ${local}: any = undefined;`;
326095
- statements2.push(placeholder2);
326129
+ if (lint3) {
326130
+ statements2.push(
326131
+ kind === "style_module" ? `const ${local}: Record<string, string> = {};` : `const ${local}: any = undefined;`
326132
+ );
326133
+ continue;
326134
+ }
326135
+ const value = kind === "package" ? packageExpression(specifier) : kind === "style_module" ? styleModuleExpression(resolve8(specifier)) : null;
326136
+ if (value === null) {
326137
+ statements2.push(`const ${local} = undefined;`);
326138
+ } else if (item.type === "ImportSpecifier") {
326139
+ statements2.push(`const ${local} = ${value}[${JSON.stringify(importedName(item))}];`);
326140
+ } else if (item.type === "ImportDefaultSpecifier" && kind === "package") {
326141
+ statements2.push(`const ${local} = ${value}.default;`);
326142
+ } else {
326143
+ statements2.push(`const ${local} = ${value};`);
326144
+ }
326096
326145
  }
326097
326146
  return statements2.join(" ");
326098
326147
  }
@@ -326115,12 +326164,12 @@ function foreignTypeAliases(statement2) {
326115
326164
  return `type ${local} = ${SDK_TYPE_DECLARATIONS[local] ?? "any"};`;
326116
326165
  });
326117
326166
  }
326118
- function foreignBindings(source, ast, imports) {
326167
+ function foreignBindings(source, ast, imports, resolve8) {
326119
326168
  return ast.program.body.filter((statement2) => statement2.type === "ImportDeclaration").filter((statement2) => !imports.some((item) => item.statement === statement2)).filter((statement2) => !isAuthoringModule(statement2.source.value)).map((statement2) => ({
326120
326169
  start: statement2.start,
326121
326170
  end: statement2.end,
326122
- text: foreignBindingText(statement2, { lint: false }),
326123
- lintText: foreignBindingText(statement2, { lint: true }),
326171
+ text: foreignBindingText(statement2, { lint: false, resolve: resolve8 }),
326172
+ lintText: foreignBindingText(statement2, { lint: true, resolve: resolve8 }),
326124
326173
  original: sliceOf(source, statement2)
326125
326174
  })).filter((binding) => binding.text !== "" || binding.lintText !== "");
326126
326175
  }
@@ -326133,10 +326182,10 @@ function lazyImports(root, path, ast) {
326133
326182
  }
326134
326183
  function appImports(root, path, source, ast) {
326135
326184
  if (root === null) {
326136
- return { ...NO_APP_IMPORTS, bindings: foreignBindings(source, ast, []) };
326185
+ return { ...NO_APP_IMPORTS, bindings: foreignBindings(source, ast, [], () => null) };
326137
326186
  }
326138
326187
  const imports = appImportsOf(root, path, ast, { ui: true });
326139
- const foreign = foreignBindings(source, ast, imports);
326188
+ const foreign = foreignBindings(source, ast, imports, (specifier) => resolveLocalSpecifier(root, path, specifier));
326140
326189
  const lazy = lazyImports(root, path, ast);
326141
326190
  const loaded = [...imports, ...lazy.filter((item) => item.path !== null)];
326142
326191
  if (imports.length === 0 && lazy.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.27.0",
3
+ "version": "0.27.1",
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": {