Skip to content

[pull] main from TryGhost:main#1217

Merged
pull[bot] merged 2 commits into
code:mainfrom
TryGhost:main
Jun 7, 2026
Merged

[pull] main from TryGhost:main#1217
pull[bot] merged 2 commits into
code:mainfrom
TryGhost:main

Conversation

@pull

@pull pull Bot commented Jun 7, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

EvanHahn added 2 commits June 7, 2026 13:29
ref #28393

*This change should have no user impact.*

If the i18n service was imported before it was initialized, its
reference would be forever stale. For example, this would fail if it was
run before `i18n.init()`:

```js
const {t} = require('./services/i18n');
// ...some time later...
console.log(t('foo'));
```

This hadn't happened yet, but we did have a test workaround for it. And
an upcoming change ran into this problem, so it's time to fix it.

I think this is a useful change on its own, but will also be useful for
[an upcoming change](#28393).
no ref

What
----

Before this change, we had a `registerDir` function that would register
all the files in a directory with Handlebars. Pseudocode:

```js
// old pseudocode
for (const path in glob(dir)) {
    const name = path.replace('.js', '');
    const fn = require(path);
    handlebars.register(name, fn);
}
```

After this change, we do an explicit `require` of everything.
`registerDir` is removed. Pseudocode:

```js
// new pseudocode
handlebars.register('asset', require('../../helpers/asset'));
handlebars.register('authors', require('../../helpers/authors'));
handlebars.register('body_class', require('../../helpers/body_class'));
// ...
```

Why
---

This has two main benefits:

- Startup is slightly faster.
- It's easier to convert these helpers to TypeScript now. (For example,
the old code wouldn't pick up `.ts` files.)

The main drawback is verbosity, which I think is worth it.
@pull pull Bot locked and limited conversation to collaborators Jun 7, 2026
@pull pull Bot added the ⤵️ pull label Jun 7, 2026
@pull pull Bot merged commit 83ec251 into code:main Jun 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant