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

Commit 0f07f07

Browse files
authored
Merge pull request #5958 from department-of-veterans-affairs/fix/metrics-dashboard-js-errors
fix: metrics dashboard JS errors in Safari (missing _commonjsHelpers)
2 parents 081cef3 + e9a101e commit 0f07f07

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ collections:
8787
permalink: /deprecated/:title
8888

8989
include:
90-
- vendor/javascripts/component-library/dist/esm/_commonjsHelpers-8b28c6fa.js
90+
- vendor/javascripts/component-library/dist/esm/_commonjsHelpers-B85MJLTf.js
9191

9292
# Exclusions are relative to the source directory (which is set to src)
9393
exclude:

config/gulp/javascript.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var gulp = require('gulp');
2+
var fs = require('fs');
23

34
gulp.task('copy-web-components-js', function (done) {
45
console.log('copying web-components javascript');
@@ -9,4 +10,60 @@ gulp.task('copy-web-components-js', function (done) {
910
return stream;
1011
});
1112

12-
gulp.task('javascript', gulp.series('copy-web-components-js'));
13+
// Jekyll excludes files starting with `_` unless they are listed in the
14+
// `include` array in _config.yml. The Stencil build sometimes emits a
15+
// `_commonjsHelpers-<hash>.js` chunk whose hash changes with each
16+
// web-components release. This task reads the actual installed package,
17+
// finds the current filename (if any), and keeps _config.yml in sync so
18+
// the file is never silently dropped from the Jekyll build.
19+
gulp.task('sync-jekyll-includes', function (done) {
20+
var esmDir = './node_modules/@department-of-veterans-affairs/web-components/dist/esm/';
21+
var configPath = './_config.yml';
22+
var includePrefix = 'vendor/javascripts/component-library/dist/esm/';
23+
24+
try {
25+
var files = fs.readdirSync(esmDir);
26+
var helpersFile = files.find(function (f) {
27+
return /^_commonjsHelpers-.*\.js$/.test(f);
28+
});
29+
30+
var config = fs.readFileSync(configPath, 'utf8');
31+
var existingPattern = /vendor\/javascripts\/component-library\/dist\/esm\/_commonjsHelpers-[^\s\n]+/;
32+
33+
if (helpersFile) {
34+
var includePath = includePrefix + 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+
}
44+
} else {
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);
57+
}
58+
} else {
59+
console.log('sync-jekyll-includes: no _commonjsHelpers file in web-components package, nothing to update');
60+
}
61+
} catch (e) {
62+
console.warn('sync-jekyll-includes: could not sync _config.yml includes:', e.message);
63+
return done(e);
64+
}
65+
66+
return done();
67+
});
68+
69+
gulp.task('javascript', gulp.series('copy-web-components-js', 'sync-jekyll-includes'));

0 commit comments

Comments
 (0)