@platforma-sdk/block-tools 2.17.7 → 2.17.9
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 +12 -12
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +589 -575
- package/dist/cli.mjs.map +1 -1
- package/dist/structure/__tests__/tool-bin.d.ts +4 -0
- package/dist/structure/cli/run-structure.d.ts +6 -0
- package/dist/structure/rules/root-package-json.d.ts +1 -0
- package/dist/structure/rules/root-pnpm-workspace.d.ts +1 -0
- package/package.json +13 -12
- package/src/cmd/structure/check.ts +8 -3
- package/src/cmd/structure/refresh.ts +8 -4
- package/src/structure/__tests__/init-lint-clean.test.ts +9 -8
- package/src/structure/__tests__/oxfmt-clean-init.test.ts +8 -7
- package/src/structure/__tests__/root-catalog-bump.test.ts +3 -6
- package/src/structure/__tests__/root-catalog-floor.test.ts +107 -0
- package/src/structure/__tests__/tool-bin.ts +41 -0
- package/src/structure/__tests__/toolchain.test.ts +24 -14
- package/src/structure/cli/run-structure.ts +17 -0
- package/src/structure/rules/root-catalog-bump.ts +23 -7
- package/src/structure/rules/root-package-json.ts +17 -8
- package/src/structure/rules/root-pnpm-workspace.ts +19 -2
- package/src/structure/rules/shared/toolchain.ts +0 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** `requireRoot` is the file to resolve from — it decides WHICH copy of the
|
|
2
|
+
* tool is found (e.g. ts-builder's pinned oxlint vs block-tools' own).
|
|
3
|
+
* Returns undefined when the tool is not installed, so callers can skip. */
|
|
4
|
+
export declare function resolveToolBin(requireRoot: string, packageName: string, binName?: string): string | undefined;
|
|
@@ -15,5 +15,11 @@ export type RunStructureResult = {
|
|
|
15
15
|
changes: Change[];
|
|
16
16
|
};
|
|
17
17
|
export declare function runStructureForPath(input: RunStructureInput): Promise<RunStructureResult>;
|
|
18
|
+
/** Expand glob patterns among the positional block paths. POSIX shells expand
|
|
19
|
+
* them before the CLI sees them, but cmd.exe does not — so on Windows
|
|
20
|
+
* `structure check etc/blocks/*` would otherwise receive the literal pattern
|
|
21
|
+
* and fail with "No workspace packages found". Only directories are kept, and
|
|
22
|
+
* arguments carrying no glob metacharacter pass through untouched. */
|
|
23
|
+
export declare function expandBlockPaths(paths: string[]): string[];
|
|
18
24
|
/** One-line-per-change summary for CLI output. */
|
|
19
25
|
export declare function formatChanges(blockPath: string, changes: Change[]): string;
|
|
@@ -31,4 +31,5 @@ export declare const DERIVED_CATALOG_PINS: readonly DerivedCatalogPin[];
|
|
|
31
31
|
export declare const RUNENV_PYTHON = "@platforma-open/milaboratories.runenv-python-3";
|
|
32
32
|
export declare const RUNENV_PYTHON_VERSION = "1.8.2";
|
|
33
33
|
export declare function rootPnpmWorkspaceInitial(ctx: RunContext): Record<string, unknown>;
|
|
34
|
+
export declare function rootPnpmWorkspaceToolchainRules(): void;
|
|
34
35
|
export declare function rootPnpmWorkspaceRules(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/block-tools",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.9",
|
|
4
4
|
"description": "Utility to manipulate Platforma Blocks and Block Registry",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"@aws-sdk/client-ecr-public": "3.1157.0",
|
|
27
27
|
"@aws-sdk/client-s3": "3.1157.0",
|
|
28
28
|
"@inquirer/prompts": "^7.0.1",
|
|
29
|
-
"@milaboratories/pl-http": "1.2.
|
|
30
|
-
"@milaboratories/pl-model-backend": "1.4.
|
|
31
|
-
"@milaboratories/pl-model-common": "1.55.
|
|
32
|
-
"@milaboratories/pl-model-middle-layer": "1.
|
|
29
|
+
"@milaboratories/pl-http": "1.2.6",
|
|
30
|
+
"@milaboratories/pl-model-backend": "1.4.45",
|
|
31
|
+
"@milaboratories/pl-model-common": "1.55.1",
|
|
32
|
+
"@milaboratories/pl-model-middle-layer": "1.36.0",
|
|
33
33
|
"@milaboratories/resolve-helper": "1.1.3",
|
|
34
|
-
"@milaboratories/ts-helpers": "1.9.
|
|
35
|
-
"@platforma-sdk/blocks-deps-updater": "2.2.
|
|
36
|
-
"@platforma-sdk/package-builder-lib": "1.4.
|
|
34
|
+
"@milaboratories/ts-helpers": "1.9.1",
|
|
35
|
+
"@platforma-sdk/blocks-deps-updater": "2.2.2",
|
|
36
|
+
"@platforma-sdk/package-builder-lib": "1.4.4",
|
|
37
37
|
"canonicalize": "~2.1.0",
|
|
38
38
|
"commander": "^15.0.0",
|
|
39
39
|
"lru-cache": "^11.5.3",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"zod": "~3.25.76"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@milaboratories/build-configs": "2.0.
|
|
48
|
-
"@milaboratories/ts-builder": "1.7.
|
|
49
|
-
"@milaboratories/ts-configs": "1.4.
|
|
47
|
+
"@milaboratories/build-configs": "2.0.3",
|
|
48
|
+
"@milaboratories/ts-builder": "1.7.4",
|
|
49
|
+
"@milaboratories/ts-configs": "1.4.1",
|
|
50
50
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
51
51
|
"@types/mime-types": "^2.1.4",
|
|
52
52
|
"@types/node": "~24.19.2",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"oxfmt": "0.75.0",
|
|
56
56
|
"rollup-plugin-node-externals": "^8.0.0",
|
|
57
57
|
"semver": "^7.7.2",
|
|
58
|
+
"shx": "^0.4.0",
|
|
58
59
|
"typescript": "7.0.2",
|
|
59
60
|
"vite": "^8.3.5",
|
|
60
61
|
"vite-plugin-dts": "^5.1.2",
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"scripts": {
|
|
69
70
|
"build": "vite build",
|
|
70
71
|
"test": "vitest run --coverage",
|
|
71
|
-
"do-pack": "rm -f *.tgz && pnpm pack && mv *.tgz package.tgz",
|
|
72
|
+
"do-pack": "shx rm -f *.tgz && pnpm pack && shx mv *.tgz package.tgz",
|
|
72
73
|
"formatter:check": "ts-builder formatter --check",
|
|
73
74
|
"linter:check": "ts-builder linter --check",
|
|
74
75
|
"types:check": "ts-builder type-check --target node",
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
runStructureForPath,
|
|
6
|
+
formatChanges,
|
|
7
|
+
expandBlockPaths,
|
|
8
|
+
} from "../../structure/cli/run-structure";
|
|
5
9
|
|
|
6
10
|
export function structureCheckCommand(packageRoot: string): Command {
|
|
7
11
|
const cmd = new Command("check").description(
|
|
8
12
|
"Check block(s) against the canonical structure (read-only). Exits non-zero if any diff would land — used as the CI gate.",
|
|
9
13
|
);
|
|
10
14
|
|
|
11
|
-
// Variadic positional block paths
|
|
15
|
+
// Variadic positional block paths; glob patterns are expanded by the CLI so
|
|
16
|
+
// they work on shells that do not expand them (cmd.exe).
|
|
12
17
|
cmd.argument("[paths...]", "block path(s); defaults to the current directory");
|
|
13
18
|
cmd.option("--sdk-internal", "block(s) live inside the SDK monorepo; skip root-scope rules");
|
|
14
19
|
|
|
15
20
|
cmd.action(async (argv: string[], flags) => {
|
|
16
21
|
const logger = new ConsoleLoggerAdapter();
|
|
17
|
-
const paths = argv.length > 0 ? argv : ["."];
|
|
22
|
+
const paths = argv.length > 0 ? expandBlockPaths(argv) : ["."];
|
|
18
23
|
const templatesRoot = path.join(packageRoot, "src", "structure", "templates");
|
|
19
24
|
|
|
20
25
|
let anyChanged = false;
|
|
@@ -2,7 +2,11 @@ import { Command } from "commander";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import type { MiLogger } from "@milaboratories/ts-helpers";
|
|
4
4
|
import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
runStructureForPath,
|
|
7
|
+
formatChanges,
|
|
8
|
+
expandBlockPaths,
|
|
9
|
+
} from "../../structure/cli/run-structure";
|
|
6
10
|
|
|
7
11
|
// Shared by `structure refresh` and the deprecated `update-deps` alias.
|
|
8
12
|
export async function runRefresh(opts: {
|
|
@@ -27,18 +31,18 @@ export async function runRefresh(opts: {
|
|
|
27
31
|
|
|
28
32
|
export function structureRefreshCommand(packageRoot: string): Command {
|
|
29
33
|
const cmd = new Command("refresh").description(
|
|
30
|
-
"Bring block(s) up to date with the canonical structure. Applies rules, writes files, bumps .structure version. Default mode is offline; --update-deps-only
|
|
34
|
+
"Bring block(s) up to date with the canonical structure. Applies rules, writes files, bumps .structure version. Default mode is offline; --update-deps-only updates the catalog versions and the pnpm and Node toolchain (network).",
|
|
31
35
|
);
|
|
32
36
|
|
|
33
37
|
cmd.argument("[paths...]", "block path(s); defaults to the current directory");
|
|
34
38
|
cmd.option("--sdk-internal", "block(s) live inside the SDK monorepo; skip root-scope rules");
|
|
35
39
|
cmd.option(
|
|
36
40
|
"--update-deps-only",
|
|
37
|
-
"
|
|
41
|
+
"update ONLY the catalog versions and the pnpm and Node toolchain (npm network). Follow with `pnpm install` then a plain refresh.",
|
|
38
42
|
);
|
|
39
43
|
|
|
40
44
|
cmd.action(async (argv: string[], flags) => {
|
|
41
|
-
const paths = argv.length > 0 ? argv : ["."];
|
|
45
|
+
const paths = argv.length > 0 ? expandBlockPaths(argv) : ["."];
|
|
42
46
|
const templatesRoot = path.join(packageRoot, "src", "structure", "templates");
|
|
43
47
|
await runRefresh({
|
|
44
48
|
paths,
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import { describe, test, expect } from "vitest";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
|
-
import {
|
|
6
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { simulateInit } from "../engine/testing";
|
|
11
|
+
import { resolveToolBin } from "./tool-bin";
|
|
11
12
|
import type { BlockVars } from "../engine/api";
|
|
12
13
|
|
|
13
14
|
const VARS: BlockVars = {
|
|
@@ -22,12 +23,12 @@ function resolveTsBuilderConfig(configFile: string): string {
|
|
|
22
23
|
return fileURLToPath(import.meta.resolve(`@milaboratories/ts-builder/configs/${configFile}`));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
/** ts-builder pins its own oxlint, so block-tools'
|
|
26
|
-
*
|
|
26
|
+
/** ts-builder pins its own oxlint, so block-tools' copy is a different version —
|
|
27
|
+
* resolve from inside ts-builder to get the one its configs were written for.
|
|
28
|
+
* See tool-bin.ts for why this goes through the `bin` field rather than
|
|
29
|
+
* node_modules/.bin. */
|
|
27
30
|
function resolveOxlintBinary(): string | undefined {
|
|
28
|
-
|
|
29
|
-
const binary = path.resolve(configsDir, "..", "..", "node_modules", ".bin", "oxlint");
|
|
30
|
-
return existsSync(binary) ? binary : undefined;
|
|
31
|
+
return resolveToolBin(resolveTsBuilderConfig("oxlint-base.json"), "oxlint");
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/** The scopes whose `fmt` script lints. */
|
|
@@ -66,8 +67,8 @@ describe("init output is lint-clean (oxlint --deny-warnings)", () => {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
const result = spawnSync(
|
|
69
|
-
|
|
70
|
-
["--config", path.join(root, scope, ".oxlintrc.json"), "--deny-warnings", "src"],
|
|
70
|
+
process.execPath,
|
|
71
|
+
[oxlint!, "--config", path.join(root, scope, ".oxlintrc.json"), "--deny-warnings", "src"],
|
|
71
72
|
{ cwd: path.join(root, scope), encoding: "utf-8" },
|
|
72
73
|
);
|
|
73
74
|
expect(
|
|
@@ -13,15 +13,16 @@ import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";
|
|
|
13
13
|
import { tmpdir } from "node:os";
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
import { simulateInit } from "../engine/testing";
|
|
16
|
+
import { resolveToolBin } from "./tool-bin";
|
|
16
17
|
import type { BlockVars } from "../engine/api";
|
|
17
18
|
|
|
18
|
-
function oxfmtAvailable(): boolean {
|
|
19
|
-
const r = spawnSync("oxfmt", ["--help"], { encoding: "utf-8" });
|
|
20
|
-
return !r.error;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
describe("oxfmt-clean init output (model + ui)", () => {
|
|
24
|
-
|
|
20
|
+
// Resolved from block-tools, which declares oxfmt as a dependency. See
|
|
21
|
+
// tool-bin.ts for why this does not go through PATH or node_modules/.bin —
|
|
22
|
+
// a bare `spawnSync("oxfmt")` probe reports it unavailable on Windows and
|
|
23
|
+
// silently skips this guard.
|
|
24
|
+
const oxfmt = resolveToolBin(import.meta.url, "oxfmt");
|
|
25
|
+
const available = oxfmt !== undefined;
|
|
25
26
|
|
|
26
27
|
// Both files `ts-builder check` runs oxfmt on, per scope: package.json AND
|
|
27
28
|
// tsconfig.json. tsconfig is the regression that motivated the
|
|
@@ -47,7 +48,7 @@ describe("oxfmt-clean init output (model + ui)", () => {
|
|
|
47
48
|
for (const fileName of FILES) {
|
|
48
49
|
const content = fs.read(`${scope}/${fileName}`);
|
|
49
50
|
writeFileSync(path.join(root, scope, fileName), content);
|
|
50
|
-
const r = spawnSync(
|
|
51
|
+
const r = spawnSync(process.execPath, [oxfmt!, "--check", path.join(scope, fileName)], {
|
|
51
52
|
cwd: root,
|
|
52
53
|
encoding: "utf-8",
|
|
53
54
|
});
|
|
@@ -74,7 +74,7 @@ describe("rootCatalogBumpRules mode split", () => {
|
|
|
74
74
|
expect(fs.exists("MARKER.txt")).toBe(true);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
test("--update-deps-only: SDK catalog bumped,
|
|
77
|
+
test("--update-deps-only: SDK catalog bumped, default-mode leaf skipped", async () => {
|
|
78
78
|
const fs = freshFs();
|
|
79
79
|
engineRun(STRUCTURE, fs, ctx(true), { registryLookup: mockLookup });
|
|
80
80
|
|
|
@@ -83,15 +83,12 @@ describe("rootCatalogBumpRules mode split", () => {
|
|
|
83
83
|
// Present SDK keys refreshed to latest.
|
|
84
84
|
expect(cat["@platforma-sdk/model"]).toBe("9.9.9");
|
|
85
85
|
expect(cat["@milaboratories/ts-builder"]).toBe("9.9.9");
|
|
86
|
-
// standard infra-floor keys ABSENT from the on-disk catalog are
|
|
87
|
-
// SEEDED add-if-absent (no manual seed step needed).
|
|
88
|
-
expect(cat["shx"]).toBe("~0.4.0");
|
|
89
|
-
expect(cat["turbo"]).toBe("~2.11.10");
|
|
90
|
-
expect(cat["vitest"]).toBe("~4.0.18");
|
|
91
86
|
// Non-matching dep left alone.
|
|
92
87
|
expect(cat["lodash"]).toBe("1.0.0");
|
|
93
88
|
// Default-mode leaf was skipped in update-deps-only mode.
|
|
94
89
|
expect(fs.exists("MARKER.txt")).toBe(false);
|
|
90
|
+
// The infra floor is NOT this rule's job — it is seeded on every refresh
|
|
91
|
+
// by rootPnpmWorkspaceRules (see root-catalog-floor.test.ts).
|
|
95
92
|
});
|
|
96
93
|
|
|
97
94
|
test("init: SDK catalog bumped AND default-mode leaf fires", async () => {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// The curated infra floor must be seeded on EVERY refresh, not only on init /
|
|
2
|
+
// `--update-deps-only`. The root package.json rules hand out `catalog:`
|
|
3
|
+
// references for these entries (turbo, shx, cross-env, …) on every refresh, so
|
|
4
|
+
// seeding them only in the update-deps frame left a plain `structure refresh`
|
|
5
|
+
// writing a `catalog:` for a key the catalog did not carry — `pnpm install`
|
|
6
|
+
// then failed with ERR_PNPM_CATALOG_ENTRY_NOT_FOUND_FOR_SPEC.
|
|
7
|
+
|
|
8
|
+
import { describe, test, expect } from "vitest";
|
|
9
|
+
import { parse as parseYaml } from "yaml";
|
|
10
|
+
import { defineStructure, scope, managed, generate } from "../engine/api";
|
|
11
|
+
import {
|
|
12
|
+
rootPnpmWorkspaceInitial,
|
|
13
|
+
rootPnpmWorkspaceRules,
|
|
14
|
+
INFRA_CATALOG_FLOOR,
|
|
15
|
+
} from "../rules/root-pnpm-workspace";
|
|
16
|
+
import { run as engineRun } from "../engine/runner";
|
|
17
|
+
import { MemoryFileSystem } from "../engine/fs/memory";
|
|
18
|
+
import { createRunContext } from "../engine/ctx";
|
|
19
|
+
import type { BlockVars } from "../engine/api";
|
|
20
|
+
|
|
21
|
+
const VARS: BlockVars = {
|
|
22
|
+
facadeName: "@platforma-open/test-org.demo",
|
|
23
|
+
baseName: "test-org.demo",
|
|
24
|
+
npmOrg: "@platforma-open",
|
|
25
|
+
orgScope: "test-org",
|
|
26
|
+
shortName: "demo",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const STRUCTURE = defineStructure(() => {
|
|
30
|
+
scope("root", () => {
|
|
31
|
+
managed(
|
|
32
|
+
"pnpm-workspace.yaml",
|
|
33
|
+
generate((ctx) => rootPnpmWorkspaceInitial(ctx)),
|
|
34
|
+
() => {
|
|
35
|
+
rootPnpmWorkspaceRules();
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// A migrated block: no infra floor keys at all, and one entry already pinned
|
|
42
|
+
// to a version of the author's choosing.
|
|
43
|
+
const WORKSPACE_YAML = [
|
|
44
|
+
"packages:",
|
|
45
|
+
" - .",
|
|
46
|
+
"catalog:",
|
|
47
|
+
" shx: 0.3.0",
|
|
48
|
+
" lodash: 1.0.0",
|
|
49
|
+
"",
|
|
50
|
+
].join("\n");
|
|
51
|
+
|
|
52
|
+
function run(updateDepsOnly: boolean): Record<string, string> {
|
|
53
|
+
const fs = new MemoryFileSystem({ "pnpm-workspace.yaml": WORKSPACE_YAML });
|
|
54
|
+
engineRun(
|
|
55
|
+
STRUCTURE,
|
|
56
|
+
fs,
|
|
57
|
+
createRunContext({
|
|
58
|
+
blockVars: VARS,
|
|
59
|
+
modules: [{ scope: "root", name: VARS.facadeName, path: "" }],
|
|
60
|
+
isSdkInternal: false,
|
|
61
|
+
updateDepsOnly,
|
|
62
|
+
version: 1,
|
|
63
|
+
dryRun: false,
|
|
64
|
+
}),
|
|
65
|
+
{},
|
|
66
|
+
);
|
|
67
|
+
return (parseYaml(fs.read("pnpm-workspace.yaml")) as { catalog: Record<string, string> }).catalog;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe("infra catalog floor", () => {
|
|
71
|
+
test("a DEFAULT refresh seeds every floor entry the block is missing", () => {
|
|
72
|
+
const cat = run(false);
|
|
73
|
+
for (const [name, version] of Object.entries(INFRA_CATALOG_FLOOR)) {
|
|
74
|
+
if (name === "shx") continue; // already pinned by the author, asserted below
|
|
75
|
+
expect(cat[name], `${name} must be seeded on a default refresh`).toBe(version);
|
|
76
|
+
}
|
|
77
|
+
// Every `catalog:` the root package.json rules emit must resolve.
|
|
78
|
+
expect(cat["cross-env"]).toBe(INFRA_CATALOG_FLOOR["cross-env"]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("add-if-absent: a version the block already pins is never rewritten", () => {
|
|
82
|
+
expect(run(false)["shx"]).toBe("0.3.0");
|
|
83
|
+
expect(run(true)["shx"]).toBe("0.3.0");
|
|
84
|
+
// An unrelated entry is left alone.
|
|
85
|
+
expect(run(false)["lodash"]).toBe("1.0.0");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("seeding is a fixpoint — a second refresh changes nothing", () => {
|
|
89
|
+
const once = run(false);
|
|
90
|
+
const fs = new MemoryFileSystem({ "pnpm-workspace.yaml": WORKSPACE_YAML });
|
|
91
|
+
const context = () =>
|
|
92
|
+
createRunContext({
|
|
93
|
+
blockVars: VARS,
|
|
94
|
+
modules: [{ scope: "root", name: VARS.facadeName, path: "" }],
|
|
95
|
+
isSdkInternal: false,
|
|
96
|
+
updateDepsOnly: false,
|
|
97
|
+
version: 1,
|
|
98
|
+
dryRun: false,
|
|
99
|
+
});
|
|
100
|
+
engineRun(STRUCTURE, fs, context(), {});
|
|
101
|
+
const second = engineRun(STRUCTURE, fs, context(), {});
|
|
102
|
+
expect(second.changes.length, "second refresh must make no changes").toBe(0);
|
|
103
|
+
expect(
|
|
104
|
+
(parseYaml(fs.read("pnpm-workspace.yaml")) as { catalog: Record<string, string> }).catalog,
|
|
105
|
+
).toEqual(once);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Resolve a CLI tool's entry script through its package.json `bin` field, for
|
|
2
|
+
// tests that shell out to oxlint / oxfmt.
|
|
3
|
+
//
|
|
4
|
+
// Why not `node_modules/.bin/<tool>`? That shim is the right abstraction for a
|
|
5
|
+
// shell, but it cannot be spawned from Node without `shell: true`: the
|
|
6
|
+
// extensionless shim is an sh script (ENOENT on Windows) and the `.CMD` one is
|
|
7
|
+
// refused outright (EINVAL — Node's CVE-2024-27980 mitigation). Routing through
|
|
8
|
+
// a shell then hands the arguments to cmd.exe, which mangles any path holding a
|
|
9
|
+
// space or a `%`; these tests build paths under tmpdir(), so a machine whose
|
|
10
|
+
// user name contains a space would fail.
|
|
11
|
+
//
|
|
12
|
+
// The `bin` field is the same declarative contract the `.bin` shims are
|
|
13
|
+
// generated from, so reading it leaks no internal layout. It does assume the
|
|
14
|
+
// entry is a Node script — true for oxlint and oxfmt, and the assumption
|
|
15
|
+
// ts-builder's own executable resolver already makes.
|
|
16
|
+
|
|
17
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
|
|
21
|
+
/** `requireRoot` is the file to resolve from — it decides WHICH copy of the
|
|
22
|
+
* tool is found (e.g. ts-builder's pinned oxlint vs block-tools' own).
|
|
23
|
+
* Returns undefined when the tool is not installed, so callers can skip. */
|
|
24
|
+
export function resolveToolBin(
|
|
25
|
+
requireRoot: string,
|
|
26
|
+
packageName: string,
|
|
27
|
+
binName: string = packageName,
|
|
28
|
+
): string | undefined {
|
|
29
|
+
try {
|
|
30
|
+
const pkgJsonPath = createRequire(requireRoot).resolve(`${packageName}/package.json`);
|
|
31
|
+
const meta = JSON.parse(readFileSync(pkgJsonPath, "utf8")) as {
|
|
32
|
+
bin?: string | Record<string, string>;
|
|
33
|
+
};
|
|
34
|
+
const rel = typeof meta.bin === "string" ? meta.bin : meta.bin?.[binName];
|
|
35
|
+
if (rel === undefined) return undefined;
|
|
36
|
+
const binary = path.resolve(path.dirname(pkgJsonPath), rel);
|
|
37
|
+
return existsSync(binary) ? binary : undefined;
|
|
38
|
+
} catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -31,11 +31,18 @@ const VARS: BlockVars = {
|
|
|
31
31
|
const readMonorepoFile = (relativePath: string) =>
|
|
32
32
|
readFileSync(new URL(`../../../../../${relativePath}`, import.meta.url), "utf-8");
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const REFRESH_MODES = ["default", "update-deps-only"] as const;
|
|
35
|
+
|
|
36
|
+
function refresh(fs: MemoryFileSystem, mode: (typeof REFRESH_MODES)[number] = "default") {
|
|
37
|
+
return engineRun(
|
|
38
|
+
STRUCTURE,
|
|
39
|
+
fs,
|
|
40
|
+
discoverRunContext({ fs, isSdkInternal: false, updateDepsOnly: mode === "update-deps-only" }),
|
|
41
|
+
{
|
|
42
|
+
templates: defaultTemplateProvider(),
|
|
43
|
+
rediscover: () => discoverRunContext({ fs, isSdkInternal: false, dryRun: true }),
|
|
44
|
+
},
|
|
45
|
+
);
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
function editJson(fs: MemoryFileSystem, edit: (json: Record<string, unknown>) => void) {
|
|
@@ -67,7 +74,7 @@ describe("block toolchain", () => {
|
|
|
67
74
|
expect(workspace.allowBuilds).toMatchObject({ ...REQUIRED_BUILDS, ...SKIPPED_BUILDS });
|
|
68
75
|
});
|
|
69
76
|
|
|
70
|
-
test("refresh moves an old block to the SDK pnpm and Node", () => {
|
|
77
|
+
test.each(REFRESH_MODES)("refresh (%s) moves an old block to the SDK pnpm and Node", (mode) => {
|
|
71
78
|
const { fs } = simulateInit({ vars: VARS });
|
|
72
79
|
editJson(fs, (json) => {
|
|
73
80
|
json.packageManager = "pnpm@9.12.0";
|
|
@@ -80,7 +87,7 @@ describe("block toolchain", () => {
|
|
|
80
87
|
doc.setIn(["catalog", "turbo"], "~2.8.11");
|
|
81
88
|
});
|
|
82
89
|
|
|
83
|
-
refresh(fs);
|
|
90
|
+
refresh(fs, mode);
|
|
84
91
|
|
|
85
92
|
const pkg = JSON.parse(fs.read("package.json"));
|
|
86
93
|
expect(pkg.packageManager).toBe(PACKAGE_MANAGER);
|
|
@@ -146,11 +153,14 @@ describe("block toolchain", () => {
|
|
|
146
153
|
expect(workspace.allowBuilds).toEqual({ ...SKIPPED_BUILDS, ...REQUIRED_BUILDS });
|
|
147
154
|
});
|
|
148
155
|
|
|
149
|
-
test
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
test.each(REFRESH_MODES)(
|
|
157
|
+
"refresh (%s) refuses a package.json pnpm field with settings",
|
|
158
|
+
(mode) => {
|
|
159
|
+
const { fs } = simulateInit({ vars: VARS });
|
|
160
|
+
editJson(fs, (json) => {
|
|
161
|
+
json.pnpm = { overrides: { zod: "~3.25.76" } };
|
|
162
|
+
});
|
|
163
|
+
expect(() => refresh(fs, mode)).toThrow(/pnpm-workspace\.yaml/);
|
|
164
|
+
},
|
|
165
|
+
);
|
|
156
166
|
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// cross-block state).
|
|
7
7
|
|
|
8
8
|
import path from "node:path";
|
|
9
|
+
import { globSync, statSync } from "node:fs";
|
|
9
10
|
import { NodeFileSystem } from "../engine/fs/node";
|
|
10
11
|
import { NodeTemplateProvider } from "../engine/templates";
|
|
11
12
|
import { run as engineRun, type Change } from "../engine/runner";
|
|
@@ -89,6 +90,22 @@ export async function runStructureForPath(input: RunStructureInput): Promise<Run
|
|
|
89
90
|
return { blockPath: input.blockPath, changes: result.changes };
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
/** Expand glob patterns among the positional block paths. POSIX shells expand
|
|
94
|
+
* them before the CLI sees them, but cmd.exe does not — so on Windows
|
|
95
|
+
* `structure check etc/blocks/*` would otherwise receive the literal pattern
|
|
96
|
+
* and fail with "No workspace packages found". Only directories are kept, and
|
|
97
|
+
* arguments carrying no glob metacharacter pass through untouched. */
|
|
98
|
+
export function expandBlockPaths(paths: string[]): string[] {
|
|
99
|
+
const expanded = paths.flatMap((p) => {
|
|
100
|
+
if (!/[*?[]/.test(p)) return [p];
|
|
101
|
+
return globSync(p)
|
|
102
|
+
.filter((match) => statSync(match, { throwIfNoEntry: false })?.isDirectory() === true)
|
|
103
|
+
.map((match) => match.split(path.sep).join("/"))
|
|
104
|
+
.sort();
|
|
105
|
+
});
|
|
106
|
+
return [...new Set(expanded)];
|
|
107
|
+
}
|
|
108
|
+
|
|
92
109
|
/** One-line-per-change summary for CLI output. */
|
|
93
110
|
export function formatChanges(blockPath: string, changes: Change[]): string {
|
|
94
111
|
if (changes.length === 0) return ` ${blockPath}: up to date (0 changes)`;
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
// migrated block that never carried `@milaboratories/ts-builder` etc. now
|
|
15
15
|
// gets them ADDED on `--update-deps-only`, no manual catalog seed required.
|
|
16
16
|
//
|
|
17
|
+
// The same frame also applies the toolchain rules (SDK pnpm and Node, pnpm 12
|
|
18
|
+
// workspace settings), so `upgrade-sdk` runs its first `pnpm i` on the SDK
|
|
19
|
+
// pnpm with its release-age check.
|
|
20
|
+
//
|
|
17
21
|
// Wrapped in the same root-scope `when(!isSdkInternal)` guard as the rest of
|
|
18
22
|
// the root rules — internal blocks get their catalog from the parent
|
|
19
23
|
// monorepo, so catalog resolution never applies there.
|
|
@@ -27,11 +31,14 @@ import {
|
|
|
27
31
|
ensureCatalogLatest,
|
|
28
32
|
ensureCatalogVersion,
|
|
29
33
|
pinCatalogToDependencyOf,
|
|
34
|
+
enforceFieldOrder,
|
|
30
35
|
} from "../engine/api";
|
|
36
|
+
import { rootPackageJsonInitial, rootPackageJsonToolchainRules } from "./root-package-json";
|
|
37
|
+
import { canonicalPackageJsonOrder } from "./shared/key-order";
|
|
31
38
|
import {
|
|
32
39
|
rootPnpmWorkspaceInitial,
|
|
40
|
+
rootPnpmWorkspaceToolchainRules,
|
|
33
41
|
SDK_CATALOG_PACKAGES,
|
|
34
|
-
INFRA_CATALOG_FLOOR,
|
|
35
42
|
DERIVED_CATALOG_PINS,
|
|
36
43
|
RUNENV_PYTHON,
|
|
37
44
|
RUNENV_PYTHON_VERSION,
|
|
@@ -43,6 +50,14 @@ export function rootCatalogBumpRules(): void {
|
|
|
43
50
|
when(
|
|
44
51
|
({ ctx }) => !ctx.isSdkInternal,
|
|
45
52
|
() => {
|
|
53
|
+
managed(
|
|
54
|
+
"package.json",
|
|
55
|
+
generate(() => rootPackageJsonInitial()),
|
|
56
|
+
() => {
|
|
57
|
+
rootPackageJsonToolchainRules();
|
|
58
|
+
enforceFieldOrder([...canonicalPackageJsonOrder]);
|
|
59
|
+
},
|
|
60
|
+
);
|
|
46
61
|
// On init, the default root rules create pnpm-workspace.yaml from
|
|
47
62
|
// this same generator (the curated SDK placeholders + infra
|
|
48
63
|
// floor); this leaf then overwrites the SDK entries with npm
|
|
@@ -67,17 +82,18 @@ export function rootCatalogBumpRules(): void {
|
|
|
67
82
|
for (const pin of DERIVED_CATALOG_PINS) {
|
|
68
83
|
pinCatalogToDependencyOf(pin.entry, { of: pin.of, ofVersion: pin.ofVersion });
|
|
69
84
|
}
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
// The curated infra floor is seeded by `rootPnpmWorkspaceRules`,
|
|
86
|
+
// which runs on every refresh — the root package.json rules hand
|
|
87
|
+
// out `catalog:` references for those entries on every refresh
|
|
88
|
+
// too, so seeding them only here would leave a plain refresh with
|
|
89
|
+
// an unresolvable reference.
|
|
90
|
+
//
|
|
76
91
|
// The python runenv pin is relevant only to software-bearing
|
|
77
92
|
// blocks; seed it add-if-absent when one is present.
|
|
78
93
|
if (ctx.modules.some((m) => m.scope === "software")) {
|
|
79
94
|
ensureCatalogVersion(RUNENV_PYTHON, RUNENV_PYTHON_VERSION);
|
|
80
95
|
}
|
|
96
|
+
rootPnpmWorkspaceToolchainRules();
|
|
81
97
|
},
|
|
82
98
|
);
|
|
83
99
|
},
|
|
@@ -21,24 +21,27 @@ import { NODE_RUNTIME, PACKAGE_MANAGER } from "./shared/toolchain";
|
|
|
21
21
|
|
|
22
22
|
// `variant=all` builds every variant the software declares — docker-vs-binary is not a per-script
|
|
23
23
|
// choice. `no-software` builds placeholder software for validators.
|
|
24
|
+
//
|
|
25
|
+
// `cross-env` rather than a bare `VAR=value` prefix or `env`: package scripts run through cmd.exe
|
|
26
|
+
// on Windows, which has neither. Without it every one of these dies with "'env' is not recognized".
|
|
24
27
|
|
|
25
28
|
const BUILD_SCRIPTS: Record<string, string> = {
|
|
26
29
|
"build:dev-local":
|
|
27
|
-
"env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=all PL_BUILD_LOCATION=local turbo run build",
|
|
30
|
+
"cross-env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=all PL_BUILD_LOCATION=local turbo run build",
|
|
28
31
|
"build:dev-remote":
|
|
29
|
-
"env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=all PL_BUILD_LOCATION=remote turbo run build",
|
|
30
|
-
"build:dev-no-software": "env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=none turbo run build",
|
|
32
|
+
"cross-env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=all PL_BUILD_LOCATION=remote turbo run build",
|
|
33
|
+
"build:dev-no-software": "cross-env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=none turbo run build",
|
|
31
34
|
"build:dev-binary-existing":
|
|
32
|
-
"env PL_BUILD_CHANNEL=dev PL_BUILD_USE_PUBLISHED=true turbo run build",
|
|
35
|
+
"cross-env PL_BUILD_CHANNEL=dev PL_BUILD_USE_PUBLISHED=true turbo run build",
|
|
33
36
|
"build:release":
|
|
34
|
-
"env PL_BUILD_CHANNEL=release PL_BUILD_VARIANT=all PL_BUILD_LOCATION=remote turbo run build",
|
|
37
|
+
"cross-env PL_BUILD_CHANNEL=release PL_BUILD_VARIANT=all PL_BUILD_LOCATION=remote turbo run build",
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
// `test` / `test:dry-run` run the build-then-test DAG in the dev-binary-local target; the live
|
|
38
41
|
// backend's env reaches the integration tests via the turbo `test` task's passThroughEnv.
|
|
39
42
|
const TEST_SCRIPTS: Record<string, string> = {
|
|
40
|
-
test: `env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=binary PL_BUILD_LOCATION=local turbo run test --concurrency 1`,
|
|
41
|
-
"test:dry-run": `env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=binary PL_BUILD_LOCATION=local turbo run test --dry-run=json`,
|
|
43
|
+
test: `cross-env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=binary PL_BUILD_LOCATION=local turbo run test --concurrency 1`,
|
|
44
|
+
"test:dry-run": `cross-env PL_BUILD_CHANNEL=dev PL_BUILD_VARIANT=binary PL_BUILD_LOCATION=local turbo run test --dry-run=json`,
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
export function rootPackageJsonInitial(): Record<string, unknown> {
|
|
@@ -70,13 +73,14 @@ export function rootPackageJsonInitial(): Record<string, unknown> {
|
|
|
70
73
|
"@changesets/cli": "catalog:",
|
|
71
74
|
"@milaboratories/ts-builder": "sdk:",
|
|
72
75
|
"@platforma-sdk/block-tools": "sdk:",
|
|
76
|
+
"cross-env": "catalog:",
|
|
73
77
|
shx: "catalog:",
|
|
74
78
|
turbo: "catalog:",
|
|
75
79
|
},
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
export function
|
|
83
|
+
export function rootPackageJsonToolchainRules(): void {
|
|
80
84
|
ensureField("packageManager", PACKAGE_MANAGER);
|
|
81
85
|
ensureField("devEngines.runtime", NODE_RUNTIME);
|
|
82
86
|
removeField(
|
|
@@ -92,6 +96,10 @@ export function rootPackageJsonRules(): void {
|
|
|
92
96
|
"pnpm",
|
|
93
97
|
'pnpm 11+ ignores the "pnpm" field in package.json. Move its settings to pnpm-workspace.yaml: overrides as is, onlyBuiltDependencies as allowBuilds true, neverBuiltDependencies as allowBuilds false.',
|
|
94
98
|
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function rootPackageJsonRules(): void {
|
|
102
|
+
rootPackageJsonToolchainRules();
|
|
95
103
|
|
|
96
104
|
// Root is never published — it carries no `name`; delete any stray one.
|
|
97
105
|
removeField("name");
|
|
@@ -135,6 +143,7 @@ export function rootPackageJsonRules(): void {
|
|
|
135
143
|
"@changesets/cli": "catalog:",
|
|
136
144
|
"@milaboratories/ts-builder": "sdk:",
|
|
137
145
|
"@platforma-sdk/block-tools": "sdk:",
|
|
146
|
+
"cross-env": "catalog:",
|
|
138
147
|
shx: "catalog:",
|
|
139
148
|
turbo: "catalog:",
|
|
140
149
|
});
|