@platforma-sdk/block-tools 2.20.6 → 2.22.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.
- package/dist/cli.js +10 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +580 -569
- package/dist/cli.mjs.map +1 -1
- package/dist/structure/engine/api.d.ts +4 -0
- package/dist/structure/engine/ctx.d.ts +1 -0
- package/dist/structure/engine/version.d.ts +8 -1
- package/package.json +1 -1
- package/src/structure/__tests__/root-ci-workflows.test.ts +64 -0
- package/src/structure/engine/api.ts +4 -0
- package/src/structure/engine/ctx.ts +2 -0
- package/src/structure/engine/discovery-fs.ts +1 -0
- package/src/structure/engine/runner.ts +2 -2
- package/src/structure/engine/version.ts +19 -4
- package/src/structure/rules/root-ci.ts +10 -0
- package/src/structure/templates/text/workflows/build.tpl.yaml +1 -1
|
@@ -48,6 +48,10 @@ 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 `npm-own-registry-scopes`). True when
|
|
53
|
+
* absent; false only for a block that opted out. */
|
|
54
|
+
ownNpmRegistry: boolean;
|
|
51
55
|
};
|
|
52
56
|
export type { ContentForm, ManagedBody, RunMode, Structure, TriggerFn };
|
|
53
57
|
export { defineStructure, scope, when, whenFilesExist, onUpdateDeps, onInitOrUpdate, fixed, managed, scaffold, seed, remove, rename, file, binaryFile, text, tpl, generate, blockVars, } from './builders';
|
|
@@ -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
|
+
/** Whether the block publishes `@platforma-open` to npm.platforma.bio
|
|
9
|
+
* (the shared CI's `npm-own-registry-scopes`). Absent = yes, the default.
|
|
10
|
+
* `false` keeps the block on npmjs (opt-out, set by hand). */
|
|
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,8 @@ 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. Only the
|
|
23
|
+
* opt-out (`ownNpmRegistry: false`) is written: `true` is the default, so a
|
|
24
|
+
* block on the default keeps `{"version":N}` (an explicit `true` from the
|
|
25
|
+
* opt-in period is dropped). */
|
|
19
26
|
export declare function writeStructureMeta(fs: FileSystem, meta: StructureMeta): void;
|
package/package.json
CHANGED
|
@@ -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,68 @@ describe("root CI workflows (fixed, generated)", () => {
|
|
|
71
73
|
expect(ciChanges).toEqual([]);
|
|
72
74
|
});
|
|
73
75
|
|
|
76
|
+
test("by default the workflow publishes to the own registry", () => {
|
|
77
|
+
const { fs, ctx } = simulateInit({ vars: VARS });
|
|
78
|
+
expect(ctx.ownNpmRegistry).toBe(true);
|
|
79
|
+
const build = fs.read(BUILD);
|
|
80
|
+
expect(build.match(/npm-own-registry-scopes: '@platforma-open'/g)).toHaveLength(1);
|
|
81
|
+
// The default is not written: a block on it keeps {"version":N}.
|
|
82
|
+
expect(fs.read(STRUCTURE_META_FILE)).not.toContain("ownNpmRegistry");
|
|
83
|
+
expect(discoverRunContext({ fs, isSdkInternal: false }).ownNpmRegistry).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("ownNpmRegistry: false opts out, and refresh keeps the opt-out", () => {
|
|
87
|
+
const { fs } = simulateInit({ vars: VARS });
|
|
88
|
+
const meta = readStructureMeta(fs);
|
|
89
|
+
fs.write(STRUCTURE_META_FILE, JSON.stringify({ ...meta, ownNpmRegistry: false }));
|
|
90
|
+
|
|
91
|
+
const ctx = discoverRunContext({ fs, isSdkInternal: false });
|
|
92
|
+
expect(ctx.ownNpmRegistry).toBe(false);
|
|
93
|
+
engineRun(STRUCTURE, fs, ctx, { templates: TEMPLATES });
|
|
94
|
+
|
|
95
|
+
const build = fs.read(BUILD);
|
|
96
|
+
expect(build).not.toContain("npm-own-registry-scopes");
|
|
97
|
+
// The placeholder expands to nothing: the next line follows directly.
|
|
98
|
+
expect(build).toContain("require-package-path-bump: true\n\n npmrc-config: |");
|
|
99
|
+
// Refresh rewrote .structure and kept the opt-out.
|
|
100
|
+
expect(readStructureMeta(fs).ownNpmRegistry).toBe(false);
|
|
101
|
+
|
|
102
|
+
// Fixpoint: a check right after changes nothing in the workflow files.
|
|
103
|
+
const checkCtx: RunContext = {
|
|
104
|
+
...discoverRunContext({ fs, isSdkInternal: false }),
|
|
105
|
+
dryRun: true,
|
|
106
|
+
};
|
|
107
|
+
const result = engineRun(STRUCTURE, fs, checkCtx, { templates: TEMPLATES });
|
|
108
|
+
expect(result.changes.filter((c) => c.path === BUILD || c.path === MARK_STABLE)).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("removing the opt-out brings the input back on refresh", () => {
|
|
112
|
+
const { fs } = simulateInit({ vars: VARS });
|
|
113
|
+
const meta = readStructureMeta(fs);
|
|
114
|
+
fs.write(STRUCTURE_META_FILE, JSON.stringify({ ...meta, ownNpmRegistry: false }));
|
|
115
|
+
engineRun(STRUCTURE, fs, discoverRunContext({ fs, isSdkInternal: false }), {
|
|
116
|
+
templates: TEMPLATES,
|
|
117
|
+
});
|
|
118
|
+
expect(fs.read(BUILD)).not.toContain("npm-own-registry-scopes");
|
|
119
|
+
|
|
120
|
+
fs.write(STRUCTURE_META_FILE, JSON.stringify({ version: meta.version }));
|
|
121
|
+
engineRun(STRUCTURE, fs, discoverRunContext({ fs, isSdkInternal: false }), {
|
|
122
|
+
templates: TEMPLATES,
|
|
123
|
+
});
|
|
124
|
+
expect(fs.read(BUILD)).toContain("npm-own-registry-scopes");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("an explicit ownNpmRegistry: true (opt-in period) is kept on and dropped from .structure", () => {
|
|
128
|
+
const { fs } = simulateInit({ vars: VARS });
|
|
129
|
+
const meta = readStructureMeta(fs);
|
|
130
|
+
fs.write(STRUCTURE_META_FILE, JSON.stringify({ ...meta, ownNpmRegistry: true }));
|
|
131
|
+
engineRun(STRUCTURE, fs, discoverRunContext({ fs, isSdkInternal: false }), {
|
|
132
|
+
templates: TEMPLATES,
|
|
133
|
+
});
|
|
134
|
+
expect(fs.read(BUILD).match(/npm-own-registry-scopes: '@platforma-open'/g)).toHaveLength(1);
|
|
135
|
+
expect(fs.read(STRUCTURE_META_FILE)).toBe(JSON.stringify({ version: meta.version }));
|
|
136
|
+
});
|
|
137
|
+
|
|
74
138
|
test("sdk-internal blocks get neither workflow file", () => {
|
|
75
139
|
const { fs } = simulateInit({ vars: VARS, isSdkInternal: true });
|
|
76
140
|
expect(fs.exists(BUILD)).toBe(false);
|
|
@@ -62,6 +62,10 @@ 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 `npm-own-registry-scopes`). True when
|
|
67
|
+
* absent; false only for a block that opted out. */
|
|
68
|
+
ownNpmRegistry: boolean;
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
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 ?? true,
|
|
94
96
|
};
|
|
95
97
|
}
|
|
@@ -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 = {
|
|
18
|
+
export type StructureMeta = {
|
|
19
|
+
version: number;
|
|
20
|
+
/** Whether the block publishes `@platforma-open` to npm.platforma.bio
|
|
21
|
+
* (the shared CI's `npm-own-registry-scopes`). Absent = yes, the default.
|
|
22
|
+
* `false` keeps the block on npmjs (opt-out, set by hand). */
|
|
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
|
-
|
|
31
|
+
const meta: StructureMeta = {
|
|
32
|
+
version: typeof parsed?.version === "number" ? parsed.version : 0,
|
|
33
|
+
};
|
|
34
|
+
if (typeof parsed?.ownNpmRegistry === "boolean") meta.ownNpmRegistry = parsed.ownNpmRegistry;
|
|
35
|
+
return meta;
|
|
26
36
|
} catch {
|
|
27
37
|
return { version: 0 };
|
|
28
38
|
}
|
|
@@ -51,8 +61,13 @@ 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. Only the
|
|
65
|
+
* opt-out (`ownNpmRegistry: false`) is written: `true` is the default, so a
|
|
66
|
+
* block on the default keeps `{"version":N}` (an explicit `true` from the
|
|
67
|
+
* opt-in period is dropped). */
|
|
55
68
|
export function writeStructureMeta(fs: FileSystem, meta: StructureMeta): void {
|
|
69
|
+
const payload: StructureMeta = { version: meta.version };
|
|
70
|
+
if (meta.ownNpmRegistry === false) payload.ownNpmRegistry = false;
|
|
56
71
|
// Compact, single-line — this is a tiny machine file, no pretty-print.
|
|
57
|
-
fs.write(STRUCTURE_META_FILE, JSON.stringify(
|
|
72
|
+
fs.write(STRUCTURE_META_FILE, JSON.stringify(payload));
|
|
58
73
|
}
|
|
@@ -29,6 +29,15 @@ function humanizeShortName(shortName: string): string {
|
|
|
29
29
|
.join(" ");
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/** Appended after `require-package-path-bump` unless `.structure` has
|
|
33
|
+
* `ownNpmRegistry: false`: the shared CI then installs and publishes
|
|
34
|
+
* `@platforma-open` through npm.platforma.bio. Empty for an opted-out block,
|
|
35
|
+
* which keeps publishing to npmjs. */
|
|
36
|
+
const OWN_NPM_REGISTRY_INPUT = `
|
|
37
|
+
|
|
38
|
+
# Publish @platforma-open to npm.platforma.bio (opt out: .structure "ownNpmRegistry": false).
|
|
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
|
{
|