Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadashy committed Jan 25, 2025
1 parent f0b1c1c commit fc20dde
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 75 deletions.
1 change: 0 additions & 1 deletion src/config/configLoad.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'node:fs/promises';
import path from 'node:path';
import stripJsonComments from 'strip-json-comments';
import { z } from 'zod';
import { RepomixError, rethrowValidationErrorIfZodError } from '../shared/errorHandle.js';
import { logger } from '../shared/logger.js';
import {
Expand Down
14 changes: 2 additions & 12 deletions src/core/file/fileCollect.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import pc from 'picocolors';
import { Piscina } from 'piscina';
import { logger } from '../../shared/logger.js';
import { getWorkerThreadCount } from '../../shared/processConcurrency.js';
import { initPiscina } from '../../shared/processConcurrency.js';
import type { RepomixProgressCallback } from '../../shared/types.js';
import type { RawFile } from './fileTypes.js';
import type { FileCollectTask } from './workers/fileCollectWorker.js';

const initTaskRunner = (numOfTasks: number) => {
const { minThreads, maxThreads } = getWorkerThreadCount(numOfTasks);
logger.trace(`Initializing worker pool with min=${minThreads}, max=${maxThreads} threads`);

const pool = new Piscina({
filename: new URL('./workers/fileCollectWorker.js', import.meta.url).href,
minThreads,
maxThreads,
idleTimeout: 5000,
});

const pool = initPiscina(numOfTasks, new URL('./workers/fileCollectWorker.js', import.meta.url).href);
return (task: FileCollectTask) => pool.run(task);
};

Check warning on line 11 in src/core/file/fileCollect.ts

View check run for this annotation

Codecov / codecov/patch

src/core/file/fileCollect.ts#L9-L11

Added lines #L9 - L11 were not covered by tests

Expand Down
14 changes: 2 additions & 12 deletions src/core/file/fileProcess.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import pc from 'picocolors';
import { Piscina } from 'piscina';
import type { RepomixConfigMerged } from '../../config/configSchema.js';
import { logger } from '../../shared/logger.js';
import { getWorkerThreadCount } from '../../shared/processConcurrency.js';
import { initPiscina } from '../../shared/processConcurrency.js';
import type { RepomixProgressCallback } from '../../shared/types.js';
import type { ProcessedFile, RawFile } from './fileTypes.js';
import type { FileProcessTask } from './workers/fileProcessWorker.js';

const initTaskRunner = (numOfTasks: number) => {
const { minThreads, maxThreads } = getWorkerThreadCount(numOfTasks);
logger.trace(`Initializing worker pool with min=${minThreads}, max=${maxThreads} threads`);

const pool = new Piscina({
filename: new URL('./workers/fileProcessWorker.js', import.meta.url).href,
minThreads,
maxThreads,
idleTimeout: 5000,
});

const pool = initPiscina(numOfTasks, new URL('./workers/fileProcessWorker.js', import.meta.url).href);
return (task: FileProcessTask) => pool.run(task);
};

Check warning on line 12 in src/core/file/fileProcess.ts

View check run for this annotation

Codecov / codecov/patch

src/core/file/fileProcess.ts#L10-L12

Added lines #L10 - L12 were not covered by tests

Expand Down
14 changes: 2 additions & 12 deletions src/core/metrics/calculateAllFileMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import pc from 'picocolors';
import { Piscina } from 'piscina';
import type { TiktokenEncoding } from 'tiktoken';
import { logger } from '../../shared/logger.js';
import { getWorkerThreadCount } from '../../shared/processConcurrency.js';
import { initPiscina } from '../../shared/processConcurrency.js';
import type { RepomixProgressCallback } from '../../shared/types.js';
import type { ProcessedFile } from '../file/fileTypes.js';
import type { FileMetricsTask } from './workers/fileMetricsWorker.js';
import type { FileMetrics } from './workers/types.js';

const initTaskRunner = (numOfTasks: number) => {
const { minThreads, maxThreads } = getWorkerThreadCount(numOfTasks);
logger.trace(`Initializing worker pool with min=${minThreads}, max=${maxThreads} threads`);

const pool = new Piscina({
filename: new URL('./workers/fileMetricsWorker.js', import.meta.url).href,
minThreads,
maxThreads,
idleTimeout: 5000,
});

const pool = initPiscina(numOfTasks, new URL('./workers/fileMetricsWorker.js', import.meta.url).href);
return (task: FileMetricsTask) => pool.run(task);
};

Check warning on line 13 in src/core/metrics/calculateAllFileMetrics.ts

View check run for this annotation

Codecov / codecov/patch

src/core/metrics/calculateAllFileMetrics.ts#L11-L13

Added lines #L11 - L13 were not covered by tests

Expand Down
13 changes: 2 additions & 11 deletions src/core/metrics/calculateOutputMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Piscina } from 'piscina';
import type { TiktokenEncoding } from 'tiktoken';
import { logger } from '../../shared/logger.js';
import { initPiscina } from '../../shared/processConcurrency.js';
import type { OutputMetricsTask } from './workers/outputMetricsWorker.js';

const initTaskRunner = () => {
const pool = new Piscina({
filename: new URL('./workers/outputMetricsWorker.js', import.meta.url).href,
// Set minThreads and maxThreads to 1
minThreads: 1,
maxThreads: 1,
idleTimeout: 5000,
});

const pool = initPiscina(1, new URL('./workers/outputMetricsWorker.js', import.meta.url).href);
return (task: OutputMetricsTask) => pool.run(task);
};

Check warning on line 9 in src/core/metrics/calculateOutputMetrics.ts

View check run for this annotation

Codecov / codecov/patch

src/core/metrics/calculateOutputMetrics.ts#L7-L9

Added lines #L7 - L9 were not covered by tests

Expand Down
16 changes: 2 additions & 14 deletions src/core/security/securityCheck.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import pc from 'picocolors';
import { Piscina } from 'piscina';
import { logger } from '../../shared/logger.js';
import { getWorkerThreadCount } from '../../shared/processConcurrency.js';
import { initPiscina } from '../../shared/processConcurrency.js';
import type { RepomixProgressCallback } from '../../shared/types.js';
import type { RawFile } from '../file/fileTypes.js';
import type { SecurityCheckTask } from './workers/securityCheckWorker.js';
Expand All @@ -14,16 +11,7 @@ export interface SuspiciousFileResult {
}

const initTaskRunner = (numOfTasks: number) => {
const { minThreads, maxThreads } = getWorkerThreadCount(numOfTasks);
logger.trace(`Initializing worker pool with min=${minThreads}, max=${maxThreads} threads`);

const pool = new Piscina({
filename: new URL('./workers/securityCheckWorker.js', import.meta.url).href,
minThreads,
maxThreads,
idleTimeout: 5000,
});

const pool = initPiscina(numOfTasks, new URL('./workers/securityCheckWorker.js', import.meta.url).href);
return (task: SecurityCheckTask) => pool.run(task);
};

Check warning on line 16 in src/core/security/securityCheck.ts

View check run for this annotation

Codecov / codecov/patch

src/core/security/securityCheck.ts#L14-L16

Added lines #L14 - L16 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion src/core/security/workers/securityCheckWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lintSource } from '@secretlint/core';
import { creator } from '@secretlint/secretlint-rule-preset-recommend';
import type { SecretLintCoreConfig, SecretLintCoreResult } from '@secretlint/types';
import type { SecretLintCoreConfig } from '@secretlint/types';
import { logger } from '../../../shared/logger.js';

export interface SecurityCheckTask {
Expand Down
17 changes: 17 additions & 0 deletions src/shared/processConcurrency.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os from 'node:os';
import { Piscina } from 'piscina';
import { logger } from './logger.js';

export const getProcessConcurrency = (): number => {
return typeof os.availableParallelism === 'function' ? os.availableParallelism() : os.cpus().length;
Expand All @@ -17,3 +19,18 @@ export const getWorkerThreadCount = (numOfTasks: number): { minThreads: number;
maxThreads,
};
};

export const initPiscina = (numOfTasks: number, workerPath: string): Piscina => {
const { minThreads, maxThreads } = getWorkerThreadCount(numOfTasks);

Check warning on line 24 in src/shared/processConcurrency.ts

View check run for this annotation

Codecov / codecov/patch

src/shared/processConcurrency.ts#L24

Added line #L24 was not covered by tests

logger.trace(
`Initializing worker pool with min=${minThreads}, max=${maxThreads} threads. Worker path: ${workerPath}`,
);

Check warning on line 28 in src/shared/processConcurrency.ts

View check run for this annotation

Codecov / codecov/patch

src/shared/processConcurrency.ts#L26-L28

Added lines #L26 - L28 were not covered by tests

return new Piscina({
filename: workerPath,
minThreads,
maxThreads,
idleTimeout: 5000,
});

Check warning on line 35 in src/shared/processConcurrency.ts

View check run for this annotation

Codecov / codecov/patch

src/shared/processConcurrency.ts#L30-L35

Added lines #L30 - L35 were not covered by tests
};
1 change: 0 additions & 1 deletion tests/cli/actions/remoteAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
isValidRemoteValue,
runRemoteAction,
} from '../../../src/cli/actions/remoteAction.js';
import type { SuspiciousFileResult } from '../../../src/core/security/securityCheck.js';
import { createMockConfig } from '../../testing/testUtils.js';

vi.mock('node:fs/promises', async (importOriginal) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cliPrint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
import { printCompletion, printSecurityCheck, printSummary, printTopFiles } from '../../src/cli/cliPrint.js';
import type { SuspiciousFileResult } from '../../src/core/security/securityCheck.js';
import { logger } from '../../src/shared/logger.js';
import { createMockConfig, isWindows } from '../testing/testUtils.js';
import { createMockConfig } from '../testing/testUtils.js';

vi.mock('../../src/shared/logger');
vi.mock('picocolors', () => ({
Expand Down
3 changes: 1 addition & 2 deletions tests/config/configSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { outro } from '@clack/prompts';
import { describe, expect, it } from 'vitest';
import { custom, z } from 'zod';
import { z } from 'zod';
import {
repomixConfigBaseSchema,
repomixConfigCliSchema,
Expand Down
8 changes: 3 additions & 5 deletions tests/core/metrics/calculateAllFileMetrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import type { ProcessedFile } from '../../../src/core/file/fileTypes.js';
import { calculateAllFileMetrics } from '../../../src/core/metrics/calculateAllFileMetrics.js';
import {
type FileMetricsTask,
calculateIndividualFileMetrics,
} from '../../../src/core/metrics/workers/fileMetricsWorker.js';
import type { FileMetricsTask } from '../../../src/core/metrics/workers/fileMetricsWorker.js';
import fileMetricsWorker from '../../../src/core/metrics/workers/fileMetricsWorker.js';
import type { RepomixProgressCallback } from '../../../src/shared/types.js';

vi.mock('../../shared/processConcurrency', () => ({
Expand All @@ -13,7 +11,7 @@ vi.mock('../../shared/processConcurrency', () => ({

const mockInitTaskRunner = (numOfTasks: number) => {
return async (task: FileMetricsTask) => {
return await calculateIndividualFileMetrics(task.file, task.encoding);
return await fileMetricsWorker(task);
};
};

Expand Down
1 change: 0 additions & 1 deletion tests/core/packager/copyToClipboardIfEnabled.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import clipboard from 'clipboardy';
import { logger } from 'handlebars';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { RepomixConfigMerged } from '../../../src/config/configSchema.js';
import { copyToClipboardIfEnabled } from '../../../src/core/packager/copyToClipboardIfEnabled.js';
Expand Down
2 changes: 1 addition & 1 deletion website/compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Run website in development mode
# $ docker-compose -f website/compose.yml up --build
# $ docker compose -f website/compose.yml up --build

services:
client:
Expand Down
2 changes: 1 addition & 1 deletion website/server/src/utils/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pako from 'pako';
import type { PackOptions, PackResult } from '../types.js';
import type { PackOptions } from '../types.js';

interface CacheEntry<T> {
value: Uint8Array; // Compressed data
Expand Down

0 comments on commit fc20dde

Please sign in to comment.