Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: enable Node cache before loading modules #3894

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/core/bin/rsbuild.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env node
import { __internalHelper, logger } from '../dist/index.js';
import nodeModule from 'node:module';

const { runCli, prepareCli } = __internalHelper;
// enable on-disk code caching of all modules loaded by Node.js
// requires Nodejs >= 22.8.0
// @ts-expect-error enableCompileCache is not typed in `@types/node` 18.x
const { enableCompileCache } = nodeModule;
if (enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
enableCompileCache();
} catch {
// ignore errors
}
}

async function main() {
const { __internalHelper, logger } = await import('../dist/index.js');
const { runCli, prepareCli } = __internalHelper;

prepareCli();

try {
Expand Down
11 changes: 0 additions & 11 deletions packages/core/src/cli/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import nodeModule from 'node:module';
import { logger } from '../logger';

function initNodeEnv() {
Expand All @@ -13,16 +12,6 @@ function initNodeEnv() {
export function prepareCli(): void {
initNodeEnv();

// @ts-expect-error enableCompileCache is not typed yet
const { enableCompileCache } = nodeModule;
if (enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
enableCompileCache();
} catch {
// ignore errors
}
}

// Print a blank line to keep the greet log nice.
// Some package managers automatically output a blank line, some do not.
const { npm_execpath } = process.env;
Expand Down
Loading