Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit e9a101e

Browse files
fix: address copilot review comments on sync-jekyll-includes task
- Explicitly test existingPattern before replace; if no entry exists yet, insert one under the include: block (or create the block) rather than silently no-oping and logging a misleading "already references" message - Call done(e) in the catch block so gulp/CI fails loudly instead of completing successfully with a broken _config.yml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8d364d3 commit e9a101e

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

config/gulp/javascript.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,38 @@ gulp.task('sync-jekyll-includes', function (done) {
3232

3333
if (helpersFile) {
3434
var includePath = includePrefix + helpersFile;
35-
var updated = config.replace(existingPattern, includePath);
36-
if (updated !== config) {
37-
fs.writeFileSync(configPath, updated);
38-
console.log('sync-jekyll-includes: updated _config.yml to include ' + helpersFile);
35+
36+
if (existingPattern.test(config)) {
37+
var updated = config.replace(existingPattern, includePath);
38+
if (updated !== config) {
39+
fs.writeFileSync(configPath, updated);
40+
console.log('sync-jekyll-includes: updated _config.yml to include ' + helpersFile);
41+
} else {
42+
console.log('sync-jekyll-includes: _config.yml already references ' + helpersFile);
43+
}
3944
} else {
40-
console.log('sync-jekyll-includes: _config.yml already references ' + helpersFile);
45+
// No existing _commonjsHelpers entry — insert one under the include: block.
46+
var includeBlockPattern = /^include:[^\n]*$/m;
47+
var updatedConfig;
48+
if (includeBlockPattern.test(config)) {
49+
updatedConfig = config.replace(includeBlockPattern, function (line) {
50+
return line + '\n - ' + includePath;
51+
});
52+
} else {
53+
updatedConfig = config + '\ninclude:\n - ' + includePath + '\n';
54+
}
55+
fs.writeFileSync(configPath, updatedConfig);
56+
console.log('sync-jekyll-includes: added _config.yml include for ' + helpersFile);
4157
}
4258
} else {
4359
console.log('sync-jekyll-includes: no _commonjsHelpers file in web-components package, nothing to update');
4460
}
4561
} catch (e) {
4662
console.warn('sync-jekyll-includes: could not sync _config.yml includes:', e.message);
63+
return done(e);
4764
}
4865

49-
done();
66+
return done();
5067
});
5168

5269
gulp.task('javascript', gulp.series('copy-web-components-js', 'sync-jekyll-includes'));

0 commit comments

Comments
 (0)