Skip to content

Commit 5c3e842

Browse files
authored
chore: remove unmaintained metalsmith plugins (#4551)
* chore: remove unmaintained metalsmith plugins Replace with inline equivalents. This addresses some security warnings in the GitHub interface and in `npm audit`. (The warnings are relevant to our build tooling, not to the site.) * fixup! chore: remove unmaintained metalsmith plugins
1 parent ba4039b commit 5c3e842

File tree

3 files changed

+46
-125
lines changed

3 files changed

+46
-125
lines changed

build.js

+40-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const path = require('path');
1414
const Metalsmith = require('metalsmith');
1515
const collections = require('metalsmith-collections');
1616
const feed = require('metalsmith-feed');
17-
const discoverHelpers = require('metalsmith-discover-helpers');
18-
const discoverPartials = require('metalsmith-discover-partials');
1917
const layouts = require('metalsmith-layouts');
2018
const markdown = require('@metalsmith/markdown');
2119
const permalinks = require('@metalsmith/permalinks');
@@ -29,6 +27,8 @@ const ncp = require('ncp');
2927
const junk = require('junk');
3028
const semver = require('semver');
3129
const replace = require('metalsmith-one-replace');
30+
const glob = require('glob');
31+
const Handlebars = require('handlebars');
3232

3333
const githubLinks = require('./scripts/plugins/githubLinks');
3434
const navigation = require('./scripts/plugins/navigation');
@@ -41,7 +41,7 @@ const latestVersion = require('./scripts/helpers/latestversion');
4141
const DEFAULT_LANG = 'en';
4242

4343
// The history links of nodejs versions at doc/index.md
44-
const nodejsVersionsContent = require('fs')
44+
const nodejsVersionsContent = fs
4545
.readFileSync('./source/nodejsVersions.md')
4646
.toString();
4747

@@ -190,18 +190,43 @@ function buildLocale(source, locale, opts) {
190190
// Finally, this compiles the rest of the layouts present in ./layouts.
191191
// They're language-agnostic, but have to be regenerated for every locale
192192
// anyways.
193-
.use(
194-
discoverPartials({
195-
directory: 'layouts/partials',
196-
pattern: /\.hbs$/
197-
})
198-
)
199-
.use(
200-
discoverHelpers({
201-
directory: 'scripts/helpers',
202-
pattern: /\.js$/
203-
})
204-
)
193+
.use((files, metalsmith, done) => {
194+
const fsPromises = require('fs/promises');
195+
glob(
196+
`${metalsmith.path('layouts/partials')}/**/*.hbs`,
197+
{},
198+
async (err, matches) => {
199+
if (err) {
200+
throw err;
201+
}
202+
await Promise.all(
203+
matches.map(async (file) => {
204+
const contents = await fsPromises.readFile(file, 'utf8');
205+
const id = path.basename(file, path.extname(file));
206+
return Handlebars.registerPartial(id, contents);
207+
})
208+
);
209+
done();
210+
}
211+
);
212+
})
213+
.use((files, metalsmith, done) => {
214+
glob(
215+
`${metalsmith.path('scripts/helpers')}/**/*.js`,
216+
{},
217+
(err, matches) => {
218+
if (err) {
219+
throw err;
220+
}
221+
matches.forEach((file) => {
222+
const fn = require(path.resolve(file));
223+
const id = path.basename(file, path.extname(file));
224+
return Handlebars.registerHelper(id, fn);
225+
});
226+
done();
227+
}
228+
);
229+
})
205230
.use(layouts())
206231
// Pipes the generated files into their respective subdirectory in the build
207232
// directory.

package-lock.json

+5-108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
"marked": "^4.0.14",
4444
"metalsmith": "^2.4.2",
4545
"metalsmith-collections": "^0.9.0",
46-
"metalsmith-discover-helpers": "^0.1.1",
47-
"metalsmith-discover-partials": "^0.1.2",
4846
"metalsmith-feed": "^1.0.0",
4947
"metalsmith-layouts": "^2.3.1",
5048
"metalsmith-one-replace": "^0.1.7",
@@ -68,6 +66,7 @@
6866
"eslint-plugin-node": "^11.1.0",
6967
"eslint-plugin-prettier": "^4.0.0",
7068
"eslint-plugin-promise": "^6.0.0",
69+
"glob": "^7.2.0",
7170
"lockfile-lint": "^4.7.4",
7271
"nock": "^13.2.4",
7372
"node-fetch": "^2.6.7",

0 commit comments

Comments
 (0)