@clearlydev/nx-archweave 0.5.1 → 0.5.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.
Files changed (36) hide show
  1. package/README.md +6 -4
  2. package/dist/generators/_chunks/{chunk-ILICA6LC.js → chunk-23NN76E3.js} +1 -1
  3. package/dist/generators/_chunks/{chunk-624F6DEP.js → chunk-7EDJKUY4.js} +4 -106
  4. package/dist/generators/_chunks/chunk-AMOOSD5Q.js +79 -0
  5. package/dist/generators/_chunks/{chunk-M7OQWSNF.js → chunk-C2WELXMV.js} +11 -3
  6. package/dist/generators/_chunks/{chunk-WVMTOWLM.js → chunk-FBCIELXS.js} +4 -93
  7. package/dist/generators/_chunks/chunk-FZGN5NEP.js +31 -0
  8. package/dist/generators/_chunks/chunk-LJRFVE6B.js +55 -0
  9. package/dist/generators/_chunks/{chunk-Q7IYHKT3.js → chunk-M7UBCSYL.js} +5 -3
  10. package/dist/generators/_chunks/{chunk-ERCX7F6K.js → chunk-OEEWCZCO.js} +7 -7
  11. package/dist/generators/_chunks/chunk-SHKQSTV2.js +110 -0
  12. package/dist/generators/_chunks/{chunk-TJ6SCQLI.js → chunk-VCLVE4EQ.js} +10 -79
  13. package/dist/generators/_chunks/{chunk-ZNTGYYLU.js → chunk-VI7U5HS5.js} +5 -55
  14. package/dist/generators/_chunks/{chunk-AON4KGZT.js → chunk-WQDJYSOD.js} +13 -6
  15. package/dist/generators/_chunks/{chunk-N6B6VBHG.js → chunk-XXXON43Z.js} +205 -2
  16. package/dist/generators/_chunks/chunk-YEMQFSL6.js +95 -0
  17. package/dist/generators/_chunks/chunk-ZFCK3KMO.js +396 -0
  18. package/dist/generators/_chunks/{chunk-3ZHRZK5M.js → chunk-ZRHIFPUC.js} +4 -32
  19. package/dist/generators/add-agent-rules/generator.js +4 -3
  20. package/dist/generators/add-backend/generator.js +3 -2
  21. package/dist/generators/add-fsd-lite/generator.js +7 -5
  22. package/dist/generators/add-github-templates/generator.js +3 -2
  23. package/dist/generators/add-integration/generator.js +2 -2
  24. package/dist/generators/add-review/generator.js +3 -3
  25. package/dist/generators/doctor/generator.js +35 -21
  26. package/dist/generators/entity/generator.js +4 -3
  27. package/dist/generators/feature/generator.js +4 -3
  28. package/dist/generators/init/generator.js +30 -358
  29. package/dist/generators/install-integration/generator.js +2 -2
  30. package/dist/generators/page/generator.js +4 -3
  31. package/dist/generators/shared/generator.js +4 -3
  32. package/dist/generators/widget/generator.js +4 -3
  33. package/dist/migrations/update-0.5.3/add-toolkit-config-lint-input.js +62 -0
  34. package/generators.json +1 -1
  35. package/migrations.json +9 -0
  36. package/package.json +22 -9
@@ -3,7 +3,7 @@ import {
3
3
  } from "../_chunks/chunk-U6LAFHSF.js";
4
4
  import {
5
5
  detectUnitTestRunner
6
- } from "../_chunks/chunk-Q7IYHKT3.js";
6
+ } from "../_chunks/chunk-M7UBCSYL.js";
7
7
  import "../_chunks/chunk-ASY3CK5L.js";
8
8
  import {
9
9
  REVIEW_MODES,
@@ -25,13 +25,16 @@ import {
25
25
  import {
26
26
  TOOLKIT_CONFIG_INPUT,
27
27
  classifyFsdEslintConfig,
28
+ lintInputsKeySnippet,
28
29
  lintInputsProjectSnippet,
29
- lintInputsTargetDefaultsSnippet
30
- } from "../_chunks/chunk-N6B6VBHG.js";
30
+ lintInputsTargetDefaultsSnippet,
31
+ resolveTargetDefaults
32
+ } from "../_chunks/chunk-XXXON43Z.js";
31
33
  import {
32
34
  resolveFrontendApp,
33
35
  sourceRootOf
34
- } from "../_chunks/chunk-WVMTOWLM.js";
36
+ } from "../_chunks/chunk-FBCIELXS.js";
37
+ import "../_chunks/chunk-YEMQFSL6.js";
35
38
  import "../_chunks/chunk-TXAQ2GJC.js";
36
39
  import {
37
40
  ESLINT_CONFIG_CANDIDATES,
@@ -50,11 +53,11 @@ import {
50
53
  import "../_chunks/chunk-34V6HAJT.js";
51
54
  import {
52
55
  diskRunNx
53
- } from "../_chunks/chunk-ILICA6LC.js";
56
+ } from "../_chunks/chunk-23NN76E3.js";
54
57
  import {
55
58
  readToolkitConfig,
56
59
  recordedFrontends
57
- } from "../_chunks/chunk-M7OQWSNF.js";
60
+ } from "../_chunks/chunk-C2WELXMV.js";
58
61
  import {
59
62
  detectWorkspacePackageManager,
60
63
  runNxCommand
@@ -869,7 +872,7 @@ function buildFsdRuleAnchoredCheck(root, projects) {
869
872
  import { existsSync as existsSync6, readdirSync as readdirSync5, readFileSync as readFileSync5 } from "node:fs";
870
873
  import { join as join6 } from "node:path";
871
874
  var ESLINT_PLUGIN = "@nx/eslint/plugin";
872
- var ESLINT_EXECUTOR = "@nx/eslint:lint";
875
+ var INFERRED_EXECUTOR = "nx:run-commands";
873
876
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
874
877
  function readJson(path) {
875
878
  try {
@@ -895,7 +898,7 @@ function readLintSetup(root) {
895
898
  }
896
899
  function projectList(root, projects) {
897
900
  if (projects !== void 0)
898
- return projects.map((project) => ({ name: project.name, root: project.root }));
901
+ return projects.map((project) => ({ name: project.name, root: project.root, tags: project.tags }));
899
902
  const found = [];
900
903
  for (const folder of ["apps", "libs"]) {
901
904
  let entries = [];
@@ -909,7 +912,8 @@ function projectList(root, projects) {
909
912
  const config = readJson(join6(root, dir, "project.json")) ?? readJson(join6(root, dir, "package.json"));
910
913
  if (config === null)
911
914
  continue;
912
- found.push({ name: typeof config["name"] === "string" ? config["name"] : name, root: dir });
915
+ const tags = Array.isArray(config["tags"]) ? config["tags"] : isObject(config["nx"]) && Array.isArray(config["nx"]["tags"]) ? config["nx"]["tags"] : [];
916
+ found.push({ name: typeof config["name"] === "string" ? config["name"] : name, root: dir, tags: tags.map(String) });
913
917
  }
914
918
  }
915
919
  return found;
@@ -944,13 +948,16 @@ function configFileOf(root, projectRoot) {
944
948
  const prefix = projectPrefix(projectRoot);
945
949
  return existsSync6(join6(root, `${prefix}project.json`)) ? `${prefix}project.json` : `${prefix}package.json`;
946
950
  }
947
- function defaultsInputs(setup, executor) {
948
- for (const key of [executor ?? ESLINT_EXECUTOR, setup.target]) {
949
- const entry = setup.targetDefaults[key];
950
- if (isObject(entry) && Array.isArray(entry["inputs"]))
951
- return entry["inputs"];
952
- }
953
- return void 0;
951
+ function resolveDefaults(setup, project, own) {
952
+ const executor = own === null ? INFERRED_EXECUTOR : own.executor ?? (setup.pluginRegistered ? INFERRED_EXECUTOR : void 0);
953
+ return resolveTargetDefaults(setup.targetDefaults, setup.target, {
954
+ executor,
955
+ plugin: own === null && setup.pluginRegistered ? ESLINT_PLUGIN : void 0,
956
+ project: { name: project.name, root: project.root, tags: project.tags }
957
+ });
958
+ }
959
+ function defaultsInputs(resolved) {
960
+ return resolved.kind === "found" ? resolved.inputs : void 0;
954
961
  }
955
962
  function carriesToolkitConfig(inputs, namedInputs) {
956
963
  return inputs.some((input) => {
@@ -997,14 +1004,20 @@ function buildLintCacheCheck(root, projects) {
997
1004
  if (projectPrefix(project.root) === "")
998
1005
  return false;
999
1006
  const own = ownLintTarget(root, project, setup.target);
1000
- const inputs = own?.inputs ?? defaultsInputs(setup, own?.executor);
1007
+ const inputs = own?.inputs ?? defaultsInputs(resolveDefaults(setup, project, own));
1001
1008
  return inputs === void 0 || !carriesToolkitConfig(inputs, setup.namedInputs);
1002
1009
  });
1003
1010
  if (missing.length === 0) {
1004
1011
  return createDoctorCheck({ id, label, status: "pass", message: "toolkit.config.json is among the FSD projects' lint inputs", evidence: [] });
1005
1012
  }
1006
1013
  const ownTargets = all.map((project) => ownLintTarget(root, project, setup.target)).filter((own) => own !== null);
1007
- const lines = setup.pluginRegistered && ownTargets.length === 0 ? lintInputsTargetDefaultsSnippet(setup.target) : missing.flatMap((project) => {
1014
+ const otherKeys = /* @__PURE__ */ new Map();
1015
+ for (const project of missing) {
1016
+ const resolved = resolveDefaults(setup, project, null);
1017
+ if (resolved.kind === "found" && resolved.key !== setup.target)
1018
+ otherKeys.set(resolved.key, resolved.inputs !== void 0);
1019
+ }
1020
+ const lines = setup.pluginRegistered && ownTargets.length === 0 ? otherKeys.size > 0 ? [...otherKeys].flatMap(([key, hasInputs]) => lintInputsKeySnippet(key, setup.target, hasInputs)) : lintInputsTargetDefaultsSnippet(setup.target) : missing.flatMap((project) => {
1008
1021
  const own = ownLintTarget(root, project, setup.target);
1009
1022
  return lintInputsProjectSnippet({
1010
1023
  file: own?.file ?? configFileOf(root, project.root),
@@ -1038,7 +1051,7 @@ function buildLintInputsSpreadCheck(root, projects) {
1038
1051
  const own = ownLintTarget(root, project, setup.target);
1039
1052
  if (own === null || own.inputs !== void 0)
1040
1053
  return false;
1041
- const inputs = defaultsInputs(setup, own.executor);
1054
+ const inputs = defaultsInputs(resolveDefaults(setup, project, own));
1042
1055
  return inputs !== void 0 && inputs.includes("...") && !namesOwnFiles(inputs);
1043
1056
  });
1044
1057
  if (affected.length === 0) {
@@ -1240,14 +1253,15 @@ function buildFrameworkChecks(env) {
1240
1253
  const dependencies = env.rootPackageJson?.["dependencies"] ?? {};
1241
1254
  const devDependencies = env.rootPackageJson?.["devDependencies"] ?? {};
1242
1255
  const allDeps = { ...dependencies, ...devDependencies };
1243
- const hasReactVite = Boolean(allDeps.vite && allDeps.react);
1244
1256
  const hasNext = Boolean(allDeps.next);
1257
+ const reactViteDeps = Boolean(allDeps.vite && allDeps.react);
1258
+ const hasReactVite = reactViteDeps && !hasNext;
1245
1259
  return [
1246
1260
  createDoctorCheck({
1247
1261
  id: "framework-react-vite",
1248
1262
  label: "React + Vite (root package.json only)",
1249
1263
  status: hasReactVite ? "pass" : "not-applicable",
1250
- message: hasReactVite ? "react + vite dependencies detected in the root package.json" : "Not detected in the root package.json (sub-packages are not scanned)",
1264
+ message: hasReactVite ? "react + vite dependencies detected in the root package.json" : reactViteDeps ? "next is in the root package.json too, so vite may come from its test runner \u2014 see each app's Frontend framework check" : "Not detected in the root package.json (sub-packages are not scanned)",
1251
1265
  evidence: hasReactVite ? ["package.json"] : []
1252
1266
  }),
1253
1267
  createDoctorCheck({
@@ -3,8 +3,9 @@ import {
3
3
  } from "../_chunks/chunk-H222FPLK.js";
4
4
  import {
5
5
  runFsdSlice
6
- } from "../_chunks/chunk-Q7IYHKT3.js";
7
- import "../_chunks/chunk-WVMTOWLM.js";
6
+ } from "../_chunks/chunk-M7UBCSYL.js";
7
+ import "../_chunks/chunk-FBCIELXS.js";
8
+ import "../_chunks/chunk-YEMQFSL6.js";
8
9
  import "../_chunks/chunk-TXAQ2GJC.js";
9
10
  import "../_chunks/chunk-6ZTIUBB2.js";
10
11
  import "../_chunks/chunk-YNMLB4DL.js";
@@ -12,7 +13,7 @@ import "../_chunks/chunk-JPS6XKYK.js";
12
13
  import {
13
14
  resolveDryRun
14
15
  } from "../_chunks/chunk-TUN34LAQ.js";
15
- import "../_chunks/chunk-M7OQWSNF.js";
16
+ import "../_chunks/chunk-C2WELXMV.js";
16
17
  import "../_chunks/chunk-5Z7VZPES.js";
17
18
 
18
19
  // src/generators/entity/generator.ts
@@ -3,8 +3,9 @@ import {
3
3
  } from "../_chunks/chunk-H222FPLK.js";
4
4
  import {
5
5
  runFsdSlice
6
- } from "../_chunks/chunk-Q7IYHKT3.js";
7
- import "../_chunks/chunk-WVMTOWLM.js";
6
+ } from "../_chunks/chunk-M7UBCSYL.js";
7
+ import "../_chunks/chunk-FBCIELXS.js";
8
+ import "../_chunks/chunk-YEMQFSL6.js";
8
9
  import "../_chunks/chunk-TXAQ2GJC.js";
9
10
  import "../_chunks/chunk-6ZTIUBB2.js";
10
11
  import "../_chunks/chunk-YNMLB4DL.js";
@@ -12,7 +13,7 @@ import "../_chunks/chunk-JPS6XKYK.js";
12
13
  import {
13
14
  resolveDryRun
14
15
  } from "../_chunks/chunk-TUN34LAQ.js";
15
- import "../_chunks/chunk-M7OQWSNF.js";
16
+ import "../_chunks/chunk-C2WELXMV.js";
16
17
  import "../_chunks/chunk-5Z7VZPES.js";
17
18
 
18
19
  // src/generators/feature/generator.ts
@@ -1,7 +1,13 @@
1
+ import {
2
+ applyLintInputs,
3
+ failedSections,
4
+ leftForYou,
5
+ renderInitReport
6
+ } from "../_chunks/chunk-ZFCK3KMO.js";
1
7
  import {
2
8
  recordedReview,
3
9
  runAddReview
4
- } from "../_chunks/chunk-ERCX7F6K.js";
10
+ } from "../_chunks/chunk-OEEWCZCO.js";
5
11
  import "../_chunks/chunk-ASY3CK5L.js";
6
12
  import {
7
13
  DEFAULT_MAX_ROUNDS,
@@ -9,41 +15,36 @@ import {
9
15
  buildReviewConfigSnippet
10
16
  } from "../_chunks/chunk-2WXAGWAJ.js";
11
17
  import {
12
- renderAddAgentRulesReport,
13
18
  runAddAgentRules
14
- } from "../_chunks/chunk-ZNTGYYLU.js";
15
- import {
16
- renderAddReviewReport
17
- } from "../_chunks/chunk-AON4KGZT.js";
19
+ } from "../_chunks/chunk-VI7U5HS5.js";
20
+ import "../_chunks/chunk-LJRFVE6B.js";
21
+ import "../_chunks/chunk-WQDJYSOD.js";
18
22
  import "../_chunks/chunk-5MI3O4VZ.js";
19
23
  import {
20
- renderAddBackendBody,
21
24
  runAddBackend
22
- } from "../_chunks/chunk-624F6DEP.js";
25
+ } from "../_chunks/chunk-7EDJKUY4.js";
26
+ import "../_chunks/chunk-SHKQSTV2.js";
23
27
  import "../_chunks/chunk-WNO3ZGBB.js";
24
28
  import {
25
29
  DEFAULT_CONFLICT_POLICY,
26
- renderAddFsdLiteReport,
27
30
  runAddFsdLite
28
- } from "../_chunks/chunk-TJ6SCQLI.js";
29
- import {
30
- TOOLKIT_CONFIG_INPUT,
31
- lintInputsProjectSnippet,
32
- lintInputsTargetDefaultsSnippet
33
- } from "../_chunks/chunk-N6B6VBHG.js";
31
+ } from "../_chunks/chunk-VCLVE4EQ.js";
32
+ import "../_chunks/chunk-AMOOSD5Q.js";
33
+ import "../_chunks/chunk-XXXON43Z.js";
34
34
  import {
35
- allFrameworkProfiles,
36
35
  resolveFrontendApp
37
- } from "../_chunks/chunk-WVMTOWLM.js";
36
+ } from "../_chunks/chunk-FBCIELXS.js";
37
+ import {
38
+ allFrameworkProfiles
39
+ } from "../_chunks/chunk-YEMQFSL6.js";
38
40
  import "../_chunks/chunk-TXAQ2GJC.js";
39
41
  import {
40
- ESLINT_CONFIG_CANDIDATES,
41
42
  readBoundaryTags
42
43
  } from "../_chunks/chunk-6ZTIUBB2.js";
43
44
  import {
44
- renderAddGithubTemplatesReport,
45
45
  runAddGithubTemplates
46
- } from "../_chunks/chunk-3ZHRZK5M.js";
46
+ } from "../_chunks/chunk-ZRHIFPUC.js";
47
+ import "../_chunks/chunk-FZGN5NEP.js";
47
48
  import "../_chunks/chunk-YNMLB4DL.js";
48
49
  import "../_chunks/chunk-JPS6XKYK.js";
49
50
  import {
@@ -52,7 +53,7 @@ import {
52
53
  import {
53
54
  spawnableCommand
54
55
  } from "../_chunks/chunk-34V6HAJT.js";
55
- import "../_chunks/chunk-ILICA6LC.js";
56
+ import "../_chunks/chunk-23NN76E3.js";
56
57
  import {
57
58
  DEFAULT_AI_HOSTS,
58
59
  RECORDED_BACKENDS,
@@ -60,6 +61,7 @@ import {
60
61
  RECORDED_PRESETS,
61
62
  TOOLKIT_CONFIG_PATH,
62
63
  applyJsonEdits,
64
+ messageOnlyError,
63
65
  readToolkitConfigFile,
64
66
  recordedChoice,
65
67
  recordedFrontends,
@@ -68,9 +70,8 @@ import {
68
70
  resolveLocaleOption,
69
71
  reviewProviderFor,
70
72
  treePackageManager
71
- } from "../_chunks/chunk-M7OQWSNF.js";
73
+ } from "../_chunks/chunk-C2WELXMV.js";
72
74
  import {
73
- packageManagerCommands,
74
75
  runNxCommand
75
76
  } from "../_chunks/chunk-5Z7VZPES.js";
76
77
 
@@ -150,330 +151,6 @@ function buildPresetConfig(input) {
150
151
  };
151
152
  }
152
153
 
153
- // src/generators/init/left-for-you.ts
154
- var PLUGIN = "@clearlydev/nx-archweave";
155
- function leftForYou(report) {
156
- const runNx = report.runNx ?? runNxCommand(report.packageManager);
157
- const kept = [];
158
- const manual = [];
159
- for (const section of report.sections) {
160
- if (!section.enabled || section.report === null) continue;
161
- const sectionReport = section.report;
162
- switch (sectionReport.kind) {
163
- case "fsd": {
164
- const fsd = sectionReport.report;
165
- if (fsd.aborted) break;
166
- if (fsd.eslint === "degraded-unrecognized") {
167
- manual.push(
168
- fsd.eslintPath === null ? `${fsd.project ?? "the app"}: no ESLint config found \u2014 add the archweave/fsd-boundaries rule to one (the snippet is above)` : `${fsd.eslintPath}: not recognized \u2014 add the archweave/fsd-boundaries rule yourself (the snippet is above)`
169
- );
170
- }
171
- const steiger = fsd.steiger;
172
- if (steiger !== null) {
173
- if (steiger.config === "kept") kept.push(`${steiger.configPath}: an existing steiger config with other content \u2014 left as it is`);
174
- if (steiger.target === "unrecognized") manual.push(`${fsd.project ?? "the app"}: add the fsd-check target yourself (no parseable project.json or package.json)`);
175
- if (steiger.dependencies === "unrecognized") {
176
- manual.push("package.json: could not be parsed \u2014 add steiger and @feature-sliced/steiger-plugin to devDependencies yourself");
177
- }
178
- }
179
- break;
180
- }
181
- case "agentRules":
182
- for (const file of sectionReport.report.files) {
183
- if (file.action === "user-modified") {
184
- kept.push(`${file.filePath}: its nx-archweave block was edited by hand \u2014 to replace it: ${runNx} g ${PLUGIN}:add-agent-rules --overwriteBlock`);
185
- } else if (file.action === "unrecognized") {
186
- kept.push(`${file.filePath}: left untouched (${file.reason ?? "its nx-archweave markers could not be placed"}) \u2014 fix the file, then rerun init`);
187
- }
188
- }
189
- break;
190
- case "githubTemplates":
191
- for (const file of sectionReport.report.files) {
192
- if (file.action === "skipped") {
193
- kept.push(`${file.filePath}: a different file is already there \u2014 to use the generated one, delete it and run ${runNx} g ${PLUGIN}:add-github-templates`);
194
- }
195
- }
196
- break;
197
- case "review": {
198
- const review = sectionReport.report;
199
- if (review.workflowAction === "aborted") break;
200
- if (review.workflowAction === "proposed" || review.workflowAction === "skipped") {
201
- kept.push(`${review.workflowPath}: differs from the generated workflow \u2014 to replace it: ${runNx} g ${PLUGIN}:add-review --onConflict=overwrite`);
202
- } else if (review.workflowAction === "alternate") {
203
- manual.push(`${review.workflowPath}: written alongside the existing workflow \u2014 replace the main workflow file with it yourself`);
204
- }
205
- if (review.dependabot === "proposed") manual.push(".github/dependabot.yml: add the github-actions entry shown above");
206
- break;
207
- }
208
- case "backend": {
209
- const backend = sectionReport.report;
210
- if (backend.refused !== void 0) break;
211
- if (backend.eslint === "degraded-unrecognized") manual.push("ESLint boundaries: your config was not recognized \u2014 merge the constraints shown above yourself");
212
- if (backend.tsconfigPaths === "unrecognized") {
213
- manual.push(`tsconfig.base.json: could not be parsed \u2014 add the ${backend.sharedTypesPackage ?? "shared-types"} path yourself`);
214
- }
215
- const linkedByPaths = backend.tsconfigPaths === "added" || backend.tsconfigPaths === "present";
216
- if (backend.workspaceGlob === "unrecognized" && !linkedByPaths) {
217
- const registry = packageManagerCommands(backend.packageManager ?? "pnpm").workspaceRegistration;
218
- manual.push(`${registry}: shape not recognized \u2014 add '${backend.sharedTypesRoot ?? "libs/shared-types"}' to its workspace list yourself`);
219
- }
220
- break;
221
- }
222
- }
223
- }
224
- return { kept, manual };
225
- }
226
- function renderLeftForYou(left) {
227
- const lines = [];
228
- if (left.kept.length > 0) {
229
- lines.push("", "Skipped to keep your changes:", ...left.kept.map((item) => ` ${item}`));
230
- }
231
- if (left.manual.length > 0) {
232
- lines.push("", "Needs a manual step:", ...left.manual.map((item) => ` ${item}`));
233
- }
234
- return lines;
235
- }
236
-
237
- // src/generators/init/lint-inputs.ts
238
- import { getProjects } from "@nx/devkit";
239
- import { parse } from "jsonc-parser";
240
- var ESLINT_PLUGIN = "@nx/eslint/plugin";
241
- var ESLINT_EXECUTOR = "@nx/eslint:lint";
242
- var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
243
- function applyLintInputs(tree, input) {
244
- const raw = tree.read("nx.json", "utf-8");
245
- if (raw === null) return void 0;
246
- const nxJson = parse(raw, [], { allowTrailingComma: true });
247
- if (!isObject(nxJson)) return void 0;
248
- const plugins = Array.isArray(nxJson["plugins"]) ? nxJson["plugins"] : [];
249
- const plugin = plugins.find((entry) => entry === ESLINT_PLUGIN || isObject(entry) && entry["plugin"] === ESLINT_PLUGIN);
250
- const options = isObject(plugin) && isObject(plugin["options"]) ? plugin["options"] : {};
251
- const target = typeof options["targetName"] === "string" ? options["targetName"] : "lint";
252
- const targetDefaults = isObject(nxJson["targetDefaults"]) ? nxJson["targetDefaults"] : {};
253
- const namedInputs = isObject(nxJson["namedInputs"]) ? nxJson["namedInputs"] : {};
254
- const defaultsKey = [target, ESLINT_EXECUTOR].find((key) => isObject(targetDefaults[key]) && Array.isArray(targetDefaults[key]["inputs"]));
255
- const defaultsInputs = defaultsKey === void 0 ? void 0 : targetDefaults[defaultsKey]["inputs"];
256
- const carries = (inputs) => inputs.some((entry) => {
257
- if (entry === TOOLKIT_CONFIG_INPUT) return true;
258
- const named = typeof entry === "string" ? namedInputs[entry.replace(/^\^/, "")] : void 0;
259
- return Array.isArray(named) && named.includes(TOOLKIT_CONFIG_INPUT);
260
- });
261
- if (defaultsInputs !== void 0 && carries(defaultsInputs)) return { action: "present", target };
262
- const projects = getProjects(tree);
263
- const ownTarget = (name) => {
264
- const project = projects.get(name);
265
- if (project === void 0) return void 0;
266
- if (isObject(project.targets?.[target])) return { file: projectFile(tree, project.root), inputs: project.targets?.[target]?.inputs };
267
- const pkg = readJson(tree, `${prefix(project.root)}package.json`);
268
- if (isObject(pkg) && isObject(pkg["scripts"]) && typeof pkg["scripts"][target] === "string") return { file: `${prefix(project.root)}package.json`, inputs: void 0 };
269
- return void 0;
270
- };
271
- const ownTargets = [...projects.keys()].filter((name) => ownTarget(name) !== void 0).sort();
272
- const reason = !input.firstRun ? "not-first-run" : plugin === void 0 ? "no-plugin" : ownTargets.length > 0 ? "own-targets" : defaultsInputs !== void 0 ? "existing-inputs" : void 0;
273
- if (reason === void 0) {
274
- if (!input.dryRun) tree.write("nx.json", applyJsonEdits(raw, [[["targetDefaults", target, "inputs"], ["...", TOOLKIT_CONFIG_INPUT]]]));
275
- return { action: "added", target };
276
- }
277
- const fsdProjects = input.fsdProjects.filter((name) => prefix(projects.get(name)?.root ?? "") !== "");
278
- const snippet = reason === "existing-inputs" && defaultsKey !== void 0 ? [`Add "${TOOLKIT_CONFIG_INPUT}" to targetDefaults["${defaultsKey}"].inputs in nx.json.`] : plugin !== void 0 && ownTargets.length === 0 ? lintInputsTargetDefaultsSnippet(target) : fsdProjects.flatMap((name) => {
279
- const root = projects.get(name)?.root ?? "";
280
- const own = ownTarget(name);
281
- return lintInputsProjectSnippet({
282
- file: own?.file ?? projectFile(tree, root),
283
- target,
284
- ownInputs: own?.inputs !== void 0,
285
- eslintConfigs: eslintConfigs(tree, root)
286
- });
287
- });
288
- return {
289
- action: "snippet",
290
- target,
291
- reason,
292
- ...reason === "own-targets" ? { ownTargets } : {},
293
- snippet,
294
- skipCache: fsdProjects.map((name) => `${input.runNx} ${target} ${name} --skip-nx-cache`)
295
- };
296
- }
297
- function prefix(root) {
298
- return root === "" || root === "." ? "" : `${root}/`;
299
- }
300
- function readJson(tree, path) {
301
- const raw = tree.read(path, "utf-8");
302
- return raw === null ? null : parse(raw, [], { allowTrailingComma: true });
303
- }
304
- function projectFile(tree, root) {
305
- return tree.exists(`${prefix(root)}project.json`) ? `${prefix(root)}project.json` : `${prefix(root)}package.json`;
306
- }
307
- function eslintConfigs(tree, root) {
308
- const own = ESLINT_CONFIG_CANDIDATES.find((name) => tree.exists(`${prefix(root)}${name}`));
309
- const workspace = ESLINT_CONFIG_CANDIDATES.find((name) => tree.exists(name));
310
- return [...own === void 0 || prefix(root) === "" ? [] : [`{projectRoot}/${own}`], ...workspace === void 0 ? [] : [`{workspaceRoot}/${workspace}`]];
311
- }
312
-
313
- // src/generators/init/render.ts
314
- var SECTION_TITLES = {
315
- fsd: "add-fsd-lite",
316
- agentRules: "add-agent-rules",
317
- githubTemplates: "add-github-templates",
318
- review: "add-review",
319
- backend: "add-backend"
320
- };
321
- function renderSectionReport(report) {
322
- switch (report.kind) {
323
- case "fsd":
324
- return renderAddFsdLiteReport(report.report);
325
- case "agentRules":
326
- return renderAddAgentRulesReport(report.report);
327
- case "githubTemplates":
328
- return renderAddGithubTemplatesReport(report.report);
329
- case "review":
330
- return renderAddReviewReport(report.report);
331
- case "backend":
332
- return renderAddBackendBody(report.report);
333
- }
334
- }
335
- function sectionAborted(section) {
336
- if (section.thrownError !== void 0) return true;
337
- if (section.report === null) return false;
338
- if (section.report.kind === "fsd") return section.report.report.aborted;
339
- if (section.report.kind === "review") return section.report.report.workflowAction === "aborted";
340
- if (section.report.kind === "backend") return section.report.report.refused !== void 0;
341
- return false;
342
- }
343
- function failedSections(report) {
344
- const failed = report.sections.filter(sectionAborted).map((section) => SECTION_TITLES[section.id]);
345
- return report.config?.action === "unrecognized" ? [...failed, "toolkit.config.json"] : failed;
346
- }
347
- function renderInitReport(report) {
348
- const lines = [];
349
- const backendSuffix = report.backend === "none" ? "" : `, backend: ${report.backend}`;
350
- const header = `init (preset: ${report.preset}, frontend: ${report.frontend}${backendSuffix})`;
351
- lines.push(report.dryRun ? `${header} \u2014 dry run` : header);
352
- if (report.preset === "solo") {
353
- lines.push("Note: solo is now an alias of quick-start \u2014 AI PR review stays off unless you pass --review.");
354
- }
355
- if (report.refused) {
356
- lines.push("", ...renderRefusal(report.dirtyFiles));
357
- return lines.join("\n");
358
- }
359
- for (const section of report.sections) {
360
- if (section.id === "backend" && !section.enabled) continue;
361
- lines.push("");
362
- lines.push(`## ${SECTION_TITLES[section.id]}`);
363
- if (!section.enabled) {
364
- lines.push(
365
- section.id === "fsd" && report.frontend === "none" ? " skipped (backend-only workspace \u2014 no frontend to structure)" : " skipped (disabled for this run)"
366
- );
367
- if (section.keptFiles !== void 0 && section.keptFiles.length > 0) {
368
- lines.push(` Kept as they are: ${section.keptFiles.join(", ")}. To update them, run add-review.`);
369
- }
370
- continue;
371
- }
372
- if (section.thrownError !== void 0) {
373
- lines.push(` aborted \u2014 unexpected error: ${section.thrownError}`);
374
- lines.push(" Nothing was written for this section. Rerun add-fsd-lite directly once resolved.");
375
- continue;
376
- }
377
- if (section.report !== null) {
378
- lines.push(renderSectionReport(section.report));
379
- }
380
- }
381
- if (report.config !== void 0 && (report.config.action !== "skipped" || report.config.notRecorded.length > 0)) {
382
- lines.push("");
383
- lines.push("## toolkit.config.json");
384
- const fieldList = report.config.fields.join(", ");
385
- switch (report.config.action) {
386
- case "created":
387
- case "updated":
388
- lines.push(` ${report.dryRun ? "would record" : "recorded"} ${fieldList} (${report.config.action})`);
389
- break;
390
- case "unchanged":
391
- lines.push(` already records ${fieldList} (unchanged)`);
392
- break;
393
- case "unrecognized":
394
- lines.push(` aborted \u2014 the file is not a JSON object, so init left it alone (it never rewrites a shape it`);
395
- lines.push(` does not recognize) and could not record ${fieldList}. The generators you run next read`);
396
- lines.push(" them from here: make the file a JSON object (or delete it), then rerun init.");
397
- break;
398
- case "skipped":
399
- break;
400
- }
401
- if (report.config.notRecorded.length > 0) {
402
- lines.push(` not recorded: ${report.config.notRecorded.map((n) => n.field).join(", ")} \u2014 that section did not apply cleanly`);
403
- lines.push(" this run (aborted, or written as an alternate file). Once resolved, record it with:");
404
- const runNx = report.runNx ?? runNxCommand(report.packageManager);
405
- for (const entry of report.config.notRecorded) lines.push(` ${runNx} g @clearlydev/nx-archweave:${entry.rerun}`);
406
- }
407
- }
408
- if (report.lintInputs !== void 0) lines.push("", "## nx.json", ...renderLintInputs(report.lintInputs, report.dryRun));
409
- const ranDirty = report.allowDirty === true && !report.cleanTree && !report.dryRun;
410
- if (ranDirty && report.dirtyFromCaller !== true) {
411
- lines.push("");
412
- lines.push("Note: --allowDirty was set and the working tree already had uncommitted changes \u2014");
413
- lines.push("restoring the files this run modified also reverts your earlier changes to them.");
414
- }
415
- const hadAbort = failedSections(report).length > 0;
416
- if (!report.dryRun && hadAbort) {
417
- lines.push("");
418
- lines.push("One or more sections aborted. To undo what this run wrote:");
419
- const written = report.written ?? { created: [], modified: [] };
420
- if (written.modified.length > 0) {
421
- lines.push(` git restore -- ${written.modified.join(" ")}`);
422
- if (ranDirty) lines.push(" (--allowDirty: this also reverts the uncommitted changes those files already had.)");
423
- }
424
- if (written.created.length > 0) {
425
- lines.push(" Created by this run (untracked \u2014 delete them yourself; `git clean -n` lists them):");
426
- for (const path of written.created) lines.push(` ${path}`);
427
- }
428
- }
429
- lines.push(...renderLeftForYou(leftForYou(report)));
430
- return lines.join("\n");
431
- }
432
- function renderLintInputs(outcome, dryRun) {
433
- if (outcome.action === "present") return [` ${outcome.target} inputs already include toolkit.config.json`];
434
- if (outcome.action === "added") {
435
- return [
436
- ` ${dryRun ? "would add" : "added"} "{workspaceRoot}/toolkit.config.json" to targetDefaults.${outcome.target}.inputs, after "..." (which keeps`,
437
- " the inputs @nx/eslint/plugin infers), so Nx re-runs lint after a change to the fsd policy"
438
- ];
439
- }
440
- const reason = {
441
- "not-first-run": "init writes nx.json only when it sets a workspace up for the first time",
442
- "no-plugin": "@nx/eslint/plugin is not registered, so targetDefaults would replace the lint targets' inputs",
443
- "own-targets": `${(outcome.ownTargets ?? []).join(", ")} write their own ${outcome.target} target, which keeps only what targetDefaults lists`,
444
- "existing-inputs": `targetDefaults already gives ${outcome.target} inputs of its own`
445
- }[outcome.reason ?? "not-first-run"];
446
- return [
447
- " toolkit.config.json is not among lint's inputs, so Nx can replay a cached lint result after a change to the",
448
- ` fsd policy. Not written \u2014 ${reason}.`,
449
- ...(outcome.snippet ?? []).map((line) => ` ${line}`),
450
- ...(outcome.skipCache ?? []).length > 0 ? [` Or, after changing the fsd policy, check with: ${(outcome.skipCache ?? []).join(", ")}`] : []
451
- ];
452
- }
453
- var SHOWN_DIRTY_FILES = 20;
454
- var LOCKFILES = /* @__PURE__ */ new Set(["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock", "bun.lockb"]);
455
- function renderRefusal(dirtyFiles) {
456
- const lines = ["Refused: the working tree has uncommitted changes."];
457
- lines.push(" init only runs against a clean working tree, so a partial run can be rolled back exactly");
458
- if (dirtyFiles === void 0 || dirtyFiles.length === 0) {
459
- lines.push(" to what was committed \u2014 commit or stash your changes, then rerun.");
460
- } else {
461
- lines.push(" to what was committed. Uncommitted:");
462
- for (const path of dirtyFiles.slice(0, SHOWN_DIRTY_FILES)) lines.push(` ${path}`);
463
- if (dirtyFiles.length > SHOWN_DIRTY_FILES) lines.push(` \u2026 and ${dirtyFiles.length - SHOWN_DIRTY_FILES} more`);
464
- const pluginInstall = dirtyFiles.includes("package.json") && dirtyFiles.every((path) => path === "package.json" || LOCKFILES.has(path));
465
- if (pluginInstall) {
466
- lines.push(" These are the plugin install. Commit them, then rerun init:");
467
- lines.push(` git add ${dirtyFiles.join(" ")} && git commit -m "chore: add @clearlydev/nx-archweave"`);
468
- } else {
469
- lines.push(" Check them with `git status`, then commit or stash them, and rerun init.");
470
- }
471
- }
472
- lines.push(" Or pass --allowDirty to run anyway: restoring a file this run modifies then also reverts");
473
- lines.push(" the changes you had made to it.");
474
- return lines;
475
- }
476
-
477
154
  // src/generators/init/validation.ts
478
155
  import { spawnSync } from "node:child_process";
479
156
  function createProcessExec() {
@@ -546,15 +223,15 @@ function recordPresetChoices(tree, choices, notRecorded, write) {
546
223
  const { raw, parsed } = readToolkitConfigFile(tree);
547
224
  if (raw !== null && parsed === null) return { action: "unrecognized", fields, notRecorded };
548
225
  const existing = parsed ?? {};
549
- const isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
226
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
550
227
  const edits = [];
551
228
  for (const key of topLevel) {
552
229
  if (existing[key] !== choices[key]) edits.push([[key], choices[key]]);
553
230
  }
554
231
  const nested = (parent, key, value) => {
555
232
  const holder = existing[parent];
556
- if (isObject2(holder) && holder[key] === value) return;
557
- edits.push(isObject2(holder) ? [[parent, key], value] : [[parent], { [key]: value }]);
233
+ if (isObject(holder) && holder[key] === value) return;
234
+ edits.push(isObject(holder) ? [[parent, key], value] : [[parent], { [key]: value }]);
558
235
  };
559
236
  if (choices.enforcement !== void 0) nested("fsd", "enforcement", choices.enforcement);
560
237
  if (choices.teamRules !== void 0) nested("agentRules", "teamRules", choices.teamRules);
@@ -602,14 +279,14 @@ function runInit(tree, options, deps) {
602
279
  const recorded = readToolkitConfigFile(tree).parsed;
603
280
  const preset = options.preset ?? recordedChoice(recorded, "preset", RECORDED_PRESETS);
604
281
  if (preset === void 0) {
605
- throw new Error("init: pass --preset=quick-start|solo|team (toolkit.config.json records none).");
282
+ throw messageOnlyError("init: pass --preset=quick-start|solo|team (toolkit.config.json records none).");
606
283
  }
607
284
  const app = options.frontend === void 0 && recordedChoice(recorded, "frontend", RECORDED_FRONTENDS) === void 0 ? resolveFrontendApp(tree, void 0) : null;
608
285
  const detected = app?.kind === "found" && app.framework !== "generic" ? app.framework : void 0;
609
286
  const frontend = resolveInitFrontend(options.frontend ?? detected, recorded);
610
287
  const backend = options.backend ?? recordedChoice(recorded, "backend", RECORDED_BACKENDS) ?? "none";
611
288
  if (frontend === "none" && backend === "none") {
612
- throw new Error("init: --frontend=none is a backend-only workspace \u2014 pass --backend=express|nest.");
289
+ throw messageOnlyError("init: --frontend=none is a backend-only workspace \u2014 pass --backend=express|nest.");
613
290
  }
614
291
  const dryRun = options.dryRun ?? false;
615
292
  const locale = resolveLocaleOption(options.locale, recorded);
@@ -820,11 +497,6 @@ function initFailure(report, strict) {
820
497
  const count = left.kept.length + left.manual.length;
821
498
  return count === 0 ? null : `init --strict: init couldn't do everything you asked for (${count} ${count === 1 ? "item" : "items"}) \u2014 see the report above.`;
822
499
  }
823
- function reportedFailure(message) {
824
- const error = new Error(message);
825
- error.stack = "";
826
- return error;
827
- }
828
500
  function collectWrittenWorkflowPaths(report) {
829
501
  const paths = [];
830
502
  for (const section of report.sections) {
@@ -841,7 +513,7 @@ async function initGenerator(tree, options, deps = { workingTreeChanges: gitWork
841
513
  const report = runInit(tree, { ...options, dryRun: resolveDryRun(options) }, deps);
842
514
  console.log(renderInitReport(report));
843
515
  const message = initFailure(report, options.strict === true);
844
- const failure = message === null ? null : reportedFailure(message);
516
+ const failure = message === null ? null : messageOnlyError(message);
845
517
  if (failure !== null && (report.dryRun || report.refused)) throw failure;
846
518
  if (report.dryRun || report.refused) return;
847
519
  const wrote = tree.listChanges().length !== changesBefore;