@bedrock-core/builder 0.1.2 → 0.3.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/CHANGELOG.md +84 -1
- package/dist/bin/api-library.d.ts +1 -0
- package/dist/bin/api-library.js +10 -0
- package/dist/bin/audit-paths.d.ts +1 -0
- package/dist/bin/audit-paths.js +44 -0
- package/dist/bin/build.js +1 -1
- package/dist/bin/builder.js +13 -2
- package/dist/bin/migrate.js +1 -15
- package/dist/bin/plan.js +2 -2
- package/dist/bin/watch.js +1 -1
- package/dist/package.json +12 -10
- package/dist/schemas/bundler.schema.json +5 -0
- package/dist/schemas/config.schema.json +40 -10
- package/dist/schemas/generator.schema.json +11 -29
- package/dist/schemas/guides.schema.json +0 -5
- package/dist/schemas/i18n.schema.json +0 -5
- package/dist/schemas/pack-manifest.schema.json +294 -0
- package/dist/schemas/ui-compiler.schema.json +0 -15
- package/dist/src/config.d.ts +21 -7
- package/dist/src/config.js +3 -0
- package/dist/src/contract.d.ts +5 -2
- package/dist/src/export.d.ts +7 -5
- package/dist/src/export.js +274 -47
- package/dist/src/migrate.d.ts +1 -1
- package/dist/src/migrate.js +23 -17
- package/dist/src/migration/exports.js +1 -1
- package/dist/src/migration/filters.d.ts +4 -7
- package/dist/src/migration/filters.js +41 -234
- package/dist/src/migration/project.d.ts +1 -2
- package/dist/src/migration/project.js +35 -25
- package/dist/src/migration/types.d.ts +1 -8
- package/dist/src/path-audit.d.ts +29 -0
- package/dist/src/path-audit.js +110 -0
- package/dist/src/plan.d.ts +1 -0
- package/dist/src/plan.js +7 -7
- package/dist/src/plugin-routing.js +1 -1
- package/dist/src/plugins.js +10 -1
- package/dist/src/project.d.ts +1 -3
- package/dist/src/project.js +1 -12
- package/dist/src/regolith.d.ts +3 -3
- package/dist/src/regolith.js +26 -4
- package/dist/src/run.js +86 -38
- package/dist/src/staging.d.ts +4 -0
- package/dist/src/staging.js +305 -0
- package/dist/src/validation.d.ts +1 -1
- package/dist/src/watch.js +48 -29
- package/package.json +41 -20
- package/schemas/bundler.schema.json +5 -0
- package/schemas/config.schema.json +40 -10
- package/schemas/generator.schema.json +11 -29
- package/schemas/guides.schema.json +0 -5
- package/schemas/i18n.schema.json +0 -5
- package/schemas/pack-manifest.schema.json +294 -0
- package/schemas/ui-compiler.schema.json +0 -15
- package/dist/src/migration/local-filter.d.ts +0 -3
- package/dist/src/migration/local-filter.js +0 -20
|
@@ -1,173 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
'manifest': ['manifestPath', 'pretty'],
|
|
6
|
-
'generator': ['include', 'exclude', 'pretty', 'types', 'schemaVersion', 'typesDir', 'strict', 'typePrefix', 'maxAgeHours'],
|
|
7
|
-
'guides': ['namespace', 'sourceDir', 'defaultLocale', 'include', 'exclude', 'manifestPath', 'maxCodeLineBytes', 'strictLocales', 'compileScreens', 'screensDir', 'screenTitle', 'componentsModule', 'pretty'],
|
|
8
|
-
'i18n': ['namespace', 'sourceDir', 'defaultLocale', 'strict', 'vanilla', 'vanillaLangUrlTemplate', 'cacheMaxAgeHours', 'pretty'],
|
|
9
|
-
'ui-compiler': ['namespace', 'testMetadata', 'stamp', 'screens', 'pretty'],
|
|
10
|
-
'bundler': ['debug', 'tsConfigPath'],
|
|
11
|
-
};
|
|
12
|
-
function filterKind(id, definition, options) {
|
|
13
|
-
if (Object.hasOwn(options.filters ?? {}, id)) {
|
|
14
|
-
return options.filters[id];
|
|
15
|
-
}
|
|
16
|
-
if (!isRecord(definition) || typeof definition.url !== 'string' || definition.script !== undefined || definition.runWith !== undefined) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
const match = /^(?:https:\/\/)?github\.com\/bedrock-core\/regolith-filters(?:\/([a-z-]+))?\/?$/i.exec(definition.url);
|
|
20
|
-
const name = match?.[1] ?? (match ? id : undefined);
|
|
21
|
-
return name === 'core' || stages.some(stage => stage === name) ? name : undefined;
|
|
22
|
-
}
|
|
23
|
-
/** Translate Regolith workspace prefixes into authored project paths. */
|
|
24
|
-
function projectPath(value, packs, dataPath, report, location) {
|
|
25
|
-
const normalized = value.replaceAll('\\', '/').replace(/^\.\//, '').replace(/^packs\//, '');
|
|
26
|
-
const candidates = [];
|
|
27
|
-
for (const directory of Object.values(packs)) {
|
|
28
|
-
const source = directory.replaceAll('\\', '/').replace(/^\.\//, '').replace(/\/$/, '');
|
|
29
|
-
const staged = source.replace(/^packs\//, '');
|
|
30
|
-
if (normalized === staged || normalized.startsWith(`${staged}/`)) {
|
|
31
|
-
candidates.push(`${source}${normalized.slice(staged.length)}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (normalized === 'data' || normalized.startsWith('data/')) {
|
|
35
|
-
if (typeof dataPath === 'string') {
|
|
36
|
-
candidates.push(`${dataPath.replaceAll('\\', '/').replace(/\/$/, '')}${normalized.slice(4)}`);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
report('data-source', location, 'Set an explicit project-relative source path; the Regolith data folder is not configured.');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (new Set(candidates).size > 1) {
|
|
43
|
-
report('ambiguous-source-path', location, `Path ${value} matches multiple Regolith workspace roots. Convert it to a project-relative path manually.`);
|
|
44
|
-
}
|
|
45
|
-
return candidates[0] ?? value;
|
|
46
|
-
}
|
|
47
|
-
function settingsFor(entry, packs, dataPath, report) {
|
|
48
|
-
const { stage, settings, location } = entry;
|
|
49
|
-
const converted = {};
|
|
50
|
-
function pattern(value, key) {
|
|
51
|
-
if (typeof value !== 'string') {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
const mapped = projectPath(value, packs, dataPath, report, location);
|
|
55
|
-
const normalized = mapped.replaceAll('\\', '/').replace(/^\.\//, '');
|
|
56
|
-
const insidePack = Object.values(packs).some((directory) => {
|
|
57
|
-
const root = directory.replaceAll('\\', '/').replace(/^\.\//, '').replace(/\/$/, '');
|
|
58
|
-
return normalized.startsWith(`${root}/`);
|
|
59
|
-
});
|
|
60
|
-
if (value.startsWith('!') || (key === 'include' && (!insidePack || normalized.split('/').includes('..')))) {
|
|
61
|
-
report('generator-pattern', `${location}/settings/${key}`, 'Use project-relative patterns inside configured packs; broad or negated template includes need manual conversion.');
|
|
62
|
-
}
|
|
63
|
-
return mapped;
|
|
64
|
-
}
|
|
65
|
-
for (const [key, value] of Object.entries(settings)) {
|
|
66
|
-
if (key === 'namespace' && stage !== 'i18n' && stage !== 'ui-compiler' && stage !== 'guides') {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (!keys[stage].includes(key) && key !== 'pretty' && key !== 'debug') {
|
|
70
|
-
report('filter-setting', `${location}/settings/${pointer(key)}`, `Setting ${key} has no verified ${stage} migration. Convert it manually.`);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (stage === 'manifest' && key === 'manifestPath') {
|
|
74
|
-
const map = (file) => typeof file === 'string' ? projectPath(file, packs, dataPath, report, location) : file;
|
|
75
|
-
converted.manifestPath = Array.isArray(value) ? value.map(map) : map(value);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if ((key === 'include' || key === 'exclude') && stage !== 'guides') {
|
|
79
|
-
converted[key] = Array.isArray(value) ? value.map(value => pattern(value, key)) : pattern(value, key);
|
|
80
|
-
}
|
|
81
|
-
else if (key === 'screens' && Array.isArray(value)) {
|
|
82
|
-
converted.screens = value.map((source) => {
|
|
83
|
-
if (typeof source !== 'string' || !source.startsWith('.')) {
|
|
84
|
-
return source;
|
|
85
|
-
}
|
|
86
|
-
const mapped = projectPath(source, packs, dataPath, report, location);
|
|
87
|
-
return mapped.startsWith('.') || path.isAbsolute(mapped) ? mapped : `./${mapped}`;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
else if (['sourceDir', 'manifestPath', 'screensDir', 'componentsModule'].includes(key) && typeof value === 'string' && value !== '') {
|
|
91
|
-
converted[key] = projectPath(value, packs, dataPath, report, location);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
converted[key === 'tsConfigPath' ? 'tsconfig' : key] = structuredClone(value);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (stage === 'guides') {
|
|
98
|
-
const source = typeof converted.sourceDir === 'string' ? converted.sourceDir : projectPath('data/guides', packs, dataPath, report, location);
|
|
99
|
-
const screens = typeof converted.screensDir === 'string' ? converted.screensDir : projectPath('BP/scripts/guides', packs, dataPath, report, location);
|
|
100
|
-
const normalize = (value) => value.replaceAll('\\', '/').replace(/^\.\//, '').replace(/\/$/, '');
|
|
101
|
-
const ownerFor = (file) => Object.entries(packs).find(([, directory]) => normalize(file).startsWith(`${normalize(directory)}/`));
|
|
102
|
-
const owner = ownerFor(source) ?? ownerFor(screens);
|
|
103
|
-
if (owner) {
|
|
104
|
-
converted.owner = owner[0];
|
|
105
|
-
const relative = (file) => path.posix.relative(normalize(owner[1]), normalize(file));
|
|
106
|
-
if (ownerFor(source)?.[0] === owner[0]) {
|
|
107
|
-
converted.sourceDir = relative(source);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
converted.sourceDir = 'guides';
|
|
111
|
-
report('guides-pack-sources', location, `Place guide content from ${source} inside ${owner[1]}/guides before building. Migration does not move files or rewrite their imports.`, 'warning');
|
|
112
|
-
}
|
|
113
|
-
for (const key of ['screensDir', 'componentsModule', 'manifestPath']) {
|
|
114
|
-
const file = key === 'screensDir' ? screens : converted[key];
|
|
115
|
-
if (typeof file !== 'string') {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (ownerFor(file)?.[0] === owner[0]) {
|
|
119
|
-
converted[key] = relative(file);
|
|
120
|
-
}
|
|
121
|
-
else if (key === 'componentsModule') {
|
|
122
|
-
report('guides-pack-components', location, `Place the component registry ${file} inside owner pack ${owner[0]} and use a pack-relative componentsModule path.`);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
delete converted[key];
|
|
126
|
-
report('guides-pack-output', location, `The guides ${key} uses its owner-specific default. Configure a pack-relative output path to customize it.`, 'warning');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
converted.sourceDir = 'guides';
|
|
132
|
-
report('guides-pack-sources', location, `Place guide content from ${source} inside the intended owner pack's guides directory before building. Migration does not move files or rewrite their imports.`, 'warning');
|
|
133
|
-
}
|
|
134
|
-
report('guides-declarations', location, 'Include .bedrock-core/generated/guides/<packId> in tsconfig. Typed runtime imports use @bedrock-core/generated/guides/<packId>. Guide paths are pack-relative.', 'warning');
|
|
135
|
-
}
|
|
136
|
-
if (stage === 'i18n') {
|
|
137
|
-
const source = typeof converted.sourceDir === 'string' ? converted.sourceDir : projectPath('data/i18n', packs, dataPath, report, location);
|
|
138
|
-
const owner = Object.entries(packs).find(([, directory]) => {
|
|
139
|
-
const root = directory.replaceAll('\\', '/').replace(/^\.\//, '').replace(/\/$/, '');
|
|
140
|
-
return source.replaceAll('\\', '/').replace(/^\.\//, '').startsWith(`${root}/`);
|
|
141
|
-
});
|
|
142
|
-
if (owner) {
|
|
143
|
-
converted.owner = owner[0];
|
|
144
|
-
converted.sourceDir = path.posix.relative(owner[1].replaceAll('\\', '/'), source.replaceAll('\\', '/'));
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
converted.sourceDir = 'i18n';
|
|
148
|
-
report('i18n-pack-sources', location, `Place locale sources from ${source} inside the intended owner pack's i18n directory before building. Migration does not move files or rewrite their imports.`, 'warning');
|
|
149
|
-
}
|
|
150
|
-
report('i18n-declarations', location, 'Include .bedrock-core/generated/i18n/<packId> in tsconfig. Typed runtime imports use @bedrock-core/generated/i18n/<packId>. sourceDir is pack-relative.', 'warning');
|
|
151
|
-
}
|
|
152
|
-
if (stage === 'generator' && settings.types !== false) {
|
|
153
|
-
report('generator-declarations', location, 'Include the configured generator declarations (default .bedrock-core/generated/mc/globals.d.ts) in tsconfig.', 'warning');
|
|
154
|
-
}
|
|
155
|
-
if (stage === 'bundler') {
|
|
156
|
-
report('bundler-entry', location, 'Verify manifest script entries select the intended sources. tsconfig files/include do not select builder entry points; project code and tsconfig are not rewritten.', 'warning');
|
|
157
|
-
}
|
|
158
|
-
return Object.keys(converted).length ? converted : stage === 'generator' ? true : 'auto';
|
|
159
|
-
}
|
|
160
|
-
/** Flatten profile references and preserve the supported, fixed stage order. */
|
|
161
|
-
export function convertFilters(name, profiles, definitions, packs, dataPath, options, report) {
|
|
162
|
-
const entries = [];
|
|
163
|
-
const namespaces = new Set();
|
|
1
|
+
import { isRecord, pointer } from './types.js';
|
|
2
|
+
/** Flatten profile references into ordered steps for standalone Node filters. */
|
|
3
|
+
export function convertFilters(name, profiles, definitions, plugins, dataPath, report) {
|
|
4
|
+
const steps = [];
|
|
164
5
|
let remaining = 10000;
|
|
165
|
-
function add(stage, settings, location) {
|
|
166
|
-
if (typeof settings.namespace === 'string' && settings.namespace) {
|
|
167
|
-
namespaces.add(settings.namespace);
|
|
168
|
-
}
|
|
169
|
-
entries.push({ stage, settings, location });
|
|
170
|
-
}
|
|
171
6
|
function visit(profileName, parents) {
|
|
172
7
|
const location = `/regolith/profiles/${pointer(profileName)}`;
|
|
173
8
|
if (parents.includes(profileName) || parents.length > 64) {
|
|
@@ -187,7 +22,7 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
187
22
|
for (const key of ['preShell', 'postShell']) {
|
|
188
23
|
const commands = profile[key];
|
|
189
24
|
if (commands !== undefined && !(Array.isArray(commands) && commands.length === 0) && !(isRecord(commands) && Object.keys(commands).length === 0)) {
|
|
190
|
-
report('shell-commands', `${location}/${key}`, 'Move shell commands and environment setup into a
|
|
25
|
+
report('shell-commands', `${location}/${key}`, 'Move shell commands and environment setup into a Node step or a Builder plugin.');
|
|
191
26
|
}
|
|
192
27
|
}
|
|
193
28
|
for (const [index, item] of profile.filters.entries()) {
|
|
@@ -207,23 +42,25 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
207
42
|
report('filter-disabled', `${itemPath}/disabled`, 'disabled must be a boolean.');
|
|
208
43
|
}
|
|
209
44
|
if (item.when !== undefined) {
|
|
210
|
-
report('filter-condition', `${itemPath}/when`, 'Conditional execution needs separate profiles or a
|
|
45
|
+
report('filter-condition', `${itemPath}/when`, 'Conditional execution needs separate profiles or a Builder plugin.');
|
|
211
46
|
continue;
|
|
212
47
|
}
|
|
213
48
|
for (const key of Object.keys(item)) {
|
|
214
49
|
if (!['filter', 'profile', 'settings', 'disabled', 'when', 'arguments', 'extraArguments'].includes(key)) {
|
|
215
|
-
report(key === 'asyncFilters' ? 'parallel-filters' : 'filter-property', `${itemPath}/${pointer(key)}`, 'This filter property needs manual conversion
|
|
50
|
+
report(key === 'asyncFilters' ? 'parallel-filters' : 'filter-property', `${itemPath}/${pointer(key)}`, 'This filter property needs manual conversion. Builder file transformations are sequential.');
|
|
216
51
|
}
|
|
217
52
|
}
|
|
218
|
-
|
|
219
|
-
|
|
53
|
+
const args = item.arguments;
|
|
54
|
+
if (args !== undefined && (!Array.isArray(args) || !args.every(value => typeof value === 'string'))) {
|
|
55
|
+
report('filter-arguments', `${itemPath}/arguments`, 'Filter arguments must be an array of strings.');
|
|
56
|
+
continue;
|
|
220
57
|
}
|
|
221
58
|
if (item.extraArguments !== undefined && item.extraArguments !== 'ignore') {
|
|
222
|
-
report('extra-arguments', `${itemPath}/extraArguments`, 'Runtime argument forwarding needs manual
|
|
59
|
+
report('extra-arguments', `${itemPath}/extraArguments`, 'Runtime argument forwarding needs manual conversion.');
|
|
223
60
|
}
|
|
224
61
|
if (typeof item.profile === 'string' && item.filter === undefined) {
|
|
225
|
-
if (item.settings !== undefined) {
|
|
226
|
-
report('profile-settings',
|
|
62
|
+
if (item.settings !== undefined || args?.length) {
|
|
63
|
+
report('profile-settings', itemPath, 'Settings and arguments on profile references need manual conversion.');
|
|
227
64
|
}
|
|
228
65
|
visit(item.profile, [...parents, profileName]);
|
|
229
66
|
continue;
|
|
@@ -232,75 +69,45 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
232
69
|
report('filter-entry', itemPath, 'Use exactly one filter or profile reference.');
|
|
233
70
|
continue;
|
|
234
71
|
}
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
72
|
+
const id = item.filter;
|
|
73
|
+
const definition = Object.hasOwn(definitions, id) ? definitions[id] : undefined;
|
|
74
|
+
const definitionPath = `/regolith/filterDefinitions/${pointer(id)}`;
|
|
75
|
+
if (!isRecord(definition) || definition.url !== undefined || definition.npm !== undefined) {
|
|
76
|
+
report('custom-filter', itemPath, `Provide a local Node entry for ${id} or configure its Builder step manually.`);
|
|
239
77
|
continue;
|
|
240
78
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
report('filter-definition', `/regolith/filterDefinitions/${pointer(item.filter)}/${pointer(key)}`, 'This filter definition property needs manual conversion.');
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (definition.runWith !== undefined && definition.runWith !== 'nodejs') {
|
|
247
|
-
report('filter-runtime', itemPath, 'Only verified Node TS/JS filter equivalents can become built-in stages.');
|
|
248
|
-
}
|
|
249
|
-
if (definition.version !== undefined) {
|
|
250
|
-
report('filter-version', itemPath, 'Built-in stages use the installed builder version. Verify output parity against the pinned Regolith filter version.', 'warning');
|
|
251
|
-
}
|
|
252
|
-
if (item.settings !== undefined && !isRecord(item.settings)) {
|
|
253
|
-
report('filter-settings', `${itemPath}/settings`, 'Filter settings must be an object.');
|
|
79
|
+
if (definition.runWith !== 'nodejs') {
|
|
80
|
+
report('filter-runtime', definitionPath, 'Automatic conversion supports local NodeJS filters.');
|
|
254
81
|
continue;
|
|
255
82
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
add(kind, settings, itemPath);
|
|
83
|
+
if (typeof definition.script !== 'string' || !definition.script.trim()) {
|
|
84
|
+
report('filter-script', `${definitionPath}/script`, 'Provide the path to the local Node entry.');
|
|
259
85
|
continue;
|
|
260
86
|
}
|
|
261
|
-
for (const key of Object.keys(
|
|
262
|
-
if (
|
|
263
|
-
report('
|
|
87
|
+
for (const key of Object.keys(definition)) {
|
|
88
|
+
if (!['runWith', 'script', 'requirements'].includes(key)) {
|
|
89
|
+
report('filter-definition', `${definitionPath}/${pointer(key)}`, 'This filter definition property needs manual conversion.');
|
|
264
90
|
}
|
|
265
91
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
report('core-shared', `${itemPath}/settings/shared`, 'Shared settings must be an object.');
|
|
269
|
-
continue;
|
|
92
|
+
if (typeof definition.requirements === 'string' && definition.requirements.trim()) {
|
|
93
|
+
report('filter-requirements', `${definitionPath}/requirements`, `Install the filter dependencies in ${definition.requirements} before building.`, 'warning');
|
|
270
94
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
report('core-shared-setting', `${itemPath}/settings/shared/${pointer(key)}`, 'Move this shared setting to each stage that consumes it.');
|
|
274
|
-
}
|
|
95
|
+
else if (definition.requirements !== undefined) {
|
|
96
|
+
report('filter-requirements', `${definitionPath}/requirements`, 'Provide the directory containing the Node filter dependencies.');
|
|
275
97
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (own !== undefined && !isRecord(own) && !(stage === 'generator' && own === true)) {
|
|
282
|
-
report('core-stage', `${itemPath}/settings/${stage}`, 'Expected a settings object, false, or generator: true.');
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
add(stage, { ...shared, ...(isRecord(own) ? own : {}) }, itemPath);
|
|
98
|
+
if (item.settings !== undefined && !isRecord(item.settings)) {
|
|
99
|
+
report('filter-settings', `${itemPath}/settings`, 'Filter settings must be an object.');
|
|
100
|
+
continue;
|
|
286
101
|
}
|
|
102
|
+
plugins.set(id, { script: definition.script, ...(dataPath === undefined ? {} : { dataPath }) });
|
|
103
|
+
steps.push({
|
|
104
|
+
plugin: id,
|
|
105
|
+
after: 'prepare',
|
|
106
|
+
...(item.settings === undefined ? {} : { settings: item.settings }),
|
|
107
|
+
...(args === undefined ? {} : { arguments: args }),
|
|
108
|
+
});
|
|
287
109
|
}
|
|
288
110
|
}
|
|
289
111
|
visit(name, []);
|
|
290
|
-
|
|
291
|
-
const seen = new Set();
|
|
292
|
-
let previous = -1;
|
|
293
|
-
for (const entry of entries) {
|
|
294
|
-
const index = stages.indexOf(entry.stage);
|
|
295
|
-
if (seen.has(entry.stage)) {
|
|
296
|
-
report('repeated-stage', entry.location, `Stage ${entry.stage} runs more than once. Port repeated transformations to explicit plugin steps.`);
|
|
297
|
-
}
|
|
298
|
-
if (index < previous) {
|
|
299
|
-
report('stage-order', entry.location, 'The configured filter order differs from the fixed builder stage order. Convert the sequence to plugin hooks manually.');
|
|
300
|
-
}
|
|
301
|
-
previous = index;
|
|
302
|
-
seen.add(entry.stage);
|
|
303
|
-
selected[entry.stage] = settingsFor(entry, packs, dataPath, report);
|
|
304
|
-
}
|
|
305
|
-
return { stages: selected, namespaces: [...namespaces] };
|
|
112
|
+
return steps;
|
|
306
113
|
}
|
|
@@ -7,10 +7,9 @@ export interface ProjectMigration extends MigrationResult {
|
|
|
7
7
|
sourceText: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Inspect pack metadata and
|
|
10
|
+
* Inspect pack metadata and local Node entry files without importing project code.
|
|
11
11
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
12
12
|
* @returns A preview with inspected metadata and the original config text for guarded writes.
|
|
13
|
-
* @remarks Inspects source manifests and known local wrapper identities without importing authored filter code.
|
|
14
13
|
*/
|
|
15
14
|
export declare function migrateRegolithProject(configPath?: string, options?: MigrationOptions): Promise<ProjectMigration>;
|
|
16
15
|
/**
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import { lstat, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { lstat, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { migrateRegolithConfig } from
|
|
6
|
-
import { readManifest } from
|
|
7
|
-
import { inspectPack } from
|
|
8
|
-
import { resolveExportPaths } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { isRecord, pointer } from
|
|
5
|
+
import { migrateRegolithConfig } from '../migrate.js';
|
|
6
|
+
import { readManifest } from '../manifest.js';
|
|
7
|
+
import { inspectPack } from '../packs.js';
|
|
8
|
+
import { resolveExportPaths } from '../export.js';
|
|
9
|
+
import { validateConfig } from '../config.js';
|
|
10
|
+
import { scriptSource } from '@bedrock-core/builder-bundler/entries';
|
|
11
|
+
import { isRecord, pointer } from './types.js';
|
|
12
12
|
/**
|
|
13
|
-
* Inspect pack metadata and
|
|
13
|
+
* Inspect pack metadata and local Node entry files without importing project code.
|
|
14
14
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
15
15
|
* @returns A preview with inspected metadata and the original config text for guarded writes.
|
|
16
|
-
* @remarks Inspects source manifests and known local wrapper identities without importing authored filter code.
|
|
17
16
|
*/
|
|
18
17
|
export async function migrateRegolithProject(configPath = 'config.json', options = {}) {
|
|
19
18
|
const file = await realpath(configPath);
|
|
20
19
|
const project = path.dirname(file);
|
|
21
20
|
const sourceText = await readFile(file, 'utf8');
|
|
22
21
|
const input = JSON.parse(sourceText);
|
|
23
|
-
const inferred = { ...options,
|
|
22
|
+
const inferred = { ...options, packKinds: { ...options.packKinds } };
|
|
24
23
|
const diagnostics = [];
|
|
25
24
|
const engineVersions = new Set();
|
|
26
25
|
const identities = new Set();
|
|
@@ -36,8 +35,16 @@ export async function migrateRegolithProject(configPath = 'config.json', options
|
|
|
36
35
|
continue;
|
|
37
36
|
}
|
|
38
37
|
try {
|
|
39
|
-
const manifest = await readManifest(id, packPath);
|
|
38
|
+
const manifest = await readManifest(id, packPath, true);
|
|
40
39
|
inferred.packKinds[id] = (await inspectPack(id, packPath)).kind;
|
|
40
|
+
for (const module of manifest.modules.filter(module => module.type === 'script')) {
|
|
41
|
+
try {
|
|
42
|
+
await scriptSource(id, path.resolve(packPath, module.entry), packPath);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
diagnostics.push({ severity: 'error', code: 'script-entry', path: `/packs/${pointer(id)}`, message: error instanceof Error ? error.message : String(error) });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
41
48
|
for (const uuid of [manifest.header.uuid, ...manifest.modules.map(module => module.uuid)]) {
|
|
42
49
|
if (identities.has(uuid.toLowerCase())) {
|
|
43
50
|
diagnostics.push({ severity: 'error', code: 'manifest-identity', path: `/packs/${pointer(id)}`, message: `Manifest UUID ${uuid} is repeated. Pack and module UUIDs must be unique.` });
|
|
@@ -56,25 +63,28 @@ export async function migrateRegolithProject(configPath = 'config.json', options
|
|
|
56
63
|
inferred.targetVersion = [...engineVersions][0];
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
inferred.schema ??= path.relative(project, fileURLToPath(new URL('../../schemas/config.schema.json', import.meta.url))).replaceAll('\\', '/');
|
|
67
|
+
const result = migrateRegolithConfig(input, inferred);
|
|
68
|
+
const builder = result.config.bedrockCore;
|
|
69
|
+
if (isRecord(builder) && isRecord(builder.plugins)) {
|
|
70
|
+
const defaultDataPath = './packs/data';
|
|
71
|
+
const defaultData = await stat(path.resolve(project, defaultDataPath), { throwIfNoEntry: false });
|
|
72
|
+
for (const [id, definition] of Object.entries(builder.plugins)) {
|
|
73
|
+
if (!isRecord(definition) || typeof definition.script !== 'string') {
|
|
63
74
|
continue;
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
const entry = await stat(path.resolve(project, definition.script), { throwIfNoEntry: false });
|
|
77
|
+
if (!entry?.isFile()) {
|
|
78
|
+
diagnostics.push({
|
|
79
|
+
severity: 'error', code: 'filter-script', path: `/regolith/filterDefinitions/${pointer(id)}/script`,
|
|
80
|
+
message: `Node filter entry must be a file: ${definition.script}.`,
|
|
81
|
+
});
|
|
70
82
|
}
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
if (definition.dataPath === undefined && defaultData?.isDirectory()) {
|
|
84
|
+
definition.dataPath = defaultDataPath;
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
|
-
inferred.schema ??= path.relative(project, fileURLToPath(new URL('../../schemas/config.schema.json', import.meta.url))).replaceAll('\\', '/');
|
|
77
|
-
const result = migrateRegolithConfig(input, inferred);
|
|
78
88
|
if (isRecord(result.config.packs) && isRecord(result.config.bedrockCore) && isRecord(result.config.bedrockCore.profiles)) {
|
|
79
89
|
for (const [name, profile] of Object.entries(result.config.bedrockCore.profiles)) {
|
|
80
90
|
if (!isRecord(profile) || !isRecord(profile.export)) {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { StageName } from '../config.ts';
|
|
2
1
|
import type { PackInfo } from '../packs.ts';
|
|
3
|
-
/** Known built-in filter implementation accepted by configuration conversion. */
|
|
4
|
-
export type FilterKind = StageName | 'core';
|
|
5
2
|
/** Configuration conversion issue with a stable code and JSON pointer. */
|
|
6
3
|
export interface MigrationDiagnostic {
|
|
7
4
|
/** Errors prevent writing; warnings allow a ready preview. */
|
|
@@ -13,18 +10,14 @@ export interface MigrationDiagnostic {
|
|
|
13
10
|
/** Actionable explanation of the conversion issue. */
|
|
14
11
|
message: string;
|
|
15
12
|
}
|
|
16
|
-
/** Explicit metadata, profile
|
|
13
|
+
/** Explicit metadata, profile and destination mappings for Regolith configuration conversion. */
|
|
17
14
|
export interface MigrationOptions {
|
|
18
|
-
/** Supply a missing project namespace. */
|
|
19
|
-
namespace?: string;
|
|
20
15
|
/** Supply a missing target Minecraft version. */
|
|
21
16
|
targetVersion?: string;
|
|
22
17
|
/** Profile names to convert; omission selects all profiles. */
|
|
23
18
|
profiles?: string[];
|
|
24
19
|
/** Exact destination overrides keyed by profile and configured pack ID. */
|
|
25
20
|
exports?: Record<string, Record<string, string>>;
|
|
26
|
-
/** Explicit mappings for verified local filters or forks; no module is executed. */
|
|
27
|
-
filters?: Record<string, FilterKind>;
|
|
28
21
|
/** Explicit classification for packs whose type cannot be inferred. */
|
|
29
22
|
packKinds?: Record<string, PackInfo['kind']>;
|
|
30
23
|
/** Editor schema reference inserted into the converted config. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface PathAuditOptions {
|
|
2
|
+
maxLength: number;
|
|
3
|
+
folders?: {
|
|
4
|
+
creator: string;
|
|
5
|
+
pack: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
interface PathFinding {
|
|
9
|
+
rule: 'path-length' | 'path-depth' | 'asset-folder';
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/** Audit the file names of an existing pack or unpacked add-on. */
|
|
14
|
+
export declare function auditPackPaths(directory: string, { maxLength, folders }: PathAuditOptions): Promise<{
|
|
15
|
+
limits: {
|
|
16
|
+
length: number;
|
|
17
|
+
depth: number;
|
|
18
|
+
};
|
|
19
|
+
packs: {
|
|
20
|
+
path: string;
|
|
21
|
+
files: number;
|
|
22
|
+
longest: {
|
|
23
|
+
path: string;
|
|
24
|
+
length: number;
|
|
25
|
+
};
|
|
26
|
+
findings: PathFinding[];
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { lstat, readdir } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const containers = new Set(['behavior_packs', 'resource_packs']);
|
|
4
|
+
// Creator Tools 0.20.0 strips these pack folder names from its path budget.
|
|
5
|
+
const packAliases = new Set(['bp', 'rp', 'behavior pack', 'resource pack', 'behavior_pack', 'resource_pack', 'skin_pack', 'world', 'world_template']);
|
|
6
|
+
const assetFiles = new Map([
|
|
7
|
+
['textures', /\.(png|tga|jpe?g)$/i],
|
|
8
|
+
['sounds', /\.(ogg|wav|fsb)$/i],
|
|
9
|
+
['functions', /\.mcfunction$/i],
|
|
10
|
+
['loot_tables', /\.json$/i],
|
|
11
|
+
['trading', /\.json$/i],
|
|
12
|
+
]);
|
|
13
|
+
const maxDepth = 8;
|
|
14
|
+
async function hasManifest(directory) {
|
|
15
|
+
try {
|
|
16
|
+
return (await lstat(path.join(directory, 'manifest.json'))).isFile();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code === 'ENOENT') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function packRoots(root) {
|
|
26
|
+
if (!(await lstat(root)).isDirectory()) {
|
|
27
|
+
throw new Error(`Path audit requires a pack or unpacked add-on directory: ${root}`);
|
|
28
|
+
}
|
|
29
|
+
if (await hasManifest(root)) {
|
|
30
|
+
return [{ directory: root, relative: '.', prefix: '' }];
|
|
31
|
+
}
|
|
32
|
+
const packs = [];
|
|
33
|
+
for (const container of await readdir(root, { withFileTypes: true })) {
|
|
34
|
+
if (!containers.has(container.name.toLowerCase())) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const directory = path.join(root, container.name);
|
|
38
|
+
if (!container.isDirectory()) {
|
|
39
|
+
throw new Error(`Path audit requires a real pack container directory: ${directory}`);
|
|
40
|
+
}
|
|
41
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
42
|
+
const pack = path.join(directory, entry.name);
|
|
43
|
+
if (entry.isSymbolicLink()) {
|
|
44
|
+
throw new Error(`Path audit cannot follow a link: ${pack}`);
|
|
45
|
+
}
|
|
46
|
+
if (entry.isDirectory() && await hasManifest(pack)) {
|
|
47
|
+
packs.push({
|
|
48
|
+
directory: pack,
|
|
49
|
+
relative: path.posix.join(container.name, entry.name),
|
|
50
|
+
prefix: packAliases.has(entry.name.toLowerCase()) ? '' : entry.name,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!packs.length) {
|
|
56
|
+
throw new Error(`No pack manifests found at ${root} or under its behavior_packs and resource_packs directories`);
|
|
57
|
+
}
|
|
58
|
+
return packs.sort((a, b) => a.relative.localeCompare(b.relative));
|
|
59
|
+
}
|
|
60
|
+
async function packFiles(directory, files = [], prefix = '') {
|
|
61
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
62
|
+
const relative = path.posix.join(prefix, entry.name);
|
|
63
|
+
const file = path.join(directory, entry.name);
|
|
64
|
+
if (entry.isSymbolicLink()) {
|
|
65
|
+
throw new Error(`Path audit cannot follow a link: ${file}`);
|
|
66
|
+
}
|
|
67
|
+
if (entry.isDirectory()) {
|
|
68
|
+
await packFiles(file, files, relative);
|
|
69
|
+
}
|
|
70
|
+
else if (entry.isFile()) {
|
|
71
|
+
files.push(relative);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return files;
|
|
75
|
+
}
|
|
76
|
+
/** Audit the file names of an existing pack or unpacked add-on. */
|
|
77
|
+
export async function auditPackPaths(directory, { maxLength, folders }) {
|
|
78
|
+
const packs = [];
|
|
79
|
+
for (const pack of await packRoots(path.resolve(directory))) {
|
|
80
|
+
const files = (await packFiles(pack.directory)).sort();
|
|
81
|
+
const findings = [];
|
|
82
|
+
let longest = { path: '', length: 0 };
|
|
83
|
+
for (const file of files) {
|
|
84
|
+
const measured = path.posix.join(pack.prefix, file);
|
|
85
|
+
const length = measured.length;
|
|
86
|
+
const depth = measured.split('/').length - 1;
|
|
87
|
+
const segments = file.split('/');
|
|
88
|
+
const category = segments[0];
|
|
89
|
+
if (length > longest.length) {
|
|
90
|
+
longest = { path: measured, length };
|
|
91
|
+
}
|
|
92
|
+
if (length > maxLength) {
|
|
93
|
+
findings.push({ rule: 'path-length', path: measured, message: `Path length ${length} exceeds the ${maxLength}-character budget` });
|
|
94
|
+
}
|
|
95
|
+
if (depth > maxDepth) {
|
|
96
|
+
findings.push({ rule: 'path-depth', path: measured, message: `Directory depth ${depth} exceeds the ${maxDepth}-level budget` });
|
|
97
|
+
}
|
|
98
|
+
if (!assetFiles.get(category)?.test(file)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const [, creator, name] = segments;
|
|
102
|
+
if (segments.length < 4 || (folders && (creator !== folders.creator || (name !== folders.pack && name !== 'common')))) {
|
|
103
|
+
const expected = folders ? `${folders.creator}/${folders.pack}/` : '<creator>/<pack>/';
|
|
104
|
+
findings.push({ rule: 'asset-folder', path: measured, message: `Cooperative add-ons should place these assets under ${category}/${expected}` });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
packs.push({ path: pack.relative, files: files.length, longest, findings });
|
|
108
|
+
}
|
|
109
|
+
return { limits: { length: maxLength, depth: maxDepth }, packs };
|
|
110
|
+
}
|