Files
repomix-mirror/bin/repomix.cjs
Kazuki Yamada e0971a1031 perf(cli): Propagate compile cache to child_process workers
The existing enableCompileCache() in bin/repomix.cjs only applied to the
main process. Tinypool child_process workers (defaultAction) were spawned
without compile cache because NODE_COMPILE_CACHE env var was not set.

Capture the cache directory from enableCompileCache()'s return value and
set it as NODE_COMPILE_CACHE env var so child_process workers inherit it
at startup — before any ESM static imports are resolved.

Note: worker_threads workers (fileProcess, securityCheck, calculateMetrics)
already benefit from the main process's enableCompileCache() call since
they share the same V8 isolate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 01:27:03 +09:00

75 lines
1.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
// https://nodejs.org/api/module.html#module-compile-cache
// Enable compile cache for the main process and propagate the cache directory
// via NODE_COMPILE_CACHE env var so child_process workers inherit it at startup
// (before any modules are loaded), which is critical for ESM static imports.
const nodeModule = require('node:module');
if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
const result = nodeModule.enableCompileCache();
if (result && result.directory && !process.env.NODE_COMPILE_CACHE) {
process.env.NODE_COMPILE_CACHE = result.directory;
}
} catch {
// Ignore errors
}
}
const nodeVersion = process.versions.node;
const [major] = nodeVersion.split('.').map(Number);
const EXIT_CODES = {
SUCCESS: 0,
ERROR: 1,
};
if (major < 20) {
console.warn(
`Warning: Repomix recommends Node.js version 20 or higher. Current version: ${nodeVersion}. Some features may not work as expected.\n`,
);
}
function setupErrorHandlers() {
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
process.exit(EXIT_CODES.ERROR);
});
process.on('unhandledRejection', (reason) => {
console.error('Unhandled Promise Rejection:', reason);
process.exit(EXIT_CODES.ERROR);
});
function shutdown() {
process.exit(EXIT_CODES.SUCCESS);
}
process.on('SIGINT', () => {
console.log('\nReceived SIGINT. Shutting down...');
shutdown();
});
process.on('SIGTERM', shutdown);
}
(async () => {
try {
setupErrorHandlers();
const { run } = await import('../lib/cli/cliRun.js');
await run();
} catch (error) {
if (error instanceof Error) {
console.error('Fatal Error:', {
name: error.name,
message: error.message,
stack: error.stack,
});
} else {
console.error('Fatal Error:', error);
}
process.exit(EXIT_CODES.ERROR);
}
})();