@platforma-sdk/block-tools 2.20.5 → 2.21.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.
@@ -48,6 +48,9 @@ export type RunContext = {
48
48
  version: number;
49
49
  /** True for `check` mode and the post-run recheck. */
50
50
  dryRun: boolean;
51
+ /** `ownNpmRegistry` from `.structure`: the block publishes `@platforma-open`
52
+ * to npm.platforma.bio (shared-CI opt-in). False when absent. */
53
+ ownNpmRegistry: boolean;
51
54
  };
52
55
  export type { ContentForm, ManagedBody, RunMode, Structure, TriggerFn };
53
56
  export { defineStructure, scope, when, whenFilesExist, onUpdateDeps, onInitOrUpdate, fixed, managed, scaffold, seed, remove, rename, file, binaryFile, text, tpl, generate, blockVars, } from './builders';
@@ -30,5 +30,6 @@ export type CreateRunContextInput = {
30
30
  blockVars: BlockVars;
31
31
  version?: number;
32
32
  dryRun?: boolean;
33
+ ownNpmRegistry?: boolean;
33
34
  };
34
35
  export declare function createRunContext(input: CreateRunContextInput): RunContext;
@@ -5,6 +5,10 @@ export declare const STRUCTURE_MIN_SUPPORTED = 0;
5
5
  export declare const STRUCTURE_META_FILE = ".structure";
6
6
  export type StructureMeta = {
7
7
  version: number;
8
+ /** The block publishes `@platforma-open` to npm.platforma.bio instead of
9
+ * npmjs (the shared CI's `npm-own-registry-scopes` opt-in). Set by hand in
10
+ * `.structure` while blocks move; absent = npmjs, as before. */
11
+ ownNpmRegistry?: boolean;
8
12
  };
9
13
  /** Read `.structure`. Missing file or invalid payload → version 0. */
10
14
  export declare function readStructureMeta(fs: FileSystem): StructureMeta;
@@ -15,5 +19,6 @@ export declare class StructureVersionFloorError extends Error {
15
19
  readonly floor: number;
16
20
  constructor(version: number, floor: number);
17
21
  }
18
- /** Write `.structure`. Writes a fresh payload rather than merging. */
22
+ /** Write `.structure`. Writes a fresh payload rather than merging; an unset
23
+ * `ownNpmRegistry` is left out, so a block without it keeps `{"version":N}`. */
19
24
  export declare function writeStructureMeta(fs: FileSystem, meta: StructureMeta): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/block-tools",
3
- "version": "2.20.5",
3
+ "version": "2.21.0",
4
4
  "description": "Utility to manipulate Platforma Blocks and Block Registry",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  "@milaboratories/pl-http": "1.2.7",
29
29
  "@milaboratories/pl-model-backend": "1.4.53",
30
30
  "@milaboratories/pl-model-common": "1.56.0",
31
- "@milaboratories/pl-model-middle-layer": "1.40.0",
31
+ "@milaboratories/pl-model-middle-layer": "1.41.0",
32
32
  "@milaboratories/resolve-helper": "1.1.3",
33
33
  "@milaboratories/ts-helpers": "1.9.1",
34
34
  "@platforma-sdk/blocks-deps-updater": "2.2.2",
@@ -12,6 +12,8 @@ import type { BlockVars, RunContext } from "../engine/api";
12
12
  import { STRUCTURE } from "../structure-definition";
13
13
  import { run as engineRun } from "../engine/runner";
14
14
  import { defaultTemplateProvider, simulateInit } from "../engine/testing";
15
+ import { discoverRunContext } from "../engine/discovery-fs";
16
+ import { readStructureMeta, STRUCTURE_META_FILE } from "../engine/version";
15
17
  import { NODE_VERSION } from "../rules/shared/toolchain";
16
18
 
17
19
  const TEMPLATES = defaultTemplateProvider();
@@ -71,6 +73,55 @@ describe("root CI workflows (fixed, generated)", () => {
71
73
  expect(ciChanges).toEqual([]);
72
74
  });
73
75
 
76
+ test("without ownNpmRegistry the workflow has no own-registry input", () => {
77
+ const { fs, ctx } = simulateInit({ vars: VARS });
78
+ expect(ctx.ownNpmRegistry).toBe(false);
79
+ const build = fs.read(BUILD);
80
+ expect(build).not.toContain("npm-own-registry-scopes");
81
+ // The placeholder expands to nothing: the next line follows directly.
82
+ expect(build).toContain("require-package-path-bump: true\n\n npmrc-config: |");
83
+ expect(fs.read(STRUCTURE_META_FILE)).not.toContain("ownNpmRegistry");
84
+ });
85
+
86
+ test("ownNpmRegistry in .structure adds the opt-in input, and refresh keeps both", () => {
87
+ const { fs } = simulateInit({ vars: VARS });
88
+ const meta = readStructureMeta(fs);
89
+ fs.write(STRUCTURE_META_FILE, JSON.stringify({ ...meta, ownNpmRegistry: true }));
90
+
91
+ const ctx = discoverRunContext({ fs, isSdkInternal: false });
92
+ expect(ctx.ownNpmRegistry).toBe(true);
93
+ engineRun(STRUCTURE, fs, ctx, { templates: TEMPLATES });
94
+
95
+ const build = fs.read(BUILD);
96
+ expect(build.match(/npm-own-registry-scopes: '@platforma-open'/g)).toHaveLength(1);
97
+ // Refresh rewrote .structure and kept the setting.
98
+ expect(readStructureMeta(fs).ownNpmRegistry).toBe(true);
99
+
100
+ // Fixpoint: a check right after changes nothing in the workflow files.
101
+ const checkCtx: RunContext = {
102
+ ...discoverRunContext({ fs, isSdkInternal: false }),
103
+ dryRun: true,
104
+ };
105
+ const result = engineRun(STRUCTURE, fs, checkCtx, { templates: TEMPLATES });
106
+ expect(result.changes.filter((c) => c.path === BUILD || c.path === MARK_STABLE)).toEqual([]);
107
+ });
108
+
109
+ test("removing ownNpmRegistry from .structure removes the input on refresh", () => {
110
+ const { fs } = simulateInit({ vars: VARS });
111
+ const meta = readStructureMeta(fs);
112
+ fs.write(STRUCTURE_META_FILE, JSON.stringify({ ...meta, ownNpmRegistry: true }));
113
+ engineRun(STRUCTURE, fs, discoverRunContext({ fs, isSdkInternal: false }), {
114
+ templates: TEMPLATES,
115
+ });
116
+ expect(fs.read(BUILD)).toContain("npm-own-registry-scopes");
117
+
118
+ fs.write(STRUCTURE_META_FILE, JSON.stringify({ version: meta.version }));
119
+ engineRun(STRUCTURE, fs, discoverRunContext({ fs, isSdkInternal: false }), {
120
+ templates: TEMPLATES,
121
+ });
122
+ expect(fs.read(BUILD)).not.toContain("npm-own-registry-scopes");
123
+ });
124
+
74
125
  test("sdk-internal blocks get neither workflow file", () => {
75
126
  const { fs } = simulateInit({ vars: VARS, isSdkInternal: true });
76
127
  expect(fs.exists(BUILD)).toBe(false);
@@ -62,6 +62,9 @@ export type RunContext = {
62
62
  version: number;
63
63
  /** True for `check` mode and the post-run recheck. */
64
64
  dryRun: boolean;
65
+ /** `ownNpmRegistry` from `.structure`: the block publishes `@platforma-open`
66
+ * to npm.platforma.bio (shared-CI opt-in). False when absent. */
67
+ ownNpmRegistry: boolean;
65
68
  };
66
69
 
67
70
  export type { ContentForm, ManagedBody, RunMode, Structure, TriggerFn };
@@ -81,6 +81,7 @@ export type CreateRunContextInput = {
81
81
  blockVars: BlockVars;
82
82
  version?: number;
83
83
  dryRun?: boolean;
84
+ ownNpmRegistry?: boolean;
84
85
  };
85
86
 
86
87
  export function createRunContext(input: CreateRunContextInput): RunContext {
@@ -91,5 +92,6 @@ export function createRunContext(input: CreateRunContextInput): RunContext {
91
92
  blockVars: input.blockVars,
92
93
  version: input.version ?? 0,
93
94
  dryRun: input.dryRun ?? false,
95
+ ownNpmRegistry: input.ownNpmRegistry ?? false,
94
96
  };
95
97
  }
@@ -217,5 +217,6 @@ export function discoverRunContext(input: DiscoverInput): RunContext {
217
217
  blockVars,
218
218
  version: meta.version,
219
219
  dryRun: input.dryRun ?? false,
220
+ ownNpmRegistry: meta.ownNpmRegistry === true,
220
221
  });
221
222
  }
@@ -499,7 +499,7 @@ export function run(
499
499
 
500
500
  if (isRefreshDefault) {
501
501
  // version bump
502
- writeStructureMeta(fs, { version: STRUCTURE_VERSION });
502
+ writeStructureMeta(fs, { version: STRUCTURE_VERSION, ownNpmRegistry: ctx.ownNpmRegistry });
503
503
 
504
504
  // post-run recheck. Fresh discovery → fresh flatten →
505
505
  // dry-run. Any change list emits RecheckError on the first item.
@@ -527,7 +527,7 @@ export function run(
527
527
  // Init mode: write .structure so the resulting tree carries the
528
528
  // current version (matches what `init` ships to disk).
529
529
  if (initMode && !ctx.dryRun) {
530
- writeStructureMeta(fs, { version: STRUCTURE_VERSION });
530
+ writeStructureMeta(fs, { version: STRUCTURE_VERSION, ownNpmRegistry: ctx.ownNpmRegistry });
531
531
  }
532
532
 
533
533
  return { changes };
@@ -15,14 +15,24 @@ export const STRUCTURE_MIN_SUPPORTED = 0;
15
15
  /** Block-relative path of the structurer metadata file. */
16
16
  export const STRUCTURE_META_FILE = ".structure";
17
17
 
18
- export type StructureMeta = { version: number };
18
+ export type StructureMeta = {
19
+ version: number;
20
+ /** The block publishes `@platforma-open` to npm.platforma.bio instead of
21
+ * npmjs (the shared CI's `npm-own-registry-scopes` opt-in). Set by hand in
22
+ * `.structure` while blocks move; absent = npmjs, as before. */
23
+ ownNpmRegistry?: boolean;
24
+ };
19
25
 
20
26
  /** Read `.structure`. Missing file or invalid payload → version 0. */
21
27
  export function readStructureMeta(fs: FileSystem): StructureMeta {
22
28
  if (!fs.exists(STRUCTURE_META_FILE)) return { version: 0 };
23
29
  try {
24
30
  const parsed = JSON.parse(fs.read(STRUCTURE_META_FILE)) as Partial<StructureMeta>;
25
- return { version: typeof parsed?.version === "number" ? parsed.version : 0 };
31
+ const meta: StructureMeta = {
32
+ version: typeof parsed?.version === "number" ? parsed.version : 0,
33
+ };
34
+ if (parsed?.ownNpmRegistry === true) meta.ownNpmRegistry = true;
35
+ return meta;
26
36
  } catch {
27
37
  return { version: 0 };
28
38
  }
@@ -51,8 +61,11 @@ export class StructureVersionFloorError extends Error {
51
61
  }
52
62
  }
53
63
 
54
- /** Write `.structure`. Writes a fresh payload rather than merging. */
64
+ /** Write `.structure`. Writes a fresh payload rather than merging; an unset
65
+ * `ownNpmRegistry` is left out, so a block without it keeps `{"version":N}`. */
55
66
  export function writeStructureMeta(fs: FileSystem, meta: StructureMeta): void {
67
+ const payload: StructureMeta = { version: meta.version };
68
+ if (meta.ownNpmRegistry === true) payload.ownNpmRegistry = true;
56
69
  // Compact, single-line — this is a tiny machine file, no pretty-print.
57
- fs.write(STRUCTURE_META_FILE, JSON.stringify(meta));
70
+ fs.write(STRUCTURE_META_FILE, JSON.stringify(payload));
58
71
  }
@@ -29,6 +29,15 @@ function humanizeShortName(shortName: string): string {
29
29
  .join(" ");
30
30
  }
31
31
 
32
+ /** Appended after `require-package-path-bump` when `.structure` has
33
+ * `ownNpmRegistry: true`: the shared CI then installs and publishes
34
+ * `@platforma-open` through npm.platforma.bio. Empty otherwise, so a block
35
+ * without the setting gets the same file byte for byte. */
36
+ const OWN_NPM_REGISTRY_INPUT = `
37
+
38
+ # .structure "ownNpmRegistry": publish @platforma-open to npm.platforma.bio.
39
+ npm-own-registry-scopes: '@platforma-open'`;
40
+
32
41
  export function rootCiRules(): void {
33
42
  scope("root", () => {
34
43
  when(
@@ -42,6 +51,7 @@ export function rootCiRules(): void {
42
51
  appName: `Block: ${humanizeShortName(shortName)}`,
43
52
  appNameSlug: `block-${shortName}`,
44
53
  nodeVersion: NODE_VERSION,
54
+ ownNpmRegistry: ctx.ownNpmRegistry ? OWN_NPM_REGISTRY_INPUT : "",
45
55
  };
46
56
  }),
47
57
  );
@@ -42,7 +42,7 @@ jobs:
42
42
  # Require the published `block` package to be bumped by a changeset on
43
43
  # PRs (empty changeset or the `skip-changelog` label waives it). Needs
44
44
  # the input to exist on the pinned `@v4` reusable workflow.
45
- require-package-path-bump: true
45
+ require-package-path-bump: true${ownNpmRegistry}
46
46
 
47
47
  npmrc-config: |
48
48
  {