Skip to content

Commit 49f8178

Browse files
authored
provide informative error if Feature id does not match its containing folder
1 parent 1da368b commit 49f8178

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/spec-node/collectionCommonUtils/packageCommandImpl.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -183,39 +183,44 @@ export async function packageCollection(args: PackageCommandInput, collectionTyp
183183
// Validate minimal folder structure
184184
const devcontainerJsonName = `devcontainer-${collectionType}.json`;
185185

186+
// Be tolerant of other folders that may not contain Feature source code
186187
if (!(await isLocalFile(path.join(folder, devcontainerJsonName)))) {
187-
output.write(`(!) WARNING: ${collectionType} '${c}' is missing a ${devcontainerJsonName}. Skipping... `, LogLevel.Warning);
188+
output.write(`(!) WARNING: ${collectionType} '${c}' is missing a ${devcontainerJsonName}. Skipping...`, LogLevel.Warning);
188189
continue;
189190
}
190191

191192
const tmpSrcDir = path.join(os.tmpdir(), `/templates-src-output-${Date.now()}`);
192193
await cpDirectoryLocal(folder, tmpSrcDir);
194+
const jsonPath = path.join(tmpSrcDir, devcontainerJsonName);
195+
const metadata = jsonc.parse(await readLocalFile(jsonPath, 'utf-8'));
193196

194-
const archiveName = getArchiveName(c, collectionType);
197+
if (!metadata.id || !metadata.version || !metadata.name) {
198+
output.write(`ERROR: ${collectionType} '${c}' is missing one of the following required properties in its ${devcontainerJsonName}: 'id', 'version', 'name'.`, LogLevel.Error);
199+
return;
200+
}
195201

196-
const jsonPath = path.join(tmpSrcDir, devcontainerJsonName);
202+
// Validate that the 'id' field in the metadata property matches the folder name
203+
if (c !== metadata.id) {
204+
output.write(`ERROR: ${collectionType} id '${metadata.id}' does not match its containing folder name '${c}'.`, LogLevel.Error);
205+
return;
206+
}
197207

198208
if (collectionType === 'feature') {
199209
const installShPath = path.join(tmpSrcDir, 'install.sh');
200210
if (!(await isLocalFile(installShPath))) {
201211
output.write(`Feature '${c}' is missing an install.sh`, LogLevel.Error);
202212
return;
203213
}
204-
205214
await addsAdditionalFeatureProps(jsonPath, output);
206215
} else if (collectionType === 'template') {
207216
if (!(await addsAdditionalTemplateProps(tmpSrcDir, jsonPath, output))) {
208217
return;
209218
}
210219
}
211220

221+
const archiveName = getArchiveName(c, collectionType);
212222
await tarDirectory(tmpSrcDir, archiveName, outputDir);
213223

214-
const metadata = jsonc.parse(await readLocalFile(jsonPath, 'utf-8'));
215-
if (!metadata.id || !metadata.version || !metadata.name) {
216-
output.write(`${collectionType} '${c}' is missing one of the following required properties in its ${devcontainerJsonName}: 'id', 'version', 'name'.`, LogLevel.Error);
217-
return;
218-
}
219224
metadatas.push(metadata);
220225
await rmLocal(tmpSrcDir, { recursive: true, force: true });
221226
}

src/spec-node/featuresCLI/packageCommandImpl.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export async function doFeaturesPackageCommand(args: PackageCommandInput): Promi
2323
let metadataOutput: Feature[] | undefined = [];
2424
if (isSingleFeature) {
2525
// Package individual features
26-
output.write('Packaging single feature...', LogLevel.Info);
26+
output.write('Packaging single Feature...', LogLevel.Info);
2727
metadataOutput = await packageSingleFeature(args);
2828
} else {
29-
output.write('Packaging feature collection...', LogLevel.Info);
29+
output.write('Packaging Feature collection...', LogLevel.Info);
3030
metadataOutput = await packageFeatureCollection(args);
3131
}
3232

3333
if (!metadataOutput) {
34-
output.write('Failed to package features', LogLevel.Error);
34+
output.write('Failed to package Features', LogLevel.Error);
3535
return undefined;
3636
}
3737

0 commit comments

Comments
 (0)