@@ -183,39 +183,44 @@ export async function packageCollection(args: PackageCommandInput, collectionTyp
183
183
// Validate minimal folder structure
184
184
const devcontainerJsonName = `devcontainer-${ collectionType } .json` ;
185
185
186
+ // Be tolerant of other folders that may not contain Feature source code
186
187
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 ) ;
188
189
continue ;
189
190
}
190
191
191
192
const tmpSrcDir = path . join ( os . tmpdir ( ) , `/templates-src-output-${ Date . now ( ) } ` ) ;
192
193
await cpDirectoryLocal ( folder , tmpSrcDir ) ;
194
+ const jsonPath = path . join ( tmpSrcDir , devcontainerJsonName ) ;
195
+ const metadata = jsonc . parse ( await readLocalFile ( jsonPath , 'utf-8' ) ) ;
193
196
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
+ }
195
201
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
+ }
197
207
198
208
if ( collectionType === 'feature' ) {
199
209
const installShPath = path . join ( tmpSrcDir , 'install.sh' ) ;
200
210
if ( ! ( await isLocalFile ( installShPath ) ) ) {
201
211
output . write ( `Feature '${ c } ' is missing an install.sh` , LogLevel . Error ) ;
202
212
return ;
203
213
}
204
-
205
214
await addsAdditionalFeatureProps ( jsonPath , output ) ;
206
215
} else if ( collectionType === 'template' ) {
207
216
if ( ! ( await addsAdditionalTemplateProps ( tmpSrcDir , jsonPath , output ) ) ) {
208
217
return ;
209
218
}
210
219
}
211
220
221
+ const archiveName = getArchiveName ( c , collectionType ) ;
212
222
await tarDirectory ( tmpSrcDir , archiveName , outputDir ) ;
213
223
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
- }
219
224
metadatas . push ( metadata ) ;
220
225
await rmLocal ( tmpSrcDir , { recursive : true , force : true } ) ;
221
226
}
0 commit comments