1 | import path from 'path';
|
2 | import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
|
3 | import { optionsPath } from '../utils/index.js';
|
4 | import { coreTokens } from '../di/index.js';
|
5 | import { objectUtils } from '../utils/object-utils.js';
|
6 | import { FileMatcher } from '../config/index.js';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export class DisableTypeChecksPreprocessor {
|
12 | constructor(log, options, impl) {
|
13 | this.log = log;
|
14 | this.options = options;
|
15 | this.impl = impl;
|
16 | }
|
17 | async preprocess(project) {
|
18 | const matcher = new FileMatcher(this.options.disableTypeChecks);
|
19 | let warningLogged = false;
|
20 | await Promise.all(objectUtils.map(project.files, async (file, name) => {
|
21 | if (matcher.matches(path.resolve(name))) {
|
22 | try {
|
23 | const { content } = await this.impl(await file.toInstrumenterFile(), { plugins: this.options.mutator.plugins });
|
24 | file.setContent(content);
|
25 | }
|
26 | catch (err) {
|
27 | if (objectUtils.isWarningEnabled('preprocessorErrors', this.options.warnings)) {
|
28 | warningLogged = true;
|
29 | this.log.warn(`Unable to disable type checking for file "${name}". Shouldn't type checking be disabled for this file? Consider configuring a more restrictive "${optionsPath('disableTypeChecks')}" settings (or turn it completely off with \`false\`)`, err);
|
30 | }
|
31 | }
|
32 | }
|
33 | }));
|
34 | if (warningLogged) {
|
35 | this.log.warn(`(disable "${optionsPath('warnings', 'preprocessorErrors')}" to ignore this warning`);
|
36 | }
|
37 | }
|
38 | }
|
39 | DisableTypeChecksPreprocessor.inject = tokens(commonTokens.logger, commonTokens.options, coreTokens.disableTypeChecksHelper);
|
40 |
|
\ | No newline at end of file |