@diagonal-hq/cli 0.4.0 → 0.4.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.
- package/dist/cli.mjs +66 -30
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -266849,15 +266849,18 @@ function isTypeOnlyStatement(statement2) {
|
|
|
266849
266849
|
if (statement2.type === "TSTypeAliasDeclaration" || statement2.type === "TSInterfaceDeclaration") {
|
|
266850
266850
|
return true;
|
|
266851
266851
|
}
|
|
266852
|
+
if (statement2.type === "ExportAllDeclaration") {
|
|
266853
|
+
return statement2.exportKind === "type";
|
|
266854
|
+
}
|
|
266852
266855
|
if (statement2.type !== "ExportNamedDeclaration") {
|
|
266853
266856
|
return false;
|
|
266854
266857
|
}
|
|
266855
266858
|
if (statement2.exportKind === "type") {
|
|
266856
266859
|
return true;
|
|
266857
266860
|
}
|
|
266858
|
-
return statement2.declaration?.type === "TSTypeAliasDeclaration" || statement2.declaration?.type === "TSInterfaceDeclaration";
|
|
266861
|
+
return statement2.declaration?.type === "TSTypeAliasDeclaration" || statement2.declaration?.type === "TSInterfaceDeclaration" || statement2.specifiers.length > 0 && statement2.specifiers.every((specifier) => specifier.exportKind === "type");
|
|
266859
266862
|
}
|
|
266860
|
-
function defaultExportOf(ast, {
|
|
266863
|
+
function defaultExportOf(ast, { helpers: helperPlacement = "none", allowAppImports = false, extraImports = [] } = {}) {
|
|
266861
266864
|
const imports = [];
|
|
266862
266865
|
const helpers = [];
|
|
266863
266866
|
let declaration = null;
|
|
@@ -266889,12 +266892,18 @@ function defaultExportOf(ast, { allowHelpers = false, allowAppImports = false, e
|
|
|
266889
266892
|
declaration = statement2.declaration;
|
|
266890
266893
|
continue;
|
|
266891
266894
|
}
|
|
266892
|
-
if (
|
|
266895
|
+
if (allowAppImports && (statement2.type === "ExportNamedDeclaration" || statement2.type === "ExportAllDeclaration")) {
|
|
266896
|
+
throw new SourceError(
|
|
266897
|
+
"Named exports are not allowed in a page, layout, or component file. Remove export or move the code to a lib/ module",
|
|
266898
|
+
statement2
|
|
266899
|
+
);
|
|
266900
|
+
}
|
|
266901
|
+
if (helperPlacement === "anywhere" || helperPlacement === "above" && declaration === null) {
|
|
266893
266902
|
helpers.push(statement2);
|
|
266894
266903
|
continue;
|
|
266895
266904
|
}
|
|
266896
266905
|
throw new SourceError(
|
|
266897
|
-
|
|
266906
|
+
helperPlacement === "above" ? `Top-level ${statement2.type} after the default export is not allowed. Move it above the export` : `Top-level ${statement2.type} is not allowed. Put the code inside the exported function`,
|
|
266898
266907
|
statement2
|
|
266899
266908
|
);
|
|
266900
266909
|
}
|
|
@@ -295012,11 +295021,14 @@ function customComponentCatalog(components) {
|
|
|
295012
295021
|
}));
|
|
295013
295022
|
}
|
|
295014
295023
|
function mapPosition(unit, line, column) {
|
|
295015
|
-
const { prefixLine, prefixColumn, prefixLength } = unit.lint;
|
|
295016
|
-
if (line
|
|
295017
|
-
|
|
295024
|
+
const { prefixLine, prefixColumn, prefixLength, suffixLine, suffixColumn, suffixLength } = unit.lint;
|
|
295025
|
+
if (line === prefixLine && column >= prefixColumn) {
|
|
295026
|
+
column = Math.max(prefixColumn, column - prefixLength);
|
|
295027
|
+
}
|
|
295028
|
+
if (line === suffixLine && column >= suffixColumn) {
|
|
295029
|
+
column = Math.max(suffixColumn, column - suffixLength);
|
|
295018
295030
|
}
|
|
295019
|
-
return { line, column
|
|
295031
|
+
return { line, column };
|
|
295020
295032
|
}
|
|
295021
295033
|
function failureEntries(failure2) {
|
|
295022
295034
|
const entries = [];
|
|
@@ -298355,6 +298367,7 @@ function compile(code2, functionNode) {
|
|
|
298355
298367
|
}
|
|
298356
298368
|
}
|
|
298357
298369
|
var FACTORY_PREFIX = "return (";
|
|
298370
|
+
var FACTORY_SUFFIX = ");";
|
|
298358
298371
|
var SDK_TYPE_DECLARATIONS = {
|
|
298359
298372
|
LayoutProps: "{ children?: React.ReactNode }"
|
|
298360
298373
|
};
|
|
@@ -298375,16 +298388,18 @@ function keptTypeRange(statement2, helpers) {
|
|
|
298375
298388
|
return null;
|
|
298376
298389
|
}
|
|
298377
298390
|
var LAZY_IMPORT = "__lazy(";
|
|
298378
|
-
function lintUnit2(original, ast, functionNode, helpers, app) {
|
|
298391
|
+
function lintUnit2(original, ast, functionNode, helpers, app, functionBinding) {
|
|
298379
298392
|
let source = original;
|
|
298380
298393
|
for (const lazy of app.lazy) {
|
|
298381
298394
|
source = source.slice(0, lazy.start) + LAZY_IMPORT + source.slice(lazy.start + LAZY_IMPORT.length);
|
|
298382
298395
|
}
|
|
298383
|
-
let kept = blankOut(source
|
|
298384
|
-
const ranges = ast.program.body.map((statement2) => keptTypeRange(statement2, helpers)).filter((range) => range !== null
|
|
298396
|
+
let kept = blankOut(source);
|
|
298397
|
+
const ranges = ast.program.body.map((statement2) => keptTypeRange(statement2, helpers)).filter((range) => range !== null);
|
|
298385
298398
|
for (const [start, end] of ranges) {
|
|
298386
298399
|
kept = kept.slice(0, start) + source.slice(start, end) + kept.slice(end);
|
|
298387
298400
|
}
|
|
298401
|
+
const trailing = kept.slice(functionNode.end);
|
|
298402
|
+
kept = kept.slice(0, functionNode.start);
|
|
298388
298403
|
for (const binding of app.bindings.toSorted((left, right) => right.start - left.start)) {
|
|
298389
298404
|
const replaced = `${binding.text}${"\n".repeat(newlines(binding.original))}`;
|
|
298390
298405
|
kept = kept.slice(0, binding.start) + replaced + kept.slice(binding.end);
|
|
@@ -298394,10 +298409,12 @@ function lintUnit2(original, ast, functionNode, helpers, app) {
|
|
|
298394
298409
|
);
|
|
298395
298410
|
const code2 = [
|
|
298396
298411
|
kept,
|
|
298397
|
-
FACTORY_PREFIX,
|
|
298412
|
+
functionBinding === null ? FACTORY_PREFIX : "",
|
|
298398
298413
|
sliceOf(source, functionNode),
|
|
298399
|
-
"
|
|
298400
|
-
|
|
298414
|
+
functionBinding === null ? FACTORY_SUFFIX : "",
|
|
298415
|
+
trailing,
|
|
298416
|
+
functionBinding === null ? "" : `
|
|
298417
|
+
return ${functionBinding};`,
|
|
298401
298418
|
...importedTypes.map((declaration) => `
|
|
298402
298419
|
${declaration}`),
|
|
298403
298420
|
lazyDeclaration(app.lazy)
|
|
@@ -298406,7 +298423,10 @@ ${declaration}`),
|
|
|
298406
298423
|
code: code2,
|
|
298407
298424
|
prefixLine: functionNode.loc.start.line,
|
|
298408
298425
|
prefixColumn: functionNode.loc.start.column + 1,
|
|
298409
|
-
prefixLength: FACTORY_PREFIX.length,
|
|
298426
|
+
prefixLength: functionBinding === null ? FACTORY_PREFIX.length : 0,
|
|
298427
|
+
suffixLine: functionNode.loc.end.line,
|
|
298428
|
+
suffixColumn: functionNode.loc.end.column + 1,
|
|
298429
|
+
suffixLength: functionBinding === null ? FACTORY_SUFFIX.length : 0,
|
|
298410
298430
|
appModules: Object.fromEntries([...app.modules].map(([path, module]) => [path, module.source]))
|
|
298411
298431
|
};
|
|
298412
298432
|
}
|
|
@@ -298511,7 +298531,11 @@ function functionUnit(source, ast, functionNode, helpers, app) {
|
|
|
298511
298531
|
`).join("");
|
|
298512
298532
|
const prelude = helpers.map((statement2) => `${sliceOf(source, statement2)}
|
|
298513
298533
|
`).join("");
|
|
298514
|
-
const
|
|
298534
|
+
const functionBinding = functionNode.type === "FunctionDeclaration" ? functionNode.id?.name ?? null : null;
|
|
298535
|
+
const functionSource = sliceOf(source, functionNode);
|
|
298536
|
+
const returned = functionBinding === null ? `${FACTORY_PREFIX}${functionSource}${FACTORY_SUFFIX}` : `${functionSource}
|
|
298537
|
+
return ${functionBinding};`;
|
|
298538
|
+
const code2 = `${app.prelude}${bindings}${prelude}${returned}`;
|
|
298515
298539
|
const moduleReferences = [...app.modules].flatMap(
|
|
298516
298540
|
([path, module]) => customComponentReferences(parseSource(module.source, { jsx: path.endsWith("x") }).program).map(
|
|
298517
298541
|
(reference) => ({ name: reference.name, node: null })
|
|
@@ -298527,15 +298551,18 @@ function functionUnit(source, ast, functionNode, helpers, app) {
|
|
|
298527
298551
|
...moduleReferences,
|
|
298528
298552
|
...[functionNode, ...helpers].flatMap((node) => customComponentReferences(node)).toSorted((left, right) => left.node.start - right.node.start)
|
|
298529
298553
|
],
|
|
298530
|
-
lint: lintUnit2(source, ast, functionNode, helpers, app)
|
|
298554
|
+
lint: lintUnit2(source, ast, functionNode, helpers, app, functionBinding)
|
|
298531
298555
|
};
|
|
298532
298556
|
}
|
|
298533
298557
|
function exportedFunction(ast, kind) {
|
|
298534
|
-
const { declaration } = defaultExportOf(ast, {
|
|
298558
|
+
const { declaration, helpers } = defaultExportOf(ast, {
|
|
298559
|
+
helpers: "anywhere",
|
|
298560
|
+
allowAppImports: true
|
|
298561
|
+
});
|
|
298535
298562
|
if (!isFunctionNode(declaration)) {
|
|
298536
298563
|
throw new SourceError(`A ${kind} file must export default a function`, declaration);
|
|
298537
298564
|
}
|
|
298538
|
-
return declaration;
|
|
298565
|
+
return { functionNode: declaration, helpers };
|
|
298539
298566
|
}
|
|
298540
298567
|
function buildComponent(path, name, source, ast, root = null) {
|
|
298541
298568
|
if (!COMPONENT_NAME_PATTERN.test(name)) {
|
|
@@ -298544,19 +298571,19 @@ function buildComponent(path, name, source, ast, root = null) {
|
|
|
298544
298571
|
ast.program
|
|
298545
298572
|
);
|
|
298546
298573
|
}
|
|
298547
|
-
const functionNode = exportedFunction(ast, "component");
|
|
298574
|
+
const { functionNode, helpers } = exportedFunction(ast, "component");
|
|
298548
298575
|
return {
|
|
298549
298576
|
path,
|
|
298550
298577
|
name,
|
|
298551
|
-
...functionUnit(source, ast, functionNode,
|
|
298578
|
+
...functionUnit(source, ast, functionNode, helpers, appImports(root, path, source, ast))
|
|
298552
298579
|
};
|
|
298553
298580
|
}
|
|
298554
298581
|
function buildLayout(path, name, source, ast, root = null) {
|
|
298555
|
-
const functionNode = exportedFunction(ast, "layout");
|
|
298582
|
+
const { functionNode, helpers } = exportedFunction(ast, "layout");
|
|
298556
298583
|
return {
|
|
298557
298584
|
path,
|
|
298558
298585
|
name,
|
|
298559
|
-
...functionUnit(source, ast, functionNode,
|
|
298586
|
+
...functionUnit(source, ast, functionNode, helpers, appImports(root, path, source, ast))
|
|
298560
298587
|
};
|
|
298561
298588
|
}
|
|
298562
298589
|
function normalizeRoute(route) {
|
|
@@ -298684,7 +298711,7 @@ function pageParams(meta, nodes, route) {
|
|
|
298684
298711
|
}
|
|
298685
298712
|
function buildPage(path, source, ast, root = null, resources = null) {
|
|
298686
298713
|
const { declaration, helpers } = defaultExportOf(ast, {
|
|
298687
|
-
|
|
298714
|
+
helpers: "above",
|
|
298688
298715
|
allowAppImports: true
|
|
298689
298716
|
});
|
|
298690
298717
|
const [metaNode, functionNode] = expectDefineCall(declaration, "definePage", 2);
|
|
@@ -300764,9 +300791,9 @@ function componentClosure(start, componentsByName) {
|
|
|
300764
300791
|
}
|
|
300765
300792
|
return [...closure].toSorted((left, right) => left.localeCompare(right));
|
|
300766
300793
|
}
|
|
300767
|
-
function reportUnknownComponents(unit, componentsByName, diagnostics) {
|
|
300794
|
+
function reportUnknownComponents(unit, componentsByName, failedComponents, diagnostics) {
|
|
300768
300795
|
for (const reference of unit.references) {
|
|
300769
|
-
if (!componentsByName.has(reference.name)) {
|
|
300796
|
+
if (!componentsByName.has(reference.name) && !failedComponents.has(reference.name)) {
|
|
300770
300797
|
diagnostics.push(
|
|
300771
300798
|
diagnosticAt(
|
|
300772
300799
|
unit.path,
|
|
@@ -300889,6 +300916,8 @@ function buildWorkspace(root, { writeGeneratedResources = false } = {}) {
|
|
|
300889
300916
|
);
|
|
300890
300917
|
syncGeneratedResources(root, names2, writeGeneratedResources, diagnostics);
|
|
300891
300918
|
const uiEntries = [];
|
|
300919
|
+
const failedLayouts = /* @__PURE__ */ new Set();
|
|
300920
|
+
const failedComponents = /* @__PURE__ */ new Set();
|
|
300892
300921
|
for (const path of files) {
|
|
300893
300922
|
const kind = classify(path);
|
|
300894
300923
|
if (kind === "ignored") {
|
|
@@ -300952,6 +300981,11 @@ function buildWorkspace(root, { writeGeneratedResources = false } = {}) {
|
|
|
300952
300981
|
}
|
|
300953
300982
|
} catch (error) {
|
|
300954
300983
|
diagnostics.push(diagnosticFromError(path, error));
|
|
300984
|
+
if (kind === "layout") {
|
|
300985
|
+
failedLayouts.add(stem(path));
|
|
300986
|
+
} else if (kind === "component") {
|
|
300987
|
+
failedComponents.add(stem(path));
|
|
300988
|
+
}
|
|
300955
300989
|
}
|
|
300956
300990
|
}
|
|
300957
300991
|
if (output.config === null && !diagnostics.some((diagnostic2) => diagnostic2.path === CONFIG_PATH)) {
|
|
@@ -301002,11 +301036,13 @@ function buildWorkspace(root, { writeGeneratedResources = false } = {}) {
|
|
|
301002
301036
|
);
|
|
301003
301037
|
const layoutsByName = new Map(output.layouts.map((layout) => [layout.name, layout]));
|
|
301004
301038
|
for (const unit of [...output.components, ...output.layouts, ...output.pages]) {
|
|
301005
|
-
reportUnknownComponents(unit, componentsByName, diagnostics);
|
|
301039
|
+
reportUnknownComponents(unit, componentsByName, failedComponents, diagnostics);
|
|
301006
301040
|
}
|
|
301007
301041
|
if (resourcesComplete) {
|
|
301008
301042
|
lintUnits(
|
|
301009
|
-
[...output.components, ...output.layouts, ...output.pages]
|
|
301043
|
+
[...output.components, ...output.layouts, ...output.pages].filter(
|
|
301044
|
+
(unit) => !unit.references.some((reference) => failedComponents.has(reference.name))
|
|
301045
|
+
),
|
|
301010
301046
|
output.resources,
|
|
301011
301047
|
output.components,
|
|
301012
301048
|
diagnostics
|
|
@@ -301027,7 +301063,7 @@ function buildWorkspace(root, { writeGeneratedResources = false } = {}) {
|
|
|
301027
301063
|
const names3 = references.map((reference) => reference.name);
|
|
301028
301064
|
if (page.layout !== null) {
|
|
301029
301065
|
const layout = layoutsByName.get(page.layout);
|
|
301030
|
-
if (layout === void 0) {
|
|
301066
|
+
if (layout === void 0 && !failedLayouts.has(page.layout)) {
|
|
301031
301067
|
diagnostics.push(
|
|
301032
301068
|
diagnosticAt(
|
|
301033
301069
|
page.path,
|
|
@@ -301035,7 +301071,7 @@ function buildWorkspace(root, { writeGeneratedResources = false } = {}) {
|
|
|
301035
301071
|
`Unknown layout "${page.layout}". Add layouts/${page.layout}.tsx`
|
|
301036
301072
|
)
|
|
301037
301073
|
);
|
|
301038
|
-
} else {
|
|
301074
|
+
} else if (layout !== void 0) {
|
|
301039
301075
|
names3.push(...layout.references.map((reference) => reference.name));
|
|
301040
301076
|
}
|
|
301041
301077
|
}
|