mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 09:40:34 +08:00
Refactor: use ROOT_DIR
This commit is contained in:
parent
57dc1b6787
commit
8340a0f4f5
@ -30,6 +30,7 @@ import { createSpan, printTraceResult, whyIsNodeRunning } from './trace';
|
||||
import { buildDeprecateFiles } from './build-deprecate-files';
|
||||
import { cacheGc } from './lib/make-fetch-happen';
|
||||
import path from 'node:path';
|
||||
import { ROOT_DIR } from './constants/dir';
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught exception:', error);
|
||||
@ -40,7 +41,7 @@ process.on('unhandledRejection', (reason) => {
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const buildFinishedLock = path.join(__dirname, '../.BUILD_FINISHED');
|
||||
const buildFinishedLock = path.join(ROOT_DIR, '.BUILD_FINISHED');
|
||||
|
||||
(async () => {
|
||||
console.log('Version:', process.version);
|
||||
|
||||
@ -18,6 +18,7 @@ import { Custom304NotModifiedError, CustomAbortError, CustomNoETagFallbackError,
|
||||
|
||||
import type { IncomingHttpHeaders } from 'undici/types/header';
|
||||
import { Headers } from 'undici';
|
||||
import { ROOT_DIR } from '../constants/dir';
|
||||
|
||||
export interface CacheOptions<S = string> {
|
||||
/** Path to sqlite file dir */
|
||||
@ -429,13 +430,11 @@ export class Cache<S = string> {
|
||||
}
|
||||
}
|
||||
|
||||
export const fsFetchCache = new Cache({ cachePath: path.resolve(__dirname, '../../.cache') });
|
||||
export const fsFetchCache = new Cache({ cachePath: path.resolve(ROOT_DIR, '.cache') });
|
||||
// process.on('exit', () => {
|
||||
// fsFetchCache.destroy();
|
||||
// });
|
||||
|
||||
// export const fsCache = traceSync('initializing filesystem cache', () => new Cache<Uint8Array>({ cachePath: path.resolve(__dirname, '../../.cache'), type: 'buffer' }));
|
||||
|
||||
const separator = '\u0000';
|
||||
export const serializeSet = (set: Set<string>) => fastStringArrayJoin(Array.from(set), separator);
|
||||
export const deserializeSet = (str: string) => new Set(str.split(separator));
|
||||
|
||||
@ -8,8 +8,9 @@ import process from 'node:process';
|
||||
import { exec } from 'tinyexec';
|
||||
import { mkdirp } from './misc';
|
||||
import { $$fetch } from './fetch-retry';
|
||||
import { ROOT_DIR } from '../constants/dir';
|
||||
|
||||
const mihomoBinaryDir = path.join(__dirname, '../../node_modules/.cache/mihomo');
|
||||
const mihomoBinaryDir = path.join(ROOT_DIR, '.cache/mihomo');
|
||||
const mihomoBinaryPath = path.join(mihomoBinaryDir, 'mihomo');
|
||||
|
||||
const mihomoBinaryUrl: Partial<Record<NodeJS.Platform, Partial<Record<NodeJS.Architecture, string>>>> = {
|
||||
|
||||
@ -16,6 +16,7 @@ export type UndiciResponseData<T = unknown> = Dispatcher.ResponseData<T>;
|
||||
|
||||
import { inspect } from 'node:util';
|
||||
import path from 'node:path';
|
||||
import { ROOT_DIR } from '../constants/dir';
|
||||
|
||||
const agent = new Agent({});
|
||||
|
||||
@ -105,7 +106,7 @@ setGlobalDispatcher(agent.compose(
|
||||
}),
|
||||
interceptors.cache({
|
||||
store: new BetterSqlite3CacheStore({
|
||||
location: path.resolve(__dirname, '../../.cache/undici-better-sqlite3-cache-store.db'),
|
||||
location: path.join(ROOT_DIR, '.cache/undici-better-sqlite3-cache-store.db'),
|
||||
maxEntrySize: 1024 * 1024 * 50 // 50 MiB
|
||||
})
|
||||
})
|
||||
|
||||
@ -5,8 +5,9 @@ import picocolors from 'picocolors';
|
||||
import { Cache } from './cache-filesystem';
|
||||
import { createMemoize } from 'foxts/serialized-memo';
|
||||
import type { MemoizeStorageProvider } from 'foxts/serialized-memo';
|
||||
import { ROOT_DIR } from '../constants/dir';
|
||||
|
||||
const fsMemoCache = new Cache({ cachePath: path.resolve(__dirname, '../../.cache'), tableName: 'fs_memo_cache' });
|
||||
const fsMemoCache = new Cache({ cachePath: path.join(ROOT_DIR, '.cache'), tableName: 'fs_memo_cache' });
|
||||
|
||||
const fsMemoCacheProvider: MemoizeStorageProvider = {
|
||||
has(key) {
|
||||
|
||||
@ -6,9 +6,10 @@ import fsp from 'node:fs/promises';
|
||||
// import picocolors from 'picocolors';
|
||||
|
||||
import { task } from '../trace';
|
||||
import { ROOT_DIR } from '../constants/dir';
|
||||
// import { bytes } from 'xbits';
|
||||
|
||||
const cachePath = path.resolve(__dirname, '../../.cache/__make_fetch_happen__');
|
||||
const cachePath = path.join(ROOT_DIR, '.cache/__make_fetch_happen__');
|
||||
// fs.mkdirSync(cachePath, { recursive: true });
|
||||
|
||||
// interface CacacheVerifyStats {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user