@platforma-sdk/block-tools 2.10.16 → 2.10.18

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 (34) hide show
  1. package/dist/cli.js +13 -13
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +404 -373
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/structure/engine/api.d.ts +1 -1
  6. package/dist/structure/engine/builders.d.ts +9 -9
  7. package/dist/structure/engine/content-rules.d.ts +17 -0
  8. package/dist/structure/engine/registry-client.d.ts +30 -2
  9. package/dist/structure/engine/runner.d.ts +6 -0
  10. package/dist/structure/rules/root-pnpm-workspace.d.ts +13 -0
  11. package/package.json +5 -5
  12. package/src/structure/__tests__/model-package-json.snapshot.test.ts +1 -2
  13. package/src/structure/__tests__/tsconfig-idempotency.test.ts +94 -0
  14. package/src/structure/cli/run-structure.ts +12 -2
  15. package/src/structure/engine/__tests__/content-rules/pin-catalog-to-dependency-of.test.ts +65 -0
  16. package/src/structure/engine/__tests__/content-rules/when-inner.test.ts +30 -0
  17. package/src/structure/engine/__tests__/derived-pin-lookup.test.ts +54 -0
  18. package/src/structure/engine/api.ts +1 -0
  19. package/src/structure/engine/builders.ts +38 -23
  20. package/src/structure/engine/content-rules.ts +29 -0
  21. package/src/structure/engine/registry-client.ts +116 -2
  22. package/src/structure/engine/runner.ts +18 -2
  23. package/src/structure/init-block-constructor.ts +16 -3
  24. package/src/structure/rules/model-package-json.ts +35 -16
  25. package/src/structure/rules/model.ts +11 -35
  26. package/src/structure/rules/root-catalog-bump.ts +12 -1
  27. package/src/structure/rules/root-package-json.ts +7 -5
  28. package/src/structure/rules/root-pnpm-workspace.ts +24 -8
  29. package/src/structure/rules/ui-package-json.ts +34 -13
  30. package/src/structure/rules/ui.ts +10 -22
  31. package/src/structure/rules/workflow-package-json.ts +25 -11
  32. package/src/structure/rules/workflow.ts +21 -2
  33. package/src/structure/templates/static/model/tsconfig.node.json +7 -0
  34. package/src/structure/templates/static/ui/tsconfig.node.json +7 -0
@@ -13,9 +13,6 @@ import {
13
13
  blockVars,
14
14
  when,
15
15
  whenFilesExist,
16
- ensureField,
17
- removeField,
18
- pruneKeysMatching,
19
16
  } from "../engine/api";
20
17
  import { getActiveRunContext } from "../engine/builders";
21
18
  import { uiPackageJsonInitial, uiPackageJsonRules } from "./ui-package-json";
@@ -23,25 +20,16 @@ import { COLOCATED_TEST_GLOB } from "./shared/colocated-tests";
23
20
 
24
21
  export function uiRules(): void {
25
22
  scope("ui", () => {
26
- // tsconfig is managed (not fixed) so node ambient types can be provided
27
- // CONDITIONALLY. The body still enforces the canonical shape —
28
- // `{extends, include}` with NO stray keys — and, ONLY when the ui
29
- // carries co-located unit tests (`src/**/*.test.ts`), adds
30
- // `compilerOptions.types: ["node"]` so tests importing `node:*`
31
- // type-check under vue-tsc: provide node types, do NOT exclude the
32
- // tests. A test-less ui is canonicalised to
33
- // bare `{extends, include}` and stays a refresh fixpoint. The matching
34
- // `@types/node` devDep is wired by the package.json rule under the same
35
- // predicate.
36
- managed("tsconfig.json", file("ui/tsconfig.json"), () => {
37
- ensureField("extends", "@milaboratories/ts-configs/block/ui");
38
- removeField("compilerOptions");
39
- when(whenFilesExist(COLOCATED_TEST_GLOB), () => {
40
- ensureField("compilerOptions.types", ["node"]);
41
- });
42
- ensureField("include", ["src/**/*"]);
43
- pruneKeysMatching((k) => k !== "extends" && k !== "include" && k !== "compilerOptions");
44
- });
23
+ // Two static end states by co-located-test presence: a test-bearing ui gets
24
+ // node ambient types (`.node.json`) so tests' `node:*` imports type-check
25
+ // under vue-tsc — `@types/node` is wired alongside by the package.json rule;
26
+ // a test-less ui stays bare. `fixed` (engine-owned, whole-file overwrite)
27
+ // not `managed`, so refresh is idempotent by construction — no key-order drift.
28
+ when(
29
+ whenFilesExist(COLOCATED_TEST_GLOB),
30
+ () => fixed("tsconfig.json", file("ui/tsconfig.node.json")),
31
+ () => fixed("tsconfig.json", file("ui/tsconfig.json")),
32
+ );
45
33
  fixed(".oxlintrc.json", file("ui/.oxlintrc.json"));
46
34
  // Block-local oxfmt config — the ui is oxfmt-checked (`ts-builder check
47
35
  // --target block-ui`).
@@ -8,6 +8,7 @@ import {
8
8
  ensureScript,
9
9
  ensureDep,
10
10
  ensureDevDeps,
11
+ removeDep,
11
12
  ensureWorkspaceScopeDeps,
12
13
  enforceAlphabeticalOrder,
13
14
  enforceFieldOrder,
@@ -44,7 +45,8 @@ export function workflowPackageJsonInitial(ctx: RunContext): Record<string, unkn
44
45
  devDependencies: {
45
46
  "@platforma-sdk/tengo-builder": "sdk:",
46
47
  "@platforma-sdk/test": "sdk:",
47
- vitest: "catalog:",
48
+ // `vitest` is NOT seeded here — it's wired by the body rule only when the
49
+ // workflow carries co-located tests (a freshly-init'd workflow has none).
48
50
  shx: "catalog:",
49
51
  },
50
52
  };
@@ -59,15 +61,28 @@ export function workflowPackageJsonRules(): void {
59
61
  ensureScript("check", "pl-tengo check");
60
62
  // Tengo source formatter (emacs batch); no-op notice when emacs is absent.
61
63
  ensureScript("format", "/usr/bin/env emacs --script ./format.el || echo 'No emacs.'");
62
- // The vitest `test` script is wired ONLY when the workflow carries
63
- // co-located integration tests (`src/**/*.test.ts`, incl. `src/test/`).
64
- // A test-less workflow gets no `test` task and stays a refresh fixpoint.
65
- // (Workflow tests type-check via the standalone workflow/tsconfig with
66
- // `types: []` — they pull their types from `@platforma-sdk/test` — so no
67
- // node-types wiring is needed here, unlike model/ui.)
68
- when(whenFilesExist(COLOCATED_TEST_GLOB), () => {
69
- ensureScript("test", "vitest run --passWithNoTests");
70
- });
64
+ // The vitest `test` script AND the `vitest` devDep are wired ONLY when the
65
+ // workflow carries co-located integration tests (`src/**/*.test.ts`, incl.
66
+ // `src/test/`). A test-less workflow gets neither — no `test` task, no
67
+ // vitest dep — and stays a refresh fixpoint. (Workflow tests type-check via
68
+ // the standalone workflow/tsconfig with `types: []` — they pull their types
69
+ // from `@platforma-sdk/test` — so no node-types wiring is needed here,
70
+ // unlike model/ui.)
71
+ //
72
+ // Skipped entirely for sdk-internal (in-monorepo) blocks: they own their test
73
+ // wiring under the monorepo's shared infrastructure — see model-package-json.
74
+ when(
75
+ ({ ctx }) => !ctx.isSdkInternal,
76
+ () =>
77
+ when(
78
+ whenFilesExist(COLOCATED_TEST_GLOB),
79
+ () => {
80
+ ensureScript("test", "vitest run --passWithNoTests");
81
+ ensureDevDeps({ vitest: "catalog:" });
82
+ },
83
+ () => removeDep("vitest"),
84
+ ),
85
+ );
71
86
 
72
87
  ensureDep("@platforma-sdk/workflow-tengo", "sdk:");
73
88
 
@@ -80,7 +95,6 @@ export function workflowPackageJsonRules(): void {
80
95
  ensureDevDeps({
81
96
  "@platforma-sdk/tengo-builder": "sdk:",
82
97
  "@platforma-sdk/test": "sdk:",
83
- vitest: "catalog:",
84
98
  shx: "catalog:",
85
99
  });
86
100
 
@@ -11,10 +11,13 @@ import {
11
11
  tpl,
12
12
  generate,
13
13
  remove,
14
+ when,
15
+ whenFilesExist,
14
16
  blockVars,
15
17
  } from "../engine/api";
16
18
  import { getActiveRunContext } from "../engine/builders";
17
19
  import { workflowPackageJsonInitial, workflowPackageJsonRules } from "./workflow-package-json";
20
+ import { COLOCATED_TEST_GLOB } from "./shared/colocated-tests";
18
21
 
19
22
  export function workflowRules(): void {
20
23
  scope("workflow", () => {
@@ -24,8 +27,24 @@ export function workflowRules(): void {
24
27
  fixed("tsconfig.json", file("workflow/tsconfig.json"));
25
28
  // Tengo source formatter (emacs batch); the `format` script invokes it.
26
29
  fixed("format.el", file("workflow/format.el"));
27
- // scaffold (not fixed): tengo test config is author-tunable.
28
- scaffold("vitest.config.mts", file("workflow/vitest.config.mts"));
30
+ // vitest config only when the workflow carries co-located tests
31
+ // (`src/**/*.test.ts`, incl. `src/test/`) — paired with the conditional
32
+ // `vitest` devDep + `test` script in workflow-package-json. scaffold (not
33
+ // fixed): author-tunable when present; a test-less workflow gets none.
34
+ //
35
+ // Skipped entirely for sdk-internal (in-monorepo) blocks: they own their
36
+ // test config under the monorepo's shared infrastructure (e.g. a bespoke
37
+ // `vitest run --coverage` + `createVitestConfig`), which the structurer
38
+ // must neither scaffold nor remove. See workflow-package-json.
39
+ when(
40
+ ({ ctx }) => !ctx.isSdkInternal,
41
+ () =>
42
+ when(
43
+ whenFilesExist(COLOCATED_TEST_GLOB),
44
+ () => scaffold("vitest.config.mts", file("workflow/vitest.config.mts")),
45
+ () => remove("vitest.config.mts"),
46
+ ),
47
+ );
29
48
  // No workflow facade (index.js / index.d.ts): the block loader resolves the
30
49
  // workflow via the `block:` components dist path (workflow/dist/.../main.plj.gz),
31
50
  // never the JS facade. It was orphaned in production — dropped. Actively
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@milaboratories/ts-configs/block/model",
3
+ "compilerOptions": {
4
+ "types": ["node"]
5
+ },
6
+ "include": ["src/**/*"]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@milaboratories/ts-configs/block/ui",
3
+ "compilerOptions": {
4
+ "types": ["node"]
5
+ },
6
+ "include": ["src/**/*"]
7
+ }