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

refactor(file): move File from api to util #3489

Merged
merged 2 commits into from
Apr 30, 2022
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
1 change: 0 additions & 1 deletion packages/api/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { File } from './file.js';
export type { Position } from './position.js';
export type { Location } from './location.js';
export * from './mutant.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { File, PartialStrykerOptions } from '@stryker-mutator/api/core';
import { PartialStrykerOptions } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

export interface PresetConfiguration {
config: PartialStrykerOptions;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/initializer/presets/vue-js-preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inquirer from 'inquirer';
import { File, PartialStrykerOptions } from '@stryker-mutator/api/core';
import { PartialStrykerOptions } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

import { Preset } from './preset.js';
import { PresetConfiguration } from './preset-configuration.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/input/input-file-collection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { File, MutationRange } from '@stryker-mutator/api/core';
import { MutationRange } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { normalizeWhitespaces } from '@stryker-mutator/util';
import { File, normalizeWhitespaces } from '@stryker-mutator/util';

export class InputFileCollection {
public readonly files: readonly File[];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/input/input-file-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { isDeepStrictEqual } from 'util';

import { from, lastValueFrom } from 'rxjs';
import { filter, map, mergeMap, toArray } from 'rxjs/operators';
import { File, StrykerOptions, MutationRange } from '@stryker-mutator/api/core';
import { StrykerOptions, MutationRange } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
import { isErrnoException, notEmpty } from '@stryker-mutator/util';
import { File, isErrnoException, notEmpty } from '@stryker-mutator/util';
import minimatch, { type IMinimatch } from 'minimatch';

import { MAX_CONCURRENT_FILE_IO } from '../utils/file-utils.js';
Expand Down
11 changes: 3 additions & 8 deletions packages/core/src/process/2-mutant-instrumenter-executor.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { execaCommand } from 'execa';
import { Injector, tokens, commonTokens, BaseContext } from '@stryker-mutator/api/plugin';
import { createInstrumenter, InstrumentResult } from '@stryker-mutator/instrumenter';
import { File, StrykerOptions } from '@stryker-mutator/api/core';

import { StrykerOptions } from '@stryker-mutator/api/core';
import { Reporter } from '@stryker-mutator/api/src/report';

import { I } from '@stryker-mutator/util';

import { execaCommand } from 'execa';
import { File, I } from '@stryker-mutator/util';

import { coreTokens } from '../di/index.js';
import { InputFileCollection } from '../input/index.js';
import { Sandbox } from '../sandbox/sandbox.js';
import { LoggingClientContext } from '../logging/index.js';

import { ConcurrencyTokenProvider, createCheckerPool } from '../concurrent/index.js';
import { createCheckerFactory } from '../checker/index.js';
import { createPreprocessor } from '../sandbox/index.js';

import { Timer } from '../utils/timer.js';
import { TemporaryDirectory } from '../utils/temporary-directory.js';
import { UnexpectedExitHandler } from '../unexpected-exit-handler.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path';

import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
import { File, StrykerOptions } from '@stryker-mutator/api/core';
import { StrykerOptions } from '@stryker-mutator/api/core';
import type { disableTypeChecks } from '@stryker-mutator/instrumenter';
import { Logger } from '@stryker-mutator/api/logging';
import { File } from '@stryker-mutator/util';

import { optionsPath } from '../utils/index.js';
import { coreTokens } from '../di/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/sandbox/file-preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

/**
* A preprocessor changes files before writing them to the sandbox.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/sandbox/multi-preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

import { FilePreprocessor } from './file-preprocessor.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { promises as fsPromises } from 'fs';

import type { execaCommand } from 'execa';
import { npmRunPathEnv } from 'npm-run-path';
import { StrykerOptions, File } from '@stryker-mutator/api/core';
import { normalizeWhitespaces, I } from '@stryker-mutator/util';
import { StrykerOptions } from '@stryker-mutator/api/core';
import { normalizeWhitespaces, I, File } from '@stryker-mutator/util';
import { Logger } from '@stryker-mutator/api/logging';
import { tokens, commonTokens, Disposable } from '@stryker-mutator/api/plugin';
import { mergeMap, toArray } from 'rxjs/operators';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/sandbox/ts-config-preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'path';

import { StrykerOptions, File } from '@stryker-mutator/api/core';
import { StrykerOptions } from '@stryker-mutator/api/core';
import { tokens, commonTokens } from '@stryker-mutator/api/plugin';
import { Logger } from '@stryker-mutator/api/logging';
import { File } from '@stryker-mutator/util';

import { FilePreprocessor } from './file-preprocessor.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/integration/utils/file-utils.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { promises as fsPromises } from 'fs';
import mkdirp from 'mkdirp';

import { expect } from 'chai';
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import nodeGlob from 'glob';
import { assertions } from '@stryker-mutator/test-helpers';

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/unit/input/input-file-resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import { Dirent, promises as fsPromises } from 'fs';

import { File, MutationRange } from '@stryker-mutator/api/core';
import { MutationRange } from '@stryker-mutator/api/core';
import { assertions, factory, testInjector, tick } from '@stryker-mutator/test-helpers';
import { Task } from '@stryker-mutator/util';
import { File, Task } from '@stryker-mutator/util';
import { expect } from 'chai';
import sinon from 'sinon';

Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/unit/process/1-prepare-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { JSONSchema7 } from 'json-schema';
import { Injector } from 'typed-inject';
import { expect } from 'chai';
import { testInjector, factory } from '@stryker-mutator/test-helpers';
import { PartialStrykerOptions, File, LogLevel } from '@stryker-mutator/api/core';
import { PartialStrykerOptions, LogLevel } from '@stryker-mutator/api/core';
import { BaseContext } from '@stryker-mutator/api/plugin';
import { File } from '@stryker-mutator/util';

import { MutantInstrumenterContext, PrepareExecutor } from '../../../src/process/index.js';
import { coreTokens, PluginLoader, LoadedPlugins } from '../../../src/di/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import sinon from 'sinon';
import { expect } from 'chai';
import { File } from '@stryker-mutator/api/core';
import { Injector } from 'typed-inject';
import { factory, testInjector } from '@stryker-mutator/test-helpers';
import { Instrumenter, InstrumentResult, InstrumenterOptions, createInstrumenter } from '@stryker-mutator/instrumenter';
import { I } from '@stryker-mutator/util';
import { I, File } from '@stryker-mutator/util';

import { DryRunContext, MutantInstrumenterContext, MutantInstrumenterExecutor } from '../../../src/process/index.js';
import { InputFileCollection } from '../../../src/input/index.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/unit/process/3-dry-run-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import sinon from 'sinon';
import { TestRunner, CompleteDryRunResult, ErrorDryRunResult, TimeoutDryRunResult, DryRunResult } from '@stryker-mutator/api/test-runner';
import { expect } from 'chai';
import { Observable, mergeMap } from 'rxjs';
import { I } from '@stryker-mutator/util';
import { File } from '@stryker-mutator/api/core';
import { File, I } from '@stryker-mutator/util';

import { Timer } from '../../../src/utils/timer.js';
import { DryRunContext, DryRunExecutor, MutationTestContext } from '../../../src/process/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sinon from 'sinon';
import { File, Location, MutantResult, MutantStatus, schema } from '@stryker-mutator/api/core';
import { Location, MutantResult, MutantStatus, schema } from '@stryker-mutator/api/core';
import { Reporter } from '@stryker-mutator/api/report';
import { factory, testInjector } from '@stryker-mutator/test-helpers';
import type { requireResolve } from '@stryker-mutator/util';
import { File, type requireResolve } from '@stryker-mutator/util';
import { expect } from 'chai';
import { CompleteDryRunResult } from '@stryker-mutator/api/test-runner';
import { CheckStatus } from '@stryker-mutator/api/check';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { testInjector, assertions } from '@stryker-mutator/test-helpers';
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

import { FilePreprocessor, createPreprocessor } from '../../../src/sandbox/index.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import { assertions, testInjector } from '@stryker-mutator/test-helpers';
import sinon from 'sinon';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/unit/sandbox/multi-preprocessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sinon from 'sinon';
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import { expect } from 'chai';

import { MultiPreprocessor } from '../../../src/sandbox/multi-preprocessor.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/unit/sandbox/sandbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { npmRunPathEnv } from 'npm-run-path';
import { expect } from 'chai';
import sinon from 'sinon';
import { testInjector, tick, factory } from '@stryker-mutator/test-helpers';
import { File } from '@stryker-mutator/api/core';
import { I, normalizeWhitespaces, Task } from '@stryker-mutator/util';
import { File, I, normalizeWhitespaces, Task } from '@stryker-mutator/util';

import { Sandbox } from '../../../src/sandbox/sandbox.js';
import { coreTokens } from '../../../src/di/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';

import { expect } from 'chai';
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import { assertions, testInjector } from '@stryker-mutator/test-helpers';

import { TSConfig, TSConfigPreprocessor } from '../../../src/sandbox/ts-config-preprocessor.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/instrumenter/src/disable-type-checks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { types } from '@babel/core';
import { File } from '@stryker-mutator/api/core';
import { notEmpty } from '@stryker-mutator/util';
import { notEmpty, File } from '@stryker-mutator/util';

import { createParser, getFormat, ParserOptions } from './parsers/index.js';
import { AstFormat, HtmlAst, ScriptAst } from './syntax/index.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/instrumenter/src/instrument-result.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { File, Mutant } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

export interface InstrumentResult {
files: readonly File[];
Expand Down
3 changes: 2 additions & 1 deletion packages/instrumenter/src/instrumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import path from 'path';

import { tokens, commonTokens } from '@stryker-mutator/api/plugin';
import { Logger } from '@stryker-mutator/api/logging';
import { File, MutationRange } from '@stryker-mutator/api/core';
import { MutationRange } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

import { createParser } from './parsers/index.js';
import { transform, MutantCollector } from './transformers/index.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promises as fsPromises } from 'fs';
import { expect } from 'chai';
import chaiJestSnapshot from 'chai-jest-snapshot';

import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';

import { disableTypeChecks } from '../../src/index.js';
import { createInstrumenterOptions } from '../helpers/factories.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fsPromises } from 'fs';

import { testInjector } from '@stryker-mutator/test-helpers';
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import { expect } from 'chai';
import chaiJestSnapshot from 'chai-jest-snapshot';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { File } from '@stryker-mutator/util';
import { assertions } from '@stryker-mutator/test-helpers';

import { disableTypeChecks } from '../../src/index.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/instrumenter/test/unit/instrumenter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { testInjector } from '@stryker-mutator/test-helpers';
import { File } from '@stryker-mutator/api/core';
import { I } from '@stryker-mutator/util';
import { I, File } from '@stryker-mutator/util';

import { Instrumenter } from '../../src/index.js';
import * as parsers from '../../src/parsers/index.js';
Expand Down
9 changes: 8 additions & 1 deletion packages/test-helpers/src/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ import {
TestStatus,
TimeoutMutantRunResult,
} from '@stryker-mutator/api/test-runner';
import { File } from '@stryker-mutator/api/core';
import { CheckResult, FailedCheckResult, CheckStatus } from '@stryker-mutator/api/check';

/**
* Simple file interface, since we cannot use the File class directly because that would result in a dependency cycle
*/
interface File {
name: string;
textContent: string;
}

export function expectKilled(result: MutantRunResult): asserts result is KilledMutantRunResult {
assert.strictEqual(result.status, MutantRunStatus.Killed, result.status === MutantRunStatus.Error ? result.errorMessage : '');
}
Expand Down
5 changes: 0 additions & 5 deletions packages/test-helpers/src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ajv from 'ajv';
import {
File,
Location,
MutationScoreThresholds,
StrykerOptions,
Expand Down Expand Up @@ -395,10 +394,6 @@ export function injector<T = unknown>(): sinon.SinonStubbedInstance<Injector<T>>
return injectorMock;
}

export function file(): File {
return new File('', '');
}

export function fileNotFoundError(): NodeJS.ErrnoException {
return createErrnoException('ENOENT');
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './require-resolve.js';
export * from './deep-merge.js';
export * from './find-unserializables.js';
export * from './platform.js';
export * from './file.js';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { File } from '../../../src/core/index.js';
import { File } from '../../src/index.js';

describe('File', () => {
it('should allow utf8 encoded string content in the constructor', () => {
Expand Down