@clearlydev/nx-archweave 0.6.1 → 0.7.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 (53) hide show
  1. package/README.md +34 -3
  2. package/dist/eslint/index.js +1 -1
  3. package/dist/generators/_chunks/{chunk-MQNQJOWA.js → chunk-22FVJUNE.js} +4 -2
  4. package/dist/generators/_chunks/{chunk-CH5AF5S2.js → chunk-2ADC6RKP.js} +1 -1
  5. package/dist/generators/_chunks/{chunk-2K4JADTK.js → chunk-6PKKKQMD.js} +46 -3
  6. package/dist/generators/_chunks/chunk-72D3GWHO.js +269 -0
  7. package/dist/generators/_chunks/{chunk-2TQWFUMC.js → chunk-736LFDT4.js} +21 -1
  8. package/dist/generators/_chunks/{chunk-D7J7HTND.js → chunk-7RTT5NBN.js} +4 -4
  9. package/dist/generators/_chunks/chunk-AOKTOS3U.js +294 -0
  10. package/dist/generators/_chunks/chunk-B6RBCUIL.js +325 -0
  11. package/dist/generators/_chunks/{chunk-XZM354ZH.js → chunk-CHZPA6OE.js} +5 -3
  12. package/dist/generators/_chunks/{chunk-UAPIAMRL.js → chunk-DAXD47YO.js} +1 -1
  13. package/dist/generators/_chunks/chunk-GN76UMTK.js +28 -0
  14. package/dist/generators/_chunks/{chunk-L52OUT5T.js → chunk-J24X4EOB.js} +1 -1
  15. package/dist/generators/_chunks/{chunk-EHYC6FUR.js → chunk-JSHZ6VSW.js} +1 -1
  16. package/dist/generators/_chunks/chunk-KNVBFTH4.js +64 -0
  17. package/dist/generators/_chunks/chunk-MF75SQM6.js +98 -0
  18. package/dist/generators/_chunks/chunk-N6SPEKJB.js +106 -0
  19. package/dist/generators/_chunks/chunk-OX7W4SJ2.js +214 -0
  20. package/dist/generators/_chunks/chunk-R2VEJGNP.js +84 -0
  21. package/dist/generators/_chunks/chunk-SBOQHME6.js +140 -0
  22. package/dist/generators/_chunks/{chunk-WD2HL2RE.js → chunk-STGNMZLM.js} +1 -1
  23. package/dist/generators/_chunks/{chunk-XXXON43Z.js → chunk-SZRBDQCU.js} +4 -51
  24. package/dist/generators/_chunks/{chunk-LKXSS5E2.js → chunk-W2BBF5MS.js} +3 -86
  25. package/dist/generators/add-agent-rules/generator.js +2 -2
  26. package/dist/generators/add-backend/generator.js +2 -2
  27. package/dist/generators/add-fsd-lite/generator.js +7 -5
  28. package/dist/generators/add-github-templates/generator.js +2 -2
  29. package/dist/generators/add-integration/generator.js +2 -2
  30. package/dist/generators/add-review/generator.js +2 -2
  31. package/dist/generators/add-storybook/files/example/button/button.stories.tsx.template +13 -0
  32. package/dist/generators/add-storybook/files/example/button/button.tsx.template +7 -0
  33. package/dist/generators/add-storybook/files/example/index.ts.template +1 -0
  34. package/dist/generators/add-storybook/files/library/tailwind.css.template +2 -0
  35. package/dist/generators/add-storybook/generator.js +28 -0
  36. package/dist/generators/add-tailwind/files/next/postcss.config.mjs.template +7 -0
  37. package/dist/generators/add-tailwind/files/react-vite/index.css.template +2 -0
  38. package/dist/generators/add-tailwind/generator.js +26 -0
  39. package/dist/generators/allow-builds/generator.js +7 -207
  40. package/dist/generators/doctor/generator.js +388 -29
  41. package/dist/generators/entity/generator.js +4 -3
  42. package/dist/generators/feature/generator.js +4 -3
  43. package/dist/generators/init/generator.js +49 -10
  44. package/dist/generators/install-integration/generator.js +2 -2
  45. package/dist/generators/page/generator.js +4 -3
  46. package/dist/generators/shared/generator.js +4 -3
  47. package/dist/generators/widget/generator.js +4 -3
  48. package/dist/migrations/update-0.5.3/add-toolkit-config-lint-input.js +7 -3
  49. package/generators.json +10 -0
  50. package/package.json +1 -1
  51. package/src/generators/add-storybook/schema.json +33 -0
  52. package/src/generators/add-tailwind/schema.json +18 -0
  53. package/src/generators/init/schema.json +8 -0
@@ -0,0 +1,28 @@
1
+ // src/generators/shared/tool-target-report.ts
2
+ function toolTargetRefusalLines(refusal, generator) {
3
+ switch (refusal.reason) {
4
+ case "project-not-found":
5
+ return [` --project=${refusal.project} names no project in this workspace.`];
6
+ case "ambiguous-frontend":
7
+ return [" More than one frontend app \u2014 rerun with --project=<one of them>:", ...refusal.candidates.map((name) => ` - ${name}`)];
8
+ case "no-frontend-app":
9
+ return refusal.otherProjects.length > 0 ? [" No project was recognised as a frontend app. If one of these is it, rerun with --project=<name>:", ...refusal.otherProjects.map((name) => ` - ${name}`)] : [" The workspace has no frontend app \u2014 create one (nx g @nx/react:app or nx g @nx/next:app), then rerun."];
10
+ case "invalid-project-json":
11
+ return [` A project.json could not be parsed (${refusal.detail}) \u2014 fix it, then rerun.`];
12
+ case "not-a-frontend":
13
+ return [
14
+ ` ${refusal.project} is not a frontend app (a backend, a library, or not in toolkit.config.json's frontends).`,
15
+ ...refusal.recordedFrontends.length > 0 ? [" The frontend apps recorded in toolkit.config.json:", ...refusal.recordedFrontends.map((name) => ` - ${name}`)] : []
16
+ ];
17
+ case "unsupported-framework":
18
+ return [` ${refusal.project} is a ${refusal.framework} app; ${generator} supports React (Vite) and Next.js apps.`];
19
+ case "unsupported-library":
20
+ return [` ${refusal.project}'s Storybook uses ${refusal.framework}; ${generator} supports React (Vite) libraries only.`];
21
+ case "backend-library":
22
+ return [` ${refusal.project} is a backend library; ${generator} takes frontend apps and React (Vite) libraries.`];
23
+ }
24
+ }
25
+
26
+ export {
27
+ toolTargetRefusalLines
28
+ };
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  readToolkitConfig,
16
16
  resolveLocaleOption
17
- } from "./chunk-2TQWFUMC.js";
17
+ } from "./chunk-736LFDT4.js";
18
18
 
19
19
  // src/generators/add-github-templates/generator.ts
20
20
  import { join } from "node:path";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TOOLKIT_CONFIG_PATH,
3
3
  workspacePackageManager
4
- } from "./chunk-2TQWFUMC.js";
4
+ } from "./chunk-736LFDT4.js";
5
5
  import {
6
6
  runNxCommand
7
7
  } from "./chunk-5Z7VZPES.js";
@@ -0,0 +1,64 @@
1
+ import {
2
+ maskComments
3
+ } from "./chunk-6ZTIUBB2.js";
4
+
5
+ // ../template-engine/dist/lib/eslint-config-array.js
6
+ var EXPORT_DEFAULT_ARRAY = /export\s+default\s+\[/g;
7
+ var IMPORT_STATEMENT = /^import\b[^;]*?\bfrom\s+['"][^'"]+['"]\s*;?[ \t]*$/gm;
8
+ var CLOSING_BRACKET = /\]\s*;?\s*$/;
9
+ function closingBracketOf(masked, open) {
10
+ let depth = 0;
11
+ for (let i = open; i < masked.length; i++) {
12
+ const ch = masked[i];
13
+ if (ch === '"' || ch === "'" || ch === "`") {
14
+ for (i++; i < masked.length && masked[i] !== ch; i++)
15
+ if (masked[i] === "\\")
16
+ i++;
17
+ continue;
18
+ }
19
+ if (ch === "[")
20
+ depth++;
21
+ else if (ch === "]" && --depth === 0)
22
+ return i;
23
+ }
24
+ return -1;
25
+ }
26
+ function namedConfigArrayEnd(masked) {
27
+ const exported = [...masked.matchAll(/export\s+default\s+([A-Za-z_$][\w$]*)\s*;?/g)];
28
+ if (exported.length !== 1)
29
+ return -1;
30
+ const declaration = new RegExp(`(?:const|let|var)\\s+${exported[0][1].replace(/\$/g, "\\$")}\\s*=\\s*(?:defineConfig\\s*\\(\\s*)?\\[`).exec(masked);
31
+ if (declaration === null)
32
+ return -1;
33
+ return closingBracketOf(masked, declaration.index + declaration[0].length - 1);
34
+ }
35
+ function insertConfigEntries(configText, imports, entries) {
36
+ const masked = maskComments(configText);
37
+ EXPORT_DEFAULT_ARRAY.lastIndex = 0;
38
+ const exportMatches = masked.match(EXPORT_DEFAULT_ARRAY) ?? [];
39
+ const closing = CLOSING_BRACKET.exec(masked);
40
+ const closingIndex = exportMatches.length === 1 && closing !== null ? closing.index : namedConfigArrayEnd(masked);
41
+ if (closingIndex === -1)
42
+ return { status: "unrecognized" };
43
+ const eol = configText.includes("\r\n") ? "\r\n" : "\n";
44
+ const before = configText.slice(0, closingIndex);
45
+ const lastNonSpace = before.replace(/\s+$/, "");
46
+ const needsComma = entries.length > 0 && !lastNonSpace.endsWith(",") && !lastNonSpace.endsWith("[");
47
+ const entryText = entries.length === 0 ? before.slice(lastNonSpace.length) : `${needsComma ? "," : ""}${entries.map((entry) => `${eol} ${entry}`).join("")}${eol}`;
48
+ const withEntries = `${lastNonSpace}${entryText}${configText.slice(closingIndex)}`;
49
+ if (imports.length === 0)
50
+ return { status: "applied", text: withEntries };
51
+ IMPORT_STATEMENT.lastIndex = 0;
52
+ let lastImportEnd = -1;
53
+ const maskedWithEntries = maskComments(withEntries);
54
+ for (let m = IMPORT_STATEMENT.exec(maskedWithEntries); m !== null; m = IMPORT_STATEMENT.exec(maskedWithEntries)) {
55
+ lastImportEnd = m.index + m[0].length;
56
+ }
57
+ const importText = imports.join(eol);
58
+ const text = lastImportEnd === -1 ? `${importText}${eol}${eol}${withEntries}` : `${withEntries.slice(0, lastImportEnd)}${eol}${importText}${withEntries.slice(lastImportEnd)}`;
59
+ return { status: "applied", text };
60
+ }
61
+
62
+ export {
63
+ insertConfigEntries
64
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ ensurePreviewImport,
3
+ stylesheetImportLine,
4
+ tailwindEntryStylesheet
5
+ } from "./chunk-B6RBCUIL.js";
6
+ import {
7
+ isBackend,
8
+ resolveFrontendApp,
9
+ sourceRootOf
10
+ } from "./chunk-W2BBF5MS.js";
11
+ import {
12
+ resolveProjectType
13
+ } from "./chunk-TXAQ2GJC.js";
14
+ import {
15
+ readBoundaryTags
16
+ } from "./chunk-6ZTIUBB2.js";
17
+ import {
18
+ readToolkitConfig,
19
+ recordedFrontends
20
+ } from "./chunk-736LFDT4.js";
21
+
22
+ // src/generators/shared/tree-files.ts
23
+ var treeFiles = (tree) => ({
24
+ read: (path) => tree.read(path, "utf-8"),
25
+ children: (dir) => tree.children(dir),
26
+ isFile: (path) => tree.isFile(path)
27
+ });
28
+
29
+ // src/generators/shared/storybook-preview.ts
30
+ import { posix } from "node:path";
31
+ var STORYBOOK_PREVIEWS = ["preview.ts", "preview.tsx", "preview.mts", "preview.js", "preview.jsx"];
32
+ var prefixOf = (root) => root === "" || root === "." ? "" : `${root}/`;
33
+ function storybookPreviewStep(tree, app, write, options = {}) {
34
+ const storybookDir = `${prefixOf(app.root)}.storybook`;
35
+ const preview = STORYBOOK_PREVIEWS.map((name) => `${storybookDir}/${name}`).find((path) => tree.exists(path)) ?? `${storybookDir}/preview.ts`;
36
+ const stylesheet = tailwindEntryStylesheet(app, treeFiles(tree));
37
+ if (stylesheet === null || options.stylesheetMustExist && !tree.exists(stylesheet)) return { file: preview, outcome: "not-wired", reason: "no-tailwind-stylesheet", lines: [] };
38
+ const relative = posix.relative(storybookDir, stylesheet);
39
+ const spec = relative.startsWith(".") ? relative : `./${relative}`;
40
+ const text = tree.read(preview, "utf-8");
41
+ if (text === null) return { file: preview, outcome: "not-wired", reason: "no-preview", lines: [stylesheetImportLine(spec)] };
42
+ const result = ensurePreviewImport(text, spec);
43
+ if (result.status === "applied" && write) tree.write(preview, result.text);
44
+ return result.status === "unrecognized" ? { file: preview, outcome: "not-wired", reason: result.reason, lines: [stylesheetImportLine(spec)] } : { file: preview, outcome: result.status };
45
+ }
46
+
47
+ // src/generators/shared/tool-target.ts
48
+ import { getProjects } from "@nx/devkit";
49
+ var refused = (refusal) => ({ kind: "refused", refusal });
50
+ function resolveToolTarget(tree, project, options = {}) {
51
+ const config = readToolkitConfig(tree);
52
+ if (project !== void 0 && options.libraries !== void 0) {
53
+ const library = namedLibrary(tree, project, readBoundaryTags(config).backend, options.libraries);
54
+ if (library !== null) return library;
55
+ }
56
+ const recorded = recordedFrontends(config);
57
+ let wanted = project;
58
+ if (recorded.length > 0) {
59
+ if (wanted !== void 0 && !recorded.includes(wanted)) return refused({ reason: "not-a-frontend", project: wanted, recordedFrontends: recorded });
60
+ if (wanted === void 0 && recorded.length > 1) return refused({ reason: "ambiguous-frontend", candidates: recorded });
61
+ wanted ??= recorded[0];
62
+ }
63
+ const app = resolveFrontendApp(tree, wanted);
64
+ if (app.kind === "not-found") return refused({ reason: "project-not-found", project: app.project });
65
+ if (app.kind === "ambiguous") return refused({ reason: "ambiguous-frontend", candidates: app.candidates });
66
+ if (app.kind === "none") return refused({ reason: "no-frontend-app", otherProjects: app.otherProjects });
67
+ if (app.kind === "invalid-project-json") return refused({ reason: "invalid-project-json", detail: app.detail });
68
+ if (wanted !== void 0 && app.inferredRoot !== true) {
69
+ const projectConfig = getProjects(tree).get(app.project) ?? { root: app.root };
70
+ const backendTag = readBoundaryTags(config).backend;
71
+ if (isBackend(app.root, projectConfig, backendTag) || resolveProjectType(tree, app.root, projectConfig.projectType) === "library") {
72
+ return refused({ reason: "not-a-frontend", project: app.project, recordedFrontends: recorded });
73
+ }
74
+ }
75
+ if (app.framework !== "react-vite" && app.framework !== "next") {
76
+ return refused({ reason: "unsupported-framework", project: app.project, framework: app.framework });
77
+ }
78
+ return { kind: "found", project: app.project, root: app.root, sourceRoot: app.sourceRoot, framework: app.framework, projectType: "application" };
79
+ }
80
+ function namedLibrary(tree, project, backendTag, check) {
81
+ let projectConfig;
82
+ try {
83
+ projectConfig = getProjects(tree).get(project);
84
+ } catch {
85
+ return null;
86
+ }
87
+ if (projectConfig === void 0 || resolveProjectType(tree, projectConfig.root, projectConfig.projectType) !== "library") return null;
88
+ if (isBackend(projectConfig.root, projectConfig, backendTag)) return refused({ reason: "backend-library", project });
89
+ const result = check(tree, projectConfig.root);
90
+ if (typeof result === "object") return refused({ reason: "unsupported-library", project, root: projectConfig.root, framework: result.unsupported });
91
+ return { kind: "found", project, root: projectConfig.root, sourceRoot: sourceRootOf(tree, projectConfig), framework: "react-vite", projectType: "library" };
92
+ }
93
+
94
+ export {
95
+ treeFiles,
96
+ storybookPreviewStep,
97
+ resolveToolTarget
98
+ };
@@ -0,0 +1,106 @@
1
+ import {
2
+ toolTargetRefusalLines
3
+ } from "./chunk-GN76UMTK.js";
4
+ import {
5
+ INSTALL_ASSUMES_PNPM
6
+ } from "./chunk-5Z7VZPES.js";
7
+
8
+ // src/generators/add-tailwind/render.ts
9
+ var SASS_DOCS = "https://tailwindcss.com/docs/compatibility#sass-less-and-stylus";
10
+ var NOT_WIRED_REASONS = {
11
+ "no-vite-config": "no Vite config found",
12
+ "several-vite-configs": "more than one Vite config",
13
+ "no-plugins-array": "no plugins array this generator recognises",
14
+ "several-plugins-arrays": "more than one plugins array",
15
+ "no-react-plugin": "no @vitejs/plugin-react call in the plugins array",
16
+ "tailwind-import-shape": "@tailwindcss/vite is loaded some other way than import tailwindcss from \u2026",
17
+ "tailwind-call-outside-plugins": "tailwindcss() is called outside the plugins array",
18
+ "no-app-module": "no such file",
19
+ "no-imports": "a module without import statements",
20
+ "postcss-config-without-tailwind": "an existing PostCSS config \u2014 add the plugin to it yourself",
21
+ "no-root-layout": "no root layout found",
22
+ "no-css-import": "the root layout imports no local stylesheet",
23
+ "several-css-imports": "the root layout imports more than one local stylesheet",
24
+ "stylesheet-missing": "the stylesheet the root layout imports does not exist",
25
+ "no-preview": "no .storybook/preview file",
26
+ "no-tailwind-stylesheet": "the app's Tailwind stylesheet could not be found (see the lines above)"
27
+ };
28
+ function renderRefusal(refusal, lines) {
29
+ if (refusal.reason === "tailwind-v3") {
30
+ lines.push(` Tailwind CSS v3 is set up here (${refusal.evidence.join(", ")}).`);
31
+ lines.push(" Upgrade it to v4 first (npx @tailwindcss/upgrade), then rerun add-tailwind.");
32
+ } else if (refusal.reason === "sass") {
33
+ lines.push(` The app's global styles are Sass (${refusal.evidence.join(", ")}), and Tailwind CSS v4 is not designed to be used with Sass, Less or Stylus:`);
34
+ lines.push(` ${SASS_DOCS}`);
35
+ } else {
36
+ lines.push(...toolTargetRefusalLines(refusal, "add-tailwind"));
37
+ }
38
+ }
39
+ function renderStep(step, lines) {
40
+ switch (step.outcome) {
41
+ case "created":
42
+ lines.push(` ${step.file}: created`);
43
+ break;
44
+ case "applied":
45
+ lines.push(` ${step.file}: updated`);
46
+ break;
47
+ case "already-applied":
48
+ lines.push(` ${step.file}: already set up \u2014 no change`);
49
+ break;
50
+ case "not-wired":
51
+ lines.push(
52
+ ` ${step.file}: NOT changed \u2014 ${NOT_WIRED_REASONS[step.reason ?? ""] ?? step.reason}.${(step.lines ?? []).length === 0 ? "" : step.target === void 0 ? " Add this yourself:" : ` Add these lines to ${step.target}:`}`
53
+ );
54
+ for (const line of step.lines ?? []) lines.push(` ${line}`);
55
+ break;
56
+ }
57
+ }
58
+ function renderAddTailwindReport(report) {
59
+ const lines = [];
60
+ if (report.refusal !== null) {
61
+ lines.push("add-tailwind refused \u2014 nothing was written.");
62
+ renderRefusal(report.refusal, lines);
63
+ return lines.join("\n");
64
+ }
65
+ if (report.dryRun) lines.push("add-tailwind dry-run \u2014 no files were written.");
66
+ lines.push(`Tailwind CSS v4 for ${report.project} (${report.framework === "next" ? "Next.js" : "React + Vite"}):`);
67
+ if (report.handWiredStylesheet !== void 0) {
68
+ lines.push(` The app already imports Tailwind from ${report.handWiredStylesheet}, so that file was used \u2014 no app-layer stylesheet was created and the app module was left alone.`);
69
+ }
70
+ for (const step of report.steps) renderStep(step, lines);
71
+ if (report.dependencies === "added") {
72
+ lines.push(`Dependencies: added to package.json devDependencies: ${report.added.join(", ")}`);
73
+ if (report.installCommand !== null) {
74
+ lines.push(` Install them: ${report.installCommand}${report.installAssumed ? ` (${INSTALL_ASSUMES_PNPM})` : ""}`);
75
+ }
76
+ } else if (report.dependencies === "present") {
77
+ lines.push("Dependencies: already in package.json \u2014 no change");
78
+ } else if (report.dependencies === "unrecognized") {
79
+ lines.push("Dependencies: NOT added \u2014 the root package.json is not a JSON object. Add tailwindcss and its build plugin yourself.");
80
+ }
81
+ switch (report.record) {
82
+ case "created":
83
+ case "updated":
84
+ lines.push(`toolkit.config.json: recorded ${report.project} under tailwind.projects`);
85
+ break;
86
+ case "unchanged":
87
+ lines.push(`toolkit.config.json: ${report.project} already recorded \u2014 no change`);
88
+ break;
89
+ case "unrecognized":
90
+ lines.push("toolkit.config.json: not recorded \u2014 the file is not a JSON object, so doctor can't check this app's Tailwind setup. Fix the file and rerun add-tailwind.");
91
+ break;
92
+ case null:
93
+ break;
94
+ }
95
+ if (report.replacedSection) {
96
+ lines.push(' "tailwind" was not an object in toolkit.config.json; it now holds { "projects": [...] }.');
97
+ }
98
+ if (report.steps.some((step) => step.outcome === "not-wired")) {
99
+ lines.push(report.record === "unrecognized" ? "Some files were left for you (above)." : "Some files were left for you (above). The app is recorded, so doctor reports what is still missing.");
100
+ }
101
+ return lines.join("\n");
102
+ }
103
+
104
+ export {
105
+ renderAddTailwindReport
106
+ };
@@ -0,0 +1,214 @@
1
+ // ../template-engine/dist/pnpm/allow-builds.js
2
+ var PENDING_PLACEHOLDER = "set this to true or false";
3
+ function isPlainPackageName(name) {
4
+ return /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/i.test(name);
5
+ }
6
+ function allowPackageBuilds(yamlText, names, options = {}) {
7
+ const bom = yamlText.startsWith("\uFEFF") ? "\uFEFF" : "";
8
+ const body = yamlText.slice(bom.length);
9
+ const eol = body.includes("\r\n") ? "\r\n" : "\n";
10
+ const unique = [...new Set(names)];
11
+ const listIsRead = options.pnpmMajor === void 0 || options.pnpmMajor < 11;
12
+ const result = edit(body.split(/\r?\n/), eol, unique, listIsRead);
13
+ return result.status === "updated" ? { ...result, text: `${bom}${result.text}` } : result;
14
+ }
15
+ function pnpmMajorFromModulesManifest(modulesYamlText) {
16
+ const match = /^\s*["']?packageManager["']?\s*:\s*["']?pnpm@(\d+)\./m.exec(modulesYamlText);
17
+ return match ? Number(match[1]) : void 0;
18
+ }
19
+ function edit(original, eol, names, listIsRead) {
20
+ const shape = checkDocumentShape(original);
21
+ if (shape !== void 0)
22
+ return { status: "unrecognized", reason: shape };
23
+ const lines = expandFlow(original, "allowBuilds");
24
+ if (typeof lines === "string")
25
+ return { status: "unrecognized", reason: lines };
26
+ const allowBuilds = findBlock(lines, "allowBuilds");
27
+ if (typeof allowBuilds === "string")
28
+ return { status: "unrecognized", reason: allowBuilds };
29
+ if (allowBuilds)
30
+ return editAllowBuilds(lines, eol, allowBuilds, names);
31
+ if (!listIsRead)
32
+ return appendAllowBuilds(original, eol, names);
33
+ const listLines = expandFlow(original, "onlyBuiltDependencies");
34
+ if (typeof listLines === "string")
35
+ return { status: "unrecognized", reason: listLines };
36
+ const onlyBuilt = findBlock(listLines, "onlyBuiltDependencies");
37
+ if (typeof onlyBuilt === "string")
38
+ return { status: "unrecognized", reason: onlyBuilt };
39
+ if (onlyBuilt)
40
+ return editOnlyBuilt(listLines, eol, onlyBuilt, names);
41
+ return appendAllowBuilds(original, eol, names);
42
+ }
43
+ function appendAllowBuilds(original, eol, names) {
44
+ const changes = names.map((name) => ({ name, previous: "absent" }));
45
+ const entries = names.map((name) => ` ${yamlPackageKey(name)}: true`);
46
+ const head = original[original.length - 1] === "" ? original.slice(0, -1) : original;
47
+ return { status: "updated", target: "allowBuilds", changes, text: [...head, "allowBuilds:", ...entries, ""].join(eol) };
48
+ }
49
+ function editAllowBuilds(lines, eol, block, names) {
50
+ const entries = [];
51
+ for (const index of block.entries) {
52
+ const match = /^(\s+)('([^']*)'|"([^"]*)"|([^\s'"#-]\S*?)):(?:\s+(.*))?$/.exec(lines[index]);
53
+ if (!match)
54
+ return { status: "unrecognized", reason: 'allowBuilds holds something other than "<package>: <value>" entries' };
55
+ entries.push({ index, indent: match[1], rawKey: match[2], key: match[3] ?? match[4] ?? match[5], ...splitValue(match[6] ?? "") });
56
+ }
57
+ const indent = entries[0]?.indent ?? " ";
58
+ for (const name of names) {
59
+ if (entries.filter((entry) => entry.key === name).length > 1)
60
+ return { status: "unrecognized", reason: `allowBuilds lists ${name} more than once` };
61
+ const versioned = entries.find((entry) => entry.key.startsWith(`${name}@`) && classify(entry.value) !== "allowed");
62
+ if (versioned)
63
+ return { status: "unrecognized", reason: `allowBuilds has a version-specific entry for ${name} (${versioned.key}) that is not true` };
64
+ }
65
+ const next = [...lines];
66
+ const appended = [];
67
+ const changes = names.map((name) => {
68
+ const entry = entries.find((candidate) => candidate.key === name);
69
+ if (!entry) {
70
+ appended.push(`${indent}${yamlPackageKey(name)}: true`);
71
+ return { name, previous: "absent" };
72
+ }
73
+ const previous = classify(entry.value);
74
+ if (previous !== "allowed")
75
+ next[entry.index] = `${entry.indent}${entry.rawKey}: true${entry.comment ? ` ${entry.comment}` : ""}`;
76
+ return { name, previous };
77
+ });
78
+ if (changes.every((change) => change.previous === "allowed"))
79
+ return { status: "unchanged", target: "allowBuilds", changes };
80
+ next.splice(insertionPoint(block), 0, ...appended);
81
+ return { status: "updated", target: "allowBuilds", changes, text: next.join(eol) };
82
+ }
83
+ function editOnlyBuilt(lines, eol, block, names) {
84
+ const listed = /* @__PURE__ */ new Set();
85
+ for (const index of block.entries) {
86
+ const item = /^\s+-\s+(?:'([^']*)'|"([^"]*)"|([^\s#'"][^#]*?))\s*(?:#.*)?$/.exec(lines[index]);
87
+ const value = item ? item[1] ?? item[2] ?? item[3] : void 0;
88
+ if (value === void 0 || item?.[3] !== void 0 && /:(\s|$)/.test(value)) {
89
+ return { status: "unrecognized", reason: 'onlyBuiltDependencies holds something other than "- <package>" items' };
90
+ }
91
+ listed.add(value);
92
+ }
93
+ const indent = block.entries.length > 0 ? leadingSpace(lines[block.entries[0]]) : " ";
94
+ const changes = names.map((name) => ({ name, previous: listed.has(name) ? "allowed" : "absent" }));
95
+ if (changes.every((change) => change.previous === "allowed")) {
96
+ return { status: "unchanged", target: "onlyBuiltDependencies", changes };
97
+ }
98
+ const next = [...lines];
99
+ const appended = changes.filter((change) => change.previous === "absent").map((change) => `${indent}- ${yamlPackageKey(change.name)}`);
100
+ next.splice(insertionPoint(block), 0, ...appended);
101
+ return { status: "updated", target: "onlyBuiltDependencies", changes, text: next.join(eol) };
102
+ }
103
+ function checkDocumentShape(lines) {
104
+ const content = lines.filter((line) => line.trim() !== "" && !/^\s*#/.test(line));
105
+ if (content.some((line) => /^(---|\.\.\.)(\s|$)/.test(line)))
106
+ return "the file has YAML document markers (--- / ...)";
107
+ const first = content[0];
108
+ if (first !== void 0 && !/^(?:'[^']*'|"[^"]*"|[^\s#'"?{[\]-][^:]*?)\s*:(?:\s|$)/.test(first)) {
109
+ return "the file is not a plain mapping with its keys at column 0";
110
+ }
111
+ return void 0;
112
+ }
113
+ function expandFlow(lines, key) {
114
+ const keyLine = topLevelKeyLine(key);
115
+ const index = lines.findIndex((line) => keyLine.test(line));
116
+ if (index === -1)
117
+ return lines;
118
+ const match = /^(.*?:)\s*([{[])(.*)([}\]])\s*(#.*)?$/.exec(lines[index]);
119
+ if (!match)
120
+ return lines;
121
+ const [, head, open, inner, close, comment] = match;
122
+ const isMap = key === "allowBuilds";
123
+ if (isMap && (open !== "{" || close !== "}") || !isMap && (open !== "[" || close !== "]")) {
124
+ return `${key} is a flow collection of the wrong kind`;
125
+ }
126
+ const items = inner.trim() === "" ? [] : inner.split(",").map((item) => item.trim());
127
+ const valid = isMap ? (item) => /^(?:'[^']*'|"[^"]*"|[^\s'"#-]\S*?):\s+[^{}[\],]+$/.test(item) : (item) => /^(?:'[^']*'|"[^"]*"|[^\s'"#{}[\],:-][^{}[\],:]*)$/.test(item);
128
+ if (items.some((item) => !valid(item)))
129
+ return `${key} is a flow collection this parser does not split`;
130
+ const block = items.map((item) => isMap ? ` ${item}` : ` - ${item}`);
131
+ return [...lines.slice(0, index), `${head}${comment ? ` ${comment}` : ""}`, ...block, ...lines.slice(index + 1)];
132
+ }
133
+ function topLevelKeyLine(key) {
134
+ return new RegExp(`^(['"]?)${key}\\1\\s*:(.*)$`);
135
+ }
136
+ function findBlock(lines, key) {
137
+ const keyLine = topLevelKeyLine(key);
138
+ const keyIndices = lines.flatMap((line, index) => keyLine.test(line) ? [index] : []);
139
+ const mentions = lines.filter((line) => !/^\s*#/.test(line) && new RegExp(`\\b${key}\\b`).test(line));
140
+ if (mentions.length > keyIndices.length)
141
+ return `${key} appears somewhere other than a top-level key`;
142
+ if (keyIndices.length === 0)
143
+ return void 0;
144
+ if (keyIndices.length > 1)
145
+ return `${key} appears more than once at the top level`;
146
+ const keyIndex = keyIndices[0];
147
+ const rest = (keyLine.exec(lines[keyIndex])?.[2] ?? "").replace(/\s+#.*$/, "").trim();
148
+ if (rest !== "")
149
+ return `${key} is not a block (found "${key}: ${rest}")`;
150
+ const entries = [];
151
+ for (let index = keyIndex + 1; index < lines.length; index++) {
152
+ const line = lines[index];
153
+ if (line.trim() === "" || /^\s*#/.test(line))
154
+ continue;
155
+ if (/^\S/.test(line)) {
156
+ if (line.startsWith("-"))
157
+ return `${key} uses a column-0 list`;
158
+ break;
159
+ }
160
+ entries.push(index);
161
+ }
162
+ if (entries.length > 0) {
163
+ const indent = leadingSpace(lines[entries[0]]);
164
+ if (entries.some((index) => leadingSpace(lines[index]) !== indent))
165
+ return `${key} has entries at more than one indentation`;
166
+ }
167
+ return { keyIndex, entries };
168
+ }
169
+ function insertionPoint(block) {
170
+ return (block.entries.length > 0 ? block.entries[block.entries.length - 1] : block.keyIndex) + 1;
171
+ }
172
+ function splitValue(raw) {
173
+ const match = /^('[^']*'|"[^"]*"|[^#]*?)\s*(#.*)?$/.exec(raw.trim());
174
+ return { value: match?.[1] ?? raw.trim(), comment: match?.[2] ?? "" };
175
+ }
176
+ function classify(value) {
177
+ if (/^(true|True|TRUE)$/.test(value))
178
+ return "allowed";
179
+ if (/^(false|False|FALSE)$/.test(value))
180
+ return "denied";
181
+ const unquoted = /^(['"])(.*)\1$/.exec(value)?.[2] ?? value;
182
+ if (unquoted === PENDING_PLACEHOLDER)
183
+ return "pending";
184
+ return "other";
185
+ }
186
+ function yamlPackageKey(name) {
187
+ return /^[a-z][a-z0-9._~-]*$/i.test(name) && !/^(true|false|null|yes|no|on|off|y|n)$/i.test(name) ? name : `'${name}'`;
188
+ }
189
+ function leadingSpace(line) {
190
+ return /^(\s*)/.exec(line)?.[1] ?? "";
191
+ }
192
+ function escapeRegExp(text) {
193
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
194
+ }
195
+ function missingFromLockfile(lockfileText, names) {
196
+ const installed = [];
197
+ let section = "";
198
+ for (const line of lockfileText.split(/\r?\n/)) {
199
+ if (/^\S/.test(line))
200
+ section = /^([A-Za-z]+):/.exec(line)?.[1] ?? "";
201
+ else if (section === "packages" || section === "snapshots")
202
+ installed.push(line);
203
+ }
204
+ const text = installed.join("\n");
205
+ return names.filter((name) => !new RegExp(`^ {2}(['"]?)/?${escapeRegExp(name)}@`, "m").test(text));
206
+ }
207
+
208
+ export {
209
+ isPlainPackageName,
210
+ allowPackageBuilds,
211
+ pnpmMajorFromModulesManifest,
212
+ yamlPackageKey,
213
+ missingFromLockfile
214
+ };
@@ -0,0 +1,84 @@
1
+ // ../template-engine/dist/fsd/slice-rules.js
2
+ function toCamelCase(kebabName) {
3
+ return kebabName.split("-").filter((part) => part.length > 0).map((part, index) => index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)).join("");
4
+ }
5
+ function resolveSlicePublicApiName(name, publicApiName) {
6
+ return publicApiName ?? toCamelCase(name);
7
+ }
8
+ var IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
9
+ var RESERVED_WORDS = /* @__PURE__ */ new Set([
10
+ "await",
11
+ "break",
12
+ "case",
13
+ "catch",
14
+ "class",
15
+ "const",
16
+ "continue",
17
+ "debugger",
18
+ "default",
19
+ "delete",
20
+ "do",
21
+ "else",
22
+ "enum",
23
+ "export",
24
+ "extends",
25
+ "false",
26
+ "finally",
27
+ "for",
28
+ "function",
29
+ "if",
30
+ "implements",
31
+ "import",
32
+ "in",
33
+ "instanceof",
34
+ "interface",
35
+ "let",
36
+ "new",
37
+ "null",
38
+ "package",
39
+ "private",
40
+ "protected",
41
+ "public",
42
+ "return",
43
+ "static",
44
+ "super",
45
+ "switch",
46
+ "this",
47
+ "throw",
48
+ "true",
49
+ "try",
50
+ "typeof",
51
+ "var",
52
+ "void",
53
+ "while",
54
+ "with",
55
+ "yield"
56
+ ]);
57
+ function isUsableSliceApiName(candidate) {
58
+ return IDENTIFIER_PATTERN.test(candidate) && !RESERVED_WORDS.has(candidate);
59
+ }
60
+ var ESSENCE_SEGMENT_NAMES = [
61
+ "components",
62
+ "hooks",
63
+ "helpers",
64
+ "utils",
65
+ "types",
66
+ "constants",
67
+ "consts",
68
+ "interfaces",
69
+ "enums",
70
+ "modals",
71
+ "stores",
72
+ "services"
73
+ ];
74
+ function isEssenceSegmentName(name) {
75
+ return ESSENCE_SEGMENT_NAMES.includes(name);
76
+ }
77
+ var SEGMENT_NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
78
+
79
+ export {
80
+ resolveSlicePublicApiName,
81
+ isUsableSliceApiName,
82
+ isEssenceSegmentName,
83
+ SEGMENT_NAME_PATTERN
84
+ };