@wildshard/build 0.0.0 → 0.4.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/build.mjs +45194 -0
- package/package.json +73 -5
- package/scripts/decision-legacy-lines.d.mts +4 -0
- package/scripts/decision-legacy-lines.mjs +30 -0
- package/scripts/shard-outputs.d.mts +20 -0
- package/scripts/shard-outputs.mjs +98 -0
- package/src/.oxlintrc.json +12 -0
- package/src/sharddev/buildMain.ts +62 -0
- package/src/sharddev/buildVerb.ts +163 -0
- package/src/sharddev/project.ts +369 -0
- package/src/sharddev/synth.ts +64 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,13 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/build",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "The build: read a shard source, run its generators, write and validate the shard file (SDK-SPLIT SP9c; the build verb, SP9d1). Engine-free; published with the sdk at one version (D5, SP12).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=24.18.0"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"wildshard-build": "./dist/build.mjs"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"scripts/*.mjs",
|
|
16
|
+
"scripts/*.d.mts",
|
|
17
|
+
"!scripts/compile.mjs",
|
|
18
|
+
"!src/**/*.test.*"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@gltf-transform/core": "4.5.0",
|
|
22
|
+
"@gltf-transform/extensions": "4.5.0",
|
|
23
|
+
"@gltf-transform/functions": "4.5.0",
|
|
24
|
+
"@types/three": "0.186.0",
|
|
25
|
+
"@typescript/typescript6": "6.0.2",
|
|
26
|
+
"@valibot/to-json-schema": "1.8.0",
|
|
27
|
+
"@wildshard/format": "npm:@wildshard/shard-format@0.23.0",
|
|
28
|
+
"ajv": "6.15.0",
|
|
29
|
+
"assemblyscript": "0.28.20",
|
|
30
|
+
"binaryen": "132.0.0",
|
|
31
|
+
"fflate": "0.8.3",
|
|
32
|
+
"meshoptimizer": "1.2.0",
|
|
33
|
+
"rolldown": "1.2.16",
|
|
34
|
+
"sharp": "0.35.5",
|
|
35
|
+
"valibot": "1.5.0",
|
|
36
|
+
"@wildshard/sdk": "0.4.0",
|
|
37
|
+
"@wildshard/kit": "0.4.0",
|
|
38
|
+
"@wildshard/upload": "0.4.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "24.3.1",
|
|
42
|
+
"esbuild": "0.28.2",
|
|
43
|
+
"three": "0.186.0",
|
|
44
|
+
"vite": "8.3.0",
|
|
45
|
+
"vitest": "5.0.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"three": "0.186.0"
|
|
49
|
+
},
|
|
50
|
+
"exports": {
|
|
51
|
+
"./package.json": "./package.json",
|
|
52
|
+
"./project": "./src/sharddev/project.ts",
|
|
53
|
+
"./synth": "./src/sharddev/synth.ts",
|
|
54
|
+
"./buildVerb": "./src/sharddev/buildVerb.ts",
|
|
55
|
+
"./scripts/shard-outputs.mjs": {
|
|
56
|
+
"types": "./scripts/shard-outputs.d.mts",
|
|
57
|
+
"default": "./scripts/shard-outputs.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./scripts/decision-legacy-lines.mjs": {
|
|
60
|
+
"types": "./scripts/decision-legacy-lines.d.mts",
|
|
61
|
+
"default": "./scripts/decision-legacy-lines.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./buildMain": "./src/sharddev/buildMain.ts"
|
|
64
|
+
},
|
|
6
65
|
"repository": {
|
|
7
66
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/project-wildshard/sharddev.git"
|
|
67
|
+
"url": "git+https://github.com/project-wildshard/sharddev.git",
|
|
68
|
+
"directory": "packages/build"
|
|
9
69
|
},
|
|
70
|
+
"license": "UNLICENSED",
|
|
10
71
|
"publishConfig": {
|
|
11
72
|
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"lint:kit": "node ../../kit/scripts/lint.mjs --type-aware --deny-warnings --ignore-pattern 'src/sharddev/**' --no-error-on-unmatched-pattern src",
|
|
76
|
+
"lint:author": "WILDSHARD_RATCHET_FILE=lint/ratchet.json node ../../kit/scripts/bin-tools.mjs -c .oxlintrc.author.json --deny-warnings src/sharddev",
|
|
77
|
+
"test": "pnpm test:author",
|
|
78
|
+
"test:author": "vitest run",
|
|
79
|
+
"compile": "node scripts/compile.mjs"
|
|
12
80
|
}
|
|
13
|
-
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Repo-only pinned denominator; the public SDK receives only its numeric result. */
|
|
2
|
+
export function decisionLegacyLines(root: string, slug: string): number | undefined;
|
|
3
|
+
/** Shard-keyed build and ruler baselines, independent of the frozen folder inventory. */
|
|
4
|
+
export function shardLineBaselines(root: string): ReadonlyMap<string, {source: string; lines: number}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Repo-only build policy: the SDK receives a number and never reads lint inventories.
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import * as v from 'valibot';
|
|
5
|
+
|
|
6
|
+
const pathSchema = v.pipe(v.string(), v.check(path => path.length > 0 && !path.startsWith('/') && !path.includes('\\') && path.split('/').every(part => part !== '' && part !== '.' && part !== '..')));
|
|
7
|
+
const basisSchema = v.strictObject({ schema: v.literal('legacy-line-basis/1'), revision: v.pipe(v.string(), v.regex(/^[a-f0-9]{40}$/u)),
|
|
8
|
+
shards: v.record(pathSchema, v.strictObject({ source: v.pipe(v.string(), v.regex(/^[a-f0-9]{40}$/u)),
|
|
9
|
+
excluded: v.array(pathSchema), files: v.record(pathSchema, v.pipe(v.number(), v.integer(), v.minValue(0))) })) });
|
|
10
|
+
// The historical producer exclusions and per-file counts are pinned at 1258254a3.
|
|
11
|
+
// Never recount with today's producer catalogue or compatibility-only frozen edits:
|
|
12
|
+
// e45fe0e4d and a888b0ac1 moved the denominator without removing custom work.
|
|
13
|
+
// See progress/shard-platform/ruler-basis-2026-10-17/README.md for the audit.
|
|
14
|
+
function lineBasis(root) {
|
|
15
|
+
return v.parse(basisSchema, JSON.parse(readFileSync(resolve(root, 'lint/legacy-line-basis.json'), 'utf8')));
|
|
16
|
+
}
|
|
17
|
+
/** Shard-owned historical counts survive retirement of the frozen folder list.
|
|
18
|
+
* The checked-in basis declares both the unchanged AS denominator and provenance. */
|
|
19
|
+
export function shardLineBaselines(root) {
|
|
20
|
+
if (!existsSync(resolve(root, 'lint/legacy-line-basis.json'))) return new Map();
|
|
21
|
+
return new Map(Object.entries(lineBasis(root).shards).map(([slug, pinned]) => {
|
|
22
|
+
const lines = Object.values(pinned.files).reduce((total, amount) => total + amount, 0);
|
|
23
|
+
if (lines <= 0) throw new Error(`${slug}: pinned basis has no authored TypeScript lines`);
|
|
24
|
+
return [slug, { source: pinned.source, lines }];
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
/** Same pinned denominator for the official build adapter and P4 ruler; no inventory lookup. */
|
|
28
|
+
export function decisionLegacyLines(root, slug) {
|
|
29
|
+
return shardLineBaselines(root).get(slug)?.lines;
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** One declared output row of `src/shards/<folder>/outputs.json`: its product slug, manifest overrides and the shard's own fields. */
|
|
2
|
+
export interface ShardOutputRow { readonly slug: string; readonly manifest?: Readonly<Record<string, unknown>>; readonly [field: string]: unknown }
|
|
3
|
+
/** A product of the shard folders: an output of a folder, or the folder itself (`output` null). */
|
|
4
|
+
export interface ShardFolder { readonly slug: string; readonly folder: string; readonly output: ShardOutputRow | null }
|
|
5
|
+
export function mergeManifest(base: unknown, over: unknown): unknown;
|
|
6
|
+
/** SA42: a single-shard repo's folder name (its source at `src/`), or null. */
|
|
7
|
+
export function singleShardFolder(root: string): string | null;
|
|
8
|
+
/** SA42: a shard folder's source directory, `src/` or `src/shards/<folder>`. */
|
|
9
|
+
export function shardSourceDir(root: string, folder: string): string;
|
|
10
|
+
/** SA42: the tree holds shard source in either layout. */
|
|
11
|
+
export function hasShardSource(root: string): boolean;
|
|
12
|
+
/** SA42: the source folders holding one of `markers`, in either layout, sorted. */
|
|
13
|
+
export function shardSourceFolders(root: string, markers: readonly string[]): string[];
|
|
14
|
+
export function shardOutputs(root: string, folder: string): { slug: string; folder: string; row: ShardOutputRow }[] | null;
|
|
15
|
+
export function builtShardFolders(root: string, folders: readonly string[]): ShardFolder[];
|
|
16
|
+
export function outputManifest(root: string, folder: string, output: ShardOutputRow): Record<string, unknown>;
|
|
17
|
+
export function manifestFolders(root: string): string[];
|
|
18
|
+
export function outputFolderOf(root: string, slug: string): string;
|
|
19
|
+
/** The built product that stands for a source shard in per-shard measures (its first output, else itself). */
|
|
20
|
+
export function representativeFolder(root: string, slug: string): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// SF88g (G538/G539): one source folder may emit several shardfile products. `src/shards/<folder>/outputs.json` lists them:
|
|
2
|
+
// `{ "outputs": [{ "slug": "<product slug>", "manifest": { …overrides of the folder's manifest.json }, …the shard's own
|
|
3
|
+
// fields }] }`. Without the file a folder is one product whose slug is its name. Every tool that lists products (discovery,
|
|
4
|
+
// the slug table, the shardfile build, the catalogue) reads them through here; the folder's manifest.json is then the
|
|
5
|
+
// shared base each output's overrides merge into (plain objects merge, everything else replaces).
|
|
6
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
7
|
+
import { basename, relative, resolve } from 'node:path';
|
|
8
|
+
|
|
9
|
+
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
10
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
11
|
+
const plain = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
12
|
+
/** @param {string} file @returns {unknown} */
|
|
13
|
+
const readJson = (file) => { try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return undefined; } };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* SA42 (J317, sharddev SA16 `shardSource.ts`): a single-shard repo keeps its shard source at `src/` (its `src/shard.config.ts`, or a
|
|
17
|
+
* hand-written shard file folder `src/shard.json` with no config), a multi-shard repo at `src/shards/<folder>/`. The single source's
|
|
18
|
+
* folder name is a hand-written index's `identity.slug`, else its manifest's slug, else the repo folder's name, as sharddev names it.
|
|
19
|
+
* Null for a repo with no single-shard source. @param {string} root @returns {string | null}
|
|
20
|
+
*/
|
|
21
|
+
export function singleShardFolder(root) {
|
|
22
|
+
const src = resolve(root, 'src'), config = existsSync(resolve(src, 'shard.config.ts'));
|
|
23
|
+
const handwritten = !config && existsSync(resolve(src, 'shard.json'));
|
|
24
|
+
if (!config && !handwritten) return null;
|
|
25
|
+
if (handwritten) {
|
|
26
|
+
const index = readJson(resolve(src, 'shard.json'));
|
|
27
|
+
if (plain(index) && plain(index.identity) && typeof index.identity.slug === 'string') return index.identity.slug;
|
|
28
|
+
}
|
|
29
|
+
const manifest = readJson(resolve(src, 'manifest.json'));
|
|
30
|
+
return plain(manifest) && typeof manifest.slug === 'string' ? manifest.slug : basename(resolve(root));
|
|
31
|
+
}
|
|
32
|
+
/** SA42: a shard folder's source directory: `src/` for the single-shard repo's own folder, else `src/shards/<folder>`. @param {string} root @param {string} folder */
|
|
33
|
+
export function shardSourceDir(root, folder) {
|
|
34
|
+
return singleShardFolder(root) === folder ? resolve(root, 'src') : resolve(root, 'src/shards', folder);
|
|
35
|
+
}
|
|
36
|
+
/** SA42: this tree holds shard source in either layout (P3: a tree with none reads pinned products only). @param {string} root */
|
|
37
|
+
export function hasShardSource(root) {
|
|
38
|
+
return singleShardFolder(root) !== null || existsSync(resolve(root, 'src/shards'));
|
|
39
|
+
}
|
|
40
|
+
/** SA42: the source folders holding one of `markers` (a manifest, `shard.config.ts`): `src/shards/*` and a single-shard repo's own, sorted.
|
|
41
|
+
* @param {string} root @param {readonly string[]} markers */
|
|
42
|
+
export function shardSourceFolders(root, markers) {
|
|
43
|
+
const single = singleShardFolder(root), shards = resolve(root, 'src/shards');
|
|
44
|
+
const folders = existsSync(shards) ? readdirSync(shards, { withFileTypes: true })
|
|
45
|
+
.filter((entry) => entry.isDirectory() && markers.some((file) => existsSync(resolve(shards, entry.name, file)))).map((entry) => entry.name) : [];
|
|
46
|
+
if (single !== null && !folders.includes(single) && markers.some((file) => existsSync(resolve(root, 'src', file)))) folders.push(single);
|
|
47
|
+
return folders.sort();
|
|
48
|
+
}
|
|
49
|
+
/** Deep-merge plain objects (`over` wins); arrays and scalars replace. @param {unknown} base @param {unknown} over @returns {unknown} */
|
|
50
|
+
export function mergeManifest(base, over) {
|
|
51
|
+
if (!plain(base) || !plain(over)) return over === undefined ? base : over;
|
|
52
|
+
/** @type {Record<string, unknown>} */
|
|
53
|
+
const out = { ...base };
|
|
54
|
+
for (const [key, value] of Object.entries(over)) out[key] = mergeManifest(base[key], value);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/** A folder's declared outputs, or null for a one-product folder. @param {string} root @param {string} folder */
|
|
58
|
+
export function shardOutputs(root, folder) {
|
|
59
|
+
const file = resolve(shardSourceDir(root, folder), 'outputs.json'), named = relative(resolve(root), file);
|
|
60
|
+
if (!existsSync(file)) return null;
|
|
61
|
+
const rows = JSON.parse(readFileSync(file, 'utf8')).outputs;
|
|
62
|
+
if (!Array.isArray(rows) || rows.length === 0) throw new Error(`${named}: needs a nonempty outputs list`);
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
return rows.map((row) => {
|
|
65
|
+
if (!plain(row) || typeof row.slug !== 'string' || !SLUG.test(row.slug) || seen.has(row.slug) || row.slug === folder) throw new Error(`${named}: invalid or duplicate output slug ${String(row?.slug)}`);
|
|
66
|
+
if (row.manifest !== undefined && !plain(row.manifest)) throw new Error(`${named}: ${row.slug} manifest overrides must be an object`);
|
|
67
|
+
seen.add(row.slug);
|
|
68
|
+
return { slug: row.slug, folder, row };
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Every product of the shard folders: `{ slug, folder, output }` (output null for a one-product folder), sorted by slug.
|
|
72
|
+
* @param {string} root @param {readonly string[]} folders */
|
|
73
|
+
export function builtShardFolders(root, folders) {
|
|
74
|
+
const products = folders.flatMap((folder) => shardOutputs(root, folder)?.map((output) => ({ slug: output.slug, folder, output: output.row })) ?? [{ slug: folder, folder, output: null }]);
|
|
75
|
+
const slugs = products.map((row) => row.slug);
|
|
76
|
+
if (new Set(slugs).size !== slugs.length) throw new Error('shard outputs: a product slug is declared twice');
|
|
77
|
+
return products.sort((a, b) => a.slug.localeCompare(b.slug));
|
|
78
|
+
}
|
|
79
|
+
/** An output's authored manifest: the folder base with its overrides, its slug, canonical shardfile path and data map.
|
|
80
|
+
* @param {string} root @param {string} folder @param {{ slug: string, manifest?: object }} output */
|
|
81
|
+
export function outputManifest(root, folder, output) {
|
|
82
|
+
const base = JSON.parse(readFileSync(resolve(shardSourceDir(root, folder), 'manifest.json'), 'utf8'));
|
|
83
|
+
return mergeManifest(base, { ...output.manifest, slug: output.slug, shardfile: `/shardfiles/${output.slug}/shard.json`, minimap: { image: `/assets/${output.slug}/map/top.webp` } });
|
|
84
|
+
}
|
|
85
|
+
/** The shard folders with a manifest: under src/shards, or a single-shard repo's src/ (SA42). P3: a tree with no shard source has none. @param {string} root */
|
|
86
|
+
export function manifestFolders(root) {
|
|
87
|
+
return shardSourceFolders(root, ['manifest.ts', 'manifest.json']);
|
|
88
|
+
}
|
|
89
|
+
/** The source folder of a product slug (itself for a one-product folder). @param {string} root @param {string} slug */
|
|
90
|
+
export function outputFolderOf(root, slug) {
|
|
91
|
+
return builtShardFolders(root, manifestFolders(root)).find((row) => row.slug === slug)?.folder ?? slug;
|
|
92
|
+
}
|
|
93
|
+
/** The built product that stands for a source shard in per-shard measures: a folder that emits several outputs (all from
|
|
94
|
+
* one source, sharing its structure and scripts) is read through its first output; any other folder is its own product.
|
|
95
|
+
* Section inventories union every output (scripts/output-reader.mjs). @param {string} root @param {string} slug */
|
|
96
|
+
export function representativeFolder(root, slug) {
|
|
97
|
+
return (/^[a-z0-9_-]+$/u.test(slug) ? shardOutputs(root, slug)?.[0]?.slug : undefined) ?? slug;
|
|
98
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../sdk/node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"extends": ["../../../kit/.oxlintrc.json"],
|
|
4
|
+
// oxlint does not inherit ignorePatterns through extends (K11, J329).
|
|
5
|
+
"ignorePatterns": [
|
|
6
|
+
"scripts/**",
|
|
7
|
+
"dist/**",
|
|
8
|
+
"test/fixtures/**",
|
|
9
|
+
"test-results/**",
|
|
10
|
+
"playwright-report/**"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// SDK-SPLIT SP9d2: `wildshard-build <source> [folder] [flags]`, build's own bin. It runs the same verb as `wildshard build`
|
|
2
|
+
// (buildVerb.ts) with the same options dev's scripts/wildshard.mjs composes (declared outputs, the composed manifest, the
|
|
3
|
+
// legacy line basis, upload's shard file writer), but needs no dev, no engine and no run-time bundle of the CLI:
|
|
4
|
+
// scripts/compile.mjs compiles it to dist/build.mjs at pack time.
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The verb reads the author's repo.
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The verb resolves the author's paths.
|
|
8
|
+
import { basename, resolve } from 'node:path';
|
|
9
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Exit status and argv.
|
|
10
|
+
import process from 'node:process';
|
|
11
|
+
import { locatedError } from '@wildshard/sdk/internal/authorError';
|
|
12
|
+
import type { ProjectManifestSource } from '@wildshard/sdk/projectManifest';
|
|
13
|
+
import { writeShardfile } from '@wildshard/upload/cli/shardfile/shardfile';
|
|
14
|
+
import { refusalCode, refusalHint, refusalNote } from '@wildshard/upload/sharddev/refusals';
|
|
15
|
+
import { findShardSource, shardFolderName } from '@wildshard/upload/sharddev/shardSource';
|
|
16
|
+
import { decisionLegacyLines } from '../../scripts/decision-legacy-lines.mjs';
|
|
17
|
+
import { outputManifest, shardOutputs } from '../../scripts/shard-outputs.mjs';
|
|
18
|
+
import { runBuild, ShardfileRefusalError, type BuildVerbOptions } from './buildVerb';
|
|
19
|
+
|
|
20
|
+
const USAGE = 'usage: wildshard-build <source> [folder] [--shardfile-only|--folder-only] [--no-placeholders] [--output=<slug>]';
|
|
21
|
+
|
|
22
|
+
/** The options dev's scripts/wildshard.mjs gives `build` for the source `project`, read from the repo at `root`. */
|
|
23
|
+
function buildOptions(root: string, project: string, selected: string | undefined): BuildVerbOptions {
|
|
24
|
+
// The folder build checks the manifest slug against: a src/ source takes its manifest's slug (new <dir> <slug>).
|
|
25
|
+
const folder = shardFolderName(project);
|
|
26
|
+
// SF88g: `--output=<slug>` builds one declared output of the folder, under its own slug and composed manifest.
|
|
27
|
+
const output = selected === undefined ? undefined : new Map((shardOutputs(root, folder) ?? []).map(row => [row.slug, row])).get(selected);
|
|
28
|
+
if (selected !== undefined && output === undefined) throw new Error(`wildshard-build: ${basename(project)} declares no output ${selected}`);
|
|
29
|
+
const manifest: ProjectManifestSource | undefined = !existsSync(resolve(project, 'shard.config.ts')) ? undefined : {
|
|
30
|
+
folder: output?.slug ?? folder,
|
|
31
|
+
...(output !== undefined ? { composed: outputManifest(root, folder, output.row) } : existsSync(resolve(project, 'manifest.json')) ? { file: resolve(project, 'manifest.json') } : {}),
|
|
32
|
+
imageRoots: [{ prefix: `/src/shards/${folder}/`, directory: project }, { prefix: '/assets/', directory: resolve(root, 'public/assets') }],
|
|
33
|
+
};
|
|
34
|
+
const legacy = decisionLegacyLines(root, folder);
|
|
35
|
+
return {
|
|
36
|
+
...(legacy === undefined ? {} : { decisionLegacyLines: legacy }),
|
|
37
|
+
...(manifest === undefined ? {} : { manifest }),
|
|
38
|
+
writeShardfile: async (dir, source) => (await writeShardfile({ dir, source, report: line => console.info(line) })).file,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The refusal with its rule, fix and GUIDE.md link on a second line, as `wildshard build` prints it. */
|
|
43
|
+
function refusal(error: unknown): string {
|
|
44
|
+
const located = locatedError(error);
|
|
45
|
+
const message = located instanceof Error ? located.message : String(located);
|
|
46
|
+
return `${message}\n ${refusalHint(refusalNote(error instanceof ShardfileRefusalError ? 'shardfile' : 'build', message, { code: refusalCode(error) }))}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Run `wildshard-build` with `args` (the words after the bin) from the repo at `root`. */
|
|
50
|
+
export async function buildMain(args: readonly string[], root: string): Promise<void> {
|
|
51
|
+
const [operand, ...rest] = args;
|
|
52
|
+
if (operand === undefined || operand.startsWith('-')) throw new Error(USAGE);
|
|
53
|
+
// SA16 (J317): a repo path names its shard source at src/ (one shard) or its one src/shards/<slug>/ (several).
|
|
54
|
+
const project = resolve(findShardSource(operand));
|
|
55
|
+
const selected = rest.find(arg => arg.startsWith('--output='))?.slice('--output='.length);
|
|
56
|
+
try { await runBuild(project, rest, buildOptions(root, project, selected)); } catch (error) { throw new Error(refusal(error), { cause: error }); }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The bin: the repo is the folder the author stands in. */
|
|
60
|
+
export async function main(): Promise<void> {
|
|
61
|
+
try { await buildMain(process.argv.slice(2), process.cwd()); } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }
|
|
62
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// SDK-SPLIT SP9d1: the `wildshard build` verb is build's. Dev's author CLI (packages/dev/src/sharddev/cli.ts) hands its
|
|
2
|
+
// `build` branch here, and SP9d2's compiled entry runs the same function, so a build never loads the engine.
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The verb resolves the author's paths.
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
import { STILL_IMAGE_LIMITS } from '@wildshard/format/stillImage'
|
|
7
|
+
import { buildBehaviourProject } from '@wildshard/sdk/buildBehaviour'
|
|
8
|
+
import {
|
|
9
|
+
performanceReport,
|
|
10
|
+
performanceReportLines,
|
|
11
|
+
type PerformanceObservations,
|
|
12
|
+
} from '@wildshard/sdk/reportCard'
|
|
13
|
+
import { readBoundedFile } from '@wildshard/sdk/sourceReader'
|
|
14
|
+
import { shardOutputRoot } from '@wildshard/upload/sharddev/shardSource'
|
|
15
|
+
|
|
16
|
+
import { buildProject } from '../sharddev/project'
|
|
17
|
+
|
|
18
|
+
import type { Shardfile } from '@wildshard/format/shardSchema'
|
|
19
|
+
import type { ProjectManifestSource } from '@wildshard/sdk/projectManifest'
|
|
20
|
+
|
|
21
|
+
// The flags `build <source> [folder]` takes after the folder.
|
|
22
|
+
const KNOWN_FLAG =
|
|
23
|
+
/^--(?:shardfile-only|folder-only|product-only|no-placeholders|format=2|copy-runtime)$|^--(?:map|map-tiles-hash|output|generated-map-tiles-hash)=/u
|
|
24
|
+
const unmeasured: PerformanceObservations = {
|
|
25
|
+
scripts: { p95Micros: 0, maxMicros: 0, samples: 0 },
|
|
26
|
+
fuel: { p95: 0, max: 0, samples: 0 },
|
|
27
|
+
}
|
|
28
|
+
/** The performance report's static half (declared bounds, downloads, memory): every refusal stands except the missing
|
|
29
|
+
* execution samples, which `wildshard check` measures (SP7c). */
|
|
30
|
+
export function printStaticReport(
|
|
31
|
+
shard: Shardfile,
|
|
32
|
+
policy: 'warn' | 'refuse',
|
|
33
|
+
): void {
|
|
34
|
+
const report = performanceReport(shard, unmeasured, policy)
|
|
35
|
+
for (const line of performanceReportLines(report)) console.info(line)
|
|
36
|
+
if (
|
|
37
|
+
report.issues.some(
|
|
38
|
+
issue =>
|
|
39
|
+
issue.severity === 'refusal' &&
|
|
40
|
+
issue.code !== 'perf-script-samples-missing',
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
throw new Error('Performance report refused this shard')
|
|
44
|
+
}
|
|
45
|
+
/** SA3: writes a built folder's shard file (hero check against `source`, format and audio checks) and returns its path;
|
|
46
|
+
* scripts/wildshard.mjs gives it. `draftWarning: false` leaves the draft warning (J198) to the caller. */
|
|
47
|
+
export type ShardfileWriter = (
|
|
48
|
+
folder: string,
|
|
49
|
+
source: string,
|
|
50
|
+
options?: { readonly draftWarning?: boolean },
|
|
51
|
+
) => Promise<string>
|
|
52
|
+
/** A refusal from the shard file step, named by its own rules (SA3), not build's source rules. */
|
|
53
|
+
export class ShardfileRefusalError extends Error {
|
|
54
|
+
override readonly name = 'ShardfileRefusalError'
|
|
55
|
+
}
|
|
56
|
+
export interface BuildVerbOptions {
|
|
57
|
+
readonly decisionLegacyLines?: number
|
|
58
|
+
readonly manifest?: ProjectManifestSource
|
|
59
|
+
readonly writeShardfile?: ShardfileWriter
|
|
60
|
+
}
|
|
61
|
+
export async function writeShardfileOf(
|
|
62
|
+
options: BuildVerbOptions,
|
|
63
|
+
folder: string,
|
|
64
|
+
source: string,
|
|
65
|
+
): Promise<void> {
|
|
66
|
+
try {
|
|
67
|
+
await options.writeShardfile?.(folder, source)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
throw new ShardfileRefusalError(
|
|
70
|
+
error instanceof Error ? error.message : String(error),
|
|
71
|
+
{ cause: error },
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** `wildshard build <source> [folder] [flags]` and `build <source> --behaviour-only [--check]`; `input` is the shard source
|
|
76
|
+
* the caller found (SA16), `rest` the words after it. */
|
|
77
|
+
export async function runBuild(
|
|
78
|
+
input: string,
|
|
79
|
+
rest: readonly string[],
|
|
80
|
+
options: BuildVerbOptions,
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
const [output, buildFlag] = rest
|
|
83
|
+
if (
|
|
84
|
+
output === '--behaviour-only' &&
|
|
85
|
+
(buildFlag === undefined || buildFlag === '--check')
|
|
86
|
+
) {
|
|
87
|
+
const files = await buildBehaviourProject(resolve(input), {
|
|
88
|
+
check: buildFlag === '--check',
|
|
89
|
+
})
|
|
90
|
+
console.info(`built ${files.length} native behaviour outputs`)
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
// A flag straight after the project is a flag, not the output folder.
|
|
94
|
+
const folder = output?.startsWith('--') === true ? undefined : output
|
|
95
|
+
const flags = rest.slice(folder === undefined ? 0 : 1)
|
|
96
|
+
const value = (prefix: string): string | undefined =>
|
|
97
|
+
flags.find(flag => flag.startsWith(prefix))?.slice(prefix.length)
|
|
98
|
+
const count = (prefix: string): number =>
|
|
99
|
+
flags.filter(flag => flag.startsWith(prefix)).length
|
|
100
|
+
const mapSourceHash = value('--generated-map-tiles-hash='),
|
|
101
|
+
mapPath = value('--map='),
|
|
102
|
+
tilesHash = value('--map-tiles-hash='),
|
|
103
|
+
selected = value('--output=')
|
|
104
|
+
// SA3: --shardfile-only skips the client; --folder-only also skips the shard file, for build-shards, whose folders are
|
|
105
|
+
// cached and prepared before anything tars them. --product-only keeps its old meaning: --folder-only.
|
|
106
|
+
const folderOnly =
|
|
107
|
+
flags.includes('--folder-only') || flags.includes('--product-only'),
|
|
108
|
+
noClient = folderOnly || flags.includes('--shardfile-only')
|
|
109
|
+
const unknownFlag = flags.find(flag => !KNOWN_FLAG.test(flag))
|
|
110
|
+
if (unknownFlag !== undefined)
|
|
111
|
+
throw new Error(`unknown build flag: ${unknownFlag}`)
|
|
112
|
+
if (
|
|
113
|
+
count('--output=') > 1 ||
|
|
114
|
+
flags.length !== new Set(flags).size ||
|
|
115
|
+
count('--map=') > 1 ||
|
|
116
|
+
count('--map-tiles-hash=') > 1 ||
|
|
117
|
+
count('--generated-map-tiles-hash=') > 1 ||
|
|
118
|
+
(mapSourceHash !== undefined && mapPath !== undefined) ||
|
|
119
|
+
(mapPath === undefined) !== (tilesHash === undefined)
|
|
120
|
+
)
|
|
121
|
+
throw new Error('unknown or incomplete build map flag')
|
|
122
|
+
const map =
|
|
123
|
+
mapPath === undefined || tilesHash === undefined
|
|
124
|
+
? undefined
|
|
125
|
+
: {
|
|
126
|
+
bytes: readBoundedFile(resolve(mapPath), STILL_IMAGE_LIMITS.bytes),
|
|
127
|
+
tilesHash,
|
|
128
|
+
}
|
|
129
|
+
const shard = await buildProject(
|
|
130
|
+
resolve(input),
|
|
131
|
+
folder === undefined ? undefined : resolve(folder),
|
|
132
|
+
{
|
|
133
|
+
outputFormat: 2,
|
|
134
|
+
...(selected === undefined ? {} : { output: selected }),
|
|
135
|
+
...(options.decisionLegacyLines === undefined
|
|
136
|
+
? {}
|
|
137
|
+
: { decisionLegacyLines: options.decisionLegacyLines }),
|
|
138
|
+
...(options.manifest === undefined ? {} : { manifest: options.manifest }),
|
|
139
|
+
copyRuntime: flags.includes('--copy-runtime'),
|
|
140
|
+
...(noClient ? { client: null } : {}),
|
|
141
|
+
...(map === undefined ? {} : { map }),
|
|
142
|
+
...(mapSourceHash === undefined ? {} : { mapSourceHash }),
|
|
143
|
+
placeholders: !flags.includes('--no-placeholders'),
|
|
144
|
+
admit: async (built, _assets, policy) => {
|
|
145
|
+
printStaticReport(built, policy)
|
|
146
|
+
await Promise.resolve()
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
)
|
|
150
|
+
console.info(`built ${shard.identity.slug} v${shard.version}`)
|
|
151
|
+
if (!folderOnly)
|
|
152
|
+
await writeShardfileOf(
|
|
153
|
+
options,
|
|
154
|
+
folder === undefined
|
|
155
|
+
? resolve(
|
|
156
|
+
shardOutputRoot(resolve(input)),
|
|
157
|
+
'public/shardfiles',
|
|
158
|
+
shard.identity.slug,
|
|
159
|
+
)
|
|
160
|
+
: resolve(folder),
|
|
161
|
+
resolve(input),
|
|
162
|
+
)
|
|
163
|
+
}
|