@bedrock-core/builder 0.2.0 → 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 +38 -1
- package/dist/bin/migrate.js +0 -10
- package/dist/package.json +7 -6
- package/dist/schemas/bundler.schema.json +5 -0
- package/dist/schemas/config.schema.json +13 -3
- package/dist/schemas/generator.schema.json +11 -29
- package/dist/schemas/pack-manifest.schema.json +52 -1
- package/dist/schemas/ui-compiler.schema.json +0 -10
- package/dist/src/config.d.ts +15 -5
- package/dist/src/contract.d.ts +3 -2
- package/dist/src/export.d.ts +1 -1
- package/dist/src/export.js +1 -1
- package/dist/src/migrate.d.ts +1 -1
- package/dist/src/migrate.js +16 -13
- package/dist/src/migration/filters.d.ts +4 -7
- package/dist/src/migration/filters.js +40 -234
- package/dist/src/migration/project.d.ts +1 -2
- package/dist/src/migration/project.js +19 -18
- package/dist/src/migration/types.d.ts +1 -6
- package/dist/src/plan.d.ts +1 -0
- package/dist/src/plan.js +5 -5
- package/dist/src/regolith.d.ts +3 -3
- package/dist/src/regolith.js +24 -2
- package/dist/src/run.js +24 -13
- package/dist/src/staging.js +9 -1
- package/dist/src/validation.d.ts +1 -1
- package/dist/src/watch.js +0 -9
- package/package.json +24 -13
- package/schemas/bundler.schema.json +5 -0
- package/schemas/config.schema.json +13 -3
- package/schemas/generator.schema.json +11 -29
- package/schemas/pack-manifest.schema.json +52 -1
- package/schemas/ui-compiler.schema.json +0 -10
- package/dist/src/migration/local-filter.d.ts +0 -3
- package/dist/src/migration/local-filter.js +0 -20
|
@@ -1,174 +1,8 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { stages } from '../plan.js';
|
|
3
1
|
import { isRecord, pointer } from './types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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();
|
|
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
|
-
delete settings.namespace;
|
|
170
|
-
entries.push({ stage, settings, location });
|
|
171
|
-
}
|
|
172
6
|
function visit(profileName, parents) {
|
|
173
7
|
const location = `/regolith/profiles/${pointer(profileName)}`;
|
|
174
8
|
if (parents.includes(profileName) || parents.length > 64) {
|
|
@@ -188,7 +22,7 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
188
22
|
for (const key of ['preShell', 'postShell']) {
|
|
189
23
|
const commands = profile[key];
|
|
190
24
|
if (commands !== undefined && !(Array.isArray(commands) && commands.length === 0) && !(isRecord(commands) && Object.keys(commands).length === 0)) {
|
|
191
|
-
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.');
|
|
192
26
|
}
|
|
193
27
|
}
|
|
194
28
|
for (const [index, item] of profile.filters.entries()) {
|
|
@@ -208,23 +42,25 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
208
42
|
report('filter-disabled', `${itemPath}/disabled`, 'disabled must be a boolean.');
|
|
209
43
|
}
|
|
210
44
|
if (item.when !== undefined) {
|
|
211
|
-
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.');
|
|
212
46
|
continue;
|
|
213
47
|
}
|
|
214
48
|
for (const key of Object.keys(item)) {
|
|
215
49
|
if (!['filter', 'profile', 'settings', 'disabled', 'when', 'arguments', 'extraArguments'].includes(key)) {
|
|
216
|
-
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.');
|
|
217
51
|
}
|
|
218
52
|
}
|
|
219
|
-
|
|
220
|
-
|
|
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;
|
|
221
57
|
}
|
|
222
58
|
if (item.extraArguments !== undefined && item.extraArguments !== 'ignore') {
|
|
223
|
-
report('extra-arguments', `${itemPath}/extraArguments`, 'Runtime argument forwarding needs manual
|
|
59
|
+
report('extra-arguments', `${itemPath}/extraArguments`, 'Runtime argument forwarding needs manual conversion.');
|
|
224
60
|
}
|
|
225
61
|
if (typeof item.profile === 'string' && item.filter === undefined) {
|
|
226
|
-
if (item.settings !== undefined) {
|
|
227
|
-
report('profile-settings',
|
|
62
|
+
if (item.settings !== undefined || args?.length) {
|
|
63
|
+
report('profile-settings', itemPath, 'Settings and arguments on profile references need manual conversion.');
|
|
228
64
|
}
|
|
229
65
|
visit(item.profile, [...parents, profileName]);
|
|
230
66
|
continue;
|
|
@@ -233,75 +69,45 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
233
69
|
report('filter-entry', itemPath, 'Use exactly one filter or profile reference.');
|
|
234
70
|
continue;
|
|
235
71
|
}
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
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.`);
|
|
240
77
|
continue;
|
|
241
78
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
report('filter-definition', `/regolith/filterDefinitions/${pointer(item.filter)}/${pointer(key)}`, 'This filter definition property needs manual conversion.');
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (definition.runWith !== undefined && definition.runWith !== 'nodejs') {
|
|
248
|
-
report('filter-runtime', itemPath, 'Only verified Node TS/JS filter equivalents can become built-in stages.');
|
|
249
|
-
}
|
|
250
|
-
if (definition.version !== undefined) {
|
|
251
|
-
report('filter-version', itemPath, 'Built-in stages use the installed builder version. Verify output parity against the pinned Regolith filter version.', 'warning');
|
|
252
|
-
}
|
|
253
|
-
if (item.settings !== undefined && !isRecord(item.settings)) {
|
|
254
|
-
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.');
|
|
255
81
|
continue;
|
|
256
82
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
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.');
|
|
260
85
|
continue;
|
|
261
86
|
}
|
|
262
|
-
for (const key of Object.keys(
|
|
263
|
-
if (
|
|
264
|
-
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.');
|
|
265
90
|
}
|
|
266
91
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
report('core-shared', `${itemPath}/settings/shared`, 'Shared settings must be an object.');
|
|
270
|
-
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');
|
|
271
94
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
report('core-shared-setting', `${itemPath}/settings/shared/${pointer(key)}`, 'Move this shared setting to each stage that consumes it.');
|
|
275
|
-
}
|
|
95
|
+
else if (definition.requirements !== undefined) {
|
|
96
|
+
report('filter-requirements', `${definitionPath}/requirements`, 'Provide the directory containing the Node filter dependencies.');
|
|
276
97
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
if (own !== undefined && !isRecord(own) && !(stage === 'generator' && own === true)) {
|
|
283
|
-
report('core-stage', `${itemPath}/settings/${stage}`, 'Expected a settings object, false, or generator: true.');
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
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;
|
|
287
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
|
+
});
|
|
288
109
|
}
|
|
289
110
|
}
|
|
290
111
|
visit(name, []);
|
|
291
|
-
|
|
292
|
-
const seen = new Set();
|
|
293
|
-
let previous = -1;
|
|
294
|
-
for (const entry of entries) {
|
|
295
|
-
const index = stages.indexOf(entry.stage);
|
|
296
|
-
if (seen.has(entry.stage)) {
|
|
297
|
-
report('repeated-stage', entry.location, `Stage ${entry.stage} runs more than once. Port repeated transformations to explicit plugin steps.`);
|
|
298
|
-
}
|
|
299
|
-
if (index < previous) {
|
|
300
|
-
report('stage-order', entry.location, 'The configured filter order differs from the fixed builder stage order. Convert the sequence to plugin hooks manually.');
|
|
301
|
-
}
|
|
302
|
-
previous = index;
|
|
303
|
-
seen.add(entry.stage);
|
|
304
|
-
selected[entry.stage] = settingsFor(entry, packs, dataPath, report);
|
|
305
|
-
}
|
|
306
|
-
return { stages: selected, namespaces: [...namespaces] };
|
|
112
|
+
return steps;
|
|
307
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,4 +1,4 @@
|
|
|
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';
|
|
@@ -6,22 +6,20 @@ import { migrateRegolithConfig } from '../migrate.js';
|
|
|
6
6
|
import { readManifest } from '../manifest.js';
|
|
7
7
|
import { inspectPack } from '../packs.js';
|
|
8
8
|
import { resolveExportPaths } from '../export.js';
|
|
9
|
-
import { localFilterKind } from './local-filter.js';
|
|
10
9
|
import { validateConfig } from '../config.js';
|
|
11
10
|
import { scriptSource } from '@bedrock-core/builder-bundler/entries';
|
|
12
11
|
import { isRecord, pointer } from './types.js';
|
|
13
12
|
/**
|
|
14
|
-
* Inspect pack metadata and
|
|
13
|
+
* Inspect pack metadata and local Node entry files without importing project code.
|
|
15
14
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
16
15
|
* @returns A preview with inspected metadata and the original config text for guarded writes.
|
|
17
|
-
* @remarks Inspects source manifests and known local wrapper identities without importing authored filter code.
|
|
18
16
|
*/
|
|
19
17
|
export async function migrateRegolithProject(configPath = 'config.json', options = {}) {
|
|
20
18
|
const file = await realpath(configPath);
|
|
21
19
|
const project = path.dirname(file);
|
|
22
20
|
const sourceText = await readFile(file, 'utf8');
|
|
23
21
|
const input = JSON.parse(sourceText);
|
|
24
|
-
const inferred = { ...options,
|
|
22
|
+
const inferred = { ...options, packKinds: { ...options.packKinds } };
|
|
25
23
|
const diagnostics = [];
|
|
26
24
|
const engineVersions = new Set();
|
|
27
25
|
const identities = new Set();
|
|
@@ -65,25 +63,28 @@ export async function migrateRegolithProject(configPath = 'config.json', options
|
|
|
65
63
|
inferred.targetVersion = [...engineVersions][0];
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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') {
|
|
72
74
|
continue;
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
});
|
|
79
82
|
}
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (definition.dataPath === undefined && defaultData?.isDirectory()) {
|
|
84
|
+
definition.dataPath = defaultDataPath;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
inferred.schema ??= path.relative(project, fileURLToPath(new URL('../../schemas/config.schema.json', import.meta.url))).replaceAll('\\', '/');
|
|
86
|
-
const result = migrateRegolithConfig(input, inferred);
|
|
87
88
|
if (isRecord(result.config.packs) && isRecord(result.config.bedrockCore) && isRecord(result.config.bedrockCore.profiles)) {
|
|
88
89
|
for (const [name, profile] of Object.entries(result.config.bedrockCore.profiles)) {
|
|
89
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,7 +10,7 @@ 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
15
|
/** Supply a missing target Minecraft version. */
|
|
19
16
|
targetVersion?: string;
|
|
@@ -21,8 +18,6 @@ export interface MigrationOptions {
|
|
|
21
18
|
profiles?: string[];
|
|
22
19
|
/** Exact destination overrides keyed by profile and configured pack ID. */
|
|
23
20
|
exports?: Record<string, Record<string, string>>;
|
|
24
|
-
/** Explicit mappings for verified local filters or forks; no module is executed. */
|
|
25
|
-
filters?: Record<string, FilterKind>;
|
|
26
21
|
/** Explicit classification for packs whose type cannot be inferred. */
|
|
27
22
|
packKinds?: Record<string, PackInfo['kind']>;
|
|
28
23
|
/** Editor schema reference inserted into the converted config. */
|
package/dist/src/plan.d.ts
CHANGED
package/dist/src/plan.js
CHANGED
|
@@ -81,10 +81,10 @@ export function planBuild(config, profileName = 'default') {
|
|
|
81
81
|
if (step.mode !== undefined && step.mode !== 'auto' && step.mode !== 'always') {
|
|
82
82
|
throw new Error(`Invalid plugin mode: ${step.plugin}`);
|
|
83
83
|
}
|
|
84
|
-
if ('
|
|
84
|
+
if (!('module' in definition) && step.mode === 'auto') {
|
|
85
85
|
throw new Error(`Automatic detection requires a module plugin: ${step.plugin}`);
|
|
86
86
|
}
|
|
87
|
-
if ('
|
|
87
|
+
if (!('module' in definition) && (step.packs !== undefined || step.links !== undefined)) {
|
|
88
88
|
throw new Error(`Pack and link overrides require a native module plugin: ${step.plugin}`);
|
|
89
89
|
}
|
|
90
90
|
if ('module' in definition && (step.packs !== undefined || step.links !== undefined)) {
|
|
@@ -101,9 +101,9 @@ export function planBuild(config, profileName = 'default') {
|
|
|
101
101
|
if ('module' in definition && Object.keys(scriptOverrides).length) {
|
|
102
102
|
throw new Error(`Folder and data overrides require a Node script: ${step.plugin}`);
|
|
103
103
|
}
|
|
104
|
-
const script = '
|
|
105
|
-
?
|
|
106
|
-
:
|
|
104
|
+
const script = 'module' in definition
|
|
105
|
+
? undefined
|
|
106
|
+
: validatePluginDefinition({ ...definition, ...scriptOverrides }, step.plugin);
|
|
107
107
|
if (script?.persistData && script.dataPath === undefined) {
|
|
108
108
|
throw new Error(`Persistent Node data requires an explicit dataPath: ${step.plugin}`);
|
|
109
109
|
}
|
package/dist/src/regolith.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { BuildContext } from './contract.d.ts';
|
|
2
2
|
import type { NodePluginDefinition, Settings } from './config.ts';
|
|
3
|
-
|
|
3
|
+
type NodeFilterOptions = NodePluginDefinition & {
|
|
4
4
|
settings?: Settings;
|
|
5
5
|
arguments?: string[];
|
|
6
|
-
}
|
|
7
|
-
/** Run a
|
|
6
|
+
};
|
|
7
|
+
/** Run a Node entry against conventional staged BP, RP and data folders. */
|
|
8
8
|
export declare function runNodeFilter(context: BuildContext, options: NodeFilterOptions, sharedContext?: BuildContext): Promise<void>;
|
|
9
9
|
/** Publish opted-in data with pack publication, restoring authored data if publication fails. */
|
|
10
10
|
export declare function publishNodeData<T>(context: BuildContext, publish: () => Promise<T>): Promise<T>;
|
package/dist/src/regolith.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm } from 'node:fs/promises';
|
|
4
|
+
import { createRequire, isBuiltin } from 'node:module';
|
|
4
5
|
import path from 'node:path';
|
|
5
6
|
import { createInterface } from 'node:readline';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
import { resolve } from 'import-meta-resolve';
|
|
6
9
|
import { withSourceWrites } from './source-writes.js';
|
|
7
10
|
const sessions = new WeakMap();
|
|
8
11
|
const roles = ['BP', 'RP'];
|
|
@@ -191,11 +194,30 @@ async function execute(context, options, directory, script, filterDir) {
|
|
|
191
194
|
});
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
|
-
|
|
197
|
+
function moduleEntry(specifier, filterDir) {
|
|
198
|
+
if (specifier.startsWith('.') || path.isAbsolute(specifier) || specifier.includes(':') || isBuiltin(specifier)) {
|
|
199
|
+
throw new Error('Node filter module must be a package specifier: ' + specifier);
|
|
200
|
+
}
|
|
201
|
+
const parent = pathToFileURL(path.join(filterDir, 'package.json'));
|
|
202
|
+
try {
|
|
203
|
+
return fileURLToPath(resolve(specifier, parent.href));
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
try {
|
|
207
|
+
return createRequire(parent).resolve(specifier);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
throw new Error('Cannot resolve Node filter module ' + specifier + ' from ' + filterDir, { cause: error });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** Run a Node entry against conventional staged BP, RP and data folders. */
|
|
195
215
|
export async function runNodeFilter(context, options, sharedContext = context) {
|
|
196
216
|
context.signal?.throwIfAborted();
|
|
197
217
|
const filterDir = await realpath(path.resolve(context.projectRoot, options.filterDir ?? '.'));
|
|
198
|
-
const script = await realpath(
|
|
218
|
+
const script = await realpath(options.nodeModule === undefined
|
|
219
|
+
? path.resolve(filterDir, options.script)
|
|
220
|
+
: moduleEntry(options.nodeModule, filterDir));
|
|
199
221
|
if (!(await lstat(script)).isFile()) {
|
|
200
222
|
throw new Error('Node filter script must be a file: ' + script);
|
|
201
223
|
}
|