Skip to content

Commit 3578d45

Browse files
authored
perf(cli): enable the Node.js compile cache (#17782)
1 parent aa33b44 commit 3578d45

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

.changeset/tidy-pears-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Improves the performance of the Astro CLI in local by enabling Node's module compilation cache.

packages/astro/bin/astro.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#!/usr/bin/env node
22
'use strict';
33

4+
import module from 'node:module';
5+
6+
// In CI writing the cache is (most of the time) harmful, as it'll never get re-used and just slows down the CLI.
7+
if (!process.env.CI) {
8+
try {
9+
module.enableCompileCache?.();
10+
// Long-running commands like `astro dev` never reach the flush that happens on process exit.
11+
setTimeout(() => {
12+
try {
13+
module.flushCompileCache?.();
14+
} catch {}
15+
}, 10_000).unref();
16+
} catch {}
17+
}
18+
419
const CI_INSTRUCTIONS = {
520
NETLIFY: 'https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript',
621
GITHUB_ACTIONS:

0 commit comments

Comments
 (0)